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 *BalanceResponseResult `json:"result"` |
14
|
|
|
} |
15
|
|
|
|
16
|
|
|
// BalanceResponseResult contains the result of the balance response |
17
|
|
|
type BalanceResponseResult struct { |
18
|
|
|
AccountDepositNumber string `json:"accountDepositNumber"` |
19
|
|
|
AccountCommissionNumber string `json:"accountCommissionNumber"` |
20
|
|
|
AccountDepositBalance int `json:"accountDepositBalance"` |
21
|
|
|
AccountCommissionBalance int `json:"accountCommissionBalance"` |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
// Balance lists all visible accounts of the given user, and for each account show the current deposit balance, and current commission. |
25
|
|
|
// |
26
|
|
|
// API Docs: https://developers.afrikpay.com/devportal/apis/cc20a007-0c4f-4de8-ba1a-17ab6dec5e63/documents/default |
27
|
|
|
func (client *Client) Balance(ctx context.Context) (*BalanceResponse, *Response, error) { |
28
|
|
|
request, err := client.newRequest(ctx, http.MethodPost, "/api/oss/balance/partner/v1", nil) |
29
|
|
|
if err != nil { |
30
|
|
|
return nil, nil, err |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
response, err := client.do(request) |
34
|
|
|
if err != nil { |
35
|
|
|
return nil, response, err |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
balance := new(BalanceResponse) |
39
|
|
|
if err = json.Unmarshal(*response.Body, &balance); err != nil { |
40
|
|
|
return nil, response, err |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
return balance, response, nil |
44
|
|
|
} |
45
|
|
|
|