neppayments
Version:
A simple and easy-to-use package for integrating Nepali payment gateways (Khalti and eSewa) into your applications
94 lines (93 loc) • 4.07 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.PaymentEnvironment = exports.PaymentError = exports.PaymentErrorCode = exports.NormalizedPaymentStatus = exports.PaymentStatus = exports.PaymentGateway = void 0;
/**
* Supported payment gateways
*/
var PaymentGateway;
(function (PaymentGateway) {
PaymentGateway["KHALTI"] = "KHALTI";
PaymentGateway["ESEWA"] = "ESEWA";
})(PaymentGateway || (exports.PaymentGateway = PaymentGateway = {}));
/**
* Payment status
*/
var PaymentStatus;
(function (PaymentStatus) {
PaymentStatus["PENDING"] = "PENDING";
PaymentStatus["COMPLETED"] = "COMPLETED";
PaymentStatus["FAILED"] = "FAILED";
PaymentStatus["EXPIRED"] = "EXPIRED";
PaymentStatus["CANCELED"] = "CANCELED";
})(PaymentStatus || (exports.PaymentStatus = PaymentStatus = {}));
/**
* Payment status for internal use
* Normalized status across all payment gateways
*/
var NormalizedPaymentStatus;
(function (NormalizedPaymentStatus) {
NormalizedPaymentStatus["SUCCESS"] = "success";
NormalizedPaymentStatus["FAILED"] = "failed";
NormalizedPaymentStatus["PENDING"] = "pending";
NormalizedPaymentStatus["REFUNDED"] = "refunded";
NormalizedPaymentStatus["CANCELLED"] = "cancelled";
NormalizedPaymentStatus["EXPIRED"] = "expired";
NormalizedPaymentStatus["PARTIALLY_REFUNDED"] = "partially_refunded";
})(NormalizedPaymentStatus || (exports.NormalizedPaymentStatus = NormalizedPaymentStatus = {}));
/**
* Payment error codes
*/
var PaymentErrorCode;
(function (PaymentErrorCode) {
// Configuration errors
PaymentErrorCode["INVALID_CONFIG"] = "INVALID_CONFIG";
PaymentErrorCode["GATEWAY_NOT_CONFIGURED"] = "GATEWAY_NOT_CONFIGURED";
// Validation errors
PaymentErrorCode["VALIDATION_ERROR"] = "VALIDATION_ERROR";
PaymentErrorCode["INVALID_AMOUNT"] = "INVALID_AMOUNT";
PaymentErrorCode["INVALID_URL"] = "INVALID_URL";
PaymentErrorCode["INVALID_PAYMENT_ID"] = "INVALID_PAYMENT_ID";
PaymentErrorCode["INVALID_PARAMETER"] = "INVALID_PARAMETER";
// Authentication errors
PaymentErrorCode["AUTHENTICATION_ERROR"] = "AUTHENTICATION_ERROR";
PaymentErrorCode["INVALID_CREDENTIALS"] = "INVALID_CREDENTIALS";
PaymentErrorCode["TOKEN_EXPIRED"] = "TOKEN_EXPIRED";
// Payment errors
PaymentErrorCode["PAYMENT_FAILED"] = "PAYMENT_FAILED";
PaymentErrorCode["PAYMENT_EXPIRED"] = "PAYMENT_EXPIRED";
PaymentErrorCode["PAYMENT_CANCELED"] = "PAYMENT_CANCELED";
PaymentErrorCode["PAYMENT_ALREADY_COMPLETED"] = "PAYMENT_ALREADY_COMPLETED";
// Verification errors
PaymentErrorCode["VERIFICATION_FAILED"] = "VERIFICATION_FAILED";
PaymentErrorCode["VERIFICATION_TIMEOUT"] = "VERIFICATION_TIMEOUT";
// Gateway errors
PaymentErrorCode["GATEWAY_ERROR"] = "GATEWAY_ERROR";
PaymentErrorCode["GATEWAY_TIMEOUT"] = "GATEWAY_TIMEOUT";
PaymentErrorCode["GATEWAY_UNAVAILABLE"] = "GATEWAY_UNAVAILABLE";
// Network errors
PaymentErrorCode["NETWORK_ERROR"] = "NETWORK_ERROR";
PaymentErrorCode["REQUEST_TIMEOUT"] = "REQUEST_TIMEOUT";
// Unknown errors
PaymentErrorCode["UNKNOWN_ERROR"] = "UNKNOWN_ERROR";
// New errors
PaymentErrorCode["SIGNATURE_GENERATION_FAILED"] = "SIGNATURE_GENERATION_FAILED";
PaymentErrorCode["INVALID_PAYMENT_OPTIONS"] = "INVALID_PAYMENT_OPTIONS";
PaymentErrorCode["INVALID_RESPONSE"] = "INVALID_RESPONSE";
PaymentErrorCode["INVALID_VERIFICATION_OPTIONS"] = "INVALID_VERIFICATION_OPTIONS";
})(PaymentErrorCode || (exports.PaymentErrorCode = PaymentErrorCode = {}));
/**
* Custom error class for payment-related errors
*/
class PaymentError extends Error {
constructor(message, code) {
super(message);
this.code = code;
this.name = 'PaymentError';
}
}
exports.PaymentError = PaymentError;
var PaymentEnvironment;
(function (PaymentEnvironment) {
PaymentEnvironment["SANDBOX"] = "sandbox";
PaymentEnvironment["PRODUCTION"] = "production";
})(PaymentEnvironment || (exports.PaymentEnvironment = PaymentEnvironment = {}));