-
Notifications
You must be signed in to change notification settings - Fork 23
/
payment_transactions.go
295 lines (250 loc) · 8.17 KB
/
payment_transactions.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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
package AuthorizeCIM
import (
"encoding/json"
)
func (tranx NewTransaction) Charge() (*TransactionResponse, error) {
var new TransactionRequest
new = TransactionRequest{
TransactionType: "authCaptureTransaction",
Amount: tranx.Amount,
Payment: &Payment{
CreditCard: tranx.CreditCard,
},
BillTo: tranx.BillTo,
AuthCode: tranx.AuthCode,
}
response, err := SendTransactionRequest(new)
return response, err
}
func (tranx NewTransaction) ChargeProfile(profile Customer) (*TransactionResponse, error) {
var new TransactionRequest
new = TransactionRequest{
TransactionType: "authCaptureTransaction",
Amount: tranx.Amount,
Profile: &Profile{
CustomerProfileId: profile.ID,
PaymentProfile: &PaymentProfile{
PaymentProfileId: profile.PaymentID,
},
},
}
response, err := SendTransactionRequest(new)
return response, err
}
func (tranx NewTransaction) AuthOnly() (*TransactionResponse, error) {
var new TransactionRequest
new = TransactionRequest{
TransactionType: "authOnlyTransaction",
Amount: tranx.Amount,
Payment: &Payment{
CreditCard: tranx.CreditCard,
},
}
response, err := SendTransactionRequest(new)
return response, err
}
func (tranx NewTransaction) Refund() (*TransactionResponse, error) {
var new TransactionRequest
new = TransactionRequest{
TransactionType: "refundTransaction",
Amount: tranx.Amount,
RefTransId: tranx.RefTransId,
}
response, err := SendTransactionRequest(new)
return response, err
}
func (tranx PreviousTransaction) Void() (*TransactionResponse, error) {
var new TransactionRequest
new = TransactionRequest{
TransactionType: "voidTransaction",
RefTransId: tranx.RefId,
}
response, err := SendTransactionRequest(new)
return response, err
}
func (tranx PreviousTransaction) Capture() (*TransactionResponse, error) {
var new TransactionRequest
new = TransactionRequest{
TransactionType: "priorAuthCaptureTransaction",
RefTransId: tranx.RefId,
}
response, err := SendTransactionRequest(new)
return response, err
}
func UpdateSplitTenderGround() {
}
func DebitBankAccount() {
}
func CreditBankAccount() {
}
func ChargeTokenCard() {
}
func CreditAcceptPaymentTransaction() {
}
func GetAccessPaymentPage() {
}
func GetHostedPaymentPage() {
}
func SendTransactionRequest(input TransactionRequest) (*TransactionResponse, error) {
action := CreatePayment{
CreateTransactionRequest: CreateTransactionRequest{
MerchantAuthentication: GetAuthentication(),
TransactionRequest: input,
},
}
jsoned, err := json.Marshal(action)
if err != nil {
return nil, err
}
response, err := SendRequest(jsoned)
var dat TransactionResponse
err = json.Unmarshal(response, &dat)
if err != nil {
return nil, err
}
return &dat, err
}
type NewTransaction struct {
Amount string `json:"amount,omitempty"`
InvoiceId string `json:"invoiceId,omitempty"`
RefTransId string `json:"refTransId,omitempty"`
CreditCard CreditCard `json:"payment,omitempty"`
AuthCode string `json:"authCode,omitempty"`
BillTo *BillTo `json:"omitempty"`
}
type PreviousTransaction struct {
RefId string `json:"refTransId,omitempty"`
Amount string `json:"amount,omitempty"`
}
type TransactionResponse struct {
Response TranxResponse `json:"transactionResponse"`
MessagesResponse
}
type TranxResponse struct {
ResponseCode string `json:"responseCode"`
AuthCode string `json:"authCode"`
AvsResultCode string `json:"avsResultCode"`
CvvResultCode string `json:"cvvResultCode"`
CavvResultCode string `json:"cavvResultCode"`
TransID string `json:"transId"`
RefTransID string `json:"refTransID"`
TransHash string `json:"transHash"`
TestRequest string `json:"testRequest"`
AccountNumber string `json:"accountNumber"`
AccountType string `json:"accountType"`
Errors []struct {
ErrorCode string `json:"errorCode"`
ErrorText string `json:"errorText"`
} `json:"errors"`
TransactionMessages
TransHashSha2 string `json:"transHashSha2"`
Message TransactionMessages
}
type TransactionMessages struct {
Message []struct {
Code string `json:"code"`
Description string `json:"description"`
} `json:"messages"`
}
type Message struct {
Code string `json:"code"`
Text string `json:"text"`
}
type MerchantAuthentication struct {
Name *string `json:"name,omitempty"`
TransactionKey *string `json:"transactionKey,omitempty"`
}
type CreatePayment struct {
CreateTransactionRequest CreateTransactionRequest `json:"createTransactionRequest,omitempty"`
}
type CreateTransactionRequest struct {
MerchantAuthentication MerchantAuthentication `json:"merchantAuthentication,omitempty"`
RefID string `json:"refId,omitempty"`
TransactionRequest TransactionRequest `json:"transactionRequest,omitempty"`
}
type Payment struct {
CreditCard CreditCard `json:"creditCard,omitempty"`
}
type CreditCard struct {
CardNumber string `json:"cardNumber,omitempty"`
ExpirationDate string `json:"expirationDate,omitempty"`
CardCode string `json:"cardCode,omitempty"`
}
type LineItems struct {
LineItem []LineItem `json:"lineItem,omitempty"`
}
type LineItem struct {
ItemID string `json:"itemId,omitempty"`
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
Quantity string `json:"quantity,omitempty"`
UnitPrice string `json:"unitPrice,omitempty"`
}
type Shipping struct {
Amount string `json:"amount,omitempty"`
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
}
type Duty struct {
Amount string `json:"amount,omitempty"`
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
}
type Tax struct {
Amount string `json:"amount,omitempty"`
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
}
type Customer struct {
ID string `json:"id,omitempty"`
Email string `json:"email,omitempty"`
PaymentID string `json:"paymentId,omitempty"`
ShippingID string `json:"shippingId,omitempty"`
PhoneNumber string `json:"phoneNumber,omitempty"`
}
type TransactionSettings struct {
Setting Setting `json:"setting,omitempty"`
}
type Setting struct {
SettingName string `json:"settingName,omitempty"`
SettingValue string `json:"settingValue,omitempty"`
}
type UserFields struct {
UserField []UserField `json:"userField,omitempty"`
}
type UserField struct {
Name string `json:"name,omitempty"`
Value string `json:"value,omitempty"`
}
type TransactionRequest struct {
TransactionType string `json:"transactionType,omitempty"`
Amount string `json:"amount,omitempty"`
Payment *Payment `json:"payment,omitempty"`
RefTransId string `json:"refTransId,omitempty"`
AuthCode string `json:"authCode,omitempty"`
Profile *Profile `json:"profile,omitempty"`
LineItems *LineItems `json:"lineItems,omitempty"`
//Tax Tax `json:"tax,omitempty"`
//Duty Duty `json:"duty,omitempty"`
//Shipping Shipping `json:"shipping,omitempty"`
//PoNumber string `json:"poNumber,omitempty"`
//Customer Customer `json:"customer,omitempty"`
BillTo *BillTo `json:"billTo,omitempty"`
ShipTo *Address `json:"shipTo,omitempty"`
CustomerIP string `json:"customerIP,omitempty"`
//TransactionSettings TransactionSettings `json:"transactionSettings,omitempty"`
//UserFields UserFields `json:"userFields,omitempty"`
}
type Address struct {
FirstName string `json:"firstName,omitempty"`
LastName string `json:"lastName,omitempty"`
Company string `json:"company,omitempty"`
Address string `json:"address,omitempty"`
City string `json:"city,omitempty"`
State string `json:"state,omitempty"`
Zip string `json:"zip,omitempty"`
Country string `json:"country,omitempty"`
PhoneNumber string `json:"phoneNumber,omitempty"`
FaxNumber string `json:"faxNumber,omitempty"`
CustomerAddressID string `json:"customerAddressId,omitempty"`
}