Passed
Push — main ( 50455e...dee0b0 )
by Acho
01:58
created

afrikpay.*Client.Balance   A

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  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