Total Lines | 41 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | package flutterwave |
||
2 | |||
3 | import ( |
||
4 | "context" |
||
5 | "encoding/json" |
||
6 | "net/http" |
||
7 | "strconv" |
||
8 | ) |
||
9 | |||
10 | // transfersService is the API client for the `/v3/transfers` endpoint |
||
11 | type transfersService service |
||
12 | |||
13 | // Estimate the Transfer Rate of a transaction |
||
14 | // |
||
15 | // API Docs: https://developer.flutterwave.com/reference/check-transfer-rates |
||
16 | func (service *transfersService) Rate(ctx context.Context, amount int, destination_currency, source_currency string) (*TransferRateResponse, *Response, error) { |
||
17 | uri := "/v3/transfers/rates" |
||
18 | |||
19 | request, err := service.client.newRequest(ctx, http.MethodGet, uri, nil) |
||
20 | if err != nil { |
||
21 | return nil, nil, err |
||
22 | } |
||
23 | |||
24 | // Adding the parameters |
||
25 | requestWithParams := service.client.addURLParams(request, map[string]string{ |
||
26 | "amount": strconv.Itoa(amount), |
||
27 | "destination_currency": destination_currency, |
||
28 | "source_currency": source_currency, |
||
29 | }) |
||
30 | |||
31 | response, err := service.client.do(requestWithParams) |
||
32 | if err != nil { |
||
33 | return nil, response, err |
||
34 | } |
||
35 | |||
36 | var data TransferRateResponse |
||
37 | if err = json.Unmarshal(*response.Body, &data); err != nil { |
||
38 | return nil, response, err |
||
39 | } |
||
40 | |||
41 | return &data, response, nil |
||
42 | |||
44 |