Callbacks & Status
Every gateway notifies your server of the payment result. handleCallback() verifies the gateway's signature and returns a PaymentCallback. Pass it the Laravel request as is: signatures are checked against the exact body the gateway sent. Wave Pay Mini App also checks the request's own URL, the callback URL its payment was signed with.
Production setup
For production, follow Handling Webhooks; this example handles everything inline.
Every callback goes through the same steps; KBZ Pay is shown here.
use Illuminate\Http\Request;
use Laranex\LaravelMyanmarPayments\Facades\MyanmarPayments;
use Laranex\PhpMyanmarPayments\Amount;
use Laranex\PhpMyanmarPayments\Exceptions\SignatureVerificationException;
Route::post('/payments/kbz/callback', function (Request $request) {
try {
$callback = MyanmarPayments::kbzPay()->handleCallback($request);
} catch (SignatureVerificationException) {
abort(400);
}
$order = Order::where('reference', $callback->orderId)->firstOrFail();
// $order->amount is a string such as "10000"; compare by value, not floats
$paid = Amount::parse($order->amount)->equals($callback->amount);
if ($callback->isSuccessful() && ! $order->isPaid() && $paid) {
$order->markAsPaid($callback->gatewayReference);
}
return MyanmarPayments::acknowledge($callback);
})->name('payments.kbz.callback');Gateways post from their own servers, so exclude callback routes from CSRF verification. A body over 64 KiB (CallbackRequestFactory::MAX_CALLBACK_BODY_BYTES, 65536 bytes, checked by Content-Length first) answers 413 with The callback request body is larger than 65536 bytes. before any verification.
Callback Helpers
| Helper | What it does |
|---|---|
kbzPay()->handleCallback($request) | Verifies the callback. Takes the Laravel Request as is, or the SDK's CallbackRequest |
MyanmarPayments::handleCallback($gateway, $request) | The same, by gateway name, for one route that serves every gateway (Wave Pay Mini App verifies against $request->url()); see Handling Webhooks |
MyanmarPayments::gateway($name) | The gateway for kbz-pay, wave-pay, wave-pay-mini-app, aya-pay, yoma-mmqr or cyber-source (gateways() lists them). An unknown name throws InvalidArgumentException |
MyanmarPayments::acknowledge($callback) | The response the gateway expects, as a Responsable. Without a callback, an empty 200 |
ayaPay()->verifyRedirect($request) | Verifies AYA's browser return; see AYA Pay |
Signatures are computed over the exact bytes the gateway sent; the package reads them from $request->getContent(), so don't rewrite the body in middleware before the callback route. A body is read as JSON only when it is a single JSON object; any other body is read as a urlencoded form.
Rules
- Verify, then trust. A callback that fails verification throws
SignatureVerificationException, and so does one whose signed or hashed field holds an object or array instead of a single value, since no gateway signs nested values. Never act on its payload; it carries the unverified data in$e->rawfor logging only. - Check the amount. Compare
$callback->amount(as the gateway sent it, a string) with your order before fulfilling. A gateway may format it differently from your order (10000or10000.00);Amount::parse($order->amount)->equals($callback->amount)compares decimal strings exactly. Yoma MMQR callbacks carry no amount: confirm those withstatus(). - Signed is not enough on its own. Where a gateway joins the signed values with a separator (AYA Pay
:, CyberSource,and=) or with none (Wave Pay, Wave Pay Mini App), the package also rejects values that could be re-split into other fields. See each driver's Handling Callbacks section. - Be idempotent. Gateways retry and may deliver the same callback more than once.
- Acknowledge.
MyanmarPayments::acknowledge($callback)returns the response the gateway expects, e.g. KBZ Pay's plainsuccess. Without it, gateways keep retrying.
PaymentStatus
Every gateway's own status values are mapped onto one enum. The original value stays in $callback->gatewayStatus.
| Case | Meaning |
|---|---|
PaymentStatus::Successful | The customer paid. The only status that means money was collected. |
PaymentStatus::Pending | Still in progress or waiting on the customer. |
PaymentStatus::Failed | Attempted and failed or rejected. |
PaymentStatus::Canceled | Canceled or closed before completing. |
PaymentStatus::Expired | The payment window ran out. |
PaymentStatus::Unknown | A status this package does not recognize yet. Inspect gatewayStatus. |
$status->isFinal() is false for Pending and Unknown. Unknown statuses never throw.
Each gateway page lists its exact mapping.
Status Checks
When a callback is late, ask KBZ Pay, AYA or Yoma directly; Wave Pay, Wave Pay Mini App and CyberSource have no status API in this package.
Status checks return a PaymentStatusResult with the same status, gatewayStatus, gatewayReference and amount fields.
| Gateway | Call |
|---|---|
| KBZ Pay | MyanmarPayments::kbzPay()->status($orderId) |
| AYA Payment Gateway | MyanmarPayments::ayaPay()->status($orderId) |
| Yoma MMQR | MyanmarPayments::yomaMmqr()->status($payment->reference) |
| Wave Pay | No status API: rely on the callback |
| Wave Pay Mini App | No status API: rely on the callback |
| CyberSource | No status API in this package: rely on the callback |
$result = MyanmarPayments::kbzPay()->status('ORDER_'.$order->id);
if ($result->isSuccessful()) {
// ...
}See PaymentCallback & Status for every property.