---
url: https://laranex.vercel.app/goravel-myanmar-payments/payment-flows.md
description: >-
  Each gateway method returns one typed result per flow — RedirectPayment,
  FormPayment, QrPayment, AppPayment or MiniAppPayment — so you always know what
  to do next.
---

# 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 it returns. Each flow has its own result type with exactly the fields that flow needs.

| Result | What you do | Returned by |
|---|---|---|
| `*RedirectPayment` | Redirect the customer to `payment.URL` | `KbzPay()` → `PWA()`, `WavePay()` → `Initiate()` |
| `*FormPayment` | Redirect to `payments.AutoSubmitURL(form)` | `AyaPay()` → `Initiate()`, `CyberSource()` → `HostedCheckout()` |
| `*QrPayment` | Show the QR to the customer | `KbzPay()` → `QR()`, `YomaMmqr()` → `Initiate()`, `RenewQR()` |
| `*AppPayment` | Return the signed payload to your mobile app | `KbzPay()` → `App()` |
| `*MiniAppPayment` | Return the signed payload to your mini app page | `WavePayMiniApp()` → `Payment()` |

The customer finishing on the gateway's side is never proof of payment. Fulfill orders from the verified [callback](/goravel-myanmar-payments/callbacks) or a status check.

Goravel's `http.Context` is a `context.Context`, so pass `ctx` straight to gateway calls that hit the network.

## 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.

```go
import (
	"fmt"

	"github.com/goravel/framework/contracts/http"
	myanmarpayments "github.com/laranex/go-myanmar-payments/v4"
	"github.com/laranex/go-myanmar-payments/v4/kbzpay"
	paymentsfacades "github.com/laranex/goravel-myanmar-payments/v4/facades"
)

func (r *CheckoutController) KbzPay(ctx http.Context) http.Response {
	order := findOrder(ctx) // your own order lookup

	kbz, err := paymentsfacades.MyanmarPayments().KbzPay()
	if err != nil {
		return ctx.Response().String(http.StatusInternalServerError, "%s", err)
	}
	payment, err := kbz.PWA(ctx, kbzpay.PaymentData{
		OrderID:     fmt.Sprintf("ORDER_%d", order.ID),
		Amount:      myanmarpayments.Kyat(10000),
		CallbackURL: "https://shop.test/payments/kbz/callback",
	})
	if err != nil {
		return ctx.Response().String(http.StatusBadGateway, "%s", err)
	}

	return ctx.Response().Redirect(http.StatusFound, payment.URL)
}
```

`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. The package hosts a page that renders the form and submits it immediately, so a redirect is enough:

```go
import (
	"github.com/goravel/framework/contracts/http"
	payments "github.com/laranex/goravel-myanmar-payments/v4"
	paymentsfacades "github.com/laranex/goravel-myanmar-payments/v4/facades"
)

aya, err := paymentsfacades.MyanmarPayments().AyaPay()
form, err := aya.Initiate(data)
link, err := payments.AutoSubmitURL(form)

return ctx.Response().Redirect(http.StatusFound, link)
```

The link is an encrypted, expiring link to the package's `myanmar-payments.form` route. See [Configuration](/goravel-myanmar-payments/configuration#auto-submit-form-route).

To render the form yourself, for example with your own loading state, return `form.HTML()` or use `Action`, `Fields` and `Enctype`:

```go
import "github.com/goravel/framework/contracts/http"

html := []byte(form.HTML())

return ctx.Response().Data(http.StatusOK, "text/html; charset=utf-8", html)
```

Under a Content-Security-Policy that allows scripts by nonce (`script-src 'nonce-…'`), use `form.HTMLWithNonce(nonce)`, which renders `<script nonce="…">`. The package's form route does the same when you set [`form_route.nonce`](/goravel-myanmar-payments/configuration#auto-submit-form-route).

Post the fields unchanged: they are signed. `Fields` is a slice in signing order; `form.Values()` returns them as a map and `form.Field(name)` reads one.

## 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:

| Field | Gateway | Use it as |
|---|---|---|
| `QRString` | KBZ Pay | A payload: encode it into a QR image with any QR library |
| `QRImage` | Yoma MMQR | A base64 image: display it as is, e.g. with `QRImageDataURI("")` |

```go
import (
	"html/template"

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

yoma, err := paymentsfacades.MyanmarPayments().YomaMmqr()
payment, err := yoma.Initiate(ctx, data)

return ctx.Response().View().Make("payments/qr.tmpl", map[string]any{
	// template.URL keeps html/template from rejecting the data URI
	"qr":      template.URL(payment.QRImageDataURI("")),
	"expires": payment.ExpiresAt.Format("15:04:05"),
})
```

```html
<img src="{{ .qr }}" alt="Scan to pay">
<p>Valid until {{ .expires }}</p>
```

`ExpiresAt` is set when the gateway limits how long the QR is payable (the zero `time.Time` otherwise), and `Reference` holds the ID used for status checks (Yoma `refLabel`).

## App Payments

Here is the flow with the KBZ Pay mobile SDK.

The KBZ Pay mobile SDK needs a signed order string. Return it to your app, which passes it to `KBZPay.startPay()`:

```go
import (
	"github.com/goravel/framework/contracts/http"
	paymentsfacades "github.com/laranex/goravel-myanmar-payments/v4/facades"
)

kbz, err := paymentsfacades.MyanmarPayments().KbzPay()
payment, err := kbz.App(ctx, data)

// orderId, orderInfo, sign, signType (Raw is not encoded)
return ctx.Response().Json(http.StatusOK, payment)
```

`KBZPay.startPay()`'s 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.JSON()` is exactly that object:

```go
import (
	"github.com/goravel/framework/contracts/http"
	paymentsfacades "github.com/laranex/goravel-myanmar-payments/v4/facades"
)

miniApp, err := paymentsfacades.MyanmarPayments().WavePayMiniApp()
payment, err := miniApp.Payment(data)

// {"amount", "miniAppID", "merchantRefID", "orderID", "callBackUrl", "hashValue", "items"}
return ctx.Response().Data(http.StatusOK, "application/json", []byte(payment.JSON()))
```

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](/goravel-myanmar-payments/drivers/wave-pay-mini-app) for the whole flow.

See [Results](/goravel-myanmar-payments/references/results) for every field.
