Skip to content

Commit

Permalink
Merge pull request #154 from facturacr/return-atv-document-object
Browse files Browse the repository at this point in the history
Return atv document object
  • Loading branch information
m-arrieta-r authored Apr 28, 2024
2 parents 8f061ee + 6f398a3 commit 35c9541
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 10 deletions.
4 changes: 4 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Ejemplos con implementaciones para pruebas

```
yarn build
```

Para probar crear y enviar factura
```
yarn ts-node -r tsconfig-paths/register --require dotenv/config examples/createAndSend.ts
Expand Down
2 changes: 1 addition & 1 deletion examples/createAndSend.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fs from 'fs'
import { ATV } from '@src/ATV'
import { ATV } from '../dist/src/ATV'
import { createDocumentInputStub } from '@test/stubs/createDocument.stub'

const IS_STG = process.env.IS_STG
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": "0.0.18beta",
"version": "0.0.20-beta",
"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
1 change: 0 additions & 1 deletion src/ATV/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ export class ATV {
public async sendConfirmation(input: SendConfirmationInput) {
try {
const response = await axios(input)
console.log('response', response)
const xmlResponse = response.data['respuesta-xml']
if (!xmlResponse) {
const state = response.data['ind-estado']
Expand Down
4 changes: 2 additions & 2 deletions src/ATV/mappers/billDocToAtv.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Document, FacturaElectronicaContenedor, DetalleServicio, Resumen, Persona } from '@src/types/facturaInterfaces'
import { Document, InvoiceDocumentContainer, DetalleServicio, Resumen, Persona } from '@src/types/facturaInterfaces'
import { Document as DomainDocument } from '../core/Document'
import { OrderLine } from '../core/OrderLine'
import { Person } from '../core/Person'

type AtvFormat = FacturaElectronicaContenedor
type AtvFormat = InvoiceDocumentContainer

const mapOrderLinesToAtvFormat = (orderLines: OrderLine[]): DetalleServicio => {
const LineaDetalle = orderLines.map<DetalleServicio['LineaDetalle'][0]>((orderLine) => {
Expand Down
3 changes: 2 additions & 1 deletion src/ATV/useCases/createDocument/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ export class CreateDocumentCommand {
return {
command,
extraData: {
xml
xml,
document: atvDocument
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/ATV/useCases/createDocument/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { PersonProps } from '@src/ATV/core/Person'
import { DocumentNames } from '@src/ATV/core/documentNames.types'
import { InvoiceDocumentContainer } from '@src/types/facturaInterfaces';
import { Method } from 'axios'

type PersonInput = PersonProps;
Expand Down Expand Up @@ -71,9 +72,11 @@ export type Command = {
'Content-Type': string;
};
}

export type CreateAndSendDocumentResponse = {
command: Command;
extraData: {
xml: string;
document: InvoiceDocumentContainer;
};
}
4 changes: 2 additions & 2 deletions src/lib/genJSON/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ClientPayload } from '@src/types/globalInterfaces'
import { FacturaElectronicaContenedor, Resumen, Persona, Impuesto, LineaDetalle } from '@src/types/facturaInterfaces'
import { InvoiceDocumentContainer, Resumen, Persona, Impuesto, LineaDetalle } from '@src/types/facturaInterfaces'
import { genXML } from '@src/lib/genXML'

// Default XML Values
Expand Down Expand Up @@ -123,7 +123,7 @@ export default async (frontEndRequest: ClientPayload, date: any, clave: string,
},
ResumenFactura: getBillResum(lines)
}
const factura: FacturaElectronicaContenedor = {
const factura: InvoiceDocumentContainer = {
[key]: body
}
const XML = await genXML(key, factura, options)
Expand Down
2 changes: 1 addition & 1 deletion src/types/facturaInterfaces.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export interface Document {
};
}

export interface FacturaElectronicaContenedor {
export interface InvoiceDocumentContainer {
[key: 'FacturaElectronica' | 'FacturaElectronicaExportacion']: Document | FacturaElectronicaExportacion;
}

Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@
]
},
"include": ["./src/**/*", "__tests__/**/*", "__tests__/stubs", "examples"],
"exclude": ["node_modules/**/*"]
"exclude": ["node_modules/**/*", "examples/**/*"]
}

0 comments on commit 35c9541

Please sign in to comment.