AYA Pay
The AYA Payment Gateway is one hosted checkout for AYA Pay, other wallets (KBZ Pay, WavePay, UAB Pay, CB Pay…) and cards (VISA, Mastercard, JCB).
| Call | What it does | Returns |
|---|---|---|
aya.services() | List the channels enabled for your account | list[AyaPayService] |
aya.initiate(data) | Signed form posted to AYA | FormPayment |
aya.status(order_id) | Enquire an order | PaymentStatusResult |
aya.handle_callback(request) | Verify the backend callback | PaymentCallback |
aya.verify_redirect(request) | Verify the customer's return | PaymentCallback |
AsyncAyaPay has the same methods: await services() and status(); initiate(), handle_callback() and verify_redirect() stay plain calls.
Responses shows what AYA Pay puts in each result.
How it works
AYA posts the result to your callback URL and also signs the query string it adds when sending the customer back.
Channels and Methods
channel is a lowercase key such as aya_pay, kbz_pay or visa; method is how the customer pays through it. Which ones you have depends on your merchant account, so list them:
from python_myanmar_payments import AyaPay, AyaPayConfig, AyaPayMethod
aya = AyaPay(
AyaPayConfig(
app_key="...",
app_secret="...",
base_url=AyaPayConfig.PRODUCTION_URL,
)
)
for service in aya.services():
# service.name: "AYA Pay"
# service.key: "aya_pay", pass it as channel
# service.image_url: the channel's logo
# service.methods: (AyaPayMethod.QR, AyaPayMethod.NOTI)
if service.supports(AyaPayMethod.QR):
... # offer the QR methodMethods AYA lists that this package doesn't know yet are kept in service.unknown_methods; data and each service's methods are read only when they are JSON lists, and method entries that aren't text, numbers or booleans are skipped.
AyaPayMethod | Value | Customer |
|---|---|---|
AyaPayMethod.WEB | WEB | Pays on a hosted web page (cards) |
AyaPayMethod.QR | QR | Scans a QR with the wallet app |
AyaPayMethod.NOTI | NOTI | Approves a push notification in the wallet app |
Initiating a Payment
from django.http import HttpResponse
from django.shortcuts import get_object_or_404
from python_myanmar_payments import AyaPayMethod, AyaPayPaymentData
from shop.models import Order
def aya_checkout(request, order_id: int):
order = get_object_or_404(Order, pk=order_id)
data = AyaPayPaymentData(
order_id=f"ORDER_{order.id}",
amount=10000,
channel="aya_pay",
method=AyaPayMethod.QR,
return_url="https://shop.test/payments/aya/return",
description=f"Order #{order.id}",
)
payment = aya.initiate(data)
# The page posts the signed form to AYA on load.
return HttpResponse(payment.to_html())AyaPayPaymentData
| Field | Type | Required | Rules |
|---|---|---|---|
order_id | str | Yes | Unique, 6 to 40 characters (merchOrderId), no : |
amount | Amount | int | str | Decimal | Yes | Whole kyat, greater than 0, e.g. 10000 or Amount.kyat(10000). AYA documents no decimals and only accepts MMK (104) |
channel | str | Yes | A key from services() |
method | AyaPayMethod | Yes | AyaPayMethod.WEB, .QR or .NOTI (or the strings "WEB", "QR", "NOTI") |
return_url | str | No | Absolute http or https URL. Unset uses the URL registered with AYA |
description | str | No | Shown to the customer, no : |
user_refs | Sequence[str] | No | Up to 5 of your own values, as a list or tuple, echoed back in the callback, none containing : |
AYA joins the signed values with :, so order_id, description and user_refs can't contain one (The order_id field must not contain ":".); a : in any user ref is reported once, under user_refs.
Handling Callbacks
AYA posts to the callback URL registered with them.
from django.http import HttpResponse
from django.views.decorators.csrf import csrf_exempt
from python_myanmar_payments import CallbackRequest, SignatureVerificationError
# POST /payments/aya/callback
@csrf_exempt
def aya_callback(request):
callback_request = CallbackRequest(
body=request.body,
headers=request.headers,
query=request.META.get("QUERY_STRING", ""),
)
try:
callback = aya.handle_callback(callback_request)
except SignatureVerificationError:
return HttpResponse("invalid callback", status=400)
if callback.is_successful():
# callback.order_id is your merchOrderId
# callback.gateway_reference is AYA's tranId
...
ack = callback.acknowledgement
return HttpResponse(ack.body, status=ack.status, headers=ack.headers)AYA signs only the fields present in its payload: fields AYA leaves out are skipped when verifying, and the rest are verified in the order the specification lists.
Because AYA joins the signed values with :, a matching checkSum alone could let a value be re-split into other fields. A payload is therefore only accepted when, besides the checksum:
- no signed value contains
:, exceptdateTime, which must be empty or have the formYYYY-MM-DD HH:MM:SS; merchOrderIdis present, and so istranIdwhenstatusCodeis00(a failed, rejected or pending payload may leave it out);amountis a decimal, e.g.10000or10000.00;- the currency code is
104(MMK); statusCodeis two digits.
Anything else raises SignatureVerificationError: AYA Pay callback checksum verification failed. when payload or checkSum is missing or not a string, the payload can't be decoded, holds a nested value or the checksum doesn't match, and AYA Pay callback payload is malformed. when a correctly signed payload breaks these rules (redirect or enquiry response instead of callback for the return page and status()).
The Return Page
AYA signs the query string it adds when sending the customer back, so the return page can show the right message:
from django.http import HttpResponse
from python_myanmar_payments import CallbackRequest, SignatureVerificationError
# GET /payments/aya/return
def aya_return(request):
callback_request = CallbackRequest(
body=request.body,
headers=request.headers,
query=request.META.get("QUERY_STRING", ""),
)
try:
result = aya.verify_redirect(callback_request)
except SignatureVerificationError:
return HttpResponse("invalid return", status=400)
if result.is_successful():
return HttpResponse("Thank you, your payment was received.")
return HttpResponse(f"Payment {result.status}.")payload may be standard base64 with or without its = padding; partial padding, the URL-safe alphabet, line breaks and payloads that aren't UTF-8 JSON are rejected. A + that reached you as a space (an unencoded query string) is read back as +; the checksum is still verified. Still fulfill orders from the backend callback.
Status Checks
result = aya.status(f"ORDER_{order.id}")
if result.is_successful():
# result.gateway_reference is AYA's tranId
...status() takes your order_id. An order AYA doesn't know raises ApiError (20 Transaction not found).
Responses
What AYA Pay puts in each field. See Results and PaymentCallback & Status for the full classes.
services() → list[AyaPayService]
AyaPayService is AYA-only, so it is listed in full here. It is a frozen dataclass.
| Field / Method | AYA Pay value |
|---|---|
name | AYA name, e.g. AYA Pay. Falls back to key |
key | AYA key, e.g. aya_pay, kbz_pay, visa. Pass it as channel. Always set |
image_url | AYA image_url, the channel's logo. None when AYA sends none |
methods | A tuple[AyaPayMethod, ...] of the methods this package knows, e.g. (AyaPayMethod.QR, AyaPayMethod.NOTI) |
unknown_methods | A tuple[str, ...] of methods AYA listed that this package doesn't know yet. Usually () |
supports(method) | Whether methods contains method (an AyaPayMethod or its string) |
Entries AYA sends without a key are skipped.
initiate() → FormPayment
| Field / Method | AYA Pay value |
|---|---|
flow | PaymentFlow.FORM |
order_id | Your data.order_id |
action | {base_url}/v1/payment/request, e.g. https://pgw.ayainnovation.com/v1/payment/request |
fields | The signed fields below, in signing order. Post them unchanged |
enctype | multipart/form-data |
to_html(nonce=None) | A full HTML page that posts fields to action on load; nonce is added to its inline script |
| Form field | Value |
|---|---|
merchOrderId | data.order_id |
amount | data.amount, e.g. 10000 |
appKey | config.app_key |
timestamp | Unix time in seconds |
userRef1 … userRef5 | data.user_refs, "" when unused |
description | data.description, "" when unset |
currencyCode | 104 (MMK) |
channel | data.channel, e.g. aya_pay |
method | data.method, e.g. QR |
overrideFrontendRedirectUrl | data.return_url, "" when unset |
checkSum | HMAC-SHA256 of the values above joined with : |
FormPayment has no raw: nothing is sent to AYA until the customer's browser posts the form.
status() → PaymentStatusResult
| Field | AYA Pay value |
|---|---|
order_id | AYA merchOrderId. Always set: an enquiry payload without it fails verification |
status | statusCode mapped, see Statuses |
gateway_status | AYA statusCode, always two digits, e.g. 00 |
gateway_reference | AYA tranId. Always set when statusCode is 00; None when a payload with another status leaves it out |
amount | AYA amount, e.g. 10000 |
raw | The verified, decoded enquiry payload: merchOrderId, tranId, amount, currenyCode, statusCode, paymentCardNumber, paymentMobileNumber, cardTypeName, cardExpiryDate, nameOnCard, approvalCode, tranRef, userRef1–5, description, dateTime |
raw only has the keys AYA sent. The currency code arrives as currenyCode: AYA's payload spells it that way.
handle_callback() → PaymentCallback
| Field / Method | AYA Pay value |
|---|---|
order_id | AYA merchOrderId (your order_id) |
status | statusCode mapped, see Statuses |
gateway_status | AYA statusCode, always two digits, e.g. 00 |
gateway_reference | AYA tranId. Always set when statusCode is 00; None when a payload with another status leaves it out |
amount | AYA amount, e.g. 10000 |
raw | The verified, decoded payload, with the same keys as status() |
acknowledgement | HTTP 200, empty body, Content-Type: text/plain |
verify_redirect() → PaymentCallback
The same values as handle_callback(), read from the signed payload and checkSum AYA adds to your return URL (query string first, then the body). There is nothing to acknowledge: render your own page.
Statuses
AYA statusCode | PaymentStatus |
|---|---|
00 | SUCCESSFUL |
01 | PENDING |
02 (fail), 03 (reject) | FAILED |
04 | EXPIRED |
| anything else | UNKNOWN |
Errors
| Call | Raises | When |
|---|---|---|
initiate() | InvalidPaymentDataError | AyaPay.validate(data) fails. Nothing is signed |
services() | ApiError | AYA answers with an HTTP error or a status other than 00 |
status() | ApiError | AYA answers with an HTTP error or a status other than 00, e.g. 20 Transaction not found |
status() | SignatureVerificationError | The enquiry payload's checkSum doesn't match, or the payload is malformed (see Handling Callbacks) |
handle_callback(), verify_redirect() | SignatureVerificationError | payload or checkSum is missing, payload isn't base64 JSON, a signed field holds an object or a list, checkSum doesn't match, or the payload is malformed (see Handling Callbacks) |
AsyncAyaPay raises the same errors. ApiError carries AYA's status (e.g. 20 Transaction not found, 09 Duplicate order ID) in gateway_code and its message in gateway_message.