Error Handling

Error handling

⚠️

PaymentError returns a pointer to a memory address, so don't use it directly to show values.

PaymentError

Returned by: CreatePayment, CheckPayment, CancelPayment, RefundPayment.

FieldDefinition
errorStandard Go error interface.
ErrorBodyAn object containing additional error details.

ErrorBody

FieldDefinition
TraceIDA unique identifier for tracing the error.
ErrorsAn array of Error objects detailing the error.

Error

FieldDefinition
CodeA machine-readable error code.
TitleThe title of the error.
DetailDetailed description of what caused the error.
error.go
client, err := fib.New(clientID, clientSecret, isTesting)
if err != nil {
    log.Fatalf("Error creating FIB client: %s - %s", err.Title, err.Description)
}
 
response, paymentErr := client.CreatePayment(500, "IQD", "http://callback.url")
if paymentErr != nil {
    log.Fatalf("Error creating payment: %s - %s", paymentErr.ErrorBody.Errors[0].Title, paymentErr.ErrorBody.Errors[0].Detail)
}
 
checkResponse, checkErr := client.CheckPayment(paymentID)
if checkErr != nil {
    log.Fatalf("Error checking payment: %s - %s", checkErr.ErrorBody.Errors[0].Title, checkErr.ErrorBody.Errors[0].Detail)
}
 
cancelSuccess, cancelErr := client.CancelPayment(paymentID)
if cancelErr != nil {
    log.Fatalf("Error canceling payment: %s - %s", cancelErr.ErrorBody.Errors[0].Title, cancelErr.ErrorBody.Errors[0].Detail)
}
 
refundErr := client.RefundPayment(paymentID)
if refundErr != nil {
    log.Fatalf("Error initiating refund: %s - %s", refundErr.ErrorBody.Errors[0].Title, refundErr.ErrorBody.Errors[0].Detail)
}