activemerchant 1.126.0 → 1.131.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +269 -0
- data/lib/active_merchant/billing/check.rb +40 -8
- data/lib/active_merchant/billing/credit_card.rb +28 -1
- data/lib/active_merchant/billing/credit_card_methods.rb +80 -24
- data/lib/active_merchant/billing/gateways/adyen.rb +69 -10
- data/lib/active_merchant/billing/gateways/airwallex.rb +40 -11
- data/lib/active_merchant/billing/gateways/alelo.rb +256 -0
- data/lib/active_merchant/billing/gateways/authorize_net.rb +24 -6
- data/lib/active_merchant/billing/gateways/beanstream.rb +18 -0
- data/lib/active_merchant/billing/gateways/blue_snap.rb +22 -1
- data/lib/active_merchant/billing/gateways/bogus.rb +4 -0
- data/lib/active_merchant/billing/gateways/borgun.rb +57 -16
- data/lib/active_merchant/billing/gateways/braintree_blue.rb +72 -24
- data/lib/active_merchant/billing/gateways/card_connect.rb +27 -9
- data/lib/active_merchant/billing/gateways/card_stream.rb +23 -0
- data/lib/active_merchant/billing/gateways/checkout_v2.rb +238 -57
- data/lib/active_merchant/billing/gateways/commerce_hub.rb +366 -0
- data/lib/active_merchant/billing/gateways/credorax.rb +47 -27
- data/lib/active_merchant/billing/gateways/cyber_source/cyber_source_common.rb +36 -0
- data/lib/active_merchant/billing/gateways/cyber_source.rb +119 -33
- data/lib/active_merchant/billing/gateways/cyber_source_rest.rb +454 -0
- data/lib/active_merchant/billing/gateways/d_local.rb +45 -5
- data/lib/active_merchant/billing/gateways/decidir.rb +15 -4
- data/lib/active_merchant/billing/gateways/ebanx.rb +36 -24
- data/lib/active_merchant/billing/gateways/element.rb +21 -1
- data/lib/active_merchant/billing/gateways/global_collect.rb +113 -40
- data/lib/active_merchant/billing/gateways/ipg.rb +13 -8
- data/lib/active_merchant/billing/gateways/iveri.rb +39 -3
- data/lib/active_merchant/billing/gateways/kushki.rb +21 -1
- data/lib/active_merchant/billing/gateways/litle.rb +25 -5
- data/lib/active_merchant/billing/gateways/mastercard.rb +1 -8
- data/lib/active_merchant/billing/gateways/mercado_pago.rb +17 -0
- data/lib/active_merchant/billing/gateways/merchant_e_solutions.rb +44 -10
- data/lib/active_merchant/billing/gateways/monei.rb +2 -0
- data/lib/active_merchant/billing/gateways/moneris.rb +20 -5
- data/lib/active_merchant/billing/gateways/mundipagg.rb +3 -0
- data/lib/active_merchant/billing/gateways/ogone.rb +35 -7
- data/lib/active_merchant/billing/gateways/openpay.rb +20 -3
- data/lib/active_merchant/billing/gateways/orbital.rb +43 -22
- data/lib/active_merchant/billing/gateways/pay_trace.rb +64 -18
- data/lib/active_merchant/billing/gateways/payeezy.rb +59 -4
- data/lib/active_merchant/billing/gateways/paymentez.rb +18 -6
- data/lib/active_merchant/billing/gateways/paypal/paypal_express_response.rb +4 -0
- data/lib/active_merchant/billing/gateways/paypal_express.rb +2 -0
- data/lib/active_merchant/billing/gateways/paysafe.rb +22 -14
- data/lib/active_merchant/billing/gateways/payu_latam.rb +4 -1
- data/lib/active_merchant/billing/gateways/plexo.rb +308 -0
- data/lib/active_merchant/billing/gateways/priority.rb +29 -6
- data/lib/active_merchant/billing/gateways/rapyd.rb +110 -49
- data/lib/active_merchant/billing/gateways/reach.rb +277 -0
- data/lib/active_merchant/billing/gateways/redsys.rb +11 -6
- data/lib/active_merchant/billing/gateways/sage_pay.rb +1 -1
- data/lib/active_merchant/billing/gateways/securion_pay.rb +40 -0
- data/lib/active_merchant/billing/gateways/shift4.rb +345 -0
- data/lib/active_merchant/billing/gateways/simetrik.rb +28 -22
- data/lib/active_merchant/billing/gateways/stripe.rb +30 -6
- data/lib/active_merchant/billing/gateways/stripe_payment_intents.rb +62 -22
- data/lib/active_merchant/billing/gateways/tns.rb +2 -5
- data/lib/active_merchant/billing/gateways/trans_first_transaction_express.rb +1 -1
- data/lib/active_merchant/billing/gateways/trust_commerce.rb +14 -3
- data/lib/active_merchant/billing/gateways/vanco.rb +12 -3
- data/lib/active_merchant/billing/gateways/visanet_peru.rb +1 -1
- data/lib/active_merchant/billing/gateways/vpos.rb +7 -4
- data/lib/active_merchant/billing/gateways/wompi.rb +8 -4
- data/lib/active_merchant/billing/gateways/worldpay.rb +128 -13
- data/lib/active_merchant/billing/response.rb +15 -1
- data/lib/active_merchant/connection.rb +0 -2
- data/lib/active_merchant/country.rb +1 -0
- data/lib/active_merchant/errors.rb +4 -1
- data/lib/active_merchant/version.rb +1 -1
- metadata +24 -3
@@ -9,12 +9,24 @@ module ActiveMerchant #:nodoc:
|
|
9
9
|
self.supported_countries = %w[AD AE AR AT AU BE BG BH BR CH CL CN CO CY CZ DE DK EE EG ES FI FR GB GR HK HR HU IE IS IT JO JP KW LI LT LU LV MC MT MX MY NL NO NZ OM PE PL PT QA RO SA SE SG SI SK SM TR US]
|
10
10
|
self.default_currency = 'USD'
|
11
11
|
self.money_format = :cents
|
12
|
-
self.supported_cardtypes = %i[visa master american_express diners_club maestro discover jcb]
|
12
|
+
self.supported_cardtypes = %i[visa master american_express diners_club maestro discover jcb mada bp_plus]
|
13
13
|
self.currencies_without_fractions = %w(BIF DJF GNF ISK KMF XAF CLF XPF JPY PYG RWF KRW VUV VND XOF)
|
14
14
|
self.currencies_with_three_decimal_places = %w(BHD LYD JOD KWD OMR TND)
|
15
15
|
|
16
|
+
LIVE_ACCESS_TOKEN_URL = 'https://access.checkout.com/connect/token'
|
17
|
+
TEST_ACCESS_TOKEN_URL = 'https://access.sandbox.checkout.com/connect/token'
|
18
|
+
|
16
19
|
def initialize(options = {})
|
17
|
-
|
20
|
+
@options = options
|
21
|
+
@access_token = nil
|
22
|
+
|
23
|
+
if options.has_key?(:secret_key)
|
24
|
+
requires!(options, :secret_key)
|
25
|
+
else
|
26
|
+
requires!(options, :client_id, :client_secret)
|
27
|
+
@access_token = setup_access_token
|
28
|
+
end
|
29
|
+
|
18
30
|
super
|
19
31
|
end
|
20
32
|
|
@@ -22,31 +34,44 @@ module ActiveMerchant #:nodoc:
|
|
22
34
|
post = {}
|
23
35
|
build_auth_or_purchase(post, amount, payment_method, options)
|
24
36
|
|
25
|
-
commit(:purchase, post)
|
37
|
+
commit(:purchase, post, options)
|
26
38
|
end
|
27
39
|
|
28
40
|
def authorize(amount, payment_method, options = {})
|
29
41
|
post = {}
|
30
42
|
post[:capture] = false
|
31
43
|
build_auth_or_purchase(post, amount, payment_method, options)
|
32
|
-
|
33
|
-
commit(:authorize, post)
|
44
|
+
options[:incremental_authorization] ? commit(:incremental_authorize, post, options, options[:incremental_authorization]) : commit(:authorize, post, options)
|
34
45
|
end
|
35
46
|
|
36
47
|
def capture(amount, authorization, options = {})
|
37
48
|
post = {}
|
49
|
+
post[:capture_type] = options[:capture_type] || 'Final'
|
38
50
|
add_invoice(post, amount, options)
|
39
51
|
add_customer_data(post, options)
|
52
|
+
add_shipping_address(post, options)
|
40
53
|
add_metadata(post, options)
|
41
54
|
|
42
|
-
commit(:capture, post, authorization)
|
55
|
+
commit(:capture, post, options, authorization)
|
56
|
+
end
|
57
|
+
|
58
|
+
def credit(amount, payment, options = {})
|
59
|
+
post = {}
|
60
|
+
post[:instruction] = {}
|
61
|
+
post[:instruction][:funds_transfer_type] = options[:funds_transfer_type] || 'FD'
|
62
|
+
add_processing_channel(post, options)
|
63
|
+
add_invoice(post, amount, options)
|
64
|
+
add_payment_method(post, payment, options, :destination)
|
65
|
+
add_source(post, options)
|
66
|
+
|
67
|
+
commit(:credit, post, options)
|
43
68
|
end
|
44
69
|
|
45
70
|
def void(authorization, _options = {})
|
46
71
|
post = {}
|
47
72
|
add_metadata(post, options)
|
48
73
|
|
49
|
-
commit(:void, post, authorization)
|
74
|
+
commit(:void, post, options, authorization)
|
50
75
|
end
|
51
76
|
|
52
77
|
def refund(amount, authorization, options = {})
|
@@ -55,7 +80,7 @@ module ActiveMerchant #:nodoc:
|
|
55
80
|
add_customer_data(post, options)
|
56
81
|
add_metadata(post, options)
|
57
82
|
|
58
|
-
commit(:refund, post, authorization)
|
83
|
+
commit(:refund, post, options, authorization)
|
59
84
|
end
|
60
85
|
|
61
86
|
def verify(credit_card, options = {})
|
@@ -63,7 +88,7 @@ module ActiveMerchant #:nodoc:
|
|
63
88
|
end
|
64
89
|
|
65
90
|
def verify_payment(authorization, option = {})
|
66
|
-
commit(:verify_payment, authorization)
|
91
|
+
commit(:verify_payment, nil, options, authorization, :get)
|
67
92
|
end
|
68
93
|
|
69
94
|
def supports_scrubbing?
|
@@ -74,19 +99,52 @@ module ActiveMerchant #:nodoc:
|
|
74
99
|
transcript.
|
75
100
|
gsub(/(Authorization: )[^\\]*/i, '\1[FILTERED]').
|
76
101
|
gsub(/("number\\":\\")\d+/, '\1[FILTERED]').
|
77
|
-
gsub(/("cvv\\":\\")\d+/, '\1[FILTERED]')
|
102
|
+
gsub(/("cvv\\":\\")\d+/, '\1[FILTERED]').
|
103
|
+
gsub(/("cryptogram\\":\\")\w+/, '\1[FILTERED]').
|
104
|
+
gsub(/(source\\":\{.*\\"token\\":\\")\d+/, '\1[FILTERED]').
|
105
|
+
gsub(/("token\\":\\")\w+/, '\1[FILTERED]')
|
106
|
+
end
|
107
|
+
|
108
|
+
def store(payment_method, options = {})
|
109
|
+
post = {}
|
110
|
+
MultiResponse.run do |r|
|
111
|
+
if payment_method.is_a?(NetworkTokenizationCreditCard)
|
112
|
+
r.process { verify(payment_method, options) }
|
113
|
+
break r unless r.success?
|
114
|
+
|
115
|
+
r.params['source']['customer'] = r.params['customer']
|
116
|
+
r.process { response(:store, true, r.params['source']) }
|
117
|
+
else
|
118
|
+
r.process { tokenize(payment_method, options) }
|
119
|
+
break r unless r.success?
|
120
|
+
|
121
|
+
token = r.params['token']
|
122
|
+
add_payment_method(post, token, options)
|
123
|
+
post.merge!(post.delete(:source))
|
124
|
+
add_customer_data(post, options)
|
125
|
+
add_shipping_address(post, options)
|
126
|
+
r.process { commit(:store, post, options) }
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
def unstore(id, options = {})
|
132
|
+
commit(:unstore, nil, options, id, :delete)
|
78
133
|
end
|
79
134
|
|
80
135
|
private
|
81
136
|
|
82
137
|
def build_auth_or_purchase(post, amount, payment_method, options)
|
83
138
|
add_invoice(post, amount, options)
|
139
|
+
add_authorization_type(post, options)
|
84
140
|
add_payment_method(post, payment_method, options)
|
85
141
|
add_customer_data(post, options)
|
142
|
+
add_extra_customer_data(post, payment_method, options)
|
143
|
+
add_shipping_address(post, options)
|
86
144
|
add_stored_credential_options(post, options)
|
87
145
|
add_transaction_data(post, options)
|
88
146
|
add_3ds(post, options)
|
89
|
-
add_metadata(post, options)
|
147
|
+
add_metadata(post, options, payment_method)
|
90
148
|
add_processing_channel(post, options)
|
91
149
|
add_marketplace_data(post, options)
|
92
150
|
end
|
@@ -104,33 +162,66 @@ module ActiveMerchant #:nodoc:
|
|
104
162
|
post[:metadata][:udf5] = application_id || 'ActiveMerchant'
|
105
163
|
end
|
106
164
|
|
107
|
-
def
|
165
|
+
def add_authorization_type(post, options)
|
166
|
+
post[:authorization_type] = options[:authorization_type] if options[:authorization_type]
|
167
|
+
end
|
168
|
+
|
169
|
+
def add_metadata(post, options, payment_method = nil)
|
108
170
|
post[:metadata] = {} unless post[:metadata]
|
109
171
|
post[:metadata].merge!(options[:metadata]) if options[:metadata]
|
172
|
+
post[:metadata][:udf1] = 'mada' if payment_method.try(:brand) == 'mada'
|
110
173
|
end
|
111
174
|
|
112
|
-
def add_payment_method(post, payment_method, options)
|
113
|
-
post[
|
114
|
-
|
175
|
+
def add_payment_method(post, payment_method, options, key = :source)
|
176
|
+
post[key] = {}
|
177
|
+
case payment_method
|
178
|
+
when NetworkTokenizationCreditCard
|
115
179
|
token_type = token_type_from(payment_method)
|
116
180
|
cryptogram = payment_method.payment_cryptogram
|
117
181
|
eci = payment_method.eci || options[:eci]
|
118
182
|
eci ||= '05' if token_type == 'vts'
|
119
183
|
|
120
|
-
post[
|
121
|
-
post[
|
122
|
-
post[
|
123
|
-
post[
|
124
|
-
post[
|
125
|
-
|
126
|
-
post[
|
127
|
-
post[
|
128
|
-
post[
|
129
|
-
post[
|
130
|
-
post[
|
184
|
+
post[key][:type] = 'network_token'
|
185
|
+
post[key][:token] = payment_method.number
|
186
|
+
post[key][:token_type] = token_type
|
187
|
+
post[key][:cryptogram] = cryptogram if cryptogram
|
188
|
+
post[key][:eci] = eci if eci
|
189
|
+
when ->(pm) { pm.try(:credit_card?) }
|
190
|
+
post[key][:type] = 'card'
|
191
|
+
post[key][:name] = payment_method.name
|
192
|
+
post[key][:number] = payment_method.number
|
193
|
+
post[key][:cvv] = payment_method.verification_value
|
194
|
+
post[key][:stored] = 'true' if options[:card_on_file] == true
|
195
|
+
if options[:account_holder_type]
|
196
|
+
post[key][:account_holder] = {}
|
197
|
+
post[key][:account_holder][:type] = options[:account_holder_type]
|
198
|
+
post[key][:account_holder][:first_name] = payment_method.first_name if payment_method.first_name
|
199
|
+
post[key][:account_holder][:last_name] = payment_method.last_name if payment_method.last_name
|
200
|
+
else
|
201
|
+
post[key][:first_name] = payment_method.first_name if payment_method.first_name
|
202
|
+
post[key][:last_name] = payment_method.last_name if payment_method.last_name
|
203
|
+
end
|
204
|
+
end
|
205
|
+
if payment_method.is_a?(String)
|
206
|
+
if /tok/.match?(payment_method)
|
207
|
+
post[:type] = 'token'
|
208
|
+
post[:token] = payment_method
|
209
|
+
elsif /src/.match?(payment_method)
|
210
|
+
post[key][:type] = 'id'
|
211
|
+
post[key][:id] = payment_method
|
212
|
+
else
|
213
|
+
add_source(post, options)
|
214
|
+
end
|
215
|
+
elsif payment_method.try(:year)
|
216
|
+
post[key][:expiry_year] = format(payment_method.year, :four_digits)
|
217
|
+
post[key][:expiry_month] = format(payment_method.month, :two_digits)
|
131
218
|
end
|
132
|
-
|
133
|
-
|
219
|
+
end
|
220
|
+
|
221
|
+
def add_source(post, options)
|
222
|
+
post[:source] = {}
|
223
|
+
post[:source][:type] = options[:source_type] if options[:source_type]
|
224
|
+
post[:source][:id] = options[:source_id] if options[:source_id]
|
134
225
|
end
|
135
226
|
|
136
227
|
def add_customer_data(post, options)
|
@@ -149,6 +240,28 @@ module ActiveMerchant #:nodoc:
|
|
149
240
|
end
|
150
241
|
end
|
151
242
|
|
243
|
+
# created a separate method for these fields because they should not be included
|
244
|
+
# in all transaction types that include methods with source and customer fields
|
245
|
+
def add_extra_customer_data(post, payment_method, options)
|
246
|
+
post[:source][:phone] = {}
|
247
|
+
post[:source][:phone][:number] = options[:phone] || options.dig(:billing_address, :phone) || options.dig(:billing_address, :phone_number)
|
248
|
+
post[:source][:phone][:country_code] = options[:phone_country_code] if options[:phone_country_code]
|
249
|
+
post[:customer][:name] = payment_method.name if payment_method.respond_to?(:name)
|
250
|
+
end
|
251
|
+
|
252
|
+
def add_shipping_address(post, options)
|
253
|
+
if address = options[:shipping_address]
|
254
|
+
post[:shipping] = {}
|
255
|
+
post[:shipping][:address] = {}
|
256
|
+
post[:shipping][:address][:address_line1] = address[:address1] unless address[:address1].blank?
|
257
|
+
post[:shipping][:address][:address_line2] = address[:address2] unless address[:address2].blank?
|
258
|
+
post[:shipping][:address][:city] = address[:city] unless address[:city].blank?
|
259
|
+
post[:shipping][:address][:state] = address[:state] unless address[:state].blank?
|
260
|
+
post[:shipping][:address][:country] = address[:country] unless address[:country].blank?
|
261
|
+
post[:shipping][:address][:zip] = address[:zip] unless address[:zip].blank?
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
152
265
|
def add_transaction_data(post, options = {})
|
153
266
|
post[:payment_type] = 'Regular' if options[:transaction_indicator] == 1
|
154
267
|
post[:payment_type] = 'Recurring' if options[:transaction_indicator] == 2
|
@@ -156,23 +269,31 @@ module ActiveMerchant #:nodoc:
|
|
156
269
|
post[:previous_payment_id] = options[:previous_charge_id] if options[:previous_charge_id]
|
157
270
|
end
|
158
271
|
|
159
|
-
def
|
160
|
-
|
272
|
+
def merchant_initiated_override(post, options)
|
273
|
+
post[:merchant_initiated] = true
|
274
|
+
post[:source][:stored] = true
|
275
|
+
post[:previous_payment_id] = options[:merchant_initiated_transaction_id]
|
276
|
+
end
|
161
277
|
|
162
|
-
|
163
|
-
|
278
|
+
def add_stored_credentials_using_normalized_fields(post, options)
|
279
|
+
if options[:stored_credential][:initial_transaction] == true
|
164
280
|
post[:merchant_initiated] = false
|
165
|
-
|
166
|
-
post[:
|
281
|
+
else
|
282
|
+
post[:source][:stored] = true
|
167
283
|
post[:previous_payment_id] = options[:stored_credential][:network_transaction_id] if options[:stored_credential][:network_transaction_id]
|
168
284
|
post[:merchant_initiated] = true
|
169
285
|
end
|
286
|
+
end
|
287
|
+
|
288
|
+
def add_stored_credential_options(post, options = {})
|
289
|
+
return unless options[:stored_credential]
|
290
|
+
|
291
|
+
post[:payment_type] = 'Recurring' if %w(recurring installment).include? options[:stored_credential][:reason_type]
|
170
292
|
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
return
|
293
|
+
if options[:merchant_initiated_transaction_id]
|
294
|
+
merchant_initiated_override(post, options)
|
295
|
+
else
|
296
|
+
add_stored_credentials_using_normalized_fields(post, options)
|
176
297
|
end
|
177
298
|
end
|
178
299
|
|
@@ -183,6 +304,8 @@ module ActiveMerchant #:nodoc:
|
|
183
304
|
post[:success_url] = options[:callback_url] if options[:callback_url]
|
184
305
|
post[:failure_url] = options[:callback_url] if options[:callback_url]
|
185
306
|
post[:'3ds'][:attempt_n3d] = options[:attempt_n3d] if options[:attempt_n3d]
|
307
|
+
post[:'3ds'][:challenge_indicator] = options[:challenge_indicator] if options[:challenge_indicator]
|
308
|
+
post[:'3ds'][:exemption] = options[:exemption] if options[:exemption]
|
186
309
|
end
|
187
310
|
|
188
311
|
if options[:three_d_secure]
|
@@ -190,6 +313,7 @@ module ActiveMerchant #:nodoc:
|
|
190
313
|
post[:'3ds'][:cryptogram] = options[:three_d_secure][:cavv] if options[:three_d_secure][:cavv]
|
191
314
|
post[:'3ds'][:version] = options[:three_d_secure][:version] if options[:three_d_secure][:version]
|
192
315
|
post[:'3ds'][:xid] = options[:three_d_secure][:ds_transaction_id] || options[:three_d_secure][:xid]
|
316
|
+
post[:'3ds'][:status] = options[:three_d_secure][:authentication_response_status]
|
193
317
|
end
|
194
318
|
end
|
195
319
|
|
@@ -204,55 +328,95 @@ module ActiveMerchant #:nodoc:
|
|
204
328
|
end
|
205
329
|
end
|
206
330
|
|
207
|
-
def
|
331
|
+
def access_token_header
|
332
|
+
{
|
333
|
+
'Authorization' => "Basic #{Base64.encode64("#{@options[:client_id]}:#{@options[:client_secret]}").delete("\n")}",
|
334
|
+
'Content-Type' => 'application/x-www-form-urlencoded'
|
335
|
+
}
|
336
|
+
end
|
337
|
+
|
338
|
+
def access_token_url
|
339
|
+
test? ? TEST_ACCESS_TOKEN_URL : LIVE_ACCESS_TOKEN_URL
|
340
|
+
end
|
341
|
+
|
342
|
+
def setup_access_token
|
343
|
+
request = 'grant_type=client_credentials'
|
344
|
+
response = parse(ssl_post(access_token_url, request, access_token_header))
|
345
|
+
response['access_token']
|
346
|
+
end
|
347
|
+
|
348
|
+
def commit(action, post, options, authorization = nil, method = :post)
|
208
349
|
begin
|
209
|
-
raw_response = (
|
350
|
+
raw_response = ssl_request(method, url(action, authorization), post.nil? || post.empty? ? nil : post.to_json, headers(action, options))
|
210
351
|
response = parse(raw_response)
|
211
352
|
response['id'] = response['_links']['payment']['href'].split('/')[-1] if action == :capture && response.key?('_links')
|
353
|
+
source_id = authorization if action == :unstore
|
212
354
|
rescue ResponseError => e
|
213
355
|
raise unless e.response.code.to_s =~ /4\d\d/
|
214
356
|
|
215
357
|
response = parse(e.response.body, error: e.response)
|
216
358
|
end
|
217
359
|
|
218
|
-
succeeded = success_from(response)
|
360
|
+
succeeded = success_from(action, response)
|
219
361
|
|
220
|
-
response(action, succeeded, response)
|
362
|
+
response(action, succeeded, response, source_id)
|
221
363
|
end
|
222
364
|
|
223
|
-
def response(action, succeeded, response)
|
365
|
+
def response(action, succeeded, response, source_id = nil)
|
224
366
|
successful_response = succeeded && action == :purchase || action == :authorize
|
225
367
|
avs_result = successful_response ? avs_result(response) : nil
|
226
368
|
cvv_result = successful_response ? cvv_result(response) : nil
|
227
|
-
|
369
|
+
authorization = authorization_from(response) unless action == :unstore
|
370
|
+
body = action == :unstore ? { response_code: response.to_s } : response
|
228
371
|
Response.new(
|
229
372
|
succeeded,
|
230
373
|
message_from(succeeded, response),
|
231
|
-
|
232
|
-
authorization:
|
233
|
-
error_code: error_code_from(succeeded,
|
374
|
+
body,
|
375
|
+
authorization: authorization,
|
376
|
+
error_code: error_code_from(succeeded, body),
|
234
377
|
test: test?,
|
235
378
|
avs_result: avs_result,
|
236
379
|
cvv_result: cvv_result
|
237
380
|
)
|
238
381
|
end
|
239
382
|
|
240
|
-
def headers
|
241
|
-
{
|
242
|
-
|
383
|
+
def headers(action, options)
|
384
|
+
auth_token = @access_token ? "Bearer #{@access_token}" : @options[:secret_key]
|
385
|
+
auth_token = @options[:public_key] if action == :tokens
|
386
|
+
headers = {
|
387
|
+
'Authorization' => auth_token,
|
243
388
|
'Content-Type' => 'application/json;charset=UTF-8'
|
244
389
|
}
|
390
|
+
headers['Cko-Idempotency-Key'] = options[:idempotency_key] if options[:idempotency_key]
|
391
|
+
headers
|
245
392
|
end
|
246
393
|
|
247
|
-
def
|
248
|
-
|
394
|
+
def tokenize(payment_method, options = {})
|
395
|
+
post = {}
|
396
|
+
add_authorization_type(post, options)
|
397
|
+
add_payment_method(post, payment_method, options)
|
398
|
+
add_customer_data(post, options)
|
399
|
+
commit(:tokens, post[:source], options)
|
400
|
+
end
|
401
|
+
|
402
|
+
def url(action, authorization)
|
403
|
+
case action
|
404
|
+
when :authorize, :purchase, :credit
|
249
405
|
"#{base_url}/payments"
|
250
|
-
|
406
|
+
when :unstore, :store
|
407
|
+
"#{base_url}/instruments/#{authorization}"
|
408
|
+
when :capture
|
251
409
|
"#{base_url}/payments/#{authorization}/captures"
|
252
|
-
|
410
|
+
when :refund
|
253
411
|
"#{base_url}/payments/#{authorization}/refunds"
|
254
|
-
|
412
|
+
when :void
|
255
413
|
"#{base_url}/payments/#{authorization}/voids"
|
414
|
+
when :incremental_authorize
|
415
|
+
"#{base_url}/payments/#{authorization}/authorizations"
|
416
|
+
when :tokens
|
417
|
+
"#{base_url}/tokens"
|
418
|
+
when :verify_payment
|
419
|
+
"#{base_url}/payments/#{authorization}"
|
256
420
|
else
|
257
421
|
"#{base_url}/payments/#{authorization}/#{action}"
|
258
422
|
end
|
@@ -282,7 +446,14 @@ module ActiveMerchant #:nodoc:
|
|
282
446
|
response
|
283
447
|
end
|
284
448
|
|
285
|
-
def success_from(response)
|
449
|
+
def success_from(action, response)
|
450
|
+
return response['status'] == 'Pending' if action == :credit
|
451
|
+
return true if action == :unstore && response == 204
|
452
|
+
|
453
|
+
store_response = response['token'] || response['id']
|
454
|
+
if store_response
|
455
|
+
return true if (action == :tokens && store_response.match(/tok/)) || (action == :store && store_response.match(/src_/))
|
456
|
+
end
|
286
457
|
response['response_summary'] == 'Approved' || response['approved'] == true || !response.key?('response_summary') && response.key?('action_id')
|
287
458
|
end
|
288
459
|
|
@@ -335,6 +506,16 @@ module ActiveMerchant #:nodoc:
|
|
335
506
|
'applepay'
|
336
507
|
end
|
337
508
|
end
|
509
|
+
|
510
|
+
def handle_response(response)
|
511
|
+
case response.code.to_i
|
512
|
+
# to get the response code after unstore(delete instrument), because the body is nil
|
513
|
+
when 200...300
|
514
|
+
response.body || response.code
|
515
|
+
else
|
516
|
+
raise ResponseError.new(response)
|
517
|
+
end
|
518
|
+
end
|
338
519
|
end
|
339
520
|
end
|
340
521
|
end
|