1
|
|
|
package flutterwave |
2
|
|
|
|
3
|
|
|
import ( |
4
|
|
|
"context" |
5
|
|
|
"encoding/json" |
6
|
|
|
"fmt" |
7
|
|
|
"net/http" |
8
|
|
|
) |
9
|
|
|
|
10
|
|
|
// transactionsService is the API client for the `/v3/transactions` endpoint |
11
|
|
|
type transactionsService service |
12
|
|
|
|
13
|
|
|
// Verify the final status of a transaction |
14
|
|
|
// |
15
|
|
|
// API Docs: https://developer.flutterwave.com/reference/endpoints/transactions |
16
|
|
|
func (service *transactionsService) Verify(ctx context.Context, transactionID int64) (*TransactionResponse, *Response, error) { |
17
|
|
|
uri := fmt.Sprintf("/v3/transactions/%d/verify", transactionID) |
18
|
|
|
|
19
|
|
|
request, err := service.client.newRequest(ctx, http.MethodGet, uri, nil) |
20
|
|
|
if err != nil { |
21
|
|
|
return nil, nil, err |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
response, err := service.client.do(request) |
25
|
|
|
if err != nil { |
26
|
|
|
return nil, response, err |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
var data TransactionResponse |
30
|
|
|
if err = json.Unmarshal(*response.Body, &data); err != nil { |
31
|
|
|
return nil, response, err |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
return &data, response, nil |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
// Refund a transaction |
38
|
|
|
// |
39
|
|
|
// API Docs: https://developer.flutterwave.com/reference/endpoints/transactions/#create-a-refund |
40
|
|
|
func (service *transactionsService) Refund(ctx context.Context, transactionID int64, amount int32) (*RefundTransactionResponse, *Response, error) { |
41
|
|
|
uri := fmt.Sprintf("/v3/transactions/%d/refund", transactionID) |
42
|
|
|
|
43
|
|
|
request, err := service.client.newRequest(ctx, http.MethodPost, uri, map[string]int32{"amount": amount}) |
44
|
|
|
if err != nil { |
45
|
|
|
return nil, nil, err |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
response, err := service.client.do(request) |
49
|
|
|
if err != nil { |
50
|
|
|
return nil, response, err |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
var data RefundTransactionResponse |
54
|
|
|
if err = json.Unmarshal(*response.Body, &data); err != nil { |
55
|
|
|
return nil, response, err |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
return &data, response, nil |
59
|
|
|
} |
60
|
|
|
|