Skip to content

KBZ Pay ​

KBZ Pay is KBZ Bank's mobile wallet: customers pay in the KBZ Pay PWA, by scanning a QR code, or from your mobile app.

CallWhat it doesReturns
await kbz.pwa(data)Redirect to the KBZ Pay PWARedirectPayment
await kbz.qr(data)Customer scans a QRQrPayment
await kbz.app(data)Your mobile app opens the KBZ Pay SDKAppPayment
await kbz.status(orderId)Query an orderPaymentStatusResult
kbz.handleCallback(request)Verify the notificationPaymentCallback

Responses shows what KBZ Pay puts in each result.

How it works ​

Every KBZ Pay flow starts with the same precreate call and ends with KBZ's signed notification.

KBZ Pay: precreate, pay, notifyCustomerYour appKBZ PayPick the flowkbz.pwa() / qr() / app()Precreate the orderPWAAPP / PAY_BY_QRCODE / APPprepay_idplus qrCode for QRPWA URL, QR or signed orderurl / qrString / orderInfo + signPay in the KBZ Pay appNotify callbackUrlsigned JSON under RequestVerified callback is proofkbz.handleCallback(request)Plain-text successwithin about 10 s, or KBZ retriesNo notify? Query the orderawait kbz.status(orderId)
KBZ Pay: precreate, pay, notify

Initiating a Payment ​

ts
import {
  KbzPay,
  type KbzPayPaymentData,
} from '@laranex/myanmar-payments/kbz-pay';

const kbz = new KbzPay({
  appId: '...',
  appKey: '...',
  merchantCode: '...',
  timeoutSeconds: 30,
});

const data: KbzPayPaymentData = {
  orderId: `ORDER_${order.id}`,
  amount: 10000,
  callbackUrl: 'https://shop.test/payments/kbz/callback',
};

// PWA: send the customer to the KBZ Pay PWA
const redirect = await kbz.pwa(data);
res.writeHead(302, { Location: redirect.url }).end();

// QR: encode qr.qrString into a QR image
const qr = await kbz.qr(data);

// In-app: hand the signed values to your mobile app
const app = await kbz.app(data);
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify(app));

KbzPayPaymentData ​

FieldTypeRequiredRules
orderIdstringYesUnique per order. Letters, digits and _ only, at most 40 characters
amountAmount | number | bigintYesKyat, greater than 0, at most 2 decimal places, e.g. 10000 or Amount.parse('1000.50'). KBZ only accepts MMK
callbackUrlstringYesPublic URL KBZ posts the result to. Absolute http or https URL, at most 512 characters, no query string
titlestringNoProduct name shown to the customer
timeoutMinutesnumberNoAn integer from 1 to 120. Unset leaves it to KBZ (120)
callbackInfostringNoFree text echoed back in the callback, at most 512 characters once URL-encoded

PWA Notes ​

  • The PWA only opens on a phone with the KBZ Pay app installed.
  • KBZ checks the redirect's Referer against the URL registered with them (error AOP08512). Redirect from that domain and don't strip the referrer.
  • After payment, KBZ sends the customer to the return URL registered with them during onboarding; it cannot be set per payment.

Handling Callbacks ​

KBZ Pay posts JSON nested under a Request key; build the CallbackRequest from the whole request.

ts
import { CallbackRequest } from '@laranex/myanmar-payments';

// POST /payments/kbz/callback
try {
  const request = await CallbackRequest.fromNodeRequest(req);
  const callback = kbz.handleCallback(request);

  if (callback.isSuccessful()) {
    // callback.orderId is your merch_order_id
    // callback.gatewayReference is KBZ's mm_order_id
  }

  callback.acknowledgement.send(res); // plain-text "success"
} catch {
  res.writeHead(400).end('invalid callback');
}

KBZ requires an HTTP 200 with the plain-text body success, answered within about 10 seconds. Otherwise it retries after 60 and 600 seconds; when no callback arrives, query the order.

Status Checks ​

ts
const result = await kbz.status(`ORDER_${order.id}`);

if (result.isSuccessful()) {
  // result.gatewayReference is KBZ's mm_order_id
}

status() takes your orderId. An order KBZ doesn't know throws ApiError.

Responses ​

What KBZ Pay puts in each field. See Results and PaymentCallback & Status for the full classes. A field the gateway didn't send is undefined. raw holds plain JavaScript values, with JSON numbers kept as their exact text in a string (1000.50 stays "1000.50").

pwa() → RedirectPayment ​

FieldKBZ Pay value
flow'redirect'
orderIdYour data.orderId
url{pwaUrl}?appid=…&merch_code=…&nonce_str=…&prepay_id=…&timestamp=…&sign=…
gatewayReferenceKBZ prepay_id. Always set
rawThe precreate response: result, code, msg, merch_order_id, prepay_id, nonce_str, sign_type, sign

qr() → QrPayment ​

Field / MethodKBZ Pay value
flow'qr'
orderIdYour data.orderId
qrStringKBZ qrCode, a payload to encode into a QR image. Always set
qrImageAlways undefined
expiresAtNow + timeoutMinutes. undefined when timeoutMinutes is unset (KBZ then allows 120 minutes)
referenceKBZ prepay_id. Always set
rawThe precreate response, as for pwa() plus qrCode
qrImageDataUri()Always undefined, as qrImage is

app() → AppPayment ​

Field / MethodKBZ Pay value
flow'app'
orderIdYour data.orderId
orderInfoappid=…&merch_code=…&nonce_str=…&prepay_id=…&timestamp=…
signSHA-256 signature of orderInfo, uppercase hex. See Signing
signTypeSHA256
rawThe precreate response, as for pwa()
toJSON()orderId, orderInfo, sign and signType, without raw

status() → PaymentStatusResult ​

FieldKBZ Pay value
orderIdKBZ merch_order_id, falling back to the orderId you passed. Always set
statustrade_status mapped, see Statuses
gatewayStatusKBZ trade_status, trimmed, e.g. PAY_SUCCESS
gatewayReferenceKBZ mm_order_id. undefined until KBZ has created the payment
amountKBZ total_amount, e.g. 10000
rawThe queryorder response: result, code, msg, merch_order_id, mm_order_id, total_amount, trans_currency, trade_status, trans_end_time, nonce_str, sign_type, sign

handleCallback() → PaymentCallback ​

FieldKBZ Pay value
orderIdKBZ merch_order_id (your orderId)
statustrade_status mapped, see Statuses
gatewayStatusKBZ trade_status, trimmed, e.g. PAY_SUCCESS
gatewayReferenceKBZ mm_order_id
amountKBZ total_amount, e.g. 10000
rawThe verified Request: appid, notify_time, merch_code, merch_order_id, mm_order_id, total_amount, trans_currency, trade_status, trans_end_time, callback_info, nonce_str, sign_type, sign
acknowledgementHTTP 200, body success, Content-Type: text/plain

Statuses ​

KBZ trade_statusPaymentStatus
PAY_SUCCESSsuccessful
WAIT_PAY, PAYINGpending
PAY_FAILEDfailed
ORDER_CLOSEDcanceled
ORDER_EXPIREDexpired
anything elseunknown

Signing ​

KBZ signs requests, the in-app orderInfo and notifications the same way: every non-empty field except sign and sign_type, sorted by key, joined as raw key=value pairs, with &key=<app key> appended, hashed with SHA-256 and uppercased. The package signs every request and verifies every notification for you; kbz.signer (a KbzPaySigner, also exported from @laranex/myanmar-payments/kbz-pay) exposes the same signature for custom calls: signString(fields), sign(fields) and verify(fields).

Errors ​

CallThrowsWhen
pwa(), qr(), app()InvalidPaymentDataErrorKbzPay.validate(data) fails. Nothing is sent
pwa(), qr(), app()ApiErrorKBZ answers with an HTTP error, result other than SUCCESS or code other than 0, or without a prepay_id
qr()ApiErrorKBZ returns no qrCode
status()ApiErrorKBZ answers with an HTTP error, result other than SUCCESS or code other than 0, e.g. for an unknown order
handleCallback()SignatureVerificationErrorsign doesn't match, or a field holds an object or array

The async calls reject with these errors. ApiError carries KBZ's code (e.g. ORDER_ID_USED, AOP08508) in gatewayCode and its msg in gatewayMessage. When KBZ can't be reached, the request times out or the signal aborts, the calls throw ApiError with the original error as cause.

Released under the MIT License, except where a package says otherwise.