activemerchant-kiddy 1.15.0.kiddy

Sign up to get free protection for your applications and to get access to all the features.
Files changed (184) hide show
  1. data/CHANGELOG +688 -0
  2. data/CONTRIBUTORS +233 -0
  3. data/MIT-LICENSE +20 -0
  4. data/README.rdoc +164 -0
  5. data/gem-public_cert.pem +20 -0
  6. data/lib/active_merchant/billing/avs_result.rb +98 -0
  7. data/lib/active_merchant/billing/base.rb +57 -0
  8. data/lib/active_merchant/billing/check.rb +68 -0
  9. data/lib/active_merchant/billing/credit_card.rb +172 -0
  10. data/lib/active_merchant/billing/credit_card_formatting.rb +21 -0
  11. data/lib/active_merchant/billing/credit_card_methods.rb +125 -0
  12. data/lib/active_merchant/billing/cvv_result.rb +38 -0
  13. data/lib/active_merchant/billing/expiry_date.rb +34 -0
  14. data/lib/active_merchant/billing/gateway.rb +170 -0
  15. data/lib/active_merchant/billing/gateways/authorize_net.rb +671 -0
  16. data/lib/active_merchant/billing/gateways/authorize_net_cim.rb +858 -0
  17. data/lib/active_merchant/billing/gateways/barclays_epdq.rb +309 -0
  18. data/lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb +282 -0
  19. data/lib/active_merchant/billing/gateways/beanstream.rb +139 -0
  20. data/lib/active_merchant/billing/gateways/beanstream_interac.rb +54 -0
  21. data/lib/active_merchant/billing/gateways/blue_pay.rb +11 -0
  22. data/lib/active_merchant/billing/gateways/bogus.rb +132 -0
  23. data/lib/active_merchant/billing/gateways/braintree/braintree_common.rb +9 -0
  24. data/lib/active_merchant/billing/gateways/braintree.rb +17 -0
  25. data/lib/active_merchant/billing/gateways/braintree_blue.rb +293 -0
  26. data/lib/active_merchant/billing/gateways/braintree_orange.rb +17 -0
  27. data/lib/active_merchant/billing/gateways/card_stream.rb +230 -0
  28. data/lib/active_merchant/billing/gateways/cyber_source.rb +410 -0
  29. data/lib/active_merchant/billing/gateways/data_cash.rb +597 -0
  30. data/lib/active_merchant/billing/gateways/efsnet.rb +235 -0
  31. data/lib/active_merchant/billing/gateways/elavon.rb +134 -0
  32. data/lib/active_merchant/billing/gateways/epay.rb +268 -0
  33. data/lib/active_merchant/billing/gateways/eway.rb +277 -0
  34. data/lib/active_merchant/billing/gateways/eway_managed.rb +231 -0
  35. data/lib/active_merchant/billing/gateways/exact.rb +222 -0
  36. data/lib/active_merchant/billing/gateways/federated_canada.rb +168 -0
  37. data/lib/active_merchant/billing/gateways/first_pay.rb +177 -0
  38. data/lib/active_merchant/billing/gateways/garanti.rb +262 -0
  39. data/lib/active_merchant/billing/gateways/ideal/ideal_base.rb +250 -0
  40. data/lib/active_merchant/billing/gateways/ideal/ideal_rabobank.pem +13 -0
  41. data/lib/active_merchant/billing/gateways/ideal/ideal_response.rb +29 -0
  42. data/lib/active_merchant/billing/gateways/ideal_rabobank.rb +55 -0
  43. data/lib/active_merchant/billing/gateways/inspire.rb +221 -0
  44. data/lib/active_merchant/billing/gateways/instapay.rb +164 -0
  45. data/lib/active_merchant/billing/gateways/iridium.rb +258 -0
  46. data/lib/active_merchant/billing/gateways/jetpay.rb +276 -0
  47. data/lib/active_merchant/billing/gateways/linkpoint.rb +454 -0
  48. data/lib/active_merchant/billing/gateways/merchant_e_solutions.rb +156 -0
  49. data/lib/active_merchant/billing/gateways/merchant_ware.rb +289 -0
  50. data/lib/active_merchant/billing/gateways/modern_payments.rb +36 -0
  51. data/lib/active_merchant/billing/gateways/modern_payments_cim.rb +220 -0
  52. data/lib/active_merchant/billing/gateways/moneris.rb +209 -0
  53. data/lib/active_merchant/billing/gateways/net_registry.rb +189 -0
  54. data/lib/active_merchant/billing/gateways/netaxept.rb +239 -0
  55. data/lib/active_merchant/billing/gateways/netbilling.rb +168 -0
  56. data/lib/active_merchant/billing/gateways/nmi.rb +13 -0
  57. data/lib/active_merchant/billing/gateways/ogone.rb +292 -0
  58. data/lib/active_merchant/billing/gateways/orbital/orbital_soft_descriptors.rb +46 -0
  59. data/lib/active_merchant/billing/gateways/orbital.rb +317 -0
  60. data/lib/active_merchant/billing/gateways/pay_junction.rb +392 -0
  61. data/lib/active_merchant/billing/gateways/pay_secure.rb +120 -0
  62. data/lib/active_merchant/billing/gateways/paybox_direct.rb +207 -0
  63. data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +207 -0
  64. data/lib/active_merchant/billing/gateways/payflow/payflow_express_response.rb +39 -0
  65. data/lib/active_merchant/billing/gateways/payflow/payflow_response.rb +13 -0
  66. data/lib/active_merchant/billing/gateways/payflow.rb +253 -0
  67. data/lib/active_merchant/billing/gateways/payflow_express.rb +222 -0
  68. data/lib/active_merchant/billing/gateways/payflow_express_uk.rb +15 -0
  69. data/lib/active_merchant/billing/gateways/payflow_uk.rb +21 -0
  70. data/lib/active_merchant/billing/gateways/payment_express.rb +235 -0
  71. data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +351 -0
  72. data/lib/active_merchant/billing/gateways/paypal/paypal_express_response.rb +49 -0
  73. data/lib/active_merchant/billing/gateways/paypal.rb +121 -0
  74. data/lib/active_merchant/billing/gateways/paypal_ca.rb +13 -0
  75. data/lib/active_merchant/billing/gateways/paypal_express.rb +177 -0
  76. data/lib/active_merchant/billing/gateways/paypal_express_common.rb +25 -0
  77. data/lib/active_merchant/billing/gateways/plugnpay.rb +298 -0
  78. data/lib/active_merchant/billing/gateways/psigate.rb +219 -0
  79. data/lib/active_merchant/billing/gateways/psl_card.rb +304 -0
  80. data/lib/active_merchant/billing/gateways/qbms.rb +295 -0
  81. data/lib/active_merchant/billing/gateways/quantum.rb +282 -0
  82. data/lib/active_merchant/billing/gateways/quickpay.rb +218 -0
  83. data/lib/active_merchant/billing/gateways/realex.rb +311 -0
  84. data/lib/active_merchant/billing/gateways/sage/sage_bankcard.rb +88 -0
  85. data/lib/active_merchant/billing/gateways/sage/sage_core.rb +116 -0
  86. data/lib/active_merchant/billing/gateways/sage/sage_virtual_check.rb +97 -0
  87. data/lib/active_merchant/billing/gateways/sage.rb +146 -0
  88. data/lib/active_merchant/billing/gateways/sage_pay.rb +320 -0
  89. data/lib/active_merchant/billing/gateways/sallie_mae.rb +144 -0
  90. data/lib/active_merchant/billing/gateways/secure_net.rb +330 -0
  91. data/lib/active_merchant/billing/gateways/secure_pay.rb +31 -0
  92. data/lib/active_merchant/billing/gateways/secure_pay_au.rb +193 -0
  93. data/lib/active_merchant/billing/gateways/secure_pay_tech.rb +113 -0
  94. data/lib/active_merchant/billing/gateways/skip_jack.rb +453 -0
  95. data/lib/active_merchant/billing/gateways/smart_ps.rb +271 -0
  96. data/lib/active_merchant/billing/gateways/trans_first.rb +127 -0
  97. data/lib/active_merchant/billing/gateways/transax.rb +25 -0
  98. data/lib/active_merchant/billing/gateways/trust_commerce.rb +423 -0
  99. data/lib/active_merchant/billing/gateways/usa_epay.rb +194 -0
  100. data/lib/active_merchant/billing/gateways/verifi.rb +233 -0
  101. data/lib/active_merchant/billing/gateways/viaklix.rb +189 -0
  102. data/lib/active_merchant/billing/gateways/wirecard.rb +318 -0
  103. data/lib/active_merchant/billing/gateways/worldpay.rb +280 -0
  104. data/lib/active_merchant/billing/gateways.rb +18 -0
  105. data/lib/active_merchant/billing/integrations/action_view_helper.rb +68 -0
  106. data/lib/active_merchant/billing/integrations/bogus/helper.rb +17 -0
  107. data/lib/active_merchant/billing/integrations/bogus/notification.rb +11 -0
  108. data/lib/active_merchant/billing/integrations/bogus/return.rb +10 -0
  109. data/lib/active_merchant/billing/integrations/bogus.rb +23 -0
  110. data/lib/active_merchant/billing/integrations/chronopay/helper.rb +120 -0
  111. data/lib/active_merchant/billing/integrations/chronopay/notification.rb +158 -0
  112. data/lib/active_merchant/billing/integrations/chronopay/return.rb +10 -0
  113. data/lib/active_merchant/billing/integrations/chronopay.rb +23 -0
  114. data/lib/active_merchant/billing/integrations/direc_pay/helper.rb +200 -0
  115. data/lib/active_merchant/billing/integrations/direc_pay/notification.rb +76 -0
  116. data/lib/active_merchant/billing/integrations/direc_pay/return.rb +32 -0
  117. data/lib/active_merchant/billing/integrations/direc_pay/status.rb +37 -0
  118. data/lib/active_merchant/billing/integrations/direc_pay.rb +41 -0
  119. data/lib/active_merchant/billing/integrations/directebanking/helper.rb +90 -0
  120. data/lib/active_merchant/billing/integrations/directebanking/notification.rb +120 -0
  121. data/lib/active_merchant/billing/integrations/directebanking/return.rb +11 -0
  122. data/lib/active_merchant/billing/integrations/directebanking.rb +47 -0
  123. data/lib/active_merchant/billing/integrations/gestpay/common.rb +42 -0
  124. data/lib/active_merchant/billing/integrations/gestpay/helper.rb +70 -0
  125. data/lib/active_merchant/billing/integrations/gestpay/notification.rb +85 -0
  126. data/lib/active_merchant/billing/integrations/gestpay/return.rb +10 -0
  127. data/lib/active_merchant/billing/integrations/gestpay.rb +25 -0
  128. data/lib/active_merchant/billing/integrations/helper.rb +96 -0
  129. data/lib/active_merchant/billing/integrations/hi_trust/helper.rb +58 -0
  130. data/lib/active_merchant/billing/integrations/hi_trust/notification.rb +59 -0
  131. data/lib/active_merchant/billing/integrations/hi_trust/return.rb +67 -0
  132. data/lib/active_merchant/billing/integrations/hi_trust.rb +27 -0
  133. data/lib/active_merchant/billing/integrations/moneybookers/helper.rb +48 -0
  134. data/lib/active_merchant/billing/integrations/moneybookers/notification.rb +129 -0
  135. data/lib/active_merchant/billing/integrations/moneybookers.rb +26 -0
  136. data/lib/active_merchant/billing/integrations/nochex/helper.rb +68 -0
  137. data/lib/active_merchant/billing/integrations/nochex/notification.rb +94 -0
  138. data/lib/active_merchant/billing/integrations/nochex/return.rb +10 -0
  139. data/lib/active_merchant/billing/integrations/nochex.rb +88 -0
  140. data/lib/active_merchant/billing/integrations/notification.rb +62 -0
  141. data/lib/active_merchant/billing/integrations/paypal/helper.rb +119 -0
  142. data/lib/active_merchant/billing/integrations/paypal/notification.rb +154 -0
  143. data/lib/active_merchant/billing/integrations/paypal/return.rb +10 -0
  144. data/lib/active_merchant/billing/integrations/paypal.rb +39 -0
  145. data/lib/active_merchant/billing/integrations/quickpay/helper.rb +72 -0
  146. data/lib/active_merchant/billing/integrations/quickpay/notification.rb +74 -0
  147. data/lib/active_merchant/billing/integrations/quickpay.rb +21 -0
  148. data/lib/active_merchant/billing/integrations/return.rb +42 -0
  149. data/lib/active_merchant/billing/integrations/sage_pay_form/encryption.rb +33 -0
  150. data/lib/active_merchant/billing/integrations/sage_pay_form/helper.rb +111 -0
  151. data/lib/active_merchant/billing/integrations/sage_pay_form/notification.rb +210 -0
  152. data/lib/active_merchant/billing/integrations/sage_pay_form/return.rb +31 -0
  153. data/lib/active_merchant/billing/integrations/sage_pay_form.rb +37 -0
  154. data/lib/active_merchant/billing/integrations/two_checkout/helper.rb +59 -0
  155. data/lib/active_merchant/billing/integrations/two_checkout/notification.rb +114 -0
  156. data/lib/active_merchant/billing/integrations/two_checkout/return.rb +17 -0
  157. data/lib/active_merchant/billing/integrations/two_checkout.rb +23 -0
  158. data/lib/active_merchant/billing/integrations/valitor/helper.rb +86 -0
  159. data/lib/active_merchant/billing/integrations/valitor/notification.rb +13 -0
  160. data/lib/active_merchant/billing/integrations/valitor/response_fields.rb +88 -0
  161. data/lib/active_merchant/billing/integrations/valitor/return.rb +13 -0
  162. data/lib/active_merchant/billing/integrations/valitor.rb +33 -0
  163. data/lib/active_merchant/billing/integrations/world_pay/helper.rb +100 -0
  164. data/lib/active_merchant/billing/integrations/world_pay/notification.rb +160 -0
  165. data/lib/active_merchant/billing/integrations/world_pay.rb +38 -0
  166. data/lib/active_merchant/billing/integrations.rb +17 -0
  167. data/lib/active_merchant/billing/response.rb +32 -0
  168. data/lib/active_merchant/billing.rb +9 -0
  169. data/lib/active_merchant/common/connection.rb +177 -0
  170. data/lib/active_merchant/common/country.rb +328 -0
  171. data/lib/active_merchant/common/error.rb +26 -0
  172. data/lib/active_merchant/common/post_data.rb +24 -0
  173. data/lib/active_merchant/common/posts_data.rb +63 -0
  174. data/lib/active_merchant/common/requires_parameters.rb +16 -0
  175. data/lib/active_merchant/common/utils.rb +22 -0
  176. data/lib/active_merchant/common/validateable.rb +81 -0
  177. data/lib/active_merchant/common.rb +14 -0
  178. data/lib/active_merchant/version.rb +3 -0
  179. data/lib/active_merchant.rb +50 -0
  180. data/lib/activemerchant.rb +1 -0
  181. data/lib/certs/cacert.pem +7815 -0
  182. data/lib/support/gateway_support.rb +58 -0
  183. data/lib/support/outbound_hosts.rb +25 -0
  184. metadata +273 -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,231 @@
1
+ module ActiveMerchant #:nodoc:
2
+ module Billing #:nodoc:
3
+ class EwayManagedGateway < Gateway
4
+ TEST_URL = 'https://www.eway.com.au/gateway/ManagedPaymentService/test/managedCreditCardPayment.asmx'
5
+ LIVE_URL = 'https://www.eway.com.au/gateway/ManagedPaymentService/managedCreditCardPayment.asmx'
6
+
7
+ # The countries the gateway supports merchants from as 2 digit ISO country codes
8
+ self.supported_countries = ['AU']
9
+
10
+ # The card types supported by the payment gateway
11
+ self.supported_cardtypes = [:visa, :master]
12
+
13
+ self.default_currency = 'AUD'
14
+
15
+ #accepted money format
16
+ self.money_format = :cents
17
+
18
+ # The homepage URL of the gateway
19
+ self.homepage_url = 'http://www.eway.com.au/'
20
+
21
+ # The name of the gateway
22
+ self.display_name = 'eWay Managed Payments'
23
+
24
+ def initialize(options = {})
25
+ requires!(options, :login, :username, :password)
26
+ @options = options
27
+
28
+ # eWay returns 500 code for faults, which AM snaffles.
29
+ # So, we tell it to allow them.
30
+ @options[:ignore_http_status]=true
31
+ super
32
+ end
33
+
34
+ # add a new customer CC to your eway account and return unique ManagedCustomerID
35
+ # supports storing details required by eway see "add_creditcard" and "add_address"
36
+ def store(creditcard, options = {})
37
+ post = {}
38
+
39
+ # Handle our required fields
40
+ requires!(options, :billing_address)
41
+
42
+ # Handle eWay specific required fields.
43
+ billing_address = options[:billing_address]
44
+ eway_requires!(billing_address)
45
+
46
+ add_creditcard(post, creditcard)
47
+ add_address(post, billing_address)
48
+ add_misc_fields(post, billing_address)
49
+
50
+ commit("CreateCustomer", post)
51
+ end
52
+
53
+ def update(billing_id, creditcard, options={})
54
+ post = {}
55
+
56
+ # Handle our required fields
57
+ requires!(options, :billing_address)
58
+
59
+ # Handle eWay specific required fields.
60
+ billing_address = options[:billing_address]
61
+ eway_requires!(billing_address)
62
+
63
+ post[:managedCustomerID]=billing_id
64
+ add_creditcard(post, creditcard)
65
+ add_address(post, billing_address)
66
+ add_misc_fields(post, billing_address)
67
+
68
+ commit("UpdateCustomer", post)
69
+ end
70
+
71
+ #process payment for given amount from stored CC "ManagedCustomerID = billing_id"
72
+ def purchase(money, billing_id, options={})
73
+ post = {}
74
+ post[:managedCustomerID] = billing_id.to_s
75
+ post[:amount]=money
76
+
77
+ commit("ProcessPayment", post)
78
+ end
79
+
80
+ # TODO: eWay API also provides QueryCustomer
81
+ # TODO: eWay API also provides QueryPayment
82
+
83
+ def test?
84
+ @options[:test] || Base.gateway_mode == :test
85
+ end
86
+ private
87
+
88
+ def eway_requires!(hash)
89
+ raise ArgumentError.new("Missing eWay required parameter in `billing_address`: title") unless hash.has_key?(:title)
90
+ raise ArgumentError.new("Missing eWay required parameter in `billing_address`: country") unless hash.has_key?(:country)
91
+ end
92
+
93
+ def add_address(post, address)
94
+ post[:Address] = address[:address1].to_s
95
+ post[:Phone] = address[:phone].to_s
96
+ post[:PostCode] = address[:zip].to_s
97
+ post[:Suburb] = address[:city].to_s
98
+ post[:Country] = address[:country].to_s.downcase
99
+ post[:State] = address[:state].to_s
100
+ post[:Mobile] = address[:mobile].to_s
101
+ post[:Fax] = address[:fax].to_s
102
+ end
103
+
104
+ def add_misc_fields(post, options)
105
+ post[:CustomerRef]=options[:customer_ref].to_s
106
+ post[:Title]=options[:title]
107
+ post[:Company]=options[:company]
108
+ post[:JobDesc]=options[:job_desc]
109
+ post[:Email]=options[:email]
110
+ post[:URL]=options[:url]
111
+ end
112
+
113
+ # add credit card details to be stored by eway. NOTE eway requires "title" field
114
+ def add_creditcard(post, creditcard)
115
+ post[:CCNumber] = creditcard.number
116
+ post[:CCExpiryMonth] = sprintf("%.2i", creditcard.month)
117
+ post[:CCExpiryYear] = sprintf("%.4i", creditcard.year)[-2..-1]
118
+ post[:CCNameOnCard] = creditcard.name
119
+ post[:FirstName] = creditcard.first_name
120
+ post[:LastName] = creditcard.last_name
121
+ end
122
+
123
+ def parse(body)
124
+ reply = {}
125
+ xml = REXML::Document.new(body)
126
+ if root = REXML::XPath.first(xml, "//soap:Fault") then
127
+ reply=parse_fault(root)
128
+ else
129
+ if root = REXML::XPath.first(xml, '//ProcessPaymentResponse/ewayResponse') then
130
+ # Successful payment
131
+ reply=parse_purchase(root)
132
+ else
133
+ if root = REXML::XPath.first(xml, '//CreateCustomerResult') then
134
+ reply[:message]='OK'
135
+ reply[:CreateCustomerResult]=root.text
136
+ reply[:success]=true
137
+ else
138
+ if root = REXML::XPath.first(xml, '//UpdateCustomerResult') then
139
+ if root.text.downcase == 'true' then
140
+ reply[:message]='OK'
141
+ reply[:success]=true
142
+ else
143
+ # ERROR: This state should never occur. If there is a problem,
144
+ # a soap:Fault will be returned. The presence of this
145
+ # element always means a success.
146
+ raise StandardError, "Unexpected \"false\" in UpdateCustomerResult"
147
+ end
148
+ else
149
+ # ERROR: This state should never occur currently. We have handled
150
+ # responses for all the methods which we support.
151
+ raise StandardError, "Unexpected response"
152
+ end
153
+ end
154
+ end
155
+ end
156
+ return reply
157
+ end
158
+
159
+ def parse_fault(node)
160
+ reply={}
161
+ reply[:message]=REXML::XPath.first(node, '//soap:Reason/soap:Text').text
162
+ reply[:success]=false
163
+ reply
164
+ end
165
+
166
+ def parse_purchase(node)
167
+ reply={}
168
+ reply[:message]=REXML::XPath.first(node, '//ewayTrxnError').text
169
+ reply[:success]=(REXML::XPath.first(node, '//ewayTrxnStatus').text == 'True')
170
+ reply[:auth_code]=REXML::XPath.first(node, '//ewayAuthCode').text
171
+ reply
172
+ end
173
+
174
+ def commit(action, post)
175
+ raw = begin
176
+ ssl_post(test? ? TEST_URL : LIVE_URL, soap_request(post, action), 'Content-Type' => 'application/soap+xml; charset=utf-8')
177
+ rescue ResponseError => e
178
+ e.response.body
179
+ end
180
+ response = parse(raw)
181
+
182
+ EwayResponse.new(response[:success], response[:message], response,
183
+ :test => test?,
184
+ :authorization => response[:auth_code]
185
+ )
186
+ end
187
+
188
+ # Where we build the full SOAP 1.2 request using builder
189
+ def soap_request(arguments, action)
190
+ # eWay demands all fields be sent, but contain an empty string if blank
191
+ post=default_fields.merge(arguments)
192
+
193
+ xml = Builder::XmlMarkup.new :indent => 2
194
+ xml.instruct!
195
+ 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
196
+ xml.tag! 'soap12:Header' do
197
+ xml.tag! 'eWAYHeader', {'xmlns' => 'https://www.eway.com.au/gateway/managedpayment'} do
198
+ xml.tag! 'eWAYCustomerID', @options[:login]
199
+ xml.tag! 'Username', @options[:username]
200
+ xml.tag! 'Password', @options[:password]
201
+ end
202
+ end
203
+ xml.tag! 'soap12:Body' do |x|
204
+ x.tag! "#{action}", {'xmlns' => 'https://www.eway.com.au/gateway/managedpayment'} do |y|
205
+ post.each do |key, value|
206
+ y.tag! "#{key}", "#{value}"
207
+ end
208
+ end
209
+ end
210
+ end
211
+ xml.target!
212
+ end
213
+
214
+ def default_fields
215
+ hash={}
216
+ %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|
217
+ hash[field.to_sym]=''
218
+ end
219
+ return hash
220
+ end
221
+
222
+ class EwayResponse < Response
223
+ # add a method to response so we can easily get the eway token "ManagedCustomerID"
224
+ def token
225
+ @params['CreateCustomerResult']
226
+ end
227
+ end
228
+
229
+ end
230
+ end
231
+ end