forked from vonmutinda/chapa
-
Notifications
You must be signed in to change notification settings - Fork 2
/
data.go
185 lines (162 loc) · 6.15 KB
/
data.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
package chapa
import (
validation "github.com/go-ozzo/ozzo-validation/v4"
)
type (
PaymentRequest struct {
Amount float64 `json:"amount"`
Currency string `json:"currency"`
Email string `json:"email"`
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
Phone string `json:"phone"`
CallbackURL string `json:"callback_url"`
TransactionRef string `json:"tx_ref"`
Customization map[string]interface{} `json:"customization"`
}
PaymentResponse struct {
Message string `json:"message"`
Status string `json:"status"`
Data struct {
CheckoutURL string `json:"checkout_url"`
}
}
VerifyResponse struct {
Message string `json:"message"`
Status string `json:"status"`
Data struct {
TransactionFee float64 `json:"charge"`
}
}
// BankTransfer is an object used in bank transfer.
BankTransfer struct {
// AccountName is the recipient Account Name matches on their bank account.
AccountName string `json:"account_name"`
// AccountNumber is the recipient Account Number.
AccountNumber string `json:"account_number"`
// Amount is the amount to be transferred to the recipient.
Amount float64 `json:"amount"`
// Currency is the currency for the Transfer. Expected value is ETB.
Currency string `json:"currency"`
// Reference is merchant’s uniques reference for the transfer,
// it can be used to query for the status of the transfer.
Reference string `json:"reference"`
// BankCode is the recipient bank code.
// You can see a list of all the available banks and their codes from the get banks endpoint.
BankCode string `json:"bank_code"`
}
BankTransferResponse struct {
Message string `json:"message"`
Status string `json:"status"`
Data string `json:"data"`
}
Transaction struct {
Status TransactionStatus `json:"status"`
RefID string `json:"ref_id"`
Type string `json:"type"`
CreatedAt string `json:"created_at"`
Currency string `json:"currency"`
Amount string `json:"amount"`
Charge string `json:"charge"`
TransID string `json:"trans_id"` // Use pointer to handle null values
PaymentMethod string `json:"payment_method"`
Customer *Customer `json:"customer"`
}
Customer struct {
ID int64 `json:"id"`
Email *string `json:"email"`
FirstName *string `json:"first_name"`
LastName *string `json:"last_name"`
Mobile *string `json:"mobile"`
}
Pagination struct {
PerPage int `json:"per_page"`
CurrentPage int `json:"current_page"`
FirstPageURL string `json:"first_page_url"`
NextPageURL *string `json:"next_page_url"`
PrevPageURL *string `json:"prev_page_url"`
}
TransactionList struct {
Transactions []Transaction `json:"transactions"`
Pagination Pagination `json:"pagination"`
}
TransactionsResponse struct {
Message string `json:"message"`
Status string `json:"status"`
Data TransactionList `json:"data"`
}
CheckoutForm struct {
Amount float64 `json:"amount"`
Currency string `json:"currency"`
}
TransactionStatus string
Currency string
Bank struct {
ID int64 `json:"id"`
Swift string `json:"swift"`
Name string `json:"name"`
AcctLength int64 `json:"acct_length"`
CountryID int64 `json:"country_id"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
IsRTGS *int64 `json:"is_rtgs"`
IsMobileMoney *int64 `json:"is_mobilemoney"`
Currency Currency `json:"currency"`
}
BanksResponse struct {
Message string `json:"message"`
Data []Bank `json:"data"`
}
BulkData struct {
AccountName string `json:"account_name"`
AccountNumber string `json:"account_number"`
Amount int64 `json:"amount"`
Reference string `json:"reference"`
BankCode string `json:"bank_code"`
}
BulkTransferRequest struct {
Title string `json:"title"`
Currency string `json:"currency"`
BulkData []BulkData `json:"bulk_data"` // Slice of BulkData for multiple entries
}
BulkTransferResponseData struct {
ID int `json:"id"`
CreatedAt string `json:"created_at"`
}
BulkTransferResponse struct {
Message string `json:"message"`
Status string `json:"status"`
Data BulkTransferResponseData `json:"data"`
}
)
const (
FailedTransactionStatus TransactionStatus = "failed"
PendingTransactionStatus TransactionStatus = "pending"
SuccessTransactionStatus TransactionStatus = "success"
ETB Currency = "ETB"
USD Currency = "USD"
)
func (p PaymentRequest) Validate() error {
return validation.ValidateStruct(&p,
validation.Field(&p.TransactionRef, validation.Required.Error("transaction reference is required")),
validation.Field(&p.Currency, validation.Required.Error("currency is required")),
validation.Field(&p.Amount, validation.Required.Error("amount is required")),
)
}
func (t BankTransfer) Validate() error {
return validation.ValidateStruct(&t,
validation.Field(&t.AccountName, validation.Required.Error("account name is required")),
validation.Field(&t.AccountNumber, validation.Required.Error("account number is required")),
validation.Field(&t.Amount, validation.Required.Error("amount is required")),
validation.Field(&t.Currency, validation.Required.Error("currency is required")),
validation.Field(&t.Reference, validation.Required.Error("reference is required")),
validation.Field(&t.BankCode, validation.Required.Error("bank code is required")),
)
}
func (t BulkTransferRequest) Validate() error {
return validation.ValidateStruct(&t,
validation.Field(&t.Title, validation.Required.Error("title of the bulk transfer is required")),
validation.Field(&t.Currency, validation.Required.Error("currency is required")),
validation.Field(&t.BulkData, validation.NilOrNotEmpty.Error("at least one account is required")),
)
}