Codxplore.com

Latest news:

Sahih al-Bukhari (সহীহ বুখারী) is a free Hadith application for android. This application is advertisement free. Download now https://play.google.com/store/apps/details?id=com.akramhossin.bukharisharif

implement hesabe payment gateway in Nodejs using Typescript


implement hesabe payment gateway in Nodejs using Typescript

implement hesabe payment gateway in Nodejs using Typescript

in this blog post i will try explain how to implement hesabe payment gatway in Nodejs using Typescript.

At first we will install two npm package hesabe-crypt-ts and aes-js.

to install this two packages run the following command

npm i -S hesabe-crypt-ts then

npm i aes-js

we have to import this two package on our typescript file as below

import { HesabeCrypt } from "hesabe-crypt-ts/lib"

import aesjs from "aes-js";

from my github repository download the https://github.com/akramrana/hesabe-payment-helper/blob/main/HesabeHelper.ts file and

make following changes

1.change iv key

2.change encryption key

3.change success url

4.change error url

5.change response url

6.change access code

now import this HesabeHelper.ts file any of your class file for example 

import { HesabeHelper } from "../helpers/HesabeHelper";

constructor(){   

     public hesabeHelper: HesabeHelper,

}

for making payment, call the payment function of HesabeHelper like below

let payment: any = await this.hesabeHelper.payment(200, '10005552', 'src_card');

now console.log(payment) object

hesabe payment URL will be visible in your console. now proceed with that your and complete the payment

upon payment, hesabe will redirect you to your provided response url. 

to process that request made by hesabe server use below code snippet to your route or controller file 

@Get('/response')
@OnUndefined(302)
async hesabeResponse(
    @Req() request: any,
    @Res() response: any,
): Promise {
    const hisabeResponseEnc: any = request.query.data;
    if (hisabeResponseEnc) {
        const ivKey = "hesabe iv Key";
        const encryptionKey = "hesabe encryption Key";
        let key = aesjs.utils.utf8.toBytes(encryptionKey);
        let iv = aesjs.utils.utf8.toBytes(ivKey);
        let instance = new HesabeCrypt();
        let jsonData = instance.decryptAes(hisabeResponseEnc, key, iv);
        let responseData = JSON.parse(jsonData);
        console.log(responseData);
        //todo code as per need
        return response.redirect(302, '/hesabe/success');
    }else{
        return response.redirect(302, '/hesabe/error');
    }
}

@Get('/success')
async hesabeSuccess(@Req() request: any, @Res() response: any): Promise {
    let apiResponse = request.query;
    return response.status(200).send(apiResponse);
}

@Get('/error')
async hesabeError(@Req() request: any, @Res() response: any): Promise {
    let apiResponse = request.query;
    return response.status(200).send(apiResponse);
}

we are done!


Views : 470

Subscribe Us


Follow Us