Skip to content

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.

Handling a KBZ Pay callbackYour appKBZ PayPayment notificationPOST to callbackUrlVerify the signaturekbzPay()->handleCallback()Invalid: 400, never fulfillSignatureVerificationExceptionFind the orderby $callback->orderIdFulfill onceskip if paid, match the amountAcknowledge: plain successacknowledge($callback)No acknowledgement? Retryafter 60 s, then 600 s
Handling a KBZ Pay callback
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 ​

HelperWhat 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->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().
  • 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.

CaseMeaning
PaymentStatus::SuccessfulThe customer paid. The only status that means money was collected.
PaymentStatus::PendingStill in progress or waiting on the customer.
PaymentStatus::FailedAttempted and failed or rejected.
PaymentStatus::CanceledCanceled or closed before completing.
PaymentStatus::ExpiredThe payment window ran out.
PaymentStatus::UnknownA 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.

Checking the status when the callback is lateYour appKBZ PayCallback late or missingAsk for the order statuskbzPay()->status($orderId)PaymentStatusResulttrade_status, e.g. PAY_SUCCESSSuccessful? Fulfill oncesame checks as the callbackNot final? Check again later$result->status->isFinal()
Checking the status when the callback is late

Status checks return a PaymentStatusResult with the same status, gatewayStatus, gatewayReference and amount fields.

GatewayCall
KBZ PayMyanmarPayments::kbzPay()->status($orderId)
AYA Payment GatewayMyanmarPayments::ayaPay()->status($orderId)
Yoma MMQRMyanmarPayments::yomaMmqr()->status($payment->reference)
Wave PayNo status API: rely on the callback
Wave Pay Mini AppNo status API: rely on the callback
CyberSourceNo status API in this package: rely on the callback
php
$result = MyanmarPayments::kbzPay()->status('ORDER_'.$order->id);

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

See PaymentCallback & Status for every property.