activemerchant 1.56.0 → 1.66.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +331 -0
  3. data/README.md +9 -9
  4. data/lib/active_merchant/billing/check.rb +3 -0
  5. data/lib/active_merchant/billing/credit_card.rb +8 -3
  6. data/lib/active_merchant/billing/credit_card_methods.rb +41 -1
  7. data/lib/active_merchant/billing/gateway.rb +14 -6
  8. data/lib/active_merchant/billing/gateways/adyen.rb +228 -0
  9. data/lib/active_merchant/billing/gateways/authorize_net.rb +157 -44
  10. data/lib/active_merchant/billing/gateways/authorize_net_cim.rb +7 -4
  11. data/lib/active_merchant/billing/gateways/barclaycard_smartpay.rb +283 -0
  12. data/lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb +68 -2
  13. data/lib/active_merchant/billing/gateways/blue_pay.rb +2 -2
  14. data/lib/active_merchant/billing/gateways/blue_snap.rb +348 -0
  15. data/lib/active_merchant/billing/gateways/bpoint.rb +1 -1
  16. data/lib/active_merchant/billing/gateways/braintree_blue.rb +58 -20
  17. data/lib/active_merchant/billing/gateways/bridge_pay.rb +37 -8
  18. data/lib/active_merchant/billing/gateways/card_stream.rb +161 -40
  19. data/lib/active_merchant/billing/gateways/cashnet.rb +1 -0
  20. data/lib/active_merchant/billing/gateways/checkout_v2.rb +5 -2
  21. data/lib/active_merchant/billing/gateways/citrus_pay.rb +24 -0
  22. data/lib/active_merchant/billing/gateways/clearhaus.rb +24 -40
  23. data/lib/active_merchant/billing/gateways/conekta.rb +6 -1
  24. data/lib/active_merchant/billing/gateways/creditcall.rb +1 -1
  25. data/lib/active_merchant/billing/gateways/credorax.rb +310 -0
  26. data/lib/active_merchant/billing/gateways/culqi.rb +279 -0
  27. data/lib/active_merchant/billing/gateways/cyber_source.rb +80 -64
  28. data/lib/active_merchant/billing/gateways/data_cash.rb +10 -304
  29. data/lib/active_merchant/billing/gateways/digitzs.rb +292 -0
  30. data/lib/active_merchant/billing/gateways/elavon.rb +40 -26
  31. data/lib/active_merchant/billing/gateways/element.rb +356 -0
  32. data/lib/active_merchant/billing/gateways/fat_zebra.rb +16 -2
  33. data/lib/active_merchant/billing/gateways/firstdata_e4.rb +6 -1
  34. data/lib/active_merchant/billing/gateways/forte.rb +10 -2
  35. data/lib/active_merchant/billing/gateways/global_collect.rb +311 -0
  36. data/lib/active_merchant/billing/gateways/global_transport.rb +1 -0
  37. data/lib/active_merchant/billing/gateways/iats_payments.rb +13 -0
  38. data/lib/active_merchant/billing/gateways/in_context_paypal_express.rb +15 -0
  39. data/lib/active_merchant/billing/gateways/iveri.rb +251 -0
  40. data/lib/active_merchant/billing/gateways/jetpay.rb +33 -19
  41. data/lib/active_merchant/billing/gateways/kushki.rb +217 -0
  42. data/lib/active_merchant/billing/gateways/latitude19.rb +416 -0
  43. data/lib/active_merchant/billing/gateways/linkpoint.rb +2 -0
  44. data/lib/active_merchant/billing/gateways/litle.rb +29 -13
  45. data/lib/active_merchant/billing/gateways/mastercard.rb +268 -0
  46. data/lib/active_merchant/billing/gateways/maxipago.rb +145 -122
  47. data/lib/active_merchant/billing/gateways/merchant_e_solutions.rb +15 -1
  48. data/lib/active_merchant/billing/gateways/merchant_warrior.rb +10 -7
  49. data/lib/active_merchant/billing/gateways/mercury.rb +13 -5
  50. data/lib/active_merchant/billing/gateways/metrics_global.rb +1 -1
  51. data/lib/active_merchant/billing/gateways/migs.rb +23 -1
  52. data/lib/active_merchant/billing/gateways/monei.rb +1 -1
  53. data/lib/active_merchant/billing/gateways/moneris.rb +21 -1
  54. data/lib/active_merchant/billing/gateways/nab_transact.rb +12 -0
  55. data/lib/active_merchant/billing/gateways/ncr_secure_pay.rb +165 -0
  56. data/lib/active_merchant/billing/gateways/netbanx.rb +245 -0
  57. data/lib/active_merchant/billing/gateways/nmi.rb +30 -9
  58. data/lib/active_merchant/billing/gateways/omise.rb +9 -5
  59. data/lib/active_merchant/billing/gateways/openpay.rb +10 -1
  60. data/lib/active_merchant/billing/gateways/opp.rb +362 -0
  61. data/lib/active_merchant/billing/gateways/orbital.rb +28 -7
  62. data/lib/active_merchant/billing/gateways/pagarme.rb +248 -0
  63. data/lib/active_merchant/billing/gateways/pay_junction_v2.rb +190 -0
  64. data/lib/active_merchant/billing/gateways/payeezy.rb +61 -12
  65. data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +1 -1
  66. data/lib/active_merchant/billing/gateways/payflow.rb +6 -0
  67. data/lib/active_merchant/billing/gateways/payment_express.rb +1 -1
  68. data/lib/active_merchant/billing/gateways/paymill.rb +29 -11
  69. data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +1 -1
  70. data/lib/active_merchant/billing/gateways/paypal_express.rb +1 -6
  71. data/lib/active_merchant/billing/gateways/payu_in.rb +3 -2
  72. data/lib/active_merchant/billing/gateways/payu_latam.rb +402 -0
  73. data/lib/active_merchant/billing/gateways/pin.rb +6 -3
  74. data/lib/active_merchant/billing/gateways/pro_pay.rb +326 -0
  75. data/lib/active_merchant/billing/gateways/psl_card.rb +3 -3
  76. data/lib/active_merchant/billing/gateways/quickpay/quickpay_common.rb +1 -1
  77. data/lib/active_merchant/billing/gateways/quickpay/quickpay_v10.rb +0 -2
  78. data/lib/active_merchant/billing/gateways/quickpay/quickpay_v4to7.rb +1 -1
  79. data/lib/active_merchant/billing/gateways/quickpay.rb +3 -3
  80. data/lib/active_merchant/billing/gateways/qvalent.rb +44 -1
  81. data/lib/active_merchant/billing/gateways/redsys.rb +3 -0
  82. data/lib/active_merchant/billing/gateways/s5.rb +8 -5
  83. data/lib/active_merchant/billing/gateways/safe_charge.rb +220 -0
  84. data/lib/active_merchant/billing/gateways/sage.rb +397 -128
  85. data/lib/active_merchant/billing/gateways/sage_pay.rb +45 -20
  86. data/lib/active_merchant/billing/gateways/secure_net.rb +0 -5
  87. data/lib/active_merchant/billing/gateways/secure_pay.rb +1 -1
  88. data/lib/active_merchant/billing/gateways/secure_pay_au.rb +12 -0
  89. data/lib/active_merchant/billing/gateways/securion_pay.rb +46 -17
  90. data/lib/active_merchant/billing/gateways/stripe.rb +125 -29
  91. data/lib/active_merchant/billing/gateways/telr.rb +275 -0
  92. data/lib/active_merchant/billing/gateways/tns.rb +13 -222
  93. data/lib/active_merchant/billing/gateways/trans_first.rb +40 -16
  94. data/lib/active_merchant/billing/gateways/trans_first_transaction_express.rb +606 -0
  95. data/lib/active_merchant/billing/gateways/usa_epay_advanced.rb +114 -9
  96. data/lib/active_merchant/billing/gateways/vanco.rb +14 -10
  97. data/lib/active_merchant/billing/gateways/visanet_peru.rb +209 -0
  98. data/lib/active_merchant/billing/gateways/wepay.rb +73 -38
  99. data/lib/active_merchant/billing/gateways/wirecard.rb +1 -0
  100. data/lib/active_merchant/billing/gateways/world_net.rb +344 -0
  101. data/lib/active_merchant/billing/gateways/worldpay.rb +48 -16
  102. data/lib/active_merchant/billing/network_tokenization_credit_card.rb +15 -0
  103. data/lib/active_merchant/country.rb +6 -4
  104. data/lib/active_merchant/posts_data.rb +1 -1
  105. data/lib/active_merchant/version.rb +1 -1
  106. metadata +32 -13
  107. data/lib/active_merchant/billing/gateways/app55.rb +0 -176
  108. data/lib/active_merchant/billing/gateways/barclays_epdq.rb +0 -314
  109. data/lib/active_merchant/billing/gateways/certo_direct.rb +0 -278
  110. data/lib/active_merchant/billing/gateways/sage/sage_bankcard.rb +0 -89
  111. data/lib/active_merchant/billing/gateways/sage/sage_core.rb +0 -115
  112. data/lib/active_merchant/billing/gateways/sage/sage_vault.rb +0 -149
  113. data/lib/active_merchant/billing/gateways/sage/sage_virtual_check.rb +0 -97
@@ -0,0 +1,310 @@
1
+ module ActiveMerchant #:nodoc:
2
+ module Billing #:nodoc:
3
+ class CredoraxGateway < Gateway
4
+ class_attribute :test_url, :live_na_url, :live_eu_url
5
+
6
+ self.display_name = "Credorax Gateway"
7
+ self.homepage_url = "https://www.credorax.com/"
8
+
9
+ self.test_url = "https://intconsole.credorax.com/intenv/service/gateway"
10
+
11
+ # The live URL is assigned on a per merchant basis once certification has passed
12
+ # See the Credorax remote tests for the full certification test suite
13
+ #
14
+ # Once you have your assigned subdomain, you can override the live URL in your application via:
15
+ # ActiveMerchant::Billing::CredoraxGateway.live_url = "https://assigned-subdomain.credorax.net/crax_gate/service/gateway"
16
+ self.live_url = 'https://assigned-subdomain.credorax.net/crax_gate/service/gateway'
17
+
18
+ self.supported_countries = %w(DE GB FR IT ES PL NL BE GR CZ PT SE HU RS AT CH BG DK FI SK NO IE HR BA AL LT MK SI LV EE ME LU MT IS AD MC LI SM)
19
+ self.default_currency = "EUR"
20
+ self.money_format = :cents
21
+ self.supported_cardtypes = [:visa, :master, :maestro]
22
+
23
+ RESPONSE_MESSAGES = {
24
+ "00" => "Approved or completed successfully",
25
+ "01" => "Refer to card issuer",
26
+ "02" => "Refer to card issuer special condition",
27
+ "03" => "Invalid merchant",
28
+ "04" => "Pick up card",
29
+ "05" => "Do not Honour",
30
+ "06" => "Invalid Transaction for Terminal",
31
+ "07" => "Pick up card special condition",
32
+ "08" => "Time-Out",
33
+ "09" => "No Original",
34
+ "10" => "Approved for partial amount",
35
+ "11" => "Partial Approval",
36
+ "12" => "Invalid transaction card / issuer / acquirer",
37
+ "13" => "Invalid amount",
38
+ "14" => "Invalid card number",
39
+ "17" => "Invalid Capture date (terminal business date)",
40
+ "19" => "System Error; Re-enter transaction",
41
+ "20" => "No From Account",
42
+ "21" => "No To Account",
43
+ "22" => "No Checking Account",
44
+ "23" => "No Saving Account",
45
+ "24" => "No Credit Account",
46
+ "30" => "Format error",
47
+ "34" => "Implausible card data",
48
+ "39" => "Transaction Not Allowed",
49
+ "41" => "Lost Card, Pickup",
50
+ "42" => "Special Pickup",
51
+ "43" => "Hot Card, Pickup (if possible)",
52
+ "44" => "Pickup Card",
53
+ "51" => "Not sufficient funds",
54
+ "52" => "No checking Account",
55
+ "53" => "No savings account",
56
+ "54" => "Expired card",
57
+ "55" => "Pin incorrect",
58
+ "57" => "Transaction not allowed for cardholder",
59
+ "58" => "Transaction not allowed for merchant",
60
+ "59" => "Suspected Fraud",
61
+ "61" => "Exceeds withdrawal amount limit",
62
+ "62" => "Restricted card",
63
+ "63" => "MAC Key Error",
64
+ "65" => "Activity count limit exceeded",
65
+ "66" => "Exceeds Acquirer Limit",
66
+ "67" => "Retain Card; no reason specified",
67
+ "68" => "Response received too late",
68
+ "75" => "Pin tries exceeded",
69
+ "76" => "Invalid Account",
70
+ "77" => "Issuer Does Not Participate In The Service",
71
+ "78" => "Function Not Available",
72
+ "79" => "Key Validation Error",
73
+ "80" => "Approval for Purchase Amount Only",
74
+ "81" => "Unable to Verify PIN",
75
+ "82" => "Time out at issuer system",
76
+ "83" => "Not declined (Valid for all zero amount transactions)",
77
+ "84" => "Invalid Life Cycle of transaction",
78
+ "85" => "Not declined",
79
+ "86" => "Cannot verify pin",
80
+ "87" => "Purchase amount only, no cashback allowed",
81
+ "88" => "MAC sync Error",
82
+ "89" => "Security Violation",
83
+ "91" => "Issuer not available",
84
+ "92" => "Unable to route at acquirer Module",
85
+ "93" => "Transaction cannot be completed",
86
+ "94" => "Duplicate transaction",
87
+ "95" => "Contact Acquirer",
88
+ "96" => "System malfunction",
89
+ "97" => "No Funds Transfer",
90
+ "98" => "Duplicate Reversal",
91
+ "99" => "Duplicate Transaction",
92
+ "N3" => "Cash Service Not Available",
93
+ "N4" => "Cash Back Request Exceeds Issuer Limit",
94
+ "N7" => "N7 (visa), Decline CVV2 failure",
95
+ "R0" => "Stop Payment Order",
96
+ "R1" => "Revocation of Authorisation Order",
97
+ "R3" => "Revocation of all Authorisations Order"
98
+ }
99
+
100
+ def initialize(options={})
101
+ requires!(options, :merchant_id, :cipher_key)
102
+ super
103
+ end
104
+
105
+ def purchase(amount, payment_method, options={})
106
+ post = {}
107
+ add_invoice(post, amount, options)
108
+ add_payment_method(post, payment_method)
109
+ add_customer_data(post, options)
110
+ add_email(post, options)
111
+ add_echo(post, options)
112
+
113
+ commit(:purchase, post)
114
+ end
115
+
116
+ def authorize(amount, payment_method, options={})
117
+ post = {}
118
+ add_invoice(post, amount, options)
119
+ add_payment_method(post, payment_method)
120
+ add_customer_data(post, options)
121
+ add_email(post, options)
122
+ add_echo(post, options)
123
+
124
+ commit(:authorize, post)
125
+ end
126
+
127
+ def capture(amount, authorization, options={})
128
+ post = {}
129
+ add_invoice(post, amount, options)
130
+ add_reference(post, authorization)
131
+ add_customer_data(post, options)
132
+ add_echo(post, options)
133
+
134
+ commit(:capture, post)
135
+ end
136
+
137
+ def void(authorization, options={})
138
+ post = {}
139
+ add_customer_data(post, options)
140
+ reference_action = add_reference(post, authorization)
141
+ add_echo(post, options)
142
+ post[:a1] = generate_unique_id
143
+
144
+ commit(:void, post, reference_action)
145
+ end
146
+
147
+ def refund(amount, authorization, options={})
148
+ post = {}
149
+ add_invoice(post, amount, options)
150
+ add_reference(post, authorization)
151
+ add_customer_data(post, options)
152
+ add_echo(post, options)
153
+
154
+ commit(:refund, post)
155
+ end
156
+
157
+ def credit(amount, payment_method, options={})
158
+ post = {}
159
+ add_invoice(post, amount, options)
160
+ add_payment_method(post, payment_method)
161
+ add_customer_data(post, options)
162
+ add_email(post, options)
163
+ add_echo(post, options)
164
+
165
+ commit(:credit, post)
166
+ end
167
+
168
+ def verify(credit_card, options={})
169
+ MultiResponse.run(:use_first_response) do |r|
170
+ r.process { authorize(100, credit_card, options) }
171
+ r.process(:ignore_result) { void(r.authorization, options) }
172
+ end
173
+ end
174
+
175
+ def supports_scrubbing?
176
+ true
177
+ end
178
+
179
+ def scrub(transcript)
180
+ transcript.
181
+ gsub(%r((b1=)\d+), '\1[FILTERED]').
182
+ gsub(%r((b5=)\d+), '\1[FILTERED]')
183
+ end
184
+
185
+ private
186
+
187
+ def add_invoice(post, money, options)
188
+ post[:a4] = amount(money)
189
+ post[:a1] = generate_unique_id
190
+ post[:a5] = options[:currency] || currency(money)
191
+ post[:h9] = options[:order_id]
192
+ end
193
+
194
+ CARD_TYPES = {
195
+ "visa" => '1',
196
+ "mastercard" => '2',
197
+ "maestro" => '9'
198
+ }
199
+
200
+ def add_payment_method(post, payment_method)
201
+ post[:c1] = payment_method.name
202
+ post[:b2] = CARD_TYPES[payment_method.brand] || ''
203
+ post[:b1] = payment_method.number
204
+ post[:b5] = payment_method.verification_value
205
+ post[:b4] = format(payment_method.year, :two_digits)
206
+ post[:b3] = format(payment_method.month, :two_digits)
207
+ end
208
+
209
+ def add_customer_data(post, options)
210
+ post[:d1] = options[:ip] || '127.0.0.1'
211
+ if (billing_address = options[:billing_address])
212
+ post[:c5] = billing_address[:address1]
213
+ post[:c7] = billing_address[:city]
214
+ post[:c10] = billing_address[:zip]
215
+ post[:c8] = billing_address[:state]
216
+ post[:c9] = billing_address[:country]
217
+ post[:c2] = billing_address[:phone]
218
+ end
219
+ end
220
+
221
+ def add_reference(post, authorization)
222
+ response_id, authorization_code, request_id, action = authorization.split(";")
223
+ post[:g2] = response_id
224
+ post[:g3] = authorization_code
225
+ post[:g4] = request_id
226
+ action || :authorize
227
+ end
228
+
229
+ def add_email(post, options)
230
+ post[:c3] = options[:email] || 'unspecified@example.com'
231
+ end
232
+
233
+ def add_echo(post, options)
234
+ # The d2 parameter is used during the certification process
235
+ # See remote tests for full certification test suite
236
+ post[:d2] = options[:echo] unless options[:echo].blank?
237
+ end
238
+
239
+ ACTIONS = {
240
+ purchase: '1',
241
+ authorize: '2',
242
+ capture: '3',
243
+ authorize_void:'4',
244
+ refund: '5',
245
+ credit: '6',
246
+ purchase_void: '7',
247
+ refund_void: '8',
248
+ capture_void: '9'
249
+ }
250
+
251
+ def commit(action, params, reference_action = nil)
252
+ raw_response = ssl_post(url, post_data(action, params, reference_action))
253
+ response = parse(raw_response)
254
+
255
+ Response.new(
256
+ success_from(response),
257
+ message_from(response),
258
+ response,
259
+ authorization: "#{response["Z1"]};#{response["Z4"]};#{response["A1"]};#{action}",
260
+ avs_result: AVSResult.new(code: response["Z9"]),
261
+ cvv_result: CVVResult.new(response["Z14"]),
262
+ test: test?
263
+ )
264
+ end
265
+
266
+ def sign_request(params)
267
+ params = params.sort
268
+ params.each { |param| param[1].gsub!(/[<>()\\]/, ' ') }
269
+ values = params.map { |param| param[1].strip }
270
+ Digest::MD5.hexdigest(values.join + @options[:cipher_key])
271
+ end
272
+
273
+ def post_data(action, params, reference_action)
274
+ params.keys.each { |key| params[key] = params[key].to_s}
275
+ params[:M] = @options[:merchant_id]
276
+ params[:O] = request_action(action, reference_action)
277
+ params[:K] = sign_request(params)
278
+ params.map {|k, v| "#{k}=#{CGI.escape(v.to_s)}"}.join('&')
279
+ end
280
+
281
+ def request_action(action, reference_action)
282
+ if reference_action
283
+ ACTIONS["#{reference_action}_#{action}".to_sym]
284
+ else
285
+ ACTIONS[action]
286
+ end
287
+ end
288
+
289
+ def url
290
+ test? ? test_url : live_url
291
+ end
292
+
293
+ def parse(body)
294
+ Hash[CGI::parse(body).map{|k,v| [k.upcase,v.first]}]
295
+ end
296
+
297
+ def success_from(response)
298
+ response["Z2"] == "0"
299
+ end
300
+
301
+ def message_from(response)
302
+ if success_from(response)
303
+ "Succeeded"
304
+ else
305
+ RESPONSE_MESSAGES[response["Z6"]] || response["Z3"] || "Unable to read error message"
306
+ end
307
+ end
308
+ end
309
+ end
310
+ end
@@ -0,0 +1,279 @@
1
+ require 'digest/md5'
2
+
3
+ module ActiveMerchant #:nodoc:
4
+ module Billing #:nodoc:
5
+ # Important note:
6
+ # ===
7
+ # Culqi merchant accounts are configured for either purchase or auth/capture
8
+ # modes. This is configured by Culqi when setting up a merchant account and
9
+ # largely depends on the transaction acquiring bank. Be sure to understand how
10
+ # your account was configured prior to using this gateway.
11
+ class CulqiGateway < Gateway
12
+ self.display_name = "Culqi"
13
+ self.homepage_url = "https://www.culqi.com"
14
+
15
+ self.test_url = "https://staging.paymentz.com/transaction/"
16
+ self.live_url = "https://secure.culqi.com/transaction/"
17
+
18
+ self.supported_countries = ["PE"]
19
+ self.default_currency = "PEN"
20
+ self.money_format = :dollars
21
+ self.supported_cardtypes = [:visa, :master, :diners_club, :american_express]
22
+
23
+ def initialize(options={})
24
+ requires!(options, :merchant_id, :terminal_id, :secret_key)
25
+ super
26
+ end
27
+
28
+ def purchase(amount, payment_method, options={})
29
+ authorize(amount, payment_method, options)
30
+ end
31
+
32
+ def authorize(amount, payment_method, options={})
33
+ if payment_method.is_a?(String)
34
+ action = :tokenpay
35
+ else
36
+ action = :authorize
37
+ end
38
+ post = {}
39
+ add_credentials(post)
40
+ add_invoice(action, post, amount, options)
41
+ add_payment_method(post, payment_method, action, options)
42
+ add_customer_data(post, options)
43
+ add_checksum(action, post)
44
+
45
+ commit(action, post)
46
+ end
47
+
48
+ def capture(amount, authorization, options={})
49
+ action = :capture
50
+ post = {}
51
+ add_credentials(post)
52
+ add_invoice(action, post, amount, options)
53
+ add_reference(post, authorization)
54
+ add_checksum(action, post)
55
+
56
+ commit(action, post)
57
+ end
58
+
59
+ def void(authorization, options={})
60
+ action = :void
61
+ post = {}
62
+ add_credentials(post)
63
+ add_invoice(action, post, nil, options)
64
+ add_reference(post, authorization)
65
+ add_checksum(action, post)
66
+
67
+ commit(action, post)
68
+ end
69
+
70
+ def refund(amount, authorization, options={})
71
+ action = :refund
72
+ post = {}
73
+ add_credentials(post)
74
+ add_invoice(action, post, amount, options)
75
+ add_reference(post, authorization)
76
+ add_checksum(action, post)
77
+
78
+ commit(action, post)
79
+ end
80
+
81
+ def verify(credit_card, options={})
82
+ MultiResponse.run(:use_first_response) do |r|
83
+ r.process { authorize(1000, credit_card, options) }
84
+ r.process(:ignore_result) { void(r.authorization, options) }
85
+ end
86
+ end
87
+
88
+ def verify_credentials
89
+ response = void("0", order_id: "0")
90
+ response.message.include? "Transaction not found"
91
+ end
92
+
93
+ def store(credit_card, options={})
94
+ action = :tokenize
95
+ post = {}
96
+ post[:partnerid] = options[:partner_id] if options[:partner_id]
97
+ post[:cardholderid] = options[:cardholder_id] if options[:cardholder_id]
98
+ add_credentials(post)
99
+ add_payment_method(post, credit_card, action, options)
100
+ add_customer_data(post, options)
101
+ add_checksum(action, post)
102
+
103
+ commit(action, post)
104
+ end
105
+
106
+ def invalidate(authorization, options={})
107
+ action = :invalidate
108
+ post = {}
109
+ post[:partnerid] = options[:partner_id] if options[:partner_id]
110
+ add_credentials(post)
111
+ post[:token] = authorization
112
+ add_checksum(action, post)
113
+
114
+ commit(action, post)
115
+ end
116
+
117
+ def supports_scrubbing?
118
+ true
119
+ end
120
+
121
+ def scrub(transcript)
122
+ transcript.
123
+ gsub(%r((cardnumber=)\d+), '\1[FILTERED]').
124
+ gsub(%r((cvv=)\d+), '\1[FILTERED]')
125
+ end
126
+
127
+ private
128
+
129
+ def add_credentials(post)
130
+ post[:toid] = @options[:merchant_id]
131
+ post[:totype] = 'Culqi'
132
+ post[:terminalid] = @options[:terminal_id]
133
+ post[:language] = 'ENG'
134
+ end
135
+
136
+ def add_invoice(action, post, money, options)
137
+ case action
138
+ when :capture
139
+ post[:captureamount] = amount(money)
140
+ when :refund
141
+ post[:refundamount] = amount(money)
142
+ post[:reason] = 'none'
143
+ else
144
+ post[:amount] = amount(money)
145
+ end
146
+
147
+ post[:description] = options[:order_id]
148
+ post[:redirecturl] = options[:redirect_url] || 'http://www.example.com'
149
+ end
150
+
151
+ def add_payment_method(post, payment_method, action, options)
152
+ if payment_method.is_a?(String)
153
+ post[:token] = payment_method
154
+ post[:cvv] = options[:cvv] if options[:cvv]
155
+ else
156
+ post[:cardnumber] = payment_method.number
157
+ post[:cvv] = payment_method.verification_value
158
+ post[:firstname], post[:lastname] = payment_method.name.split(' ')
159
+ if action == :tokenize
160
+ post[:expirymonth] = format(payment_method.month, :two_digits)
161
+ post[:expiryyear] = format(payment_method.year, :four_digits)
162
+ else
163
+ post[:expiry_month] = format(payment_method.month, :two_digits)
164
+ post[:expiry_year] = format(payment_method.year, :four_digits)
165
+ end
166
+ end
167
+ end
168
+
169
+ def add_customer_data(post, options)
170
+ post[:emailaddr] = options[:email] || 'unspecified@example.com'
171
+ if (billing_address = options[:billing_address] || options[:address])
172
+ post[:street] = [billing_address[:address1], billing_address[:address2]].join(' ')
173
+ post[:city] = billing_address[:city]
174
+ post[:state] = billing_address[:state]
175
+ post[:countrycode] = billing_address[:country]
176
+ post[:zip] = billing_address[:zip]
177
+ post[:telno] = billing_address[:phone]
178
+ post[:telnocc] = options[:telephone_country_code] || '051'
179
+ end
180
+ end
181
+
182
+ def add_checksum(action, post)
183
+ checksum_elements = case action
184
+ when :capture; [post[:toid], post[:trackingid], post[:captureamount], @options[:secret_key]]
185
+ when :void; [post[:toid], post[:description], post[:trackingid], @options[:secret_key]]
186
+ when :refund; [post[:toid], post[:trackingid], post[:refundamount], @options[:secret_key]]
187
+ when :tokenize; [post[:partnerid], post[:cardnumber], post[:cvv], @options[:secret_key]]
188
+ when :invalidate; [post[:partnerid], post[:token], @options[:secret_key]]
189
+ else [post[:toid], post[:totype], post[:amount], post[:description], post[:redirecturl],
190
+ post[:cardnumber] || post[:token], @options[:secret_key]]
191
+ end
192
+
193
+ post[:checksum] = Digest::MD5.hexdigest(checksum_elements.compact.join('|'))
194
+ end
195
+
196
+ def add_reference(post, authorization)
197
+ post[:trackingid] = authorization
198
+ end
199
+
200
+ ACTIONS = {
201
+ authorize: "SingleCallGenericServlet",
202
+ capture: "SingleCallGenericCaptureServlet",
203
+ void: "SingleCallGenericVoid",
204
+ refund: "SingleCallGenericReverse",
205
+ tokenize: "SingleCallTokenServlet",
206
+ invalidate: "SingleCallInvalidateToken",
207
+ tokenpay: "SingleCallTokenTransaction",
208
+ }
209
+
210
+ def commit(action, params)
211
+ response = begin
212
+ parse(ssl_post(url + ACTIONS[action], post_data(action, params), headers))
213
+ rescue ResponseError => e
214
+ parse(e.response.body)
215
+ end
216
+
217
+ success = success_from(response)
218
+
219
+ Response.new(
220
+ success,
221
+ message_from(response),
222
+ response,
223
+ authorization: success ? authorization_from(response) : nil,
224
+ cvv_result: success ? cvvresult_from(response) : nil,
225
+ error_code: success ? nil : error_from(response),
226
+ test: test?
227
+ )
228
+ end
229
+
230
+ def headers
231
+ {
232
+ "Accept" => "application/json",
233
+ "Content-Type" => "application/x-www-form-urlencoded;charset=UTF-8"
234
+ }
235
+ end
236
+
237
+ def post_data(action, params)
238
+ params.map {|k, v| "#{k}=#{CGI.escape(v.to_s)}"}.join('&')
239
+ end
240
+
241
+ def url
242
+ test? ? test_url : live_url
243
+ end
244
+
245
+ def parse(body)
246
+ begin
247
+ JSON.parse(body)
248
+ rescue JSON::ParserError
249
+ message = "Invalid JSON response received from CulqiGateway. Please contact CulqiGateway if you continue to receive this message."
250
+ message += "(The raw response returned by the API was #{body.inspect})"
251
+ {
252
+ "status" => "N",
253
+ "statusdescription" => message
254
+ }
255
+ end
256
+ end
257
+
258
+ def success_from(response)
259
+ response['status'] == 'Y'
260
+ end
261
+
262
+ def message_from(response)
263
+ response['statusdescription'] || response['statusDescription']
264
+ end
265
+
266
+ def authorization_from(response)
267
+ response['trackingid'] || response['token']
268
+ end
269
+
270
+ def cvvresult_from(response)
271
+ CVVResult.new(response['cvvresult'])
272
+ end
273
+
274
+ def error_from(response)
275
+ response['resultcode']
276
+ end
277
+ end
278
+ end
279
+ end