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

# 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(data)` | Check out the order and generate its first QR | [`QrPayment`](#initiate-response) |
| `yoma.renew_qr(order_id)` | Generate a new QR for a checked-out order | [`QrPayment`](#renew-qr-response) |
| `yoma.status(reference)` | Check a QR's payment status | [`PaymentStatusResult`](#status-response) |
| `yoma.handle_callback(request)` | Verify the callback | [`PaymentCallback`](#handle-callback-response) |

`AsyncYomaMmqr` has the same methods: await `initiate()`, `renew_qr()`, `status()` and `forget_token()`; `handle_callback()` stays a plain call.

[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

```python
from django.shortcuts import get_object_or_404, render
from python_myanmar_payments import (
    YomaMmqr,
    YomaMmqrConfig,
    YomaMmqrPaymentData,
)

from shop.models import Order

# Create it once at startup: the in-memory token cache lives on the instance.
yoma = YomaMmqr(
    YomaMmqrConfig(
        merchant_id="...",
        client_id="...",
        client_secret="...",
        webhook_hash_key="...",
        api_version="v1rc",
        webhook_secret="...",
        base_url=YomaMmqrConfig.PRODUCTION_URL,
    )
)


def yoma_checkout(request, order_id: int):
    order = get_object_or_404(Order, pk=order_id)

    data = YomaMmqrPaymentData(
        order_id=f"ORDER_{order.id}",
        amount=10000,
        description=f"Order #{order.id}",
    )

    payment = yoma.initiate(data)

    # Store payment.reference with the order for status checks.

    return render(request, "yoma_qr.html", {"payment": payment})
```

```html
<img src="{{ payment.qr_image_data_uri }}" alt="Scan with any MMQR wallet">
```

### YomaMmqrPaymentData

| Field | Type | Required | Rules |
|---|---|---|---|
| `order_id` | `str` | Yes | Unique order number, at most 20 characters |
| `amount` | `Amount \| int \| str \| Decimal` | Yes | Whole kyat, greater than 0, e.g. `10000` or `Amount.kyat(10000)`. Yoma documents no decimals or currency |
| `description` | `str` | Yes | At most 50 characters |

Length limits count characters, not bytes.

## Handling Callbacks

```python
from django.http import HttpResponse
from django.views.decorators.csrf import csrf_exempt
from python_myanmar_payments import CallbackRequest, SignatureVerificationError


# POST /payments/yoma/callback
@csrf_exempt
def yoma_callback(request):
    callback_request = CallbackRequest(
        body=request.body,
        headers=request.headers,
        query=request.META.get("QUERY_STRING", ""),
    )
    try:
        callback = yoma.handle_callback(callback_request)
    except SignatureVerificationError:
        return HttpResponse("invalid callback", status=400)

    if callback.is_successful():
        # callback.order_id is your orderNumber
        ...

    ack = callback.acknowledgement
    return HttpResponse(ack.body, status=ack.status, headers=ack.headers)
```

The callback URL is registered with Yoma, not sent per order. Every callback must carry the configured `webhook_secret` 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 `webhook_hash_key`. 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 `None`). Before fulfilling, confirm the payment with `yoma.status(reference)`, using the `reference` of the QR you created for the order's stored amount, rather than trusting the callback alone. The status result has no amount either, so trust your stored amount.
:::

## QR Lifetime and Renewal

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

```python
payment = yoma.renew_qr(f"ORDER_{order.id}")

# Store the new payment.reference: the previous one stops working.
```

## Status Checks

```python
# reference is the payment.reference you stored
result = yoma.status(reference)

if result.is_successful():
    ...  # the QR was paid
```

`status()` takes the QR's `reference`, not your `order_id`. An expired QR returns `EXPIRED` instead of raising.

## Responses

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

### `initiate()` → `QrPayment` {#initiate-response}

| Field / Method | Yoma MMQR value |
|---|---|
| `flow` | `PaymentFlow.QR` |
| `order_id` | Your `data.order_id` (Yoma `orderNumber`) |
| `qr_string` | Always `None` |
| `qr_image` | Yoma `qrString`, a base64 QR image. Always set |
| `expires_at` | Now + 120 seconds (`YomaMmqr.QR_LIFETIME_SECONDS`), in UTC. Always set |
| `reference` | Yoma `refLabel`, e.g. `100000083331`. Pass it to `status()`. Always set |
| `raw` | The `qr/generate` response: `refLabel`, `qrString`, `errorCode` (`None`), `errorDescription` |
| `qr_image_data_uri()` | `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.

### `renew_qr()` → `QrPayment` {#renew-qr-response}

The same values as [`initiate()`](#initiate-response) for the `order_id` you passed, with a new `qr_image`, `reference` and `expires_at`. The previous `reference` stops answering status checks.

### `status()` → `PaymentStatusResult` {#status-response}

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

### `handle_callback()` → `PaymentCallback` {#handle-callback-response}

| Field / Method | Yoma MMQR value |
|---|---|
| `order_id` | Yoma `orderNumber` (your `order_id`) |
| `status` | `status` mapped case-insensitively, see [Statuses](#statuses) |
| `gateway_status` | Yoma `status`, trimmed, as sent, e.g. `success` |
| `gateway_reference` | Always `None`: Yoma's callback has no reference |
| `amount` | Always `None`: 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) | `SUCCESSFUL` |
| `PENDING` | `PENDING` |
| `fail` (callback), `FAILED` (status) | `FAILED` |
| `QR EXPIRED` error | `EXPIRED` |
| anything else | `UNKNOWN` |

## Access Tokens

Yoma authenticates with an OAuth token that lasts hours. The gateway keeps it in the [token cache](/python-myanmar-payments/configuration#token-cache) (passed as `token_cache=`), shares one token request between concurrent calls (a thread lock on `YomaMmqr`, an `asyncio.Lock` on `AsyncYomaMmqr`), and fetches a new token, retrying once, when Yoma answers `401`. `yoma.forget_token()` (awaited on `AsyncYomaMmqr`) drops the cached token, e.g. after rotating the client secret.

The token is cached under `myanmar-payments.yoma-mmqr.token.<sha256(base_url|client_id)>`, the same key every Laranex SDK uses, so services in different languages can share one cache, 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 | Raises | When |
|---|---|---|
| `initiate()` | `InvalidPaymentDataError` | `YomaMmqr.validate(data)` 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 |
| `renew_qr()` | `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` |
| `handle_callback()` | `SignatureVerificationError` | `X-Webhook-Secret` is missing or wrong, `orderNumber` is missing, `orderNumber` or `status` holds an object or a list, or `hashValue` doesn't match |

`AsyncYomaMmqr` raises the same errors. Yoma reports business errors with HTTP 200 and an `errorCode`; `ApiError` carries it in `gateway_code` (an empty `errorCode` counts as none) and Yoma's `errorDescription` (or `error_description`) in `gateway_message`.

### 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 `renew_qr()` |
| `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 |
