activemerchant 1.119.0 → 1.120.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +75 -1
  3. data/README.md +3 -1
  4. data/lib/active_merchant/billing/check.rb +10 -0
  5. data/lib/active_merchant/billing/credit_card_methods.rb +9 -3
  6. data/lib/active_merchant/billing/gateways/adyen.rb +20 -6
  7. data/lib/active_merchant/billing/gateways/authorize_net.rb +9 -3
  8. data/lib/active_merchant/billing/gateways/authorize_net_cim.rb +3 -0
  9. data/lib/active_merchant/billing/gateways/braintree_blue.rb +47 -7
  10. data/lib/active_merchant/billing/gateways/cashnet.rb +7 -2
  11. data/lib/active_merchant/billing/gateways/checkout_v2.rb +21 -0
  12. data/lib/active_merchant/billing/gateways/credorax.rb +13 -8
  13. data/lib/active_merchant/billing/gateways/cyber_source.rb +23 -3
  14. data/lib/active_merchant/billing/gateways/d_local.rb +1 -1
  15. data/lib/active_merchant/billing/gateways/elavon.rb +11 -1
  16. data/lib/active_merchant/billing/gateways/forte.rb +12 -0
  17. data/lib/active_merchant/billing/gateways/hps.rb +55 -1
  18. data/lib/active_merchant/billing/gateways/litle.rb +1 -1
  19. data/lib/active_merchant/billing/gateways/mercado_pago.rb +2 -2
  20. data/lib/active_merchant/billing/gateways/netbanx.rb +26 -2
  21. data/lib/active_merchant/billing/gateways/orbital.rb +62 -53
  22. data/lib/active_merchant/billing/gateways/payeezy.rb +30 -6
  23. data/lib/active_merchant/billing/gateways/payment_express.rb +5 -5
  24. data/lib/active_merchant/billing/gateways/payway_dot_com.rb +253 -0
  25. data/lib/active_merchant/billing/gateways/qvalent.rb +23 -9
  26. data/lib/active_merchant/billing/gateways/redsys.rb +19 -4
  27. data/lib/active_merchant/billing/gateways/safe_charge.rb +18 -11
  28. data/lib/active_merchant/billing/gateways/stripe.rb +8 -8
  29. data/lib/active_merchant/billing/gateways/stripe_payment_intents.rb +61 -25
  30. data/lib/active_merchant/billing/gateways/vpos.rb +172 -0
  31. data/lib/active_merchant/billing/gateways/worldpay.rb +24 -11
  32. data/lib/active_merchant/version.rb +1 -1
  33. data/lib/certs/cacert.pem +1582 -2431
  34. metadata +5 -3
@@ -39,6 +39,7 @@ module ActiveMerchant
39
39
  add_address(params, options)
40
40
  add_amount(params, amount, options)
41
41
  add_soft_descriptors(params, options)
42
+ add_level2_data(params, options)
42
43
  add_stored_credentials(params, options)
43
44
 
44
45
  commit(params, options)
@@ -53,6 +54,7 @@ module ActiveMerchant
53
54
  add_address(params, options)
54
55
  add_amount(params, amount, options)
55
56
  add_soft_descriptors(params, options)
57
+ add_level2_data(params, options)
56
58
  add_stored_credentials(params, options)
57
59
 
58
60
  commit(params, options)
@@ -77,6 +79,14 @@ module ActiveMerchant
77
79
  commit(params, options)
78
80
  end
79
81
 
82
+ def credit(amount, payment_method, options = {})
83
+ params = { transaction_type: 'refund' }
84
+
85
+ add_amount(params, amount, options)
86
+ add_payment_method(params, payment_method, options)
87
+ commit(params, options)
88
+ end
89
+
80
90
  def store(payment_method, options = {})
81
91
  params = { transaction_type: 'store' }
82
92
 
@@ -246,6 +256,13 @@ module ActiveMerchant
246
256
  params[:soft_descriptors] = options[:soft_descriptors] if options[:soft_descriptors]
247
257
  end
248
258
 
259
+ def add_level2_data(params, options)
260
+ return unless level2_data = options[:level2]
261
+
262
+ params[:level2] = {}
263
+ params[:level2][:customer_ref] = level2_data[:customer_ref]
264
+ end
265
+
249
266
  def add_stored_credentials(params, options)
250
267
  if options[:sequence] || options[:stored_credential]
251
268
  params[:stored_credentials] = {}
@@ -290,15 +307,16 @@ module ActiveMerchant
290
307
  response = json_error(e.response.body)
291
308
  end
292
309
 
310
+ success = success_from(response)
293
311
  Response.new(
294
- success_from(response),
295
- handle_message(response, success_from(response)),
312
+ success,
313
+ handle_message(response, success),
296
314
  response,
297
315
  test: test?,
298
316
  authorization: authorization_from(params, response),
299
317
  avs_result: { code: response['avs'] },
300
318
  cvv_result: response['cvv2'],
301
- error_code: error_code(response, success_from(response))
319
+ error_code: success ? nil : error_code_from(response)
302
320
  )
303
321
  end
304
322
 
@@ -352,10 +370,16 @@ module ActiveMerchant
352
370
  }
353
371
  end
354
372
 
355
- def error_code(response, success)
356
- return if success
373
+ def error_code_from(response)
374
+ error_code = nil
375
+ if response['bank_resp_code'] == '100'
376
+ return
377
+ elsif response['bank_resp_code']
378
+ error_code = response['bank_resp_code']
379
+ elsif error_code = response['Error'].to_h['messages'].to_a.map { |e| e['code'] }.join(', ')
380
+ end
357
381
 
358
- response['Error'].to_h['messages'].to_a.map { |e| e['code'] }.join(', ')
382
+ error_code
359
383
  end
360
384
 
361
385
  def success_from(response)
@@ -86,8 +86,8 @@ module ActiveMerchant #:nodoc:
86
86
  refund(money, identification, options)
87
87
  end
88
88
 
89
- def verify(money, payment_source, options = {})
90
- request = build_purchase_or_authorization_request(money, payment_source, options)
89
+ def verify(payment_source, options = {})
90
+ request = build_purchase_or_authorization_request(nil, payment_source, options)
91
91
  commit(:validate, request)
92
92
  end
93
93
 
@@ -154,7 +154,7 @@ module ActiveMerchant #:nodoc:
154
154
  add_credit_card(result, payment_source)
155
155
  end
156
156
 
157
- add_amount(result, money, options)
157
+ add_amount(result, money, options) if money
158
158
  add_invoice(result, options)
159
159
  add_address_verification_data(result, options)
160
160
  add_optional_elements(result, options)
@@ -234,8 +234,8 @@ module ActiveMerchant #:nodoc:
234
234
  address = options[:billing_address] || options[:address]
235
235
  return if address.nil?
236
236
 
237
- xml.add_element('EnableAvsData').text = 1
238
- xml.add_element('AvsAction').text = 1
237
+ xml.add_element('EnableAvsData').text = options[:enable_avs_data] || 1
238
+ xml.add_element('AvsAction').text = options[:avs_action] || 1
239
239
 
240
240
  xml.add_element('AvsStreetAddress').text = address[:address1]
241
241
  xml.add_element('AvsPostCode').text = address[:zip]
@@ -0,0 +1,253 @@
1
+ module ActiveMerchant #:nodoc:
2
+ module Billing #:nodoc:
3
+ class PaywayDotComGateway < Gateway
4
+ self.test_url = 'https://devedgilpayway.net/PaywayWS/Payment/CreditCard'
5
+ self.live_url = 'https://edgilpayway.com/PaywayWS/Payment/CreditCard'
6
+
7
+ self.supported_countries = %w[US CA]
8
+ self.default_currency = 'USD'
9
+ self.supported_cardtypes = %i[visa master american_express discover]
10
+
11
+ self.money_format = :cents
12
+
13
+ self.homepage_url = 'http://www.payway.com'
14
+ self.display_name = 'Payway Gateway'
15
+
16
+ STANDARD_ERROR_CODE_MAPPING = {
17
+ '5012' => STANDARD_ERROR_CODE[:card_declined],
18
+ '5035' => STANDARD_ERROR_CODE[:invalid_number],
19
+ '5037' => STANDARD_ERROR_CODE[:invalid_expiry_date],
20
+ '5045' => STANDARD_ERROR_CODE[:incorrect_zip]
21
+ }
22
+
23
+ # Payway to standard AVSResult codes.
24
+ AVS_MAPPING = {
25
+ 'N1' => 'I', # No address given with order
26
+ 'N2' => 'I', # Bill-to address did not pass
27
+ '““' => 'R', # AVS not performed (Blanks returned)
28
+ 'IU' => 'G', # AVS not performed by Issuer
29
+ 'ID' => 'S', # Issuer does not participate in AVS
30
+ 'IE' => 'E', # Edit Error - AVS data is invalid
31
+ 'IS' => 'R', # System unavailable or time-out
32
+ 'IB' => 'B', # Street address match. Postal code not verified due to incompatible formats (both were sent).
33
+ 'IC' => 'C', # Street address and postal code not verified due to incompatible format (both were sent).
34
+ 'IP' => 'P', # Postal code match. Street address not verified due to incompatible formats (both were sent).
35
+ 'A1' => 'K', # Accountholder name matches
36
+ 'A3' => 'V', # Accountholder name, billing address and postal code.
37
+ 'A4' => 'L', # Accountholder name and billing postal code match
38
+ 'A7' => 'O', # Accountholder name and billing address match
39
+ 'B3' => 'H', # Accountholder name incorrect, billing address and postal code match
40
+ 'B4' => 'F', # Accountholder name incorrect, billing postal code matches
41
+ 'B7' => 'T', # Accountholder name incorrect, billing address matches
42
+ 'B8' => 'N', # Accountholder name, billing address and postal code are all incorrect
43
+ '??' => 'R', # A double question mark symbol indicates an unrecognized response from association
44
+ 'I1' => 'X', # Zip code +4 and Address Match
45
+ 'I2' => 'W', # Zip code +4 Match
46
+ 'I3' => 'Y', # Zip code and Address Match
47
+ 'I4' => 'Z', # Zip code Match
48
+ 'I5' => 'M', # +4 and Address Match
49
+ 'I6' => 'W', # +4 Match
50
+ 'I7' => 'A', # Address Match
51
+ 'I8' => 'C', # No Match
52
+ }
53
+
54
+ PAYWAY_WS_SUCCESS = '5000'
55
+
56
+ SCRUB_PATTERNS = [
57
+ %r(("password\\?":\\?")[^\\]+),
58
+ %r(("fsv\\?":\\?")\d+),
59
+ %r(("fsv\\?": \\?")\d+),
60
+ %r(("accountNumber\\?":\\?")\d+),
61
+ %r(("accountNumber\\?": \\?")[^\\]+),
62
+ %r(("Invalid account number: )\d+)
63
+ ].freeze
64
+
65
+ SCRUB_REPLACEMENT = '\1[FILTERED]'
66
+
67
+ def initialize(options = {})
68
+ requires!(options, :login, :password, :company_id, :source_id)
69
+ super
70
+ end
71
+
72
+ def purchase(money, payment, options = {})
73
+ post = {}
74
+ add_common(post, options)
75
+ add_card_payment(post, payment, options)
76
+ add_card_transaction_details(post, money, options)
77
+ add_address(post, payment, options)
78
+
79
+ commit('sale', post)
80
+ end
81
+
82
+ def authorize(money, payment, options = {})
83
+ post = {}
84
+ add_common(post, options)
85
+ add_card_payment(post, payment, options)
86
+ add_card_transaction_details(post, money, options)
87
+ add_address(post, payment, options)
88
+
89
+ commit('authorize', post)
90
+ end
91
+
92
+ def capture(money, authorization, options = {})
93
+ post = {}
94
+ add_common(post, options)
95
+ add_card_transaction_name(post, authorization, options)
96
+
97
+ commit('capture', post)
98
+ end
99
+
100
+ def credit(money, payment, options = {})
101
+ post = {}
102
+ add_common(post, options)
103
+ add_card_payment(post, payment, options)
104
+ add_card_transaction_details(post, money, options)
105
+ add_address(post, payment, options)
106
+
107
+ commit('credit', post)
108
+ end
109
+
110
+ def void(authorization, options = {})
111
+ post = {}
112
+ add_common(post, options)
113
+ add_card_transaction_name(post, authorization, options)
114
+
115
+ commit('void', post)
116
+ end
117
+
118
+ def supports_scrubbing?
119
+ true
120
+ end
121
+
122
+ def scrub(transcript)
123
+ SCRUB_PATTERNS.inject(transcript) do |text, pattern|
124
+ text.gsub(pattern, SCRUB_REPLACEMENT)
125
+ end
126
+ end
127
+
128
+ private
129
+
130
+ def add_common(post, options)
131
+ post[:userName] = @options[:login]
132
+ post[:password] = @options[:password]
133
+ post[:companyId] = @options[:company_id]
134
+ post[:cardTransaction] = {}
135
+ post[:cardTransaction][:sourceId] = @options[:source_id]
136
+ end
137
+
138
+ def add_address(post, payment, options)
139
+ post[:cardAccount] ||= {}
140
+ address = options[:billing_address] || options[:address] || {}
141
+ first_name, last_name = split_names(address[:name])
142
+ full_address = "#{address[:address1]} #{address[:address2]}".strip
143
+ phone = address[:phone] || address[:phone_number]
144
+
145
+ post[:cardAccount][:firstName] = first_name if first_name
146
+ post[:cardAccount][:lastName] = last_name if last_name
147
+ post[:cardAccount][:address] = full_address if full_address
148
+ post[:cardAccount][:city] = address[:city] if address[:city]
149
+ post[:cardAccount][:state] = address[:state] if address[:state]
150
+ post[:cardAccount][:zip] = address[:zip] if address[:zip]
151
+ post[:cardAccount][:phone] = phone if phone
152
+ end
153
+
154
+ def add_card_transaction_details(post, money, options)
155
+ post[:cardTransaction][:amount] = amount(money)
156
+ eci_type = options[:eci_type].nil? ? '1' : options[:eci_type]
157
+ post[:cardTransaction][:eciType] = eci_type
158
+ post[:cardTransaction][:processorSoftDescriptor] = options[:processor_soft_descriptor] if options[:processor_soft_descriptor]
159
+ post[:cardTransaction][:tax] = options[:tax] if options[:tax]
160
+ end
161
+
162
+ def add_card_transaction_name(post, identifier, options)
163
+ post[:cardTransaction][:name] = identifier
164
+ end
165
+
166
+ def add_card_payment(post, payment, options)
167
+ # credit_card
168
+ post[:accountInputMode] = 'primaryAccountNumber'
169
+
170
+ post[:cardAccount] ||= {}
171
+ post[:cardAccount][:accountNumber] = payment.number
172
+ post[:cardAccount][:fsv] = payment.verification_value
173
+ post[:cardAccount][:expirationDate] = expdate(payment)
174
+ post[:cardAccount][:email] = options[:email] if options[:email]
175
+ end
176
+
177
+ def expdate(credit_card)
178
+ year = format(credit_card.year, :four_digits)
179
+ month = format(credit_card.month, :two_digits)
180
+
181
+ month + year
182
+ end
183
+
184
+ def parse(body)
185
+ body.blank? ? {} : JSON.parse(body)
186
+ end
187
+
188
+ def commit(action, parameters)
189
+ parameters[:request] = action
190
+
191
+ url = (test? ? test_url : live_url)
192
+ payload = parameters.to_json unless parameters.nil?
193
+
194
+ response =
195
+ begin
196
+ parse(ssl_request(:post, url, payload, headers))
197
+ rescue ResponseError => e
198
+ return Response.new(false, 'Invalid Login') if e.response.code == '401'
199
+
200
+ parse(e.response.body)
201
+ end
202
+
203
+ success = success_from(response)
204
+ avs_result_code = response['cardTransaction'].nil? || response['cardTransaction']['addressVerificationResults'].nil? ? '' : response['cardTransaction']['addressVerificationResults']
205
+ avs_result = AVSResult.new(code: AVS_MAPPING[avs_result_code])
206
+ cvv_result = CVVResult.new(response['cardTransaction']['fraudSecurityResults']) if response['cardTransaction'] && response['cardTransaction']['fraudSecurityResults']
207
+
208
+ Response.new(
209
+ success,
210
+ message_from(success, response),
211
+ response,
212
+ test: test?,
213
+ error_code: error_code_from(response),
214
+ authorization: authorization_from(response),
215
+ avs_result: avs_result,
216
+ cvv_result: cvv_result
217
+ )
218
+ end
219
+
220
+ def success_from(response)
221
+ response['paywayCode'] == PAYWAY_WS_SUCCESS
222
+ end
223
+
224
+ def error_code_from(response)
225
+ return '' if success_from(response)
226
+
227
+ error = !STANDARD_ERROR_CODE_MAPPING[response['paywayCode']].nil? ? STANDARD_ERROR_CODE_MAPPING[response['paywayCode']] : STANDARD_ERROR_CODE[:processing_error]
228
+ return error
229
+ end
230
+
231
+ def message_from(success, response)
232
+ return '' if response['paywayCode'].nil?
233
+
234
+ return response['paywayCode'] + '-' + 'success' if success
235
+
236
+ response['paywayCode'] + '-' + response['paywayMessage']
237
+ end
238
+
239
+ def authorization_from(response)
240
+ return '' if !success_from(response) || response['cardTransaction'].nil?
241
+
242
+ response['cardTransaction']['name']
243
+ end
244
+
245
+ def headers
246
+ {
247
+ 'Accept' => 'application/json',
248
+ 'Content-type' => 'application/json'
249
+ }
250
+ end
251
+ end
252
+ end
253
+ end
@@ -17,7 +17,7 @@ module ActiveMerchant #:nodoc:
17
17
  }
18
18
 
19
19
  def initialize(options = {})
20
- requires!(options, :username, :password, :merchant, :pem, :pem_password)
20
+ requires!(options, :username, :password, :merchant, :pem)
21
21
  super
22
22
  end
23
23
 
@@ -30,6 +30,7 @@ module ActiveMerchant #:nodoc:
30
30
  add_stored_credential_data(post, payment_method, options)
31
31
  add_customer_data(post, options)
32
32
  add_soft_descriptors(post, options)
33
+ add_customer_reference(post, options)
33
34
 
34
35
  commit('capture', post)
35
36
  end
@@ -43,6 +44,7 @@ module ActiveMerchant #:nodoc:
43
44
  add_stored_credential_data(post, payment_method, options)
44
45
  add_customer_data(post, options)
45
46
  add_soft_descriptors(post, options)
47
+ add_customer_reference(post, options)
46
48
 
47
49
  commit('preauth', post)
48
50
  end
@@ -53,6 +55,7 @@ module ActiveMerchant #:nodoc:
53
55
  add_reference(post, authorization, options)
54
56
  add_customer_data(post, options)
55
57
  add_soft_descriptors(post, options)
58
+ add_customer_reference(post, options)
56
59
 
57
60
  commit('captureWithoutAuth', post)
58
61
  end
@@ -64,6 +67,7 @@ module ActiveMerchant #:nodoc:
64
67
  add_customer_data(post, options)
65
68
  add_soft_descriptors(post, options)
66
69
  post['order.ECI'] = options[:eci] || 'SSL'
70
+ add_customer_reference(post, options)
67
71
 
68
72
  commit('refund', post)
69
73
  end
@@ -76,6 +80,7 @@ module ActiveMerchant #:nodoc:
76
80
  add_payment_method(post, payment_method)
77
81
  add_customer_data(post, options)
78
82
  add_soft_descriptors(post, options)
83
+ add_customer_reference(post, options)
79
84
 
80
85
  commit('refund', post)
81
86
  end
@@ -85,6 +90,7 @@ module ActiveMerchant #:nodoc:
85
90
  add_reference(post, authorization, options)
86
91
  add_customer_data(post, options)
87
92
  add_soft_descriptors(post, options)
93
+ add_customer_reference(post, options)
88
94
 
89
95
  commit('reversal', post)
90
96
  end
@@ -92,7 +98,7 @@ module ActiveMerchant #:nodoc:
92
98
  def store(payment_method, options = {})
93
99
  post = {}
94
100
  add_payment_method(post, payment_method)
95
- add_card_reference(post)
101
+ add_card_reference(post, options)
96
102
 
97
103
  commit('registerAccount', post)
98
104
  end
@@ -149,12 +155,16 @@ module ActiveMerchant #:nodoc:
149
155
  return unless payment_method.brand == 'visa'
150
156
 
151
157
  stored_credential = options[:stored_credential]
152
- if stored_credential[:initial_transaction]
153
- post['card.storedCredentialUsage'] = 'INITIAL_STORAGE'
154
- elsif stored_credential[:reason_type] == ('recurring' || 'installment')
158
+ if stored_credential[:reason_type] == 'unscheduled'
159
+ if stored_credential[:initiator] == 'merchant'
160
+ post['card.storedCredentialUsage'] = 'UNSCHEDULED_MIT'
161
+ elsif stored_credential[:initiator] == 'customer'
162
+ post['card.storedCredentialUsage'] = 'UNSCHEDULED_CIT'
163
+ end
164
+ elsif stored_credential[:reason_type] == 'recurring'
155
165
  post['card.storedCredentialUsage'] = 'RECURRING'
156
- elsif stored_credential[:reason_type] == 'unscheduled'
157
- post['card.storedCredentialUsage'] = 'UNSCHEDULED'
166
+ elsif stored_credential[:reason_type] == 'installment'
167
+ post['card.storedCredentialUsage'] = 'INSTALLMENT'
158
168
  end
159
169
  end
160
170
 
@@ -181,8 +191,12 @@ module ActiveMerchant #:nodoc:
181
191
  post['card.CVN'] = payment_method.verification_value
182
192
  end
183
193
 
184
- def add_card_reference(post)
185
- post['customer.customerReferenceNumber'] = options[:order_id]
194
+ def add_card_reference(post, options)
195
+ post['customer.customerReferenceNumber'] = options[:customer_reference_number] || options[:order_id]
196
+ end
197
+
198
+ def add_customer_reference(post, options)
199
+ post['customer.customerReferenceNumber'] = options[:customer_reference_number] if options[:customer_reference_number]
186
200
  end
187
201
 
188
202
  def add_reference(post, authorization, options)