Skip to content

Callbacks & Status ​

Every gateway notifies your server of the payment result. HandleCallbackFromContext(gateway, ctx) verifies the gateway's signature against the exact body the gateway sent and returns a *PaymentCallback.

Production setup

For production, follow Handling Webhooks (recommended): verify, store the call, acknowledge immediately, then process it once in the background with retries. The example below handles everything inline to show the API.

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

Handling a KBZ Pay callbackYour appKBZ PayPayment notificationPOST to CallbackURLVerify the signatureHandleCallbackFromContext(name, ctx)Invalid: 400, never fulfill*SignatureVerificationErrorFind the orderby callback.OrderIDFulfill onceskip if paid, match the amountAcknowledge: plain successpayments.Acknowledge(ctx, callback)No acknowledgement? Retryafter 60 s, then 600 s
Handling a KBZ Pay callback
go
import (
	"github.com/goravel/framework/contracts/http"
	myanmarpayments "github.com/laranex/go-myanmar-payments/v4"
	payments "github.com/laranex/goravel-myanmar-payments/v4"
	paymentsfacades "github.com/laranex/goravel-myanmar-payments/v4/facades"

	"yourapp/app/facades"
	"yourapp/app/models"
)

facades.Route().Post("/payments/kbz/callback", func(
	ctx http.Context,
) http.Response {
	callback, err := paymentsfacades.MyanmarPayments().
		HandleCallbackFromContext(payments.GatewayKbzPay, ctx)
	if err != nil { // *myanmarpayments.SignatureVerificationError, ...
		return ctx.Response().String(http.StatusBadRequest, "invalid")
	}

	var order models.Order
	err = facades.Orm().Query().
		Where("reference", callback.OrderID).
		FirstOrFail(&order)
	if err != nil {
		return ctx.Response().String(http.StatusNotFound, "unknown order")
	}

	// order.Amount is a string such as "10000"; compare by value, not floats
	amount, err := myanmarpayments.ParseAmount(order.Amount)
	paid := err == nil && amount.Equals(callback.Amount)

	if callback.IsSuccessful() && !order.IsPaid() && paid {
		order.MarkAsPaid(callback.GatewayReference)
	}

	return payments.Acknowledge(ctx, callback)
})

Gateways post from their own servers, so keep callback routes free of CSRF and authentication middleware.

Callback Helpers ​

HelperWhat it does
manager.HandleCallbackFromContext(gateway, ctx)Verifies the callback in the current request by gateway name. It resolves the gateway first (payments.ErrUnknownGateway or a *myanmarpayments.ConfigurationError), then reads the body (payments.ErrCallbackBodyTooLarge), then checks the signature (*myanmarpayments.SignatureVerificationError). Wave Pay Mini App callbacks are verified against the URL they were posted to, payments.CallbackURLFromContext(ctx)
kbz.HandleCallback(request)Verifies the callback. Takes the SDK's *myanmarpayments.CallbackRequest
manager.HandleCallback(gateway, request)The same, by gateway name, for one route that serves every gateway, e.g. to store the request first; see Handling Webhooks. A request carries no URL, so wave-pay-mini-app returns payments.ErrCallbackURLRequired: use WavePayMiniApp().HandleCallback(request, callbackURL)
payments.CallbackURLFromContext(ctx)The current request's URL without its query string (scheme, host and path), the callback URL Wave Pay Mini App callbacks are verified against; see Wave Pay Mini App
payments.CallbackRequestFromContext(ctx)Builds the *myanmarpayments.CallbackRequest from the current Goravel request: the raw body, the headers and the query string. A body over payments.MaxCallbackBodyBytes (64 KiB) returns payments.ErrCallbackBodyTooLarge
manager.Gateway(name)The gateway for kbz-pay, wave-pay, wave-pay-mini-app, aya-pay, yoma-mmqr or cyber-source (payments.GatewayNames() lists them), as a payments.CallbackHandler (for wave-pay-mini-app, a *payments.WavePayMiniAppCallbackHandler; set its CallbackURL). An unknown name returns an error wrapping payments.ErrUnknownGateway
payments.Acknowledge(ctx, callback)The response the gateway expects, written as the Goravel response. With a nil callback, an empty 200
aya.VerifyRedirect(request)Verifies AYA's browser return; see AYA Pay

manager is paymentsfacades.MyanmarPayments().

Signatures are computed over the exact bytes the gateway sent, so always build the request with CallbackRequestFromContext, never from ctx.Request().All():

BodyWhat you get
JSON (KBZ Pay, Wave Pay, Wave Pay Mini App, Yoma MMQR)The body byte for byte
application/x-www-form-urlencoded or multipart/form-data (AYA Pay, CyberSource)Goravel's gin driver parses form bodies before your handler runs, which consumes them. The body is rebuilt from the parsed form fields as urlencoded and Content-Type says so. These gateways sign field values, so the result verifies the same

Body Size Limit ​

Answer payments.ErrCallbackBodyTooLarge with 413:

go
callback, err := paymentsfacades.MyanmarPayments().
	HandleCallbackFromContext(payments.GatewayKbzPay, ctx)
if errors.Is(err, payments.ErrCallbackBodyTooLarge) {
	return ctx.Response().String(http.StatusRequestEntityTooLarge, "too large")
}

Goravel parses form bodies before your handler runs, so keep a body size limit on your server or in middleware as well.

Rules ​

  • Verify, then trust. A callback that fails verification returns a *myanmarpayments.SignatureVerificationError, 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 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.Equals(callback.Amount), with amount parsed from your order by myanmarpayments.ParseAmount(), 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. payments.Acknowledge(ctx, 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 type. The original value stays in callback.GatewayStatus.

ConstantMeaning
myanmarpayments.StatusSuccessfulThe customer paid. The only status that means money was collected.
myanmarpayments.StatusPendingStill in progress or waiting on the customer.
myanmarpayments.StatusFailedAttempted and failed or rejected.
myanmarpayments.StatusCanceledCanceled or closed before completing.
myanmarpayments.StatusExpiredThe payment window ran out.
myanmarpayments.StatusUnknownA status this package does not recognize yet. Inspect GatewayStatus.

status.IsFinal() is false for StatusPending and StatusUnknown. Unknown statuses never return an error.

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 statuskbz.Status(ctx, orderID)PaymentStatusResulttrade_status, e.g. PAY_SUCCESSSuccessful? Fulfill oncesame checks as the callbackNot final? Check again laterresult.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 PayKbzPay() → Status(ctx, orderID)
AYA Payment GatewayAyaPay() → Status(ctx, orderID)
Yoma MMQRYomaMmqr() → Status(ctx, 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
go
import (
	"fmt"

	paymentsfacades "github.com/laranex/goravel-myanmar-payments/v4/facades"
)

kbz, err := paymentsfacades.MyanmarPayments().KbzPay()
result, err := kbz.Status(ctx, fmt.Sprintf("ORDER_%d", order.ID))

if err == nil && result.IsSuccessful() {
	// ...
}

See PaymentCallback & Status for every field.