activemerchant 1.58.0 → 1.59.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +54 -0
  3. data/README.md +3 -3
  4. data/lib/active_merchant/billing/check.rb +3 -0
  5. data/lib/active_merchant/billing/credit_card.rb +7 -2
  6. data/lib/active_merchant/billing/credit_card_methods.rb +5 -1
  7. data/lib/active_merchant/billing/gateway.rb +5 -3
  8. data/lib/active_merchant/billing/gateways/authorize_net.rb +3 -3
  9. data/lib/active_merchant/billing/gateways/barclaycard_smartpay.rb +34 -5
  10. data/lib/active_merchant/billing/gateways/blue_pay.rb +1 -1
  11. data/lib/active_merchant/billing/gateways/blue_snap.rb +348 -0
  12. data/lib/active_merchant/billing/gateways/braintree_blue.rb +6 -3
  13. data/lib/active_merchant/billing/gateways/card_stream.rb +33 -15
  14. data/lib/active_merchant/billing/gateways/cashnet.rb +1 -0
  15. data/lib/active_merchant/billing/gateways/cyber_source.rb +7 -3
  16. data/lib/active_merchant/billing/gateways/global_collect.rb +293 -0
  17. data/lib/active_merchant/billing/gateways/jetpay.rb +11 -8
  18. data/lib/active_merchant/billing/gateways/latitude19.rb +416 -0
  19. data/lib/active_merchant/billing/gateways/merchant_e_solutions.rb +13 -0
  20. data/lib/active_merchant/billing/gateways/merchant_warrior.rb +10 -7
  21. data/lib/active_merchant/billing/gateways/mercury.rb +1 -1
  22. data/lib/active_merchant/billing/gateways/metrics_global.rb +1 -1
  23. data/lib/active_merchant/billing/gateways/moneris.rb +8 -1
  24. data/lib/active_merchant/billing/gateways/nmi.rb +25 -9
  25. data/lib/active_merchant/billing/gateways/openpay.rb +1 -1
  26. data/lib/active_merchant/billing/gateways/orbital.rb +5 -3
  27. data/lib/active_merchant/billing/gateways/paymill.rb +1 -1
  28. data/lib/active_merchant/billing/gateways/paypal_express.rb +1 -6
  29. data/lib/active_merchant/billing/gateways/payu_in.rb +3 -2
  30. data/lib/active_merchant/billing/gateways/s5.rb +8 -5
  31. data/lib/active_merchant/billing/gateways/sage.rb +1 -7
  32. data/lib/active_merchant/billing/gateways/sage_pay.rb +0 -4
  33. data/lib/active_merchant/billing/gateways/secure_net.rb +0 -5
  34. data/lib/active_merchant/billing/gateways/secure_pay.rb +1 -1
  35. data/lib/active_merchant/billing/gateways/securion_pay.rb +46 -17
  36. data/lib/active_merchant/billing/gateways/stripe.rb +5 -8
  37. data/lib/active_merchant/billing/gateways/tns.rb +1 -1
  38. data/lib/active_merchant/billing/gateways/trans_first.rb +1 -2
  39. data/lib/active_merchant/billing/gateways/vanco.rb +1 -1
  40. data/lib/active_merchant/billing/gateways/visanet_peru.rb +218 -0
  41. data/lib/active_merchant/billing/gateways/world_net.rb +344 -0
  42. data/lib/active_merchant/billing/gateways/worldpay.rb +8 -11
  43. data/lib/active_merchant/billing/network_tokenization_credit_card.rb +4 -0
  44. data/lib/active_merchant/country.rb +0 -2
  45. data/lib/active_merchant/version.rb +1 -1
  46. metadata +7 -2
@@ -0,0 +1,416 @@
1
+ module ActiveMerchant #:nodoc:
2
+ module Billing #:nodoc:
3
+ class Latitude19Gateway < Gateway
4
+ self.display_name = "Latitude19 Gateway"
5
+ self.homepage_url = "http://www.l19tech.com"
6
+
7
+ self.live_url = "https://gateway.l19tech.com/payments/"
8
+ self.test_url = "https://gateway-sb.l19tech.com/payments/"
9
+
10
+ self.supported_countries = ["US", "CA"]
11
+ self.default_currency = "USD"
12
+ self.money_format = :cents
13
+ self.supported_cardtypes = [:visa, :master, :american_express, :discover, :diners_club, :jcb]
14
+
15
+ RESPONSE_CODE_MAPPING = {
16
+ '100' => 'Approved',
17
+ '101' => 'Local duplicate detected',
18
+ '102' => 'Accepted local capture with no match',
19
+ '103' => 'Auth succeeded but capture failed',
20
+ '104' => 'Auth succeeded but failed to save info',
21
+ '200' => STANDARD_ERROR_CODE[:card_declined],
22
+ '300' => 'Processor reject',
23
+ '301' => 'Local reject on user/password',
24
+ '302' => 'Local reject',
25
+ '303' => 'Processor unknown response',
26
+ '304' => 'Error parsing processor response',
27
+ '305' => 'Processor auth succeeded but settle failed',
28
+ '306' => 'Processor auth succeeded settle status unknown',
29
+ '307' => 'Processor settle status unknown',
30
+ '308' => 'Processor duplicate',
31
+ '400' => 'Not submitted',
32
+ '401' => 'Terminated before request submitted',
33
+ '402' => 'Local server busy',
34
+ '500' => 'Submitted not returned',
35
+ '501' => 'Terminated before response returned',
36
+ '502' => 'Processor returned timeout status',
37
+ '600' => 'Failed local capture with no match',
38
+ '601' => 'Failed local capture',
39
+ '700' => 'Failed local void (not in capture file)',
40
+ '701' => 'Failed local void',
41
+ '800' => 'Failed local refund (not authorized)',
42
+ '801' => 'Failed local refund'
43
+ }
44
+
45
+ BRAND_MAP = {
46
+ "master" => "MC",
47
+ "visa" => "VI",
48
+ "american_express" => "AX",
49
+ "discover" => "DS",
50
+ "diners_club" => "DC",
51
+ "jcb" => "JC"
52
+ }
53
+
54
+ def initialize(options={})
55
+ requires!(options, :account_number, :configuration_id, :secret)
56
+ super
57
+ end
58
+
59
+ def purchase(amount, payment_method, options={})
60
+ if payment_method.is_a?(String)
61
+ auth_or_sale("sale", payment_method, amount, nil, options)
62
+ else
63
+ MultiResponse.run() do |r|
64
+ r.process { get_session(options) }
65
+ r.process { get_token(r.authorization, payment_method, options) }
66
+ r.process { auth_or_sale("sale", r.authorization, amount, payment_method, options) }
67
+ end
68
+ end
69
+ end
70
+
71
+ def authorize(amount, payment_method, options={})
72
+ if payment_method.is_a?(String)
73
+ auth_or_sale("auth", payment_method, amount, nil, options)
74
+ else
75
+ MultiResponse.run() do |r|
76
+ r.process { get_session(options) }
77
+ r.process { get_token(r.authorization, payment_method, options) }
78
+ r.process { auth_or_sale("auth", r.authorization, amount, payment_method, options) }
79
+ end
80
+ end
81
+ end
82
+
83
+ def capture(amount, authorization, options={})
84
+ post = {}
85
+ post[:method] = "deposit"
86
+ add_request_id(post)
87
+
88
+ params = {}
89
+
90
+ _, params[:pgwTID] = split_authorization(authorization)
91
+
92
+ add_invoice(params, amount, options)
93
+ add_credentials(params, post[:method])
94
+
95
+ post[:params] = [params]
96
+ commit("v1/", post)
97
+ end
98
+
99
+ def void(authorization, options={})
100
+ method, pgwTID = split_authorization(authorization)
101
+ case method
102
+ when "auth"
103
+ reverse_or_void("reversal", pgwTID, options)
104
+ when "deposit", "sale"
105
+ reverse_or_void("void", pgwTID, options)
106
+ else
107
+ message = "Unsupported operation: successful Purchase, Authorize and unsettled Capture transactions can only be voided."
108
+ return Response.new(false, message)
109
+ end
110
+ end
111
+
112
+ def credit(amount, payment_method, options={})
113
+ if payment_method.is_a?(String)
114
+ refundWithCard(payment_method, amount, nil, options)
115
+ else
116
+ MultiResponse.run() do |r|
117
+ r.process { get_session(options) }
118
+ r.process { get_token(r.authorization, payment_method, options) }
119
+ r.process { refundWithCard(r.authorization, amount, payment_method, options) }
120
+ end
121
+ end
122
+ end
123
+
124
+ def verify(payment_method, options={}, action=nil)
125
+ if payment_method.is_a?(String)
126
+ verifyOnly(action, payment_method, nil, options)
127
+ else
128
+ MultiResponse.run() do |r|
129
+ r.process { get_session(options) }
130
+ r.process { get_token(r.authorization, payment_method, options) }
131
+ r.process { verifyOnly(action, r.authorization, payment_method, options) }
132
+ end
133
+ end
134
+ end
135
+
136
+ def store(payment_method, options={})
137
+ verify(payment_method, options, "store")
138
+ end
139
+
140
+ def supports_scrubbing?
141
+ true
142
+ end
143
+
144
+ def scrub(transcript)
145
+ transcript.
146
+ gsub(%r((\"cardNumber\\\":\\\")\d+), '\1[FILTERED]').
147
+ gsub(%r((\"cvv\\\":\\\")\d+), '\1[FILTERED]')
148
+ end
149
+
150
+
151
+ private
152
+
153
+ def add_request_id(post)
154
+ post[:id] = SecureRandom.hex(16)
155
+ end
156
+
157
+ def add_timestamp()
158
+ Time.now.getutc.strftime("%Y%m%d%H%M%S")
159
+ end
160
+
161
+ def add_hmac(params, method)
162
+ if method == "getSession"
163
+ hmac_message = params[:pgwAccountNumber] + "|" + params[:pgwConfigurationId] + "|" + params[:requestTimeStamp] + "|" + method
164
+ else
165
+ hmac_message = params[:pgwAccountNumber] + "|" + params[:pgwConfigurationId] + "|" + (params[:orderNumber] || "") + "|" + method + "|" + (params[:amount] || "") + "|" + (params[:sessionToken] || "") + "|" + (params[:accountToken] || "")
166
+ end
167
+
168
+ OpenSSL::HMAC.hexdigest('sha512', @options[:secret], hmac_message)
169
+ end
170
+
171
+ def add_credentials(params, method)
172
+ params[:pgwAccountNumber] = @options[:account_number]
173
+ params[:pgwConfigurationId] = @options[:configuration_id]
174
+
175
+ params[:requestTimeStamp] = add_timestamp() if method == "getSession"
176
+
177
+ params[:pgwHMAC] = add_hmac(params, method)
178
+ end
179
+
180
+ def add_invoice(params, money, options)
181
+ params[:amount] = amount(money)
182
+ params[:orderNumber] = options[:order_id]
183
+ params[:transactionClass] = options[:transaction_class] || "eCommerce"
184
+ end
185
+
186
+ def add_payment_method(params, credit_card)
187
+ params[:cardExp] = format(credit_card.month, :two_digits).to_s + "/" + format(credit_card.year, :two_digits).to_s
188
+ params[:cardType] = BRAND_MAP[credit_card.brand.to_s]
189
+ params[:cvv] = credit_card.verification_value
190
+ params[:firstName] = credit_card.first_name
191
+ params[:lastName] = credit_card.last_name
192
+ end
193
+
194
+ def add_customer_data(params, options)
195
+ if (billing_address = options[:billing_address] || options[:address])
196
+ params[:address1] = billing_address[:address1]
197
+ params[:address2] = billing_address[:address2]
198
+ params[:city] = billing_address[:city]
199
+ params[:stateProvince] = billing_address[:state]
200
+ params[:zipPostalCode] = billing_address[:zip]
201
+ params[:countryCode] = billing_address[:country]
202
+ end
203
+ end
204
+
205
+ def get_session(options={})
206
+ post = {}
207
+ post[:method] = "getSession"
208
+ add_request_id(post)
209
+
210
+ params = {}
211
+ add_credentials(params, post[:method])
212
+
213
+ post[:params] = [params]
214
+ commit("session", post)
215
+ end
216
+
217
+ def get_token(authorization, payment_method, options={})
218
+ post = {}
219
+ post[:method] = "tokenize"
220
+ add_request_id(post)
221
+
222
+ params = {}
223
+ _, params[:sessionId] = split_authorization(authorization)
224
+ params[:cardNumber] = payment_method.number
225
+
226
+ post[:params] = [params]
227
+ commit("token", post)
228
+ end
229
+
230
+ def auth_or_sale(method, authorization, amount, credit_card, options={})
231
+ post = {}
232
+ post[:method] = method
233
+ add_request_id(post)
234
+
235
+ params = {}
236
+ if credit_card
237
+ _, params[:sessionToken] = split_authorization(authorization)
238
+ add_payment_method(params, credit_card)
239
+ add_customer_data(params, options)
240
+ else
241
+ _, params[:accountToken] = split_authorization(authorization)
242
+ end
243
+ add_invoice(params, amount, options)
244
+ add_credentials(params, post[:method])
245
+
246
+ post[:params] = [params]
247
+ commit("v1/", post)
248
+ end
249
+
250
+ def verifyOnly(action, authorization, credit_card, options={})
251
+ post = {}
252
+ post[:method] = "verifyOnly"
253
+ add_request_id(post)
254
+
255
+ params = {}
256
+ if credit_card
257
+ _, params[:sessionToken] = split_authorization(authorization)
258
+ add_payment_method(params, credit_card)
259
+ add_customer_data(params, options)
260
+ else
261
+ _, params[:accountToken] = split_authorization(authorization)
262
+ end
263
+ params[:requestAccountToken] = "1" if action == "store"
264
+ add_invoice(params, 0, options)
265
+ add_credentials(params, post[:method])
266
+
267
+ post[:params] = [params]
268
+ commit("v1/", post)
269
+ end
270
+
271
+ def refundWithCard(authorization, amount, credit_card, options={})
272
+ post = {}
273
+ post[:method] = "refundWithCard"
274
+ add_request_id(post)
275
+
276
+ params = {}
277
+ if credit_card
278
+ _, params[:sessionToken] = split_authorization(authorization)
279
+ add_payment_method(params, credit_card)
280
+ else
281
+ _, params[:accountToken] = split_authorization(authorization)
282
+ end
283
+ add_invoice(params, amount, options)
284
+ add_credentials(params, post[:method])
285
+
286
+ post[:params] = [params]
287
+ commit("v1/", post)
288
+ end
289
+
290
+ def reverse_or_void(method, pgwTID, options={})
291
+ post = {}
292
+ post[:method] = method
293
+ add_request_id(post)
294
+
295
+ params = {}
296
+ params[:orderNumber] = options[:order_id]
297
+ params[:pgwTID] = pgwTID
298
+ add_credentials(params, post[:method])
299
+
300
+ post[:params] = [params]
301
+ commit("v1/", post)
302
+ end
303
+
304
+ def commit(endpoint, post)
305
+ begin
306
+ raw_response = ssl_post(url() + endpoint, post_data(post), headers)
307
+ response = parse(raw_response)
308
+ rescue ResponseError => e
309
+ raw_response = e.response.body
310
+ response_error(raw_response)
311
+ rescue JSON::ParserError
312
+ unparsable_response(raw_response)
313
+ else
314
+ success = success_from(response)
315
+ Response.new(
316
+ success,
317
+ message_from(response),
318
+ response,
319
+ authorization: success ? authorization_from(response, post[:method]) : nil,
320
+ avs_result: success ? avs_from(response) : nil,
321
+ cvv_result: success ? cvv_from(response) : nil,
322
+ error_code: success ? nil : error_from(response),
323
+ test: test?
324
+ )
325
+ end
326
+ end
327
+
328
+ def headers
329
+ {
330
+ "Content-Type" => "application/json"
331
+ }
332
+ end
333
+
334
+ def post_data(params)
335
+ params.to_json
336
+ end
337
+
338
+ def url
339
+ test? ? test_url : live_url
340
+ end
341
+
342
+ def parse(body)
343
+ JSON.parse(body)
344
+ end
345
+
346
+ def success_from(response)
347
+ return false if response["result"].nil? || response["error"]
348
+
349
+ if response["result"].key?("pgwResponseCode")
350
+ response["error"].nil? && response["result"]["lastActionSucceeded"] == 1 && response["result"]["pgwResponseCode"] == "100"
351
+ else
352
+ response["error"].nil? && response["result"]["lastActionSucceeded"] == 1
353
+ end
354
+ end
355
+
356
+ def message_from(response)
357
+ return response["error"] if response["error"]
358
+ return "Failed" unless response.key?("result")
359
+
360
+ if response["result"].key?("pgwResponseCode")
361
+ RESPONSE_CODE_MAPPING[response["result"]["pgwResponseCode"]] || response["result"]["responseText"]
362
+ else
363
+ response["result"]["lastActionSucceeded"] == 1 ? "Succeeded" : "Failed"
364
+ end
365
+ end
366
+
367
+ def error_from(response)
368
+ return response["error"] if response["error"]
369
+ return "Failed" unless response.key?("result")
370
+ return response["result"]["pgwResponseCode"] || response["result"]["processor"]["responseCode"] || "Failed"
371
+ end
372
+
373
+ def authorization_from(response, method)
374
+ method + "|" + (
375
+ response["result"]["sessionId"] ||
376
+ response["result"]["sessionToken"] ||
377
+ response["result"]["pgwTID"] ||
378
+ response["result"]["accountToken"]
379
+ )
380
+ end
381
+
382
+ def split_authorization(authorization)
383
+ authorization.split("|")
384
+ end
385
+
386
+ def avs_from(response)
387
+ response["result"].key?("avsResponse") ? AVSResult.new(code: response["result"]["avsResponse"]) : nil
388
+ end
389
+
390
+ def cvv_from(response)
391
+ response["result"].key?("cvvResponse") ? CVVResult.new(response["result"]["cvvResponse"]) : nil
392
+ end
393
+
394
+ def response_error(raw_response)
395
+ begin
396
+ response = parse(raw_response)
397
+ rescue JSON::ParserError
398
+ unparsable_response(raw_response)
399
+ else
400
+ return Response.new(
401
+ false,
402
+ message_from(response),
403
+ response,
404
+ :test => test?
405
+ )
406
+ end
407
+ end
408
+
409
+ def unparsable_response(raw_response)
410
+ message = "Invalid JSON response received from Latitude19Gateway. Please contact Latitude19Gateway if you continue to receive this message."
411
+ message += " (The raw response returned by the API was #{raw_response.inspect})"
412
+ return Response.new(false, message)
413
+ end
414
+ end
415
+ end
416
+ end
@@ -1,6 +1,8 @@
1
1
  module ActiveMerchant #:nodoc:
2
2
  module Billing #:nodoc:
3
3
  class MerchantESolutionsGateway < Gateway
4
+ include Empty
5
+
4
6
  self.test_url = 'https://cert.merchante-solutions.com/mes-api/tridentApi'
5
7
  self.live_url = 'https://api.merchante-solutions.com/mes-api/tridentApi'
6
8
 
@@ -28,6 +30,7 @@ module ActiveMerchant #:nodoc:
28
30
  add_invoice(post, options)
29
31
  add_payment_source(post, creditcard_or_card_id, options)
30
32
  add_address(post, options)
33
+ add_3dsecure_params(post, options)
31
34
  commit('P', money, post)
32
35
  end
33
36
 
@@ -38,6 +41,7 @@ module ActiveMerchant #:nodoc:
38
41
  add_invoice(post, options)
39
42
  add_payment_source(post, creditcard_or_card_id, options)
40
43
  add_address(post, options)
44
+ add_3dsecure_params(post, options)
41
45
  commit('D', money, post)
42
46
  end
43
47
 
@@ -45,6 +49,8 @@ module ActiveMerchant #:nodoc:
45
49
  post ={}
46
50
  post[:transaction_id] = transaction_id
47
51
  post[:client_reference_number] = options[:customer] if options.has_key?(:customer)
52
+ add_invoice(post, options)
53
+ add_3dsecure_params(post, options)
48
54
  commit('S', money, post)
49
55
  end
50
56
 
@@ -121,6 +127,13 @@ module ActiveMerchant #:nodoc:
121
127
  post[:card_exp_date] = expdate(creditcard)
122
128
  end
123
129
 
130
+ def add_3dsecure_params(post, options)
131
+ post[:xid] = options[:xid] unless empty?(options[:xid])
132
+ post[:cavv] = options[:cavv] unless empty?(options[:cavv])
133
+ post[:ucaf_collection_ind] = options[:ucaf_collection_ind] unless empty?(options[:ucaf_collection_ind])
134
+ post[:ucaf_auth_data] = options[:ucaf_auth_data] unless empty?(options[:ucaf_auth_data])
135
+ end
136
+
124
137
  def parse(body)
125
138
  results = {}
126
139
  body.split(/&/).each do |pair|