---
url: https://laranex.vercel.app/laravel-myanmar-payments/callbacks.md
description: >-
  Verify gateway callbacks with handleCallback(), read a gateway-independent
  PaymentStatus, acknowledge the callback, and check payment status when a
  callback is late.
---

# 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](/laravel-myanmar-payments/drivers/wave-pay-mini-app#handling-callbacks) its payment was signed with.

::: tip Production setup
For production, follow [Handling Webhooks](/laravel-myanmar-payments/webhooks); this example handles everything inline.
:::

Every callback goes through the same steps; KBZ Pay is shown here.

```php
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](/laravel-myanmar-payments/webhooks#route-and-controller) |
| `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](/laravel-myanmar-payments/drivers/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->raw` for 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 (`10000` or `10000.00`); `Amount::parse($order->amount)->equals($callback->amount)` compares decimal strings exactly. Yoma MMQR callbacks carry no amount: confirm those with [`status()`](/laravel-myanmar-payments/drivers/yoma-mmqr#status-checks).
* **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 plain `success`. 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 |

```php
$result = MyanmarPayments::kbzPay()->status('ORDER_'.$order->id);

if ($result->isSuccessful()) {
    // ...
}
```

See [PaymentCallback & Status](/laravel-myanmar-payments/references/payment-callback) for every property.
