Skip to content

Commit

Permalink
chore: improve response data on confirmation message
Browse files Browse the repository at this point in the history
  • Loading branch information
m-arrieta-r committed Oct 5, 2024
1 parent b301ac2 commit 68b54d7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
6 changes: 4 additions & 2 deletions examples/createAndSend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { PersonProps } from 'dist/src/ATV/core/Person'
const IS_STG = process.env.IS_STG
const USERNAME_TEST = process.env.USERNAME_TEST
const PASSWORD_TEST = process.env.PASSWORD_TEST
console.log('process.env.IS_STG', IS_STG)

const SOURCE_P12_URI = process.env.SOURCE_P12_URI
const SOURCE_P12_PASSPORT = process.env.SOURCE_P12_PASSPORT
Expand All @@ -18,8 +17,11 @@ if (!SOURCE_P12_PASSPORT || !SOURCE_P12_URI) {

const pem = fs.readFileSync(SOURCE_P12_URI, 'binary')

const paramConsecutive = process.argv[2]
console.log('paramConsecutive', paramConsecutive)

// TODO: dynamic param --identifier 1 args[x]
createDocumentInputExample.consecutiveIdentifier = process.env.TEST_CONSECUTIVE
createDocumentInputExample.consecutiveIdentifier = paramConsecutive || process.env.TEST_CONSECUTIVE
createDocumentInputExample.emitter.identifier.id = process.env.EMITTER_IDENTIFIER_ID as string;
createDocumentInputExample.emitter.identifier.type = process.env.EMITTER_IDENTIFIER_TYPE as PersonProps['identifier']['type'];

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@facturacr/atv-sdk",
"version": "1.2.7",
"version": "1.2.3",
"description": "Librería (SDK) de Javascript/NodeJS para acceder al API de Administración Tributaria Virtual (ATV) del Ministerio de Hacienda.",
"main": "dist/src/index.js",
"types": "dist/src/index.d.ts",
Expand Down
15 changes: 7 additions & 8 deletions src/ATV/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,27 +55,26 @@ export class ATV {
try {
const response = await axios(input)
const xmlResponse = response.data['respuesta-xml']
const headerResultState = response.data['ind-estado']
if (!xmlResponse) {
const state = response.data['ind-estado']
return {
status: response.status,
state,
errorCause: null
}
throw new Error('NO_XML_IN_RESPONSE')
}
const xmlString = this.decodeBase64(xmlResponse)

return {
status: response.status,
headerResultState,
confirmation: this.parseConfirmationMessage(xmlString),
xml: xmlString,
errorCause: null
rawResponse: response,
errorCause: null,
}
} catch (error) {
const response = error.response || {}
return {
status: response.status || 500,
errorCause: response.statusText
errorCause: response.statusText || error.message,
rawResponse: response,
}
}
}
Expand Down

0 comments on commit 68b54d7

Please sign in to comment.