activemerchant 1.125.0 → 1.129.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +316 -0
  3. data/lib/active_merchant/billing/check.rb +40 -8
  4. data/lib/active_merchant/billing/credit_card.rb +28 -1
  5. data/lib/active_merchant/billing/credit_card_methods.rb +91 -23
  6. data/lib/active_merchant/billing/gateway.rb +2 -1
  7. data/lib/active_merchant/billing/gateways/adyen.rb +74 -12
  8. data/lib/active_merchant/billing/gateways/airwallex.rb +370 -0
  9. data/lib/active_merchant/billing/gateways/alelo.rb +256 -0
  10. data/lib/active_merchant/billing/gateways/authorize_net.rb +21 -4
  11. data/lib/active_merchant/billing/gateways/barclaycard_smartpay.rb +2 -1
  12. data/lib/active_merchant/billing/gateways/beanstream.rb +18 -0
  13. data/lib/active_merchant/billing/gateways/blue_pay.rb +1 -1
  14. data/lib/active_merchant/billing/gateways/blue_snap.rb +53 -22
  15. data/lib/active_merchant/billing/gateways/bogus.rb +4 -0
  16. data/lib/active_merchant/billing/gateways/borgun.rb +56 -16
  17. data/lib/active_merchant/billing/gateways/braintree/braintree_common.rb +6 -1
  18. data/lib/active_merchant/billing/gateways/braintree/token_nonce.rb +113 -0
  19. data/lib/active_merchant/billing/gateways/braintree_blue.rb +151 -32
  20. data/lib/active_merchant/billing/gateways/card_connect.rb +28 -10
  21. data/lib/active_merchant/billing/gateways/card_stream.rb +23 -0
  22. data/lib/active_merchant/billing/gateways/checkout_v2.rb +228 -57
  23. data/lib/active_merchant/billing/gateways/commerce_hub.rb +361 -0
  24. data/lib/active_merchant/billing/gateways/credorax.rb +56 -26
  25. data/lib/active_merchant/billing/gateways/cyber_source/cyber_source_common.rb +36 -0
  26. data/lib/active_merchant/billing/gateways/cyber_source.rb +112 -58
  27. data/lib/active_merchant/billing/gateways/cyber_source_rest.rb +456 -0
  28. data/lib/active_merchant/billing/gateways/d_local.rb +93 -5
  29. data/lib/active_merchant/billing/gateways/decidir.rb +32 -5
  30. data/lib/active_merchant/billing/gateways/decidir_plus.rb +185 -14
  31. data/lib/active_merchant/billing/gateways/ebanx.rb +39 -26
  32. data/lib/active_merchant/billing/gateways/element.rb +21 -1
  33. data/lib/active_merchant/billing/gateways/global_collect.rb +98 -37
  34. data/lib/active_merchant/billing/gateways/ipg.rb +14 -10
  35. data/lib/active_merchant/billing/gateways/iveri.rb +39 -3
  36. data/lib/active_merchant/billing/gateways/kushki.rb +21 -1
  37. data/lib/active_merchant/billing/gateways/litle.rb +118 -6
  38. data/lib/active_merchant/billing/gateways/mastercard.rb +1 -8
  39. data/lib/active_merchant/billing/gateways/mercado_pago.rb +17 -0
  40. data/lib/active_merchant/billing/gateways/merchant_e_solutions.rb +44 -10
  41. data/lib/active_merchant/billing/gateways/monei.rb +2 -0
  42. data/lib/active_merchant/billing/gateways/moneris.rb +55 -13
  43. data/lib/active_merchant/billing/gateways/mundipagg.rb +3 -0
  44. data/lib/active_merchant/billing/gateways/nmi.rb +12 -7
  45. data/lib/active_merchant/billing/gateways/ogone.rb +35 -7
  46. data/lib/active_merchant/billing/gateways/openpay.rb +20 -3
  47. data/lib/active_merchant/billing/gateways/orbital.rb +378 -335
  48. data/lib/active_merchant/billing/gateways/pay_trace.rb +64 -18
  49. data/lib/active_merchant/billing/gateways/payeezy.rb +59 -4
  50. data/lib/active_merchant/billing/gateways/payflow.rb +62 -0
  51. data/lib/active_merchant/billing/gateways/paymentez.rb +44 -13
  52. data/lib/active_merchant/billing/gateways/paypal/paypal_express_response.rb +4 -0
  53. data/lib/active_merchant/billing/gateways/paysafe.rb +37 -29
  54. data/lib/active_merchant/billing/gateways/payu_latam.rb +28 -15
  55. data/lib/active_merchant/billing/gateways/plexo.rb +308 -0
  56. data/lib/active_merchant/billing/gateways/priority.rb +185 -140
  57. data/lib/active_merchant/billing/gateways/rapyd.rb +319 -0
  58. data/lib/active_merchant/billing/gateways/reach.rb +277 -0
  59. data/lib/active_merchant/billing/gateways/redsys.rb +9 -5
  60. data/lib/active_merchant/billing/gateways/safe_charge.rb +1 -4
  61. data/lib/active_merchant/billing/gateways/sage_pay.rb +1 -1
  62. data/lib/active_merchant/billing/gateways/securion_pay.rb +40 -0
  63. data/lib/active_merchant/billing/gateways/shift4.rb +342 -0
  64. data/lib/active_merchant/billing/gateways/simetrik.rb +368 -0
  65. data/lib/active_merchant/billing/gateways/stripe.rb +25 -3
  66. data/lib/active_merchant/billing/gateways/stripe_payment_intents.rb +155 -70
  67. data/lib/active_merchant/billing/gateways/tns.rb +2 -5
  68. data/lib/active_merchant/billing/gateways/trans_first_transaction_express.rb +1 -1
  69. data/lib/active_merchant/billing/gateways/trust_commerce.rb +14 -3
  70. data/lib/active_merchant/billing/gateways/vanco.rb +12 -3
  71. data/lib/active_merchant/billing/gateways/visanet_peru.rb +6 -2
  72. data/lib/active_merchant/billing/gateways/vpos.rb +7 -4
  73. data/lib/active_merchant/billing/gateways/wompi.rb +8 -4
  74. data/lib/active_merchant/billing/gateways/worldpay.rb +117 -9
  75. data/lib/active_merchant/billing/response.rb +15 -1
  76. data/lib/active_merchant/connection.rb +0 -2
  77. data/lib/active_merchant/country.rb +1 -0
  78. data/lib/active_merchant/errors.rb +4 -1
  79. data/lib/active_merchant/version.rb +1 -1
  80. metadata +28 -3
@@ -0,0 +1,319 @@
1
+ module ActiveMerchant #:nodoc:
2
+ module Billing #:nodoc:
3
+ class RapydGateway < Gateway
4
+ self.test_url = 'https://sandboxapi.rapyd.net/v1/'
5
+ self.live_url = 'https://api.rapyd.net/v1/'
6
+
7
+ self.supported_countries = %w(CA CL CO DO SV PE PT VI AU HK IN ID JP MY NZ PH SG KR TW TH VN AD AT BE BA BG HR CY CZ DK EE FI FR GE DE GI GR GL HU IS IE IL IT LV LI LT LU MK MT MD MC ME NL GB NO PL RO RU SM SK SI ZA ES SE CH TR VA)
8
+ self.default_currency = 'USD'
9
+ self.supported_cardtypes = %i[visa master american_express discover]
10
+
11
+ self.homepage_url = 'https://www.rapyd.net/'
12
+ self.display_name = 'Rapyd Gateway'
13
+
14
+ USA_PAYMENT_METHODS = %w[us_debit_discover_card us_debit_mastercard_card us_debit_visa_card us_ach_bank]
15
+
16
+ STANDARD_ERROR_CODE_MAPPING = {}
17
+
18
+ def initialize(options = {})
19
+ requires!(options, :secret_key, :access_key)
20
+ super
21
+ end
22
+
23
+ def purchase(money, payment, options = {})
24
+ post = {}
25
+ add_auth_purchase(post, money, payment, options)
26
+ post[:capture] = true unless payment.is_a?(Check)
27
+
28
+ commit(:post, 'payments', post)
29
+ end
30
+
31
+ def authorize(money, payment, options = {})
32
+ post = {}
33
+ add_auth_purchase(post, money, payment, options)
34
+ post[:capture] = false unless payment.is_a?(Check)
35
+
36
+ commit(:post, 'payments', post)
37
+ end
38
+
39
+ def capture(money, authorization, options = {})
40
+ post = {}
41
+ commit(:post, "payments/#{add_reference(authorization)}/capture", post)
42
+ end
43
+
44
+ def refund(money, authorization, options = {})
45
+ post = {}
46
+ post[:payment] = add_reference(authorization)
47
+ add_invoice(post, money, options)
48
+ add_metadata(post, options)
49
+ add_ewallet(post, options)
50
+
51
+ commit(:post, 'refunds', post)
52
+ end
53
+
54
+ def void(authorization, options = {})
55
+ post = {}
56
+ commit(:delete, "payments/#{add_reference(authorization)}", post)
57
+ end
58
+
59
+ def verify(credit_card, options = {})
60
+ authorize(0, credit_card, options)
61
+ end
62
+
63
+ def store(payment, options = {})
64
+ post = {}
65
+ add_payment(post, payment, options)
66
+ add_customer_object(post, payment, options)
67
+ add_metadata(post, options)
68
+ add_ewallet(post, options)
69
+ add_payment_fields(post, options)
70
+ add_payment_urls(post, options)
71
+ add_address(post, payment, options)
72
+ commit(:post, 'customers', post)
73
+ end
74
+
75
+ def unstore(customer)
76
+ commit(:delete, "customers/#{add_reference(customer)}", {})
77
+ end
78
+
79
+ def supports_scrubbing?
80
+ true
81
+ end
82
+
83
+ def scrub(transcript)
84
+ transcript.
85
+ gsub(%r((Access_key: )\w+), '\1[FILTERED]').
86
+ gsub(%r(("number\\?":\\?")\d+), '\1[FILTERED]').
87
+ gsub(%r(("account_number\\?":\\?")\d+), '\1[FILTERED]').
88
+ gsub(%r(("routing_number\\?":\\?")\d+), '\1[FILTERED]').
89
+ gsub(%r(("cvv\\?":\\?")\d+), '\1[FILTERED]')
90
+ end
91
+
92
+ private
93
+
94
+ def add_reference(authorization)
95
+ return unless authorization
96
+
97
+ authorization.split('|')[0]
98
+ end
99
+
100
+ def add_auth_purchase(post, money, payment, options)
101
+ add_invoice(post, money, options)
102
+ add_payment(post, payment, options)
103
+ add_customer_object(post, payment, options)
104
+ add_3ds(post, payment, options)
105
+ add_address(post, payment, options)
106
+ add_metadata(post, options)
107
+ add_ewallet(post, options)
108
+ add_payment_fields(post, options)
109
+ add_payment_urls(post, options)
110
+ add_customer_id(post, options)
111
+ end
112
+
113
+ def add_address(post, creditcard, options)
114
+ return unless address = options[:billing_address]
115
+
116
+ post[:address] = {}
117
+ # name and line_1 are required at the gateway
118
+ post[:address][:name] = address[:name] if address[:name]
119
+ post[:address][:line_1] = address[:address1] if address[:address1]
120
+ post[:address][:line_2] = address[:address2] if address[:address2]
121
+ post[:address][:city] = address[:city] if address[:city]
122
+ post[:address][:state] = address[:state] if address[:state]
123
+ post[:address][:country] = address[:country] if address[:country]
124
+ post[:address][:zip] = address[:zip] if address[:zip]
125
+ post[:address][:phone_number] = address[:phone].gsub(/\D/, '') if address[:phone]
126
+ end
127
+
128
+ def add_invoice(post, money, options)
129
+ post[:amount] = money.zero? ? 0 : amount(money).to_f.to_s
130
+ post[:currency] = (options[:currency] || currency(money))
131
+ end
132
+
133
+ def add_payment(post, payment, options)
134
+ if payment.is_a?(CreditCard)
135
+ add_creditcard(post, payment, options)
136
+ elsif payment.is_a?(Check)
137
+ add_ach(post, payment, options)
138
+ else
139
+ add_token(post, payment, options)
140
+ end
141
+ end
142
+
143
+ def add_stored_credential(post, options)
144
+ return unless stored_credential = options[:stored_credential]
145
+
146
+ post[:payment_method][:fields][:network_reference_id] = stored_credential[:network_transaction_id] if stored_credential[:network_transaction_id]
147
+ post[:initiation_type] = stored_credential[:reason_type] if stored_credential[:reason_type]
148
+ end
149
+
150
+ def add_creditcard(post, payment, options)
151
+ post[:payment_method] = {}
152
+ post[:payment_method][:fields] = {}
153
+ pm_fields = post[:payment_method][:fields]
154
+
155
+ post[:payment_method][:type] = options[:pm_type]
156
+ pm_fields[:number] = payment.number
157
+ pm_fields[:expiration_month] = payment.month.to_s
158
+ pm_fields[:expiration_year] = payment.year.to_s
159
+ pm_fields[:name] = "#{payment.first_name} #{payment.last_name}"
160
+ pm_fields[:cvv] = payment.verification_value.to_s
161
+
162
+ add_stored_credential(post, options)
163
+ end
164
+
165
+ def add_ach(post, payment, options)
166
+ post[:payment_method] = {}
167
+ post[:payment_method][:fields] = {}
168
+
169
+ post[:payment_method][:type] = options[:pm_type]
170
+ post[:payment_method][:fields][:proof_of_authorization] = options[:proof_of_authorization]
171
+ post[:payment_method][:fields][:first_name] = payment.first_name if payment.first_name
172
+ post[:payment_method][:fields][:last_name] = payment.last_name if payment.last_name
173
+ post[:payment_method][:fields][:routing_number] = payment.routing_number
174
+ post[:payment_method][:fields][:account_number] = payment.account_number
175
+ post[:payment_method][:fields][:payment_purpose] = options[:payment_purpose] if options[:payment_purpose]
176
+ end
177
+
178
+ def add_token(post, payment, options)
179
+ return unless token = payment.split('|')[1]
180
+
181
+ post[:payment_method] = token
182
+ end
183
+
184
+ def add_3ds(post, payment, options)
185
+ return unless three_d_secure = options[:three_d_secure]
186
+
187
+ post[:payment_method_options] = {}
188
+ post[:payment_method_options]['3d_required'] = three_d_secure[:required]
189
+ post[:payment_method_options]['3d_version'] = three_d_secure[:version]
190
+ post[:payment_method_options][:cavv] = three_d_secure[:cavv]
191
+ post[:payment_method_options][:eci] = three_d_secure[:eci]
192
+ post[:payment_method_options][:xid] = three_d_secure[:xid]
193
+ post[:payment_method_options][:ds_trans_id] = three_d_secure[:ds_transaction_id]
194
+ end
195
+
196
+ def add_metadata(post, options)
197
+ post[:metadata] = options[:metadata] if options[:metadata]
198
+ end
199
+
200
+ def add_ewallet(post, options)
201
+ post[:ewallet_id] = options[:ewallet_id] if options[:ewallet_id]
202
+ end
203
+
204
+ def add_payment_fields(post, options)
205
+ post[:payment] = {}
206
+
207
+ post[:payment][:description] = options[:description] if options[:description]
208
+ post[:payment][:statement_descriptor] = options[:statement_descriptor] if options[:statement_descriptor]
209
+ end
210
+
211
+ def add_payment_urls(post, options)
212
+ post[:complete_payment_url] = options[:complete_payment_url] if options[:complete_payment_url]
213
+ post[:error_payment_url] = options[:error_payment_url] if options[:error_payment_url]
214
+ end
215
+
216
+ def add_customer_object(post, payment, options)
217
+ post[:name] = "#{payment.first_name} #{payment.last_name}" unless payment.is_a?(String)
218
+ phone = options.dig(:billing_address, :phone) .gsub(/\D/, '') unless options[:billing_address].nil?
219
+ post[:phone_number] = phone || options.dig(:customer, :phone_number)
220
+ post[:email] = options[:email] || options.dig(:customer, :email)
221
+ post[:addresses] = options.dig(:customer, :addresses) if USA_PAYMENT_METHODS.include?(options[:pm_type])
222
+ end
223
+
224
+ def add_customer_id(post, options)
225
+ post[:customer] = options[:customer_id] if options[:customer_id]
226
+ end
227
+
228
+ def parse(body)
229
+ return {} if body.empty? || body.nil?
230
+
231
+ JSON.parse(body)
232
+ end
233
+
234
+ def commit(method, action, parameters)
235
+ url = (test? ? test_url : live_url) + action.to_s
236
+ rel_path = "#{method}/v1/#{action}"
237
+ response = api_request(method, url, rel_path, parameters)
238
+
239
+ Response.new(
240
+ success_from(response),
241
+ message_from(response),
242
+ response,
243
+ authorization: authorization_from(response),
244
+ avs_result: avs_result(response),
245
+ cvv_result: cvv_result(response),
246
+ test: test?,
247
+ error_code: error_code_from(response)
248
+ )
249
+ end
250
+
251
+ def api_request(method, url, rel_path, params)
252
+ params == {} ? body = '' : body = params.to_json
253
+ parse(ssl_request(method, url, body, headers(rel_path, body)))
254
+ end
255
+
256
+ def headers(rel_path, payload)
257
+ salt = SecureRandom.base64(12)
258
+ timestamp = Time.new.to_i.to_s
259
+ {
260
+ 'Content-Type' => 'application/json',
261
+ 'access_key' => @options[:access_key],
262
+ 'salt' => salt,
263
+ 'timestamp' => timestamp,
264
+ 'signature' => generate_hmac(rel_path, salt, timestamp, payload)
265
+ }
266
+ end
267
+
268
+ def generate_hmac(rel_path, salt, timestamp, payload)
269
+ signature = "#{rel_path}#{salt}#{timestamp}#{@options[:access_key]}#{@options[:secret_key]}#{payload}"
270
+ hash = Base64.urlsafe_encode64(OpenSSL::HMAC.hexdigest('sha256', @options[:secret_key], signature))
271
+ hash
272
+ end
273
+
274
+ def avs_result(response)
275
+ return nil unless (code = response.dig('data', 'payment_method_data', 'acs_check'))
276
+
277
+ AVSResult.new(code: code)
278
+ end
279
+
280
+ def cvv_result(response)
281
+ return nil unless (code = response.dig('data', 'payment_method_data', 'cvv_check'))
282
+
283
+ CVVResult.new(code)
284
+ end
285
+
286
+ def success_from(response)
287
+ response.dig('status', 'status') == 'SUCCESS' && response.dig('status', 'error') != 'ERR'
288
+ end
289
+
290
+ def message_from(response)
291
+ case response.dig('status', 'status')
292
+ when 'ERROR'
293
+ response.dig('status', 'message') == '' ? response.dig('status', 'error_code') : response.dig('status', 'message')
294
+ else
295
+ response.dig('status', 'status')
296
+ end
297
+ end
298
+
299
+ def authorization_from(response)
300
+ id = response.dig('data') ? response.dig('data', 'id') : response.dig('status', 'operation_id')
301
+
302
+ "#{id}|#{response.dig('data', 'default_payment_method')}"
303
+ end
304
+
305
+ def error_code_from(response)
306
+ response.dig('status', 'error_code') unless success_from(response)
307
+ end
308
+
309
+ def handle_response(response)
310
+ case response.code.to_i
311
+ when 200...300, 400, 401, 404
312
+ response.body
313
+ else
314
+ raise ResponseError.new(response)
315
+ end
316
+ end
317
+ end
318
+ end
319
+ end
@@ -0,0 +1,277 @@
1
+ module ActiveMerchant #:nodoc:
2
+ module Billing #:nodoc:
3
+ class ReachGateway < Gateway
4
+ self.test_url = 'https://checkout.rch.how/'
5
+ self.live_url = 'https://checkout.rch.io/'
6
+
7
+ self.supported_countries = ['US']
8
+ self.default_currency = 'USD'
9
+ self.supported_cardtypes = %i[visa diners_club american_express jcb master discover maestro]
10
+
11
+ self.homepage_url = 'https://www.withreach.com/'
12
+ self.display_name = 'Reach'
13
+ self.currencies_without_fractions = %w(BIF BYR CLF CLP CVE DJF GNF ISK JPY KMF KRW PYG RWF UGX UYI VND VUV XAF XOF XPF IDR MGA MRO)
14
+
15
+ API_VERSION = 'v2.22'.freeze
16
+ STANDARD_ERROR_CODE_MAPPING = {}
17
+ PAYMENT_METHOD_MAP = {
18
+ american_express: 'AMEX',
19
+ cabal: 'CABAL',
20
+ check: 'ACH',
21
+ dankort: 'DANKORT',
22
+ diners_club: 'DINERS',
23
+ discover: 'DISC',
24
+ elo: 'ELO',
25
+ jcb: 'JCB',
26
+ maestro: 'MAESTRO',
27
+ master: 'MC',
28
+ naranja: 'NARANJA',
29
+ union_pay: 'UNIONPAY',
30
+ visa: 'VISA'
31
+ }
32
+
33
+ def initialize(options = {})
34
+ requires!(options, :merchant_id, :secret)
35
+ super
36
+ end
37
+
38
+ def authorize(money, payment, options = {})
39
+ request = build_checkout_request(money, payment, options)
40
+ add_custom_fields_data(request, options)
41
+ add_customer_data(request, options, payment)
42
+ add_stored_credentials(request, options)
43
+ post = { request: request, card: add_payment(payment, options) }
44
+ if options[:stored_credential]
45
+ MultiResponse.run(:use_first_response) do |r|
46
+ r.process { commit('checkout', post) }
47
+ r.process do
48
+ r2 = get_network_payment_reference(r.responses[0])
49
+ r.params[:network_transaction_id] = r2.message
50
+ r2
51
+ end
52
+ end
53
+ else
54
+ commit('checkout', post)
55
+ end
56
+ end
57
+
58
+ def purchase(money, payment, options = {})
59
+ options[:capture] = true
60
+ authorize(money, payment, options)
61
+ end
62
+
63
+ def capture(money, authorization, options = {})
64
+ post = { request: { MerchantId: @options[:merchant_id], OrderId: authorization } }
65
+ commit('capture', post)
66
+ end
67
+
68
+ def supports_scrubbing?
69
+ true
70
+ end
71
+
72
+ def scrub(transcript)
73
+ transcript.
74
+ gsub(%r(((MerchantId)[% \w]+[%]\d{2})[\w -]+), '\1[FILTERED]').
75
+ gsub(%r((signature=)[\w%]+), '\1[FILTERED]\2').
76
+ gsub(%r((Number%22%3A%22)[\d]+), '\1[FILTERED]\2').
77
+ gsub(%r((VerificationCode%22%3A)[\d]+), '\1[FILTERED]\2')
78
+ end
79
+
80
+ def refund(amount, authorization, options = {})
81
+ currency = options[:currency] || currency(options[:amount])
82
+ post = {
83
+ request: {
84
+ MerchantId: @options[:merchant_id],
85
+ OrderId: authorization,
86
+ ReferenceId: options[:order_id] || options[:reference_id],
87
+ Amount: localized_amount(amount, currency)
88
+ }
89
+ }
90
+ commit('refund', post)
91
+ end
92
+
93
+ def void(authorization, options = {})
94
+ post = {
95
+ request: {
96
+ MerchantId: @options[:merchant_id],
97
+ OrderId: authorization
98
+ }
99
+ }
100
+
101
+ commit('cancel', post)
102
+ end
103
+
104
+ def verify(credit_card, options = {})
105
+ MultiResponse.run(:use_first_response) do |r|
106
+ r.process { authorize(100, credit_card, options) }
107
+ r.process(:ignore_result) { void(r.authorization, options) }
108
+ end
109
+ end
110
+
111
+ private
112
+
113
+ def build_checkout_request(amount, payment, options)
114
+ currency = options[:currency] || currency(options[:amount])
115
+ {
116
+ MerchantId: @options[:merchant_id],
117
+ ReferenceId: options[:order_id],
118
+ ConsumerCurrency: currency,
119
+ Capture: options[:capture] || false,
120
+ PaymentMethod: PAYMENT_METHOD_MAP.fetch(payment.brand.to_sym, 'unsupported'),
121
+ Items: [
122
+ Sku: options[:item_sku] || SecureRandom.alphanumeric,
123
+ ConsumerPrice: localized_amount(amount, currency),
124
+ Quantity: (options[:item_quantity] || 1)
125
+ ]
126
+ }
127
+ end
128
+
129
+ def add_payment(payment, options)
130
+ ntid = options.dig(:stored_credential, :network_transaction_id)
131
+ cvv_or_previos_reference = (ntid ? { PreviousNetworkPaymentReference: ntid } : { VerificationCode: payment.verification_value })
132
+ {
133
+ Name: payment.name,
134
+ Number: payment.number,
135
+ Expiry: { Month: payment.month, Year: payment.year }
136
+ }.merge!(cvv_or_previos_reference)
137
+ end
138
+
139
+ def add_customer_data(request, options, payment)
140
+ address = options[:billing_address] || options[:address]
141
+
142
+ return if address.blank?
143
+
144
+ request[:Consumer] = {
145
+ Name: payment.respond_to?(:name) ? payment.name : address[:name],
146
+ Email: options[:email],
147
+ Address: address[:address1],
148
+ City: address[:city],
149
+ Country: address[:country]
150
+ }.compact
151
+ end
152
+
153
+ def add_stored_credentials(request, options)
154
+ request[:PaymentModel] = payment_model(options) || ''
155
+ request[:DeviceFingerprint] = options[:device_fingerprint] if options[:device_fingerprint]
156
+ end
157
+
158
+ def payment_model(options)
159
+ stored_credential = options[:stored_credential]
160
+ return options[:payment_model] if options[:payment_model]
161
+ return 'CIT-One-Time' unless stored_credential
162
+
163
+ payment_model_options = {
164
+ initial_transaction: {
165
+ 'cardholder' => {
166
+ 'installment' => 'CIT-Setup-Scheduled',
167
+ 'unscheduled' => 'CIT-Setup-Unscheduled-MIT',
168
+ 'recurring' => 'CIT-Setup-Unscheduled'
169
+ }
170
+ },
171
+ no_initial_transaction: {
172
+ 'cardholder' => {
173
+ 'unscheduled' => 'CIT-Subsequent-Unscheduled'
174
+ },
175
+ 'merchant' => {
176
+ 'recurring' => 'MIT-Subsequent-Scheduled',
177
+ 'unscheduled' => 'MIT-Subsequent-Unscheduled'
178
+ }
179
+ }
180
+ }
181
+ initial = stored_credential[:initial_transaction] ? :initial_transaction : :no_initial_transaction
182
+ payment_model_options[initial].dig(stored_credential[:initiator], stored_credential[:reason_type])
183
+ end
184
+
185
+ def add_custom_fields_data(request, options)
186
+ add_shipping_data(request, options) if options[:taxes].present?
187
+ request[:RateOfferId] = options[:rate_offer_id] if options[:rate_offer_id].present?
188
+ request[:Items] = options[:items] if options[:items].present?
189
+ end
190
+
191
+ def add_shipping_data(request, options)
192
+ request[:Shipping] = {
193
+ ConsumerPrice: options[:price],
194
+ ConsumerTaxes: options[:taxes],
195
+ ConsumerDuty: options[:duty]
196
+ }
197
+ request[:Consignee] = {
198
+ Name: options[:consignee_name],
199
+ Address: options[:consignee_address],
200
+ City: options[:consignee_city],
201
+ Country: options[:consignee_country]
202
+ }
203
+ end
204
+
205
+ def sign_body(body)
206
+ Base64.strict_encode64(OpenSSL::HMAC.digest('sha256', @options[:secret].encode('utf-8'), body.encode('utf-8')))
207
+ end
208
+
209
+ def parse(body)
210
+ hash_response = URI.decode_www_form(body).to_h
211
+ hash_response['response'] = JSON.parse(hash_response['response'])
212
+
213
+ hash_response
214
+ end
215
+
216
+ def format_and_sign(post)
217
+ post[:request] = post[:request].to_json
218
+ post[:card] = post[:card].to_json if post[:card].present?
219
+ post[:signature] = sign_body(post[:request])
220
+ post
221
+ end
222
+
223
+ def get_network_payment_reference(response)
224
+ parameters = { request: { MerchantId: @options[:merchant_id], OrderId: response.params['response']['OrderId'] } }
225
+ body = post_data format_and_sign(parameters)
226
+
227
+ raw_response = ssl_request :post, url('query'), body, {}
228
+ response = parse(raw_response)
229
+ message = response.dig('response', 'Payment', 'NetworkPaymentReference')
230
+ Response.new(true, message, {})
231
+ end
232
+
233
+ def commit(action, parameters)
234
+ body = post_data format_and_sign(parameters)
235
+ raw_response = ssl_post url(action), body
236
+ response = parse(raw_response)
237
+
238
+ Response.new(
239
+ success_from(response),
240
+ message_from(response) || '',
241
+ response,
242
+ authorization: authorization_from(response['response']),
243
+ # avs_result: AVSResult.new(code: response['some_avs_response_key']),
244
+ # cvv_result: CVVResult.new(response['some_cvv_response_key']),
245
+ test: test?,
246
+ error_code: error_code_from(response)
247
+ )
248
+ rescue ActiveMerchant::ResponseError => e
249
+ Response.new(false, (e.response.body.present? ? e.response.body : e.response.msg), {}, test: test?)
250
+ end
251
+
252
+ def success_from(response)
253
+ response.dig('response', 'Error').blank?
254
+ end
255
+
256
+ def message_from(response)
257
+ success_from(response) ? '' : response.dig('response', 'Error', 'ReasonCode')
258
+ end
259
+
260
+ def authorization_from(response)
261
+ response['OrderId']
262
+ end
263
+
264
+ def post_data(params)
265
+ params.map { |k, v| "#{k}=#{CGI.escape(v.to_s)}" }.join('&')
266
+ end
267
+
268
+ def error_code_from(response)
269
+ response['response']['Error']['Code'] unless success_from(response)
270
+ end
271
+
272
+ def url(action)
273
+ "#{test? ? test_url : live_url}#{API_VERSION}/#{action}"
274
+ end
275
+ end
276
+ end
277
+ end
@@ -91,7 +91,7 @@ module ActiveMerchant #:nodoc:
91
91
  # More operations are supported by the gateway itself, but
92
92
  # are not supported in this library.
93
93
  SUPPORTED_TRANSACTIONS = {
94
- purchase: 'A',
94
+ purchase: '0',
95
95
  authorize: '1',
96
96
  capture: '2',
97
97
  refund: '3',
@@ -266,9 +266,13 @@ module ActiveMerchant #:nodoc:
266
266
  end
267
267
 
268
268
  def verify(creditcard, options = {})
269
- MultiResponse.run(:use_first_response) do |r|
270
- r.process { authorize(100, creditcard, options) }
271
- r.process(:ignore_result) { void(r.authorization, options) }
269
+ if options[:sca_exemption_behavior_override] == 'endpoint_and_ntid'
270
+ purchase(0, creditcard, options)
271
+ else
272
+ MultiResponse.run(:use_first_response) do |r|
273
+ r.process { authorize(100, creditcard, options) }
274
+ r.process(:ignore_result) { void(r.authorization, options) }
275
+ end
272
276
  end
273
277
  end
274
278
 
@@ -685,7 +689,7 @@ module ActiveMerchant #:nodoc:
685
689
  cipher = OpenSSL::Cipher.new('DES3')
686
690
  cipher.encrypt
687
691
 
688
- cipher.key = Base64.strict_decode64(key)
692
+ cipher.key = Base64.urlsafe_decode64(key)
689
693
  # The OpenSSL default of an all-zeroes ("\\0") IV is used.
690
694
  cipher.padding = 0
691
695
 
@@ -107,10 +107,7 @@ module ActiveMerchant #:nodoc:
107
107
  end
108
108
 
109
109
  def verify(credit_card, options = {})
110
- MultiResponse.run(:use_first_response) do |r|
111
- r.process { authorize(100, credit_card, options) }
112
- r.process(:ignore_result) { void(r.authorization, options) }
113
- end
110
+ authorize(0, credit_card, options)
114
111
  end
115
112
 
116
113
  def supports_scrubbing?
@@ -427,7 +427,7 @@ module ActiveMerchant #:nodoc:
427
427
  def past_purchase_reference?(payment_method)
428
428
  return false unless payment_method.is_a?(String)
429
429
 
430
- payment_method.split(';').last == 'purchase'
430
+ %w(purchase repeat).include?(payment_method.split(';').last)
431
431
  end
432
432
  end
433
433
  end