Passed
Push — main ( cad01e...53329a )
by Acho
02:26
created

afrikpay.*accountService.Balance   A

Complexity

Conditions 4

Size

Total Lines 21
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 14
nop 1
dl 0
loc 21
rs 9.7
c 0
b 0
f 0
1
package afrikpay
2
3
import (
4
	"context"
5
	"encoding/json"
6
	"net/http"
7
)
8
9
// accountService is the API client for the `/api/account/` endpoint
10
type accountService service
11
12
// Balance is used for the partner to get the Balance of his account
13
//
14
// API Docs: https://developer.afrikpay.com/documentation/account/agent/balance/v2/
15
func (service *accountService) Balance(ctx context.Context) (*AccountBalanceResponse, *Response, error) {
16
	request, err := service.client.newRequest(ctx, http.MethodPost, "/api/account/agent/balance/v2/", map[string]string{
17
		"agentid":       service.client.agentID,
18
		"agentplatform": service.client.agentPlatform,
19
		"hash":          service.client.hash(service.client.agentID, service.client.apiKey),
20
	})
21
	if err != nil {
22
		return nil, nil, err
23
	}
24
25
	response, err := service.client.do(request)
26
	if err != nil {
27
		return nil, response, err
28
	}
29
30
	balance := new(AccountBalanceResponse)
31
	if err = json.Unmarshal(*response.Body, &balance); err != nil {
32
		return nil, response, err
33
	}
34
35
	return balance, response, nil
36
}
37