---
url: https://laranex.vercel.app/go-myanmar-payments/drivers/yoma-mmqr.md
description: >-
  Integrate Yoma Bank MMQR in Go. Ready-made QR images, QR renewal, status
  checks and verified callbacks.
---

# Yoma MMQR

Yoma MMQR is Yoma Bank's MMQR gateway: it issues ready-made QR images that customers scan with any MMQR wallet.

| Call | What it does | Returns |
|---|---|---|
| `yoma.Initiate(ctx, data)` | Check out the order and generate its first QR | [`*QrPayment`](#initiate-response) |
| `yoma.RenewQR(ctx, orderID)` | Generate a new QR for a checked-out order | [`*QrPayment`](#renewqr-response) |
| `yoma.Status(ctx, reference)` | Check a QR's payment status | [`*PaymentStatusResult`](#status-response) |
| `yoma.HandleCallback(request)` | Verify the callback | [`*PaymentCallback`](#handlecallback-response) |

[Responses](#responses) shows what Yoma MMQR puts in each result.

## How it works

Yoma checks each order out once, then issues QR codes that each stay payable for 120 seconds.

## Initiating a Payment

```go
import (
	"fmt"

	myanmarpayments "github.com/laranex/go-myanmar-payments/v4"
	"github.com/laranex/go-myanmar-payments/v4/yomammqr"
)

yoma, err := yomammqr.New(
	yomammqr.Config{
		MerchantID:     "...",
		ClientID:       "...",
		ClientSecret:   "...",
		WebhookHashKey: "...",
		APIVersion:     "v1rc",
		WebhookSecret:  "...",
		BaseURL:        yomammqr.ProductionURL,
	},
	nil, // default HTTP client
	nil, // in-memory token cache; share this gateway across requests
)
if err != nil {
	return err
}

data := yomammqr.PaymentData{
	OrderID:     fmt.Sprintf("ORDER_%d", order.ID),
	Amount:      myanmarpayments.Kyat(10000),
	Description: fmt.Sprintf("Order #%d", order.ID),
}

payment, err := yoma.Initiate(ctx, data)
if err != nil {
	return err
}

// Store payment.Reference with the order for status checks.

src := payment.QRImageDataURI("")
fmt.Fprintf(w, `<img src="%s" alt="Scan with any MMQR wallet">`, src)
```

### yomammqr.PaymentData

| Field | Type | Required | Rules |
|---|---|---|---|
| `OrderID` | `string` | Yes | Unique order number, at most 20 characters |
| `Amount` | `myanmarpayments.Amount` | Yes | Whole kyat, greater than 0, e.g. `Kyat(10000)`. Yoma documents no decimals or currency |
| `Description` | `string` | Yes | At most 50 characters |

Length limits count characters, not bytes.

### QR Image

`QRImage` is an already rendered base64 QR image: display it as is, no QR library needed.

## Handling Callbacks

```go
import (
	"net/http"

	myanmarpayments "github.com/laranex/go-myanmar-payments/v4"
)

// POST /payments/yoma/callback
request, err := myanmarpayments.NewCallbackRequestFromHTTP(r)
if err != nil {
	http.Error(w, "invalid callback", http.StatusBadRequest)
	return
}
callback, err := yoma.HandleCallback(request)
if err != nil {
	http.Error(w, "invalid callback", http.StatusBadRequest)
	return
}

if callback.IsSuccessful() {
	// callback.OrderID is your orderNumber
}

callback.Acknowledgement.Write(w)
```

The callback URL is registered with Yoma, not sent per order. Every callback must carry the configured `WebhookSecret` in the `X-Webhook-Secret` header; a missing or wrong header fails verification. The hash is checked with HMAC-SHA256 keyed with your order number plus `WebhookHashKey`. Yoma's specification only says the payload is hashed with that key; HMAC-SHA256 is inferred from its description and its 64-hex-digit sample.

::: warning Callbacks carry no amount
Yoma signs only `orderNumber` and `status`, and the callback has no amount (`callback.Amount` is `""`). Before fulfilling, confirm the payment with `yoma.Status(ctx, reference)`, using the `Reference` of the QR you created for the order's stored amount, rather than trusting the callback alone.
:::

## QR Lifetime and Renewal

A QR is payable for 120 seconds (`yomammqr.QRLifetime`); `payment.ExpiresAt` tells you when. Yoma accepts each order number **once**, so never call `Initiate` again for the same order. Renew the QR instead:

```go
import "fmt"

payment, err := yoma.RenewQR(ctx, fmt.Sprintf("ORDER_%d", order.ID))
if err != nil {
	return err
}

// Store the new payment.Reference: the previous one stops working.
```

## Status Checks

```go
// reference is the payment.Reference you stored
result, err := yoma.Status(ctx, reference)
if err != nil {
	return err
}

if result.IsSuccessful() {
	// the QR was paid
}
```

`Status` takes the QR's `Reference`, not your `OrderID`. An expired QR returns `StatusExpired` instead of an error.

## Responses

What Yoma MMQR puts in each field. See [Results](/go-myanmar-payments/references/results) and [PaymentCallback & Status](/go-myanmar-payments/references/payment-callback) for the full structs.

### `Initiate()` → `*myanmarpayments.QrPayment` {#initiate-response}

| Field / Method | Yoma MMQR value |
|---|---|
| `Flow()` | `FlowQR` |
| `OrderID` | Your `data.OrderID` (Yoma `orderNumber`) |
| `QRString` | Always `""` |
| `QRImage` | Yoma `qrString`, a base64 QR image. Always set |
| `ExpiresAt` | Now + 120 seconds (`yomammqr.QRLifetime`). Always set |
| `Reference` | Yoma `refLabel`, e.g. `100000083331`. Pass it to `Status`. Always set |
| `Raw` | The `qr/generate` response: `refLabel`, `qrString`, `errorCode` (`nil`), `errorDescription` |
| `QRImageDataURI("")` | `data:image/png;base64,…`. Yoma doesn't name the image format; PNG is the usual one |

`Initiate` checks the order out (`payment/checkout`), then generates its first QR; the result comes from the generate call.

### `RenewQR()` → `*myanmarpayments.QrPayment` {#renewqr-response}

The same values as [`Initiate()`](#initiate-response) for the `orderID` you passed, with a new `QRImage`, `Reference` and `ExpiresAt`. The previous `Reference` stops answering status checks.

### `Status()` → `*myanmarpayments.PaymentStatusResult` {#status-response}

| Field | Yoma MMQR value |
|---|---|
| `OrderID` | Always `""`: Yoma only returns the reference |
| `Status` | `paymentStatus` mapped case-insensitively, see [Statuses](#statuses). `StatusExpired` for a `QR EXPIRED` error |
| `GatewayStatus` | Yoma `paymentStatus`, trimmed, e.g. `SUCCESS`. `QR EXPIRED` for an expired QR |
| `GatewayReference` | Yoma `refLabel`, falling back to the reference you passed. Always set |
| `Amount` | Always `""`: Yoma's status response has no amount |
| `Raw` | The `payment/check-status` response: `refLabel`, `paymentStatus`, `errorCode`, `errorDescription` |

### `HandleCallback()` → `*myanmarpayments.PaymentCallback` {#handlecallback-response}

| Field | Yoma MMQR value |
|---|---|
| `OrderID` | Yoma `orderNumber` (your `OrderID`) |
| `Status` | `status` mapped case-insensitively, see [Statuses](#statuses) |
| `GatewayStatus` | Yoma `status`, trimmed, as sent, e.g. `success` |
| `GatewayReference` | Always `""`: Yoma's callback has no reference |
| `Amount` | Always `""`: Yoma signs only `orderNumber` and `status` and sends no amount. Confirm with [`Status`](#status-checks) before fulfilling |
| `Raw` | The verified body: `orderNumber`, `status`, `hashValue` |
| `Acknowledgement` | HTTP `200`, empty body, `Content-Type: text/plain` |

## Statuses

| Yoma value | `PaymentStatus` |
|---|---|
| `success` (callback), `SUCCESS` (status) | `StatusSuccessful` |
| `PENDING` | `StatusPending` |
| `fail` (callback), `FAILED` (status) | `StatusFailed` |
| `QR EXPIRED` error | `StatusExpired` |
| anything else | `StatusUnknown` |

## Access Tokens

Yoma authenticates with an OAuth token that lasts hours. The gateway keeps it in the [token cache](/go-myanmar-payments/configuration#token-cache), shares one token request between concurrent calls, and fetches a new token, retrying once, when Yoma answers `401`. The shared token request runs without any one call's cancellation and is bounded by the configured `TimeoutSeconds` (30 by default), so a stuck request can't block later calls and canceling one call's `ctx` never fails the others; that call stops waiting and returns an `*APIError`.

The token is cached for Yoma's `expires_in` minus 60 seconds (at least 60 seconds). `expires_in` is read from its leading digits after any whitespace, so `28800.0` and ` 28800` are 28800 seconds; a missing or non-positive value means 3600.

## Errors

| Call | Returns | When |
|---|---|---|
| `Initiate()` | `*InvalidPaymentDataError` | `data.Validate()` fails. Nothing is sent |
| `Initiate()` | `*APIError` | The token request fails, Yoma answers with an HTTP error or an `errorCode` (e.g. `PAYMENT ALREADY EXISTS`), `checkOutStatus` isn't `true`, or `qrString` or `refLabel` is missing or empty |
| `RenewQR()` | `*APIError` | As `Initiate()`, without the checkout |
| `Status()` | `*APIError` | The token request fails, or Yoma answers with an HTTP error or any `errorCode` other than `QR EXPIRED` |
| `HandleCallback()` | `*SignatureVerificationError` | `X-Webhook-Secret` is missing or wrong, `orderNumber` is missing, `orderNumber` or `status` holds an object or array, or `hashValue` doesn't match |

Yoma reports business errors with HTTP 200 and an `errorCode`; `*APIError` carries it in `GatewayCode` (an empty `errorCode` counts as none) and Yoma's `errorDescription` (or `error_description`) in `GatewayMessage`.

### Error Codes

Yoma's specification lists these `errorCode` values. Its error table gives HTTP 200 for the business codes, `401` for `UNAUTHORIZED` and `400` for `VALIDATION ERROR`; `PAYMENT ALREADY EXISTS` and `QR EXPIRED` appear only in the endpoint descriptions.

| `errorCode` | Yoma's description | What it means for your app |
|---|---|---|
| `PAYMENT ALREADY EXISTS` | Listed for checkout, without a description | The order number was already checked out. Never call `Initiate()` twice for one order: call `RenewQR()` |
| `PAYMENT ALREADY DONE` | Payment already processed for this order | The order may already be paid: confirm against your records before charging again or fulfilling |
| `PAYMENT ALREADY PROCESSED` | Duplicate processing detected | As above: confirm against your records |
| `MERCHANT NOT FOUND` | Merchant is invalid or inactive | Check the merchant ID and that your Yoma account is active |
| `PAYMENT NOT FOUND` | Order or refLabel not found | Yoma doesn't know the order number or reference: check you passed the stored `refLabel` |
| `QR EXPIRED` | Qr has been expired. | `Status()` reports the QR as expired instead of an error; renew the QR to keep collecting the payment |
| `UNAUTHORIZED` | Missing or invalid token | The token is refetched once; if it persists, check the client ID and secret |
| `VALIDATION ERROR` | One or more fields are invalid | A request field broke Yoma's rules; Yoma's `errorDescription` says which |
