1
|
|
|
package afrikpay |
2
|
|
|
|
3
|
|
|
import "net/http" |
4
|
|
|
|
5
|
|
|
// Biller is the type of bill we want to pay |
6
|
|
|
type Biller string |
7
|
|
|
|
8
|
|
|
const ( |
9
|
|
|
// BillerEneoPostpay is used for postpaid bills of ENEO |
10
|
|
|
BillerEneoPostpay = Biller("eneopostpay") |
11
|
|
|
// BillerEneoPrepay is used for postpaid bills of ENEO |
12
|
|
|
BillerEneoPrepay = Biller("eneoprepay") |
13
|
|
|
// BillerCamwater is used for postpaid bills of Cameroon Water Utilities Corporation |
14
|
|
|
BillerCamwater = Biller("camwater") |
15
|
|
|
// BillerCanal is used for postpaid bills of canal+ subscriptions |
16
|
|
|
BillerCanal = Biller("canal") |
17
|
|
|
// BillerUDS is used for postpaid bills of the University of Dschang |
18
|
|
|
BillerUDS = Biller("uds") |
19
|
|
|
) |
20
|
|
|
|
21
|
|
|
// string converts the Biller to a string |
22
|
|
|
func (biller Biller) string() string { |
23
|
|
|
return string(biller) |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
// BillSMS determines if we want to receive a notification via SMS |
27
|
|
|
type BillSMS string |
28
|
|
|
|
29
|
|
|
const ( |
30
|
|
|
// BillSMSEnabled means you will receive a notification via SMS |
31
|
|
|
BillSMSEnabled = BillSMS("yes") |
32
|
|
|
// BillSMSDisabled means you will not receive a notification via SMS |
33
|
|
|
BillSMSDisabled = BillSMS("no") |
34
|
|
|
) |
35
|
|
|
|
36
|
|
|
// string converts the BillSMS to a string |
37
|
|
|
func (sms *BillSMS) string() string { |
38
|
|
|
if sms == nil { |
39
|
|
|
return string(BillSMSDisabled) |
40
|
|
|
} |
41
|
|
|
return string(*sms) |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
// Pointer converts BillSMS to *BillSMS |
45
|
|
|
func (sms BillSMS) Pointer() *BillSMS { |
46
|
|
|
return &sms |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
// BillPayParams parameters for bill payment request |
50
|
|
|
type BillPayParams struct { |
51
|
|
|
Biller Biller |
52
|
|
|
BillID string |
53
|
|
|
Mode Mode |
54
|
|
|
Amount *string |
55
|
|
|
Provider *string |
56
|
|
|
Account *string |
57
|
|
|
Mobile *string |
58
|
|
|
Code *string |
59
|
|
|
SMS *BillSMS |
60
|
|
|
ProcessingNumber *string |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
// BillPayResponse is returned from bill pay/status api requests |
64
|
|
|
type BillPayResponse struct { |
65
|
|
|
Code int `json:"code"` |
66
|
|
|
Message string `json:"message"` |
67
|
|
|
Result *BillTransaction `json:"result,omitempty"` |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
// BillTransaction is the details for a bill payment transaction |
71
|
|
|
type BillTransaction struct { |
72
|
|
|
OperatorID string `json:"operatorid"` |
73
|
|
|
TransactionID string `json:"txnid"` |
74
|
|
|
Status string `json:"status"` |
75
|
|
|
Date string `json:"date"` |
76
|
|
|
ReferenceID interface{} `json:"referenceid"` |
77
|
|
|
ProcessingNumber string `json:"processingnumber"` |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
// IsSuccessful determines if the transaction was successful |
81
|
|
|
func (response BillPayResponse) IsSuccessful() bool { |
82
|
|
|
return response.Code == http.StatusOK |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
// BillAmountResponse is returned from bill amount api requests |
86
|
|
|
type BillAmountResponse struct { |
87
|
|
|
Code int `json:"code"` |
88
|
|
|
Message string `json:"message"` |
89
|
|
|
Result *int `json:"result,omitempty"` |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
// IsSuccessful determines if the transaction was successful |
93
|
|
|
func (response BillAmountResponse) IsSuccessful() bool { |
94
|
|
|
return response.Code == http.StatusOK && response.Result != nil && *response.Result > 1000 |
95
|
|
|
} |
96
|
|
|
|