Skip to content

Errors ​

Every error the package raises extends PaymentError (which extends Exception). Catch them with except:

python
from python_myanmar_payments import ApiError, InvalidPaymentDataError

try:
    payment = kbz.pwa(data)
except InvalidPaymentDataError as error:
    raise ValueError(f"check the order: {dict(error.errors)}") from error
except ApiError as error:
    raise RuntimeError(
        f"KBZ said {error.gateway_code}: {error.gateway_message}"
    ) from error
ClassRaised when
InvalidPaymentDataErrorPayment data breaks the gateway's documented rules, or Amount.kyat / Amount.parse / Amount.of get bad input. Raised before any request is sent
ApiErrorThe gateway rejected the request, answered with an error (including errors sent with HTTP 200), or could not be reached
SignatureVerificationErrorA callback, return redirect or gateway response fails signature verification
ConfigurationErrorA gateway setting is missing or blank, or a time setting is not a whole number greater than 0

InvalidPaymentDataError ​

FieldTypeDescription
errorsMapping[str, str]A read-only mapping of field name to message, keyed by the payment data's snake_case field names, e.g. {"amount": "Wave Money does not accept decimal amounts; …"}. Wave item errors use items.0.amount keys

str(error) is Invalid payment data: followed by the messages, in field-name order.

ApiError ​

FieldTypeDescription
str(error)strWhat failed
gateway_codestr | NoneThe gateway's own error code, e.g. ORDER_ID_USED, 09, PAYMENT ALREADY EXISTS
gateway_messagestr | NoneThe gateway's own error message
http_statusintThe response status, 0 when no response was received
rawMapping[str, Any]The decoded response body, JSON numbers as their exact text ({} when there was none)
__cause__BaseException | NoneThe underlying network error, if any

When the gateway sends an error code without a message, str(error) ends with the bracketed code, e.g. KBZ Pay precreate failed: [ORDER_ID_USED]. For a call that could not reach the gateway, str(error) is Could not reach <url>: … and __cause__ is the httpx error, e.g. an httpx.ConnectError or httpx.TimeoutException.

SignatureVerificationError ​

FieldTypeDescription
str(error)strWhat failed
rawMapping[str, Any]The unverified payload, for logging only. Never act on it

ConfigurationError ​

FieldTypeDescription
gatewaystre.g. kbz_pay
keystrThe setting, e.g. app_key

str(error) is e.g. The kbz_pay configuration is missing [app_key]., or The kbz_pay configuration [timeout_in_seconds] must be a whole number greater than 0. for a time setting. Raised by each config class (and so by each gateway's from_env()), and by MyanmarPayments and AsyncMyanmarPayments when a gateway is used without configuration.

Released under the MIT License, except where a package says otherwise.