The KapitalBank Payment Integration library is a Node.js module that facilitates seamless integration with KapitalBank's payment gateway. This library allows you to create orders, complete transactions, reverse transactions, and retrieve payment status and information with ease.
The KapitalBank Payment Integration library simplifies the integration of KapitalBank's payment gateway into Node.js applications. It provides methods to interact with the payment gateway, enabling the creation and management of payment orders.
Before using this library, ensure you have the following prerequisites:
- Node.js installed on your server or development environment.
- Valid KapitalBank merchant credentials.
- SSL certificate and private key files for secure communication.
To use the KapitalBank Payment Integration library in your Node.js project, you need to install it via npm. Open a terminal and run the following command:
npm install kapitalbank@latest
Import the KapitalBank
class and initialize it with the required parameters:
const KapitalBank = require('kapitalbank');
const kb = new KapitalBank({
merchantId: "YOUR_MERCHANT_ID",
approveUrl: "APPROVE_URL",
cancelUrl: "CANCEL_URL",
declineUrl: "DECLINE_URL",
liveMode: false,
certFilePath: "CERT_FILE_PATH",
keyFilePath: "KEY_FILE_PATH",
defaultLanguage: "EN",
currency: "944"
});
The KapitalBank
class can be configured by passing appropriate values to its constructor. The available configuration options are:
-
merchantId
: Your merchant ID. -
approveUrl
: The URL where successful payments will be redirected. -
cancelUrl
: The URL where canceled payments will be redirected. -
declineUrl
: The URL where declined payments will be redirected. -
liveMode
: Set totrue
for live mode,false
for test mode. -
certFilePath
: The path to your SSL certificate file. -
keyFilePath
: The path to your SSL key file. -
defaultLanguage
: The default language for orders (optional, defaults to 'EN'). -
currency
: The default currency for orders (optional, defaults to '944').
Ensure that you provide the correct values for your environment.
Use the createOrder
method to create a new payment order:
const amount = 100;
const description = "ORDER_DESCRIPTION";
const preAuth = false;
const orderResult = await kb.createOrder(amount, description, preAuth);
console.log(orderResult);
Response:
{
"success": true,
"data": {
"amount": 100,
"orderId": "ORDER_ID",
"sessionId": "SESSION_ID",
"description": "ORDER_DESCRIPTION",
"currency": 944,
"lang": "EN",
"paymentUrl": "https://tstpg.kapitalbank.az/index.jsp?ORDERID=ORDER_ID&SESSIONID=SESSION_ID",
"orderType": "ORDER_TYPE"
}
}
Complete a payment order using the completeOrder
method:
const orderId = "ORDER_ID"; // Replace with your order ID
const sessionId = "SESSION_ID"; // Replace with your session ID
const completionResult = await kb.completeOrder(orderId, sessionId, amount, description, lang);
console.log(completionResult);
Reverse a payment transaction with the reverseOrder
method:
const orderId = "ORDER_ID"; // Replace with your order ID
const sessionId = "SESSION_ID"; // Replace with your session ID
const reversalResult = await kb.reverseOrder(orderId, sessionId, description, lang);
console.log(reversalResult);
Response:
{
"success": true,
"data": {
"orderId": 662685,
"respCode": "",
"respMessage": ""
}
}
Retrieve the status of a payment order using the getOrderStatus
method:
const orderId = "ORDER_ID"; // Replace with your order ID
const sessionId = "SESSION_ID"; // Replace with your session ID
const status = await kb.getOrderStatus(orderId, sessionId, lang);
console.log(status);
Response:
{
"success": true,
"data": {
"orderId": "ORDER_ID",
"orderStatus": "ORDER_STATUS"
}
}
Obtain detailed information about a payment order with the getOrderInformation
method:
const orderId = "ORDER_ID"; // Replace with your order ID
const sessionId = "SESSION_ID"; // Replace with your session ID
const info = await kb.getOrderInformation(orderId, sessionId, lang);
console.log(info);
Response:
{
"success": true,
"data": {
"orderId": "ORDER_ID",
"orderStatus": "ORDER_STATUS",
"sessionId": "SESSION_ID",
"createDate": "2023-09-17T09:39:05.000Z",
"lastUpdateDate": null,
"payDate": null,
"amount": 100,
"currency": "944",
"orderLanguage": "EN",
"description": "ORDER_DESCRIPTION",
"approveUrl": "APPROVE_URL",
"cancelUrl": "CANCEL_URL",
"declineUrl": "DECLINE_URL",
"receipt": "",
"twoId": "",
"refundAmount": "",
"refundCurrency": null,
"refundDate": null,
"extSystemProcess": "0",
"orderType": "Purchase",
"orderSubType": "",
"fee": 0,
"TWODate": "",
"TWOTime": ""
}
}
This library is released under the MIT License. See the LICENSE file for details.
This library is not officially maintained or endorsed by KapitalBank. Use it at your own risk.