Payment Flows
Starting a payment always follows the same pattern: build the gateway's payment data, call the gateway, then act on the typed result. Each flow has its own result class with exactly the fields that flow needs, and every result implements PaymentResult, whose flow() returns a PaymentFlow (Redirect, Form, Qr, App or MiniApp), so a match or instanceof check tells them apart.
| Result | What you do | Returned by |
|---|---|---|
RedirectPayment | Redirect the customer to $payment->url | $kbz->pwa(), $wave->initiate() |
FormPayment | Echo $payment->toHtml() | $aya->initiate(), $cs->hostedCheckout() |
QrPayment | Show the QR to the customer | $kbz->qr(), $yoma->initiate(), $yoma->renewQr() |
AppPayment | Return the signed payload to your mobile app | $kbz->app() |
MiniAppPayment | Return the signed payload to your mini app page | $wavePayMiniApp->payment() |
Every payment data class validates its values when you create it and throws InvalidPaymentDataException before any request is sent. $data->validate() runs the same checks again. Callback, return and cancel URLs must be absolute http or https URLs by PHP's FILTER_VALIDATE_URL rules, the same in every Laranex SDK: printable ASCII only, an ASCII host name (labels of letters, digits and inner -, at most 63 characters each) or a bracketed IPv6 address, and an optional port from 0 to 65535; anything else fails with The callbackUrl field must be a valid http or https URL. The customer finishing on the gateway's side is never proof of payment: fulfill orders from the verified callback or a status check.
The samples on this page and the gateway pages are plain PHP scripts; Framework Integration shows Symfony and PSR-15 handlers.
Redirect Payments
Here is the flow with the KBZ Pay PWA; Wave Pay works the same way with its own payment page.
The gateway hosts its own payment page. Send the customer there.
use Laranex\PhpMyanmarPayments\KbzPay\KbzPayPaymentData;
$data = new KbzPayPaymentData(
orderId: 'ORDER_1',
amount: 10000,
callbackUrl: 'https://shop.test/payments/kbz/callback',
);
$payment = $kbz->pwa($data);
header('Location: '.$payment->url);
exit;$payment->gatewayReference holds the gateway's ID for the attempt (KBZ prepay_id, Wave transaction_id).
Form Payments
Here is the flow with AYA Pay; CyberSource works the same way with its hosted checkout.
The gateway expects the customer's browser to POST a signed form. toHtml() returns a complete page that submits the form as soon as it loads, with every value escaped:
// no network call: it only signs
$payment = $aya->initiate($data);
header('Content-Type: text/html; charset=UTF-8');
echo $payment->toHtml();Under a Content-Security-Policy that allows scripts by nonce (script-src 'nonce-…'), pass the nonce so the inline script runs: $payment->toHtml($nonce) renders <script nonce="…">.
To build the form yourself, use action, fields (an array of name => value, in order) and enctype with your template engine, and escape every value:
<form id="payment-form" method="POST"
action="<?= htmlspecialchars($payment->action) ?>"
enctype="<?= htmlspecialchars($payment->enctype) ?>">
<?php foreach ($payment->fields as $name => $value): ?>
<input type="hidden"
name="<?= htmlspecialchars($name) ?>"
value="<?= htmlspecialchars($value) ?>">
<?php endforeach ?>
</form>Post the fields unchanged: they are signed. $payment->fields['merchOrderId'] looks up one value.
QR Payments
Here is the flow with Yoma MMQR, whose QR expires after 120 seconds; a KBZ Pay QR follows the same steps without renewals.
Gateways return QR codes in two shapes:
| Property | Gateway | Use it as |
|---|---|---|
qrString | KBZ Pay | A payload: encode it into a QR image with any QR library, e.g. endroid/qr-code |
qrImage | Yoma MMQR | A base64 image: display it as is, e.g. with qrImageDataUri() |
$payment = $yoma->initiate($data);
?>
<img src="<?= htmlspecialchars($payment->qrImageDataUri()) ?>"
alt="Scan to pay">
<p>Payable until <?= $payment->expiresAt?->format('H:i:s') ?></p>expiresAt is a DateTimeImmutable when the gateway limits how long the QR is payable (null otherwise), and reference holds the gateway's ID for the QR (Yoma refLabel, which status() takes; KBZ prepay_id).
App Payments
Here is the flow with the KBZ Pay mobile SDK.
The KBZ Pay mobile SDK needs a signed order string. AppPayment::toArray() returns the values with the SDK's names, so return it to your app as JSON; the app passes the values to KBZPay.startPay():
$payment = $kbz->app($data);
header('Content-Type: application/json');
// {"orderId", "orderInfo", "sign", "signType"}
echo json_encode($payment->toArray());The SDK's own result only means the payment screen closed; rely on the callback or $kbz->status().
Mini App Payments
Wave Pay Mini App runs your web page inside the WavePay app. payment() signs the object the page passes to Wave's JavaScript SDK; no request is sent. MiniAppPayment::toArray() (or toJson()) is exactly that object:
$payment = $wavePayMiniApp->payment($data);
header('Content-Type: application/json');
// {"amount", "miniAppID", "merchantRefID", "orderID", "callBackUrl", "hashValue", "items"}
echo $payment->toJson();The page calls WaveJsSDK.paymentModule.makePayment(payload) with it after logging in with your server's access token; the SDK's result is not proof of payment. See Wave Pay Mini App for the whole flow.
Handling Any Result
use Laranex\PhpMyanmarPayments\Results\AppPayment;
use Laranex\PhpMyanmarPayments\Results\FormPayment;
use Laranex\PhpMyanmarPayments\Results\MiniAppPayment;
use Laranex\PhpMyanmarPayments\Results\PaymentResult;
use Laranex\PhpMyanmarPayments\Results\QrPayment;
use Laranex\PhpMyanmarPayments\Results\RedirectPayment;
function respond(PaymentResult $payment): void
{
match (true) {
$payment instanceof RedirectPayment
=> header('Location: '.$payment->url),
$payment instanceof FormPayment => print $payment->toHtml(),
$payment instanceof QrPayment
=> print $payment->qrImageDataUri() ?? $payment->qrString,
$payment instanceof AppPayment
=> print json_encode($payment->toArray()),
$payment instanceof MiniAppPayment => print $payment->toJson(),
};
}See Results for every property.