upay-pg-by-kayesfahim
Version:
A Node.js SDK for interacting with the Upay payment system.
56 lines (48 loc) • 1.27 kB
JavaScript
const axios = require('axios');
class Upay {
constructor(baseUrl) {
this.baseUrl = baseUrl || 'https://uat-pg.upay.systems/payment';
}
// Auth method
async auth(merchantId, merchantKey) {
const data = JSON.stringify({
merchant_id: merchantId,
merchant_key: merchantKey,
});
const config = {
method: 'post',
maxBodyLength: Infinity,
url: `${this.baseUrl}/merchant-auth`,
headers: {
'Content-Type': 'application/json'
},
data: data,
};
try {
const response = await axios.request(config);
return response.data;
} catch (error) {
throw error.response ? error.response.data : error.message;
}
}
// Initiate payment method
async initiatePayment(paymentDetails) {
const config = {
method: 'post',
maxBodyLength: Infinity,
url: `${this.baseUrl}/initiate-payment`,
headers: {
'Content-Type': 'application/json',
Cookie: this.defaultCookie,
},
data: JSON.stringify(paymentDetails),
};
try {
const response = await axios.request(config);
return response.data;
} catch (error) {
throw error.response ? error.response.data : error.message;
}
}
}
module.exports = Upay;