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
kbzPay()->pwa($data)Redirect to the KBZ Pay PWARedirectPayment
kbzPay()->qr($data)Customer scans a QRQrPayment
kbzPay()->app($data)Your mobile app opens the KBZ Pay SDKAppPayment
kbzPay()->status($orderId)Query an orderPaymentStatusResult
kbzPay()->handleCallback($request)Verify the notificationPaymentCallback

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 flowkbzPay()->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 proofkbzPay()->handleCallback($request)Plain-text successwithin about 10 s, or KBZ retriesNo notify? Query the orderkbzPay()->status($orderId)
KBZ Pay: precreate, pay, notify

Initiating a Payment ​

php
use Laranex\LaravelMyanmarPayments\Facades\MyanmarPayments;
use Laranex\PhpMyanmarPayments\KbzPay\KbzPayPaymentData;

$data = new KbzPayPaymentData(
    orderId: 'ORDER_'.$order->id,
    amount: 10000,
    callbackUrl: route('payments.kbz.callback'),
);

// PWA: send the customer to the KBZ Pay PWA
$payment = MyanmarPayments::kbzPay()->pwa($data);

return redirect()->away($payment->url);

// QR: encode $payment->qrString into a QR image
$payment = MyanmarPayments::kbzPay()->qr($data);

// In-app: hand the signed values to your mobile app
$payment = MyanmarPayments::kbzPay()->app($data);

return response()->json($payment->toArray());

KbzPayPaymentData ​

ParameterTypeRequiredRules
orderIdstringYesUnique per order. Letters, digits and _ only, at most 40 characters
amountAmount|intYesKyat, greater than 0, at most 2 decimal places, e.g. 10000 or Amount::parse('10000.50'). KBZ only accepts MMK
callbackUrlstringYesPublic URL KBZ posts the result to. At most 512 characters, no query string
title?stringNoProduct name shown to the customer
timeToLiveMinutes?intNoMinutes the customer has to pay, 1 to 120, sent as timeout_express (30 is sent as 30m). null uses the required KBZ_PAY_TIME_TO_LIVE_IN_MINUTES
callbackInfo?stringNoFree 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; pass the whole request.

php
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
use Laranex\LaravelMyanmarPayments\Facades\MyanmarPayments;
use Laranex\PhpMyanmarPayments\Exceptions\SignatureVerificationException;

Route::post('/payments/kbz/callback', function (Request $request) {
    try {
        $callback = MyanmarPayments::kbzPay()->handleCallback($request);
    } catch (SignatureVerificationException) {
        abort(400);
    }

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

    return MyanmarPayments::acknowledge($callback); // plain-text "success"
})->name('payments.kbz.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.

KBZ also asks you to check that the notification's total_amount matches the order in your system: compare the callback's amount with your stored order total before fulfilling.

Status Checks ​

php
use Laranex\LaravelMyanmarPayments\Facades\MyanmarPayments;

$result = MyanmarPayments::kbzPay()->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 ApiException.

Responses ​

What KBZ Pay puts in each property. See Results and PaymentCallback & Status for the full classes.

pwa() → RedirectPayment ​

PropertyKBZ Pay value
orderIdYour orderId
url{pwa_url}?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 ​

Property / MethodKBZ Pay value
orderIdYour orderId
qrStringKBZ qrCode, a payload to encode into a QR image. Always set
qrImageAlways null
expiresAtNow + the time to live: timeToLiveMinutes, else KBZ_PAY_TIME_TO_LIVE_IN_MINUTES. Always set, because the configured time to live is required
referenceKBZ prepay_id. Always set
rawThe precreate response, as for pwa() plus qrCode
qrImageDataUri()Always null, as qrImage is

app() → AppPayment ​

Property / MethodKBZ Pay value
orderIdYour 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()
toArray()orderId, orderInfo, sign and signType, without raw

status() → PaymentStatusResult ​

PropertyKBZ 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, set only when trade_status is PAY_SUCCESS; null otherwise
amountKBZ total_amount, e.g. 10000
rawThe queryorder response: result, code, msg, merch_order_id, mm_order_id, total_amount, trans_currency, trade_status, pay_success_time, refund_info, nonce_str, sign_type, sign

handleCallback() → PaymentCallback ​

Property / MethodKBZ 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. The SDK exposes the signer as kbzPay()->signer (a KbzPaySigner) for custom calls and test fixtures. Whitespace around a received sign is ignored, as KBZ's own examples show padded values.

Errors ​

CallThrowsWhen
new KbzPayPaymentData(...)InvalidPaymentDataExceptionA value breaks the rules above. Nothing is sent
pwa(), qr(), app()ApiExceptionKBZ answers with an HTTP error, result other than SUCCESS or code other than 0, or without a prepay_id
qr()ApiExceptionKBZ returns no qrCode
status()ApiExceptionKBZ answers with an HTTP error, result other than SUCCESS or code other than 0, e.g. for an unknown order
handleCallback()SignatureVerificationExceptionsign doesn't match, or a field holds an object or array

ApiException carries KBZ's code (e.g. ORDER_ID_USED, AOP08508) in gatewayCode and its msg in gatewayMessage.