@muhammedaksam/sipay-node
Version:
Node.js TypeScript SDK for Sipay payment gateway
87 lines • 3.35 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Payments = void 0;
const base_1 = require("./base");
const utils_1 = require("../utils");
class Payments extends base_1.SipayResource {
/**
* Make a 2D payment (without 3D Secure authentication)
*/
async pay2D(paymentData, options) {
const data = this.addMerchantKey(paymentData);
// Generate hash key for payment verification
const hashKey = (0, utils_1.generatePaymentHashKey)(data.total, data.installments_number || 1, data.currency_code, this.client['config'].merchantKey, data.invoice_id, this.client['config'].appSecret);
data.hash_key = hashKey;
return this.post('/api/paySmart2D', data, options);
}
/**
* Process a 3D payment (with 3D Secure authentication)
* Returns HTML form that should be rendered and auto-submitted
*/
async pay3D(paymentData, options) {
const data = this.addMerchantKey(paymentData);
return this.postForm('/api/paySmart3D', data, options);
}
/**
* Get POS information and installment options for a credit card
*/
async getPos(posData, options) {
const data = this.addMerchantKey({
...posData,
credit_card: posData.credit_card,
});
return this.post('/api/getpos', data, options);
}
/**
* Check the status of a payment
*/
async checkStatus(statusData, options) {
const data = this.addMerchantKey(statusData);
// Generate hash key for status check
const hashKey = (0, utils_1.generateStatusHashKey)(data.invoice_id, this.client['config'].merchantKey, this.client['config'].appSecret);
data.hash_key = hashKey;
return this.post('/api/checkstatus', data, options);
}
/**
* Confirm a pre-authorization payment
*/
async confirmPayment(confirmData, options) {
const data = this.addMerchantKey(confirmData);
// Generate hash key for payment confirmation
// Hash format: merchant_key|invoice_id|status
const hashKey = (0, utils_1.generateConfirmPaymentHashKey)(data.merchant_key, data.invoice_id, data.status, this.client['config'].appSecret);
data.hash_key = hashKey;
return this.post('/api/confirmPayment', data, options);
}
/**
* Refund a payment
*/
async refund(refundData, options) {
const data = this.addMerchantKey(refundData);
return this.post('/api/refund', data, options);
}
/**
* Get merchant active installments
* Note: This endpoint uses Bearer token authentication
*/
async getInstallments(options) {
// This endpoint doesn't require request body, only headers with Bearer token
return this.post('/api/installments', {}, options);
}
/**
* Get authentication token
* Used for Bearer token authentication in certain endpoints
*/
async getToken(tokenData, options) {
return this.post('/api/token', tokenData, options);
}
/**
* Legacy 2D payment method (maintains compatibility)
*/
async pay(paymentData, options) {
const data = this.addMerchantKey(paymentData);
return this.post('/api/pay', data, options);
}
}
exports.Payments = Payments;
//# sourceMappingURL=payments.js.map