activemerchant 1.126.0 → 1.131.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +269 -0
- data/lib/active_merchant/billing/check.rb +40 -8
- data/lib/active_merchant/billing/credit_card.rb +28 -1
- data/lib/active_merchant/billing/credit_card_methods.rb +80 -24
- data/lib/active_merchant/billing/gateways/adyen.rb +69 -10
- data/lib/active_merchant/billing/gateways/airwallex.rb +40 -11
- data/lib/active_merchant/billing/gateways/alelo.rb +256 -0
- data/lib/active_merchant/billing/gateways/authorize_net.rb +24 -6
- data/lib/active_merchant/billing/gateways/beanstream.rb +18 -0
- data/lib/active_merchant/billing/gateways/blue_snap.rb +22 -1
- data/lib/active_merchant/billing/gateways/bogus.rb +4 -0
- data/lib/active_merchant/billing/gateways/borgun.rb +57 -16
- data/lib/active_merchant/billing/gateways/braintree_blue.rb +72 -24
- data/lib/active_merchant/billing/gateways/card_connect.rb +27 -9
- data/lib/active_merchant/billing/gateways/card_stream.rb +23 -0
- data/lib/active_merchant/billing/gateways/checkout_v2.rb +238 -57
- data/lib/active_merchant/billing/gateways/commerce_hub.rb +366 -0
- data/lib/active_merchant/billing/gateways/credorax.rb +47 -27
- data/lib/active_merchant/billing/gateways/cyber_source/cyber_source_common.rb +36 -0
- data/lib/active_merchant/billing/gateways/cyber_source.rb +119 -33
- data/lib/active_merchant/billing/gateways/cyber_source_rest.rb +454 -0
- data/lib/active_merchant/billing/gateways/d_local.rb +45 -5
- data/lib/active_merchant/billing/gateways/decidir.rb +15 -4
- data/lib/active_merchant/billing/gateways/ebanx.rb +36 -24
- data/lib/active_merchant/billing/gateways/element.rb +21 -1
- data/lib/active_merchant/billing/gateways/global_collect.rb +113 -40
- data/lib/active_merchant/billing/gateways/ipg.rb +13 -8
- data/lib/active_merchant/billing/gateways/iveri.rb +39 -3
- data/lib/active_merchant/billing/gateways/kushki.rb +21 -1
- data/lib/active_merchant/billing/gateways/litle.rb +25 -5
- data/lib/active_merchant/billing/gateways/mastercard.rb +1 -8
- data/lib/active_merchant/billing/gateways/mercado_pago.rb +17 -0
- data/lib/active_merchant/billing/gateways/merchant_e_solutions.rb +44 -10
- data/lib/active_merchant/billing/gateways/monei.rb +2 -0
- data/lib/active_merchant/billing/gateways/moneris.rb +20 -5
- data/lib/active_merchant/billing/gateways/mundipagg.rb +3 -0
- data/lib/active_merchant/billing/gateways/ogone.rb +35 -7
- data/lib/active_merchant/billing/gateways/openpay.rb +20 -3
- data/lib/active_merchant/billing/gateways/orbital.rb +43 -22
- data/lib/active_merchant/billing/gateways/pay_trace.rb +64 -18
- data/lib/active_merchant/billing/gateways/payeezy.rb +59 -4
- data/lib/active_merchant/billing/gateways/paymentez.rb +18 -6
- data/lib/active_merchant/billing/gateways/paypal/paypal_express_response.rb +4 -0
- data/lib/active_merchant/billing/gateways/paypal_express.rb +2 -0
- data/lib/active_merchant/billing/gateways/paysafe.rb +22 -14
- data/lib/active_merchant/billing/gateways/payu_latam.rb +4 -1
- data/lib/active_merchant/billing/gateways/plexo.rb +308 -0
- data/lib/active_merchant/billing/gateways/priority.rb +29 -6
- data/lib/active_merchant/billing/gateways/rapyd.rb +110 -49
- data/lib/active_merchant/billing/gateways/reach.rb +277 -0
- data/lib/active_merchant/billing/gateways/redsys.rb +11 -6
- data/lib/active_merchant/billing/gateways/sage_pay.rb +1 -1
- data/lib/active_merchant/billing/gateways/securion_pay.rb +40 -0
- data/lib/active_merchant/billing/gateways/shift4.rb +345 -0
- data/lib/active_merchant/billing/gateways/simetrik.rb +28 -22
- data/lib/active_merchant/billing/gateways/stripe.rb +30 -6
- data/lib/active_merchant/billing/gateways/stripe_payment_intents.rb +62 -22
- data/lib/active_merchant/billing/gateways/tns.rb +2 -5
- data/lib/active_merchant/billing/gateways/trans_first_transaction_express.rb +1 -1
- data/lib/active_merchant/billing/gateways/trust_commerce.rb +14 -3
- data/lib/active_merchant/billing/gateways/vanco.rb +12 -3
- data/lib/active_merchant/billing/gateways/visanet_peru.rb +1 -1
- data/lib/active_merchant/billing/gateways/vpos.rb +7 -4
- data/lib/active_merchant/billing/gateways/wompi.rb +8 -4
- data/lib/active_merchant/billing/gateways/worldpay.rb +128 -13
- data/lib/active_merchant/billing/response.rb +15 -1
- data/lib/active_merchant/connection.rb +0 -2
- data/lib/active_merchant/country.rb +1 -0
- data/lib/active_merchant/errors.rb +4 -1
- data/lib/active_merchant/version.rb +1 -1
- metadata +24 -3
@@ -0,0 +1,345 @@
|
|
1
|
+
module ActiveMerchant #:nodoc:
|
2
|
+
module Billing #:nodoc:
|
3
|
+
class Shift4Gateway < Gateway
|
4
|
+
self.test_url = 'https://utgapi.shift4test.com/api/rest/v1/'
|
5
|
+
self.live_url = 'https://utg.shift4api.net/api/rest/v1/'
|
6
|
+
|
7
|
+
self.supported_countries = %w(US CA CU HT DO PR JM TT GP MQ BS BB LC CW AW VC VI GD AG DM KY KN SX TC MF VG BQ AI BL MS)
|
8
|
+
self.default_currency = 'USD'
|
9
|
+
self.supported_cardtypes = %i[visa master american_express discover]
|
10
|
+
|
11
|
+
self.homepage_url = 'https://shift4.com'
|
12
|
+
self.display_name = 'Shift4'
|
13
|
+
|
14
|
+
RECURRING_TYPE_TRANSACTIONS = %w(recurring installment)
|
15
|
+
TRANSACTIONS_WITHOUT_RESPONSE_CODE = %w(accesstoken add)
|
16
|
+
SUCCESS_TRANSACTION_STATUS = %w(A)
|
17
|
+
DISALLOWED_ENTRY_MODE_ACTIONS = %w(capture refund add verify)
|
18
|
+
URL_POSTFIX_MAPPING = {
|
19
|
+
'accesstoken' => 'credentials',
|
20
|
+
'add' => 'tokens',
|
21
|
+
'verify' => 'cards'
|
22
|
+
}
|
23
|
+
STANDARD_ERROR_CODE_MAPPING = {
|
24
|
+
'incorrect_number' => STANDARD_ERROR_CODE[:incorrect_number],
|
25
|
+
'invalid_number' => STANDARD_ERROR_CODE[:invalid_number],
|
26
|
+
'invalid_expiry_month' => STANDARD_ERROR_CODE[:invalid_expiry_date],
|
27
|
+
'invalid_expiry_year' => STANDARD_ERROR_CODE[:invalid_expiry_date],
|
28
|
+
'invalid_cvc' => STANDARD_ERROR_CODE[:invalid_cvc],
|
29
|
+
'expired_card' => STANDARD_ERROR_CODE[:expired_card],
|
30
|
+
'insufficient_funds' => STANDARD_ERROR_CODE[:card_declined],
|
31
|
+
'incorrect_cvc' => STANDARD_ERROR_CODE[:incorrect_cvc],
|
32
|
+
'incorrect_zip' => STANDARD_ERROR_CODE[:incorrect_zip],
|
33
|
+
'card_declined' => STANDARD_ERROR_CODE[:card_declined],
|
34
|
+
'processing_error' => STANDARD_ERROR_CODE[:processing_error],
|
35
|
+
'lost_or_stolen' => STANDARD_ERROR_CODE[:card_declined],
|
36
|
+
'suspected_fraud' => STANDARD_ERROR_CODE[:card_declined],
|
37
|
+
'expired_token' => STANDARD_ERROR_CODE[:card_declined]
|
38
|
+
}
|
39
|
+
|
40
|
+
def initialize(options = {})
|
41
|
+
requires!(options, :client_guid, :auth_token)
|
42
|
+
@client_guid = options[:client_guid]
|
43
|
+
@auth_token = options[:auth_token]
|
44
|
+
@access_token = options[:access_token]
|
45
|
+
super
|
46
|
+
end
|
47
|
+
|
48
|
+
def purchase(money, payment_method, options = {})
|
49
|
+
post = {}
|
50
|
+
action = 'sale'
|
51
|
+
|
52
|
+
payment_method = get_card_token(payment_method) if payment_method.is_a?(String)
|
53
|
+
add_datetime(post, options)
|
54
|
+
add_invoice(post, money, options)
|
55
|
+
add_clerk(post, options)
|
56
|
+
add_transaction(post, options)
|
57
|
+
add_card(action, post, payment_method, options)
|
58
|
+
add_card_present(post, options)
|
59
|
+
add_customer(post, payment_method, options)
|
60
|
+
|
61
|
+
commit(action, post, options)
|
62
|
+
end
|
63
|
+
|
64
|
+
def authorize(money, payment_method, options = {})
|
65
|
+
post = {}
|
66
|
+
action = 'authorization'
|
67
|
+
|
68
|
+
payment_method = get_card_token(payment_method) if payment_method.is_a?(String)
|
69
|
+
add_datetime(post, options)
|
70
|
+
add_invoice(post, money, options)
|
71
|
+
add_clerk(post, options)
|
72
|
+
add_transaction(post, options)
|
73
|
+
add_card(action, post, payment_method, options)
|
74
|
+
add_card_present(post, options)
|
75
|
+
add_customer(post, payment_method, options)
|
76
|
+
|
77
|
+
commit(action, post, options)
|
78
|
+
end
|
79
|
+
|
80
|
+
def capture(money, authorization, options = {})
|
81
|
+
post = {}
|
82
|
+
action = 'capture'
|
83
|
+
options[:invoice] = get_invoice(authorization)
|
84
|
+
|
85
|
+
add_datetime(post, options)
|
86
|
+
add_invoice(post, money, options)
|
87
|
+
add_clerk(post, options)
|
88
|
+
add_transaction(post, options)
|
89
|
+
add_card(action, post, get_card_token(authorization), options)
|
90
|
+
|
91
|
+
commit(action, post, options)
|
92
|
+
end
|
93
|
+
|
94
|
+
def refund(money, payment_method, options = {})
|
95
|
+
post = {}
|
96
|
+
action = 'refund'
|
97
|
+
|
98
|
+
add_datetime(post, options)
|
99
|
+
add_invoice(post, money, options)
|
100
|
+
add_clerk(post, options)
|
101
|
+
add_transaction(post, options)
|
102
|
+
card_token = payment_method.is_a?(CreditCard) ? get_card_token(payment_method) : payment_method
|
103
|
+
add_card(action, post, card_token, options)
|
104
|
+
add_card_present(post, options)
|
105
|
+
|
106
|
+
commit(action, post, options)
|
107
|
+
end
|
108
|
+
|
109
|
+
alias credit refund
|
110
|
+
|
111
|
+
def void(authorization, options = {})
|
112
|
+
options[:invoice] = get_invoice(authorization)
|
113
|
+
commit('invoice', {}, options)
|
114
|
+
end
|
115
|
+
|
116
|
+
def verify(credit_card, options = {})
|
117
|
+
post = {}
|
118
|
+
action = 'verify'
|
119
|
+
post[:transaction] = {}
|
120
|
+
|
121
|
+
add_datetime(post, options)
|
122
|
+
add_card(action, post, credit_card, options)
|
123
|
+
add_customer(post, credit_card, options)
|
124
|
+
add_card_on_file(post[:transaction], options)
|
125
|
+
|
126
|
+
commit(action, post, options)
|
127
|
+
end
|
128
|
+
|
129
|
+
def store(credit_card, options = {})
|
130
|
+
post = {}
|
131
|
+
action = 'add'
|
132
|
+
|
133
|
+
add_datetime(post, options)
|
134
|
+
add_card(action, post, credit_card, options)
|
135
|
+
add_customer(post, credit_card, options)
|
136
|
+
|
137
|
+
commit(action, post, options)
|
138
|
+
end
|
139
|
+
|
140
|
+
def supports_scrubbing?
|
141
|
+
true
|
142
|
+
end
|
143
|
+
|
144
|
+
def scrub(transcript)
|
145
|
+
transcript.
|
146
|
+
gsub(%r(("Number\\?"\s*:\s*\\?")[^"]*)i, '\1[FILTERED]').
|
147
|
+
gsub(%r(("expirationDate\\?"\s*:\s*\\?")[^"]*)i, '\1[FILTERED]').
|
148
|
+
gsub(%r(("FirstName\\?"\s*:\s*\\?")[^"]*)i, '\1[FILTERED]').
|
149
|
+
gsub(%r(("LastName\\?"\s*:\s*\\?")[^"]*)i, '\1[FILTERED]').
|
150
|
+
gsub(%r(("securityCode\\?":{\\?"[\w]+\\?":[\d]+,\\?"value\\?":\\?")[\d]*)i, '\1[FILTERED]')
|
151
|
+
end
|
152
|
+
|
153
|
+
def setup_access_token
|
154
|
+
post = {}
|
155
|
+
add_credentials(post, options)
|
156
|
+
add_datetime(post, options)
|
157
|
+
|
158
|
+
response = commit('accesstoken', post, request_headers('accesstoken', options))
|
159
|
+
raise OAuthResponseError.new(response, response.params.fetch('result', [{}]).first.dig('error', 'longText')) unless response.success?
|
160
|
+
|
161
|
+
response.params['result'].first['credential']['accessToken']
|
162
|
+
end
|
163
|
+
|
164
|
+
private
|
165
|
+
|
166
|
+
def add_credentials(post, options)
|
167
|
+
post[:credential] = {}
|
168
|
+
post[:credential][:clientGuid] = @client_guid
|
169
|
+
post[:credential][:authToken] = @auth_token
|
170
|
+
end
|
171
|
+
|
172
|
+
def add_clerk(post, options)
|
173
|
+
post[:clerk] = {}
|
174
|
+
post[:clerk][:numericId] = options[:clerk_id] || '1'
|
175
|
+
end
|
176
|
+
|
177
|
+
def add_invoice(post, money, options)
|
178
|
+
post[:amount] = {}
|
179
|
+
post[:amount][:total] = amount(money.to_f)
|
180
|
+
post[:amount][:tax] = options[:tax].to_f || 0.0
|
181
|
+
end
|
182
|
+
|
183
|
+
def add_datetime(post, options)
|
184
|
+
post[:dateTime] = options[:date_time] || current_date_time(options)
|
185
|
+
end
|
186
|
+
|
187
|
+
def add_transaction(post, options)
|
188
|
+
post[:transaction] = {}
|
189
|
+
post[:transaction][:invoice] = options[:invoice] || Time.new.to_i.to_s[1..3] + rand.to_s[2..7]
|
190
|
+
post[:transaction][:notes] = options[:notes] if options[:notes].present?
|
191
|
+
post[:transaction][:vendorReference] = options[:order_id]
|
192
|
+
|
193
|
+
add_purchase_card(post[:transaction], options)
|
194
|
+
add_card_on_file(post[:transaction], options)
|
195
|
+
end
|
196
|
+
|
197
|
+
def add_card(action, post, payment_method, options)
|
198
|
+
post[:card] = {}
|
199
|
+
post[:card][:entryMode] = options[:entry_mode] || 'M' unless DISALLOWED_ENTRY_MODE_ACTIONS.include?(action)
|
200
|
+
if payment_method.is_a?(CreditCard)
|
201
|
+
post[:card][:expirationDate] = "#{format(payment_method.month, :two_digits)}#{format(payment_method.year, :two_digits)}"
|
202
|
+
post[:card][:number] = payment_method.number
|
203
|
+
post[:card][:securityCode] = {}
|
204
|
+
post[:card][:securityCode][:indicator] = 1
|
205
|
+
post[:card][:securityCode][:value] = payment_method.verification_value
|
206
|
+
else
|
207
|
+
post[:card] = {} if post[:card].nil?
|
208
|
+
post[:card][:token] = {}
|
209
|
+
post[:card][:token][:value] = payment_method
|
210
|
+
post[:card][:expirationDate] = options[:expiration_date] if options[:expiration_date]
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
def add_card_present(post, options)
|
215
|
+
post[:card] = {} unless post[:card].present?
|
216
|
+
|
217
|
+
post[:card][:present] = options[:card_present] || 'N'
|
218
|
+
end
|
219
|
+
|
220
|
+
def add_customer(post, card, options)
|
221
|
+
address = options[:billing_address] || {}
|
222
|
+
|
223
|
+
post[:customer] = {}
|
224
|
+
post[:customer][:addressLine1] = address[:address1] if address[:address1]
|
225
|
+
post[:customer][:postalCode] = address[:zip] if address[:zip] && !address[:zip]&.to_s&.empty?
|
226
|
+
post[:customer][:firstName] = card.first_name if card.is_a?(CreditCard) && card.first_name
|
227
|
+
post[:customer][:lastName] = card.last_name if card.is_a?(CreditCard) && card.last_name
|
228
|
+
post[:customer][:emailAddress] = options[:email] if options[:email]
|
229
|
+
post[:customer][:ipAddress] = options[:ip] if options[:ip]
|
230
|
+
end
|
231
|
+
|
232
|
+
def add_purchase_card(post, options)
|
233
|
+
return unless options[:customer_reference] || options[:destination_postal_code] || options[:product_descriptors]
|
234
|
+
|
235
|
+
post[:purchaseCard] = {}
|
236
|
+
post[:purchaseCard][:customerReference] = options[:customer_reference] if options[:customer_reference]
|
237
|
+
post[:purchaseCard][:destinationPostalCode] = options[:destination_postal_code] if options[:destination_postal_code]
|
238
|
+
post[:purchaseCard][:productDescriptors] = options[:product_descriptors] if options[:product_descriptors]
|
239
|
+
end
|
240
|
+
|
241
|
+
def add_card_on_file(post, options)
|
242
|
+
return unless options[:stored_credential] || options[:usage_indicator] || options[:indicator] || options[:scheduled_indicator] || options[:transaction_id]
|
243
|
+
|
244
|
+
stored_credential = options[:stored_credential] || {}
|
245
|
+
post[:cardOnFile] = {}
|
246
|
+
post[:cardOnFile][:usageIndicator] = options[:usage_indicator] || (stored_credential[:initial_transaction] ? '01' : '02')
|
247
|
+
post[:cardOnFile][:indicator] = options[:indicator] || '01'
|
248
|
+
post[:cardOnFile][:scheduledIndicator] = options[:scheduled_indicator] || (RECURRING_TYPE_TRANSACTIONS.include?(stored_credential[:reason_type]) ? '01' : '02')
|
249
|
+
post[:cardOnFile][:transactionId] = options[:transaction_id] || stored_credential[:network_transaction_id] if options[:transaction_id] || stored_credential[:network_transaction_id]
|
250
|
+
end
|
251
|
+
|
252
|
+
def commit(action, parameters, option)
|
253
|
+
url_postfix = URL_POSTFIX_MAPPING[action] || 'transactions'
|
254
|
+
url = (test? ? "#{test_url}#{url_postfix}/#{action}" : "#{live_url}#{url_postfix}/#{action}")
|
255
|
+
if action == 'invoice'
|
256
|
+
response = parse(ssl_request(:delete, url, parameters.to_json, request_headers(action, option)))
|
257
|
+
else
|
258
|
+
response = parse(ssl_post(url, parameters.to_json, request_headers(action, option)))
|
259
|
+
end
|
260
|
+
|
261
|
+
Response.new(
|
262
|
+
success_from(action, response),
|
263
|
+
message_from(action, response),
|
264
|
+
response,
|
265
|
+
authorization: authorization_from(action, response),
|
266
|
+
test: test?,
|
267
|
+
error_code: error_code_from(action, response)
|
268
|
+
)
|
269
|
+
end
|
270
|
+
|
271
|
+
def handle_response(response)
|
272
|
+
case response.code.to_i
|
273
|
+
when 200...300, 400, 401, 500
|
274
|
+
response.body
|
275
|
+
else
|
276
|
+
raise ResponseError.new(response)
|
277
|
+
end
|
278
|
+
end
|
279
|
+
|
280
|
+
def parse(body)
|
281
|
+
return {} if body == ''
|
282
|
+
|
283
|
+
JSON.parse(body)
|
284
|
+
end
|
285
|
+
|
286
|
+
def message_from(action, response)
|
287
|
+
success_from(action, response) ? 'Transaction successful' : (error(response)&.dig('longText') || 'Transaction declined')
|
288
|
+
end
|
289
|
+
|
290
|
+
def error_code_from(action, response)
|
291
|
+
return unless success_from(action, response)
|
292
|
+
|
293
|
+
STANDARD_ERROR_CODE_MAPPING[response['primaryCode']]
|
294
|
+
end
|
295
|
+
|
296
|
+
def authorization_from(action, response)
|
297
|
+
return unless success_from(action, response)
|
298
|
+
|
299
|
+
authorization = response.dig('result', 0, 'card', 'token', 'value').to_s
|
300
|
+
invoice = response.dig('result', 0, 'transaction', 'invoice')
|
301
|
+
authorization += "|#{invoice}" if invoice
|
302
|
+
authorization
|
303
|
+
end
|
304
|
+
|
305
|
+
def get_card_token(authorization)
|
306
|
+
authorization.is_a?(CreditCard) ? authorization : authorization.split('|')[0]
|
307
|
+
end
|
308
|
+
|
309
|
+
def get_invoice(authorization)
|
310
|
+
authorization.is_a?(CreditCard) ? authorization : authorization.split('|')[1]
|
311
|
+
end
|
312
|
+
|
313
|
+
def request_headers(action, options)
|
314
|
+
headers = {
|
315
|
+
'Content-Type' => 'application/json'
|
316
|
+
}
|
317
|
+
headers['AccessToken'] = @access_token
|
318
|
+
headers['Invoice'] = options[:invoice] if action != 'capture' && options[:invoice].present?
|
319
|
+
headers['InterfaceVersion'] = '1'
|
320
|
+
headers['InterfaceName'] = 'Spreedly'
|
321
|
+
headers['CompanyName'] = 'Spreedly'
|
322
|
+
headers
|
323
|
+
end
|
324
|
+
|
325
|
+
def success_from(action, response)
|
326
|
+
success = error(response).nil?
|
327
|
+
success &&= SUCCESS_TRANSACTION_STATUS.include?(response['result'].first['transaction']['responseCode']) unless TRANSACTIONS_WITHOUT_RESPONSE_CODE.include?(action)
|
328
|
+
success
|
329
|
+
end
|
330
|
+
|
331
|
+
def error(response)
|
332
|
+
server_error = { 'longText' => response['error'] } if response['error']
|
333
|
+
server_error || response['result'].first['error']
|
334
|
+
end
|
335
|
+
|
336
|
+
def current_date_time(options = {})
|
337
|
+
time_zone = options[:merchant_time_zone] || 'Pacific Time (US & Canada)'
|
338
|
+
time = Time.now.in_time_zone(time_zone)
|
339
|
+
offset = Time.now.in_time_zone(time_zone).formatted_offset
|
340
|
+
|
341
|
+
time.strftime('%Y-%m-%dT%H:%M:%S.%3N') + offset
|
342
|
+
end
|
343
|
+
end
|
344
|
+
end
|
345
|
+
end
|
@@ -4,10 +4,13 @@ module ActiveMerchant #:nodoc:
|
|
4
4
|
self.test_url = 'https://payments.sta.simetrik.com/v1'
|
5
5
|
self.live_url = 'https://payments.simetrik.com/v1'
|
6
6
|
|
7
|
-
class_attribute :test_auth_url, :live_auth_url
|
7
|
+
class_attribute :test_auth_url, :live_auth_url, :test_audience, :live_audience
|
8
8
|
self.test_auth_url = 'https://tenant-payments-dev.us.auth0.com/oauth/token'
|
9
9
|
self.live_auth_url = 'https://tenant-payments-prod.us.auth0.com/oauth/token'
|
10
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
|
+
|
11
14
|
self.supported_countries = %w(PE AR)
|
12
15
|
self.default_currency = 'USD'
|
13
16
|
self.supported_cardtypes = %i[visa master american_express discover]
|
@@ -39,7 +42,7 @@ module ActiveMerchant #:nodoc:
|
|
39
42
|
}
|
40
43
|
|
41
44
|
def initialize(options = {})
|
42
|
-
requires!(options, :client_id, :client_secret
|
45
|
+
requires!(options, :client_id, :client_secret)
|
43
46
|
super
|
44
47
|
@access_token = {}
|
45
48
|
sign_access_token()
|
@@ -52,7 +55,6 @@ module ActiveMerchant #:nodoc:
|
|
52
55
|
add_forward_route(post, options)
|
53
56
|
add_forward_payload(post, money, payment, options)
|
54
57
|
add_stored_credential(post, options)
|
55
|
-
|
56
58
|
commit('authorize', post, { token_acquirer: options[:token_acquirer] })
|
57
59
|
end
|
58
60
|
|
@@ -70,7 +72,7 @@ module ActiveMerchant #:nodoc:
|
|
70
72
|
acquire_extra_options: options[:acquire_extra_options] || {}
|
71
73
|
}
|
72
74
|
}
|
73
|
-
post[:forward_payload][:amount][:vat] = options[:vat] if options[:vat]
|
75
|
+
post[:forward_payload][:amount][:vat] = options[:vat].to_f / 100 if options[:vat]
|
74
76
|
|
75
77
|
add_forward_route(post, options)
|
76
78
|
commit('capture', post, { token_acquirer: options[:token_acquirer] })
|
@@ -127,12 +129,10 @@ module ActiveMerchant #:nodoc:
|
|
127
129
|
|
128
130
|
def scrub(transcript)
|
129
131
|
transcript.
|
130
|
-
gsub(%r((
|
131
|
-
gsub(%r((
|
132
|
-
gsub(%r((
|
133
|
-
gsub(%r((
|
134
|
-
gsub(%r((\"holder_first_name\\\":\\\")"\w+"), '\1[FILTERED]').
|
135
|
-
gsub(%r((\"holder_last_name\\\":\\\")"\w+"), '\1[FILTERED]')
|
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
136
|
end
|
137
137
|
|
138
138
|
private
|
@@ -148,7 +148,7 @@ module ActiveMerchant #:nodoc:
|
|
148
148
|
def add_forward_payload(post, money, payment, options)
|
149
149
|
forward_payload = {}
|
150
150
|
add_user(forward_payload, options[:user]) if options[:user]
|
151
|
-
add_order(forward_payload, money, options
|
151
|
+
add_order(forward_payload, money, options)
|
152
152
|
add_payment_method(forward_payload, payment, options[:payment_method]) if options[:payment_method] || payment
|
153
153
|
|
154
154
|
forward_payload[:payment_method] = {} unless forward_payload[:payment_method]
|
@@ -230,29 +230,34 @@ module ActiveMerchant #:nodoc:
|
|
230
230
|
post[:forward_payload][:authentication][:stored_credential] = options[:stored_credential] if check_initiator && check_reason_type
|
231
231
|
end
|
232
232
|
|
233
|
-
def add_order(post, money,
|
233
|
+
def add_order(post, money, options)
|
234
|
+
return unless options[:order] || money
|
235
|
+
|
234
236
|
order = {}
|
235
|
-
|
236
|
-
order[:
|
237
|
-
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]
|
238
241
|
order[:datetime_local_transaction] = order_options[:datetime_local_transaction] if order_options[:datetime_local_transaction]
|
239
242
|
|
240
|
-
add_amount(order, money,
|
241
|
-
add_address('shipping_address', order,
|
243
|
+
add_amount(order, money, options)
|
244
|
+
add_address('shipping_address', order, options)
|
242
245
|
|
243
246
|
post[:order] = order
|
244
247
|
end
|
245
248
|
|
246
|
-
def add_amount(post, money,
|
249
|
+
def add_amount(post, money, options)
|
247
250
|
amount_obj = {}
|
248
251
|
amount_obj[:total_amount] = amount(money).to_f
|
249
|
-
amount_obj[:currency] = (
|
250
|
-
amount_obj[:vat] =
|
252
|
+
amount_obj[:currency] = (options[:currency] || currency(money))
|
253
|
+
amount_obj[:vat] = options[:vat].to_f / 100 if options[:vat]
|
251
254
|
|
252
255
|
post[:amount] = amount_obj
|
253
256
|
end
|
254
257
|
|
255
|
-
def add_address(tag, post,
|
258
|
+
def add_address(tag, post, options)
|
259
|
+
return unless address_options = options[:shipping_address]
|
260
|
+
|
256
261
|
address = {}
|
257
262
|
address[:name] = address_options[:name] if address_options[:name]
|
258
263
|
address[:address1] = address_options[:address1] if address_options[:address1]
|
@@ -335,6 +340,7 @@ module ActiveMerchant #:nodoc:
|
|
335
340
|
}
|
336
341
|
end
|
337
342
|
|
343
|
+
# if this method is refactored, ensure that the client_secret is properly scrubbed
|
338
344
|
def sign_access_token
|
339
345
|
fetch_access_token() if Time.new.to_i > (@access_token[:expires_at] || 0) + 10
|
340
346
|
@access_token[:access_token]
|
@@ -348,7 +354,7 @@ module ActiveMerchant #:nodoc:
|
|
348
354
|
login_info = {}
|
349
355
|
login_info[:client_id] = @options[:client_id]
|
350
356
|
login_info[:client_secret] = @options[:client_secret]
|
351
|
-
login_info[:audience] =
|
357
|
+
login_info[:audience] = test? ? test_audience : live_audience
|
352
358
|
login_info[:grant_type] = 'client_credentials'
|
353
359
|
response = parse(ssl_post(auth_url(), login_info.to_json, {
|
354
360
|
'content-Type' => 'application/json'
|
@@ -145,6 +145,7 @@ module ActiveMerchant #:nodoc:
|
|
145
145
|
|
146
146
|
def void(identification, options = {})
|
147
147
|
post = {}
|
148
|
+
post[:reverse_transfer] = options[:reverse_transfer] if options[:reverse_transfer]
|
148
149
|
post[:metadata] = options[:metadata] if options[:metadata]
|
149
150
|
post[:reason] = options[:reason] if options[:reason]
|
150
151
|
post[:expand] = [:charge]
|
@@ -280,6 +281,7 @@ module ActiveMerchant #:nodoc:
|
|
280
281
|
def scrub(transcript)
|
281
282
|
transcript.
|
282
283
|
gsub(%r((Authorization: Basic )\w+), '\1[FILTERED]').
|
284
|
+
gsub(%r((Authorization: Bearer )\w+), '\1[FILTERED]').
|
283
285
|
gsub(%r((&?three_d_secure\[cryptogram\]=)[\w=]*(&?)), '\1[FILTERED]\2').
|
284
286
|
gsub(%r(((\[card\]|card)\[cryptogram\]=)[^&]+(&?)), '\1[FILTERED]\3').
|
285
287
|
gsub(%r(((\[card\]|card)\[cvc\]=)\d+), '\1[FILTERED]').
|
@@ -301,7 +303,7 @@ module ActiveMerchant #:nodoc:
|
|
301
303
|
def delete_latest_test_external_account(account)
|
302
304
|
return unless test?
|
303
305
|
|
304
|
-
auth_header = { 'Authorization'
|
306
|
+
auth_header = { 'Authorization' => 'Basic ' + Base64.strict_encode64(options[:login].to_s + ':').strip }
|
305
307
|
url = "#{live_url}accounts/#{CGI.escape(account)}/external_accounts"
|
306
308
|
accounts_response = JSON.parse(ssl_get("#{url}?limit=100", auth_header))
|
307
309
|
to_delete = accounts_response['data'].reject { |ac| ac['default_for_currency'] }
|
@@ -389,6 +391,7 @@ module ActiveMerchant #:nodoc:
|
|
389
391
|
end
|
390
392
|
|
391
393
|
add_metadata(post, options)
|
394
|
+
add_shipping_address(post, payment, options)
|
392
395
|
add_application_fee(post, options)
|
393
396
|
add_exchange_rate(post, options)
|
394
397
|
add_destination(post, options)
|
@@ -555,6 +558,23 @@ module ActiveMerchant #:nodoc:
|
|
555
558
|
post[:metadata][:card_read_method] = creditcard.read_method if creditcard.respond_to?(:read_method)
|
556
559
|
end
|
557
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
|
+
|
558
578
|
def add_source_owner(post, creditcard, options)
|
559
579
|
post[:owner] = {}
|
560
580
|
post[:owner][:name] = creditcard.name if creditcard.name
|
@@ -632,18 +652,19 @@ module ActiveMerchant #:nodoc:
|
|
632
652
|
end
|
633
653
|
end
|
634
654
|
|
635
|
-
def
|
636
|
-
|
637
|
-
|
655
|
+
def key(options = {})
|
656
|
+
options[:key] || @api_key
|
657
|
+
end
|
638
658
|
|
659
|
+
def headers(options = {})
|
639
660
|
headers = {
|
640
|
-
'Authorization' => 'Basic ' + Base64.strict_encode64(key.to_s + ':').strip,
|
661
|
+
'Authorization' => 'Basic ' + Base64.strict_encode64(key(options).to_s + ':').strip,
|
641
662
|
'User-Agent' => "Stripe/v1 ActiveMerchantBindings/#{ActiveMerchant::VERSION}",
|
642
663
|
'Stripe-Version' => api_version(options),
|
643
664
|
'X-Stripe-Client-User-Agent' => stripe_client_user_agent(options),
|
644
665
|
'X-Stripe-Client-User-Metadata' => { ip: options[:ip] }.to_json
|
645
666
|
}
|
646
|
-
headers['Idempotency-Key'] = idempotency_key if idempotency_key
|
667
|
+
headers['Idempotency-Key'] = options[:idempotency_key] if options[:idempotency_key]
|
647
668
|
headers['Stripe-Account'] = options[:stripe_account] if options[:stripe_account]
|
648
669
|
headers
|
649
670
|
end
|
@@ -674,6 +695,9 @@ module ActiveMerchant #:nodoc:
|
|
674
695
|
|
675
696
|
def commit(method, url, parameters = nil, options = {})
|
676
697
|
add_expand_parameters(parameters, options) if parameters
|
698
|
+
|
699
|
+
return Response.new(false, 'Invalid API Key provided') if test? && !key(options).start_with?('sk_test')
|
700
|
+
|
677
701
|
response = api_request(method, url, parameters, options)
|
678
702
|
response['webhook_id'] = options[:webhook_id] if options[:webhook_id]
|
679
703
|
success = success_from(response, options)
|