ss-sslcommerz
Version:
TypeScript-compatible SSLCommerz payment gateway wrapper for Node.js, NestJS, and Express.
63 lines (62 loc) • 3.29 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.SslCommerzPayment = void 0;
const fetch_1 = __importDefault(require("./fetch"));
const payment_init_data_process_1 = __importDefault(require("./payment-init-data-process"));
class SslCommerzPayment {
constructor(store_id, store_passwd, live = false) {
this.baseURL = `https://${live ? "securepay" : "sandbox"}.sslcommerz.com`;
this.initURL = this.baseURL + "/gwprocess/v4/api.php";
this.validationURL =
this.baseURL + "/validator/api/validationserverAPI.php?";
this.refundURL =
this.baseURL + "/validator/api/merchantTransIDvalidationAPI.php?";
this.refundQueryURL =
this.baseURL + "/validator/api/merchantTransIDvalidationAPI.php?";
this.transactionQueryBySessionIdURL =
this.baseURL + "/validator/api/merchantTransIDvalidationAPI.php?";
this.transactionQueryByTransactionIdURL =
this.baseURL + "/validator/api/merchantTransIDvalidationAPI.php?";
this.store_id = store_id;
this.store_passwd = store_passwd;
}
init(data, url = "", method = "POST") {
data.store_id = this.store_id;
data.store_passwd = this.store_passwd;
return (0, fetch_1.default)({
url: url || this.initURL,
method,
data: (0, payment_init_data_process_1.default)(data),
});
}
validate(data, url = "", method = "GET") {
const fullUrl = url ||
`${this.validationURL}val_id=${data.val_id}&store_id=${this.store_id}&store_passwd=${this.store_passwd}&v=1&format=json`;
return (0, fetch_1.default)({ url: fullUrl, method });
}
initiateRefund(data, url = "", method = "GET") {
const fullUrl = url ||
`${this.refundURL}refund_amount=${data.refund_amount}&refund_remarks=${data.refund_remarks}&bank_tran_id=${data.bank_tran_id}&refe_id=${data.refe_id}&store_id=${this.store_id}&store_passwd=${this.store_passwd}&v=1&format=json`;
return (0, fetch_1.default)({ url: fullUrl, method });
}
refundQuery(data, url = "", method = "GET") {
const fullUrl = url ||
`${this.refundQueryURL}refund_ref_id=${data.refund_ref_id}&store_id=${this.store_id}&store_passwd=${this.store_passwd}&v=1&format=json`;
return (0, fetch_1.default)({ url: fullUrl, method });
}
transactionQueryBySessionId(data, url = "", method = "GET") {
const fullUrl = url ||
`${this.transactionQueryBySessionIdURL}sessionkey=${data.sessionkey}&store_id=${this.store_id}&store_passwd=${this.store_passwd}&v=1&format=json`;
return (0, fetch_1.default)({ url: fullUrl, method });
}
transactionQueryByTransactionId(data, url = "", method = "GET") {
const fullUrl = url ||
`${this.transactionQueryByTransactionIdURL}tran_id=${data.tran_id}&store_id=${this.store_id}&store_passwd=${this.store_passwd}&v=1&format=json`;
return (0, fetch_1.default)({ url: fullUrl, method });
}
}
exports.SslCommerzPayment = SslCommerzPayment;
exports.default = SslCommerzPayment;