Installation
Via npm
Requires Node.js 20+. No runtime dependencies: it sends the gateway requests with the global
fetchand signs withnode:crypto.
bash
npm install @laranex/myanmar-paymentsbash
pnpm add @laranex/myanmar-paymentsbash
yarn add @laranex/myanmar-paymentsFully typed; ships ES modules and CommonJS. Import from @laranex/myanmar-payments:
ts
// ES modules / TypeScript
import { Amount, CallbackRequest, KbzPay } from '@laranex/myanmar-payments';js
// CommonJS
const {
Amount,
CallbackRequest,
KbzPay,
} = require('@laranex/myanmar-payments');The root entry exports every public name. Each gateway also has its own subpath, which exports only that gateway's classes and types:
| Import path | Contents |
|---|---|
@laranex/myanmar-payments | Everything below, plus Amount, results, PaymentCallback, PaymentStatus, CallbackRequest, Acknowledgement, errors, HttpClient, FetchHttpClient, TokenCache, MemoryTokenCache and the MyanmarPayments facade |
@laranex/myanmar-payments/kbz-pay | KbzPay, KbzPayConfig, KbzPaySigner, KbzPayConfigOptions, KbzPayPaymentData |
@laranex/myanmar-payments/wave-pay | WavePay, WavePayConfig, WavePayConfigOptions, WavePayItem, WavePayPaymentData |
@laranex/myanmar-payments/wave-pay-mini-app | WavePayMiniApp, WavePayMiniAppConfig, WavePayMiniAppSigner, WavePayMiniAppConfigOptions, WavePayMiniAppItem, WavePayMiniAppOptions, WavePayMiniAppPaymentData |
@laranex/myanmar-payments/aya-pay | AyaPay, AyaPayConfig, AyaPayMethod, AyaPayService, AyaPayConfigOptions, AyaPayPaymentData |
@laranex/myanmar-payments/yoma-mmqr | YomaMmqr, YomaMmqrConfig, YomaMmqrConfigOptions, YomaMmqrOptions, YomaMmqrPaymentData |
@laranex/myanmar-payments/cyber-source | CyberSource, CyberSourceConfig, CyberSourceTransactionType, CyberSourceConfigOptions, CyberSourcePaymentData |
Quick Start
A node:http app that starts a KBZ Pay PWA payment and verifies the callback:
ts
import { createServer } from 'node:http';
import {
Amount,
CallbackRequest,
KbzPay,
SignatureVerificationError,
} from '@laranex/myanmar-payments';
// Throws a ConfigurationError naming the missing setting
const kbz = KbzPay.fromEnv(process.env);
createServer(async (req, res) => {
const url = new URL(req.url ?? '/', 'http://localhost');
if (req.method === 'GET' && url.pathname === '/checkout') {
const payment = await kbz.pwa({
orderId: 'ORDER_1',
amount: Amount.kyat(10000),
callbackUrl: 'https://shop.test/payments/kbz/callback',
});
res.writeHead(302, { Location: payment.url }).end();
return;
}
if (req.method === 'POST' && url.pathname === '/payments/kbz/callback') {
let callback;
try {
callback = kbz.handleCallback(
await CallbackRequest.fromNodeRequest(req),
);
} catch (error) {
if (!(error instanceof SignatureVerificationError)) throw error;
res.writeHead(400).end('invalid callback');
return;
}
if (callback.isSuccessful()) {
// compare callback.amount with your order,
// then fulfill callback.orderId
}
callback.acknowledgement.send(res); // KBZ Pay expects a plain "success"
return;
}
res.writeHead(404).end();
}).listen(8080);See Framework Integration for Express, Fastify, Next.js and Hono.
Using NestJS?
Install @laranex/nestjs-myanmar-payments instead. It wraps this package in a NestJS module with an injectable service, callback helpers for Express and Fastify and an auto-submit form route.