Skip to content

Errors ​

Every exception the package throws extends PaymentException (which extends RuntimeException), all in Laranex\PhpMyanmarPayments\Exceptions. Catch them with catch:

php
use Laranex\PhpMyanmarPayments\Exceptions\ApiException;
use Laranex\PhpMyanmarPayments\Exceptions\InvalidPaymentDataException;
use Laranex\PhpMyanmarPayments\KbzPay\KbzPayPaymentData;

try {
    $data = new KbzPayPaymentData(
        orderId: 'ORDER_1',
        amount: 10000,
        callbackUrl: 'https://shop.test/payments/kbz/callback',
    );
    $payment = $kbz->pwa($data);
} catch (InvalidPaymentDataException $e) {
    throw new DomainException(
        'check the order: '.json_encode($e->errors()),
        previous: $e,
    );
} catch (ApiException $e) {
    throw new RuntimeException(
        "KBZ said {$e->gatewayCode}: {$e->gatewayMessage}",
        previous: $e,
    );
}
ClassThrown when
InvalidPaymentDataExceptionPayment data breaks the gateway's documented rules, or Amount::kyat / Amount::parse / Amount::from get bad input. Thrown when the payment data is created, before any request is sent
ApiExceptionThe gateway rejected the request, answered with an error (including errors sent with HTTP 200), or could not be reached
SignatureVerificationExceptionA callback, return redirect or gateway response fails signature verification (... signature, hash or checksum verification failed.), or its signature matches but its signed values are malformed (Wave Pay callback is malformed., Wave Pay Mini App callback is malformed., AYA Pay {callback|redirect|enquiry response} payload is malformed., CyberSource callback is malformed.)
ConfigurationExceptionA gateway setting (URLs, time to live and Yoma's webhook secret included) is missing or blank, or a time setting is out of range

InvalidPaymentDataException ​

Property / MethodTypeDescription
errors()array<string, string>Field name to message, keyed by the payment data's camelCase parameter names, e.g. ['amount' => 'Wave Pay does not accept decimal amounts; …']. Wave item errors use items.0.amount keys

getMessage() is Invalid payment data: followed by the messages, in field-name order. A bad amount reads e.g. The amount field must be a number such as 1000 or 1000.50, got "1,000".

A URL field (callback, return and cancel URLs) is valid when it is printable ASCII with no whitespace, starts with http:// or https:// (any case) and names a host: a bracketed IP address or dot-separated labels of letters, digits and inner - (at most 63 characters each, 253 in all, one trailing dot allowed), with an optional port from 0 to 65535. Otherwise the message is The callbackUrl field must be a valid http or https URL. (for that field). A negative amount gives The amount field must not be negative.

ApiException ​

Property / MethodTypeDescription
getMessage()stringWhat failed
gatewayCode?stringThe gateway's own error code, e.g. ORDER_ID_USED, 09, PAYMENT ALREADY EXISTS
gatewayMessage?stringThe gateway's own error message
httpStatusintThe response status, 0 when no response was received
rawarrayThe decoded response body ([] when there was none)
getPrevious()?ThrowableThe underlying network error, if any

When the gateway sends an error code without a message, getMessage() ends with the bracketed code, e.g. KBZ Pay precreate failed: [ORDER_ID_USED]. Redirects are never followed: a 3xx answer is an ApiException like any other non-2xx one (the default Guzzle client, and PSR-18 sendRequest() in general, does not follow them). For a call that could not reach the gateway, getMessage() is Could not reach <url>: … and getPrevious() is the PSR-18 client's ClientExceptionInterface, e.g. Guzzle's ConnectException.

SignatureVerificationException ​

Property / MethodTypeDescription
getMessage()stringWhat failed
rawarrayThe unverified payload, for logging only. Never act on it

ConfigurationException ​

Property / MethodTypeDescription
gatewaystringe.g. kbz_pay
keystringThe setting, e.g. app_key

getMessage() 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 (at most 2147483647; a missing or blank HTTP timeout is not an error: it defaults to 30 seconds). Thrown by each config class (and so by each gateway's constructor and fromEnv()), and by MyanmarPayments when a gateway is used without configuration.