UNPKG

@ikarha/emecef

Version:

Node.js client library for interacting with the Benin e-MCF API for normalized invoicing

109 lines (108 loc) 4.46 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); const index_1 = require("../index"); const billing_1 = require("../types/billing"); const dotenv = __importStar(require("dotenv")); dotenv.config(); async function main() { // Les variables d'environnement EMECEF_BASE_URL et EMECEF_TOKEN doivent être définies const billingService = new index_1.BillingService(); const infoService = new index_1.InfoService(); try { // Récupérer les informations sur les e-MCF const emcfInfo = await infoService.getEmeCefInfo(); console.log('Info e-MCF:', emcfInfo); // Récupérer les groupes de taxation const taxGroups = await infoService.getTaxGroups(); console.log('Groupes de taxation:', taxGroups); // Récupérer les types de factures const invoiceTypes = await infoService.getInvoiceTypes(); console.log('Types de factures:', invoiceTypes); // Récupérer les types de paiement const paymentTypes = await infoService.getPaymentTypes(); console.log('Types de paiement:', paymentTypes); // Vérifier le statut de l'API const status = await billingService.getInvoiceStatus(); console.log('Statut de l\'API:', status); // Créer une facture const invoiceData = { ifu: '3200700067314', // Numéro d'identification fiscale de l'entreprise type: billing_1.InvoiceTypeEnum.FV, items: [ { name: 'Jus d\'orange', price: 1800, quantity: 2, taxGroup: billing_1.TaxGroupTypeEnum.B }, { name: 'Lait 1/1 EX', price: 450, quantity: 3, taxGroup: billing_1.TaxGroupTypeEnum.A } ], client: { contact: '0145661122', ifu: '9999900000002', // Numéro d'identification fiscale du client name: 'Nom du client', address: 'Rue d\'ananas 23' }, operator: { id: '', name: 'Jacques' }, payment: [ { name: billing_1.PaymentTypeEnum.ESPECES, amount: 4950 } ] }; const invoiceResponse = await billingService.createInvoice(invoiceData); console.log('Réponse facture:', invoiceResponse); // Finaliser la facture const finalizeResponse = await billingService.finalizeInvoice(invoiceResponse.uid, 'confirm'); console.log('Finalisation:', finalizeResponse); // Récupérer les détails de la facture const details = await billingService.getInvoiceDetails(invoiceResponse.uid); console.log('Détails facture:', details); } catch (error) { console.error('Erreur: ', error instanceof Error ? error.message : 'Erreur inconnue'); } } main().catch(console.error);