activemerchant 1.28.0 → 1.29.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (116) hide show
  1. data.tar.gz.sig +3 -3
  2. data/CHANGELOG +36 -0
  3. data/CONTRIBUTORS +8 -0
  4. data/README.md +5 -0
  5. data/lib/active_merchant/billing/gateway.rb +2 -1
  6. data/lib/active_merchant/billing/gateways.rb +6 -7
  7. data/lib/active_merchant/billing/gateways/authorize_net.rb +3 -2
  8. data/lib/active_merchant/billing/gateways/authorize_net_cim.rb +77 -78
  9. data/lib/active_merchant/billing/gateways/balanced.rb +0 -1
  10. data/lib/active_merchant/billing/gateways/banwire.rb +1 -2
  11. data/lib/active_merchant/billing/gateways/barclays_epdq.rb +19 -20
  12. data/lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb +35 -36
  13. data/lib/active_merchant/billing/gateways/blue_pay.rb +135 -140
  14. data/lib/active_merchant/billing/gateways/braintree_blue.rb +12 -4
  15. data/lib/active_merchant/billing/gateways/card_stream.rb +54 -59
  16. data/lib/active_merchant/billing/gateways/certo_direct.rb +0 -1
  17. data/lib/active_merchant/billing/gateways/cyber_source.rb +19 -14
  18. data/lib/active_merchant/billing/gateways/data_cash.rb +106 -112
  19. data/lib/active_merchant/billing/gateways/efsnet.rb +29 -34
  20. data/lib/active_merchant/billing/gateways/elavon.rb +7 -1
  21. data/lib/active_merchant/billing/gateways/epay.rb +0 -1
  22. data/lib/active_merchant/billing/gateways/eway.rb +88 -93
  23. data/lib/active_merchant/billing/gateways/eway_managed.rb +47 -51
  24. data/lib/active_merchant/billing/gateways/exact.rb +45 -54
  25. data/lib/active_merchant/billing/gateways/federated_canada.rb +3 -4
  26. data/lib/active_merchant/billing/gateways/first_pay.rb +37 -38
  27. data/lib/active_merchant/billing/gateways/garanti.rb +1 -2
  28. data/lib/active_merchant/billing/gateways/hdfc.rb +207 -0
  29. data/lib/active_merchant/billing/gateways/ideal/ideal_base.rb +5 -8
  30. data/lib/active_merchant/billing/gateways/inspire.rb +52 -52
  31. data/lib/active_merchant/billing/gateways/instapay.rb +10 -11
  32. data/lib/active_merchant/billing/gateways/iridium.rb +38 -39
  33. data/lib/active_merchant/billing/gateways/itransact.rb +7 -9
  34. data/lib/active_merchant/billing/gateways/jetpay.rb +45 -46
  35. data/lib/active_merchant/billing/gateways/linkpoint.rb +104 -108
  36. data/lib/active_merchant/billing/gateways/litle.rb +1 -5
  37. data/lib/active_merchant/billing/gateways/merchant_e_solutions.rb +153 -155
  38. data/lib/active_merchant/billing/gateways/merchant_ware.rb +49 -50
  39. data/lib/active_merchant/billing/gateways/mercury.rb +272 -0
  40. data/lib/active_merchant/billing/gateways/metrics_global.rb +9 -10
  41. data/lib/active_merchant/billing/gateways/migs.rb +5 -3
  42. data/lib/active_merchant/billing/gateways/modern_payments.rb +6 -7
  43. data/lib/active_merchant/billing/gateways/modern_payments_cim.rb +40 -41
  44. data/lib/active_merchant/billing/gateways/moneris.rb +46 -50
  45. data/lib/active_merchant/billing/gateways/moneris_us.rb +52 -55
  46. data/lib/active_merchant/billing/gateways/nab_transact.rb +0 -5
  47. data/lib/active_merchant/billing/gateways/net_registry.rb +20 -21
  48. data/lib/active_merchant/billing/gateways/netaxept.rb +30 -36
  49. data/lib/active_merchant/billing/gateways/netbilling.rb +2 -2
  50. data/lib/active_merchant/billing/gateways/ogone.rb +0 -5
  51. data/lib/active_merchant/billing/gateways/optimal_payment.rb +1 -6
  52. data/lib/active_merchant/billing/gateways/orbital.rb +25 -21
  53. data/lib/active_merchant/billing/gateways/orbital/avs_result.rb +93 -0
  54. data/lib/active_merchant/billing/gateways/pay_gate_xml.rb +1 -6
  55. data/lib/active_merchant/billing/gateways/pay_junction.rb +62 -63
  56. data/lib/active_merchant/billing/gateways/pay_secure.rb +29 -30
  57. data/lib/active_merchant/billing/gateways/paybox_direct.rb +0 -5
  58. data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +33 -38
  59. data/lib/active_merchant/billing/gateways/payment_express.rb +48 -51
  60. data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +7 -11
  61. data/lib/active_merchant/billing/gateways/paypal/paypal_express_response.rb +7 -0
  62. data/lib/active_merchant/billing/gateways/paypal/paypal_recurring_api.rb +3 -0
  63. data/lib/active_merchant/billing/gateways/paystation.rb +62 -64
  64. data/lib/active_merchant/billing/gateways/payway.rb +2 -9
  65. data/lib/active_merchant/billing/gateways/plugnpay.rb +0 -1
  66. data/lib/active_merchant/billing/gateways/psigate.rb +102 -94
  67. data/lib/active_merchant/billing/gateways/psl_card.rb +66 -67
  68. data/lib/active_merchant/billing/gateways/qbms.rb +0 -6
  69. data/lib/active_merchant/billing/gateways/quantum.rb +2 -8
  70. data/lib/active_merchant/billing/gateways/quickpay.rb +2 -3
  71. data/lib/active_merchant/billing/gateways/realex.rb +6 -16
  72. data/lib/active_merchant/billing/gateways/redsys.rb +394 -0
  73. data/lib/active_merchant/billing/gateways/sage.rb +15 -16
  74. data/lib/active_merchant/billing/gateways/sage/sage_core.rb +25 -26
  75. data/lib/active_merchant/billing/gateways/sage_pay.rb +51 -56
  76. data/lib/active_merchant/billing/gateways/sallie_mae.rb +1 -2
  77. data/lib/active_merchant/billing/gateways/samurai.rb +1 -4
  78. data/lib/active_merchant/billing/gateways/secure_net.rb +0 -1
  79. data/lib/active_merchant/billing/gateways/secure_pay.rb +5 -8
  80. data/lib/active_merchant/billing/gateways/secure_pay_au.rb +0 -5
  81. data/lib/active_merchant/billing/gateways/secure_pay_tech.rb +17 -18
  82. data/lib/active_merchant/billing/gateways/skip_jack.rb +29 -34
  83. data/lib/active_merchant/billing/gateways/smart_ps.rb +55 -56
  84. data/lib/active_merchant/billing/gateways/stripe.rb +8 -3
  85. data/lib/active_merchant/billing/gateways/trans_first.rb +28 -29
  86. data/lib/active_merchant/billing/gateways/trust_commerce.rb +85 -87
  87. data/lib/active_merchant/billing/gateways/usa_epay_advanced.rb +27 -28
  88. data/lib/active_merchant/billing/gateways/usa_epay_transaction.rb +0 -5
  89. data/lib/active_merchant/billing/gateways/verifi.rb +86 -87
  90. data/lib/active_merchant/billing/gateways/viaklix.rb +42 -47
  91. data/lib/active_merchant/billing/gateways/vindicia.rb +30 -28
  92. data/lib/active_merchant/billing/gateways/webpay.rb +45 -0
  93. data/lib/active_merchant/billing/gateways/wirecard.rb +0 -6
  94. data/lib/active_merchant/billing/gateways/worldpay.rb +4 -9
  95. data/lib/active_merchant/billing/integrations/a1agregator.rb +26 -0
  96. data/lib/active_merchant/billing/integrations/a1agregator/helper.rb +31 -0
  97. data/lib/active_merchant/billing/integrations/a1agregator/notification.rb +186 -0
  98. data/lib/active_merchant/billing/integrations/a1agregator/status.rb +38 -0
  99. data/lib/active_merchant/billing/integrations/liqpay.rb +30 -0
  100. data/lib/active_merchant/billing/integrations/liqpay/helper.rb +43 -0
  101. data/lib/active_merchant/billing/integrations/liqpay/notification.rb +89 -0
  102. data/lib/active_merchant/billing/integrations/liqpay/return.rb +83 -0
  103. data/lib/active_merchant/billing/integrations/moneybookers/helper.rb +17 -1
  104. data/lib/active_merchant/billing/integrations/notification.rb +4 -0
  105. data/lib/active_merchant/billing/integrations/pay_fast.rb +70 -0
  106. data/lib/active_merchant/billing/integrations/pay_fast/common.rb +42 -0
  107. data/lib/active_merchant/billing/integrations/pay_fast/helper.rb +50 -0
  108. data/lib/active_merchant/billing/integrations/pay_fast/notification.rb +134 -0
  109. data/lib/active_merchant/billing/integrations/pay_fast/return.rb +10 -0
  110. data/lib/active_merchant/billing/integrations/paypal/notification.rb +64 -0
  111. data/lib/active_merchant/billing/integrations/sage_pay_form/helper.rb +10 -7
  112. data/lib/active_merchant/billing/integrations/webmoney/notification.rb +12 -0
  113. data/lib/active_merchant/billing/response.rb +19 -4
  114. data/lib/active_merchant/version.rb +1 -1
  115. metadata +45 -27
  116. metadata.gz.sig +0 -0
@@ -23,11 +23,11 @@ module ActiveMerchant
23
23
  # (response.params['receipt']) if a receipt was issued by the gateway.
24
24
  class NetRegistryGateway < Gateway
25
25
  self.live_url = self.test_url = 'https://4tknox.au.com/cgi-bin/themerchant.au.com/ecom/external2.pl'
26
-
26
+
27
27
  FILTERED_PARAMS = [ 'card_no', 'card_expiry', 'receipt_array' ]
28
-
28
+
29
29
  self.supported_countries = ['AU']
30
-
30
+
31
31
  # Note that support for Diners, Amex, and JCB require extra
32
32
  # steps in setting up your account, as detailed in
33
33
  # "Programming for NetRegistry's E-commerce Gateway."
@@ -35,7 +35,7 @@ module ActiveMerchant
35
35
  self.supported_cardtypes = [:visa, :master, :diners_club, :american_express, :jcb]
36
36
  self.display_name = 'NetRegistry'
37
37
  self.homepage_url = 'http://www.netregistry.com.au'
38
-
38
+
39
39
  TRANSACTIONS = {
40
40
  :authorization => 'preauth',
41
41
  :purchase => 'purchase',
@@ -43,13 +43,12 @@ module ActiveMerchant
43
43
  :status => 'status',
44
44
  :credit => 'refund'
45
45
  }
46
-
46
+
47
47
  # Create a new NetRegistry gateway.
48
48
  #
49
49
  # Options :login and :password must be given.
50
50
  def initialize(options = {})
51
51
  requires!(options, :login, :password)
52
- @options = options
53
52
  super
54
53
  end
55
54
 
@@ -103,7 +102,7 @@ module ActiveMerchant
103
102
  add_request_details(params, options)
104
103
  commit(:credit, params)
105
104
  end
106
-
105
+
107
106
  # Specific to NetRegistry.
108
107
  #
109
108
  # Run a 'status' command. This lets you view the status of a
@@ -113,7 +112,7 @@ module ActiveMerchant
113
112
  params = {
114
113
  'TXNREF' => identification
115
114
  }
116
-
115
+
117
116
  commit(:status, params)
118
117
  end
119
118
 
@@ -121,7 +120,7 @@ module ActiveMerchant
121
120
  def add_request_details(params, options)
122
121
  params['COMMENT'] = options[:description] unless options[:description].blank?
123
122
  end
124
-
123
+
125
124
  # Return the expiry for the given creditcard in the required
126
125
  # format for a command.
127
126
  def expiry(credit_card)
@@ -138,44 +137,44 @@ module ActiveMerchant
138
137
  def commit(action, params)
139
138
  # get gateway response
140
139
  response = parse( ssl_post(self.live_url, post_data(action, params)) )
141
-
142
- Response.new(response['status'] == 'approved', message_from(response), response,
140
+
141
+ Response.new(response['status'] == 'approved', message_from(response), response,
143
142
  :authorization => authorization_from(response, action)
144
143
  )
145
144
  end
146
-
145
+
147
146
  def post_data(action, params)
148
147
  params['COMMAND'] = TRANSACTIONS[action]
149
148
  params['LOGIN'] = "#{@options[:login]}/#{@options[:password]}"
150
149
  URI.encode(params.map{|k,v| "#{k}=#{v}"}.join('&'))
151
150
  end
152
-
151
+
153
152
  def parse(response)
154
153
  params = {}
155
-
154
+
156
155
  lines = response.split("\n")
157
-
156
+
158
157
  # Just incase there is no real response returned
159
158
  params['status'] = lines[0]
160
159
  params['response_text'] = lines[1]
161
-
160
+
162
161
  started = false
163
- lines.each do |line|
162
+ lines.each do |line|
164
163
  if started
165
164
  key, val = line.chomp.split(/=/, 2)
166
165
  params[key] = val unless FILTERED_PARAMS.include?(key)
167
166
  end
168
-
167
+
169
168
  started = line.chomp =~ /^\.$/ unless started
170
169
  end
171
-
170
+
172
171
  params
173
172
  end
174
-
173
+
175
174
  def message_from(response)
176
175
  response['response_text']
177
176
  end
178
-
177
+
179
178
  def authorization_from(response, command)
180
179
  case command
181
180
  when :purchase
@@ -5,29 +5,28 @@ module ActiveMerchant #:nodoc:
5
5
  class NetaxeptGateway < Gateway
6
6
  self.test_url = 'https://epayment-test.bbs.no/'
7
7
  self.live_url = 'https://epayment.bbs.no/'
8
-
8
+
9
9
  # The countries the gateway supports merchants from as 2 digit ISO country codes
10
10
  self.supported_countries = ['NO', 'DK', 'SE', 'FI']
11
-
11
+
12
12
  # The card types supported by the payment gateway
13
13
  self.supported_cardtypes = [:visa, :master, :american_express]
14
-
14
+
15
15
  # The homepage URL of the gateway
16
16
  self.homepage_url = 'http://www.betalingsterminal.no/Netthandel-forside/'
17
-
17
+
18
18
  # The name of the gateway
19
19
  self.display_name = 'BBS Netaxept'
20
-
20
+
21
21
  self.money_format = :cents
22
-
22
+
23
23
  self.default_currency = 'NOK'
24
-
24
+
25
25
  def initialize(options = {})
26
26
  requires!(options, :login, :password)
27
- @options = options
28
27
  super
29
- end
30
-
28
+ end
29
+
31
30
  def purchase(money, creditcard, options = {})
32
31
  requires!(options, :order_id)
33
32
 
@@ -37,7 +36,7 @@ module ActiveMerchant #:nodoc:
37
36
  add_order(post, money, options)
38
37
  add_creditcard(post, creditcard)
39
38
  commit('Sale', post)
40
- end
39
+ end
41
40
 
42
41
  def authorize(money, creditcard, options = {})
43
42
  requires!(options, :order_id)
@@ -76,35 +75,30 @@ module ActiveMerchant #:nodoc:
76
75
  commit('Annul', post, false)
77
76
  end
78
77
 
79
- def test?
80
- @options[:test] || Base.gateway_mode == :test
81
- end
82
-
83
-
84
78
  private
85
-
79
+
86
80
  def add_credentials(post, options)
87
81
  post[:merchantId] = @options[:login]
88
82
  post[:token] = @options[:password]
89
83
  end
90
-
84
+
91
85
  def add_authorization(post, authorization, money=nil)
92
86
  post[:transactionId] = authorization
93
87
  post[:transactionAmount] = amount(money) if money
94
88
  end
95
-
89
+
96
90
  def add_transaction(post, options)
97
91
  post[:transactionId] = generate_transaction_id(options)
98
92
  post[:serviceType] = 'M'
99
93
  post[:redirectUrl] = 'http://example.com'
100
94
  end
101
-
95
+
102
96
  def add_order(post, money, options)
103
97
  post[:orderNumber] = options[:order_id]
104
98
  post[:amount] = amount(money)
105
99
  post[:currencyCode] = (options[:currency] || currency(money))
106
100
  end
107
-
101
+
108
102
  CARD_TYPE_PREFIXES = {
109
103
  'visa' => 'v',
110
104
  'master' => 'm',
@@ -123,7 +117,7 @@ module ActiveMerchant #:nodoc:
123
117
  post[:creditcard][:"#{prefix}y"] = format(creditcard.year, :two_digits)
124
118
  post[:creditcard][:"#{prefix}c"] = creditcard.verification_value
125
119
  end
126
-
120
+
127
121
  def commit(action, parameters, setup=true)
128
122
  parameters[:action] = action
129
123
 
@@ -138,27 +132,27 @@ module ActiveMerchant #:nodoc:
138
132
  commit_transaction(response, parameters)
139
133
  response[:success] = true
140
134
  end
141
-
135
+
142
136
  Response.new(response[:success], response[:message], response, :test => test?, :authorization => response[:authorization])
143
137
  end
144
-
138
+
145
139
  def commit_transaction_setup(response, parameters)
146
140
  response[:setup] = parse(ssl_get(build_url("REST/Setup.aspx", pick(parameters, :merchantId, :token, :serviceType, :amount, :currencyCode, :redirectUrl, :orderNumber, :transactionId))))
147
141
  process(response, :setup)
148
142
  end
149
-
143
+
150
144
  def commit_payment_details(response, parameters)
151
145
  data = encode(parameters[:creditcard].merge(:BBSePay_transaction => response[:setup]['SetupString']))
152
146
  response[:paymentDetails] = parse(ssl_post(build_url("terminal/default.aspx"), data), false)
153
147
  process(response, :paymentDetails)
154
148
  end
155
-
149
+
156
150
  def commit_process_setup(response, parameters)
157
151
  result = ssl_get(build_url("REST/ProcessSetup.aspx", pick(parameters, :merchantId, :token, :transactionId).merge(:transactionString => response[:paymentDetails][:result])))
158
152
  response[:processSetup] = parse(result)
159
153
  process(response, :processSetup)
160
154
  end
161
-
155
+
162
156
  def commit_transaction(response, parameters)
163
157
  result = ssl_get(build_url("REST/#{parameters[:action]}.aspx", pick(parameters, :merchantId, :token, :transactionId, :transactionAmount)))
164
158
  response[:action] = parse(result)
@@ -172,11 +166,11 @@ module ActiveMerchant #:nodoc:
172
166
  else
173
167
  message = (response[step]['ResponseText'] || response[step]['ResponseCode'])
174
168
  response[:message] = (message || response[:message])
175
-
169
+
176
170
  response[:authorization] = response[step]['TransactionId']
177
171
  end
178
172
  end
179
-
173
+
180
174
  def parse(result, expects_xml=true)
181
175
  if expects_xml || /^</ =~ result
182
176
  doc = REXML::Document.new(result)
@@ -185,7 +179,7 @@ module ActiveMerchant #:nodoc:
185
179
  {:result => result}
186
180
  end
187
181
  end
188
-
182
+
189
183
  def extract_xml(element)
190
184
  if element.has_elements?
191
185
  hash = {}
@@ -197,19 +191,19 @@ module ActiveMerchant #:nodoc:
197
191
  element.text
198
192
  end
199
193
  end
200
-
194
+
201
195
  def url
202
196
  (test? ? self.test_url : self.live_url)
203
197
  end
204
-
198
+
205
199
  def generate_transaction_id(options)
206
200
  Digest::MD5.hexdigest("#{options.inspect}+#{Time.now}+#{rand}")
207
201
  end
208
-
202
+
209
203
  def pick(hash, *keys)
210
204
  keys.inject({}){|h,key| h[key] = hash[key] if hash[key]; h}
211
205
  end
212
-
206
+
213
207
  def build_url(base, parameters=nil)
214
208
  url = "#{test? ? self.test_url : self.live_url}"
215
209
  url << base
@@ -219,11 +213,11 @@ module ActiveMerchant #:nodoc:
219
213
  end
220
214
  url
221
215
  end
222
-
216
+
223
217
  def encode(hash)
224
218
  hash.collect{|(k,v)| "#{CGI.escape(k.to_s)}=#{CGI.escape(v.to_s)}"}.join('&')
225
219
  end
226
-
220
+
227
221
  class Response < Billing::Response
228
222
  attr_reader :error_detail
229
223
  def initialize(success, message, raw, options)
@@ -24,7 +24,6 @@ module ActiveMerchant #:nodoc:
24
24
 
25
25
  def initialize(options = {})
26
26
  requires!(options, :login)
27
- @options = options
28
27
  super
29
28
  end
30
29
 
@@ -81,10 +80,11 @@ module ActiveMerchant #:nodoc:
81
80
  end
82
81
 
83
82
  def test?
84
- @options[:login] == TEST_LOGIN || super
83
+ (@options[:login] == TEST_LOGIN || super)
85
84
  end
86
85
 
87
86
  private
87
+
88
88
  def add_amount(post, money)
89
89
  post[:amount] = amount(money)
90
90
  end
@@ -138,7 +138,6 @@ module ActiveMerchant #:nodoc:
138
138
 
139
139
  def initialize(options = {})
140
140
  requires!(options, :login, :user, :password)
141
- @options = options
142
141
  super
143
142
  end
144
143
 
@@ -205,10 +204,6 @@ module ActiveMerchant #:nodoc:
205
204
  response
206
205
  end
207
206
 
208
- def test?
209
- @options[:test] || super
210
- end
211
-
212
207
  private
213
208
 
214
209
  def reference_from(authorization)
@@ -18,7 +18,6 @@ module ActiveMerchant #:nodoc:
18
18
 
19
19
  def initialize(options = {})
20
20
  #requires!(options, :login, :password)
21
- @options = options
22
21
  super
23
22
  end
24
23
 
@@ -49,11 +48,7 @@ module ActiveMerchant #:nodoc:
49
48
  commit('ccSettlement', money, options)
50
49
  end
51
50
 
52
- def test?
53
- super || @options[:test]
54
- end
55
-
56
- private
51
+ private
57
52
 
58
53
  def parse_card_or_auth(card_or_auth, options)
59
54
  if card_or_auth.respond_to?(:number)
@@ -1,4 +1,5 @@
1
- require File.dirname(__FILE__) + '/orbital/orbital_soft_descriptors.rb'
1
+ require File.dirname(__FILE__) + '/orbital/orbital_soft_descriptors'
2
+ require File.dirname(__FILE__) + '/orbital/avs_result'
2
3
  require "rexml/document"
3
4
 
4
5
  module ActiveMerchant #:nodoc:
@@ -82,7 +83,6 @@ module ActiveMerchant #:nodoc:
82
83
  def initialize(options = {})
83
84
  requires!(options, :merchant_id)
84
85
  requires!(options, :login, :password) unless options[:ip_authentication]
85
- @options = options
86
86
  super
87
87
  end
88
88
 
@@ -93,7 +93,7 @@ module ActiveMerchant #:nodoc:
93
93
  add_address(xml, creditcard, options)
94
94
  add_customer_data(xml, options) if @options[:customer_profiles]
95
95
  end
96
- commit(order)
96
+ commit(order, :authorize)
97
97
  end
98
98
 
99
99
  # AC – Authorization and Capture
@@ -103,12 +103,12 @@ module ActiveMerchant #:nodoc:
103
103
  add_address(xml, creditcard, options)
104
104
  add_customer_data(xml, options) if @options[:customer_profiles]
105
105
  end
106
- commit(order)
106
+ commit(order, :purchase)
107
107
  end
108
108
 
109
109
  # MFC - Mark For Capture
110
110
  def capture(money, authorization, options = {})
111
- commit(build_mark_for_capture_xml(money, authorization, options))
111
+ commit(build_mark_for_capture_xml(money, authorization, options), :capture)
112
112
  end
113
113
 
114
114
  # R – Refund request
@@ -117,7 +117,7 @@ module ActiveMerchant #:nodoc:
117
117
  add_refund(xml, options[:currency])
118
118
  xml.tag! :CustomerRefNum, options[:customer_ref_num] if @options[:customer_profiles] && options[:profile_txn]
119
119
  end
120
- commit(order)
120
+ commit(order, :refund)
121
121
  end
122
122
 
123
123
  def credit(money, authorization, options= {})
@@ -128,7 +128,7 @@ module ActiveMerchant #:nodoc:
128
128
  # setting money to nil will perform a full void
129
129
  def void(money, authorization, options = {})
130
130
  order = build_void_request_xml(money, authorization, options)
131
- commit(order)
131
+ commit(order, :void)
132
132
  end
133
133
 
134
134
 
@@ -156,25 +156,25 @@ module ActiveMerchant #:nodoc:
156
156
  def add_customer_profile(creditcard, options = {})
157
157
  options.merge!(:customer_profile_action => 'C')
158
158
  order = build_customer_request_xml(creditcard, options)
159
- commit(order)
159
+ commit(order, :add_customer_profile)
160
160
  end
161
161
 
162
162
  def update_customer_profile(creditcard, options = {})
163
163
  options.merge!(:customer_profile_action => 'U')
164
164
  order = build_customer_request_xml(creditcard, options)
165
- commit(order)
165
+ commit(order, :update_customer_profile)
166
166
  end
167
167
 
168
168
  def retrieve_customer_profile(customer_ref_num)
169
169
  options = {:customer_profile_action => 'R', :customer_ref_num => customer_ref_num}
170
170
  order = build_customer_request_xml(nil, options)
171
- commit(order)
171
+ commit(order, :retrieve_customer_profile)
172
172
  end
173
173
 
174
174
  def delete_customer_profile(customer_ref_num)
175
175
  options = {:customer_profile_action => 'D', :customer_ref_num => customer_ref_num}
176
176
  order = build_customer_request_xml(nil, options)
177
- commit(order)
177
+ commit(order, :delete_customer_profile)
178
178
  end
179
179
 
180
180
  private
@@ -291,33 +291,37 @@ module ActiveMerchant #:nodoc:
291
291
  end
292
292
  end
293
293
 
294
- def commit(order)
294
+ def commit(order, message_type)
295
295
  headers = POST_HEADERS.merge("Content-length" => order.size.to_s)
296
- request = lambda {return parse(ssl_post(remote_url, order, headers))}
296
+ request = lambda{|url| parse(ssl_post(url, order, headers))}
297
297
 
298
- # Failover URL will be used in the event of a connection error
299
- begin response = request.call; rescue ConnectionError; retry end
298
+ # Failover URL will be attempted in the event of a connection error
299
+ response = begin
300
+ request.call(remote_url)
301
+ rescue ConnectionError
302
+ request.call(remote_url(:secondary))
303
+ end
300
304
 
301
- Response.new(success?(response), message_from(response), response,
305
+ Response.new(success?(response, message_type), message_from(response), response,
302
306
  {
303
307
  :authorization => authorization_string(response[:tx_ref_num], response[:order_id]),
304
308
  :test => self.test?,
305
- :avs_result => {:code => response[:avs_resp_code]},
309
+ :avs_result => OrbitalGateway::AVSResult.new(response[:avs_resp_code]),
306
310
  :cvv_result => response[:cvv2_resp_code]
307
311
  }
308
312
  )
309
313
  end
310
314
 
311
- def remote_url
312
- unless $!.class == ActiveMerchant::ConnectionError
315
+ def remote_url(url=:primary)
316
+ if url == :primary
313
317
  self.test? ? self.test_url : self.live_url
314
318
  else
315
319
  self.test? ? self.secondary_test_url : self.secondary_live_url
316
320
  end
317
321
  end
318
322
 
319
- def success?(response)
320
- if response[:message_type] == "R"
323
+ def success?(response, message_type)
324
+ if [:refund, :void].include?(message_type)
321
325
  response[:proc_status] == SUCCESS
322
326
  elsif response[:customer_profile_action]
323
327
  response[:profile_proc_status] == SUCCESS