UNPKG

@ikarha/emecef

Version:

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

56 lines (55 loc) 1.94 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.BillingService = void 0; const axios_1 = __importDefault(require("axios")); const config_1 = require("./config"); const api_error_1 = require("../errors/api-error"); class BillingService { constructor() { const apiConfig = (0, config_1.getConfig)(); this.axiosInstance = axios_1.default.create({ baseURL: `${apiConfig.baseUrl}/invoice`, headers: apiConfig.headers }); } async getInvoiceStatus() { try { const response = await this.axiosInstance.get('/'); return api_error_1.EmecfApiError.checkSuccessResponse(response); } catch (error) { throw api_error_1.EmecfApiError.fromResponse(error); } } async createInvoice(data) { try { const response = await this.axiosInstance.post('/', data); return api_error_1.EmecfApiError.checkSuccessResponse(response); } catch (error) { throw api_error_1.EmecfApiError.fromResponse(error); } } async finalizeInvoice(uid, action) { try { const response = await this.axiosInstance.put(`/${uid}/${action}`); return api_error_1.EmecfApiError.checkSuccessResponse(response); } catch (error) { throw api_error_1.EmecfApiError.fromResponse(error); } } async getInvoiceDetails(uid) { try { const response = await this.axiosInstance.get(`/${uid}`); return api_error_1.EmecfApiError.checkSuccessResponse(response); } catch (error) { throw api_error_1.EmecfApiError.fromResponse(error); } } } exports.BillingService = BillingService;