UNPKG

@facturacr/atv-sdk

Version:

Librería (SDK) de Javascript/NodeJS para acceder al API de Administración Tributaria Virtual (ATV) del Ministerio de Hacienda.

44 lines 2.22 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const genClave_1 = require("./lib/genClave"); const index_1 = require("./lib/genXML/index"); const index_2 = require("./services/send/index"); const confirmXML_1 = require("./lib/genJSON/confirmXML"); function getConsecutivoStr(opts) { return (0, genClave_1.consecutivoStr)({ sucursal: opts.consecutivo.sucursal, terminal: opts.consecutivo.terminal, tipoDocKey: opts.tipoDocKey, consecutivo: opts.consecutivo.consecutivo }); } exports.default = (opts) => __awaiter(void 0, void 0, void 0, function* () { const { token, pemOpt, tipoDocKey } = opts; const consecutivo = getConsecutivoStr(opts); const fullInvoice = (0, index_1.parseElectronicBillXML)(opts.xmlStr); const msjObj = (0, confirmXML_1.getMsjObj)({ fullInvoice, consecutivo, tipoDocKey }); const xmlBase64 = yield (0, index_1.genXML)(tipoDocKey, msjObj, { buffer: pemOpt.buffer, password: pemOpt.password, base64: true }); const finalMesage = (0, confirmXML_1.getFinalMessage)(fullInvoice, consecutivo, xmlBase64); return (0, index_2.send)(token, finalMesage).catch((err) => { const response = err.response || {}; const header = response.headers || {}; const data = response.data = {}; console.log('status', response.status); console.log('data', data); console.log('x-error-cause', header['x-error-cause']); }); }); //# sourceMappingURL=confirmXML.js.map