activemerchant 1.28.0 → 1.29.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (117) hide show
  1. data/CHANGELOG +41 -0
  2. data/CONTRIBUTORS +12 -0
  3. data/README.md +6 -0
  4. data/lib/active_merchant/billing/gateway.rb +2 -1
  5. data/lib/active_merchant/billing/gateways/authorize_net.rb +3 -2
  6. data/lib/active_merchant/billing/gateways/authorize_net_cim.rb +77 -78
  7. data/lib/active_merchant/billing/gateways/balanced.rb +0 -1
  8. data/lib/active_merchant/billing/gateways/banwire.rb +1 -2
  9. data/lib/active_merchant/billing/gateways/barclays_epdq.rb +19 -20
  10. data/lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb +35 -36
  11. data/lib/active_merchant/billing/gateways/blue_pay.rb +135 -140
  12. data/lib/active_merchant/billing/gateways/braintree_blue.rb +12 -4
  13. data/lib/active_merchant/billing/gateways/card_stream.rb +54 -59
  14. data/lib/active_merchant/billing/gateways/certo_direct.rb +0 -1
  15. data/lib/active_merchant/billing/gateways/cyber_source.rb +19 -14
  16. data/lib/active_merchant/billing/gateways/data_cash.rb +106 -112
  17. data/lib/active_merchant/billing/gateways/efsnet.rb +29 -34
  18. data/lib/active_merchant/billing/gateways/elavon.rb +7 -1
  19. data/lib/active_merchant/billing/gateways/epay.rb +0 -1
  20. data/lib/active_merchant/billing/gateways/eway.rb +88 -93
  21. data/lib/active_merchant/billing/gateways/eway_managed.rb +47 -51
  22. data/lib/active_merchant/billing/gateways/eway_rapid.rb +300 -0
  23. data/lib/active_merchant/billing/gateways/exact.rb +45 -54
  24. data/lib/active_merchant/billing/gateways/federated_canada.rb +3 -4
  25. data/lib/active_merchant/billing/gateways/first_pay.rb +37 -38
  26. data/lib/active_merchant/billing/gateways/garanti.rb +1 -2
  27. data/lib/active_merchant/billing/gateways/hdfc.rb +207 -0
  28. data/lib/active_merchant/billing/gateways/ideal/ideal_base.rb +5 -8
  29. data/lib/active_merchant/billing/gateways/inspire.rb +52 -52
  30. data/lib/active_merchant/billing/gateways/instapay.rb +10 -11
  31. data/lib/active_merchant/billing/gateways/iridium.rb +38 -39
  32. data/lib/active_merchant/billing/gateways/itransact.rb +7 -9
  33. data/lib/active_merchant/billing/gateways/jetpay.rb +45 -46
  34. data/lib/active_merchant/billing/gateways/linkpoint.rb +104 -108
  35. data/lib/active_merchant/billing/gateways/litle.rb +1 -5
  36. data/lib/active_merchant/billing/gateways/merchant_e_solutions.rb +153 -155
  37. data/lib/active_merchant/billing/gateways/merchant_ware.rb +49 -50
  38. data/lib/active_merchant/billing/gateways/mercury.rb +272 -0
  39. data/lib/active_merchant/billing/gateways/metrics_global.rb +9 -10
  40. data/lib/active_merchant/billing/gateways/migs.rb +5 -3
  41. data/lib/active_merchant/billing/gateways/modern_payments.rb +6 -7
  42. data/lib/active_merchant/billing/gateways/modern_payments_cim.rb +40 -41
  43. data/lib/active_merchant/billing/gateways/moneris.rb +46 -50
  44. data/lib/active_merchant/billing/gateways/moneris_us.rb +52 -55
  45. data/lib/active_merchant/billing/gateways/nab_transact.rb +0 -5
  46. data/lib/active_merchant/billing/gateways/net_registry.rb +20 -21
  47. data/lib/active_merchant/billing/gateways/netaxept.rb +30 -36
  48. data/lib/active_merchant/billing/gateways/netbilling.rb +2 -2
  49. data/lib/active_merchant/billing/gateways/ogone.rb +0 -5
  50. data/lib/active_merchant/billing/gateways/optimal_payment.rb +1 -6
  51. data/lib/active_merchant/billing/gateways/orbital/avs_result.rb +93 -0
  52. data/lib/active_merchant/billing/gateways/orbital.rb +25 -21
  53. data/lib/active_merchant/billing/gateways/pay_gate_xml.rb +1 -6
  54. data/lib/active_merchant/billing/gateways/pay_junction.rb +62 -63
  55. data/lib/active_merchant/billing/gateways/pay_secure.rb +29 -30
  56. data/lib/active_merchant/billing/gateways/paybox_direct.rb +0 -5
  57. data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +33 -38
  58. data/lib/active_merchant/billing/gateways/payment_express.rb +48 -51
  59. data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +7 -11
  60. data/lib/active_merchant/billing/gateways/paypal/paypal_express_response.rb +7 -0
  61. data/lib/active_merchant/billing/gateways/paypal/paypal_recurring_api.rb +3 -0
  62. data/lib/active_merchant/billing/gateways/paystation.rb +62 -64
  63. data/lib/active_merchant/billing/gateways/payway.rb +2 -9
  64. data/lib/active_merchant/billing/gateways/plugnpay.rb +0 -1
  65. data/lib/active_merchant/billing/gateways/psigate.rb +102 -94
  66. data/lib/active_merchant/billing/gateways/psl_card.rb +66 -67
  67. data/lib/active_merchant/billing/gateways/qbms.rb +0 -6
  68. data/lib/active_merchant/billing/gateways/quantum.rb +2 -8
  69. data/lib/active_merchant/billing/gateways/quickpay.rb +2 -3
  70. data/lib/active_merchant/billing/gateways/realex.rb +6 -16
  71. data/lib/active_merchant/billing/gateways/redsys.rb +394 -0
  72. data/lib/active_merchant/billing/gateways/sage/sage_core.rb +25 -26
  73. data/lib/active_merchant/billing/gateways/sage.rb +15 -16
  74. data/lib/active_merchant/billing/gateways/sage_pay.rb +51 -56
  75. data/lib/active_merchant/billing/gateways/sallie_mae.rb +1 -2
  76. data/lib/active_merchant/billing/gateways/samurai.rb +1 -4
  77. data/lib/active_merchant/billing/gateways/secure_net.rb +0 -1
  78. data/lib/active_merchant/billing/gateways/secure_pay.rb +5 -8
  79. data/lib/active_merchant/billing/gateways/secure_pay_au.rb +0 -5
  80. data/lib/active_merchant/billing/gateways/secure_pay_tech.rb +17 -18
  81. data/lib/active_merchant/billing/gateways/skip_jack.rb +29 -34
  82. data/lib/active_merchant/billing/gateways/smart_ps.rb +55 -56
  83. data/lib/active_merchant/billing/gateways/stripe.rb +8 -3
  84. data/lib/active_merchant/billing/gateways/trans_first.rb +28 -29
  85. data/lib/active_merchant/billing/gateways/trust_commerce.rb +85 -87
  86. data/lib/active_merchant/billing/gateways/usa_epay_advanced.rb +27 -28
  87. data/lib/active_merchant/billing/gateways/usa_epay_transaction.rb +0 -5
  88. data/lib/active_merchant/billing/gateways/verifi.rb +86 -87
  89. data/lib/active_merchant/billing/gateways/viaklix.rb +42 -47
  90. data/lib/active_merchant/billing/gateways/vindicia.rb +30 -28
  91. data/lib/active_merchant/billing/gateways/webpay.rb +45 -0
  92. data/lib/active_merchant/billing/gateways/wirecard.rb +0 -6
  93. data/lib/active_merchant/billing/gateways/worldpay.rb +4 -9
  94. data/lib/active_merchant/billing/gateways.rb +6 -7
  95. data/lib/active_merchant/billing/integrations/a1agregator/helper.rb +31 -0
  96. data/lib/active_merchant/billing/integrations/a1agregator/notification.rb +186 -0
  97. data/lib/active_merchant/billing/integrations/a1agregator/status.rb +38 -0
  98. data/lib/active_merchant/billing/integrations/a1agregator.rb +26 -0
  99. data/lib/active_merchant/billing/integrations/liqpay/helper.rb +43 -0
  100. data/lib/active_merchant/billing/integrations/liqpay/notification.rb +89 -0
  101. data/lib/active_merchant/billing/integrations/liqpay/return.rb +83 -0
  102. data/lib/active_merchant/billing/integrations/liqpay.rb +30 -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/common.rb +42 -0
  106. data/lib/active_merchant/billing/integrations/pay_fast/helper.rb +50 -0
  107. data/lib/active_merchant/billing/integrations/pay_fast/notification.rb +134 -0
  108. data/lib/active_merchant/billing/integrations/pay_fast/return.rb +10 -0
  109. data/lib/active_merchant/billing/integrations/pay_fast.rb +70 -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 +17 -4
  114. data/lib/active_merchant/version.rb +1 -1
  115. data.tar.gz.sig +0 -0
  116. metadata +46 -27
  117. metadata.gz.sig +0 -0
@@ -63,13 +63,13 @@ module ActiveMerchant #:nodoc:
63
63
  # * <tt>:test => +true+ or +false+</tt> -- Force test transactions
64
64
  def initialize(options = {})
65
65
  requires!(options, :login, :password)
66
- @options = options
67
66
  super
68
67
  end
69
68
 
70
69
  # Make a purchase
71
70
  def purchase(money, creditcard, options = {})
72
71
  form = {}
72
+ add_salestax(form, options)
73
73
  add_invoice(form, options)
74
74
  add_creditcard(form, creditcard)
75
75
  add_address(form, options)
@@ -87,6 +87,7 @@ module ActiveMerchant #:nodoc:
87
87
  # * <tt>:billing_address</tt> - The billing address for the cardholder.
88
88
  def authorize(money, creditcard, options = {})
89
89
  form = {}
90
+ add_salestax(form, options)
90
91
  add_invoice(form, options)
91
92
  add_creditcard(form, creditcard)
92
93
  add_address(form, options)
@@ -106,6 +107,7 @@ module ActiveMerchant #:nodoc:
106
107
  requires!(options, :credit_card)
107
108
 
108
109
  form = {}
110
+ add_salestax(form, options)
109
111
  add_approval_code(form, authorization)
110
112
  add_invoice(form, options)
111
113
  add_creditcard(form, options[:credit_card])
@@ -205,6 +207,10 @@ module ActiveMerchant #:nodoc:
205
207
  form[:customer_code] = options[:customer].to_s.slice(0, 10) unless options[:customer].blank?
206
208
  end
207
209
 
210
+ def add_salestax(form, options)
211
+ form[:salestax] = options[:tax] if options[:tax].present?
212
+ end
213
+
208
214
  def expdate(creditcard)
209
215
  year = sprintf("%.4i", creditcard.year)
210
216
  month = sprintf("%.2i", creditcard.month)
@@ -54,7 +54,6 @@ module ActiveMerchant #:nodoc:
54
54
  # password: referrer url (for authorize authentication)
55
55
  def initialize(options = {})
56
56
  requires!(options, :login)
57
- @options = options
58
57
  super
59
58
  end
60
59
 
@@ -3,7 +3,7 @@ require 'rexml/document'
3
3
  module ActiveMerchant #:nodoc:
4
4
  module Billing #:nodoc:
5
5
  # First, make sure you have everything setup correctly and all of your dependencies in place with:
6
- #
6
+ #
7
7
  # require 'rubygems'
8
8
  # require 'active_merchant'
9
9
  #
@@ -17,10 +17,10 @@ module ActiveMerchant #:nodoc:
17
17
  # Next, create a credit card object using a eWay approved test card number (4444333322221111).
18
18
  #
19
19
  # creditcard = ActiveMerchant::Billing::CreditCard.new(
20
- # :number => '4444333322221111',
21
- # :month => 8,
22
- # :year => 2006,
23
- # :first_name => 'Longbob',
20
+ # :number => '4444333322221111',
21
+ # :month => 8,
22
+ # :year => 2006,
23
+ # :first_name => 'Longbob',
24
24
  # :last_name => 'Longsen',
25
25
  # :verification_value => '123'
26
26
  # )
@@ -28,7 +28,7 @@ module ActiveMerchant #:nodoc:
28
28
  # :order_id => '1230123',
29
29
  # :email => 'bob@testbob.com',
30
30
  # :address => { :address1 => '47 Bobway',
31
- # :city => 'Bobville',
31
+ # :city => 'Bobville',
32
32
  # :state => 'WA',
33
33
  # :country => 'Australia',
34
34
  # :zip => '2000'
@@ -63,88 +63,87 @@ module ActiveMerchant #:nodoc:
63
63
  # This should be enough to get you started with eWay and active_merchant. For further information, review the methods
64
64
  # below and the rest of active_merchant's documentation.
65
65
 
66
- class EwayGateway < Gateway
66
+ class EwayGateway < Gateway
67
67
  self.test_url = 'https://www.eway.com.au/gateway/xmltest/testpage.asp'
68
68
  self.live_url = 'https://www.eway.com.au/gateway/xmlpayment.asp'
69
69
 
70
70
  class_attribute :test_cvn_url, :live_cvn_url
71
71
  self.test_cvn_url = 'https://www.eway.com.au/gateway_cvn/xmltest/testpage.asp'
72
72
  self.live_cvn_url = 'https://www.eway.com.au/gateway_cvn/xmlpayment.asp'
73
-
73
+
74
74
  MESSAGES = {
75
75
  "00" => "Transaction Approved",
76
76
  "01" => "Refer to Issuer",
77
- "02" => "Refer to Issuer, special",
77
+ "02" => "Refer to Issuer, special",
78
78
  "03" => "No Merchant",
79
- "04" => "Pick Up Card",
80
- "05" => "Do Not Honour",
79
+ "04" => "Pick Up Card",
80
+ "05" => "Do Not Honour",
81
81
  "06" => "Error",
82
- "07" => "Pick Up Card, Special",
83
- "08" => "Honour With Identification",
82
+ "07" => "Pick Up Card, Special",
83
+ "08" => "Honour With Identification",
84
84
  "09" => "Request In Progress",
85
- "10" => "Approved For Partial Amount",
86
- "11" => "Approved, VIP",
87
- "12" => "Invalid Transaction",
85
+ "10" => "Approved For Partial Amount",
86
+ "11" => "Approved, VIP",
87
+ "12" => "Invalid Transaction",
88
88
  "13" => "Invalid Amount",
89
- "14" => "Invalid Card Number",
90
- "15" => "No Issuer",
91
- "16" => "Approved, Update Track 3",
92
- "19" => "Re-enter Last Transaction",
93
- "21" => "No Action Taken",
94
- "22" => "Suspected Malfunction",
95
- "23" => "Unacceptable Transaction Fee",
96
- "25" => "Unable to Locate Record On File",
97
- "30" => "Format Error",
98
- "31" => "Bank Not Supported By Switch",
99
- "33" => "Expired Card, Capture",
100
- "34" => "Suspected Fraud, Retain Card",
101
- "35" => "Card Acceptor, Contact Acquirer, Retain Card",
102
- "36" => "Restricted Card, Retain Card",
103
- "37" => "Contact Acquirer Security Department, Retain Card",
104
- "38" => "PIN Tries Exceeded, Capture",
105
- "39" => "No Credit Account",
106
- "40" => "Function Not Supported",
107
- "41" => "Lost Card",
108
- "42" => "No Universal Account",
109
- "43" => "Stolen Card",
110
- "44" => "No Investment Account",
111
- "51" => "Insufficient Funds",
112
- "52" => "No Cheque Account",
113
- "53" => "No Savings Account",
114
- "54" => "Expired Card",
115
- "55" => "Incorrect PIN",
116
- "56" => "No Card Record",
117
- "57" => "Function Not Permitted to Cardholder",
118
- "58" => "Function Not Permitted to Terminal",
119
- "59" => "Suspected Fraud",
120
- "60" => "Acceptor Contact Acquirer",
121
- "61" => "Exceeds Withdrawal Limit",
122
- "62" => "Restricted Card",
123
- "63" => "Security Violation",
124
- "64" => "Original Amount Incorrect",
125
- "66" => "Acceptor Contact Acquirer, Security",
126
- "67" => "Capture Card",
127
- "75" => "PIN Tries Exceeded",
128
- "82" => "CVV Validation Error",
129
- "90" => "Cutoff In Progress",
130
- "91" => "Card Issuer Unavailable",
131
- "92" => "Unable To Route Transaction",
132
- "93" => "Cannot Complete, Violation Of The Law",
133
- "94" => "Duplicate Transaction",
89
+ "14" => "Invalid Card Number",
90
+ "15" => "No Issuer",
91
+ "16" => "Approved, Update Track 3",
92
+ "19" => "Re-enter Last Transaction",
93
+ "21" => "No Action Taken",
94
+ "22" => "Suspected Malfunction",
95
+ "23" => "Unacceptable Transaction Fee",
96
+ "25" => "Unable to Locate Record On File",
97
+ "30" => "Format Error",
98
+ "31" => "Bank Not Supported By Switch",
99
+ "33" => "Expired Card, Capture",
100
+ "34" => "Suspected Fraud, Retain Card",
101
+ "35" => "Card Acceptor, Contact Acquirer, Retain Card",
102
+ "36" => "Restricted Card, Retain Card",
103
+ "37" => "Contact Acquirer Security Department, Retain Card",
104
+ "38" => "PIN Tries Exceeded, Capture",
105
+ "39" => "No Credit Account",
106
+ "40" => "Function Not Supported",
107
+ "41" => "Lost Card",
108
+ "42" => "No Universal Account",
109
+ "43" => "Stolen Card",
110
+ "44" => "No Investment Account",
111
+ "51" => "Insufficient Funds",
112
+ "52" => "No Cheque Account",
113
+ "53" => "No Savings Account",
114
+ "54" => "Expired Card",
115
+ "55" => "Incorrect PIN",
116
+ "56" => "No Card Record",
117
+ "57" => "Function Not Permitted to Cardholder",
118
+ "58" => "Function Not Permitted to Terminal",
119
+ "59" => "Suspected Fraud",
120
+ "60" => "Acceptor Contact Acquirer",
121
+ "61" => "Exceeds Withdrawal Limit",
122
+ "62" => "Restricted Card",
123
+ "63" => "Security Violation",
124
+ "64" => "Original Amount Incorrect",
125
+ "66" => "Acceptor Contact Acquirer, Security",
126
+ "67" => "Capture Card",
127
+ "75" => "PIN Tries Exceeded",
128
+ "82" => "CVV Validation Error",
129
+ "90" => "Cutoff In Progress",
130
+ "91" => "Card Issuer Unavailable",
131
+ "92" => "Unable To Route Transaction",
132
+ "93" => "Cannot Complete, Violation Of The Law",
133
+ "94" => "Duplicate Transaction",
134
134
  "96" => "System Error"
135
135
  }
136
-
137
- self.money_format = :cents
136
+
137
+ self.money_format = :cents
138
138
  self.supported_countries = ['AU']
139
139
  self.supported_cardtypes = [:visa, :master, :american_express, :diners_club]
140
140
  self.homepage_url = 'http://www.eway.com.au/'
141
141
  self.display_name = 'eWAY'
142
-
143
- def initialize(options = {})
142
+
143
+ def initialize(options = {})
144
144
  requires!(options, :login)
145
- @options = options
146
145
  super
147
- end
146
+ end
148
147
 
149
148
  # ewayCustomerEmail, ewayCustomerAddress, ewayCustomerPostcode
150
149
  def purchase(money, creditcard, options = {})
@@ -152,20 +151,16 @@ module ActiveMerchant #:nodoc:
152
151
 
153
152
  post = {}
154
153
  add_creditcard(post, creditcard)
155
- add_address(post, options)
154
+ add_address(post, options)
156
155
  add_customer_data(post, options)
157
156
  add_invoice_data(post, options)
158
157
  # The request fails if all of the fields aren't present
159
158
  add_optional_data(post)
160
-
159
+
161
160
  commit(money, post)
162
161
  end
163
-
164
- def test?
165
- @options[:test] || super
166
- end
167
-
168
- private
162
+
163
+ private
169
164
 
170
165
  def requires_address!(options)
171
166
  raise ArgumentError.new("Missing eWay required parameters: address or billing_address") unless (options.has_key?(:address) or options.has_key?(:billing_address))
@@ -178,9 +173,9 @@ module ActiveMerchant #:nodoc:
178
173
  post[:CustomerFirstName] = creditcard.first_name
179
174
  post[:CustomerLastName] = creditcard.last_name
180
175
  post[:CardHoldersName] = creditcard.name
181
-
176
+
182
177
  post[:CVN] = creditcard.verification_value if creditcard.verification_value?
183
- end
178
+ end
184
179
 
185
180
  def add_address(post, options)
186
181
  if address = options[:billing_address] || options[:address]
@@ -192,7 +187,7 @@ module ActiveMerchant #:nodoc:
192
187
  def add_customer_data(post, options)
193
188
  post[:CustomerEmail] = options[:email]
194
189
  end
195
-
190
+
196
191
  def add_invoice_data(post, options)
197
192
  post[:CustomerInvoiceRef] = options[:order_id]
198
193
  post[:CustomerInvoiceDescription] = options[:description]
@@ -202,10 +197,10 @@ module ActiveMerchant #:nodoc:
202
197
  post[:TrxnNumber] = nil
203
198
  post[:Option1] = nil
204
199
  post[:Option2] = nil
205
- post[:Option3] = nil
200
+ post[:Option3] = nil
206
201
  end
207
202
 
208
- def commit(money, parameters)
203
+ def commit(money, parameters)
209
204
  parameters[:TotalAmount] = amount(money)
210
205
 
211
206
  response = parse( ssl_post(gateway_url(parameters[:CVN], test?), post_data(parameters)) )
@@ -213,13 +208,13 @@ module ActiveMerchant #:nodoc:
213
208
  Response.new(success?(response), message_from(response[:ewaytrxnerror]), response,
214
209
  :authorization => response[:ewayauthcode],
215
210
  :test => /\(Test( CVN)? Gateway\)/ === response[:ewaytrxnerror]
216
- )
211
+ )
217
212
  end
218
-
213
+
219
214
  def success?(response)
220
215
  response[:ewaytrxnstatus] == "True"
221
216
  end
222
-
217
+
223
218
  # Parse eway response xml into a convinient hash
224
219
  def parse(xml)
225
220
  # "<?xml version=\"1.0\"?>".
@@ -233,10 +228,10 @@ module ActiveMerchant #:nodoc:
233
228
  # <ewayReturnAmount>10</ewayReturnAmount>
234
229
  # <ewayAuthCode>123456</ewayAuthCode>
235
230
  # <ewayTrxnReference>987654321</ewayTrxnReference>
236
- # </ewayResponse>
231
+ # </ewayResponse>
237
232
 
238
233
  response = {}
239
- xml = REXML::Document.new(xml)
234
+ xml = REXML::Document.new(xml)
240
235
  xml.elements.each('//ewayResponse/*') do |node|
241
236
 
242
237
  response[node.name.downcase.to_sym] = normalize(node.text)
@@ -244,20 +239,20 @@ module ActiveMerchant #:nodoc:
244
239
  end unless xml.root.nil?
245
240
 
246
241
  response
247
- end
242
+ end
248
243
 
249
244
  def post_data(parameters = {})
250
245
  parameters[:CustomerID] = @options[:login]
251
-
246
+
252
247
  xml = REXML::Document.new
253
248
  root = xml.add_element("ewaygateway")
254
-
249
+
255
250
  parameters.each do |key, value|
256
251
  root.add_element("eway#{key}").text = value
257
- end
252
+ end
258
253
  xml.to_s
259
254
  end
260
-
255
+
261
256
  def message_from(message)
262
257
  return '' if message.blank?
263
258
  MESSAGES[message[0,2]] || message
@@ -271,9 +266,9 @@ module ActiveMerchant #:nodoc:
271
266
  when "" then nil
272
267
  when "null" then nil
273
268
  else field
274
- end
269
+ end
275
270
  end
276
-
271
+
277
272
  def gateway_url(cvn, test)
278
273
  if cvn
279
274
  test ? self.test_cvn_url : self.live_cvn_url
@@ -281,7 +276,7 @@ module ActiveMerchant #:nodoc:
281
276
  test ? self.test_url : self.live_url
282
277
  end
283
278
  end
284
-
279
+
285
280
  end
286
281
  end
287
282
  end
@@ -3,71 +3,70 @@ module ActiveMerchant #:nodoc:
3
3
  class EwayManagedGateway < Gateway
4
4
  self.test_url = 'https://www.eway.com.au/gateway/ManagedPaymentService/test/managedCreditCardPayment.asmx'
5
5
  self.live_url = 'https://www.eway.com.au/gateway/ManagedPaymentService/managedCreditCardPayment.asmx'
6
-
6
+
7
7
  # The countries the gateway supports merchants from as 2 digit ISO country codes
8
8
  self.supported_countries = ['AU']
9
-
9
+
10
10
  # The card types supported by the payment gateway
11
11
  self.supported_cardtypes = [:visa, :master]
12
-
12
+
13
13
  self.default_currency = 'AUD'
14
-
14
+
15
15
  #accepted money format
16
16
  self.money_format = :cents
17
-
17
+
18
18
  # The homepage URL of the gateway
19
19
  self.homepage_url = 'http://www.eway.com.au/'
20
-
20
+
21
21
  # The name of the gateway
22
22
  self.display_name = 'eWay Managed Payments'
23
-
23
+
24
24
  def initialize(options = {})
25
25
  requires!(options, :login, :username, :password)
26
- @options = options
27
26
 
28
27
  # eWay returns 500 code for faults, which AM snaffles.
29
28
  # So, we tell it to allow them.
30
- @options[:ignore_http_status]=true
29
+ options[:ignore_http_status] = true
31
30
  super
32
- end
33
-
31
+ end
32
+
34
33
  # add a new customer CC to your eway account and return unique ManagedCustomerID
35
34
  # supports storing details required by eway see "add_creditcard" and "add_address"
36
35
  def store(creditcard, options = {})
37
36
  post = {}
38
-
37
+
39
38
  # Handle our required fields
40
39
  requires!(options, :billing_address)
41
40
 
42
41
  # Handle eWay specific required fields.
43
42
  billing_address = options[:billing_address]
44
43
  eway_requires!(billing_address)
45
-
44
+
46
45
  add_creditcard(post, creditcard)
47
46
  add_address(post, billing_address)
48
47
  add_misc_fields(post, options)
49
-
48
+
50
49
  commit("CreateCustomer", post)
51
50
  end
52
-
51
+
53
52
  def update(billing_id, creditcard, options={})
54
53
  post = {}
55
-
54
+
56
55
  # Handle our required fields
57
56
  requires!(options, :billing_address)
58
57
 
59
58
  # Handle eWay specific required fields.
60
59
  billing_address = options[:billing_address]
61
60
  eway_requires!(billing_address)
62
-
61
+
63
62
  post[:managedCustomerID]=billing_id
64
63
  add_creditcard(post, creditcard)
65
64
  add_address(post, billing_address)
66
65
  add_misc_fields(post, options)
67
-
66
+
68
67
  commit("UpdateCustomer", post)
69
68
  end
70
-
69
+
71
70
  # Process a payment in the given amount against the stored credit card given by billing_id
72
71
  #
73
72
  # ==== Parameters
@@ -81,39 +80,36 @@ module ActiveMerchant #:nodoc:
81
80
  # * <tt>:order_id</tt> -- The order number, passed to eWay as the "Invoice Reference"
82
81
  # * <tt>:invoice</tt> -- The invoice number, passed to eWay as the "Invoice Reference" unless :order_id is also given
83
82
  # * <tt>:description</tt> -- A description of the payment, passed to eWay as the "Invoice Description"
84
- def purchase(money, billing_id, options={})
85
- post = {}
83
+ def purchase(money, billing_id, options={})
84
+ post = {}
86
85
  post[:managedCustomerID] = billing_id.to_s
87
86
  post[:amount]=money
88
87
  add_invoice(post, options)
89
-
88
+
90
89
  commit("ProcessPayment", post)
91
90
  end
92
-
91
+
93
92
  # TODO: eWay API also provides QueryCustomer
94
93
  # TODO: eWay API also provides QueryPayment
95
-
96
- def test?
97
- @options[:test] || Base.gateway_mode == :test
98
- end
99
- private
94
+
95
+ private
100
96
 
101
97
  def eway_requires!(hash)
102
98
  raise ArgumentError.new("Missing eWay required parameter in `billing_address`: title") unless hash.has_key?(:title)
103
99
  raise ArgumentError.new("Missing eWay required parameter in `billing_address`: country") unless hash.has_key?(:country)
104
100
  end
105
-
106
- def add_address(post, address)
101
+
102
+ def add_address(post, address)
107
103
  post[:Address] = address[:address1].to_s
108
104
  post[:Phone] = address[:phone].to_s
109
- post[:PostCode] = address[:zip].to_s
105
+ post[:PostCode] = address[:zip].to_s
110
106
  post[:Suburb] = address[:city].to_s
111
107
  post[:Country] = address[:country].to_s.downcase
112
- post[:State] = address[:state].to_s
108
+ post[:State] = address[:state].to_s
113
109
  post[:Mobile] = address[:mobile].to_s
114
110
  post[:Fax] = address[:fax].to_s
115
111
  end
116
-
112
+
117
113
  def add_misc_fields(post, options)
118
114
  post[:CustomerRef]=options[:billing_address][:customer_ref] || options[:customer]
119
115
  post[:Title]=options[:billing_address][:title]
@@ -123,13 +119,13 @@ private
123
119
  post[:URL]=options[:billing_address][:url]
124
120
  post[:Comments]=options[:description]
125
121
  end
126
-
122
+
127
123
  def add_invoice(post, options)
128
124
  post[:invoiceReference] = options[:order_id] || options[:invoice]
129
125
  post[:invoiceDescription] = options[:description]
130
126
  end
131
-
132
-
127
+
128
+
133
129
  # add credit card details to be stored by eway. NOTE eway requires "title" field
134
130
  def add_creditcard(post, creditcard)
135
131
  post[:CCNumber] = creditcard.number
@@ -139,7 +135,7 @@ private
139
135
  post[:FirstName] = creditcard.first_name
140
136
  post[:LastName] = creditcard.last_name
141
137
  end
142
-
138
+
143
139
  def parse(body)
144
140
  reply = {}
145
141
  xml = REXML::Document.new(body)
@@ -175,23 +171,23 @@ private
175
171
  end
176
172
  return reply
177
173
  end
178
-
174
+
179
175
  def parse_fault(node)
180
176
  reply={}
181
177
  reply[:message]=REXML::XPath.first(node, '//soap:Reason/soap:Text').text
182
178
  reply[:success]=false
183
179
  reply
184
180
  end
185
-
181
+
186
182
  def parse_purchase(node)
187
183
  reply={}
188
184
  reply[:message]=REXML::XPath.first(node, '//ewayTrxnError').text
189
185
  reply[:success]=(REXML::XPath.first(node, '//ewayTrxnStatus').text == 'True')
190
186
  reply[:auth_code]=REXML::XPath.first(node, '//ewayAuthCode').text
191
- reply[:transaction_number]=REXML::XPath.first(node, '//ewayTrxnNumber').text
187
+ reply[:transaction_number]=REXML::XPath.first(node, '//ewayTrxnNumber').text
192
188
  reply
193
189
  end
194
-
190
+
195
191
  def commit(action, post)
196
192
  raw = begin
197
193
  ssl_post(test? ? self.test_url : self.live_url, soap_request(post, action), 'Content-Type' => 'application/soap+xml; charset=utf-8')
@@ -199,23 +195,23 @@ private
199
195
  e.response.body
200
196
  end
201
197
  response = parse(raw)
202
-
203
- EwayResponse.new(response[:success], response[:message], response,
198
+
199
+ EwayResponse.new(response[:success], response[:message], response,
204
200
  :test => test?,
205
201
  :authorization => response[:auth_code]
206
202
  )
207
203
  end
208
-
204
+
209
205
  # Where we build the full SOAP 1.2 request using builder
210
206
  def soap_request(arguments, action)
211
207
  # eWay demands all fields be sent, but contain an empty string if blank
212
208
  post = case action
213
209
  when 'ProcessPayment'
214
210
  default_payment_fields.merge(arguments)
215
- else
211
+ else
216
212
  default_customer_fields.merge(arguments)
217
213
  end
218
-
214
+
219
215
  xml = Builder::XmlMarkup.new :indent => 2
220
216
  xml.instruct!
221
217
  xml.tag! 'soap12:Envelope', {'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance', 'xmlns:xsd' => 'http://www.w3.org/2001/XMLSchema', 'xmlns:soap12' => 'http://www.w3.org/2003/05/soap-envelope'} do
@@ -230,13 +226,13 @@ private
230
226
  x.tag! "#{action}", {'xmlns' => 'https://www.eway.com.au/gateway/managedpayment'} do |y|
231
227
  post.each do |key, value|
232
228
  y.tag! "#{key}", "#{value}"
233
- end
229
+ end
234
230
  end
235
231
  end
236
232
  end
237
233
  xml.target!
238
234
  end
239
-
235
+
240
236
  def default_customer_fields
241
237
  hash={}
242
238
  %w( CustomerRef Title FirstName LastName Company JobDesc Email Address Suburb State PostCode Country Phone Mobile Fax URL Comments CCNumber CCNameOnCard CCExpiryMonth CCExpiryYear ).each do |field|
@@ -244,7 +240,7 @@ private
244
240
  end
245
241
  return hash
246
242
  end
247
-
243
+
248
244
  def default_payment_fields
249
245
  hash={}
250
246
  %w( managedCustomerID amount invoiceReference invoiceDescription ).each do |field|
@@ -252,14 +248,14 @@ private
252
248
  end
253
249
  return hash
254
250
  end
255
-
251
+
256
252
  class EwayResponse < Response
257
253
  # add a method to response so we can easily get the eway token "ManagedCustomerID"
258
254
  def token
259
255
  @params['CreateCustomerResult']
260
256
  end
261
257
  end
262
-
258
+
263
259
  end
264
260
  end
265
261
  end