n8_activemerchant 1.9.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (158) hide show
  1. data/CHANGELOG +574 -0
  2. data/CONTRIBUTORS +175 -0
  3. data/MIT-LICENSE +20 -0
  4. data/README.rdoc +151 -0
  5. data/gem-public_cert.pem +20 -0
  6. data/lib/active_merchant.rb +49 -0
  7. data/lib/active_merchant/billing.rb +9 -0
  8. data/lib/active_merchant/billing/avs_result.rb +98 -0
  9. data/lib/active_merchant/billing/base.rb +57 -0
  10. data/lib/active_merchant/billing/check.rb +68 -0
  11. data/lib/active_merchant/billing/credit_card.rb +161 -0
  12. data/lib/active_merchant/billing/credit_card_formatting.rb +21 -0
  13. data/lib/active_merchant/billing/credit_card_methods.rb +125 -0
  14. data/lib/active_merchant/billing/cvv_result.rb +38 -0
  15. data/lib/active_merchant/billing/expiry_date.rb +34 -0
  16. data/lib/active_merchant/billing/gateway.rb +169 -0
  17. data/lib/active_merchant/billing/gateways.rb +18 -0
  18. data/lib/active_merchant/billing/gateways/authorize_net.rb +654 -0
  19. data/lib/active_merchant/billing/gateways/authorize_net_cim.rb +736 -0
  20. data/lib/active_merchant/billing/gateways/beanstream.rb +102 -0
  21. data/lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb +244 -0
  22. data/lib/active_merchant/billing/gateways/beanstream_interac.rb +54 -0
  23. data/lib/active_merchant/billing/gateways/bogus.rb +102 -0
  24. data/lib/active_merchant/billing/gateways/braintree.rb +17 -0
  25. data/lib/active_merchant/billing/gateways/braintree/braintree_common.rb +9 -0
  26. data/lib/active_merchant/billing/gateways/braintree_blue.rb +210 -0
  27. data/lib/active_merchant/billing/gateways/braintree_orange.rb +17 -0
  28. data/lib/active_merchant/billing/gateways/card_stream.rb +230 -0
  29. data/lib/active_merchant/billing/gateways/cyber_source.rb +406 -0
  30. data/lib/active_merchant/billing/gateways/data_cash.rb +593 -0
  31. data/lib/active_merchant/billing/gateways/efsnet.rb +229 -0
  32. data/lib/active_merchant/billing/gateways/elavon.rb +134 -0
  33. data/lib/active_merchant/billing/gateways/epay.rb +263 -0
  34. data/lib/active_merchant/billing/gateways/eway.rb +277 -0
  35. data/lib/active_merchant/billing/gateways/exact.rb +222 -0
  36. data/lib/active_merchant/billing/gateways/first_pay.rb +172 -0
  37. data/lib/active_merchant/billing/gateways/garanti.rb +222 -0
  38. data/lib/active_merchant/billing/gateways/inspire.rb +221 -0
  39. data/lib/active_merchant/billing/gateways/instapay.rb +164 -0
  40. data/lib/active_merchant/billing/gateways/iridium.rb +253 -0
  41. data/lib/active_merchant/billing/gateways/jetpay.rb +270 -0
  42. data/lib/active_merchant/billing/gateways/linkpoint.rb +449 -0
  43. data/lib/active_merchant/billing/gateways/merchant_e_solutions.rb +154 -0
  44. data/lib/active_merchant/billing/gateways/merchant_ware.rb +283 -0
  45. data/lib/active_merchant/billing/gateways/modern_payments.rb +36 -0
  46. data/lib/active_merchant/billing/gateways/modern_payments_cim.rb +220 -0
  47. data/lib/active_merchant/billing/gateways/moneris.rb +205 -0
  48. data/lib/active_merchant/billing/gateways/net_registry.rb +189 -0
  49. data/lib/active_merchant/billing/gateways/netaxept.rb +234 -0
  50. data/lib/active_merchant/billing/gateways/netbilling.rb +168 -0
  51. data/lib/active_merchant/billing/gateways/ogone.rb +279 -0
  52. data/lib/active_merchant/billing/gateways/pay_junction.rb +392 -0
  53. data/lib/active_merchant/billing/gateways/pay_secure.rb +120 -0
  54. data/lib/active_merchant/billing/gateways/paybox_direct.rb +203 -0
  55. data/lib/active_merchant/billing/gateways/payflow.rb +236 -0
  56. data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +207 -0
  57. data/lib/active_merchant/billing/gateways/payflow/payflow_express_response.rb +39 -0
  58. data/lib/active_merchant/billing/gateways/payflow/payflow_response.rb +13 -0
  59. data/lib/active_merchant/billing/gateways/payflow_express.rb +138 -0
  60. data/lib/active_merchant/billing/gateways/payflow_express_uk.rb +15 -0
  61. data/lib/active_merchant/billing/gateways/payflow_uk.rb +21 -0
  62. data/lib/active_merchant/billing/gateways/payment_express.rb +230 -0
  63. data/lib/active_merchant/billing/gateways/paypal.rb +121 -0
  64. data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +326 -0
  65. data/lib/active_merchant/billing/gateways/paypal/paypal_express_response.rb +38 -0
  66. data/lib/active_merchant/billing/gateways/paypal_ca.rb +13 -0
  67. data/lib/active_merchant/billing/gateways/paypal_express.rb +145 -0
  68. data/lib/active_merchant/billing/gateways/paypal_express_common.rb +20 -0
  69. data/lib/active_merchant/billing/gateways/paysimple/paysimple.rb +333 -0
  70. data/lib/active_merchant/billing/gateways/paysimple/usaepay.wsdl +1596 -0
  71. data/lib/active_merchant/billing/gateways/plugnpay.rb +292 -0
  72. data/lib/active_merchant/billing/gateways/psigate.rb +214 -0
  73. data/lib/active_merchant/billing/gateways/psl_card.rb +304 -0
  74. data/lib/active_merchant/billing/gateways/quickpay.rb +213 -0
  75. data/lib/active_merchant/billing/gateways/realex.rb +200 -0
  76. data/lib/active_merchant/billing/gateways/sage.rb +146 -0
  77. data/lib/active_merchant/billing/gateways/sage/sage_bankcard.rb +88 -0
  78. data/lib/active_merchant/billing/gateways/sage/sage_core.rb +116 -0
  79. data/lib/active_merchant/billing/gateways/sage/sage_virtual_check.rb +97 -0
  80. data/lib/active_merchant/billing/gateways/sage_pay.rb +315 -0
  81. data/lib/active_merchant/billing/gateways/sallie_mae.rb +144 -0
  82. data/lib/active_merchant/billing/gateways/secure_net.rb +330 -0
  83. data/lib/active_merchant/billing/gateways/secure_pay.rb +31 -0
  84. data/lib/active_merchant/billing/gateways/secure_pay_au.rb +157 -0
  85. data/lib/active_merchant/billing/gateways/secure_pay_tech.rb +113 -0
  86. data/lib/active_merchant/billing/gateways/skip_jack.rb +453 -0
  87. data/lib/active_merchant/billing/gateways/smart_ps.rb +265 -0
  88. data/lib/active_merchant/billing/gateways/trans_first.rb +127 -0
  89. data/lib/active_merchant/billing/gateways/transax.rb +25 -0
  90. data/lib/active_merchant/billing/gateways/trust_commerce.rb +418 -0
  91. data/lib/active_merchant/billing/gateways/usa_epay.rb +194 -0
  92. data/lib/active_merchant/billing/gateways/usa_epay_soap.rb +154 -0
  93. data/lib/active_merchant/billing/gateways/verifi.rb +228 -0
  94. data/lib/active_merchant/billing/gateways/viaklix.rb +189 -0
  95. data/lib/active_merchant/billing/gateways/wirecard.rb +318 -0
  96. data/lib/active_merchant/billing/integrations.rb +17 -0
  97. data/lib/active_merchant/billing/integrations/action_view_helper.rb +68 -0
  98. data/lib/active_merchant/billing/integrations/bogus.rb +23 -0
  99. data/lib/active_merchant/billing/integrations/bogus/helper.rb +17 -0
  100. data/lib/active_merchant/billing/integrations/bogus/notification.rb +11 -0
  101. data/lib/active_merchant/billing/integrations/bogus/return.rb +10 -0
  102. data/lib/active_merchant/billing/integrations/chronopay.rb +23 -0
  103. data/lib/active_merchant/billing/integrations/chronopay/helper.rb +120 -0
  104. data/lib/active_merchant/billing/integrations/chronopay/notification.rb +158 -0
  105. data/lib/active_merchant/billing/integrations/chronopay/return.rb +10 -0
  106. data/lib/active_merchant/billing/integrations/direc_pay.rb +41 -0
  107. data/lib/active_merchant/billing/integrations/direc_pay/helper.rb +188 -0
  108. data/lib/active_merchant/billing/integrations/direc_pay/notification.rb +76 -0
  109. data/lib/active_merchant/billing/integrations/direc_pay/return.rb +32 -0
  110. data/lib/active_merchant/billing/integrations/direc_pay/status.rb +37 -0
  111. data/lib/active_merchant/billing/integrations/gestpay.rb +25 -0
  112. data/lib/active_merchant/billing/integrations/gestpay/common.rb +42 -0
  113. data/lib/active_merchant/billing/integrations/gestpay/helper.rb +70 -0
  114. data/lib/active_merchant/billing/integrations/gestpay/notification.rb +85 -0
  115. data/lib/active_merchant/billing/integrations/gestpay/return.rb +10 -0
  116. data/lib/active_merchant/billing/integrations/helper.rb +96 -0
  117. data/lib/active_merchant/billing/integrations/hi_trust.rb +27 -0
  118. data/lib/active_merchant/billing/integrations/hi_trust/helper.rb +58 -0
  119. data/lib/active_merchant/billing/integrations/hi_trust/notification.rb +59 -0
  120. data/lib/active_merchant/billing/integrations/hi_trust/return.rb +67 -0
  121. data/lib/active_merchant/billing/integrations/nochex.rb +88 -0
  122. data/lib/active_merchant/billing/integrations/nochex/helper.rb +68 -0
  123. data/lib/active_merchant/billing/integrations/nochex/notification.rb +94 -0
  124. data/lib/active_merchant/billing/integrations/nochex/return.rb +10 -0
  125. data/lib/active_merchant/billing/integrations/notification.rb +62 -0
  126. data/lib/active_merchant/billing/integrations/paypal.rb +39 -0
  127. data/lib/active_merchant/billing/integrations/paypal/helper.rb +119 -0
  128. data/lib/active_merchant/billing/integrations/paypal/notification.rb +154 -0
  129. data/lib/active_merchant/billing/integrations/paypal/return.rb +10 -0
  130. data/lib/active_merchant/billing/integrations/quickpay.rb +17 -0
  131. data/lib/active_merchant/billing/integrations/quickpay/helper.rb +72 -0
  132. data/lib/active_merchant/billing/integrations/quickpay/notification.rb +74 -0
  133. data/lib/active_merchant/billing/integrations/return.rb +37 -0
  134. data/lib/active_merchant/billing/integrations/sage_pay_form.rb +37 -0
  135. data/lib/active_merchant/billing/integrations/sage_pay_form/encryption.rb +33 -0
  136. data/lib/active_merchant/billing/integrations/sage_pay_form/helper.rb +109 -0
  137. data/lib/active_merchant/billing/integrations/sage_pay_form/notification.rb +204 -0
  138. data/lib/active_merchant/billing/integrations/sage_pay_form/return.rb +27 -0
  139. data/lib/active_merchant/billing/integrations/two_checkout.rb +23 -0
  140. data/lib/active_merchant/billing/integrations/two_checkout/helper.rb +59 -0
  141. data/lib/active_merchant/billing/integrations/two_checkout/notification.rb +114 -0
  142. data/lib/active_merchant/billing/integrations/two_checkout/return.rb +17 -0
  143. data/lib/active_merchant/billing/response.rb +32 -0
  144. data/lib/active_merchant/common.rb +14 -0
  145. data/lib/active_merchant/common/connection.rb +162 -0
  146. data/lib/active_merchant/common/country.rb +328 -0
  147. data/lib/active_merchant/common/error.rb +26 -0
  148. data/lib/active_merchant/common/post_data.rb +24 -0
  149. data/lib/active_merchant/common/posts_data.rb +61 -0
  150. data/lib/active_merchant/common/requires_parameters.rb +16 -0
  151. data/lib/active_merchant/common/utils.rb +18 -0
  152. data/lib/active_merchant/common/validateable.rb +76 -0
  153. data/lib/active_merchant/version.rb +3 -0
  154. data/lib/activemerchant.rb +1 -0
  155. data/lib/certs/cacert.pem +7815 -0
  156. data/lib/support/gateway_support.rb +58 -0
  157. data/lib/support/outbound_hosts.rb +25 -0
  158. metadata +270 -0
@@ -0,0 +1,277 @@
1
+ require 'rexml/document'
2
+
3
+ module ActiveMerchant #:nodoc:
4
+ module Billing #:nodoc:
5
+ # First, make sure you have everything setup correctly and all of your dependencies in place with:
6
+ #
7
+ # require 'rubygems'
8
+ # require 'active_merchant'
9
+ #
10
+ # ActiveMerchant expects the amounts to be given as an Integer in cents. In this case, $10 US becomes 1000.
11
+ #
12
+ # tendollar = 1000
13
+ #
14
+ # Next, create a credit card object using a TC approved test card.
15
+ #
16
+ # creditcard = ActiveMerchant::Billing::CreditCard.new(
17
+ # :number => '4111111111111111',
18
+ # :month => 8,
19
+ # :year => 2006,
20
+ # :first_name => 'Longbob',
21
+ # :last_name => 'Longsen'
22
+ # )
23
+ # options = {
24
+ # :order_id => '1230123',
25
+ # :email => 'bob@testbob.com',
26
+ # :address => { :address1 => '47 Bobway',
27
+ # :city => 'Bobville',
28
+ # :state => 'WA',
29
+ # :country => 'Australia',
30
+ # :zip => '2000'
31
+ # }
32
+ # :description => 'purchased items'
33
+ # }
34
+ #
35
+ # To finish setting up, create the active_merchant object you will be using, with the eWay gateway. If you have a
36
+ # functional eWay account, replace :login with your account info.
37
+ #
38
+ # gateway = ActiveMerchant::Billing::Base.gateway(:eway).new(:login => '87654321')
39
+ #
40
+ # Now we are ready to process our transaction
41
+ #
42
+ # response = gateway.purchase(tendollar, creditcard, options)
43
+ #
44
+ # Sending a transaction to TrustCommerce with active_merchant returns a Response object, which consistently allows you to:
45
+ #
46
+ # 1) Check whether the transaction was successful
47
+ #
48
+ # response.success?
49
+ #
50
+ # 2) Retrieve any message returned by eWay, either a "transaction was successful" note or an explanation of why the
51
+ # transaction was rejected.
52
+ #
53
+ # response.message
54
+ #
55
+ # 3) Retrieve and store the unique transaction ID returned by eWway, for use in referencing the transaction in the future.
56
+ #
57
+ # response.authorization
58
+ #
59
+ # This should be enough to get you started with eWay and active_merchant. For further information, review the methods
60
+ # below and the rest of active_merchant's documentation.
61
+
62
+ class EwayGateway < Gateway
63
+ TEST_URL = 'https://www.eway.com.au/gateway/xmltest/testpage.asp'
64
+ LIVE_URL = 'https://www.eway.com.au/gateway/xmlpayment.asp'
65
+
66
+ TEST_CVN_URL = 'https://www.eway.com.au/gateway_cvn/xmltest/testpage.asp'
67
+ LIVE_CVN_URL = 'https://www.eway.com.au/gateway_cvn/xmlpayment.asp'
68
+
69
+ MESSAGES = {
70
+ "00" => "Transaction Approved",
71
+ "01" => "Refer to Issuer",
72
+ "02" => "Refer to Issuer, special",
73
+ "03" => "No Merchant",
74
+ "04" => "Pick Up Card",
75
+ "05" => "Do Not Honour",
76
+ "06" => "Error",
77
+ "07" => "Pick Up Card, Special",
78
+ "08" => "Honour With Identification",
79
+ "09" => "Request In Progress",
80
+ "10" => "Approved For Partial Amount",
81
+ "11" => "Approved, VIP",
82
+ "12" => "Invalid Transaction",
83
+ "13" => "Invalid Amount",
84
+ "14" => "Invalid Card Number",
85
+ "15" => "No Issuer",
86
+ "16" => "Approved, Update Track 3",
87
+ "19" => "Re-enter Last Transaction",
88
+ "21" => "No Action Taken",
89
+ "22" => "Suspected Malfunction",
90
+ "23" => "Unacceptable Transaction Fee",
91
+ "25" => "Unable to Locate Record On File",
92
+ "30" => "Format Error",
93
+ "31" => "Bank Not Supported By Switch",
94
+ "33" => "Expired Card, Capture",
95
+ "34" => "Suspected Fraud, Retain Card",
96
+ "35" => "Card Acceptor, Contact Acquirer, Retain Card",
97
+ "36" => "Restricted Card, Retain Card",
98
+ "37" => "Contact Acquirer Security Department, Retain Card",
99
+ "38" => "PIN Tries Exceeded, Capture",
100
+ "39" => "No Credit Account",
101
+ "40" => "Function Not Supported",
102
+ "41" => "Lost Card",
103
+ "42" => "No Universal Account",
104
+ "43" => "Stolen Card",
105
+ "44" => "No Investment Account",
106
+ "51" => "Insufficient Funds",
107
+ "52" => "No Cheque Account",
108
+ "53" => "No Savings Account",
109
+ "54" => "Expired Card",
110
+ "55" => "Incorrect PIN",
111
+ "56" => "No Card Record",
112
+ "57" => "Function Not Permitted to Cardholder",
113
+ "58" => "Function Not Permitted to Terminal",
114
+ "59" => "Suspected Fraud",
115
+ "60" => "Acceptor Contact Acquirer",
116
+ "61" => "Exceeds Withdrawal Limit",
117
+ "62" => "Restricted Card",
118
+ "63" => "Security Violation",
119
+ "64" => "Original Amount Incorrect",
120
+ "66" => "Acceptor Contact Acquirer, Security",
121
+ "67" => "Capture Card",
122
+ "75" => "PIN Tries Exceeded",
123
+ "82" => "CVV Validation Error",
124
+ "90" => "Cutoff In Progress",
125
+ "91" => "Card Issuer Unavailable",
126
+ "92" => "Unable To Route Transaction",
127
+ "93" => "Cannot Complete, Violation Of The Law",
128
+ "94" => "Duplicate Transaction",
129
+ "96" => "System Error"
130
+ }
131
+
132
+ self.money_format = :cents
133
+ self.supported_countries = ['AU']
134
+ self.supported_cardtypes = [:visa, :master, :american_express]
135
+ self.homepage_url = 'http://www.eway.com.au/'
136
+ self.display_name = 'eWAY'
137
+
138
+ def initialize(options = {})
139
+ requires!(options, :login)
140
+ @options = options
141
+ super
142
+ end
143
+
144
+ # ewayCustomerEmail, ewayCustomerAddress, ewayCustomerPostcode
145
+ def purchase(money, creditcard, options = {})
146
+ requires!(options, :order_id)
147
+
148
+ post = {}
149
+ add_creditcard(post, creditcard)
150
+ add_address(post, options)
151
+ add_customer_data(post, options)
152
+ add_invoice_data(post, options)
153
+ # The request fails if all of the fields aren't present
154
+ add_optional_data(post)
155
+
156
+ commit(money, post)
157
+ end
158
+
159
+ def test?
160
+ @options[:test] || super
161
+ end
162
+
163
+ private
164
+ def add_creditcard(post, creditcard)
165
+ post[:CardNumber] = creditcard.number
166
+ post[:CardExpiryMonth] = sprintf("%.2i", creditcard.month)
167
+ post[:CardExpiryYear] = sprintf("%.4i", creditcard.year)[-2..-1]
168
+ post[:CustomerFirstName] = creditcard.first_name
169
+ post[:CustomerLastName] = creditcard.last_name
170
+ post[:CardHoldersName] = creditcard.name
171
+
172
+ post[:CVN] = creditcard.verification_value if creditcard.verification_value?
173
+ end
174
+
175
+ def add_address(post, options)
176
+ if address = options[:billing_address] || options[:address]
177
+ post[:CustomerAddress] = [ address[:address1], address[:address2], address[:city], address[:state], address[:country] ].compact.join(', ')
178
+ post[:CustomerPostcode] = address[:zip]
179
+ end
180
+ end
181
+
182
+ def add_customer_data(post, options)
183
+ post[:CustomerEmail] = options[:email]
184
+ end
185
+
186
+ def add_invoice_data(post, options)
187
+ post[:CustomerInvoiceRef] = options[:order_id]
188
+ post[:CustomerInvoiceDescription] = options[:description]
189
+ end
190
+
191
+ def add_optional_data(post)
192
+ post[:TrxnNumber] = nil
193
+ post[:Option1] = nil
194
+ post[:Option2] = nil
195
+ post[:Option3] = nil
196
+ end
197
+
198
+ def commit(money, parameters)
199
+ parameters[:TotalAmount] = amount(money)
200
+
201
+ response = parse( ssl_post(gateway_url(parameters[:CVN], test?), post_data(parameters)) )
202
+
203
+ Response.new(success?(response), message_from(response[:ewaytrxnerror]), response,
204
+ :authorization => response[:ewayauthcode],
205
+ :test => /\(Test( CVN)? Gateway\)/ === response[:ewaytrxnerror]
206
+ )
207
+ end
208
+
209
+ def success?(response)
210
+ response[:ewaytrxnstatus] == "True"
211
+ end
212
+
213
+ # Parse eway response xml into a convinient hash
214
+ def parse(xml)
215
+ # "<?xml version=\"1.0\"?>".
216
+ # <ewayResponse>
217
+ # <ewayTrxnError></ewayTrxnError>
218
+ # <ewayTrxnStatus>True</ewayTrxnStatus>
219
+ # <ewayTrxnNumber>10002</ewayTrxnNumber>
220
+ # <ewayTrxnOption1></ewayTrxnOption1>
221
+ # <ewayTrxnOption2></ewayTrxnOption2>
222
+ # <ewayTrxnOption3></ewayTrxnOption3>
223
+ # <ewayReturnAmount>10</ewayReturnAmount>
224
+ # <ewayAuthCode>123456</ewayAuthCode>
225
+ # <ewayTrxnReference>987654321</ewayTrxnReference>
226
+ # </ewayResponse>
227
+
228
+ response = {}
229
+ xml = REXML::Document.new(xml)
230
+ xml.elements.each('//ewayResponse/*') do |node|
231
+
232
+ response[node.name.downcase.to_sym] = normalize(node.text)
233
+
234
+ end unless xml.root.nil?
235
+
236
+ response
237
+ end
238
+
239
+ def post_data(parameters = {})
240
+ parameters[:CustomerID] = @options[:login]
241
+
242
+ xml = REXML::Document.new
243
+ root = xml.add_element("ewaygateway")
244
+
245
+ parameters.each do |key, value|
246
+ root.add_element("eway#{key}").text = value
247
+ end
248
+ xml.to_s
249
+ end
250
+
251
+ def message_from(message)
252
+ return '' if message.blank?
253
+ MESSAGES[message[0,2]] || message
254
+ end
255
+
256
+ # Make a ruby type out of the response string
257
+ def normalize(field)
258
+ case field
259
+ when "true" then true
260
+ when "false" then false
261
+ when "" then nil
262
+ when "null" then nil
263
+ else field
264
+ end
265
+ end
266
+
267
+ def gateway_url(cvn, test)
268
+ if cvn
269
+ test ? TEST_CVN_URL : LIVE_CVN_URL
270
+ else
271
+ test ? TEST_URL : LIVE_URL
272
+ end
273
+ end
274
+
275
+ end
276
+ end
277
+ end
@@ -0,0 +1,222 @@
1
+ module ActiveMerchant #:nodoc:
2
+ module Billing #:nodoc:
3
+ class ExactGateway < Gateway
4
+ URL = 'https://secure2.e-xact.com/vplug-in/transaction/rpc-enc/service.asmx'
5
+
6
+ API_VERSION = "8.5"
7
+
8
+ TEST_LOGINS = [ {:login => "A00049-01", :password => "test1"},
9
+ {:login => "A00427-01", :password => "testus"} ]
10
+
11
+ TRANSACTIONS = { :sale => "00",
12
+ :authorization => "01",
13
+ :capture => "32",
14
+ :credit => "34" }
15
+
16
+
17
+ ENVELOPE_NAMESPACES = { 'xmlns:xsd' => 'http://www.w3.org/2001/XMLSchema',
18
+ 'xmlns:env' => 'http://schemas.xmlsoap.org/soap/envelope/',
19
+ 'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance'
20
+ }
21
+
22
+ SEND_AND_COMMIT_ATTRIBUTES = { 'xmlns:n1' => "http://secure2.e-xact.com/vplug-in/transaction/rpc-enc/Request",
23
+ 'env:encodingStyle' => 'http://schemas.xmlsoap.org/soap/encoding/'
24
+ }
25
+
26
+ SEND_AND_COMMIT_SOURCE_ATTRIBUTES = { 'xmlns:n2' => 'http://secure2.e-xact.com/vplug-in/transaction/rpc-enc/encodedTypes',
27
+ 'xsi:type' => 'n2:Transaction'
28
+ }
29
+
30
+ POST_HEADERS = { 'soapAction' => "http://secure2.e-xact.com/vplug-in/transaction/rpc-enc/SendAndCommit",
31
+ 'Content-Type' => 'text/xml'
32
+ }
33
+
34
+ SUCCESS = "true"
35
+
36
+ SENSITIVE_FIELDS = [ :verification_str2, :expiry_date, :card_number ]
37
+
38
+ self.supported_cardtypes = [:visa, :master, :american_express, :jcb, :discover]
39
+ self.supported_countries = ['CA', 'US']
40
+ self.homepage_url = 'http://www.e-xact.com'
41
+ self.display_name = 'E-xact'
42
+
43
+ def initialize(options = {})
44
+ requires!(options, :login, :password)
45
+ @options = options
46
+
47
+ if TEST_LOGINS.include?( { :login => options[:login], :password => options[:password] } )
48
+ @test_mode = true
49
+ end
50
+
51
+ super
52
+ end
53
+
54
+ def test?
55
+ @test_mode || Base.gateway_mode == :test
56
+ end
57
+
58
+ def authorize(money, credit_card, options = {})
59
+ commit(:authorization, build_sale_or_authorization_request(money, credit_card, options))
60
+ end
61
+
62
+ def purchase(money, credit_card, options = {})
63
+ commit(:sale, build_sale_or_authorization_request(money, credit_card, options))
64
+ end
65
+
66
+ def capture(money, authorization, options = {})
67
+ commit(:capture, build_capture_or_credit_request(money, authorization, options))
68
+ end
69
+
70
+ def credit(money, authorization, options = {})
71
+ commit(:credit, build_capture_or_credit_request(money, authorization, options))
72
+ end
73
+
74
+ private
75
+ def build_request(action, body)
76
+ xml = Builder::XmlMarkup.new
77
+
78
+ xml.instruct!
79
+ xml.tag! 'env:Envelope', ENVELOPE_NAMESPACES do
80
+ xml.tag! 'env:Body' do
81
+ xml.tag! 'n1:SendAndCommit', SEND_AND_COMMIT_ATTRIBUTES do
82
+ xml.tag! 'SendAndCommitSource', SEND_AND_COMMIT_SOURCE_ATTRIBUTES do
83
+ add_credentials(xml)
84
+ add_transaction_type(xml, action)
85
+ xml << body
86
+ end
87
+ end
88
+ end
89
+ end
90
+ xml.target!
91
+ end
92
+
93
+ def build_sale_or_authorization_request(money, credit_card, options)
94
+ xml = Builder::XmlMarkup.new
95
+
96
+ add_amount(xml, money)
97
+ add_credit_card(xml, credit_card)
98
+ add_customer_data(xml, options)
99
+ add_invoice(xml, options)
100
+
101
+ xml.target!
102
+ end
103
+
104
+ def build_capture_or_credit_request(money, identification, options)
105
+ xml = Builder::XmlMarkup.new
106
+
107
+ add_identification(xml, identification)
108
+ add_amount(xml, money)
109
+ add_customer_data(xml, options)
110
+
111
+ xml.target!
112
+ end
113
+
114
+ def add_credentials(xml)
115
+ xml.tag! 'ExactID', @options[:login]
116
+ xml.tag! 'Password', @options[:password]
117
+ end
118
+
119
+ def add_transaction_type(xml, action)
120
+ xml.tag! 'Transaction_Type', TRANSACTIONS[action]
121
+ end
122
+
123
+ def add_identification(xml, identification)
124
+ authorization_num, transaction_tag = identification.split(';')
125
+
126
+ xml.tag! 'Authorization_Num', authorization_num
127
+ xml.tag! 'Transaction_Tag', transaction_tag
128
+ end
129
+
130
+ def add_amount(xml, money)
131
+ xml.tag! 'DollarAmount', amount(money)
132
+ end
133
+
134
+ def add_credit_card(xml, credit_card)
135
+ xml.tag! 'Card_Number', credit_card.number
136
+ xml.tag! 'Expiry_Date', expdate(credit_card)
137
+ xml.tag! 'CardHoldersName', credit_card.name
138
+
139
+ if credit_card.verification_value?
140
+ xml.tag! 'CVD_Presence_Ind', '1'
141
+ xml.tag! 'VerificationStr2', credit_card.verification_value
142
+ end
143
+ end
144
+
145
+ def add_customer_data(xml, options)
146
+ xml.tag! 'Customer_Ref', options[:customer]
147
+ xml.tag! 'Client_IP', options[:ip]
148
+ xml.tag! 'Client_Email', options[:email]
149
+ end
150
+
151
+ def add_address(xml, options)
152
+ if address = options[:billing_address] || options[:address]
153
+ xml.tag! 'ZipCode', address[:zip]
154
+ end
155
+ end
156
+
157
+ def add_invoice(xml, options)
158
+ xml.tag! 'Reference_No', options[:order_id]
159
+ xml.tag! 'Reference_3', options[:description]
160
+ end
161
+
162
+ def expdate(credit_card)
163
+ "#{format(credit_card.month, :two_digits)}#{format(credit_card.year, :two_digits)}"
164
+ end
165
+
166
+ def commit(action, request)
167
+ response = parse(ssl_post(URL, build_request(action, request), POST_HEADERS))
168
+
169
+ Response.new(successful?(response), message_from(response), response,
170
+ :test => test?,
171
+ :authorization => authorization_from(response),
172
+ :avs_result => { :code => response[:avs] },
173
+ :cvv_result => response[:cvv2]
174
+ )
175
+ end
176
+
177
+ def successful?(response)
178
+ response[:transaction_approved] == SUCCESS
179
+ end
180
+
181
+ def authorization_from(response)
182
+ if response[:authorization_num] && response[:transaction_tag]
183
+ "#{response[:authorization_num]};#{response[:transaction_tag]}"
184
+ else
185
+ ''
186
+ end
187
+ end
188
+
189
+ def message_from(response)
190
+ if response[:faultcode] && response[:faultstring]
191
+ response[:faultstring]
192
+ elsif response[:error_number] != '0'
193
+ response[:error_description]
194
+ else
195
+ result = response[:exact_message] || ''
196
+ result << " - #{response[:bank_message]}" unless response[:bank_message].blank?
197
+ result
198
+ end
199
+ end
200
+
201
+ def parse(xml)
202
+ response = {}
203
+ xml = REXML::Document.new(xml)
204
+
205
+ if root = REXML::XPath.first(xml, "//types:TransactionResult")
206
+ parse_elements(response, root)
207
+ elsif root = REXML::XPath.first(xml, "//soap:Fault")
208
+ parse_elements(response, root)
209
+ end
210
+
211
+ response.delete_if{ |k,v| SENSITIVE_FIELDS.include?(k) }
212
+ end
213
+
214
+ def parse_elements(response, root)
215
+ root.elements.to_a.each do |node|
216
+ response[node.name.gsub(/EXact/, 'Exact').underscore.to_sym] = (node.text || '').strip
217
+ end
218
+ end
219
+ end
220
+ end
221
+ end
222
+