afrikpay.*Client.Balance   A
last analyzed

Complexity

Conditions 4

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 11
nop 1
dl 0
loc 17
rs 9.85
c 0
b 0
f 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  *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