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,368 @@
1
+ module ActiveMerchant #:nodoc:
2
+ module Billing #:nodoc:
3
+ class SimetrikGateway < Gateway
4
+ self.test_url = 'https://payments.sta.simetrik.com/v1'
5
+ self.live_url = 'https://payments.simetrik.com/v1'
6
+
7
+ class_attribute :test_auth_url, :live_auth_url, :test_audience, :live_audience
8
+ self.test_auth_url = 'https://tenant-payments-dev.us.auth0.com/oauth/token'
9
+ self.live_auth_url = 'https://tenant-payments-prod.us.auth0.com/oauth/token'
10
+
11
+ self.test_audience = 'https://tenant-payments-dev.us.auth0.com/api/v2/'
12
+ self.live_audience = 'https://tenant-payments-prod.us.auth0.com/api/v2/'
13
+
14
+ self.supported_countries = %w(PE AR)
15
+ self.default_currency = 'USD'
16
+ self.supported_cardtypes = %i[visa master american_express discover]
17
+
18
+ self.homepage_url = 'https://www.simetrik.com'
19
+ self.display_name = 'Simetrik'
20
+
21
+ STANDARD_ERROR_CODE_MAPPING = {
22
+ 'R101' => STANDARD_ERROR_CODE[:incorrect_number],
23
+ 'R102' => STANDARD_ERROR_CODE[:invalid_number],
24
+ 'R103' => STANDARD_ERROR_CODE[:invalid_expiry_date],
25
+ 'R104' => STANDARD_ERROR_CODE[:invalid_cvc],
26
+ 'R105' => STANDARD_ERROR_CODE[:expired_card],
27
+ 'R106' => STANDARD_ERROR_CODE[:incorrect_cvc],
28
+ 'R107' => STANDARD_ERROR_CODE[:incorrect_pin],
29
+ 'R201' => STANDARD_ERROR_CODE[:incorrect_zip],
30
+ 'R202' => STANDARD_ERROR_CODE[:incorrect_address],
31
+ 'R301' => STANDARD_ERROR_CODE[:card_declined],
32
+ 'R302' => STANDARD_ERROR_CODE[:processing_error],
33
+ 'R303' => STANDARD_ERROR_CODE[:call_issuer],
34
+ 'R304' => STANDARD_ERROR_CODE[:pick_up_card],
35
+ 'R305' => STANDARD_ERROR_CODE[:processing_error],
36
+ 'R306' => STANDARD_ERROR_CODE[:processing_error],
37
+ 'R307' => STANDARD_ERROR_CODE[:processing_error],
38
+ 'R401' => STANDARD_ERROR_CODE[:config_error],
39
+ 'R402' => STANDARD_ERROR_CODE[:test_mode_live_card],
40
+ 'R403' => STANDARD_ERROR_CODE[:unsupported_feature]
41
+
42
+ }
43
+
44
+ def initialize(options = {})
45
+ requires!(options, :client_id, :client_secret)
46
+ super
47
+ @access_token = {}
48
+ sign_access_token()
49
+ end
50
+
51
+ def authorize(money, payment, options = {})
52
+ requires!(options, :token_acquirer)
53
+
54
+ post = {}
55
+ add_forward_route(post, options)
56
+ add_forward_payload(post, money, payment, options)
57
+ add_stored_credential(post, options)
58
+ commit('authorize', post, { token_acquirer: options[:token_acquirer] })
59
+ end
60
+
61
+ def capture(money, authorization, options = {})
62
+ requires!(options, :token_acquirer)
63
+ post = {
64
+ forward_payload: {
65
+ amount: {
66
+ total_amount: amount(money).to_f,
67
+ currency: (options[:currency] || currency(money))
68
+ },
69
+ transaction: {
70
+ id: authorization
71
+ },
72
+ acquire_extra_options: options[:acquire_extra_options] || {}
73
+ }
74
+ }
75
+ post[:forward_payload][:amount][:vat] = options[:vat].to_f / 100 if options[:vat]
76
+
77
+ add_forward_route(post, options)
78
+ commit('capture', post, { token_acquirer: options[:token_acquirer] })
79
+ end
80
+
81
+ def refund(money, authorization, options = {})
82
+ requires!(options, :token_acquirer)
83
+ post = {
84
+ forward_payload: {
85
+ amount: {
86
+ total_amount: amount(money).to_f,
87
+ currency: (options[:currency] || currency(money))
88
+ },
89
+ transaction: {
90
+ id: authorization
91
+ },
92
+ acquire_extra_options: options[:acquire_extra_options] || {}
93
+ }
94
+ }
95
+ post[:forward_payload][:transaction][:comment] = options[:comment] if options[:comment]
96
+
97
+ add_forward_route(post, options)
98
+ commit('refund', post, { token_acquirer: options[:token_acquirer] })
99
+ end
100
+
101
+ def void(authorization, options = {})
102
+ requires!(options, :token_acquirer)
103
+ post = {
104
+ forward_payload: {
105
+ transaction: {
106
+ id: authorization
107
+ },
108
+ acquire_extra_options: options[:acquire_extra_options] || {}
109
+ }
110
+ }
111
+ add_forward_route(post, options)
112
+ commit('void', post, { token_acquirer: options[:token_acquirer] })
113
+ end
114
+
115
+ def purchase(money, payment, options = {})
116
+ requires!(options, :token_acquirer)
117
+
118
+ post = {}
119
+ add_forward_route(post, options)
120
+ add_forward_payload(post, money, payment, options)
121
+
122
+ add_stored_credential(post, options)
123
+ commit('charge', post, { token_acquirer: options[:token_acquirer] })
124
+ end
125
+
126
+ def supports_scrubbing?
127
+ true
128
+ end
129
+
130
+ def scrub(transcript)
131
+ transcript.
132
+ gsub(%r((Authorization: Bearer ).+), '\1[FILTERED]').
133
+ gsub(%r(("client_secret\\?":\\?")\w+), '\1[FILTERED]').
134
+ gsub(%r(("number\\?":\\?")\d+), '\1[FILTERED]').
135
+ gsub(%r(("security_code\\?":\\?")\d+), '\1[FILTERED]')
136
+ end
137
+
138
+ private
139
+
140
+ def add_forward_route(post, options)
141
+ forward_route = {}
142
+ forward_route[:trace_id] = options[:trace_id] if options[:trace_id]
143
+
144
+ forward_route[:psp_extra_fields] = options[:psp_extra_fields] || {}
145
+ post[:forward_route] = forward_route
146
+ end
147
+
148
+ def add_forward_payload(post, money, payment, options)
149
+ forward_payload = {}
150
+ add_user(forward_payload, options[:user]) if options[:user]
151
+ add_order(forward_payload, money, options)
152
+ add_payment_method(forward_payload, payment, options[:payment_method]) if options[:payment_method] || payment
153
+
154
+ forward_payload[:payment_method] = {} unless forward_payload[:payment_method]
155
+ forward_payload[:payment_method][:card] = {} unless forward_payload[:payment_method][:card]
156
+ add_address('billing_address', forward_payload[:payment_method][:card], options[:billing_address]) if options[:billing_address]
157
+
158
+ add_three_ds_fields(forward_payload[:authentication] = {}, options[:three_ds_fields]) if options[:three_ds_fields]
159
+ add_sub_merchant(forward_payload, options[:sub_merchant]) if options[:sub_merchant]
160
+ forward_payload[:acquire_extra_options] = options[:acquire_extra_options] || {}
161
+ post[:forward_payload] = forward_payload
162
+ end
163
+
164
+ def add_sub_merchant(post, sub_merchant_options)
165
+ sub_merchant = {}
166
+ sub_merchant[:merchant_id] = sub_merchant_options[:merchant_id] if sub_merchant_options[:merchant_id]
167
+ sub_merchant[:extra_params] = sub_merchant_options[:extra_params] if sub_merchant_options[:extra_params]
168
+ sub_merchant[:mcc] = sub_merchant_options[:mcc] if sub_merchant_options[:mcc]
169
+ sub_merchant[:name] = sub_merchant_options[:name] if sub_merchant_options[:name]
170
+ sub_merchant[:address] = sub_merchant_options[:address] if sub_merchant_options[:address]
171
+ sub_merchant[:postal_code] = sub_merchant_options[:postal_code] if sub_merchant_options[:postal_code]
172
+ sub_merchant[:url] = sub_merchant_options[:url] if sub_merchant_options[:url]
173
+ sub_merchant[:phone_number] = sub_merchant_options[:phone_number] if sub_merchant_options[:phone_number]
174
+
175
+ post[:sub_merchant] = sub_merchant
176
+ end
177
+
178
+ def add_payment_method(post, payment, payment_method_options)
179
+ payment_method = {}
180
+ opts = nil
181
+ opts = payment_method_options[:card] if payment_method_options
182
+ add_card(payment_method, payment, opts) if opts || payment
183
+
184
+ post[:payment_method] = payment_method
185
+ end
186
+
187
+ def add_three_ds_fields(post, three_ds_options)
188
+ three_ds = {}
189
+ three_ds[:version] = three_ds_options[:version] if three_ds_options[:version]
190
+ three_ds[:eci] = three_ds_options[:eci] if three_ds_options[:eci]
191
+ three_ds[:cavv] = three_ds_options[:cavv] if three_ds_options[:cavv]
192
+ three_ds[:ds_transaction_id] = three_ds_options[:ds_transaction_id] if three_ds_options[:ds_transaction_id]
193
+ three_ds[:acs_transaction_id] = three_ds_options[:acs_transaction_id] if three_ds_options[:acs_transaction_id]
194
+ three_ds[:xid] = three_ds_options[:xid] if three_ds_options[:xid]
195
+ three_ds[:enrolled] = three_ds_options[:enrolled] if three_ds_options[:enrolled]
196
+ three_ds[:cavv_algorithm] = three_ds_options[:cavv_algorithm] if three_ds_options[:cavv_algorithm]
197
+ three_ds[:directory_response_status] = three_ds_options[:directory_response_status] if three_ds_options[:directory_response_status]
198
+ three_ds[:authentication_response_status] = three_ds_options[:authentication_response_status] if three_ds_options[:authentication_response_status]
199
+ three_ds[:three_ds_server_trans_id] = three_ds_options[:three_ds_server_trans_id] if three_ds_options[:three_ds_server_trans_id]
200
+
201
+ post[:three_ds_fields] = three_ds
202
+ end
203
+
204
+ def add_card(post, card, card_options = {})
205
+ card_hash = {}
206
+ card_hash[:number] = card.number
207
+ card_hash[:exp_month] = card.month
208
+ card_hash[:exp_year] = card.year
209
+ card_hash[:security_code] = card.verification_value
210
+ card_hash[:type] = card.brand
211
+ card_hash[:holder_first_name] = card.first_name
212
+ card_hash[:holder_last_name] = card.last_name
213
+ post[:card] = card_hash
214
+ end
215
+
216
+ def add_user(post, user_options)
217
+ user = {}
218
+ user[:id] = user_options[:id] if user_options[:id]
219
+ user[:email] = user_options[:email] if user_options[:email]
220
+
221
+ post[:user] = user
222
+ end
223
+
224
+ def add_stored_credential(post, options)
225
+ return unless options[:stored_credential]
226
+
227
+ check_initiator = %w[merchant cardholder].any? { |item| item == options[:stored_credential][:initiator] }
228
+ check_reason_type = %w[recurring installment unscheduled].any? { |item| item == options[:stored_credential][:reason_type] }
229
+ post[:forward_payload][:authentication] = {} unless post[:forward_payload].key?(:authentication)
230
+ post[:forward_payload][:authentication][:stored_credential] = options[:stored_credential] if check_initiator && check_reason_type
231
+ end
232
+
233
+ def add_order(post, money, options)
234
+ return unless options[:order] || money
235
+
236
+ order = {}
237
+ order_options = options[:order] || {}
238
+ order[:id] = options[:order_id] if options[:order_id]
239
+ order[:description] = options[:description] if options[:description]
240
+ order[:installments] = order_options[:installments].to_i if order_options[:installments]
241
+ order[:datetime_local_transaction] = order_options[:datetime_local_transaction] if order_options[:datetime_local_transaction]
242
+
243
+ add_amount(order, money, options)
244
+ add_address('shipping_address', order, options)
245
+
246
+ post[:order] = order
247
+ end
248
+
249
+ def add_amount(post, money, options)
250
+ amount_obj = {}
251
+ amount_obj[:total_amount] = amount(money).to_f
252
+ amount_obj[:currency] = (options[:currency] || currency(money))
253
+ amount_obj[:vat] = options[:vat].to_f / 100 if options[:vat]
254
+
255
+ post[:amount] = amount_obj
256
+ end
257
+
258
+ def add_address(tag, post, options)
259
+ return unless address_options = options[:shipping_address]
260
+
261
+ address = {}
262
+ address[:name] = address_options[:name] if address_options[:name]
263
+ address[:address1] = address_options[:address1] if address_options[:address1]
264
+ address[:address2] = address_options[:address2] if address_options[:address2]
265
+ address[:company] = address_options[:company] if address_options[:company]
266
+ address[:city] = address_options[:city] if address_options[:city]
267
+ address[:state] = address_options[:state] if address_options[:state]
268
+ address[:zip] = address_options[:zip] if address_options[:zip]
269
+ address[:country] = address_options[:country] if address_options[:country]
270
+ address[:phone] = address_options[:phone] if address_options[:phone]
271
+ address[:fax] = address_options[:fax] if address_options[:fax]
272
+
273
+ post[tag] = address
274
+ end
275
+
276
+ def parse(body)
277
+ JSON.parse(body)
278
+ end
279
+
280
+ def commit(action, parameters, url_params = {})
281
+ begin
282
+ response = JSON.parse ssl_post(url(action, url_params), post_data(parameters), authorized_headers())
283
+ rescue ResponseError => exception
284
+ case exception.response.code.to_i
285
+ when 400...499
286
+ response = JSON.parse exception.response.body
287
+ else
288
+ raise exception
289
+ end
290
+ end
291
+
292
+ Response.new(
293
+ success_from(response['code']),
294
+ message_from(response),
295
+ response,
296
+ authorization: authorization_from(response),
297
+ avs_result: AVSResult.new(code: avs_code_from(response)),
298
+ cvv_result: CVVResult.new(cvv_code_from(response)),
299
+ test: test?,
300
+ error_code: error_code_from(response)
301
+ )
302
+ end
303
+
304
+ def avs_code_from(response)
305
+ response['avs_result']
306
+ end
307
+
308
+ def cvv_code_from(response)
309
+ response['cvv_result']
310
+ end
311
+
312
+ def success_from(code)
313
+ code == 'S001'
314
+ end
315
+
316
+ def message_from(response)
317
+ response['message']
318
+ end
319
+
320
+ def url(action, url_params)
321
+ "#{(test? ? test_url : live_url)}/#{url_params[:token_acquirer]}/#{action}"
322
+ end
323
+
324
+ def post_data(data = {})
325
+ data.to_json
326
+ end
327
+
328
+ def authorization_from(response)
329
+ response['simetrik_authorization_id']
330
+ end
331
+
332
+ def error_code_from(response)
333
+ STANDARD_ERROR_CODE_MAPPING[response['code']] unless success_from(response['code'])
334
+ end
335
+
336
+ def authorized_headers
337
+ {
338
+ 'content-Type' => 'application/json',
339
+ 'Authorization' => "Bearer #{sign_access_token()}"
340
+ }
341
+ end
342
+
343
+ # if this method is refactored, ensure that the client_secret is properly scrubbed
344
+ def sign_access_token
345
+ fetch_access_token() if Time.new.to_i > (@access_token[:expires_at] || 0) + 10
346
+ @access_token[:access_token]
347
+ end
348
+
349
+ def auth_url
350
+ (test? ? test_auth_url : live_auth_url)
351
+ end
352
+
353
+ def fetch_access_token
354
+ login_info = {}
355
+ login_info[:client_id] = @options[:client_id]
356
+ login_info[:client_secret] = @options[:client_secret]
357
+ login_info[:audience] = test? ? test_audience : live_audience
358
+ login_info[:grant_type] = 'client_credentials'
359
+ response = parse(ssl_post(auth_url(), login_info.to_json, {
360
+ 'content-Type' => 'application/json'
361
+ }))
362
+
363
+ @access_token[:access_token] = response['access_token']
364
+ @access_token[:expires_at] = Time.new.to_i + response['expires_in']
365
+ end
366
+ end
367
+ end
368
+ end
@@ -48,7 +48,8 @@ module ActiveMerchant #:nodoc:
48
48
  'processing_error' => STANDARD_ERROR_CODE[:processing_error],
49
49
  'incorrect_pin' => STANDARD_ERROR_CODE[:incorrect_pin],
50
50
  'test_mode_live_card' => STANDARD_ERROR_CODE[:test_mode_live_card],
51
- 'pickup_card' => STANDARD_ERROR_CODE[:pickup_card]
51
+ 'pickup_card' => STANDARD_ERROR_CODE[:pickup_card],
52
+ 'amount_too_small' => STANDARD_ERROR_CODE[:invalid_amount]
52
53
  }
53
54
 
54
55
  BANK_ACCOUNT_HOLDER_TYPE_MAPPING = {
@@ -144,6 +145,7 @@ module ActiveMerchant #:nodoc:
144
145
 
145
146
  def void(identification, options = {})
146
147
  post = {}
148
+ post[:reverse_transfer] = options[:reverse_transfer] if options[:reverse_transfer]
147
149
  post[:metadata] = options[:metadata] if options[:metadata]
148
150
  post[:reason] = options[:reason] if options[:reason]
149
151
  post[:expand] = [:charge]
@@ -279,6 +281,7 @@ module ActiveMerchant #:nodoc:
279
281
  def scrub(transcript)
280
282
  transcript.
281
283
  gsub(%r((Authorization: Basic )\w+), '\1[FILTERED]').
284
+ gsub(%r((Authorization: Bearer )\w+), '\1[FILTERED]').
282
285
  gsub(%r((&?three_d_secure\[cryptogram\]=)[\w=]*(&?)), '\1[FILTERED]\2').
283
286
  gsub(%r(((\[card\]|card)\[cryptogram\]=)[^&]+(&?)), '\1[FILTERED]\3').
284
287
  gsub(%r(((\[card\]|card)\[cvc\]=)\d+), '\1[FILTERED]').
@@ -288,7 +291,8 @@ module ActiveMerchant #:nodoc:
288
291
  gsub(%r(((\[card\]|card)\[encrypted_pin_key_id\]=)[\w=]+(&?)), '\1[FILTERED]\3').
289
292
  gsub(%r(((\[card\]|card)\[number\]=)\d+), '\1[FILTERED]').
290
293
  gsub(%r(((\[card\]|card)\[swipe_data\]=)[^&]+(&?)), '\1[FILTERED]\3').
291
- gsub(%r(((\[bank_account\]|bank_account)\[account_number\]=)\d+), '\1[FILTERED]')
294
+ gsub(%r(((\[bank_account\]|bank_account)\[account_number\]=)\d+), '\1[FILTERED]').
295
+ gsub(%r(((\[payment_method_data\]|payment_method_data)\[card\]\[token\]=)[^&]+(&?)), '\1[FILTERED]\3')
292
296
  end
293
297
 
294
298
  def supports_network_tokenization?
@@ -299,7 +303,7 @@ module ActiveMerchant #:nodoc:
299
303
  def delete_latest_test_external_account(account)
300
304
  return unless test?
301
305
 
302
- auth_header = { 'Authorization': "Bearer #{options[:login]}" }
306
+ auth_header = { 'Authorization' => 'Basic ' + Base64.strict_encode64(options[:login].to_s + ':').strip }
303
307
  url = "#{live_url}accounts/#{CGI.escape(account)}/external_accounts"
304
308
  accounts_response = JSON.parse(ssl_get("#{url}?limit=100", auth_header))
305
309
  to_delete = accounts_response['data'].reject { |ac| ac['default_for_currency'] }
@@ -387,6 +391,7 @@ module ActiveMerchant #:nodoc:
387
391
  end
388
392
 
389
393
  add_metadata(post, options)
394
+ add_shipping_address(post, payment, options)
390
395
  add_application_fee(post, options)
391
396
  add_exchange_rate(post, options)
392
397
  add_destination(post, options)
@@ -553,6 +558,23 @@ module ActiveMerchant #:nodoc:
553
558
  post[:metadata][:card_read_method] = creditcard.read_method if creditcard.respond_to?(:read_method)
554
559
  end
555
560
 
561
+ def add_shipping_address(post, payment, options = {})
562
+ return unless shipping = options[:shipping_address]
563
+ return unless shipping_name = shipping[:name]
564
+
565
+ post[:shipping] = {}
566
+
567
+ post[:shipping][:name] = shipping_name
568
+ post[:shipping][:address] = {}
569
+ post[:shipping][:address][:line1] = shipping[:address1]
570
+ post[:shipping][:address][:line2] = shipping[:address2] if shipping[:address2]
571
+ post[:shipping][:address][:city] = shipping[:city] if shipping[:city]
572
+ post[:shipping][:address][:country] = shipping[:country] if shipping[:country]
573
+ post[:shipping][:address][:state] = shipping[:state] if shipping[:state]
574
+ post[:shipping][:address][:postal_code] = shipping[:zip] if shipping[:zip]
575
+ post[:shipping][:phone] = shipping[:phone_number] if shipping[:phone_number]
576
+ end
577
+
556
578
  def add_source_owner(post, creditcard, options)
557
579
  post[:owner] = {}
558
580
  post[:owner][:name] = creditcard.name if creditcard.name