-
Notifications
You must be signed in to change notification settings - Fork 1
/
transactions.go
executable file
·698 lines (604 loc) · 30.2 KB
/
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
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
// Code generated by `gogenitor`. DO NOT EDIT.
package sumup
import (
"bytes"
"context"
"encoding/json"
"fmt"
"net/http"
"time"
)
// CardResponse is Details of the payment card.
type CardResponse struct {
// Last 4 digits of the payment card number.
Last4Digits *string `json:"last_4_digits,omitempty"`
// Issuing card network of the payment card.
Type *CardResponseType `json:"type,omitempty"`
}
// Issuing card network of the payment card.
type CardResponseType string
const (
CardResponseTypeAmex CardResponseType = "AMEX"
CardResponseTypeCup CardResponseType = "CUP"
CardResponseTypeDiners CardResponseType = "DINERS"
CardResponseTypeDiscover CardResponseType = "DISCOVER"
CardResponseTypeElo CardResponseType = "ELO"
CardResponseTypeElv CardResponseType = "ELV"
CardResponseTypeHipercard CardResponseType = "HIPERCARD"
CardResponseTypeJcb CardResponseType = "JCB"
CardResponseTypeMaestro CardResponseType = "MAESTRO"
CardResponseTypeMastercard CardResponseType = "MASTERCARD"
CardResponseTypeUnknown CardResponseType = "UNKNOWN"
CardResponseTypeVisa CardResponseType = "VISA"
CardResponseTypeVisaElectron CardResponseType = "VISA_ELECTRON"
CardResponseTypeVisaVpay CardResponseType = "VISA_VPAY"
)
// Event is the type definition for a Event.
type Event struct {
// Amount of the event.
Amount *AmountEvent `json:"amount,omitempty"`
// Amount deducted for the event.
DeductedAmount *float64 `json:"deducted_amount,omitempty"`
// Amount of the fee deducted for the event.
DeductedFeeAmount *float64 `json:"deducted_fee_amount,omitempty"`
// Amount of the fee related to the event.
FeeAmount *float64 `json:"fee_amount,omitempty"`
// Unique ID of the transaction event.
Id *EventId `json:"id,omitempty"`
// Consecutive number of the installment.
InstallmentNumber *int `json:"installment_number,omitempty"`
// Status of the transaction event.
Status *EventStatus `json:"status,omitempty"`
// Date and time of the transaction event.
Timestamp *TimestampEvent `json:"timestamp,omitempty"`
// Unique ID of the transaction.
TransactionId *TransactionId `json:"transaction_id,omitempty"`
// Type of the transaction event.
Type *EventType `json:"type,omitempty"`
}
// HorizontalAccuracy is Indication of the precision of the geographical position received from the payment terminal.
type HorizontalAccuracy float64
// Lat is Latitude value from the coordinates of the payment location (as received from the payment terminal reader).
type Lat float64
// Link is Details of a link to a related resource.
type Link struct {
// URL for accessing the related resource.
Href *string `json:"href,omitempty"`
// Specifies the relation to the current resource.
Rel *string `json:"rel,omitempty"`
// Specifies the media type of the related resource.
Type *string `json:"type,omitempty"`
}
// LinkRefund is the type definition for a LinkRefund.
type LinkRefund struct {
// URL for accessing the related resource.
Href *string `json:"href,omitempty"`
// Maximum allowed amount for the refund.
MaxAmount *float64 `json:"max_amount,omitempty"`
// Minimum allowed amount for the refund.
MinAmount *float64 `json:"min_amount,omitempty"`
// Specifies the relation to the current resource.
Rel *string `json:"rel,omitempty"`
// Specifies the media type of the related resource.
Type *string `json:"type,omitempty"`
}
// Lon is Longitude value from the coordinates of the payment location (as received from the payment terminal reader).
type Lon float64
// Product is Details of the product for which the payment is made.
type Product struct {
// Name of the product from the merchant's catalog.
Name *string `json:"name,omitempty"`
// Price of the product without VAT.
Price *float64 `json:"price,omitempty"`
// Price of a single product item with VAT.
PriceWithVat *float64 `json:"price_with_vat,omitempty"`
// Number of product items for the purchase.
Quantity *float64 `json:"quantity,omitempty"`
// Amount of the VAT for a single product item (calculated as the product of `price` and `vat_rate`, i.e. `single_vat_amount = price * vat_rate`).
SingleVatAmount *float64 `json:"single_vat_amount,omitempty"`
// Total price of the product items without VAT (calculated as the product of `price` and `quantity`, i.e. `total_price = price * quantity`).
TotalPrice *float64 `json:"total_price,omitempty"`
// Total price of the product items including VAT (calculated as the product of `price_with_vat` and `quantity`, i.e. `total_with_vat = price_with_vat * quantity`).
TotalWithVat *float64 `json:"total_with_vat,omitempty"`
// Total VAT amount for the purchase (calculated as the product of `single_vat_amount` and `quantity`, i.e. `vat_amount = single_vat_amount * quantity`).
VatAmount *float64 `json:"vat_amount,omitempty"`
// VAT rate applicable to the product.
VatRate *float64 `json:"vat_rate,omitempty"`
}
// TransactionEvent is Details of a transaction event.
type TransactionEvent struct {
// Amount of the event.
Amount *AmountEvent `json:"amount,omitempty"`
// Date when the transaction event occurred.
Date *time.Time `json:"date,omitempty"`
// Date when the transaction event is due to occur.
DueDate *time.Time `json:"due_date,omitempty"`
// Type of the transaction event.
EventType *EventType `json:"event_type,omitempty"`
// Unique ID of the transaction event.
Id *EventId `json:"id,omitempty"`
// Consecutive number of the installment that is paid. Applicable only payout events, i.e. `event_type = PAYOUT`.
InstallmentNumber *int `json:"installment_number,omitempty"`
// Status of the transaction event.
Status *EventStatus `json:"status,omitempty"`
// Date and time of the transaction event.
Timestamp *TimestampEvent `json:"timestamp,omitempty"`
}
// Payment type used for the transaction.
type TransactionFullPaymentType string
const (
TransactionFullPaymentTypeBoleto TransactionFullPaymentType = "BOLETO"
TransactionFullPaymentTypeEcom TransactionFullPaymentType = "ECOM"
TransactionFullPaymentTypeRecurring TransactionFullPaymentType = "RECURRING"
)
// Current status of the transaction.
type TransactionFullStatus string
const (
TransactionFullStatusCancelled TransactionFullStatus = "CANCELLED"
TransactionFullStatusFailed TransactionFullStatus = "FAILED"
TransactionFullStatusPending TransactionFullStatus = "PENDING"
TransactionFullStatusSuccessful TransactionFullStatus = "SUCCESSFUL"
)
// Entry mode of the payment details.
type TransactionFullEntryMode string
const (
TransactionFullEntryModeBoleto TransactionFullEntryMode = "BOLETO"
TransactionFullEntryModeCustomerEntry TransactionFullEntryMode = "CUSTOMER_ENTRY"
)
// Payout plan of the registered user at the time when the transaction was made.
type TransactionFullPayoutPlan string
const (
TransactionFullPayoutPlanAcceleratedInstallment TransactionFullPayoutPlan = "ACCELERATED_INSTALLMENT"
TransactionFullPayoutPlanSinglePayment TransactionFullPayoutPlan = "SINGLE_PAYMENT"
TransactionFullPayoutPlanTrueInstallment TransactionFullPayoutPlan = "TRUE_INSTALLMENT"
)
// TransactionFullLocation is Details of the payment location as received from the payment terminal.
type TransactionFullLocation struct {
// Indication of the precision of the geographical position received from the payment terminal.
HorizontalAccuracy *HorizontalAccuracy `json:"horizontal_accuracy,omitempty"`
// Latitude value from the coordinates of the payment location (as received from the payment terminal reader).
Lat *Lat `json:"lat,omitempty"`
// Longitude value from the coordinates of the payment location (as received from the payment terminal reader).
Lon *Lon `json:"lon,omitempty"`
}
// Payout type for the transaction.
type TransactionFullPayoutType string
const (
TransactionFullPayoutTypeBalance TransactionFullPayoutType = "BALANCE"
TransactionFullPayoutTypeBankAccount TransactionFullPayoutType = "BANK_ACCOUNT"
TransactionFullPayoutTypePrepaidCard TransactionFullPayoutType = "PREPAID_CARD"
)
// Simple name of the payment type.
type TransactionFullSimplePaymentType string
const (
TransactionFullSimplePaymentTypeCash TransactionFullSimplePaymentType = "CASH"
TransactionFullSimplePaymentTypeCcCustomerEntered TransactionFullSimplePaymentType = "CC_CUSTOMER_ENTERED"
TransactionFullSimplePaymentTypeCcSignature TransactionFullSimplePaymentType = "CC_SIGNATURE"
TransactionFullSimplePaymentTypeElv TransactionFullSimplePaymentType = "ELV"
TransactionFullSimplePaymentTypeEmv TransactionFullSimplePaymentType = "EMV"
TransactionFullSimplePaymentTypeManualEntry TransactionFullSimplePaymentType = "MANUAL_ENTRY"
TransactionFullSimplePaymentTypeMoto TransactionFullSimplePaymentType = "MOTO"
)
// Status generated from the processing status and the latest transaction state.
type TransactionFullSimpleStatus string
const (
TransactionFullSimpleStatusCancelled TransactionFullSimpleStatus = "CANCELLED"
TransactionFullSimpleStatusCancelFailed TransactionFullSimpleStatus = "CANCEL_FAILED"
TransactionFullSimpleStatusChargeback TransactionFullSimpleStatus = "CHARGEBACK"
TransactionFullSimpleStatusFailed TransactionFullSimpleStatus = "FAILED"
TransactionFullSimpleStatusNonCollection TransactionFullSimpleStatus = "NON_COLLECTION"
TransactionFullSimpleStatusPaidOut TransactionFullSimpleStatus = "PAID_OUT"
TransactionFullSimpleStatusRefunded TransactionFullSimpleStatus = "REFUNDED"
TransactionFullSimpleStatusRefundFailed TransactionFullSimpleStatus = "REFUND_FAILED"
TransactionFullSimpleStatusSuccessful TransactionFullSimpleStatus = "SUCCESSFUL"
)
// Verification method used for the transaction.
type TransactionFullVerificationMethod string
const (
TransactionFullVerificationMethodConfirmationCodeVerified TransactionFullVerificationMethod = "confirmation code verified"
TransactionFullVerificationMethodNone TransactionFullVerificationMethod = "none"
TransactionFullVerificationMethodOfflinePin TransactionFullVerificationMethod = "offline pin"
TransactionFullVerificationMethodOfflinePinSignature TransactionFullVerificationMethod = "offline pin + signature"
TransactionFullVerificationMethodOnlinePin TransactionFullVerificationMethod = "online pin"
TransactionFullVerificationMethodSignature TransactionFullVerificationMethod = "signature"
)
// TransactionFull is the type definition for a TransactionFull.
type TransactionFull struct {
// Total amount of the transaction.
Amount *float64 `json:"amount,omitempty"`
// Authorization code for the transaction sent by the payment card issuer or bank. Applicable only to card payments.
AuthCode *string `json:"auth_code,omitempty"`
// Details of the payment card.
Card *CardResponse `json:"card,omitempty"`
// Three-letter [ISO4217](https://en.wikipedia.org/wiki/ISO_4217) code of the currency for the amount. Currently supported currency values are enumerated above.
Currency *Currency `json:"currency,omitempty"`
// Entry mode of the payment details.
EntryMode *TransactionFullEntryMode `json:"entry_mode,omitempty"`
// List of events related to the transaction.
Events *[]Event `json:"events,omitempty"`
// Indication of the precision of the geographical position received from the payment terminal.
HorizontalAccuracy *HorizontalAccuracy `json:"horizontal_accuracy,omitempty"`
// Unique ID of the transaction.
Id *string `json:"id,omitempty"`
// Current number of the installment for deferred payments.
InstallmentsCount *int `json:"installments_count,omitempty"`
// Internal unique ID of the transaction on the SumUp platform.
InternalId *int `json:"internal_id,omitempty"`
// Latitude value from the coordinates of the payment location (as received from the payment terminal reader).
Lat *Lat `json:"lat,omitempty"`
// List of hyperlinks for accessing related resources.
Links *[]interface{} `json:"links,omitempty"`
// Local date and time of the creation of the transaction.
LocalTime *time.Time `json:"local_time,omitempty"`
// Details of the payment location as received from the payment terminal.
Location *TransactionFullLocation `json:"location,omitempty"`
// Longitude value from the coordinates of the payment location (as received from the payment terminal reader).
Lon *Lon `json:"lon,omitempty"`
// Unique code of the registered merchant to whom the payment is made.
MerchantCode *string `json:"merchant_code,omitempty"`
// Payment type used for the transaction.
PaymentType *TransactionFullPaymentType `json:"payment_type,omitempty"`
// Payout plan of the registered user at the time when the transaction was made.
PayoutPlan *TransactionFullPayoutPlan `json:"payout_plan,omitempty"`
// Payout type for the transaction.
PayoutType *TransactionFullPayoutType `json:"payout_type,omitempty"`
// Number of payouts that are made to the registered user specified in the `user` property.
PayoutsReceived *int `json:"payouts_received,omitempty"`
// Total number of payouts to the registered user specified in the `user` property.
PayoutsTotal *int `json:"payouts_total,omitempty"`
// Short description of the payment. The value is taken from the `description` property of the related checkout resource.
ProductSummary *string `json:"product_summary,omitempty"`
// List of products from the merchant's catalogue for which the transaction serves as a payment.
Products *[]Product `json:"products,omitempty"`
// Simple name of the payment type.
SimplePaymentType *TransactionFullSimplePaymentType `json:"simple_payment_type,omitempty"`
// Status generated from the processing status and the latest transaction state.
SimpleStatus *TransactionFullSimpleStatus `json:"simple_status,omitempty"`
// Current status of the transaction.
Status *TransactionFullStatus `json:"status,omitempty"`
// Indicates whether tax deduction is enabled for the transaction.
TaxEnabled *bool `json:"tax_enabled,omitempty"`
// Date and time of the creation of the transaction. Response format expressed according to [ISO8601](https://en.wikipedia.org/wiki/ISO_8601) code.
Timestamp *time.Time `json:"timestamp,omitempty"`
// Amount of the tip (out of the total transaction amount).
TipAmount *float64 `json:"tip_amount,omitempty"`
// Transaction code returned by the acquirer/processing entity after processing the transaction.
TransactionCode *string `json:"transaction_code,omitempty"`
// List of transaction events related to the transaction.
TransactionEvents *[]TransactionEvent `json:"transaction_events,omitempty"`
// Email address of the registered user (merchant) to whom the payment is made.
Username *string `json:"username,omitempty"`
// Amount of the applicable VAT (out of the total transaction amount).
VatAmount *float64 `json:"vat_amount,omitempty"`
// List of VAT rates applicable to the transaction.
VatRates *[]interface{} `json:"vat_rates,omitempty"`
// Verification method used for the transaction.
VerificationMethod *TransactionFullVerificationMethod `json:"verification_method,omitempty"`
}
// Payment type used for the transaction.
type TransactionHistoryPaymentType string
const (
TransactionHistoryPaymentTypeBoleto TransactionHistoryPaymentType = "BOLETO"
TransactionHistoryPaymentTypeEcom TransactionHistoryPaymentType = "ECOM"
TransactionHistoryPaymentTypeRecurring TransactionHistoryPaymentType = "RECURRING"
)
// Current status of the transaction.
type TransactionHistoryStatus string
const (
TransactionHistoryStatusCancelled TransactionHistoryStatus = "CANCELLED"
TransactionHistoryStatusFailed TransactionHistoryStatus = "FAILED"
TransactionHistoryStatusPending TransactionHistoryStatus = "PENDING"
TransactionHistoryStatusSuccessful TransactionHistoryStatus = "SUCCESSFUL"
)
// Payout plan of the registered user at the time when the transaction was made.
type TransactionHistoryPayoutPlan string
const (
TransactionHistoryPayoutPlanAcceleratedInstallment TransactionHistoryPayoutPlan = "ACCELERATED_INSTALLMENT"
TransactionHistoryPayoutPlanSinglePayment TransactionHistoryPayoutPlan = "SINGLE_PAYMENT"
TransactionHistoryPayoutPlanTrueInstallment TransactionHistoryPayoutPlan = "TRUE_INSTALLMENT"
)
// Issuing card network of the payment card used for the transaction.
type TransactionHistoryCardType string
const (
TransactionHistoryCardTypeAmex TransactionHistoryCardType = "AMEX"
TransactionHistoryCardTypeCup TransactionHistoryCardType = "CUP"
TransactionHistoryCardTypeDiners TransactionHistoryCardType = "DINERS"
TransactionHistoryCardTypeDiscover TransactionHistoryCardType = "DISCOVER"
TransactionHistoryCardTypeElo TransactionHistoryCardType = "ELO"
TransactionHistoryCardTypeElv TransactionHistoryCardType = "ELV"
TransactionHistoryCardTypeHipercard TransactionHistoryCardType = "HIPERCARD"
TransactionHistoryCardTypeJcb TransactionHistoryCardType = "JCB"
TransactionHistoryCardTypeMaestro TransactionHistoryCardType = "MAESTRO"
TransactionHistoryCardTypeMastercard TransactionHistoryCardType = "MASTERCARD"
TransactionHistoryCardTypeUnknown TransactionHistoryCardType = "UNKNOWN"
TransactionHistoryCardTypeVisa TransactionHistoryCardType = "VISA"
TransactionHistoryCardTypeVisaElectron TransactionHistoryCardType = "VISA_ELECTRON"
TransactionHistoryCardTypeVisaVpay TransactionHistoryCardType = "VISA_VPAY"
)
// Type of the transaction for the registered user specified in the `user` property.
type TransactionHistoryType string
const (
TransactionHistoryTypeChargeBack TransactionHistoryType = "CHARGE_BACK"
TransactionHistoryTypePayment TransactionHistoryType = "PAYMENT"
TransactionHistoryTypeRefund TransactionHistoryType = "REFUND"
)
// TransactionHistory is the type definition for a TransactionHistory.
type TransactionHistory struct {
// Total amount of the transaction.
Amount *float64 `json:"amount,omitempty"`
// Issuing card network of the payment card used for the transaction.
CardType *TransactionHistoryCardType `json:"card_type,omitempty"`
// Client-specific ID of the transaction.
ClientTransactionId *string `json:"client_transaction_id,omitempty"`
// Three-letter [ISO4217](https://en.wikipedia.org/wiki/ISO_4217) code of the currency for the amount. Currently supported currency values are enumerated above.
Currency *Currency `json:"currency,omitempty"`
// Unique ID of the transaction.
Id *string `json:"id,omitempty"`
// Current number of the installment for deferred payments.
InstallmentsCount *int `json:"installments_count,omitempty"`
// Payment type used for the transaction.
PaymentType *TransactionHistoryPaymentType `json:"payment_type,omitempty"`
// Payout plan of the registered user at the time when the transaction was made.
PayoutPlan *TransactionHistoryPayoutPlan `json:"payout_plan,omitempty"`
// Number of payouts that are made to the registered user specified in the `user` property.
PayoutsReceived *int `json:"payouts_received,omitempty"`
// Total number of payouts to the registered user specified in the `user` property.
PayoutsTotal *int `json:"payouts_total,omitempty"`
// Short description of the payment. The value is taken from the `description` property of the related checkout resource.
ProductSummary *string `json:"product_summary,omitempty"`
// Current status of the transaction.
Status *TransactionHistoryStatus `json:"status,omitempty"`
// Date and time of the creation of the transaction. Response format expressed according to [ISO8601](https://en.wikipedia.org/wiki/ISO_8601) code.
Timestamp *time.Time `json:"timestamp,omitempty"`
// Transaction code returned by the acquirer/processing entity after processing the transaction.
TransactionCode *string `json:"transaction_code,omitempty"`
// Unique ID of the transaction.
TransactionId *TransactionId `json:"transaction_id,omitempty"`
// Type of the transaction for the registered user specified in the `user` property.
Type *TransactionHistoryType `json:"type,omitempty"`
// Email address of the registered user (merchant) to whom the payment is made.
User *string `json:"user,omitempty"`
}
// TransactionMixinHistory is the type definition for a TransactionMixinHistory.
type TransactionMixinHistory struct {
// Payout plan of the registered user at the time when the transaction was made.
PayoutPlan *TransactionMixinHistoryPayoutPlan `json:"payout_plan,omitempty"`
// Number of payouts that are made to the registered user specified in the `user` property.
PayoutsReceived *int `json:"payouts_received,omitempty"`
// Total number of payouts to the registered user specified in the `user` property.
PayoutsTotal *int `json:"payouts_total,omitempty"`
// Short description of the payment. The value is taken from the `description` property of the related checkout resource.
ProductSummary *string `json:"product_summary,omitempty"`
}
// Payout plan of the registered user at the time when the transaction was made.
type TransactionMixinHistoryPayoutPlan string
const (
TransactionMixinHistoryPayoutPlanAcceleratedInstallment TransactionMixinHistoryPayoutPlan = "ACCELERATED_INSTALLMENT"
TransactionMixinHistoryPayoutPlanSinglePayment TransactionMixinHistoryPayoutPlan = "SINGLE_PAYMENT"
TransactionMixinHistoryPayoutPlanTrueInstallment TransactionMixinHistoryPayoutPlan = "TRUE_INSTALLMENT"
)
// ListTransactionsParams are query parameters for ListTransactions
type ListTransactionsParams struct {
ChangesSince *time.Time `json:"changes_since,omitempty"`
Limit *int `json:"limit,omitempty"`
NewestRef *string `json:"newest_ref,omitempty"`
NewestTime *time.Time `json:"newest_time,omitempty"`
OldestRef *string `json:"oldest_ref,omitempty"`
OldestTime *time.Time `json:"oldest_time,omitempty"`
Order *string `json:"order,omitempty"`
PaymentTypes *[]string `json:"payment_types,omitempty"`
Statuses *[]string `json:"statuses,omitempty"`
TransactionCode *string `json:"transaction_code,omitempty"`
Types *[]string `json:"types,omitempty"`
Users *[]string `json:"users,omitempty"`
}
// ListTransactionsResponse is the type definition for a ListTransactionsResponse.
type ListTransactionsResponse struct {
Items *[]TransactionHistory `json:"items,omitempty"`
Links *[]Link `json:"links,omitempty"`
}
// GetTransactionParams are query parameters for GetTransaction
type GetTransactionParams struct {
Id *string `json:"id,omitempty"`
InternalId *string `json:"internal_id,omitempty"`
TransactionCode *string `json:"transaction_code,omitempty"`
}
// ListTransactionsV21Params are query parameters for ListTransactionsV21
type ListTransactionsV21Params struct {
ChangesSince *time.Time `json:"changes_since,omitempty"`
Limit *int `json:"limit,omitempty"`
NewestRef *string `json:"newest_ref,omitempty"`
NewestTime *time.Time `json:"newest_time,omitempty"`
OldestRef *string `json:"oldest_ref,omitempty"`
OldestTime *time.Time `json:"oldest_time,omitempty"`
Order *string `json:"order,omitempty"`
PaymentTypes *[]string `json:"payment_types,omitempty"`
Statuses *[]string `json:"statuses,omitempty"`
TransactionCode *string `json:"transaction_code,omitempty"`
Types *[]string `json:"types,omitempty"`
Users *[]string `json:"users,omitempty"`
}
// ListTransactionsV21Response is the type definition for a ListTransactionsV21Response.
type ListTransactionsV21Response struct {
Items *[]TransactionHistory `json:"items,omitempty"`
Links *[]Link `json:"links,omitempty"`
}
// GetTransactionV21Params are query parameters for GetTransactionV21
type GetTransactionV21Params struct {
Id *string `json:"id,omitempty"`
InternalId *string `json:"internal_id,omitempty"`
TransactionCode *string `json:"transaction_code,omitempty"`
}
// RefundTransaction request body.
type RefundTransactionBody struct {
// Amount to be refunded. Eligible amount can't exceed the amount of the transaction and varies based on country and currency. If you do not specify a value, the system performs a full refund of the transaction.
Amount *float64 `json:"amount,omitempty"`
}
// RefundTransactionResponse is the type definition for a RefundTransactionResponse.
type RefundTransactionResponse struct {
}
type TransactionsService service
// ListDeprecated: List transactions (deprecated)
// Lists detailed history of all transactions associated with the merchant profile.
func (s *TransactionsService) ListDeprecated(ctx context.Context, params ListTransactionsParams) (*ListTransactionsResponse, error) {
path := fmt.Sprintf("/v0.1/me/transactions/history")
req, err := s.client.NewRequest(ctx, http.MethodGet, path, http.NoBody)
if err != nil {
return nil, fmt.Errorf("error building request: %v", err)
}
resp, err := s.client.Do(req)
if err != nil {
return nil, fmt.Errorf("error sending request: %v", err)
}
defer resp.Body.Close()
if resp.StatusCode >= 500 {
return nil, fmt.Errorf("invalid response: %d - %s", resp.StatusCode, http.StatusText(resp.StatusCode))
}
dec := json.NewDecoder(resp.Body)
if resp.StatusCode >= 400 {
var apiErr APIError
if err := dec.Decode(&apiErr); err != nil {
return nil, fmt.Errorf("read error response: %s", err.Error())
}
return nil, &apiErr
}
var v ListTransactionsResponse
if err := dec.Decode(&v); err != nil {
return nil, fmt.Errorf("decode response: %s", err.Error())
}
return &v, nil
}
// GetDeprecated: Retrieve a transaction (deprecated)
// Retrieves the full details of an identified transaction. The transaction resource is identified by a query parameter and *one* of following parameters is required:
// - `id`
// - `internal_id`
// - `transaction_code`
// - `foreign_transaction_id`
// - `client_transaction_id`
func (s *TransactionsService) GetDeprecated(ctx context.Context, params GetTransactionParams) (*TransactionFull, error) {
path := fmt.Sprintf("/v0.1/me/transactions")
req, err := s.client.NewRequest(ctx, http.MethodGet, path, http.NoBody)
if err != nil {
return nil, fmt.Errorf("error building request: %v", err)
}
resp, err := s.client.Do(req)
if err != nil {
return nil, fmt.Errorf("error sending request: %v", err)
}
defer resp.Body.Close()
if resp.StatusCode >= 500 {
return nil, fmt.Errorf("invalid response: %d - %s", resp.StatusCode, http.StatusText(resp.StatusCode))
}
dec := json.NewDecoder(resp.Body)
if resp.StatusCode >= 400 {
var apiErr APIError
if err := dec.Decode(&apiErr); err != nil {
return nil, fmt.Errorf("read error response: %s", err.Error())
}
return nil, &apiErr
}
var v TransactionFull
if err := dec.Decode(&v); err != nil {
return nil, fmt.Errorf("decode response: %s", err.Error())
}
return &v, nil
}
// List: List transactions
// Lists detailed history of all transactions associated with the merchant profile.
func (s *TransactionsService) List(ctx context.Context, merchantCode string, params ListTransactionsV21Params) (*ListTransactionsV21Response, error) {
path := fmt.Sprintf("/v2.1/merchants/%v/transactions/history", merchantCode)
req, err := s.client.NewRequest(ctx, http.MethodGet, path, http.NoBody)
if err != nil {
return nil, fmt.Errorf("error building request: %v", err)
}
resp, err := s.client.Do(req)
if err != nil {
return nil, fmt.Errorf("error sending request: %v", err)
}
defer resp.Body.Close()
if resp.StatusCode >= 500 {
return nil, fmt.Errorf("invalid response: %d - %s", resp.StatusCode, http.StatusText(resp.StatusCode))
}
dec := json.NewDecoder(resp.Body)
if resp.StatusCode >= 400 {
var apiErr APIError
if err := dec.Decode(&apiErr); err != nil {
return nil, fmt.Errorf("read error response: %s", err.Error())
}
return nil, &apiErr
}
var v ListTransactionsV21Response
if err := dec.Decode(&v); err != nil {
return nil, fmt.Errorf("decode response: %s", err.Error())
}
return &v, nil
}
// Get: Retrieve a transaction
// Retrieves the full details of an identified transaction. The transaction resource is identified by a query parameter and *one* of following parameters is required:
// - `id`
// - `internal_id`
// - `transaction_code`
// - `foreign_transaction_id`
// - `client_transaction_id`
func (s *TransactionsService) Get(ctx context.Context, merchantCode string, params GetTransactionV21Params) (*TransactionFull, error) {
path := fmt.Sprintf("/v2.1/merchants/%v/transactions", merchantCode)
req, err := s.client.NewRequest(ctx, http.MethodGet, path, http.NoBody)
if err != nil {
return nil, fmt.Errorf("error building request: %v", err)
}
resp, err := s.client.Do(req)
if err != nil {
return nil, fmt.Errorf("error sending request: %v", err)
}
defer resp.Body.Close()
if resp.StatusCode >= 500 {
return nil, fmt.Errorf("invalid response: %d - %s", resp.StatusCode, http.StatusText(resp.StatusCode))
}
dec := json.NewDecoder(resp.Body)
if resp.StatusCode >= 400 {
var apiErr APIError
if err := dec.Decode(&apiErr); err != nil {
return nil, fmt.Errorf("read error response: %s", err.Error())
}
return nil, &apiErr
}
var v TransactionFull
if err := dec.Decode(&v); err != nil {
return nil, fmt.Errorf("decode response: %s", err.Error())
}
return &v, nil
}
// Refund: Refund a transaction
// Refunds an identified transaction either in full or partially.
func (s *TransactionsService) Refund(ctx context.Context, txnId string, body RefundTransactionBody) (*RefundTransactionResponse, error) {
buf := new(bytes.Buffer)
if err := json.NewEncoder(buf).Encode(body); err != nil {
return nil, fmt.Errorf("encoding json body request failed: %v", err)
}
path := fmt.Sprintf("/v0.1/me/refund/%v", txnId)
req, err := s.client.NewRequest(ctx, http.MethodPost, path, buf)
if err != nil {
return nil, fmt.Errorf("error building request: %v", err)
}
resp, err := s.client.Do(req)
if err != nil {
return nil, fmt.Errorf("error sending request: %v", err)
}
defer resp.Body.Close()
if resp.StatusCode >= 500 {
return nil, fmt.Errorf("invalid response: %d - %s", resp.StatusCode, http.StatusText(resp.StatusCode))
}
dec := json.NewDecoder(resp.Body)
if resp.StatusCode >= 400 {
var apiErr APIError
if err := dec.Decode(&apiErr); err != nil {
return nil, fmt.Errorf("read error response: %s", err.Error())
}
return nil, &apiErr
}
var v RefundTransactionResponse
if err := dec.Decode(&v); err != nil {
return nil, fmt.Errorf("decode response: %s", err.Error())
}
return &v, nil
}