np-payment-sdk
Version:
Unified Payment SDK for Nepal (eSewa, Khalti, ConnectIPS, IME Pay, Mobile Banking)
79 lines (78 loc) • 2.89 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.EsewaGateway = void 0;
const types_1 = require("../types");
class EsewaGateway {
constructor(config) {
this.config = config;
this.baseUrl = config.baseUrl || 'https://uat.esewa.com.np'; // Use sandbox by default
}
async pay(params) {
try {
// Example: eSewa payment initiation (mocked structure)
const payload = {
amt: params.amount,
psc: 0,
pdc: 0,
txAmt: 0,
tAmt: params.amount,
pid: params.transactionId || 'demo-tx',
scd: this.config.clientId,
su: params.returnUrl,
fu: params.failUrl || params.returnUrl,
};
// In real integration, use axios.post to eSewa endpoint
// const response = await axios.post(`${this.baseUrl}/epay/main`, payload);
// For now, mock response
return {
gateway: 'esewa',
status: 'success',
params: payload,
message: 'Payment initiated (mock)'
};
}
catch (err) {
if (err instanceof Error) {
throw new types_1.PaymentError(err.message || 'eSewa payment failed', 'ESEWA_PAYMENT_ERROR');
}
throw new types_1.PaymentError('eSewa payment failed', 'ESEWA_PAYMENT_ERROR');
}
}
async verify(params) {
try {
// Example: eSewa verification (mocked structure)
// const response = await axios.post(`${this.baseUrl}/epay/transrec`, { ... });
return {
gateway: 'esewa',
status: 'success',
params,
message: 'Payment verified (mock)'
};
}
catch (err) {
if (err instanceof Error) {
throw new types_1.PaymentError(err.message || 'eSewa verification failed', 'ESEWA_VERIFY_ERROR');
}
throw new types_1.PaymentError('eSewa verification failed', 'ESEWA_VERIFY_ERROR');
}
}
async refund(params) {
try {
// Example: eSewa refund (mocked structure)
// const response = await axios.post(`${this.baseUrl}/epay/refund`, { ... });
return {
gateway: 'esewa',
status: 'success',
params,
message: 'Refund processed (mock)'
};
}
catch (err) {
if (err instanceof Error) {
throw new types_1.PaymentError(err.message || 'eSewa refund failed', 'ESEWA_REFUND_ERROR');
}
throw new types_1.PaymentError('eSewa refund failed', 'ESEWA_REFUND_ERROR');
}
}
}
exports.EsewaGateway = EsewaGateway;