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