UNPKG

neppayments

Version:

A simple and easy-to-use package for integrating Nepali payment gateways (Khalti and eSewa) into your applications

85 lines (84 loc) 3.44 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 __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.EsewaGateway = exports.KhaltiGateway = exports.PaymentError = exports.NepPayments = void 0; // index.ts const khalti_1 = require("./gateways/khalti"); const esewa_1 = require("./gateways/esewa"); const payment_enums_1 = require("./types/payment.enums"); /** * Main class for handling Nepali payment gateways */ class NepPayments { /** * Create a new NepPayments instance * @param config Configuration for payment gateways */ constructor(config) { if (config.khalti) { this.khalti = new khalti_1.KhaltiGateway(config.khalti); } if (config.esewa) { this.esewa = new esewa_1.EsewaGateway(config.esewa); } // Check if at least one gateway is configured if (!this.khalti && !this.esewa) { throw new payment_enums_1.PaymentError('At least one payment gateway must be configured', payment_enums_1.PaymentErrorCode.GATEWAY_NOT_CONFIGURED); } } /** * Get the configured Khalti gateway * @throws {PaymentError} If Khalti is not configured */ get khaltiGateway() { if (!this.khalti) { throw new payment_enums_1.PaymentError('Khalti gateway is not configured', payment_enums_1.PaymentErrorCode.GATEWAY_NOT_CONFIGURED); } return this.khalti; } /** * Get the configured eSewa gateway * @throws {PaymentError} If eSewa is not configured */ get esewaGateway() { if (!this.esewa) { throw new payment_enums_1.PaymentError('eSewa gateway is not configured', payment_enums_1.PaymentErrorCode.GATEWAY_NOT_CONFIGURED); } return this.esewa; } /** * Get list of configured gateways */ get configuredGateways() { const gateways = []; if (this.khalti) gateways.push('khalti'); if (this.esewa) gateways.push('esewa'); return gateways; } } exports.NepPayments = NepPayments; // Export types __exportStar(require("./types/payment.types"), exports); __exportStar(require("./types/payment.enums"), exports); var payment_enums_2 = require("./types/payment.enums"); Object.defineProperty(exports, "PaymentError", { enumerable: true, get: function () { return payment_enums_2.PaymentError; } }); // Export individual gateways for direct use if needed var khalti_2 = require("./gateways/khalti"); Object.defineProperty(exports, "KhaltiGateway", { enumerable: true, get: function () { return khalti_2.KhaltiGateway; } }); var esewa_2 = require("./gateways/esewa"); Object.defineProperty(exports, "EsewaGateway", { enumerable: true, get: function () { return esewa_2.EsewaGateway; } });