Giter Club home page Giter Club logo

kapitalbank's Introduction

KapitalBank Payment API with Node.js

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.

Table of Contents

  1. Introduction
  2. Prerequisites
  3. Installation
  4. Usage
  5. License
  6. Disclaimer

Introduction

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.

Prerequisites

Before using this library, ensure you have the following prerequisites:

  1. Node.js installed on your server or development environment.
  2. Valid KapitalBank merchant credentials.
  3. SSL certificate and private key files for secure communication.

Installation

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

Usage

Initialize

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"
});

Configuration parameters

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 to true 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.

Create an Order

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 an Order

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 Transaction

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": ""
  }
}

Get Order Status

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"
   }
}

Get Order Information

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": ""
   }
}

License

This library is released under the MIT License. See the LICENSE file for details.

Disclaimer

This library is not officially maintained or endorsed by KapitalBank. Use it at your own risk.

kapitalbank's People

Contributors

eyvazoff avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.