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