-
Notifications
You must be signed in to change notification settings - Fork 0
/
api_utilities.go
68 lines (55 loc) · 1.91 KB
/
api_utilities.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package client
import (
"context"
"fmt"
"net/http"
)
type UtilityPaymentInput struct {
TransactionID string `json:"transid"`
UtilityCode string `json:"utilitycode"`
UtilityReference string `json:"utilref"`
Amount float64 `json:"amount"`
Vendor string `json:"vendor"`
Pin string `json:"pin"`
Phone string `json:"msisdn"`
}
// UtilityPayment process payment for a particular payment service.
func (cln *Client) UtilityPayment(ctx context.Context, body UtilityPaymentInput) (Response, error) {
url := fmt.Sprintf("%s/%s/utilitypayment/process", cln.host, version)
var resp Response
if err := cln.do(ctx, http.MethodPost, url, body, &resp); err != nil {
return Response{}, err
}
return resp, nil
}
func (cln *Client) UtilityLookup(ctx context.Context, utilityCode, utilityRef, transactionID string) (Response, error) {
url := fmt.Sprintf("%s/%s/utilitypayment/lookup?utilitycode=%s&utilityref=%s&transid=%s", cln.host, version, utilityCode, utilityRef, transactionID)
var body = struct {
TransactionID string `json:"transid"`
UtilityCode string `json:"utilitycode"`
UtilityReference string `json:"utilref"`
}{
TransactionID: transactionID,
UtilityCode: utilityCode,
UtilityReference: utilityRef,
}
var resp Response
if err := cln.do(ctx, http.MethodGet, url, body, &resp); err != nil {
return Response{}, err
}
return resp, nil
}
// UtilityPaymentStatus checks ths status of the utility payment.
func (cln *Client) UtilityPaymentStatus(ctx context.Context, trasactionID string) (Response, error) {
url := fmt.Sprintf("%s/%s/utilitypayment/query?transid=%s", cln.host, version, trasactionID)
var body = struct {
TransactionID string `json:"transid"`
}{
TransactionID: trasactionID,
}
var resp Response
if err := cln.do(ctx, http.MethodGet, url, body, &resp); err != nil {
return Response{}, err
}
return resp, nil
}