Skip to content

Errors ​

Gateways return the SDK's typed errors from github.com/laranex/go-myanmar-payments/v4. Each implements myanmarpayments.PaymentError, so one errors.As covers the package; match a single type with errors.As too.

ErrorReturned when
*InvalidPaymentDataErrorPayment data has values the gateway would reject
*APIErrorA gateway rejects a request, answers with an error (including errors sent with HTTP 200), or cannot be reached
*SignatureVerificationErrorA callback, return redirect or gateway response fails signature verification, or its signed values are malformed (an AYA Pay value holding :, a CyberSource signed_field_names that doesn't sign itself or an unknown decision, a Wave Pay amount or ID out of format, a Wave Pay Mini App callback with an empty orderId or merchantRefId or a non-whole amount: Wave Pay Mini App callback is malformed.)
*ConfigurationErrorA gateway is requested without a setting it needs (URLs, time to live and Yoma's webhook secret included), or a time setting is out of range
go
var paymentErr myanmarpayments.PaymentError
if errors.As(err, &paymentErr) {
	log.Printf("payment failed: %v", paymentErr)
}

The package adds its own sentinel errors; match them with errors.Is:

ErrorReturned when
payments.ErrUnknownGatewayManager.Gateway(), Manager.HandleCallback() or Manager.HandleCallbackFromContext() gets a name other than kbz-pay, wave-pay, wave-pay-mini-app, aya-pay, yoma-mmqr or cyber-source
payments.ErrCallbackURLRequiredManager.HandleCallback() gets wave-pay-mini-app, or the handler Manager.Gateway("wave-pay-mini-app") returns is used with an empty CallbackURL: verify with HandleCallbackFromContext() or WavePayMiniApp().HandleCallback(request, callbackURL)
payments.ErrFormRouteDisabledAutoSubmitURL() is called while form_route.enabled is false
payments.ErrCryptNotAvailableAutoSubmitURL() is called without the crypt facade
payments.ErrInvalidFormLinkManager.ResolveFormPayment() gets a tampered, foreign or expired link
payments.ErrCallbackBodyTooLargeCallbackRequestFromContext() or Manager.HandleCallbackFromContext() gets a body (or rebuilt form) larger than payments.MaxCallbackBodyBytes (64 KiB)

InvalidPaymentDataError ​

go
import (
	"errors"
	"fmt"

	myanmarpayments "github.com/laranex/go-myanmar-payments/v4"
	"github.com/laranex/go-myanmar-payments/v4/kbzpay"
)

_, err := kbz.PWA(ctx, kbzpay.PaymentData{
	OrderID:     "ORDER-1",
	Amount:      myanmarpayments.Kyat(0),
	CallbackURL: "https://shop.test/payments/kbz/callback",
})

var invalid *myanmarpayments.InvalidPaymentDataError
if errors.As(err, &invalid) {
	fmt.Println(invalid.Errors)
	// map[amount:The amount field must be greater than 0.
	//     orderId:The orderId field may only contain letters, numbers and underscores.]
}

Validation runs inside the gateway call, before any request is sent. err.Error() is myanmarpayments: Invalid payment data: followed by the messages, in field-name order.

APIError ​

FieldTypeDescription
MessagestringWhat failed
GatewayCodestringThe gateway's error code, e.g. ORDER_ID_USED, 09, PAYMENT ALREADY EXISTS
GatewayMessagestringThe gateway's error message
HTTPStatusintHTTP status of the response, 0 when no response was received
Rawmap[string]anyThe decoded response body
ErrerrorThe transport error, returned by Unwrap()

Message describes what failed, e.g. KBZ Pay precreate failed: [ORDER_ID_USED] Duplicate order; when the gateway sends a code without a message, it ends with the bracketed code. For a call that could not reach the gateway, Message is Could not reach <url>: … and Unwrap() returns the underlying transport error.

SignatureVerificationError ​

Message says what failed; Raw holds the unverified payload. Log it, never act on it.

ConfigurationError ​

The message names the gateway and the key, e.g. myanmarpayments: The wave_pay configuration is missing [merchant_id]., or myanmarpayments: The kbz_pay configuration [timeout_in_seconds] must be a whole number greater than 0. for a time setting, with Invalid set. Gateway, Key, Invalid and Requirement hold the details; KBZ Pay's time to live reads The kbz_pay configuration [time_to_live_in_minutes] must be a whole number from 1 to 120. AutoSubmitURL returns it with form_route and ttl_minutes when the form link lifetime is missing or invalid.