-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbills_service.go
81 lines (66 loc) · 2.34 KB
/
bills_service.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
69
70
71
72
73
74
75
76
77
78
79
80
81
package flutterwave
import (
"context"
"encoding/json"
"net/http"
)
// billsService is the API client for the `/gateway` endpoint
type billsService service
// CreatePayment creates bill payments.
//
// API Docs: https://developer.flutterwave.com/reference/create-a-bill-payment
func (service *billsService) CreatePayment(ctx context.Context, payload *BillsCreatePaymentRequest) (*BillsCreatePaymentResponse, *Response, error) {
request, err := service.client.newRequest(ctx, http.MethodPost, "/v3/bills", payload)
if err != nil {
return nil, nil, err
}
response, err := service.client.do(request)
if err != nil {
return nil, response, err
}
var data BillsCreatePaymentResponse
if err = json.Unmarshal(*response.Body, &data); err != nil {
return nil, response, err
}
return &data, response, nil
}
// Validate validates services like DStv smartcard number, Meter number etc.
//
// API Docs: https://developer.flutterwave.com/reference/validate-bill-service
func (service *billsService) Validate(ctx context.Context, itemCode string, billerCode string, customer string) (*BillsValidateResponse, *Response, error) {
request, err := service.client.newRequest(ctx, http.MethodGet, "/v3/bill-items/"+itemCode+"/validate", nil)
if err != nil {
return nil, nil, err
}
request = service.client.addURLParams(request, map[string]string{
"code": billerCode,
"customer": customer,
})
response, err := service.client.do(request)
if err != nil {
return nil, response, err
}
var data BillsValidateResponse
if err = json.Unmarshal(*response.Body, &data); err != nil {
return nil, response, err
}
return &data, response, nil
}
// GetStatusVerbose gets the verbose status of a bill payment.
//
// API Docs: https://developer.flutterwave.com/reference/get-status-of-a-bill-payment
func (service *billsService) GetStatusVerbose(ctx context.Context, transactionReference string) (*BillsStatusVerboseResponse, *Response, error) {
request, err := service.client.newRequest(ctx, http.MethodGet, "/v3/bills/"+transactionReference, map[string]int{"verbose": 1})
if err != nil {
return nil, nil, err
}
response, err := service.client.do(request)
if err != nil {
return nil, response, err
}
var data BillsStatusVerboseResponse
if err = json.Unmarshal(*response.Body, &data); err != nil {
return nil, response, err
}
return &data, response, nil
}