activemerchant 1.130.0 → 1.137.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (184) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +268 -0
  3. data/lib/active_merchant/billing/check.rb +2 -2
  4. data/lib/active_merchant/billing/compatibility.rb +4 -4
  5. data/lib/active_merchant/billing/credit_card.rb +13 -8
  6. data/lib/active_merchant/billing/credit_card_formatting.rb +4 -0
  7. data/lib/active_merchant/billing/credit_card_methods.rb +64 -7
  8. data/lib/active_merchant/billing/gateway.rb +9 -0
  9. data/lib/active_merchant/billing/gateways/adyen.rb +240 -41
  10. data/lib/active_merchant/billing/gateways/airwallex.rb +26 -12
  11. data/lib/active_merchant/billing/gateways/alelo.rb +23 -5
  12. data/lib/active_merchant/billing/gateways/authorize_net.rb +44 -36
  13. data/lib/active_merchant/billing/gateways/authorize_net_arb.rb +10 -6
  14. data/lib/active_merchant/billing/gateways/authorize_net_cim.rb +1 -3
  15. data/lib/active_merchant/billing/gateways/axcessms.rb +6 -2
  16. data/lib/active_merchant/billing/gateways/banwire.rb +4 -2
  17. data/lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb +7 -3
  18. data/lib/active_merchant/billing/gateways/blue_pay.rb +13 -5
  19. data/lib/active_merchant/billing/gateways/blue_snap.rb +5 -5
  20. data/lib/active_merchant/billing/gateways/borgun.rb +6 -4
  21. data/lib/active_merchant/billing/gateways/braintree/token_nonce.rb +65 -20
  22. data/lib/active_merchant/billing/gateways/braintree_blue.rb +226 -73
  23. data/lib/active_merchant/billing/gateways/braintree_orange.rb +1 -1
  24. data/lib/active_merchant/billing/gateways/card_connect.rb +5 -2
  25. data/lib/active_merchant/billing/gateways/card_stream.rb +4 -6
  26. data/lib/active_merchant/billing/gateways/cashnet.rb +1 -1
  27. data/lib/active_merchant/billing/gateways/cecabank/cecabank_common.rb +36 -0
  28. data/lib/active_merchant/billing/gateways/cecabank/cecabank_json.rb +316 -0
  29. data/lib/active_merchant/billing/gateways/cecabank/cecabank_xml.rb +220 -0
  30. data/lib/active_merchant/billing/gateways/cecabank.rb +7 -240
  31. data/lib/active_merchant/billing/gateways/checkout_v2.rb +252 -41
  32. data/lib/active_merchant/billing/gateways/commerce_hub.rb +69 -8
  33. data/lib/active_merchant/billing/gateways/credorax.rb +3 -5
  34. data/lib/active_merchant/billing/gateways/cyber_source.rb +192 -41
  35. data/lib/active_merchant/billing/gateways/cyber_source_rest.rb +102 -58
  36. data/lib/active_merchant/billing/gateways/d_local.rb +26 -15
  37. data/lib/active_merchant/billing/gateways/data_cash.rb +21 -17
  38. data/lib/active_merchant/billing/gateways/datatrans.rb +279 -0
  39. data/lib/active_merchant/billing/gateways/decidir.rb +53 -18
  40. data/lib/active_merchant/billing/gateways/decidir_plus.rb +4 -1
  41. data/lib/active_merchant/billing/gateways/deepstack.rb +382 -0
  42. data/lib/active_merchant/billing/gateways/ebanx.rb +40 -36
  43. data/lib/active_merchant/billing/gateways/efsnet.rb +6 -2
  44. data/lib/active_merchant/billing/gateways/elavon.rb +99 -33
  45. data/lib/active_merchant/billing/gateways/element.rb +36 -7
  46. data/lib/active_merchant/billing/gateways/epay.rb +6 -2
  47. data/lib/active_merchant/billing/gateways/evo_ca.rb +6 -2
  48. data/lib/active_merchant/billing/gateways/eway.rb +4 -2
  49. data/lib/active_merchant/billing/gateways/eway_managed.rb +6 -2
  50. data/lib/active_merchant/billing/gateways/exact.rb +6 -2
  51. data/lib/active_merchant/billing/gateways/fat_zebra.rb +31 -3
  52. data/lib/active_merchant/billing/gateways/federated_canada.rb +6 -2
  53. data/lib/active_merchant/billing/gateways/first_pay/first_pay_common.rb +15 -0
  54. data/lib/active_merchant/billing/gateways/first_pay/first_pay_json.rb +190 -0
  55. data/lib/active_merchant/billing/gateways/first_pay/first_pay_xml.rb +183 -0
  56. data/lib/active_merchant/billing/gateways/first_pay.rb +6 -172
  57. data/lib/active_merchant/billing/gateways/firstdata_e4.rb +6 -2
  58. data/lib/active_merchant/billing/gateways/firstdata_e4_v27.rb +7 -3
  59. data/lib/active_merchant/billing/gateways/flex_charge.rb +347 -0
  60. data/lib/active_merchant/billing/gateways/garanti.rb +4 -2
  61. data/lib/active_merchant/billing/gateways/global_collect.rb +45 -37
  62. data/lib/active_merchant/billing/gateways/hi_pay.rb +286 -0
  63. data/lib/active_merchant/billing/gateways/hps.rb +1 -1
  64. data/lib/active_merchant/billing/gateways/iats_payments.rb +7 -2
  65. data/lib/active_merchant/billing/gateways/inspire.rb +6 -4
  66. data/lib/active_merchant/billing/gateways/instapay.rb +7 -4
  67. data/lib/active_merchant/billing/gateways/ipg.rb +10 -6
  68. data/lib/active_merchant/billing/gateways/iridium.rb +15 -5
  69. data/lib/active_merchant/billing/gateways/itransact.rb +6 -2
  70. data/lib/active_merchant/billing/gateways/iveri.rb +3 -3
  71. data/lib/active_merchant/billing/gateways/ixopay.rb +2 -2
  72. data/lib/active_merchant/billing/gateways/jetpay.rb +4 -2
  73. data/lib/active_merchant/billing/gateways/jetpay_v2.rb +4 -2
  74. data/lib/active_merchant/billing/gateways/kushki.rb +73 -13
  75. data/lib/active_merchant/billing/gateways/linkpoint.rb +6 -2
  76. data/lib/active_merchant/billing/gateways/litle.rb +33 -50
  77. data/lib/active_merchant/billing/gateways/mastercard.rb +4 -4
  78. data/lib/active_merchant/billing/gateways/maxipago.rb +2 -2
  79. data/lib/active_merchant/billing/gateways/merchant_e_solutions.rb +8 -5
  80. data/lib/active_merchant/billing/gateways/merchant_ware.rb +11 -4
  81. data/lib/active_merchant/billing/gateways/merchant_ware_version_four.rb +11 -4
  82. data/lib/active_merchant/billing/gateways/merchant_warrior.rb +19 -3
  83. data/lib/active_merchant/billing/gateways/mercury.rb +6 -2
  84. data/lib/active_merchant/billing/gateways/metrics_global.rb +8 -6
  85. data/lib/active_merchant/billing/gateways/migs/migs_codes.rb +1 -0
  86. data/lib/active_merchant/billing/gateways/migs.rb +6 -2
  87. data/lib/active_merchant/billing/gateways/mit.rb +25 -20
  88. data/lib/active_merchant/billing/gateways/modern_payments_cim.rb +18 -10
  89. data/lib/active_merchant/billing/gateways/monei.rb +1 -1
  90. data/lib/active_merchant/billing/gateways/moneris.rb +9 -3
  91. data/lib/active_merchant/billing/gateways/money_movers.rb +6 -2
  92. data/lib/active_merchant/billing/gateways/nab_transact.rb +12 -4
  93. data/lib/active_merchant/billing/gateways/net_registry.rb +6 -2
  94. data/lib/active_merchant/billing/gateways/netbanx.rb +1 -3
  95. data/lib/active_merchant/billing/gateways/netbilling.rb +6 -2
  96. data/lib/active_merchant/billing/gateways/network_merchants.rb +6 -2
  97. data/lib/active_merchant/billing/gateways/nmi.rb +23 -6
  98. data/lib/active_merchant/billing/gateways/ogone.rb +6 -2
  99. data/lib/active_merchant/billing/gateways/openpay.rb +4 -2
  100. data/lib/active_merchant/billing/gateways/opp.rb +1 -2
  101. data/lib/active_merchant/billing/gateways/optimal_payment.rb +6 -2
  102. data/lib/active_merchant/billing/gateways/orbital/orbital_soft_descriptors.rb +1 -3
  103. data/lib/active_merchant/billing/gateways/orbital.rb +83 -24
  104. data/lib/active_merchant/billing/gateways/pac_net_raven.rb +7 -4
  105. data/lib/active_merchant/billing/gateways/pay_gate_xml.rb +6 -2
  106. data/lib/active_merchant/billing/gateways/pay_hub.rb +4 -2
  107. data/lib/active_merchant/billing/gateways/pay_junction.rb +6 -2
  108. data/lib/active_merchant/billing/gateways/pay_secure.rb +6 -2
  109. data/lib/active_merchant/billing/gateways/pay_trace.rb +31 -18
  110. data/lib/active_merchant/billing/gateways/payeezy.rb +19 -8
  111. data/lib/active_merchant/billing/gateways/payex.rb +4 -2
  112. data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +1 -1
  113. data/lib/active_merchant/billing/gateways/payflow.rb +1 -3
  114. data/lib/active_merchant/billing/gateways/payment_express.rb +8 -4
  115. data/lib/active_merchant/billing/gateways/paymentez.rb +23 -11
  116. data/lib/active_merchant/billing/gateways/paysafe.rb +12 -11
  117. data/lib/active_merchant/billing/gateways/payscout.rb +7 -4
  118. data/lib/active_merchant/billing/gateways/paystation.rb +7 -3
  119. data/lib/active_merchant/billing/gateways/payway.rb +6 -2
  120. data/lib/active_merchant/billing/gateways/payway_dot_com.rb +3 -3
  121. data/lib/active_merchant/billing/gateways/pin.rb +22 -4
  122. data/lib/active_merchant/billing/gateways/plexo.rb +49 -10
  123. data/lib/active_merchant/billing/gateways/plugnpay.rb +6 -2
  124. data/lib/active_merchant/billing/gateways/priority.rb +6 -5
  125. data/lib/active_merchant/billing/gateways/psigate.rb +6 -2
  126. data/lib/active_merchant/billing/gateways/psl_card.rb +6 -2
  127. data/lib/active_merchant/billing/gateways/qbms.rb +6 -2
  128. data/lib/active_merchant/billing/gateways/quantum.rb +6 -2
  129. data/lib/active_merchant/billing/gateways/quickbooks.rb +6 -5
  130. data/lib/active_merchant/billing/gateways/quickpay/quickpay_v10.rb +7 -4
  131. data/lib/active_merchant/billing/gateways/quickpay/quickpay_v4to7.rb +6 -2
  132. data/lib/active_merchant/billing/gateways/rapyd.rb +148 -46
  133. data/lib/active_merchant/billing/gateways/reach.rb +11 -4
  134. data/lib/active_merchant/billing/gateways/redsys.rb +3 -11
  135. data/lib/active_merchant/billing/gateways/redsys_rest.rb +507 -0
  136. data/lib/active_merchant/billing/gateways/s5.rb +3 -3
  137. data/lib/active_merchant/billing/gateways/safe_charge.rb +38 -17
  138. data/lib/active_merchant/billing/gateways/sage.rb +12 -4
  139. data/lib/active_merchant/billing/gateways/sage_pay.rb +79 -5
  140. data/lib/active_merchant/billing/gateways/sallie_mae.rb +6 -2
  141. data/lib/active_merchant/billing/gateways/secure_net.rb +6 -2
  142. data/lib/active_merchant/billing/gateways/secure_pay.rb +8 -6
  143. data/lib/active_merchant/billing/gateways/secure_pay_au.rb +12 -4
  144. data/lib/active_merchant/billing/gateways/secure_pay_tech.rb +6 -2
  145. data/lib/active_merchant/billing/gateways/securion_pay.rb +24 -10
  146. data/lib/active_merchant/billing/gateways/shift4.rb +17 -20
  147. data/lib/active_merchant/billing/gateways/shift4_v2.rb +117 -0
  148. data/lib/active_merchant/billing/gateways/simetrik.rb +17 -11
  149. data/lib/active_merchant/billing/gateways/skip_jack.rb +6 -2
  150. data/lib/active_merchant/billing/gateways/smart_ps.rb +7 -4
  151. data/lib/active_merchant/billing/gateways/so_easy_pay.rb +4 -2
  152. data/lib/active_merchant/billing/gateways/spreedly_core.rb +2 -4
  153. data/lib/active_merchant/billing/gateways/stripe.rb +63 -19
  154. data/lib/active_merchant/billing/gateways/stripe_payment_intents.rb +280 -88
  155. data/lib/active_merchant/billing/gateways/sum_up.rb +223 -0
  156. data/lib/active_merchant/billing/gateways/swipe_checkout.rb +4 -2
  157. data/lib/active_merchant/billing/gateways/telr.rb +3 -4
  158. data/lib/active_merchant/billing/gateways/trans_first.rb +1 -2
  159. data/lib/active_merchant/billing/gateways/trans_first_transaction_express.rb +8 -16
  160. data/lib/active_merchant/billing/gateways/transact_pro.rb +1 -1
  161. data/lib/active_merchant/billing/gateways/trust_commerce.rb +6 -2
  162. data/lib/active_merchant/billing/gateways/usa_epay_advanced.rb +9 -8
  163. data/lib/active_merchant/billing/gateways/usa_epay_transaction.rb +6 -2
  164. data/lib/active_merchant/billing/gateways/vanco.rb +2 -4
  165. data/lib/active_merchant/billing/gateways/vantiv_express.rb +587 -0
  166. data/lib/active_merchant/billing/gateways/verifi.rb +6 -2
  167. data/lib/active_merchant/billing/gateways/viaklix.rb +6 -2
  168. data/lib/active_merchant/billing/gateways/visanet_peru.rb +2 -2
  169. data/lib/active_merchant/billing/gateways/vpos.rb +4 -4
  170. data/lib/active_merchant/billing/gateways/wirecard.rb +7 -3
  171. data/lib/active_merchant/billing/gateways/wompi.rb +5 -0
  172. data/lib/active_merchant/billing/gateways/worldpay.rb +147 -93
  173. data/lib/active_merchant/billing/gateways/worldpay_online_payments.rb +13 -10
  174. data/lib/active_merchant/billing/gateways/xpay.rb +242 -0
  175. data/lib/active_merchant/billing/network_tokenization_credit_card.rb +1 -1
  176. data/lib/active_merchant/billing/response.rb +2 -2
  177. data/lib/active_merchant/connection.rb +3 -17
  178. data/lib/active_merchant/country.rb +1 -0
  179. data/lib/active_merchant/errors.rb +10 -0
  180. data/lib/active_merchant/version.rb +1 -1
  181. data/lib/support/gateway_support.rb +2 -2
  182. data/lib/support/ssl_verify.rb +4 -4
  183. data/lib/support/ssl_version.rb +6 -6
  184. metadata +30 -9
@@ -17,15 +17,7 @@ module ActiveMerchant #:nodoc:
17
17
  TEST_ACCESS_TOKEN_URL = 'https://access.sandbox.checkout.com/connect/token'
18
18
 
19
19
  def initialize(options = {})
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
20
+ options.has_key?(:secret_key) ? requires!(options, :secret_key) : requires!(options, :client_id, :client_secret)
29
21
 
30
22
  super
31
23
  end
@@ -41,6 +33,7 @@ module ActiveMerchant #:nodoc:
41
33
  post = {}
42
34
  post[:capture] = false
43
35
  build_auth_or_purchase(post, amount, payment_method, options)
36
+
44
37
  options[:incremental_authorization] ? commit(:incremental_authorize, post, options, options[:incremental_authorization]) : commit(:authorize, post, options)
45
38
  end
46
39
 
@@ -57,12 +50,13 @@ module ActiveMerchant #:nodoc:
57
50
 
58
51
  def credit(amount, payment, options = {})
59
52
  post = {}
60
- post[:instruction] = {}
61
- post[:instruction][:funds_transfer_type] = options[:funds_transfer_type] || 'FD'
62
53
  add_processing_channel(post, options)
63
54
  add_invoice(post, amount, options)
64
55
  add_payment_method(post, payment, options, :destination)
65
56
  add_source(post, options)
57
+ add_instruction_data(post, options)
58
+ add_payout_sender_data(post, options)
59
+ add_payout_destination_data(post, options)
66
60
 
67
61
  commit(:credit, post, options)
68
62
  end
@@ -87,7 +81,7 @@ module ActiveMerchant #:nodoc:
87
81
  authorize(0, credit_card, options)
88
82
  end
89
83
 
90
- def verify_payment(authorization, option = {})
84
+ def verify_payment(authorization, options = {})
91
85
  commit(:verify_payment, nil, options, authorization, :get)
92
86
  end
93
87
 
@@ -102,7 +96,8 @@ module ActiveMerchant #:nodoc:
102
96
  gsub(/("cvv\\":\\")\d+/, '\1[FILTERED]').
103
97
  gsub(/("cryptogram\\":\\")\w+/, '\1[FILTERED]').
104
98
  gsub(/(source\\":\{.*\\"token\\":\\")\d+/, '\1[FILTERED]').
105
- gsub(/("token\\":\\")\w+/, '\1[FILTERED]')
99
+ gsub(/("token\\":\\")\w+/, '\1[FILTERED]').
100
+ gsub(/("access_token\\?"\s*:\s*\\?")[^"]*\w+/, '\1[FILTERED]')
106
101
  end
107
102
 
108
103
  def store(payment_method, options = {})
@@ -139,6 +134,7 @@ module ActiveMerchant #:nodoc:
139
134
  add_authorization_type(post, options)
140
135
  add_payment_method(post, payment_method, options)
141
136
  add_customer_data(post, options)
137
+ add_extra_customer_data(post, payment_method, options)
142
138
  add_shipping_address(post, options)
143
139
  add_stored_credential_options(post, options)
144
140
  add_transaction_data(post, options)
@@ -146,6 +142,11 @@ module ActiveMerchant #:nodoc:
146
142
  add_metadata(post, options, payment_method)
147
143
  add_processing_channel(post, options)
148
144
  add_marketplace_data(post, options)
145
+ add_recipient_data(post, options)
146
+ add_processing_data(post, options)
147
+ add_payment_sender_data(post, options)
148
+ add_risk_data(post, options)
149
+ truncate_amex_reference_id(post, options, payment_method)
149
150
  end
150
151
 
151
152
  def add_invoice(post, money, options)
@@ -161,6 +162,90 @@ module ActiveMerchant #:nodoc:
161
162
  post[:metadata][:udf5] = application_id || 'ActiveMerchant'
162
163
  end
163
164
 
165
+ def truncate_amex_reference_id(post, options, payment_method)
166
+ post[:reference] = truncate(options[:order_id], 30) if payment_method.respond_to?(:brand) && payment_method.brand == 'american_express'
167
+ end
168
+
169
+ def add_recipient_data(post, options)
170
+ return unless options[:recipient].is_a?(Hash)
171
+
172
+ recipient = options[:recipient]
173
+
174
+ post[:recipient] = {}
175
+ post[:recipient][:dob] = recipient[:dob] if recipient[:dob]
176
+ post[:recipient][:zip] = recipient[:zip] if recipient[:zip]
177
+ post[:recipient][:account_number] = recipient[:account_number] if recipient[:account_number]
178
+ post[:recipient][:first_name] = recipient[:first_name] if recipient[:first_name]
179
+ post[:recipient][:last_name] = recipient[:last_name] if recipient[:last_name]
180
+
181
+ if address = recipient[:address]
182
+ address1 = address[:address1] || address[:address_line1]
183
+ address2 = address[:address2] || address[:address_line2]
184
+
185
+ post[:recipient][:address] = {}
186
+ post[:recipient][:address][:address_line1] = address1 if address1
187
+ post[:recipient][:address][:address_line2] = address2 if address2
188
+ post[:recipient][:address][:city] = address[:city] if address[:city]
189
+ post[:recipient][:address][:state] = address[:state] if address[:state]
190
+ post[:recipient][:address][:zip] = address[:zip] if address[:zip]
191
+ post[:recipient][:address][:country] = address[:country] if address[:country]
192
+ end
193
+ end
194
+
195
+ def add_processing_data(post, options)
196
+ return unless options[:processing].is_a?(Hash)
197
+
198
+ post[:processing] = options[:processing]
199
+ end
200
+
201
+ def add_risk_data(post, options)
202
+ return unless options[:risk].is_a?(Hash)
203
+
204
+ risk = options[:risk]
205
+ post[:risk] = {} unless risk.empty?
206
+
207
+ if risk[:enabled].to_s == 'true'
208
+ post[:risk][:enabled] = true
209
+ post[:risk][:device_session_id] = risk[:device_session_id] if risk[:device_session_id]
210
+ elsif risk[:enabled].to_s == 'false'
211
+ post[:risk][:enabled] = false
212
+ end
213
+ end
214
+
215
+ def add_payment_sender_data(post, options)
216
+ return unless options[:sender].is_a?(Hash)
217
+
218
+ sender = options[:sender]
219
+
220
+ post[:sender] = {}
221
+ post[:sender][:type] = sender[:type] if sender[:type]
222
+ post[:sender][:first_name] = sender[:first_name] if sender[:first_name]
223
+ post[:sender][:last_name] = sender[:last_name] if sender[:last_name]
224
+ post[:sender][:dob] = sender[:dob] if sender[:dob]
225
+ post[:sender][:reference] = sender[:reference] if sender[:reference]
226
+ post[:sender][:company_name] = sender[:company_name] if sender[:company_name]
227
+
228
+ if address = sender[:address]
229
+ address1 = address[:address1] || address[:address_line1]
230
+ address2 = address[:address2] || address[:address_line2]
231
+
232
+ post[:sender][:address] = {}
233
+ post[:sender][:address][:address_line1] = address1 if address1
234
+ post[:sender][:address][:address_line2] = address2 if address2
235
+ post[:sender][:address][:city] = address[:city] if address[:city]
236
+ post[:sender][:address][:state] = address[:state] if address[:state]
237
+ post[:sender][:address][:zip] = address[:zip] if address[:zip]
238
+ post[:sender][:address][:country] = address[:country] if address[:country]
239
+ end
240
+
241
+ if identification = sender[:identification]
242
+ post[:sender][:identification] = {}
243
+ post[:sender][:identification][:type] = identification[:type] if identification[:type]
244
+ post[:sender][:identification][:number] = identification[:number] if identification[:number]
245
+ post[:sender][:identification][:issuing_country] = identification[:issuing_country] if identification[:issuing_country]
246
+ end
247
+ end
248
+
164
249
  def add_authorization_type(post, options)
165
250
  post[:authorization_type] = options[:authorization_type] if options[:authorization_type]
166
251
  end
@@ -172,6 +257,7 @@ module ActiveMerchant #:nodoc:
172
257
  end
173
258
 
174
259
  def add_payment_method(post, payment_method, options, key = :source)
260
+ # the key = :destination when this method is called in def credit
175
261
  post[key] = {}
176
262
  case payment_method
177
263
  when NetworkTokenizationCreditCard
@@ -189,13 +275,23 @@ module ActiveMerchant #:nodoc:
189
275
  post[key][:type] = 'card'
190
276
  post[key][:name] = payment_method.name
191
277
  post[key][:number] = payment_method.number
192
- post[key][:cvv] = payment_method.verification_value
278
+ post[key][:cvv] = payment_method.verification_value unless options[:funds_transfer_type]
193
279
  post[key][:stored] = 'true' if options[:card_on_file] == true
280
+
281
+ # because of the way the key = is implemented in the method signature, some of the destination
282
+ # data will be added here, some in the destination specific method below.
283
+ # at first i was going to move this, but since this data is coming from the payment method
284
+ # i think it makes sense to leave it
194
285
  if options[:account_holder_type]
195
286
  post[key][:account_holder] = {}
196
287
  post[key][:account_holder][:type] = options[:account_holder_type]
197
- post[key][:account_holder][:first_name] = payment_method.first_name if payment_method.first_name
198
- post[key][:account_holder][:last_name] = payment_method.last_name if payment_method.last_name
288
+
289
+ if options[:account_holder_type] == 'corporate' || options[:account_holder_type] == 'government'
290
+ post[key][:account_holder][:company_name] = payment_method.name if payment_method.respond_to?(:name)
291
+ else
292
+ post[key][:account_holder][:first_name] = payment_method.first_name if payment_method.first_name
293
+ post[key][:account_holder][:last_name] = payment_method.last_name if payment_method.last_name
294
+ end
199
295
  else
200
296
  post[key][:first_name] = payment_method.first_name if payment_method.first_name
201
297
  post[key][:last_name] = payment_method.last_name if payment_method.last_name
@@ -239,6 +335,15 @@ module ActiveMerchant #:nodoc:
239
335
  end
240
336
  end
241
337
 
338
+ # created a separate method for these fields because they should not be included
339
+ # in all transaction types that include methods with source and customer fields
340
+ def add_extra_customer_data(post, payment_method, options)
341
+ post[:source][:phone] = {}
342
+ post[:source][:phone][:number] = options[:phone] || options.dig(:billing_address, :phone) || options.dig(:billing_address, :phone_number)
343
+ post[:source][:phone][:country_code] = options[:phone_country_code] if options[:phone_country_code]
344
+ post[:customer][:name] = payment_method.name if payment_method.respond_to?(:name)
345
+ end
346
+
242
347
  def add_shipping_address(post, options)
243
348
  if address = options[:shipping_address]
244
349
  post[:shipping] = {}
@@ -266,7 +371,7 @@ module ActiveMerchant #:nodoc:
266
371
  end
267
372
 
268
373
  def add_stored_credentials_using_normalized_fields(post, options)
269
- if options[:stored_credential][:initial_transaction] == true
374
+ if options[:stored_credential][:initiator] == 'cardholder'
270
375
  post[:merchant_initiated] = false
271
376
  else
272
377
  post[:source][:stored] = true
@@ -311,6 +416,82 @@ module ActiveMerchant #:nodoc:
311
416
  post[:processing_channel_id] = options[:processing_channel_id] if options[:processing_channel_id]
312
417
  end
313
418
 
419
+ def add_instruction_data(post, options)
420
+ post[:instruction] = {}
421
+ post[:instruction][:funds_transfer_type] = options[:funds_transfer_type] || 'FD'
422
+ post[:instruction][:purpose] = options[:instruction_purpose] if options[:instruction_purpose]
423
+ end
424
+
425
+ def add_payout_sender_data(post, options)
426
+ return unless options[:payout] == true
427
+
428
+ post[:sender] = {
429
+ # options for type are individual, corporate, or government
430
+ type: options[:sender][:type],
431
+ # first and last name required if sent by type: individual
432
+ first_name: options[:sender][:first_name],
433
+ middle_name: options[:sender][:middle_name],
434
+ last_name: options[:sender][:last_name],
435
+ # company name required if sent by type: corporate or government
436
+ company_name: options[:sender][:company_name],
437
+ # these are required fields for payout, may not work if address is blank or different than cardholder(option for sender to be a company or government).
438
+ # may need to still include in GSF hash.
439
+
440
+ address: {
441
+ address_line1: options.dig(:sender, :address, :address1),
442
+ address_line2: options.dig(:sender, :address, :address2),
443
+ city: options.dig(:sender, :address, :city),
444
+ state: options.dig(:sender, :address, :state),
445
+ country: options.dig(:sender, :address, :country),
446
+ zip: options.dig(:sender, :address, :zip)
447
+ }.compact,
448
+ reference: options[:sender][:reference],
449
+ reference_type: options[:sender][:reference_type],
450
+ source_of_funds: options[:sender][:source_of_funds],
451
+ # identification object is conditional. required when card metadata issuer_country = AR, BR, CO, or PR
452
+ # checkout docs say PR (Peru), but PR is puerto rico and PE is Peru so yikes
453
+ identification: {
454
+ type: options.dig(:sender, :identification, :type),
455
+ number: options.dig(:sender, :identification, :number),
456
+ issuing_country: options.dig(:sender, :identification, :issuing_country),
457
+ date_of_expiry: options.dig(:sender, :identification, :date_of_expiry)
458
+ }.compact,
459
+ date_of_birth: options[:sender][:date_of_birth],
460
+ country_of_birth: options[:sender][:country_of_birth],
461
+ nationality: options[:sender][:nationality]
462
+ }.compact
463
+ end
464
+
465
+ def add_payout_destination_data(post, options)
466
+ return unless options[:payout] == true
467
+
468
+ post[:destination] ||= {}
469
+ post[:destination][:account_holder] ||= {}
470
+ post[:destination][:account_holder][:email] = options[:destination][:account_holder][:email] if options[:destination][:account_holder][:email]
471
+ post[:destination][:account_holder][:date_of_birth] = options[:destination][:account_holder][:date_of_birth] if options[:destination][:account_holder][:date_of_birth]
472
+ post[:destination][:account_holder][:country_of_birth] = options[:destination][:account_holder][:country_of_birth] if options[:destination][:account_holder][:country_of_birth]
473
+ # below fields only required during a card to card payout
474
+ post[:destination][:account_holder][:phone] = {}
475
+ post[:destination][:account_holder][:phone][:country_code] = options.dig(:destination, :account_holder, :phone, :country_code) if options.dig(:destination, :account_holder, :phone, :country_code)
476
+ post[:destination][:account_holder][:phone][:number] = options.dig(:destination, :account_holder, :phone, :number) if options.dig(:destination, :account_holder, :phone, :number)
477
+
478
+ post[:destination][:account_holder][:identification] = {}
479
+ post[:destination][:account_holder][:identification][:type] = options.dig(:destination, :account_holder, :identification, :type) if options.dig(:destination, :account_holder, :identification, :type)
480
+ post[:destination][:account_holder][:identification][:number] = options.dig(:destination, :account_holder, :identification, :number) if options.dig(:destination, :account_holder, :identification, :number)
481
+ post[:destination][:account_holder][:identification][:issuing_country] = options.dig(:destination, :account_holder, :identification, :issuing_country) if options.dig(:destination, :account_holder, :identification, :issuing_country)
482
+ post[:destination][:account_holder][:identification][:date_of_expiry] = options.dig(:destination, :account_holder, :identification, :date_of_expiry) if options.dig(:destination, :account_holder, :identification, :date_of_expiry)
483
+
484
+ if address = options[:billing_address] || options[:address] # destination address will come from the tokenized card billing address
485
+ post[:destination][:account_holder][:billing_address] = {}
486
+ post[:destination][:account_holder][:billing_address][:address_line1] = address[:address1] unless address[:address1].blank?
487
+ post[:destination][:account_holder][:billing_address][:address_line2] = address[:address2] unless address[:address2].blank?
488
+ post[:destination][:account_holder][:billing_address][:city] = address[:city] unless address[:city].blank?
489
+ post[:destination][:account_holder][:billing_address][:state] = address[:state] unless address[:state].blank?
490
+ post[:destination][:account_holder][:billing_address][:country] = address[:country] unless address[:country].blank?
491
+ post[:destination][:account_holder][:billing_address][:zip] = address[:zip] unless address[:zip].blank?
492
+ end
493
+ end
494
+
314
495
  def add_marketplace_data(post, options)
315
496
  if options[:marketplace]
316
497
  post[:marketplace] = {}
@@ -329,19 +510,43 @@ module ActiveMerchant #:nodoc:
329
510
  test? ? TEST_ACCESS_TOKEN_URL : LIVE_ACCESS_TOKEN_URL
330
511
  end
331
512
 
513
+ def expires_date_with_extra_range(expires_in)
514
+ # Two minutes are subtracted from the expires_in time to generate the expires date
515
+ # in order to prevent any transaction from failing due to using an access_token
516
+ # that is very close to expiring.
517
+ # e.g. the access_token has one second left to expire and the lag when the transaction
518
+ # use an already expired access_token
519
+ (DateTime.now + (expires_in - 120).seconds).strftime('%Q').to_i
520
+ end
521
+
332
522
  def setup_access_token
333
- request = 'grant_type=client_credentials'
334
- response = parse(ssl_post(access_token_url, request, access_token_header))
335
- response['access_token']
523
+ response = parse(ssl_post(access_token_url, 'grant_type=client_credentials', access_token_header))
524
+ @options[:access_token] = response['access_token']
525
+ @options[:expires] = expires_date_with_extra_range(response['expires_in']) if response['expires_in'] && response['expires_in'] > 0
526
+
527
+ Response.new(
528
+ access_token_valid?,
529
+ message_from(access_token_valid?, response, {}),
530
+ response.merge({ expires: @options[:expires] }),
531
+ test: test?,
532
+ error_code: error_code_from(access_token_valid?, response, {})
533
+ )
534
+ rescue ResponseError => e
535
+ raise OAuthResponseError.new(e)
336
536
  end
337
537
 
338
- def commit(action, post, options, authorization = nil, method = :post)
538
+ def access_token_valid?
539
+ @options[:access_token].present? && @options[:expires].to_i > DateTime.now.strftime('%Q').to_i
540
+ end
541
+
542
+ def perform_request(action, post, options, authorization = nil, method = :post)
339
543
  begin
340
544
  raw_response = ssl_request(method, url(action, authorization), post.nil? || post.empty? ? nil : post.to_json, headers(action, options))
341
545
  response = parse(raw_response)
342
546
  response['id'] = response['_links']['payment']['href'].split('/')[-1] if action == :capture && response.key?('_links')
343
- source_id = authorization if action == :unstore
344
547
  rescue ResponseError => e
548
+ @options[:access_token] = '' if e.response.code == '401' && !@options[:secret_key]
549
+
345
550
  raise unless e.response.code.to_s =~ /4\d\d/
346
551
 
347
552
  response = parse(e.response.body, error: e.response)
@@ -349,29 +554,33 @@ module ActiveMerchant #:nodoc:
349
554
 
350
555
  succeeded = success_from(action, response)
351
556
 
352
- response(action, succeeded, response, source_id)
557
+ response(action, succeeded, response, options)
558
+ end
559
+
560
+ def commit(action, post, options, authorization = nil, method = :post)
561
+ MultiResponse.run do |r|
562
+ r.process { setup_access_token } unless @options[:secret_key] || access_token_valid?
563
+ r.process { perform_request(action, post, options, authorization, method) }
564
+ end
353
565
  end
354
566
 
355
- def response(action, succeeded, response, source_id = nil)
356
- successful_response = succeeded && action == :purchase || action == :authorize
357
- avs_result = successful_response ? avs_result(response) : nil
358
- cvv_result = successful_response ? cvv_result(response) : nil
567
+ def response(action, succeeded, response, options = {}, source_id = nil)
359
568
  authorization = authorization_from(response) unless action == :unstore
360
569
  body = action == :unstore ? { response_code: response.to_s } : response
361
570
  Response.new(
362
571
  succeeded,
363
- message_from(succeeded, response),
572
+ message_from(succeeded, response, options),
364
573
  body,
365
574
  authorization: authorization,
366
- error_code: error_code_from(succeeded, body),
575
+ error_code: error_code_from(succeeded, body, options),
367
576
  test: test?,
368
- avs_result: avs_result,
369
- cvv_result: cvv_result
577
+ avs_result: avs_result(response),
578
+ cvv_result: cvv_result(response)
370
579
  )
371
580
  end
372
581
 
373
582
  def headers(action, options)
374
- auth_token = @access_token ? "Bearer #{@access_token}" : @options[:secret_key]
583
+ auth_token = @options[:access_token] ? "Bearer #{@options[:access_token]}" : @options[:secret_key]
375
584
  auth_token = @options[:public_key] if action == :tokens
376
585
  headers = {
377
586
  'Authorization' => auth_token,
@@ -417,11 +626,11 @@ module ActiveMerchant #:nodoc:
417
626
  end
418
627
 
419
628
  def avs_result(response)
420
- response['source'] && response['source']['avs_check'] ? AVSResult.new(code: response['source']['avs_check']) : nil
629
+ response.respond_to?(:dig) && response.dig('source', 'avs_check') ? AVSResult.new(code: response['source']['avs_check']) : nil
421
630
  end
422
631
 
423
632
  def cvv_result(response)
424
- response['source'] && response['source']['cvv_check'] ? CVVResult.new(response['source']['cvv_check']) : nil
633
+ response.respond_to?(:dig) && response.dig('source', 'cvv_check') ? CVVResult.new(response['source']['cvv_check']) : nil
425
634
  end
426
635
 
427
636
  def parse(body, error: nil)
@@ -441,19 +650,19 @@ module ActiveMerchant #:nodoc:
441
650
  return true if action == :unstore && response == 204
442
651
 
443
652
  store_response = response['token'] || response['id']
444
- if store_response
445
- return true if (action == :tokens && store_response.match(/tok/)) || (action == :store && store_response.match(/src_/))
446
- end
653
+ return true if store_response && ((action == :tokens && store_response.match(/tok/)) || (action == :store && store_response.match(/src_/)))
654
+
447
655
  response['response_summary'] == 'Approved' || response['approved'] == true || !response.key?('response_summary') && response.key?('action_id')
448
656
  end
449
657
 
450
- def message_from(succeeded, response)
658
+ def message_from(succeeded, response, options)
451
659
  if succeeded
452
660
  'Succeeded'
453
661
  elsif response['error_type']
454
662
  response['error_type'] + ': ' + response['error_codes'].first
455
663
  else
456
- response['response_summary'] || response['response_code'] || response['status'] || response['message'] || 'Unable to read error message'
664
+ response_summary = response['response_summary'] || response.dig('actions', 0, 'response_summary')
665
+ response_summary || response['response_code'] || response['status'] || response['message'] || 'Unable to read error message'
457
666
  end
458
667
  end
459
668
 
@@ -474,7 +683,7 @@ module ActiveMerchant #:nodoc:
474
683
  raw['id']
475
684
  end
476
685
 
477
- def error_code_from(succeeded, response)
686
+ def error_code_from(succeeded, response, options)
478
687
  return if succeeded
479
688
 
480
689
  if response['error_type'] && response['error_codes']
@@ -482,7 +691,9 @@ module ActiveMerchant #:nodoc:
482
691
  elsif response['error_type']
483
692
  response['error_type']
484
693
  else
485
- STANDARD_ERROR_CODE_MAPPING[response['response_code']]
694
+ response_code = response['response_code'] || response.dig('actions', 0, 'response_code')
695
+
696
+ STANDARD_ERROR_CODE_MAPPING[response_code]
486
697
  end
487
698
  end
488
699
 
@@ -55,6 +55,7 @@ module ActiveMerchant #:nodoc:
55
55
  add_invoice(post, money, options)
56
56
  add_transaction_details(post, options, 'capture')
57
57
  add_reference_transaction_details(post, authorization, options, :capture)
58
+ add_dynamic_descriptors(post, options)
58
59
 
59
60
  commit('sale', post, options)
60
61
  end
@@ -68,6 +69,15 @@ module ActiveMerchant #:nodoc:
68
69
  commit('refund', post, options)
69
70
  end
70
71
 
72
+ def credit(money, payment_method, options = {})
73
+ post = {}
74
+ add_invoice(post, money, options)
75
+ add_transaction_interaction(post, options)
76
+ add_payment(post, payment_method, options)
77
+
78
+ commit('refund', post, options)
79
+ end
80
+
71
81
  def void(authorization, options = {})
72
82
  post = {}
73
83
  add_transaction_details(post, options)
@@ -102,6 +112,7 @@ module ActiveMerchant #:nodoc:
102
112
  transcript.
103
113
  gsub(%r((Authorization: )[a-zA-Z0-9+./=]+), '\1[FILTERED]').
104
114
  gsub(%r((Api-Key: )\w+), '\1[FILTERED]').
115
+ gsub(%r(("apiKey\\?":\\?")\w+), '\1[FILTERED]').
105
116
  gsub(%r(("cardData\\?":\\?")\d+), '\1[FILTERED]').
106
117
  gsub(%r(("securityCode\\?":\\?")\d+), '\1[FILTERED]').
107
118
  gsub(%r(("cavv\\?":\\?")\w+), '\1[FILTERED]')
@@ -109,6 +120,23 @@ module ActiveMerchant #:nodoc:
109
120
 
110
121
  private
111
122
 
123
+ def add_three_d_secure(post, payment, options)
124
+ return unless three_d_secure = options[:three_d_secure]
125
+
126
+ post[:additionalData3DS] = {
127
+ dsTransactionId: three_d_secure[:ds_transaction_id],
128
+ authenticationStatus: three_d_secure[:authentication_response_status],
129
+ serviceProviderTransactionId: three_d_secure[:three_ds_server_trans_id],
130
+ acsTransactionId: three_d_secure[:acs_transaction_id],
131
+ mpiData: {
132
+ cavv: three_d_secure[:cavv],
133
+ eci: three_d_secure[:eci],
134
+ xid: three_d_secure[:xid]
135
+ }.compact,
136
+ versionData: { recommendedVersion: three_d_secure[:version] }
137
+ }.compact
138
+ end
139
+
112
140
  def add_transaction_interaction(post, options)
113
141
  post[:transactionInteraction] = {}
114
142
  post[:transactionInteraction][:origin] = options[:origin] || 'ECOM'
@@ -120,7 +148,11 @@ module ActiveMerchant #:nodoc:
120
148
  end
121
149
 
122
150
  def add_transaction_details(post, options, action = nil)
123
- details = { captureFlag: options[:capture_flag], createToken: options[:create_token] }
151
+ details = {
152
+ captureFlag: options[:capture_flag],
153
+ createToken: options[:create_token],
154
+ physicalGoodsIndicator: [true, 'true'].include?(options[:physical_goods_indicator])
155
+ }
124
156
 
125
157
  if options[:order_id].present? && action == 'sale'
126
158
  details[:merchantOrderId] = options[:order_id]
@@ -140,10 +172,7 @@ module ActiveMerchant #:nodoc:
140
172
  return unless billing = options[:billing_address]
141
173
 
142
174
  billing_address = {}
143
- if payment.is_a?(CreditCard)
144
- billing_address[:firstName] = payment.first_name if payment.first_name
145
- billing_address[:lastName] = payment.last_name if payment.last_name
146
- end
175
+ name_from_address(billing_address, billing) || name_from_payment(billing_address, payment)
147
176
  address = {}
148
177
  address[:street] = billing[:address1] if billing[:address1]
149
178
  address[:houseNumberOrName] = billing[:address2] if billing[:address2]
@@ -161,6 +190,22 @@ module ActiveMerchant #:nodoc:
161
190
  post[:billingAddress] = billing_address
162
191
  end
163
192
 
193
+ def name_from_payment(billing_address, payment)
194
+ return unless payment.respond_to?(:first_name) && payment.respond_to?(:last_name)
195
+
196
+ billing_address[:firstName] = payment.first_name if payment.first_name
197
+ billing_address[:lastName] = payment.last_name if payment.last_name
198
+ end
199
+
200
+ def name_from_address(billing_address, billing)
201
+ return unless address = billing
202
+
203
+ first_name, last_name = split_names(address[:name]) if address[:name]
204
+
205
+ billing_address[:firstName] = first_name if first_name
206
+ billing_address[:lastName] = last_name if last_name
207
+ end
208
+
164
209
  def add_shipping_address(post, options)
165
210
  return unless shipping = options[:shipping_address]
166
211
 
@@ -183,12 +228,28 @@ module ActiveMerchant #:nodoc:
183
228
  end
184
229
 
185
230
  def build_purchase_and_auth_request(post, money, payment, options)
231
+ add_three_d_secure(post, payment, options)
186
232
  add_invoice(post, money, options)
187
233
  add_payment(post, payment, options)
188
234
  add_stored_credentials(post, options)
189
235
  add_transaction_interaction(post, options)
190
236
  add_billing_address(post, payment, options)
191
237
  add_shipping_address(post, options)
238
+ add_dynamic_descriptors(post, options)
239
+ end
240
+
241
+ def add_dynamic_descriptors(post, options)
242
+ dynamic_descriptors_fields = %i[mcc merchant_name customer_service_number service_entitlement dynamic_descriptors_address]
243
+ return unless dynamic_descriptors_fields.any? { |key| options.include?(key) }
244
+
245
+ dynamic_descriptors = {}
246
+ dynamic_descriptors[:mcc] = options[:mcc] if options[:mcc]
247
+ dynamic_descriptors[:merchantName] = options[:merchant_name] if options[:merchant_name]
248
+ dynamic_descriptors[:customerServiceNumber] = options[:customer_service_number] if options[:customer_service_number]
249
+ dynamic_descriptors[:serviceEntitlement] = options[:service_entitlement] if options[:service_entitlement]
250
+ dynamic_descriptors[:address] = options[:dynamic_descriptors_address] if options[:dynamic_descriptors_address]
251
+
252
+ post[:dynamicDescriptors] = dynamic_descriptors
192
253
  end
193
254
 
194
255
  def add_reference_transaction_details(post, authorization, options, action = nil)
@@ -214,7 +275,7 @@ module ActiveMerchant #:nodoc:
214
275
  post[:storedCredentials][:sequence] = stored_credential[:initial_transaction] ? 'FIRST' : 'SUBSEQUENT'
215
276
  post[:storedCredentials][:initiator] = stored_credential[:initiator] == 'merchant' ? 'MERCHANT' : 'CARD_HOLDER'
216
277
  post[:storedCredentials][:scheduled] = SCHEDULED_REASON_TYPES.include?(stored_credential[:reason_type])
217
- post[:storedCredentials][:schemeReferenceTransactionId] = stored_credential[:network_transaction_id] if stored_credential[:network_transaction_id]
278
+ post[:storedCredentials][:schemeReferenceTransactionId] = options[:scheme_reference_transaction_id] || stored_credential[:network_transaction_id]
218
279
  end
219
280
 
220
281
  def add_credit_card(source, payment, options)
@@ -278,7 +339,7 @@ module ActiveMerchant #:nodoc:
278
339
  raw_signature = @options[:api_key] + client_request_id.to_s + time + request
279
340
  hmac = OpenSSL::HMAC.digest('sha256', @options[:api_secret], raw_signature)
280
341
  signature = Base64.strict_encode64(hmac.to_s).to_s
281
-
342
+ custom_headers = options.fetch(:headers_identifiers, {})
282
343
  {
283
344
  'Client-Request-Id' => client_request_id,
284
345
  'Api-Key' => @options[:api_key],
@@ -288,7 +349,7 @@ module ActiveMerchant #:nodoc:
288
349
  'Content-Type' => 'application/json',
289
350
  'Accept' => 'application/json',
290
351
  'Authorization' => signature
291
- }
352
+ }.merge!(custom_headers)
292
353
  end
293
354
 
294
355
  def add_merchant_details(post)
@@ -254,9 +254,7 @@ module ActiveMerchant #:nodoc:
254
254
  normalized_value = normalize(value)
255
255
  next if normalized_value.nil?
256
256
 
257
- if key == :'3ds_homephonecountry'
258
- next unless options[:billing_address] && options[:billing_address][:phone]
259
- end
257
+ next if key == :'3ds_homephonecountry' && !(options[:billing_address] && options[:billing_address][:phone])
260
258
 
261
259
  post[key] = normalized_value unless post[key]
262
260
  end
@@ -417,7 +415,7 @@ module ActiveMerchant #:nodoc:
417
415
  three_d_secure_options[:eci],
418
416
  three_d_secure_options[:cavv]
419
417
  )
420
- post[:'3ds_version'] = three_d_secure_options[:version]&.start_with?('2') ? '2.0' : three_d_secure_options[:version]
418
+ post[:'3ds_version'] = three_d_secure_options[:version] == '2' ? '2.0' : three_d_secure_options[:version]
421
419
  post[:'3ds_dstrxid'] = three_d_secure_options[:ds_transaction_id]
422
420
  end
423
421
 
@@ -507,7 +505,7 @@ module ActiveMerchant #:nodoc:
507
505
  end
508
506
 
509
507
  def parse(body)
510
- Hash[CGI::parse(body).map { |k, v| [k.upcase, v.first] }]
508
+ CGI::parse(body).map { |k, v| [k.upcase, v.first] }.to_h
511
509
  end
512
510
 
513
511
  def success_from(response)