bakong-khqr
v1.0.17
Published
KHQR javascript SDK
Downloads
1,000
Readme
KHQR (Khmer QRCode)
KHQR is the centralized QRCode for Cambodia, where every mobile banking app in Cambodia can scan and pay. KHQR ~ Scan.Pay.Done.
Changelog
- decode caching
Installation
Run unit test
npm run test
NPM
npm install bakong-khqr
Raw Script
Link the script src to html
<script src="https://github.com/davidhuotkeo/bakong-khqr/releases/download/bakong-khqr-1.0.6/khqr-1.0.6.min.js"></script>
Usage
NPM
const {BakongKHQR, khqrData, IndividualInfo, MerchantInfo, SourceInfo} = require("bakong-khqr");
or
import {BakongKHQR, khqrData, IndividualInfo, MerchantInfo, SourceInfo} from "bakong-khqr";
Raw Script
In your script file/tag
var {BakongKHQR, khqrData, IndividualInfo, MerchantInfo, SourceInfo} = BakongKHQR;
How to use KHQR Javascript Library?
Generate KHQRCode
There are 2 way of generating KHQR: Individual and Merchant
Merchant KHQR
const {BakongKHQR, khqrData} = require("bakong-khqr");
const optionalData = {
currency: khqrData.currency.khr,
amount: 100000,
billNumber: "#0001",
mobileNumber: "85587575857",
storeLabel: "Devit Huotkeo",
terminalLabel: "Devit I",
};
const merchantInfo = new MerchantInfo(
"devit@abaa",
"devit",
"Battambang",
1243546472,
"DEVBKKHPXXX",
optionalData
);
const khqr = new BakongKHQR();
const response = khqr.generateIndividual(merchantInfo);
console.log(response);
Individual KHQR
const {BakongKHQR, khqrData} = require("bakong-khqr");
const optionalData = {
currency: khqrData.currency.khr,
amount: 100000,
billNumber: "#0001",
mobileNumber: "85587575857",
storeLabel: "Devit Huotkeo",
terminalLabel: "Devit I",
};
const individualInfo = new IndividualInfo(
"devit@abaa",
khqrData.currency.khr,
"devit",
"Battambang",
optionalData
);
const khqr = new BakongKHQR();
const response = khqr.generateIndividual(individualInfo);
console.log(response);
Verify KHQR
const {BakongKHQR} = require("bakong-khqr");
const KHQRString =
"00020101021230190015john_smith@devb5204599953038405405500.05802KH5910John Smith6010Phnom Penh62640111Invoice#0690314Coffee Khlaing0727Cooooooooooooooooooounter 299170013161406568381963040F76";
const isKHQR = BakongKHQR.verify(KHQRString).isValid;
console.log(isKHQR);
Decode
const {BakongKHQR, khqrData} = require("bakong-khqr");
const KHQRString =
"00020101021230190015john_smith@devb5204599953038405405500.05802KH5910John Smith6010Phnom Penh62640111Invoice#0690314Coffee Khlaing0727Cooooooooooooooooooounter 299170013161406568381963040F76";
const decodeResult = BakongKHQR.decode(KHQRString);
console.log(decodeResult);
Deeplink
const {BakongKHQR, khqrData, SourceInfo} = require("bakong-khqr");
const khqr = new BakongKHQR();
// Source Info is optional but if you include it
// all fields appIconUrl, appName, appDeepLinkCallback must not be null
const sourceInfo = new SourceInfo(yourAppIconUrl, yourAppName, yourAppDeepLinkCallback);
const url = "generate deep link url provided by us";
const KHQRString =
"00020101021230190015john_smith@devb5204599953038405405500.05802KH5910John Smith6010Phnom Penh62640111Invoice#0690314Coffee Khlaing0727Cooooooooooooooooooounter 299170013161406568381963040F76";
const deepLinkURL = khqr.generateDeepLink(url, KHQRString, sourceInfo);
deepLinkURL.then(url => console.log(url))
Check bakong account ID
const {BakongKHQR} = require("bakong-khqr");
BakongKHQR.checkBakongAccount(
"open API URL",
"dave@devb"
).then((data) => console.log(data));