bitfluent-activemerchant 1.5.1.1 → 1.15.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. data/CHANGELOG +168 -0
  2. data/CONTRIBUTORS +96 -1
  3. data/README.rdoc +33 -5
  4. data/lib/active_merchant.rb +12 -0
  5. data/lib/active_merchant/billing/credit_card.rb +59 -46
  6. data/lib/active_merchant/billing/credit_card_methods.rb +3 -3
  7. data/lib/active_merchant/billing/gateway.rb +16 -9
  8. data/lib/active_merchant/billing/gateways/authorize_net.rb +19 -9
  9. data/lib/active_merchant/billing/gateways/authorize_net_cim.rb +134 -12
  10. data/lib/active_merchant/billing/gateways/barclays_epdq.rb +309 -0
  11. data/lib/active_merchant/billing/gateways/beanstream.rb +39 -2
  12. data/lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb +64 -26
  13. data/lib/active_merchant/billing/gateways/blue_pay.rb +11 -0
  14. data/lib/active_merchant/billing/gateways/bogus.rb +33 -3
  15. data/lib/active_merchant/billing/gateways/braintree.rb +11 -11
  16. data/lib/active_merchant/billing/gateways/braintree/braintree_common.rb +9 -0
  17. data/lib/active_merchant/billing/gateways/braintree_blue.rb +293 -0
  18. data/lib/active_merchant/billing/gateways/braintree_orange.rb +17 -0
  19. data/lib/active_merchant/billing/gateways/cyber_source.rb +5 -1
  20. data/lib/active_merchant/billing/gateways/data_cash.rb +6 -2
  21. data/lib/active_merchant/billing/gateways/efsnet.rb +8 -2
  22. data/lib/active_merchant/billing/gateways/epay.rb +268 -0
  23. data/lib/active_merchant/billing/gateways/eway_managed.rb +231 -0
  24. data/lib/active_merchant/billing/gateways/federated_canada.rb +168 -0
  25. data/lib/active_merchant/billing/gateways/first_pay.rb +8 -3
  26. data/lib/active_merchant/billing/gateways/garanti.rb +132 -92
  27. data/lib/active_merchant/billing/gateways/ideal/ideal_base.rb +250 -0
  28. data/lib/active_merchant/billing/gateways/ideal/ideal_rabobank.pem +13 -0
  29. data/lib/active_merchant/billing/gateways/ideal/ideal_response.rb +29 -0
  30. data/lib/active_merchant/billing/gateways/ideal_rabobank.rb +55 -0
  31. data/lib/active_merchant/billing/gateways/inspire.rb +221 -0
  32. data/lib/active_merchant/billing/gateways/iridium.rb +258 -0
  33. data/lib/active_merchant/billing/gateways/jetpay.rb +12 -6
  34. data/lib/active_merchant/billing/gateways/linkpoint.rb +6 -1
  35. data/lib/active_merchant/billing/gateways/merchant_e_solutions.rb +10 -8
  36. data/lib/active_merchant/billing/gateways/merchant_ware.rb +7 -1
  37. data/lib/active_merchant/billing/gateways/moneris.rb +6 -2
  38. data/lib/active_merchant/billing/gateways/netaxept.rb +239 -0
  39. data/lib/active_merchant/billing/gateways/nmi.rb +13 -0
  40. data/lib/active_merchant/billing/gateways/ogone.rb +16 -3
  41. data/lib/active_merchant/billing/gateways/orbital.rb +317 -0
  42. data/lib/active_merchant/billing/gateways/orbital/orbital_soft_descriptors.rb +46 -0
  43. data/lib/active_merchant/billing/gateways/pay_junction.rb +9 -9
  44. data/lib/active_merchant/billing/gateways/paybox_direct.rb +207 -0
  45. data/lib/active_merchant/billing/gateways/payflow.rb +26 -9
  46. data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +11 -11
  47. data/lib/active_merchant/billing/gateways/payflow_express.rb +122 -38
  48. data/lib/active_merchant/billing/gateways/payment_express.rb +7 -2
  49. data/lib/active_merchant/billing/gateways/paypal.rb +5 -5
  50. data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +33 -8
  51. data/lib/active_merchant/billing/gateways/paypal/paypal_express_response.rb +26 -15
  52. data/lib/active_merchant/billing/gateways/paypal_ca.rb +1 -1
  53. data/lib/active_merchant/billing/gateways/paypal_express.rb +55 -13
  54. data/lib/active_merchant/billing/gateways/paypal_express_common.rb +8 -3
  55. data/lib/active_merchant/billing/gateways/plugnpay.rb +9 -3
  56. data/lib/active_merchant/billing/gateways/psigate.rb +5 -0
  57. data/lib/active_merchant/billing/gateways/qbms.rb +295 -0
  58. data/lib/active_merchant/billing/gateways/quantum.rb +282 -0
  59. data/lib/active_merchant/billing/gateways/quickpay.rb +7 -2
  60. data/lib/active_merchant/billing/gateways/realex.rb +187 -76
  61. data/lib/active_merchant/billing/gateways/sage_pay.rb +16 -5
  62. data/lib/active_merchant/billing/gateways/secure_net.rb +330 -0
  63. data/lib/active_merchant/billing/gateways/secure_pay_au.rb +39 -3
  64. data/lib/active_merchant/billing/gateways/smart_ps.rb +9 -3
  65. data/lib/active_merchant/billing/gateways/trust_commerce.rb +7 -2
  66. data/lib/active_merchant/billing/gateways/usa_epay.rb +1 -1
  67. data/lib/active_merchant/billing/gateways/verifi.rb +6 -1
  68. data/lib/active_merchant/billing/gateways/viaklix.rb +1 -1
  69. data/lib/active_merchant/billing/gateways/worldpay.rb +280 -0
  70. data/lib/active_merchant/billing/integrations.rb +0 -12
  71. data/lib/active_merchant/billing/integrations/action_view_helper.rb +13 -24
  72. data/lib/active_merchant/billing/integrations/bogus.rb +2 -2
  73. data/lib/active_merchant/billing/integrations/chronopay.rb +2 -2
  74. data/lib/active_merchant/billing/integrations/direc_pay.rb +41 -0
  75. data/lib/active_merchant/billing/integrations/direc_pay/helper.rb +200 -0
  76. data/lib/active_merchant/billing/integrations/direc_pay/notification.rb +76 -0
  77. data/lib/active_merchant/billing/integrations/direc_pay/return.rb +32 -0
  78. data/lib/active_merchant/billing/integrations/direc_pay/status.rb +37 -0
  79. data/lib/active_merchant/billing/integrations/directebanking.rb +47 -0
  80. data/lib/active_merchant/billing/integrations/directebanking/helper.rb +90 -0
  81. data/lib/active_merchant/billing/integrations/directebanking/notification.rb +120 -0
  82. data/lib/active_merchant/billing/integrations/directebanking/return.rb +11 -0
  83. data/lib/active_merchant/billing/integrations/gestpay.rb +2 -2
  84. data/lib/active_merchant/billing/integrations/helper.rb +14 -11
  85. data/lib/active_merchant/billing/integrations/hi_trust.rb +2 -2
  86. data/lib/active_merchant/billing/integrations/ipay88.rb +4 -4
  87. data/lib/active_merchant/billing/integrations/moneybookers.rb +26 -0
  88. data/lib/active_merchant/billing/integrations/moneybookers/helper.rb +59 -0
  89. data/lib/active_merchant/billing/integrations/moneybookers/notification.rb +129 -0
  90. data/lib/active_merchant/billing/integrations/nochex.rb +2 -2
  91. data/lib/active_merchant/billing/integrations/notification.rb +1 -1
  92. data/lib/active_merchant/billing/integrations/paypal.rb +2 -2
  93. data/lib/active_merchant/billing/integrations/quickpay.rb +6 -2
  94. data/lib/active_merchant/billing/integrations/quickpay/helper.rb +1 -1
  95. data/lib/active_merchant/billing/integrations/quickpay/notification.rb +2 -2
  96. data/lib/active_merchant/billing/integrations/return.rb +10 -3
  97. data/lib/active_merchant/billing/integrations/sage_pay_form.rb +37 -0
  98. data/lib/active_merchant/billing/integrations/sage_pay_form/encryption.rb +33 -0
  99. data/lib/active_merchant/billing/integrations/sage_pay_form/helper.rb +111 -0
  100. data/lib/active_merchant/billing/integrations/sage_pay_form/notification.rb +210 -0
  101. data/lib/active_merchant/billing/integrations/sage_pay_form/return.rb +31 -0
  102. data/lib/active_merchant/billing/integrations/two_checkout.rb +2 -2
  103. data/lib/active_merchant/billing/integrations/two_checkout/notification.rb +5 -5
  104. data/lib/active_merchant/billing/integrations/valitor.rb +33 -0
  105. data/lib/active_merchant/billing/integrations/valitor/helper.rb +86 -0
  106. data/lib/active_merchant/billing/integrations/valitor/notification.rb +13 -0
  107. data/lib/active_merchant/billing/integrations/valitor/response_fields.rb +88 -0
  108. data/lib/active_merchant/billing/integrations/valitor/return.rb +13 -0
  109. data/lib/active_merchant/billing/integrations/world_pay.rb +27 -0
  110. data/lib/active_merchant/billing/integrations/world_pay/helper.rb +100 -0
  111. data/lib/active_merchant/billing/integrations/world_pay/notification.rb +160 -0
  112. data/lib/active_merchant/common.rb +1 -1
  113. data/lib/active_merchant/common/connection.rb +13 -8
  114. data/lib/active_merchant/common/country.rb +15 -6
  115. data/lib/active_merchant/common/post_data.rb +1 -1
  116. data/lib/active_merchant/common/posts_data.rb +21 -5
  117. data/lib/active_merchant/common/utils.rb +4 -0
  118. data/lib/active_merchant/common/validateable.rb +20 -15
  119. data/lib/active_merchant/version.rb +3 -0
  120. data/lib/support/gateway_support.rb +1 -1
  121. metadata +65 -27
@@ -0,0 +1,282 @@
1
+ module ActiveMerchant #:nodoc:
2
+ module Billing #:nodoc:
3
+ # ActiveMerchant Implementation for Quantum Gateway XML Requester Service
4
+ # Based on API Doc from 8/6/2009
5
+ #
6
+ # Important Notes
7
+ # * Support is included for a customer id via the :customer option, invoice number via :invoice option, invoice description via :merchant option and memo via :description option
8
+ # * You can force email of receipt with :email_receipt => true
9
+ # * You can force email of merchant receipt with :merchant_receipt => true
10
+ # * You can exclude CVV with :ignore_cvv => true
11
+ # * All transactions use dollar values.
12
+ class QuantumGateway < Gateway
13
+ LIVE_URL = 'https://secure.quantumgateway.com/cgi/xml_requester.php'
14
+
15
+ # visa, master, american_express, discover
16
+ self.supported_cardtypes = [:visa, :master, :american_express, :discover]
17
+ self.supported_countries = ['US']
18
+ self.default_currency = 'USD'
19
+ self.money_format = :dollars
20
+ self.homepage_url = 'http://www.quantumgateway.com'
21
+ self.display_name = 'Quantum Gateway'
22
+
23
+ # These are the options that can be used when creating a new Quantum Gateway object.
24
+ #
25
+ # :login => Your Quantum Gateway Gateway ID
26
+ #
27
+ # :password => Your Quantum Gateway Vault Key or Restrict Key
28
+ #
29
+ # NOTE: For testing supply your test GatewayLogin and GatewayKey
30
+ #
31
+ # :email_receipt => true if you want a receipt sent to the customer (false be default)
32
+ #
33
+ # :merchant_receipt => true if you want to override receiving the merchant receipt
34
+ #
35
+ # :ignore_avs => true ignore both AVS and CVV verification
36
+ # :ignore_cvv => true don't want to use CVV so continue processing even if CVV would have failed
37
+ #
38
+ def initialize(options = {})
39
+ requires!(options, :login, :password)
40
+ @options = options
41
+ super
42
+ end
43
+
44
+ # Should run against the test servers or not?
45
+ def test?
46
+ @options[:test] || Base.gateway_mode == :test
47
+ end
48
+
49
+ # Request an authorization for an amount from CyberSource
50
+ #
51
+ def authorize(money, creditcard, options = {})
52
+ setup_address_hash(options)
53
+ commit(build_auth_request(money, creditcard, options), options )
54
+ end
55
+
56
+ # Capture an authorization that has previously been requested
57
+ def capture(money, authorization, options = {})
58
+ setup_address_hash(options)
59
+ commit(build_capture_request(money, authorization, options), options)
60
+ end
61
+
62
+ # Purchase is an auth followed by a capture
63
+ # You must supply an order_id in the options hash
64
+ def purchase(money, creditcard, options = {})
65
+ setup_address_hash(options)
66
+ commit(build_purchase_request(money, creditcard, options), options)
67
+ end
68
+
69
+ def void(identification, options = {})
70
+ commit(build_void_request(identification, options), options)
71
+ end
72
+
73
+ def refund(money, identification, options = {})
74
+ commit(build_credit_request(money, identification, options), options)
75
+ end
76
+
77
+ def credit(money, identification, options = {})
78
+ deprecated CREDIT_DEPRECATION_MESSAGE
79
+ refund(money, identification, options)
80
+ end
81
+
82
+ private
83
+
84
+ def setup_address_hash(options)
85
+ options[:billing_address] = options[:billing_address] || options[:address] || {}
86
+ end
87
+
88
+ def build_auth_request(money, creditcard, options)
89
+ xml = Builder::XmlMarkup.new
90
+ add_common_credit_card_info(xml,'AUTH_ONLY')
91
+ add_purchase_data(xml, money)
92
+ add_creditcard(xml, creditcard)
93
+ add_address(xml, creditcard, options[:billing_address], options)
94
+ add_invoice_details(xml, options)
95
+ add_customer_details(xml, options)
96
+ add_memo(xml, options)
97
+ add_business_rules_data(xml)
98
+ xml.target!
99
+ end
100
+
101
+ def build_capture_request(money, authorization, options)
102
+ xml = Builder::XmlMarkup.new
103
+ add_common_credit_card_info(xml,'PREVIOUS_SALE')
104
+ transaction_id, _ = authorization_parts_from(authorization)
105
+ add_transaction_id(xml, transaction_id)
106
+ xml.target!
107
+ end
108
+
109
+ def build_purchase_request(money, creditcard, options)
110
+ xml = Builder::XmlMarkup.new
111
+ add_common_credit_card_info(xml, @options[:ignore_avs] || @options[:ignore_cvv] ? 'SALES' : 'AUTH_CAPTURE')
112
+ add_address(xml, creditcard, options[:billing_address], options)
113
+ add_purchase_data(xml, money)
114
+ add_creditcard(xml, creditcard)
115
+ add_invoice_details(xml, options)
116
+ add_customer_details(xml, options)
117
+ add_memo(xml, options)
118
+ add_business_rules_data(xml)
119
+ xml.target!
120
+ end
121
+
122
+ def build_void_request(authorization, options)
123
+ xml = Builder::XmlMarkup.new
124
+ add_common_credit_card_info(xml,'VOID')
125
+ transaction_id, _ = authorization_parts_from(authorization)
126
+ add_transaction_id(xml, transaction_id)
127
+ xml.target!
128
+ end
129
+
130
+ def build_credit_request(money, authorization, options)
131
+ xml = Builder::XmlMarkup.new
132
+ add_common_credit_card_info(xml,'RETURN')
133
+ add_purchase_data(xml, money)
134
+ transaction_id, cc = authorization_parts_from(authorization)
135
+ add_transaction_id(xml, transaction_id)
136
+ xml.tag! 'CreditCardNumber', cc
137
+ xml.target!
138
+ end
139
+
140
+ def add_common_credit_card_info(xml, process_type)
141
+ xml.tag! 'RequestType', 'ProcessSingleTransaction'
142
+ xml.tag! 'TransactionType', 'CREDIT'
143
+ xml.tag! 'PaymentType', 'CC'
144
+ xml.tag! 'ProcessType', process_type
145
+ end
146
+
147
+ def add_business_rules_data(xml)
148
+ xml.tag!('CustomerEmail', @options[:email_receipt] ? 'Y' : 'N')
149
+ xml.tag!('MerchantEmail', @options[:merchant_receipt] ? 'Y' : 'N')
150
+ end
151
+
152
+ def add_invoice_details(xml, options)
153
+ xml.tag! 'InvoiceNumber', options[:invoice]
154
+ xml.tag! 'InvoiceDescription', options[:merchant]
155
+ end
156
+
157
+ def add_customer_details(xml, options)
158
+ xml.tag! 'CustomerID', options[:customer]
159
+ end
160
+
161
+ def add_transaction_id(xml, transaction_id)
162
+ xml.tag! 'TransactionID', transaction_id
163
+ end
164
+
165
+ def add_memo(xml, options)
166
+ xml.tag! 'Memo', options[:description]
167
+ end
168
+
169
+ def add_purchase_data(xml, money = 0)
170
+ xml.tag! 'Amount', amount(money)
171
+ xml.tag! 'TransactionDate', Time.now
172
+ end
173
+
174
+ def add_address(xml, creditcard, address, options, shipTo = false)
175
+ xml.tag! 'FirstName', creditcard.first_name
176
+ xml.tag! 'LastName', creditcard.last_name
177
+ xml.tag! 'Address', address[:address1] # => there is no support for address2 in quantum
178
+ xml.tag! 'City', address[:city]
179
+ xml.tag! 'State', address[:state]
180
+ xml.tag! 'ZipCode', address[:zip]
181
+ xml.tag! 'Country', address[:country]
182
+ xml.tag! 'EmailAddress', options[:email]
183
+ xml.tag! 'IPAddress', options[:ip]
184
+ end
185
+
186
+ def add_creditcard(xml, creditcard)
187
+ xml.tag! 'PaymentType', 'CC'
188
+ xml.tag! 'CreditCardNumber', creditcard.number
189
+ xml.tag! 'ExpireMonth', format(creditcard.month, :two_digits)
190
+ xml.tag! 'ExpireYear', format(creditcard.year, :four_digits)
191
+ xml.tag!('CVV2', creditcard.verification_value) unless (@options[:ignore_cvv] || creditcard.verification_value.blank? )
192
+ end
193
+
194
+ # Where we actually build the full SOAP request using builder
195
+ def build_request(body, options)
196
+ xml = Builder::XmlMarkup.new
197
+ xml.instruct!
198
+ xml.tag! 'QGWRequest' do
199
+ xml.tag! 'Authentication' do
200
+ xml.tag! 'GatewayLogin', @options[:login]
201
+ xml.tag! 'GatewayKey', @options[:password]
202
+ end
203
+ xml.tag! 'Request' do
204
+ xml << body
205
+ end
206
+ end
207
+ xml.target!
208
+ end
209
+
210
+ # Contact CyberSource, make the SOAP request, and parse the reply into a Response object
211
+ def commit(request, options)
212
+ headers = { 'Content-Type' => 'text/xml' }
213
+ response = parse(ssl_post(LIVE_URL, build_request(request, options), headers))
214
+
215
+ success = response[:request_status] == "Success"
216
+ message = response[:request_message]
217
+
218
+ if success # => checking for connectivity success first
219
+ success = %w(APPROVED FORCED VOIDED).include?(response[:Status])
220
+ message = response[:StatusDescription]
221
+ authorization = success ? authorization_for(response) : nil
222
+ end
223
+
224
+ Response.new(success, message, response,
225
+ :test => test?,
226
+ :authorization => authorization,
227
+ :avs_result => { :code => response[:AVSResponseCode] },
228
+ :cvv_result => response[:CVV2ResponseCode]
229
+ )
230
+ end
231
+
232
+ # Parse the SOAP response
233
+ # Technique inspired by the Paypal Gateway
234
+ def parse(xml)
235
+ reply = {}
236
+
237
+ begin
238
+ xml = REXML::Document.new(xml)
239
+
240
+ root = REXML::XPath.first(xml, "//QGWRequest/ResponseSummary")
241
+ parse_element(reply, root)
242
+ reply[:request_status] = reply[:Status]
243
+ reply[:request_message] = "#{reply[:Status]}: #{reply[:StatusDescription]}"
244
+
245
+ if root = REXML::XPath.first(xml, "//QGWRequest/Result")
246
+ root.elements.to_a.each do |node|
247
+ parse_element(reply, node)
248
+ end
249
+ end
250
+ rescue Exception => e
251
+ reply[:request_status] = 'Failure'
252
+ reply[:request_message] = "Failure: There was a problem parsing the response XML"
253
+ end
254
+
255
+ return reply
256
+ end
257
+
258
+ def parse_element(reply, node)
259
+ if node.has_elements?
260
+ node.elements.each{|e| parse_element(reply, e) }
261
+ else
262
+ if node.parent.name =~ /item/
263
+ parent = node.parent.name + (node.parent.attributes["id"] ? "_" + node.parent.attributes["id"] : '')
264
+ reply[(parent + '_' + node.name).to_sym] = node.text
265
+ else
266
+ reply[node.name.to_sym] = node.text
267
+ end
268
+ end
269
+ return reply
270
+ end
271
+
272
+ def authorization_for(reply)
273
+ "#{reply[:TransactionID]};#{reply[:CreditCardNumber]}"
274
+ end
275
+
276
+ def authorization_parts_from(authorization)
277
+ authorization.split(/;/)
278
+ end
279
+
280
+ end
281
+ end
282
+ end
@@ -9,7 +9,7 @@ module ActiveMerchant #:nodoc:
9
9
  self.default_currency = 'DKK'
10
10
  self.money_format = :cents
11
11
  self.supported_cardtypes = [ :dankort, :forbrugsforeningen, :visa, :master, :american_express, :diners_club, :jcb, :maestro ]
12
- self.supported_countries = ['DK']
12
+ self.supported_countries = ['DK', 'SE']
13
13
  self.homepage_url = 'http://quickpay.dk/'
14
14
  self.display_name = 'Quickpay'
15
15
 
@@ -75,7 +75,7 @@ module ActiveMerchant #:nodoc:
75
75
  commit(:cancel, post)
76
76
  end
77
77
 
78
- def credit(money, identification, options = {})
78
+ def refund(money, identification, options = {})
79
79
  post = {}
80
80
 
81
81
  add_amount_without_currency(post, money)
@@ -83,6 +83,11 @@ module ActiveMerchant #:nodoc:
83
83
 
84
84
  commit(:refund, post)
85
85
  end
86
+
87
+ def credit(money, identification, options = {})
88
+ deprecated CREDIT_DEPRECATION_MESSAGE
89
+ refund(money, identification, options)
90
+ end
86
91
 
87
92
  def store(creditcard, options = {})
88
93
  post = {}
@@ -3,11 +3,11 @@ require 'digest/sha1'
3
3
 
4
4
  module ActiveMerchant
5
5
  module Billing
6
- # Realex us the leading CC gateway in Ireland
6
+ # Realex is the leading CC gateway in Ireland
7
7
  # see http://www.realexpayments.com
8
8
  # Contributed by John Ward (john@ward.name)
9
9
  # see http://thinedgeofthewedge.blogspot.com
10
- #
10
+ #
11
11
  # Realex works using the following
12
12
  # login - The unique id of the merchant
13
13
  # password - The secret is used to digitally sign the request
@@ -15,12 +15,12 @@ module ActiveMerchant
15
15
  # and is used if the merchant wishes do distuinguish cc traffic from the different sources
16
16
  # by using a different account. This must be created in advance
17
17
  #
18
- # the Realex team decided to make the orderid unique per request,
19
- # so if validation fails you can not correct and resend using the
18
+ # the Realex team decided to make the orderid unique per request,
19
+ # so if validation fails you can not correct and resend using the
20
20
  # same order id
21
21
  class RealexGateway < Gateway
22
22
  URL = 'https://epage.payandshop.com/epage-remote.cgi'
23
-
23
+
24
24
  CARD_MAPPING = {
25
25
  'master' => 'MC',
26
26
  'visa' => 'VISA',
@@ -30,46 +30,78 @@ module ActiveMerchant
30
30
  'solo' => 'SWITCH',
31
31
  'laser' => 'LASER'
32
32
  }
33
-
33
+
34
34
  self.money_format = :cents
35
35
  self.default_currency = 'EUR'
36
36
  self.supported_cardtypes = [ :visa, :master, :american_express, :diners_club, :switch, :solo, :laser ]
37
37
  self.supported_countries = [ 'IE', 'GB' ]
38
38
  self.homepage_url = 'http://www.realexpayments.com/'
39
39
  self.display_name = 'Realex'
40
-
40
+
41
41
  SUCCESS, DECLINED = "Successful", "Declined"
42
42
  BANK_ERROR = REALEX_ERROR = "Gateway is in maintenance. Please try again later."
43
43
  ERROR = CLIENT_DEACTIVATED = "Gateway Error"
44
-
44
+
45
45
  def initialize(options = {})
46
46
  requires!(options, :login, :password)
47
+ options[:refund_hash] = Digest::SHA1.hexdigest(options[:rebate_secret]) if options.has_key?(:rebate_secret)
47
48
  @options = options
48
49
  super
49
- end
50
-
50
+ end
51
+
51
52
  def purchase(money, credit_card, options = {})
52
53
  requires!(options, :order_id)
53
-
54
- request = build_purchase_or_authorization_request(:purchase, money, credit_card, options)
54
+
55
+ request = build_purchase_or_authorization_request(:purchase, money, credit_card, options)
56
+ commit(request)
57
+ end
58
+
59
+ def authorize(money, creditcard, options = {})
60
+ requires!(options, :order_id)
61
+
62
+ request = build_purchase_or_authorization_request(:authorization, money, creditcard, options)
63
+ commit(request)
64
+ end
65
+
66
+ def capture(money, authorization, options = {})
67
+ request = build_capture_request(authorization, options)
68
+ commit(request)
69
+ end
70
+
71
+ def refund(money, authorization, options = {})
72
+ request = build_refund_request(money, authorization, options)
73
+ commit(request)
74
+ end
75
+
76
+ def credit(money, authorization, options = {})
77
+ deprecated CREDIT_DEPRECATION_MESSAGE
78
+ refund(money, authorization, options)
79
+ end
80
+
81
+ def void(authorization, options = {})
82
+ request = build_void_request(authorization, options)
55
83
  commit(request)
56
- end
57
-
58
- private
59
- def commit(request)
84
+ end
85
+
86
+ private
87
+ def commit(request)
60
88
  response = parse(ssl_post(URL, request))
61
89
 
62
90
  Response.new(response[:result] == "00", message_from(response), response,
63
91
  :test => response[:message] =~ /\[ test system \]/,
64
- :authorization => response[:authcode],
65
- :cvv_result => response[:cvnresult]
66
- )
92
+ :authorization => authorization_from(response),
93
+ :cvv_result => response[:cvnresult],
94
+ :avs_result => {
95
+ :street_match => response[:avspostcoderesponse],
96
+ :postal_match => response[:avspostcoderesponse]
97
+ }
98
+ )
67
99
  end
68
100
 
69
101
  def parse(xml)
70
102
  response = {}
71
-
72
- xml = REXML::Document.new(xml)
103
+
104
+ xml = REXML::Document.new(xml)
73
105
  xml.elements.each('//response/*') do |node|
74
106
 
75
107
  if (node.elements.size == 0)
@@ -78,88 +110,165 @@ module ActiveMerchant
78
110
  node.elements.each do |childnode|
79
111
  name = "#{node.name.downcase}_#{childnode.name.downcase}"
80
112
  response[name.to_sym] = normalize(childnode.text)
81
- end
113
+ end
82
114
  end
83
115
 
84
116
  end unless xml.root.nil?
85
117
 
86
118
  response
87
119
  end
88
-
89
- def parse_credit_card_number(request)
90
- xml = REXML::Document.new(request)
91
- card_number = REXML::XPath.first(xml, '/request/card/number')
92
- card_number && card_number.text
120
+
121
+ def authorization_from(parsed)
122
+ [parsed[:orderid], parsed[:pasref], parsed[:authcode]].join(';')
93
123
  end
94
124
 
95
125
  def build_purchase_or_authorization_request(action, money, credit_card, options)
96
- timestamp = Time.now.strftime('%Y%m%d%H%M%S')
97
-
126
+ timestamp = new_timestamp
98
127
  xml = Builder::XmlMarkup.new :indent => 2
99
128
  xml.tag! 'request', 'timestamp' => timestamp, 'type' => 'auth' do
100
-
101
- xml.tag! 'merchantid', @options[:login]
102
- xml.tag! 'account', @options[:account]
103
-
129
+ add_merchant_details(xml, options)
104
130
  xml.tag! 'orderid', sanitize_order_id(options[:order_id])
131
+ add_amount(xml, money, options)
132
+ add_card(xml, credit_card)
133
+ xml.tag! 'autosettle', 'flag' => auto_settle_flag(action)
134
+ add_signed_digest(xml, timestamp, @options[:login], sanitize_order_id(options[:order_id]), amount(money), (options[:currency] || currency(money)), credit_card.number)
135
+ add_comments(xml, options)
136
+ add_address_and_customer_info(xml, options)
137
+ end
138
+ xml.target!
139
+ end
140
+
141
+ def build_capture_request(authorization, options)
142
+ timestamp = new_timestamp
143
+ xml = Builder::XmlMarkup.new :indent => 2
144
+ xml.tag! 'request', 'timestamp' => timestamp, 'type' => 'settle' do
145
+ add_merchant_details(xml, options)
146
+ add_transaction_identifiers(xml, authorization, options)
147
+ add_comments(xml, options)
148
+ add_signed_digest(xml, timestamp, @options[:login], sanitize_order_id(options[:order_id]), nil, nil, nil)
149
+ end
150
+ xml.target!
151
+ end
152
+
153
+ def build_refund_request(money, authorization, options)
154
+ timestamp = new_timestamp
155
+ xml = Builder::XmlMarkup.new :indent => 2
156
+ xml.tag! 'request', 'timestamp' => timestamp, 'type' => 'rebate' do
157
+ add_merchant_details(xml, options)
158
+ add_transaction_identifiers(xml, authorization, options)
105
159
  xml.tag! 'amount', amount(money), 'currency' => options[:currency] || currency(money)
160
+ xml.tag! 'refundhash', @options[:refund_hash] if @options[:refund_hash]
161
+ xml.tag! 'autosettle', 'flag' => 1
162
+ add_comments(xml, options)
163
+ add_signed_digest(xml, timestamp, @options[:login], sanitize_order_id(options[:order_id]), amount(money), (options[:currency] || currency(money)), nil)
164
+ end
165
+ xml.target!
166
+ end
106
167
 
107
- xml.tag! 'card' do
108
- xml.tag! 'number', credit_card.number
109
- xml.tag! 'expdate', expiry_date(credit_card)
110
- xml.tag! 'type', CARD_MAPPING[card_brand(credit_card).to_s]
111
- xml.tag! 'chname', credit_card.name
112
- xml.tag! 'issueno', credit_card.issue_number
113
-
114
- xml.tag! 'cvn' do
115
- xml.tag! 'number', credit_card.verification_value
116
- xml.tag! 'presind', credit_card.verification_value? ? 1 : nil
117
- end
118
- end
119
-
120
- xml.tag! 'autosettle', 'flag' => auto_settle_flag(action)
121
- xml.tag! 'sha1hash', sha1from("#{timestamp}.#{@options[:login]}.#{sanitize_order_id(options[:order_id])}.#{amount(money)}.#{options[:currency] || currency(money)}.#{credit_card.number}")
122
- xml.tag! 'comments' do
123
- xml.tag! 'comment', options[:description], 'id' => 1
124
- xml.tag! 'comment', 'id' => 2
125
- end
126
-
127
- billing_address = options[:billing_address] || options[:address] || {}
128
- shipping_address = options[:shipping_address] || {}
129
-
130
- xml.tag! 'tssinfo' do
168
+ def build_void_request(authorization, options)
169
+ timestamp = new_timestamp
170
+ xml = Builder::XmlMarkup.new :indent => 2
171
+ xml.tag! 'request', 'timestamp' => timestamp, 'type' => 'void' do
172
+ add_merchant_details(xml, options)
173
+ add_transaction_identifiers(xml, authorization, options)
174
+ add_comments(xml, options)
175
+ add_signed_digest(xml, timestamp, @options[:login], sanitize_order_id(options[:order_id]), nil, nil, nil)
176
+ end
177
+ xml.target!
178
+ end
179
+
180
+ def add_address_and_customer_info(xml, options)
181
+ billing_address = options[:billing_address] || options[:address]
182
+ shipping_address = options[:shipping_address]
183
+
184
+ return unless billing_address || shipping_address || options[:customer] || options[:invoice] || options[:ip]
185
+
186
+ xml.tag! 'tssinfo' do
187
+ xml.tag! 'custnum', options[:customer] if options[:customer]
188
+ xml.tag! 'prodid', options[:invoice] if options[:invoice]
189
+ xml.tag! 'custipaddress', options[:ip] if options[:ip]
190
+
191
+ if billing_address
131
192
  xml.tag! 'address', 'type' => 'billing' do
132
- xml.tag! 'code', billing_address[:zip]
193
+ xml.tag! 'code', avs_input_code( billing_address )
133
194
  xml.tag! 'country', billing_address[:country]
134
195
  end
196
+ end
135
197
 
198
+ if shipping_address
136
199
  xml.tag! 'address', 'type' => 'shipping' do
137
200
  xml.tag! 'code', shipping_address[:zip]
138
201
  xml.tag! 'country', shipping_address[:country]
139
202
  end
140
-
141
- xml.tag! 'custnum', options[:customer]
142
-
143
- xml.tag! 'prodid', options[:invoice]
144
- xml.tag! 'varref'
145
203
  end
146
204
  end
205
+ end
147
206
 
148
- xml.target!
207
+ def add_merchant_details(xml, options)
208
+ xml.tag! 'merchantid', @options[:login]
209
+ if options[:account] || @options[:account]
210
+ xml.tag! 'account', (options[:account] || @options[:account])
211
+ end
212
+ end
213
+
214
+ def add_transaction_identifiers(xml, authorization, options)
215
+ options[:order_id], pasref, authcode = authorization.split(';')
216
+ xml.tag! 'orderid', sanitize_order_id(options[:order_id])
217
+ xml.tag! 'pasref', pasref
218
+ xml.tag! 'authcode', authcode
219
+ end
220
+
221
+ def add_comments(xml, options)
222
+ return unless options[:description]
223
+ xml.tag! 'comments' do
224
+ xml.tag! 'comment', options[:description], 'id' => 1
225
+ end
226
+ end
227
+
228
+ def add_amount(xml, money, options)
229
+ xml.tag! 'amount', amount(money), 'currency' => options[:currency] || currency(money)
149
230
  end
150
-
231
+
232
+ def add_card(xml, credit_card)
233
+ xml.tag! 'card' do
234
+ xml.tag! 'number', credit_card.number
235
+ xml.tag! 'expdate', expiry_date(credit_card)
236
+ xml.tag! 'chname', credit_card.name
237
+ xml.tag! 'type', CARD_MAPPING[card_brand(credit_card).to_s]
238
+ xml.tag! 'issueno', credit_card.issue_number
239
+ xml.tag! 'cvn' do
240
+ xml.tag! 'number', credit_card.verification_value
241
+ xml.tag! 'presind', (options['presind'] || (credit_card.verification_value? ? 1 : nil))
242
+ end
243
+ end
244
+ end
245
+
246
+ def avs_input_code(address)
247
+ address.values_at(:zip, :address1).map{ |v| extract_digits(v) }.join('|')
248
+ end
249
+
250
+ def extract_digits(string)
251
+ return "" if string.nil?
252
+ string.gsub(/[\D]/,'')
253
+ end
254
+
255
+ def new_timestamp
256
+ Time.now.strftime('%Y%m%d%H%M%S')
257
+ end
258
+
259
+ def add_signed_digest(xml, *values)
260
+ string = Digest::SHA1.hexdigest(values.join("."))
261
+ xml.tag! 'sha1hash', Digest::SHA1.hexdigest([string, @options[:password]].join("."))
262
+ end
263
+
151
264
  def auto_settle_flag(action)
152
265
  action == :authorization ? '0' : '1'
153
266
  end
154
-
267
+
155
268
  def expiry_date(credit_card)
156
269
  "#{format(credit_card.month, :two_digits)}#{format(credit_card.year, :two_digits)}"
157
270
  end
158
-
159
- def sha1from(string)
160
- Digest::SHA1.hexdigest("#{Digest::SHA1.hexdigest(string)}.#{@options[:password]}")
161
- end
162
-
271
+
163
272
  def normalize(field)
164
273
  case field
165
274
  when "true" then true
@@ -167,12 +276,12 @@ module ActiveMerchant
167
276
  when "" then nil
168
277
  when "null" then nil
169
278
  else field
170
- end
279
+ end
171
280
  end
172
-
281
+
173
282
  def message_from(response)
174
283
  message = nil
175
- case response[:result]
284
+ case response[:result]
176
285
  when "00"
177
286
  message = SUCCESS
178
287
  when "101"
@@ -184,14 +293,16 @@ module ActiveMerchant
184
293
  when /^3[0-9][0-9]/
185
294
  message = REALEX_ERROR
186
295
  when /^5[0-9][0-9]/
296
+ message = response[:message]
297
+ when "600", "601", "603"
187
298
  message = ERROR
188
299
  when "666"
189
300
  message = CLIENT_DEACTIVATED
190
301
  else
191
302
  message = DECLINED
192
- end
303
+ end
193
304
  end
194
-
305
+
195
306
  def sanitize_order_id(order_id)
196
307
  order_id.to_s.gsub(/[^a-zA-Z0-9\-_]/, '')
197
308
  end