-
Notifications
You must be signed in to change notification settings - Fork 12
/
payment.go
227 lines (206 loc) · 10.3 KB
/
payment.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
package adyen
/**********
* Payment *
**********/
// One-click functionality gives the shopper the option to store their payment details with the merchant, within the Adyen environment.
//
// In this type of transaction, the shopper needs to enter the CVC code for the transaction to get through.
//
// Link: https://docs.adyen.com/developers/api-reference/payments-api#recurring
const (
RecurringPaymentOneClick = "ONECLICK"
RecurringPaymentRecurring = "RECURRING"
ShopperInteractionContAuth = "ContAuth"
SelectRecurringDetailReferenceLatests = "LATEST"
)
// AuthoriseEncrypted structure for Authorisation request (with encrypted card information)
//
// Link - https://docs.adyen.com/developers/api-reference/payments-api#paymentrequest
type AuthoriseEncrypted struct {
AdditionalData *AdditionalData `json:"additionalData,omitempty"`
Amount *Amount `json:"amount"`
BillingAddress *Address `json:"billingAddress,omitempty"`
DeliveryAddress *Address `json:"deliveryAddress,omitempty"`
Reference string `json:"reference"`
MerchantAccount string `json:"merchantAccount"`
ShopperReference string `json:"shopperReference,omitempty"` // Mandatory for recurring payment
Recurring *Recurring `json:"recurring,omitempty"`
ShopperEmail string `json:"shopperEmail,omitempty"`
ShopperInteraction string `json:"shopperInteraction,omitempty"`
ShopperIP string `json:"shopperIP,omitempty"`
ShopperLocale string `json:"shopperLocale,omitempty"`
ShopperName *Name `json:"shopperName,omitempty"`
SelectedRecurringDetailReference string `json:"selectedRecurringDetailReference,omitempty"`
BrowserInfo *BrowserInfo `json:"browserInfo,omitempty"` // Required for a 3DS process
CaptureDelayHours *int `json:"captureDelayHours,omitempty"`
}
// Authorise structure for Authorisation request (card is not encrypted)
//
// Link - https://docs.adyen.com/developers/api-reference/payments-api#paymentrequest
type Authorise struct {
AdditionalData *AdditionalData `json:"additionalData,omitempty"`
Card *Card `json:"card,omitempty"`
Amount *Amount `json:"amount"`
BillingAddress *Address `json:"billingAddress,omitempty"`
DeliveryAddress *Address `json:"deliveryAddress,omitempty"`
Reference string `json:"reference"`
MerchantAccount string `json:"merchantAccount"`
ShopperReference string `json:"shopperReference,omitempty"` // Mandatory for recurring payment
Recurring *Recurring `json:"recurring,omitempty"`
ShopperEmail string `json:"shopperEmail,omitempty"`
ShopperInteraction string `json:"shopperInteraction,omitempty"`
ShopperIP string `json:"shopperIP,omitempty"`
ShopperLocale string `json:"shopperLocale,omitempty"`
ShopperName *Name `json:"shopperName,omitempty"`
SelectedRecurringDetailReference string `json:"selectedRecurringDetailReference,omitempty"`
BrowserInfo *BrowserInfo `json:"browserInfo,omitempty"` // Required for a 3DS process
CaptureDelayHours *int `json:"captureDelayHours,omitempty"`
}
// AuthoriseResponse is a response structure for Adyen
//
// Link - https://docs.adyen.com/developers/api-reference/payments-api#paymentresult
type AuthoriseResponse struct {
PspReference string `json:"pspReference"`
ResultCode string `json:"resultCode"`
AuthCode string `json:"authCode"`
RefusalReason string `json:"refusalReason"`
IssuerURL string `json:"issuerUrl"`
MD string `json:"md"`
PaRequest string `json:"paRequest"`
FraudResult *FraudResult `json:"fraudResult,omitempty"`
AdditionalData *AdditionalData `json:"additionalData,omitempty"`
}
// AdditionalData stores encrypted information about customer's credit card
type AdditionalData struct {
Content string `json:"card.encrypted.json,omitempty"`
AliasType string `json:"aliasType,omitempty"`
Alias string `json:"alias,omitempty"`
ExpiryDate string `json:"expiryDate,omitempty"`
CardBin string `json:"cardBin,omitempty"`
CardSummary string `json:"cardSummary,omitempty"`
CardHolderName string `json:"cardHolderName,omitempty"`
PaymentMethod string `json:"paymentMethod,omitempty"`
CardPaymentMethod string `json:"cardPaymentMethod,omitempty"`
CardIssuingCountry string `json:"cardIssuingCountry,omitempty"`
RecurringDetailReference string `json:"recurring.recurringDetailReference,omitempty"`
ExecuteThreeD *StringBool `json:"executeThreeD,omitempty"`
FundingSource string `json:"fundingSource,omitempty"`
CustomRoutingFlag string `json:"customRoutingFlag,omitempty"`
RequestedTestAcquirerResponseCode int `json:"RequestedTestAcquirerResponseCode,omitempty"` //Used for trigger error from adyen
CVCResult CVCResult `json:"cvcResult,omitempty"`
CVCResultRaw string `json:"cvcResultRaw,omitempty"`
AVSResult AVSResponse `json:"avsResult,omitempty"`
AVSResultRaw string `json:"avsResultRaw,omitempty"`
}
// BrowserInfo hold information on the user browser
type BrowserInfo struct {
AcceptHeader string `json:"acceptHeader"`
UserAgent string `json:"userAgent"`
}
// Recurring hold the behavior for a future payment : could be ONECLICK or RECURRING
type Recurring struct {
Contract string `json:"contract"`
}
// FraudResult hold the fraud score of transaction
type FraudResult struct {
AccountScore int64 `json:"accountScore,omitempty"`
Results []Result `json:"results,omitempty"`
}
// Result hold the fraud score detail
type Result struct {
FraudCheckResult *FraudCheckResult `json:"FraudCheckResult,omitempty"`
}
// FraudCheckResult hold information of fraud score detail
type FraudCheckResult struct {
AccountScore int `json:"accountScore,omitempty"`
CheckID int `json:"checkId,omitempty"`
Name string `json:"name,omitempty"`
}
/*************
* Payment 3D *
*************/
// Authorise3D structure for Authorisation request (card is not encrypted)
//
// https://docs.adyen.com/developers/api-reference/payments-api#paymentrequest3d
type Authorise3D struct {
BillingAddress *Address `json:"billingAddress,omitempty"`
DeliveryAddress *Address `json:"deliveryAddress,omitempty"`
MD string `json:"md"`
MerchantAccount string `json:"merchantAccount"`
BrowserInfo *BrowserInfo `json:"browserInfo"`
PaResponse string `json:"paResponse"`
ShopperEmail string `json:"shopperEmail,omitempty"`
ShopperIP string `json:"shopperIP,omitempty"`
ShopperLocale string `json:"shopperLocale,omitempty"`
ShopperName *Name `json:"shopperName,omitempty"`
}
/*******************
* Directory lookup *
*******************/
// DirectoryLookupRequest - get list of available payment methods based on skin, country and order details
//
// Description - https://docs.adyen.com/developers/api-reference/hosted-payment-pages-api#directoryrequest
// CountryCode could be used to test local payment methods, if client's IP is from different country
type DirectoryLookupRequest struct {
CurrencyCode string `url:"currencyCode"`
MerchantAccount string `url:"merchantAccount"`
PaymentAmount int `url:"paymentAmount"`
SkinCode string `url:"skinCode"`
MerchantReference string `url:"merchantReference"`
SessionsValidity string `url:"sessionValidity"`
MerchantSig string `url:"merchantSig"`
CountryCode string `url:"countryCode"`
ShipBeforeDate string `url:"shipBeforeDate"`
}
// DirectoryLookupResponse - api response for DirectoryLookupRequest
//
// Description - https://docs.adyen.com/developers/api-reference/hosted-payment-pages-api#directoryresponse
type DirectoryLookupResponse struct {
PaymentMethods []PaymentMethod `json:"paymentMethods"`
}
// PaymentMethod - structure for single payment method in directory look up response
//
// Part of DirectoryLookupResponse
type PaymentMethod struct {
BrandCode string `json:"brandCode"`
Name string `json:"name"`
Logos logos `json:"logos"`
Issuers []issuer `json:"issuers"`
}
// logos - payment method logos
//
// Part of DirectoryLookupResponse
type logos struct {
Normal string `json:"normal"`
Small string `json:"small"`
Tiny string `json:"tiny"`
}
// issuer - bank issuer type
//
// Part of DirectoryLookupResponse
type issuer struct {
IssuerID string `json:"issuerId"`
Name string `json:"name"`
}
/***********
* Skip HPP *
***********/
// SkipHppRequest contains data that would be used to create Adyen HPP redirect URL
//
// Link: https://docs.adyen.com/developers/ecommerce-integration/local-payment-methods
//
// Request description: https://docs.adyen.com/developers/api-reference/hosted-payment-pages-api#skipdetailsrequest
type SkipHppRequest struct {
MerchantReference string `url:"merchantReference"`
PaymentAmount int `url:"paymentAmount"`
CurrencyCode string `url:"currencyCode"`
ShipBeforeDate string `url:"shipBeforeDate"`
SkinCode string `url:"skinCode"`
MerchantAccount string `url:"merchantAccount"`
ShopperLocale string `url:"shopperLocale"`
SessionsValidity string `url:"sessionValidity"`
MerchantSig string `url:"merchantSig"`
CountryCode string `url:"countryCode"`
BrandCode string `url:"brandCode"`
IssuerID string `url:"issuerId"`
}