From 2d39433001c5ebec5999d98ddd83b60fddca2443 Mon Sep 17 00:00:00 2001 From: Aland Osman <56197620+Lunatix01@users.noreply.github.com> Date: Fri, 22 Sep 2023 13:31:21 +0300 Subject: [PATCH] added handling 202 (#42) --- fib/fib.go | 1 + fib/payment.go | 12 +++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/fib/fib.go b/fib/fib.go index 84c50fa..6f8155b 100644 --- a/fib/fib.go +++ b/fib/fib.go @@ -28,6 +28,7 @@ const ( const ( OK = 200 CREATED = 201 + ACCEPTED = 202 NO_CONTENT = 204 BAD_CONTENT = 400 UNAUTHORIZED = 401 diff --git a/fib/payment.go b/fib/payment.go index d6120df..6cac5f2 100644 --- a/fib/payment.go +++ b/fib/payment.go @@ -180,13 +180,17 @@ func (client *Client) CancelPayment(paymentID uuid.UUID) (bool, *PaymentError) { } // RefundPayment method to refund a payment returns bool, PaymentError -func (client *Client) RefundPayment(paymentID uuid.UUID) *PaymentError { +func (client *Client) RefundPayment(paymentID uuid.UUID) (bool, *PaymentError) { headers := client.buildHeaders() URL := fmt.Sprintf(client.URL+PaymentRefundPath, paymentID) - _, err := request(URL, headers, nil, nil, POST) + isRefundedAlready, err := request(URL, headers, nil, nil, POST) - return err + if err != nil { + return false, err + } + + return reflect.ValueOf(isRefundedAlready).Bool(), err } // request function used by other payment methods @@ -229,6 +233,8 @@ func request(URL string, headers map[string]string, body []byte, responseBody in switch statusCode { case OK: case CREATED: + case ACCEPTED: + return true, nil case BAD_CONTENT, NOT_FOUND: var errBody ErrorBody if err := json.Unmarshal(readableBody, &errBody); err != nil {