---
url: https://laranex.vercel.app/nestjs-myanmar-payments/payment-flows.md
description: >-
  Each gateway method returns one typed result class 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 class 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 `this.payments.autoSubmitUrl(payment)` | `ayaPay().initiate()`, `cyberSource().hostedCheckout()` |
| `QrPayment` | Show the QR to the customer | `kbzPay().qr()`, `yomaMmqr().initiate()`, `yomaMmqr().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 samples run in a controller that injects `MyanmarPaymentsService` as `this.payments`. The customer finishing on the gateway's side is never proof of payment. Fulfill orders from the verified [callback](/nestjs-myanmar-payments/callbacks) or a status check.

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

```ts
import { MyanmarPaymentsService } from '@laranex/nestjs-myanmar-payments';
import { Controller, Param, Post, Redirect } from '@nestjs/common';

import { OrdersService } from '../orders/orders.service';

@Controller('checkout')
export class CheckoutController {
  constructor(
    private readonly payments: MyanmarPaymentsService,
    private readonly orders: OrdersService,
  ) {}

  @Post(':id/kbz-pay')
  @Redirect()
  async kbzPay(@Param('id') id: string): Promise<{ url: string }> {
    const order = await this.orders.findOrFail(id);

    const payment = await this.payments.kbzPay().pwa({
      orderId: `ORDER_${order.id}`,
      amount: 10000,
      callbackUrl: 'https://shop.test/payments/kbz/callback',
    });

    return { url: 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:

```ts
const payment = this.payments.ayaPay().initiate(data);

return { url: this.payments.autoSubmitUrl(payment) }; // with @Redirect()
```

`autoSubmitUrl()` returns an encrypted, expiring link to the module's form route. See [Configuration](/nestjs-myanmar-payments/configuration#auto-submit-form-route).

To render the form yourself, for example with your own loading state, return `toHtml()` or use `action`, `fields` and `enctype`:

```ts
import { Header, Param, Post } from '@nestjs/common';

@Post(':id/aya-pay')
@Header('Content-Type', 'text/html; charset=utf-8')
async ayaPay(@Param('id') id: string): Promise<string> {
  // ...
  return this.payments.ayaPay().initiate(data).toHtml();
}
```

Under a Content-Security-Policy that allows scripts by nonce (`script-src 'nonce-…'`), pass the nonce so the inline script runs: `toHtml(nonce)` renders `<script nonce="…">`. The module's own form route does this for you with helmet's nonce or `formRoute.nonce`.

```handlebars
<form id="payment-form" method="POST" action="{{payment.action}}"
      enctype="{{payment.enctype}}">
  {{#each payment.fields}}
    <input type="hidden" name="{{this.name}}" value="{{this.value}}">
  {{/each}}
</form>
<script>document.getElementById('payment-form').submit();</script>
```

Post the fields unchanged: they are signed.

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

| Property | 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()` |

```ts
const payment = await this.payments.yomaMmqr().initiate(data);
```

```handlebars
<img src="{{qrImageDataUri}}" alt="Scan to pay">
<p>Valid until {{expiresAt}}</p>
```

Pass `payment.qrImageDataUri()` and `payment.expiresAt` to your view. `expiresAt` is set when the gateway limits how long the QR is payable, 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()`:

```ts
const payment = await this.payments.kbzPay().app(data);

// JSON: orderId, orderInfo, sign, signType
return payment;
```

Returning the `AppPayment` from a handler serializes it with `toJSON()`, which leaves out `raw`. The SDK's own result only means the payment screen closed; rely on the callback or `kbzPay().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:

```ts
const payment = this.payments.wavePayMiniApp().payment(data);

// JSON: amount, miniAppID, merchantRefID, orderID, callBackUrl, hashValue, items
return payment;
```

Returning the `MiniAppPayment` from a handler serializes it with `toJSON()`, exactly Wave's `makePayment` object. The page calls `WaveJsSDK.paymentModule.makePayment(payload)` with it after logging in with your app's access token; the SDK's result is not proof of payment. See [Wave Pay Mini App](/nestjs-myanmar-payments/drivers/wave-pay-mini-app) for the whole flow.

See [Results](/nestjs-myanmar-payments/references/results) for every property.
