@facturacr/atv-sdk 1.2.13 → 2.0.0-alpha

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/.env.example +2 -0
  2. package/__tests__/stubs/createDocument.data.ts +4 -1
  3. package/dist/src/ATV/core/CreateDocFactory.d.ts +2 -1
  4. package/dist/src/ATV/core/CreateDocFactory.js +1 -1
  5. package/dist/src/ATV/core/CreateDocFactory.js.map +1 -1
  6. package/dist/src/ATV/core/Document.d.ts +2 -1
  7. package/dist/src/ATV/core/Document.js +4 -1
  8. package/dist/src/ATV/core/Document.js.map +1 -1
  9. package/dist/src/ATV/core/OrderLine.js +1 -1
  10. package/dist/src/ATV/core/OrderLine.js.map +1 -1
  11. package/dist/src/ATV/core/Person.d.ts +2 -0
  12. package/dist/src/ATV/core/Person.js +3 -0
  13. package/dist/src/ATV/core/Person.js.map +1 -1
  14. package/dist/src/ATV/mappers/billDocToAtv.js +15 -15
  15. package/dist/src/ATV/mappers/billDocToAtv.js.map +1 -1
  16. package/dist/src/index.d.ts +1 -1
  17. package/dist/src/lib/genXML/sigXML/index.js +2 -1
  18. package/dist/src/lib/genXML/sigXML/index.js.map +1 -1
  19. package/dist/src/lib/genXML/xmlConfig.d.ts +25 -24
  20. package/dist/src/lib/genXML/xmlConfig.js +25 -20
  21. package/dist/src/lib/genXML/xmlConfig.js.map +1 -1
  22. package/dist/src/types/facturaInterfaces.d.ts +10 -6
  23. package/doc/atv-structures/4.4/breaking-changes-ai-generated.md +53 -0
  24. package/doc/atv-structures/4.4/supported.md +12 -0
  25. package/examples/README.md +8 -3
  26. package/examples/createAndSend.ts +4 -3
  27. package/package.json +1 -1
  28. package/src/ATV/core/CreateDocFactory.ts +70 -70
  29. package/src/ATV/core/Document.ts +6 -2
  30. package/src/ATV/core/OrderLine.ts +1 -1
  31. package/src/ATV/core/Person.ts +5 -0
  32. package/src/ATV/mappers/billDocToAtv.ts +20 -19
  33. package/src/index.ts +2 -2
  34. package/src/lib/genXML/sigXML/index.ts +2 -1
  35. package/src/lib/genXML/xmlConfig.ts +27 -33
  36. package/src/types/facturaInterfaces.ts +11 -6
  37. package/dist/src/confirmXML.d.ts +0 -8
  38. package/dist/src/confirmXML.js +0 -44
  39. package/dist/src/confirmXML.js.map +0 -1
  40. package/dist/src/creditNote.d.ts +0 -14
  41. package/dist/src/creditNote.js +0 -77
  42. package/dist/src/creditNote.js.map +0 -1
  43. package/dist/src/electronicBill.d.ts +0 -3
  44. package/dist/src/electronicBill.js +0 -61
  45. package/dist/src/electronicBill.js.map +0 -1
  46. package/dist/src/lib/genJSON/confirmXML.d.ts +0 -7
  47. package/dist/src/lib/genJSON/confirmXML.js +0 -46
  48. package/dist/src/lib/genJSON/confirmXML.js.map +0 -1
  49. package/dist/src/lib/genJSON/index.d.ts +0 -5
  50. package/dist/src/lib/genJSON/index.js +0 -135
  51. package/dist/src/lib/genJSON/index.js.map +0 -1
  52. package/examples/genBasicXML.ts +0 -31
  53. package/src/confirmXML.ts +0 -40
  54. package/src/creditNote.ts +0 -93
  55. package/src/electronicBill.ts +0 -57
  56. package/src/lib/genJSON/confirmXML.ts +0 -47
  57. package/src/lib/genJSON/index.ts +0 -131
@@ -0,0 +1,12 @@
1
+ ## Breaking changes de la librería
2
+ - Se agregó soporte para actividad economica para receptor y emisor.
3
+ - Se agregó soporte para proveedor de servicios.
4
+ ## Ajustes mapeo generación documento ATV
5
+ - Se eliminó fax.
6
+ - Se ajustó el minimo del "Barrio" (padStart 6).
7
+ - Se ajustó "MedioPago" a objeto con "TipoMedioPago" y se mueve a ResumenFactura.
8
+ - Se cambió el nombre de "Codigo" a "CodigoCABYS" en DetalleServicio.
9
+ - Se agregó "BaseImponible" (soporte parcial).
10
+ - Se eliminó "CodigoTarifa" en Impuesto.
11
+ - Se agregó "ImpuestoAsumidoEmisorFabrica" (soporte parcial).
12
+ - Se agregó "ImpuestoNeto" (soporte parcial).
@@ -1,12 +1,17 @@
1
1
  # Ejemplos con implementaciones para pruebas
2
2
 
3
+ Configurar .env file basado en .env.example
4
+ ```
5
+ cp .env.example .env
6
+ ```
7
+
3
8
  ```
4
9
  yarn build
5
10
  ```
6
11
 
7
12
  Para probar crear y enviar factura
8
13
  ```
9
- yarn ts-node -r tsconfig-paths/register --require dotenv/config examples/createAndSend.ts
14
+ yarn ts-node -r tsconfig-paths/register --require dotenv/config examples/createAndSend.ts 1
10
15
  ```
11
16
 
12
17
  Para aceptar una factura
@@ -39,7 +44,7 @@ Para probar las funcionalidades se recomienda crear un .env en donde se especifi
39
44
  ```
40
45
  USERNAME_TEST= ## Provided be ATV System
41
46
  PASSWORD_TEST= ## Provided be ATV System
42
- IS_STG=1
47
+ IS_STG=1
43
48
  SOURCE_P12_URI= ## Provided be ATV System
44
49
  SOURCE_P12_PASSPORT= ## Provided be ATV System
45
50
  SOURCE_URI_XML_OUTPUT= ## Custom OS PATH
@@ -60,4 +65,4 @@ XML_TO_CONFIRM=$PATH/__test__/input/Comprobante_Electronico_####_####.xml
60
65
  Para usar readXML establecer en .env
61
66
  ```
62
67
  SOURCE_URI=
63
- ```
68
+ ```
@@ -21,9 +21,9 @@ const paramConsecutive = process.argv[2]
21
21
  console.log('paramConsecutive', paramConsecutive)
22
22
 
23
23
  // TODO: dynamic param --identifier 1 args[x]
24
- createDocumentInputExample.consecutiveIdentifier = paramConsecutive || process.env.TEST_CONSECUTIVE
25
- createDocumentInputExample.emitter.identifier.id = process.env.EMITTER_IDENTIFIER_ID as string;
26
- createDocumentInputExample.emitter.identifier.type = process.env.EMITTER_IDENTIFIER_TYPE as PersonProps['identifier']['type'];
24
+ createDocumentInputExample.consecutiveIdentifier = paramConsecutive || process.env.TEST_CONSECUTIVE
25
+ createDocumentInputExample.emitter.identifier.id = process.env.EMITTER_IDENTIFIER_ID as string
26
+ createDocumentInputExample.emitter.identifier.type = process.env.EMITTER_IDENTIFIER_TYPE as PersonProps['identifier']['type']
27
27
 
28
28
  console.log('requestStub consecutivo', createDocumentInputExample.consecutiveIdentifier)
29
29
 
@@ -57,6 +57,7 @@ async function main(): Promise<void> {
57
57
  password: SOURCE_P12_PASSPORT
58
58
  }
59
59
  })
60
+ console.log('extraData', extraData)
60
61
  const response = await atv.sendDocument(command)
61
62
  if (response.errorCause) {
62
63
  console.log('error response', response)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@facturacr/atv-sdk",
3
- "version": "1.2.13",
3
+ "version": "2.0.0-alpha",
4
4
  "description": "Librería (SDK) de Javascript/NodeJS para acceder al API de Administración Tributaria Virtual (ATV) del Ministerio de Hacienda.",
5
5
  "main": "dist/src/index.js",
6
6
  "types": "dist/src/index.d.ts",
@@ -1,6 +1,5 @@
1
- import { PersonProps } from '@src/ATV/core/Person'
1
+ import { Person, PersonProps } from '@src/ATV/core/Person'
2
2
  import { DocumentNames } from '@src/ATV/core/documentNames.types'
3
- import { Person } from '@src/ATV/core/Person'
4
3
  import { OrderLine } from '@src/ATV/core/OrderLine'
5
4
  import { FullConsecutive } from '@src/ATV/core/FullConsecutive'
6
5
  import { Document } from '@src/ATV/core/Document'
@@ -9,6 +8,8 @@ import { DocumentType } from '@src/ATV/core/DocumentType'
9
8
  import { ReferenceInformation, ReferenceInformationProps } from './ReferenceInformation'
10
9
  import { ReceptorMessageProps } from './types'
11
10
 
11
+ type ReferenceInfoInput = ReferenceInformationProps;
12
+
12
13
  type PersonInput = PersonProps;
13
14
 
14
15
  type TaxInput = {
@@ -38,6 +39,7 @@ type DocumentInput = {
38
39
  terminal: string; // terminal
39
40
  // documentType: DocumentTypes; // @deprecated
40
41
  documentName: DocumentNames;
42
+ providerId: string;
41
43
  countryCode: string; // codigoPais
42
44
  securityCode: string; // codigoSeguridad
43
45
  activityCode: string;
@@ -45,77 +47,75 @@ type DocumentInput = {
45
47
  ceSituation: string; // situacionCE
46
48
  orderLines: OrderInput[];
47
49
  referenceInfo?: ReferenceInfoInput;
48
- conditionSale:string
49
- paymentMethod:string;
50
+ conditionSale: string
51
+ paymentMethod: string;
50
52
  }
51
53
 
52
- type ReferenceInfoInput = ReferenceInformationProps;
53
-
54
- export type CreateDocumentInput = {
55
- document: DocumentInput;
56
- token: string;
57
- receptorMessageProps?: ReceptorMessageProps;
58
- signatureOptions: {
59
- buffer: string;
60
- password: string;
61
- };
62
- }
54
+ export type CreateDocumentInput = {
55
+ document: DocumentInput;
56
+ token: string;
57
+ receptorMessageProps?: ReceptorMessageProps;
58
+ signatureOptions: {
59
+ buffer: string;
60
+ password: string;
61
+ };
62
+ }
63
63
 
64
64
  export class CreateDocFactory {
65
65
  public createDocument(document: CreateDocumentInput['document']): Document {
66
- const documentType = DocumentType.create(document.documentName)
67
- const clave = this.createClave(document, documentType)
68
- const fullConsective = this.createFullConsecutive(document, documentType)
69
- const orderLines = this.createOrderLines(document)
70
- return Document.create({
71
- clave,
72
- fullConsecutive: fullConsective,
73
- orderLines,
74
- activityCode: document.activityCode,
75
- issueDate: new Date(),
76
- emitter: Person.create(document.emitter),
77
- receiver: Person.create(document.receiver),
78
- conditionSale: document.conditionSale,
79
- paymentMethod: document.paymentMethod,
80
- referenceInformation: document.referenceInfo ? ReferenceInformation.create(document.referenceInfo) : undefined,
81
- })
82
- }
83
-
84
- private createOrderLines(dto: CreateDocumentInput['document']): OrderLine[] {
85
- return dto.orderLines.map((orderLine, index) => {
86
- return OrderLine.create({
87
- detail: orderLine.detail,
88
- unitaryPrice: orderLine.unitaryPrice,
89
- lineNumber: orderLine.lineNumber || (index + 1).toString(),
90
- code: orderLine.code,
91
- quantity: orderLine.quantity,
92
- measureUnit: orderLine.measureUnit,
93
- totalAmount: orderLine.totalAmount,
94
- tax: orderLine.tax
95
- })
96
- })
97
- }
98
-
99
- private createFullConsecutive(dto: CreateDocumentInput['document'], docType: DocumentType): FullConsecutive {
100
- return FullConsecutive.create({
101
- consecutiveIdentifier: dto.consecutiveIdentifier,
102
- branch: dto.branch.padStart(3, '0'),
103
- terminal: dto.terminal.padStart(5, '0'),
104
- documentType: docType.value
105
- })
106
- }
107
-
108
- private createClave(dto: CreateDocumentInput['document'], docType: DocumentType): Clave {
109
- return Clave.create({
110
- branch: dto.branch,
111
- ceSituation: dto.ceSituation,
112
- consecutiveIdentifier: dto.consecutiveIdentifier,
113
- countryCode: dto.countryCode,
114
- docKeyType: docType.value,
115
- emitterIdentifier: dto.emitter.identifier.id,
116
- identifierType: dto.emitter.identifier.type, // TODO add default
117
- securityCode: dto.securityCode,
118
- terminal: dto.terminal
66
+ const documentType = DocumentType.create(document.documentName)
67
+ const clave = this.createClave(document, documentType)
68
+ const fullConsective = this.createFullConsecutive(document, documentType)
69
+ const orderLines = this.createOrderLines(document)
70
+ return Document.create({
71
+ clave,
72
+ fullConsecutive: fullConsective,
73
+ orderLines,
74
+ providerId: document.providerId,
75
+ issueDate: new Date(),
76
+ emitter: Person.create(document.emitter),
77
+ receiver: Person.create(document.receiver),
78
+ conditionSale: document.conditionSale,
79
+ paymentMethod: document.paymentMethod,
80
+ referenceInformation: document.referenceInfo ? ReferenceInformation.create(document.referenceInfo) : undefined,
81
+ })
82
+ }
83
+
84
+ private createOrderLines(dto: CreateDocumentInput['document']): OrderLine[] {
85
+ return dto.orderLines.map((orderLine, index) => {
86
+ return OrderLine.create({
87
+ detail: orderLine.detail,
88
+ unitaryPrice: orderLine.unitaryPrice,
89
+ lineNumber: orderLine.lineNumber || (index + 1).toString(),
90
+ code: orderLine.code,
91
+ quantity: orderLine.quantity,
92
+ measureUnit: orderLine.measureUnit,
93
+ totalAmount: orderLine.totalAmount,
94
+ tax: orderLine.tax
119
95
  })
120
- }
121
- }
96
+ })
97
+ }
98
+
99
+ private createFullConsecutive(dto: CreateDocumentInput['document'], docType: DocumentType): FullConsecutive {
100
+ return FullConsecutive.create({
101
+ consecutiveIdentifier: dto.consecutiveIdentifier,
102
+ branch: dto.branch.padStart(3, '0'),
103
+ terminal: dto.terminal.padStart(5, '0'),
104
+ documentType: docType.value
105
+ })
106
+ }
107
+
108
+ private createClave(dto: CreateDocumentInput['document'], docType: DocumentType): Clave {
109
+ return Clave.create({
110
+ branch: dto.branch,
111
+ ceSituation: dto.ceSituation,
112
+ consecutiveIdentifier: dto.consecutiveIdentifier,
113
+ countryCode: dto.countryCode,
114
+ docKeyType: docType.value,
115
+ emitterIdentifier: dto.emitter.identifier.id,
116
+ identifierType: dto.emitter.identifier.type, // TODO add default
117
+ securityCode: dto.securityCode,
118
+ terminal: dto.terminal
119
+ })
120
+ }
121
+ }
@@ -7,8 +7,8 @@ import { SummaryProps } from './Summary.type'
7
7
 
8
8
  export type InvoiceProps = {
9
9
  clave: Clave;
10
+ providerId: string; // ProveedorSistemas
10
11
  fullConsecutive: FullConsecutive;
11
- activityCode: string; // CodigoActividad
12
12
  issueDate: Date; // FechaEmision
13
13
  emitter: Person; // Emisor
14
14
  receiver: Person; // Receptor
@@ -42,8 +42,12 @@ export class Document {
42
42
  return this.props.fullConsecutive.value
43
43
  }
44
44
 
45
+ get providerId(): string {
46
+ return this.props.providerId
47
+ }
48
+
45
49
  get activityCode(): string {
46
- return this.props.activityCode
50
+ return this.props.emitter.activityCode
47
51
  }
48
52
 
49
53
  get issueDate(): Date {
@@ -84,7 +84,7 @@ export class OrderLine {
84
84
  }
85
85
  const tax: TaxProps = {
86
86
  code: props.tax.code,
87
- rate: props.tax.rate || 13,
87
+ rate: typeof props.tax.rate === 'number' ? props.tax.rate : 13,
88
88
  rateCode: props.tax.rateCode
89
89
  }
90
90
  return new OrderLine({
@@ -18,6 +18,7 @@ export type PersonProps = {
18
18
  id: string;
19
19
  };
20
20
  commercialName: string;
21
+ activityCode: string;
21
22
  location?: LocationProps;
22
23
  phone?: PhoneProps;
23
24
  fax?: PhoneProps;
@@ -46,6 +47,10 @@ export class Person {
46
47
  return this.props.commercialName
47
48
  }
48
49
 
50
+ get activityCode(): string {
51
+ return this.props.activityCode
52
+ }
53
+
49
54
  get location(): LocationProps | undefined {
50
55
  return this.props.location
51
56
  }
@@ -1,4 +1,4 @@
1
- import { Document, InvoiceDocumentContainer, DetalleServicio, Resumen, Persona, InformacionReferencia } from '@src/types/facturaInterfaces'
1
+ import { AtvDocument, InvoiceDocumentContainer, DetalleServicio, Resumen, Persona, InformacionReferencia } from '@src/types/facturaInterfaces'
2
2
  import { Document as DomainDocument } from '../core/Document'
3
3
  import { OrderLine } from '../core/OrderLine'
4
4
  import { Person } from '../core/Person'
@@ -15,7 +15,7 @@ const mapOrderLinesToAtvFormat = (orderLines: OrderLine[]): DetalleServicio => {
15
15
  const LineaDetalle = orderLines.map<DetalleServicio['LineaDetalle'][0]>((orderLine) => {
16
16
  return {
17
17
  NumeroLinea: orderLine.lineNumber,
18
- Codigo: orderLine.code,
18
+ CodigoCABYS: orderLine.code,
19
19
  // CodigoComercial
20
20
  Cantidad: orderLine.quantity,
21
21
  UnidadMedida: orderLine.measureUnit,
@@ -25,21 +25,22 @@ const mapOrderLinesToAtvFormat = (orderLines: OrderLine[]): DetalleServicio => {
25
25
  MontoTotal: orderLine.totalAmount,
26
26
  // Descuento
27
27
  SubTotal: orderLine.subTotal,
28
- // BaseImponible
28
+ BaseImponible: orderLine.subTotal,
29
29
  Impuesto: {
30
30
  Codigo: orderLine.tax.code,
31
- CodigoTarifa: orderLine.tax.rateCode,
32
31
  Tarifa: orderLine.tax.rate,
33
32
  Monto: parseAtvMoneyFormat(orderLine.tax.amount)
34
33
  },
35
- // ImpuestoNeto
34
+ ImpuestoAsumidoEmisorFabrica: 0,
35
+ ImpuestoNeto: parseAtvMoneyFormat(orderLine.tax.amount),
36
36
  MontoTotalLinea: parseAtvMoneyFormat(orderLine.totalOrderLineAmount)
37
37
  }
38
38
  })
39
39
  return { LineaDetalle }
40
40
  }
41
41
 
42
- const mapSummaryInvoice = (summaryInvoice: DomainDocument['summaryInvoice']): Resumen => {
42
+ const mapSummaryInvoice = (document: DomainDocument): Resumen => {
43
+ const summaryInvoice = document.summaryInvoice
43
44
  return {
44
45
  CodigoTipoMoneda: {
45
46
  CodigoMoneda: summaryInvoice.currency.code,
@@ -56,6 +57,9 @@ const mapSummaryInvoice = (summaryInvoice: DomainDocument['summaryInvoice']): Re
56
57
  TotalDescuentos: parseAtvMoneyFormat(summaryInvoice.totalDiscounts),
57
58
  TotalVentaNeta: parseAtvMoneyFormat(summaryInvoice.totalNetSale),
58
59
  TotalImpuesto: parseAtvMoneyFormat(summaryInvoice.totalTaxes),
60
+ MedioPago: {
61
+ TipoMedioPago: document.paymentMethod
62
+ },
59
63
  TotalComprobante: parseAtvMoneyFormat(summaryInvoice.totalVoucher)
60
64
  }
61
65
  }
@@ -70,26 +74,22 @@ const mapPerson = (person: Person): Persona => {
70
74
  NombreComercial: person.commercialName,
71
75
  Ubicacion: undefined,
72
76
  Telefono: undefined,
73
- Fax: undefined,
74
77
  CorreoElectronico: undefined
75
78
  }
76
79
  atvPerson.Ubicacion = person.location ? {
77
80
  Provincia: person.location?.province,
78
81
  Canton: person.location?.canton?.padStart(2, '0'),
79
82
  Distrito: person.location?.district?.padStart(2, '0'),
80
- Barrio: person.location?.neighborhood?.padStart(2, '0'),
83
+ Barrio: person.location?.neighborhood?.padStart(5, '0'),
81
84
  OtrasSenas: person.location?.details
82
85
  } : undefined
83
86
  atvPerson.Telefono = person.phone ? {
84
87
  CodigoPais: person.phone?.countryCode,
85
88
  NumTelefono: person.phone?.number
86
89
  } : undefined
87
- atvPerson.Fax = person.fax ? {
88
- CodigoPais: person.fax?.countryCode,
89
- NumTelefono: person.fax?.number
90
- } : undefined
91
90
  atvPerson.CorreoElectronico = person.email
92
- return atvPerson;
91
+
92
+ return atvPerson
93
93
  }
94
94
 
95
95
  const mapReferenceInformation = (referenceInfo: ReferenceInformation): InformacionReferencia => {
@@ -103,19 +103,20 @@ const mapReferenceInformation = (referenceInfo: ReferenceInformation): Informaci
103
103
  }
104
104
 
105
105
  export const mapDocumentToAtvFormat = (docName: string, document: DomainDocument): AtvFormat => {
106
- const key = docName
107
- const doc: Document = {
106
+ const key = docName;
107
+ const doc: AtvDocument = {
108
108
  Clave: document.clave,
109
- CodigoActividad: document.activityCode.padStart(6, '0'),
109
+ ProveedorSistemas: document.providerId,
110
+ CodigoActividadEmisor: document.emitter.activityCode.padStart(6, '0'),
111
+ CodigoActividadReceptor: document.receiver.activityCode.padStart(6, '0'),
110
112
  NumeroConsecutivo: document.fullConsecutive,
111
113
  FechaEmision: document.issueDate.toISOString(),
112
114
  Emisor: mapPerson(document.emitter),
113
115
  Receptor: mapPerson(document.receiver),
114
116
  CondicionVenta: document.conditionSale,
115
117
  PlazoCredito: document.deadlineCredit,
116
- MedioPago: document.paymentMethod,
117
118
  DetalleServicio: mapOrderLinesToAtvFormat(document.orderLines),
118
- ResumenFactura: mapSummaryInvoice(document.summaryInvoice),
119
+ ResumenFactura: mapSummaryInvoice(document),
119
120
  Otros: document.others
120
121
  }
121
122
  if (document.referenceInformation) {
@@ -143,4 +144,4 @@ export const mapReceptorMessageToAtvFormat = (props: ReceptorMessageProps): AtvF
143
144
  NumeroConsecutivoReceptor: props.receptorConcecutive
144
145
  }
145
146
  }
146
- }
147
+ }
package/src/index.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  export { parseElectronicBillXML as xmlToJson } from './lib/genXML'
2
- export { Document, InvoiceDocumentContainer, DetalleServicio, Resumen, Persona } from './types/facturaInterfaces'
2
+ export { AtvDocument as Document, InvoiceDocumentContainer, DetalleServicio, Resumen, Persona } from './types/facturaInterfaces'
3
3
  export { CreateDocumentInput } from './ATV/core/CreateDocFactory'
4
- export { ATV } from './ATV'
4
+ export { ATV } from './ATV'
@@ -2,6 +2,7 @@ import { Application, SignedXml, Parse, OptionsXAdES } from 'xadesjs'
2
2
  import { Crypto } from '@peculiar/webcrypto'
3
3
  import { genKeysAndCert } from '@src/lib/genXML/sigXML/genKeysAndCert'
4
4
  import { XMLSerializer } from 'xmldom-alpha'
5
+ import { ATV_VERSION } from '../xmlConfig'
5
6
 
6
7
  function addSigToXML(xml: Document, signature: any): string {
7
8
  xml.documentElement.appendChild(signature.GetXml())
@@ -37,7 +38,7 @@ function getOptions(publicKey: CryptoKey, x509: any, referenceId: string): Optio
37
38
  hash: 'SHA-1',
38
39
  identifier: {
39
40
  qualifier: 'OIDAsURI',
40
- value: 'https://cdn.comprobanteselectronicos.go.cr/xml-schemas/v4.3/facturaElectronica'
41
+ value: `https://cdn.comprobanteselectronicos.go.cr/xml-schemas/v${ATV_VERSION}/facturaElectronica`
41
42
  }
42
43
  },
43
44
  x509: [x509],
@@ -1,58 +1,52 @@
1
- const FE_XML_SCHEMA_NS = 'https://cdn.comprobanteselectronicos.go.cr/xml-schemas/v4.3/facturaElectronica'
2
- const FE_XML_SCHEMA_XSI = 'https://www.hacienda.go.cr/ATV/ComprobanteElectronico/docs/esquemas/2016/v4.3/FacturaElectronica_V4.3.xsd'
1
+ export const ATV_VERSION = '4.4'
3
2
 
4
- const FEE_XML_SCHEMA_NS = 'https://cdn.comprobanteselectronicos.go.cr/xml-schemas/v4.3/facturaElectronicaExportacion'
5
- const FEE_XML_SCHEMA_XSI = 'https://cdn.comprobanteselectronicos.go.cr/xml-schemas/v4.3/facturaElectronicaExportacion.xsd'
3
+ const FE_XML_SCHEMA_NS = `https://cdn.comprobanteselectronicos.go.cr/xml-schemas/v${ATV_VERSION}/facturaElectronica`
6
4
 
7
- const MR_XML_SCHEMA_NS = 'https://cdn.comprobanteselectronicos.go.cr/xml-schemas/v4.3/mensajeReceptor'
5
+ const MR_XML_SCHEMA_NS = `https://cdn.comprobanteselectronicos.go.cr/xml-schemas/v${ATV_VERSION}/mensajeReceptor`
8
6
 
9
- const NC_XML_SCHEMA_NS = 'https://cdn.comprobanteselectronicos.go.cr/xml-schemas/v4.3/notaCreditoElectronica'
10
- const NC_XML_SCHEMA_XSI = 'https://www.hacienda.go.cr/ATV/ComprobanteElectronico/docs/esquemas/2016/v4.3/NotaCreditoElectronica_V4.3.xsd'
11
-
12
- const ND_XML_SCHEMA_NS = 'https://cdn.comprobanteselectronicos.go.cr/xml-schemas/v4.3/notaDebitoElectronica'
13
- const ND_XML_SCHEMA_XSI = 'https://www.hacienda.go.cr/ATV/ComprobanteElectronico/docs/esquemas/2016/v4.3/NotaDebitoElectronica_V4.3.xsd'
7
+ const NC_XML_SCHEMA_NS = `https://cdn.comprobanteselectronicos.go.cr/xml-schemas/v${ATV_VERSION}/notaCreditoElectronica`
14
8
 
15
9
  export const declaration = '<?xml version="1.0" encoding="utf-8"?>'
16
10
 
17
11
  export const defaultOptions = {
18
- attrNodeName: 'attr'
19
- }
12
+ attrNodeName: "attr",
13
+ };
20
14
 
21
15
  const COMMON_STRUCTURE = {
22
- 'xmlns:ds': 'http://www.w3.org/2000/09/xmldsig#',
23
- 'xmlns:xsd': 'http://www.w3.org/2001/XMLSchema',
24
- 'xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance'
25
- }
16
+ "xmlns:ds": "http://www.w3.org/2000/09/xmldsig#",
17
+ "xmlns:xsd": "http://www.w3.org/2001/XMLSchema",
18
+ "xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance",
19
+ };
26
20
 
27
- const FE_XML_ATTRS = { // Factura Electronica
21
+ const FE_XML_ATTRS = {
22
+ // Factura Electronica
28
23
  xmlns: FE_XML_SCHEMA_NS,
29
24
  ...COMMON_STRUCTURE,
30
- // 'xsi:schemaLocation': `${FE_XML_SCHEMA_NS} ${FE_XML_SCHEMA_XSI}`
31
- }
25
+ };
32
26
 
33
- const FEE_XML_ATTRS = { // Factura Electronica Exportación
27
+ const FEE_XML_ATTRS = {
28
+ // Factura Electronica Exportación
34
29
  xmlns: FE_XML_SCHEMA_NS,
35
30
  ...COMMON_STRUCTURE,
36
- // 'xsi:schemaLocation': `${FEE_XML_SCHEMA_NS} ${FEE_XML_SCHEMA_XSI}`
37
- }
31
+ };
38
32
 
39
- const NC_XML_ATTRS = { // Nota Credito Electronica
33
+ const NC_XML_ATTRS = {
34
+ // Nota Credito Electronica
40
35
  xmlns: NC_XML_SCHEMA_NS,
41
36
  ...COMMON_STRUCTURE,
42
- // 'xsi:schemaLocation': `${NC_XML_SCHEMA_NS} ${NC_XML_SCHEMA_XSI}`
43
- }
37
+ };
44
38
 
45
- const ND_XML_ATTRS = { // Nota Credito Electronica
39
+ const ND_XML_ATTRS = {
40
+ // Nota Credito Electronica
46
41
  xmlns: NC_XML_SCHEMA_NS,
47
42
  ...COMMON_STRUCTURE,
48
- // 'xsi:schemaLocation': `${ND_XML_SCHEMA_NS} ${ND_XML_SCHEMA_XSI}`
49
- }
43
+ };
50
44
 
51
- const MR_XML_ATTRS = { // Mensaje Receptor
45
+ const MR_XML_ATTRS = {
46
+ // Mensaje Receptor
52
47
  xmlns: MR_XML_SCHEMA_NS,
53
48
  ...COMMON_STRUCTURE,
54
- // 'xsi:schemaLocation': `${MR_XML_SCHEMA_NS}`
55
- }
49
+ };
56
50
 
57
51
  export const xmlExtructures = {
58
52
  FacturaElectronica: FE_XML_ATTRS,
@@ -62,5 +56,5 @@ export const xmlExtructures = {
62
56
  MensajeReceptor: MR_XML_ATTRS,
63
57
  CCE: MR_XML_ATTRS,
64
58
  CPCE: MR_XML_ATTRS,
65
- RCE: MR_XML_ATTRS
66
- }
59
+ RCE: MR_XML_ATTRS,
60
+ };
@@ -5,7 +5,6 @@
5
5
 
6
6
  export interface Impuesto {
7
7
  Codigo: string;
8
- CodigoTarifa: string;
9
8
  Tarifa: number;
10
9
  Monto?: number;
11
10
  }
@@ -21,6 +20,7 @@ export interface LineaDetalle {
21
20
  SubTotal?: number;
22
21
  BaseImponible?: number;
23
22
  Impuesto?: Impuesto;
23
+ ImpuestoAsumidoEmisorFabrica: number;
24
24
  MontoTotalLinea?: number;
25
25
  }
26
26
 
@@ -45,6 +45,9 @@ export interface Resumen {
45
45
  TotalDescuentos?: number;
46
46
  TotalVentaNeta?: number;
47
47
  TotalImpuesto: number;
48
+ MedioPago?: {
49
+ TipoMedioPago: string;
50
+ };
48
51
  TotalComprobante: number;
49
52
  }
50
53
 
@@ -86,16 +89,18 @@ export interface InformacionReferencia {
86
89
  Razon: string;
87
90
  }
88
91
 
89
- export interface Document {
92
+ export interface AtvDocument {
90
93
  Clave: string;
91
- CodigoActividad: string;
94
+ ProveedorSistemas: string;
95
+ CodigoActividadEmisor: string;
96
+ CodigoActividadReceptor: string;
92
97
  NumeroConsecutivo: string;
93
98
  FechaEmision?: string;
94
99
  Emisor: Persona;
95
100
  Receptor: Persona;
96
101
  CondicionVenta?: string;
97
102
  PlazoCredito?: string;
98
- MedioPago?: string;
103
+
99
104
  DetalleServicio?: DetalleServicio;
100
105
  ResumenFactura: Resumen;
101
106
  Otros?: {
@@ -104,7 +109,7 @@ export interface Document {
104
109
  InformacionReferencia?: InformacionReferencia;
105
110
  }
106
111
 
107
- export interface XMLRawDocument extends Document {
112
+ export interface XMLRawDocument extends AtvDocument {
108
113
 
109
114
  }
110
115
 
@@ -124,7 +129,7 @@ interface MensajeReceptor {
124
129
  }
125
130
 
126
131
  export interface InvoiceDocumentContainer {
127
- [key: string]: Document | MensajeReceptor;
132
+ [key: string]: AtvDocument | MensajeReceptor;
128
133
  }
129
134
 
130
135
  export type ConfirmationMessageRaw = {
@@ -1,8 +0,0 @@
1
- declare const _default: (opts: {
2
- token: string;
3
- tipoDocKey: string;
4
- consecutivo: any;
5
- xmlStr: string;
6
- pemOpt: any;
7
- }) => Promise<any>;
8
- export default _default;
@@ -1,44 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- const genClave_1 = require("./lib/genClave");
13
- const index_1 = require("./lib/genXML/index");
14
- const index_2 = require("./services/send/index");
15
- const confirmXML_1 = require("./lib/genJSON/confirmXML");
16
- function getConsecutivoStr(opts) {
17
- return (0, genClave_1.consecutivoStr)({
18
- sucursal: opts.consecutivo.sucursal,
19
- terminal: opts.consecutivo.terminal,
20
- tipoDocKey: opts.tipoDocKey,
21
- consecutivo: opts.consecutivo.consecutivo
22
- });
23
- }
24
- exports.default = (opts) => __awaiter(void 0, void 0, void 0, function* () {
25
- const { token, pemOpt, tipoDocKey } = opts;
26
- const consecutivo = getConsecutivoStr(opts);
27
- const fullInvoice = (0, index_1.parseElectronicBillXML)(opts.xmlStr);
28
- const msjObj = (0, confirmXML_1.getMsjObj)({ fullInvoice, consecutivo, tipoDocKey });
29
- const xmlBase64 = yield (0, index_1.genXML)(tipoDocKey, msjObj, {
30
- buffer: pemOpt.buffer,
31
- password: pemOpt.password,
32
- base64: true
33
- });
34
- const finalMesage = (0, confirmXML_1.getFinalMessage)(fullInvoice, consecutivo, xmlBase64);
35
- return (0, index_2.send)(token, finalMesage).catch((err) => {
36
- const response = err.response || {};
37
- const header = response.headers || {};
38
- const data = response.data = {};
39
- console.log('status', response.status);
40
- console.log('data', data);
41
- console.log('x-error-cause', header['x-error-cause']);
42
- });
43
- });
44
- //# sourceMappingURL=confirmXML.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"confirmXML.js","sourceRoot":"","sources":["../../src/confirmXML.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,6CAAkD;AAClD,8CAAsE;AACtE,iDAA+C;AAC/C,yDAAwE;AAExE,SAAS,iBAAiB,CAAC,IAAS;IAClC,OAAO,IAAA,yBAAc,EAAC;QACpB,QAAQ,EAAE,IAAI,CAAC,WAAW,CAAC,QAAQ;QACnC,QAAQ,EAAE,IAAI,CAAC,WAAW,CAAC,QAAQ;QACnC,UAAU,EAAE,IAAI,CAAC,UAAU;QAC3B,WAAW,EAAE,IAAI,CAAC,WAAW,CAAC,WAAW;KAC1C,CAAC,CAAA;AACJ,CAAC;AAED,kBAAe,CAAO,IAMrB,EAAgB,EAAE;IACjB,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,IAAI,CAAA;IAC1C,MAAM,WAAW,GAAG,iBAAiB,CAAC,IAAI,CAAC,CAAA;IAC3C,MAAM,WAAW,GAAG,IAAA,8BAAsB,EAAC,IAAI,CAAC,MAAM,CAAC,CAAA;IACvD,MAAM,MAAM,GAAG,IAAA,sBAAS,EAAC,EAAE,WAAW,EAAE,WAAW,EAAE,UAAU,EAAE,CAAC,CAAA;IAClE,MAAM,SAAS,GAAG,MAAM,IAAA,cAAM,EAAC,UAAU,EAAE,MAAM,EAAE;QACjD,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,QAAQ,EAAE,MAAM,CAAC,QAAQ;QACzB,MAAM,EAAE,IAAI;KACb,CAAC,CAAA;IACF,MAAM,WAAW,GAAG,IAAA,4BAAe,EAAC,WAAW,EAAE,WAAW,EAAE,SAAS,CAAC,CAAA;IACxE,OAAO,IAAA,YAAI,EAAC,KAAK,EAAE,WAAW,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;QAC5C,MAAM,QAAQ,GAAG,GAAG,CAAC,QAAQ,IAAI,EAAE,CAAA;QACnC,MAAM,MAAM,GAAG,QAAQ,CAAC,OAAO,IAAI,EAAE,CAAA;QACrC,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,GAAG,EAAE,CAAA;QAC/B,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAA;QACtC,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;QACzB,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE,MAAM,CAAC,eAAe,CAAC,CAAC,CAAA;IACvD,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA,CAAA"}