TypeScript
Integrate Hesabe Payment Gateway into your TypeScript application. Type-safe encryption library with comprehensive AES encryption and decryption capabilities for secure payment processing.
Quick Start
Before you begin, ensure you have the necessary encryption library installed for AES functions:
NPM Installation
You can install the encryption library for TypeScript using npm:
npm i -S hesabe-crypt-tsImport HesabeCrypt Class
After installing the library, import the Hesabe Crypt class:
import { HesabeCrypt } from "hesabe-crypt-ts/lib";Import AES-JS
import aesjs from "aes-js";Setup Keys
You need to have a secret and an IV code. Convert your secret and IV to bytes:
const secret = 'XXXXX'; // Secret key provided by Hesabe
const ivCode = 'XXXXX'; // IV key provided by Hesabe
const key = aesjs.utils.utf8.toBytes(secret);
const iv = aesjs.utils.utf8.toBytes(ivCode);Initialize Instance
Initialize an instance of the hesabeCrypt class:
const instance = new HesabeCrypt();Padding fix for the npm package
hesabe-crypt-ts (up to 1.0.8) strips the decryption padding incorrectly: it cuts the text at the first character that matches the pad byte, which truncates many real responses. Until a fixed version is published, override its pkcs5Strip with this corrected one:
// Strips exactly the pad length and checks every pad byte
instance.pkcs5Strip = (txt: String): string => {
const pad = txt.charCodeAt(txt.length - 1);
if (pad < 1 || pad > 32 || pad > txt.length) throw new Error('Invalid padding');
for (let i = txt.length - pad; i < txt.length; i++) {
if (txt.charCodeAt(i) !== pad) throw new Error('Invalid padding');
}
return txt.slice(0, txt.length - pad);
};Use Encryption/Decryption
Now you can call the methods of hesabeCrypt for encryption and decryption:
const text = 'XXXXX'; // Any data to encrypt
const encrypted = instance.encryptAes(text, key, iv);
const decrypted = instance.decryptAes(encrypted, key, iv);Download Kit
| React Example Kit | Download Link |
|---|---|
| Complete TypeScript integration kit with React examples | Click here |
JavaScript
Integrate Hesabe Payment Gateway into your web applications using JavaScript. Complete encryption library with easy-to-use functions for secure payment processing.
.NET Core
Integrate Hesabe Payment Gateway into your .NET Core application. Complete encryption, API helpers, and comprehensive payment processing capabilities.