Skip to content

Commit

Permalink
added handling 202 (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lunatix01 authored Sep 22, 2023
1 parent cbda1ed commit 2d39433
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions fib/fib.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const (
const (
OK = 200
CREATED = 201
ACCEPTED = 202
NO_CONTENT = 204
BAD_CONTENT = 400
UNAUTHORIZED = 401
Expand Down
12 changes: 9 additions & 3 deletions fib/payment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 2d39433

Please sign in to comment.