Skip to content

Errors ​

Every error the package returns for a payment problem is a pointer to one of four structs in the root package, each implementing the myanmarpayments.PaymentError interface. Match them with errors.As:

go
payment, err := kbz.PWA(ctx, data)
if err != nil {
	var (
		invalidErr *myanmarpayments.InvalidPaymentDataError
		apiErr     *myanmarpayments.APIError
	)
	switch {
	case errors.As(err, &invalidErr):
		return fmt.Errorf("check the order: %v", invalidErr.Errors)
	case errors.As(err, &apiErr):
		return fmt.Errorf("KBZ said %s: %s",
			apiErr.GatewayCode, apiErr.GatewayMessage)
	default:
		return err
	}
}
TypeReturned when
*InvalidPaymentDataErrorPayment data breaks the gateway's documented rules, or ParseAmount gets bad input. Returned 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 (… 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
*ConfigurationErrorA gateway setting (URLs, time to live and Yoma's webhook secret included) is missing or blank, or a time setting is out of range

To match any of the four, use the interface:

go
var paymentErr myanmarpayments.PaymentError
if errors.As(err, &paymentErr) {
	log.Printf("payment failed: %v", paymentErr)
}

Every message starts with myanmarpayments: , the Go convention; the rest matches the other Laranex SDKs.

InvalidPaymentDataError ​

FieldTypeDescription
Errorsmap[string]stringField name to message, keyed by the payment data's camelCase field names, e.g. {"amount": "Wave Pay does not accept decimal amounts; …"}. Wave item errors use items.0.amount keys

err.Error() is myanmarpayments: Invalid payment data: followed by the messages, in field-name order.

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.

APIError ​

FieldTypeDescription
MessagestringWhat failed, e.g. KBZ Pay precreate failed: [ORDER_ID_USED] Duplicate order
GatewayCodestringThe gateway's own error code, e.g. ORDER_ID_USED, 09, PAYMENT ALREADY EXISTS
GatewayMessagestringThe gateway's own error message
HTTPStatusintThe response status, 0 when no response was received
Rawmap[string]anyThe decoded response body
ErrerrorThe underlying network error, if any; returned by Unwrap()

When the gateway sends an error code without a message, Message ends with the bracketed code, e.g. KBZ Pay precreate failed: [ORDER_ID_USED]. The default HTTP client never follows redirects: a 3xx answer is an *APIError like any other non-2xx one. For a call that could not reach the gateway, Message is Could not reach <url>: … and Err is the error from the HTTPDoer, so errors.Is(err, context.DeadlineExceeded) works for timed-out calls.

ErrCallbackBodyTooLarge ​

NewCallbackRequestFromHTTP reads at most myanmarpayments.MaxCallbackBodyBytes (64 KiB) and returns an error wrapping myanmarpayments.ErrCallbackBodyTooLarge for a larger body, without reading past the limit. It is a plain sentinel, not one of the four types above: test it with errors.Is(err, myanmarpayments.ErrCallbackBodyTooLarge) and answer 413.

SignatureVerificationError ​

FieldTypeDescription
MessagestringWhat failed
Rawmap[string]anyThe unverified payload, for logging only. Never act on it

ConfigurationError ​

FieldTypeDescription
Gatewaystringe.g. kbz_pay
KeystringThe setting, e.g. app_key
Invalidbooltrue when the setting is set but out of range: a time setting that is not a whole number from 1 to 2147483647, or a KBZ Pay time to live outside 1 to 120
RequirementstringWhat a valid value is, used in the message when Invalid; empty means PositiveWholeNumber (a whole number greater than 0); KBZ Pay's time to live uses kbzpay.TimeToLiveRequirement (a whole number from 1 to 120)

err.Error() is e.g. myanmarpayments: The kbz_pay configuration is missing [app_key]., or myanmarpayments: The kbz_pay configuration [timeout_in_seconds] must be a whole number greater than 0. for a time setting. Returned by each gateway's New, and by the payments.Gateways methods when a gateway is used without configuration.