Total Lines | 40 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | package afrikpay |
||
2 | |||
3 | import ( |
||
4 | "context" |
||
5 | "encoding/json" |
||
6 | "net/http" |
||
7 | ) |
||
8 | |||
9 | // BalanceResponse is the response when querying the account balance |
||
10 | type BalanceResponse struct { |
||
11 | Code int `json:"code"` |
||
12 | Message string `json:"message"` |
||
13 | Result struct { |
||
14 | AccountDepositNumber string `json:"accountDepositNumber"` |
||
15 | AccountCommissionNumber string `json:"accountCommissionNumber"` |
||
16 | AccountDepositBalance int `json:"accountDepositBalance"` |
||
17 | AccountCommissionBalance int `json:"accountCommissionBalance"` |
||
18 | } `json:"result"` |
||
19 | } |
||
20 | |||
21 | // Balance lists all visible accounts of the given user, and for each account show the current deposit balance, and current commission. |
||
22 | // |
||
23 | // API Docs: https://developers.afrikpay.com/devportal/apis/cc20a007-0c4f-4de8-ba1a-17ab6dec5e63/documents/default |
||
24 | func (client *Client) Balance(ctx context.Context) (*BalanceResponse, *Response, error) { |
||
25 | request, err := client.newRequest(ctx, http.MethodPost, "/api/oss/balance/partner/v1", nil) |
||
26 | if err != nil { |
||
27 | return nil, nil, err |
||
28 | } |
||
29 | |||
30 | response, err := client.do(request) |
||
31 | if err != nil { |
||
32 | return nil, response, err |
||
33 | } |
||
34 | |||
35 | balance := new(BalanceResponse) |
||
36 | if err = json.Unmarshal(*response.Body, &balance); err != nil { |
||
37 | return nil, response, err |
||
38 | } |
||
39 | |||
40 | return balance, response, nil |
||
41 | } |
||
42 |