activemerchant-nsp 1.27.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (252) hide show
  1. data/CHANGELOG +952 -0
  2. data/CONTRIBUTORS +347 -0
  3. data/MIT-LICENSE +20 -0
  4. data/README.md +204 -0
  5. data/gem-public_cert.pem +20 -0
  6. data/lib/active_merchant.rb +63 -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 +56 -0
  10. data/lib/active_merchant/billing/check.rb +68 -0
  11. data/lib/active_merchant/billing/credit_card.rb +274 -0
  12. data/lib/active_merchant/billing/credit_card_formatting.rb +21 -0
  13. data/lib/active_merchant/billing/credit_card_methods.rb +143 -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 +176 -0
  17. data/lib/active_merchant/billing/gateways.rb +18 -0
  18. data/lib/active_merchant/billing/gateways/authorize_net.rb +695 -0
  19. data/lib/active_merchant/billing/gateways/authorize_net_cim.rb +943 -0
  20. data/lib/active_merchant/billing/gateways/balanced.rb +462 -0
  21. data/lib/active_merchant/billing/gateways/barclays_epdq.rb +308 -0
  22. data/lib/active_merchant/billing/gateways/beanstream.rb +167 -0
  23. data/lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb +389 -0
  24. data/lib/active_merchant/billing/gateways/beanstream_interac.rb +54 -0
  25. data/lib/active_merchant/billing/gateways/blue_pay.rb +492 -0
  26. data/lib/active_merchant/billing/gateways/bogus.rb +142 -0
  27. data/lib/active_merchant/billing/gateways/braintree.rb +19 -0
  28. data/lib/active_merchant/billing/gateways/braintree/braintree_common.rb +9 -0
  29. data/lib/active_merchant/billing/gateways/braintree_blue.rb +389 -0
  30. data/lib/active_merchant/billing/gateways/braintree_orange.rb +19 -0
  31. data/lib/active_merchant/billing/gateways/card_save.rb +23 -0
  32. data/lib/active_merchant/billing/gateways/card_stream.rb +230 -0
  33. data/lib/active_merchant/billing/gateways/certo_direct.rb +278 -0
  34. data/lib/active_merchant/billing/gateways/cyber_source.rb +576 -0
  35. data/lib/active_merchant/billing/gateways/data_cash.rb +597 -0
  36. data/lib/active_merchant/billing/gateways/efsnet.rb +235 -0
  37. data/lib/active_merchant/billing/gateways/elavon.rb +137 -0
  38. data/lib/active_merchant/billing/gateways/epay.rb +276 -0
  39. data/lib/active_merchant/billing/gateways/eway.rb +287 -0
  40. data/lib/active_merchant/billing/gateways/eway_managed.rb +265 -0
  41. data/lib/active_merchant/billing/gateways/exact.rb +227 -0
  42. data/lib/active_merchant/billing/gateways/fat_zebra.rb +152 -0
  43. data/lib/active_merchant/billing/gateways/federated_canada.rb +168 -0
  44. data/lib/active_merchant/billing/gateways/first_pay.rb +177 -0
  45. data/lib/active_merchant/billing/gateways/garanti.rb +262 -0
  46. data/lib/active_merchant/billing/gateways/ideal/ideal_base.rb +252 -0
  47. data/lib/active_merchant/billing/gateways/ideal/ideal_rabobank.pem +13 -0
  48. data/lib/active_merchant/billing/gateways/ideal/ideal_response.rb +29 -0
  49. data/lib/active_merchant/billing/gateways/ideal_rabobank.rb +55 -0
  50. data/lib/active_merchant/billing/gateways/inspire.rb +221 -0
  51. data/lib/active_merchant/billing/gateways/instapay.rb +164 -0
  52. data/lib/active_merchant/billing/gateways/iridium.rb +257 -0
  53. data/lib/active_merchant/billing/gateways/itransact.rb +450 -0
  54. data/lib/active_merchant/billing/gateways/jetpay.rb +276 -0
  55. data/lib/active_merchant/billing/gateways/linkpoint.rb +451 -0
  56. data/lib/active_merchant/billing/gateways/litle.rb +290 -0
  57. data/lib/active_merchant/billing/gateways/merchant_e_solutions.rb +157 -0
  58. data/lib/active_merchant/billing/gateways/merchant_ware.rb +289 -0
  59. data/lib/active_merchant/billing/gateways/metrics_global.rb +323 -0
  60. data/lib/active_merchant/billing/gateways/migs.rb +263 -0
  61. data/lib/active_merchant/billing/gateways/migs/migs_codes.rb +100 -0
  62. data/lib/active_merchant/billing/gateways/modern_payments.rb +38 -0
  63. data/lib/active_merchant/billing/gateways/modern_payments_cim.rb +220 -0
  64. data/lib/active_merchant/billing/gateways/moneris.rb +250 -0
  65. data/lib/active_merchant/billing/gateways/moneris_us.rb +211 -0
  66. data/lib/active_merchant/billing/gateways/nab_transact.rb +257 -0
  67. data/lib/active_merchant/billing/gateways/net_registry.rb +189 -0
  68. data/lib/active_merchant/billing/gateways/netaxept.rb +239 -0
  69. data/lib/active_merchant/billing/gateways/netbilling.rb +196 -0
  70. data/lib/active_merchant/billing/gateways/nmi.rb +13 -0
  71. data/lib/active_merchant/billing/gateways/ogone.rb +427 -0
  72. data/lib/active_merchant/billing/gateways/optimal_payment.rb +277 -0
  73. data/lib/active_merchant/billing/gateways/orbital.rb +351 -0
  74. data/lib/active_merchant/billing/gateways/orbital/orbital_soft_descriptors.rb +46 -0
  75. data/lib/active_merchant/billing/gateways/pay_gate_xml.rb +266 -0
  76. data/lib/active_merchant/billing/gateways/pay_junction.rb +397 -0
  77. data/lib/active_merchant/billing/gateways/pay_secure.rb +120 -0
  78. data/lib/active_merchant/billing/gateways/paybox_direct.rb +201 -0
  79. data/lib/active_merchant/billing/gateways/payflow.rb +268 -0
  80. data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +212 -0
  81. data/lib/active_merchant/billing/gateways/payflow/payflow_express_response.rb +39 -0
  82. data/lib/active_merchant/billing/gateways/payflow/payflow_response.rb +13 -0
  83. data/lib/active_merchant/billing/gateways/payflow_express.rb +224 -0
  84. data/lib/active_merchant/billing/gateways/payflow_express_uk.rb +15 -0
  85. data/lib/active_merchant/billing/gateways/payflow_uk.rb +21 -0
  86. data/lib/active_merchant/billing/gateways/payment_express.rb +282 -0
  87. data/lib/active_merchant/billing/gateways/paypal.rb +106 -0
  88. data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +653 -0
  89. data/lib/active_merchant/billing/gateways/paypal/paypal_express_response.rb +49 -0
  90. data/lib/active_merchant/billing/gateways/paypal/paypal_recurring_api.rb +245 -0
  91. data/lib/active_merchant/billing/gateways/paypal_ca.rb +13 -0
  92. data/lib/active_merchant/billing/gateways/paypal_digital_goods.rb +43 -0
  93. data/lib/active_merchant/billing/gateways/paypal_express.rb +178 -0
  94. data/lib/active_merchant/billing/gateways/paypal_express_common.rb +30 -0
  95. data/lib/active_merchant/billing/gateways/paystation.rb +201 -0
  96. data/lib/active_merchant/billing/gateways/payway.rb +214 -0
  97. data/lib/active_merchant/billing/gateways/plugnpay.rb +295 -0
  98. data/lib/active_merchant/billing/gateways/psigate.rb +219 -0
  99. data/lib/active_merchant/billing/gateways/psl_card.rb +304 -0
  100. data/lib/active_merchant/billing/gateways/qbms.rb +297 -0
  101. data/lib/active_merchant/billing/gateways/quantum.rb +282 -0
  102. data/lib/active_merchant/billing/gateways/quickpay.rb +298 -0
  103. data/lib/active_merchant/billing/gateways/realex.rb +313 -0
  104. data/lib/active_merchant/billing/gateways/sage.rb +148 -0
  105. data/lib/active_merchant/billing/gateways/sage/sage_bankcard.rb +88 -0
  106. data/lib/active_merchant/billing/gateways/sage/sage_core.rb +115 -0
  107. data/lib/active_merchant/billing/gateways/sage/sage_virtual_check.rb +97 -0
  108. data/lib/active_merchant/billing/gateways/sage_pay.rb +322 -0
  109. data/lib/active_merchant/billing/gateways/sallie_mae.rb +144 -0
  110. data/lib/active_merchant/billing/gateways/samurai.rb +121 -0
  111. data/lib/active_merchant/billing/gateways/secure_net.rb +330 -0
  112. data/lib/active_merchant/billing/gateways/secure_pay.rb +31 -0
  113. data/lib/active_merchant/billing/gateways/secure_pay_au.rb +284 -0
  114. data/lib/active_merchant/billing/gateways/secure_pay_tech.rb +113 -0
  115. data/lib/active_merchant/billing/gateways/skip_jack.rb +458 -0
  116. data/lib/active_merchant/billing/gateways/smart_ps.rb +273 -0
  117. data/lib/active_merchant/billing/gateways/stripe.rb +236 -0
  118. data/lib/active_merchant/billing/gateways/trans_first.rb +127 -0
  119. data/lib/active_merchant/billing/gateways/transax.rb +23 -0
  120. data/lib/active_merchant/billing/gateways/trust_commerce.rb +423 -0
  121. data/lib/active_merchant/billing/gateways/usa_epay.rb +25 -0
  122. data/lib/active_merchant/billing/gateways/usa_epay_advanced.rb +1497 -0
  123. data/lib/active_merchant/billing/gateways/usa_epay_transaction.rb +206 -0
  124. data/lib/active_merchant/billing/gateways/verifi.rb +233 -0
  125. data/lib/active_merchant/billing/gateways/viaklix.rb +194 -0
  126. data/lib/active_merchant/billing/gateways/vindicia.rb +359 -0
  127. data/lib/active_merchant/billing/gateways/wirecard.rb +313 -0
  128. data/lib/active_merchant/billing/gateways/worldpay.rb +271 -0
  129. data/lib/active_merchant/billing/integrations.rb +17 -0
  130. data/lib/active_merchant/billing/integrations/action_view_helper.rb +73 -0
  131. data/lib/active_merchant/billing/integrations/authorize_net_sim.rb +38 -0
  132. data/lib/active_merchant/billing/integrations/authorize_net_sim/helper.rb +228 -0
  133. data/lib/active_merchant/billing/integrations/authorize_net_sim/notification.rb +340 -0
  134. data/lib/active_merchant/billing/integrations/bogus.rb +23 -0
  135. data/lib/active_merchant/billing/integrations/bogus/helper.rb +17 -0
  136. data/lib/active_merchant/billing/integrations/bogus/notification.rb +11 -0
  137. data/lib/active_merchant/billing/integrations/bogus/return.rb +10 -0
  138. data/lib/active_merchant/billing/integrations/chronopay.rb +23 -0
  139. data/lib/active_merchant/billing/integrations/chronopay/helper.rb +120 -0
  140. data/lib/active_merchant/billing/integrations/chronopay/notification.rb +158 -0
  141. data/lib/active_merchant/billing/integrations/chronopay/return.rb +10 -0
  142. data/lib/active_merchant/billing/integrations/direc_pay.rb +41 -0
  143. data/lib/active_merchant/billing/integrations/direc_pay/helper.rb +200 -0
  144. data/lib/active_merchant/billing/integrations/direc_pay/notification.rb +76 -0
  145. data/lib/active_merchant/billing/integrations/direc_pay/return.rb +32 -0
  146. data/lib/active_merchant/billing/integrations/direc_pay/status.rb +37 -0
  147. data/lib/active_merchant/billing/integrations/directebanking.rb +47 -0
  148. data/lib/active_merchant/billing/integrations/directebanking/helper.rb +90 -0
  149. data/lib/active_merchant/billing/integrations/directebanking/notification.rb +120 -0
  150. data/lib/active_merchant/billing/integrations/directebanking/return.rb +11 -0
  151. data/lib/active_merchant/billing/integrations/dotpay.rb +22 -0
  152. data/lib/active_merchant/billing/integrations/dotpay/helper.rb +77 -0
  153. data/lib/active_merchant/billing/integrations/dotpay/notification.rb +86 -0
  154. data/lib/active_merchant/billing/integrations/dotpay/return.rb +11 -0
  155. data/lib/active_merchant/billing/integrations/dwolla.rb +30 -0
  156. data/lib/active_merchant/billing/integrations/dwolla/helper.rb +31 -0
  157. data/lib/active_merchant/billing/integrations/dwolla/notification.rb +55 -0
  158. data/lib/active_merchant/billing/integrations/dwolla/return.rb +38 -0
  159. data/lib/active_merchant/billing/integrations/e_payment_plans.rb +48 -0
  160. data/lib/active_merchant/billing/integrations/e_payment_plans/helper.rb +34 -0
  161. data/lib/active_merchant/billing/integrations/e_payment_plans/notification.rb +84 -0
  162. data/lib/active_merchant/billing/integrations/easy_pay.rb +30 -0
  163. data/lib/active_merchant/billing/integrations/easy_pay/common.rb +40 -0
  164. data/lib/active_merchant/billing/integrations/easy_pay/helper.rb +40 -0
  165. data/lib/active_merchant/billing/integrations/easy_pay/notification.rb +51 -0
  166. data/lib/active_merchant/billing/integrations/epay.rb +21 -0
  167. data/lib/active_merchant/billing/integrations/epay/helper.rb +55 -0
  168. data/lib/active_merchant/billing/integrations/epay/notification.rb +110 -0
  169. data/lib/active_merchant/billing/integrations/first_data.rb +38 -0
  170. data/lib/active_merchant/billing/integrations/first_data/helper.rb +63 -0
  171. data/lib/active_merchant/billing/integrations/first_data/notification.rb +56 -0
  172. data/lib/active_merchant/billing/integrations/gestpay.rb +25 -0
  173. data/lib/active_merchant/billing/integrations/gestpay/common.rb +42 -0
  174. data/lib/active_merchant/billing/integrations/gestpay/helper.rb +70 -0
  175. data/lib/active_merchant/billing/integrations/gestpay/notification.rb +85 -0
  176. data/lib/active_merchant/billing/integrations/gestpay/return.rb +10 -0
  177. data/lib/active_merchant/billing/integrations/helper.rb +117 -0
  178. data/lib/active_merchant/billing/integrations/hi_trust.rb +27 -0
  179. data/lib/active_merchant/billing/integrations/hi_trust/helper.rb +58 -0
  180. data/lib/active_merchant/billing/integrations/hi_trust/notification.rb +59 -0
  181. data/lib/active_merchant/billing/integrations/hi_trust/return.rb +67 -0
  182. data/lib/active_merchant/billing/integrations/maksuturva.rb +86 -0
  183. data/lib/active_merchant/billing/integrations/maksuturva/helper.rb +119 -0
  184. data/lib/active_merchant/billing/integrations/maksuturva/notification.rb +48 -0
  185. data/lib/active_merchant/billing/integrations/moneybookers.rb +26 -0
  186. data/lib/active_merchant/billing/integrations/moneybookers/helper.rb +59 -0
  187. data/lib/active_merchant/billing/integrations/moneybookers/notification.rb +129 -0
  188. data/lib/active_merchant/billing/integrations/nelnet.rb +40 -0
  189. data/lib/active_merchant/billing/integrations/nelnet/helper.rb +34 -0
  190. data/lib/active_merchant/billing/integrations/nelnet/notification.rb +100 -0
  191. data/lib/active_merchant/billing/integrations/nochex.rb +88 -0
  192. data/lib/active_merchant/billing/integrations/nochex/helper.rb +68 -0
  193. data/lib/active_merchant/billing/integrations/nochex/notification.rb +94 -0
  194. data/lib/active_merchant/billing/integrations/nochex/return.rb +10 -0
  195. data/lib/active_merchant/billing/integrations/notification.rb +62 -0
  196. data/lib/active_merchant/billing/integrations/paxum.rb +44 -0
  197. data/lib/active_merchant/billing/integrations/paxum/common.rb +24 -0
  198. data/lib/active_merchant/billing/integrations/paxum/helper.rb +42 -0
  199. data/lib/active_merchant/billing/integrations/paxum/notification.rb +33 -0
  200. data/lib/active_merchant/billing/integrations/payflow_link.rb +21 -0
  201. data/lib/active_merchant/billing/integrations/payflow_link/helper.rb +100 -0
  202. data/lib/active_merchant/billing/integrations/payflow_link/notification.rb +78 -0
  203. data/lib/active_merchant/billing/integrations/paypal.rb +39 -0
  204. data/lib/active_merchant/billing/integrations/paypal/helper.rb +119 -0
  205. data/lib/active_merchant/billing/integrations/paypal/notification.rb +155 -0
  206. data/lib/active_merchant/billing/integrations/paypal/return.rb +10 -0
  207. data/lib/active_merchant/billing/integrations/paypal_payments_advanced.rb +20 -0
  208. data/lib/active_merchant/billing/integrations/paypal_payments_advanced/helper.rb +15 -0
  209. data/lib/active_merchant/billing/integrations/pxpay.rb +31 -0
  210. data/lib/active_merchant/billing/integrations/pxpay/helper.rb +110 -0
  211. data/lib/active_merchant/billing/integrations/pxpay/notification.rb +157 -0
  212. data/lib/active_merchant/billing/integrations/pxpay/return.rb +25 -0
  213. data/lib/active_merchant/billing/integrations/quickpay.rb +21 -0
  214. data/lib/active_merchant/billing/integrations/quickpay/helper.rb +71 -0
  215. data/lib/active_merchant/billing/integrations/quickpay/notification.rb +74 -0
  216. data/lib/active_merchant/billing/integrations/return.rb +42 -0
  217. data/lib/active_merchant/billing/integrations/robokassa.rb +49 -0
  218. data/lib/active_merchant/billing/integrations/robokassa/common.rb +19 -0
  219. data/lib/active_merchant/billing/integrations/robokassa/helper.rb +50 -0
  220. data/lib/active_merchant/billing/integrations/robokassa/notification.rb +55 -0
  221. data/lib/active_merchant/billing/integrations/robokassa/return.rb +17 -0
  222. data/lib/active_merchant/billing/integrations/sage_pay_form.rb +37 -0
  223. data/lib/active_merchant/billing/integrations/sage_pay_form/encryption.rb +33 -0
  224. data/lib/active_merchant/billing/integrations/sage_pay_form/helper.rb +129 -0
  225. data/lib/active_merchant/billing/integrations/sage_pay_form/notification.rb +210 -0
  226. data/lib/active_merchant/billing/integrations/sage_pay_form/return.rb +31 -0
  227. data/lib/active_merchant/billing/integrations/two_checkout.rb +44 -0
  228. data/lib/active_merchant/billing/integrations/two_checkout/helper.rb +91 -0
  229. data/lib/active_merchant/billing/integrations/two_checkout/notification.rb +139 -0
  230. data/lib/active_merchant/billing/integrations/two_checkout/return.rb +17 -0
  231. data/lib/active_merchant/billing/integrations/valitor.rb +33 -0
  232. data/lib/active_merchant/billing/integrations/valitor/helper.rb +86 -0
  233. data/lib/active_merchant/billing/integrations/valitor/notification.rb +13 -0
  234. data/lib/active_merchant/billing/integrations/valitor/response_fields.rb +97 -0
  235. data/lib/active_merchant/billing/integrations/valitor/return.rb +13 -0
  236. data/lib/active_merchant/billing/integrations/verkkomaksut.rb +20 -0
  237. data/lib/active_merchant/billing/integrations/verkkomaksut/helper.rb +87 -0
  238. data/lib/active_merchant/billing/integrations/verkkomaksut/notification.rb +59 -0
  239. data/lib/active_merchant/billing/integrations/web_pay.rb +45 -0
  240. data/lib/active_merchant/billing/integrations/web_pay/common.rb +50 -0
  241. data/lib/active_merchant/billing/integrations/web_pay/helper.rb +68 -0
  242. data/lib/active_merchant/billing/integrations/web_pay/notification.rb +51 -0
  243. data/lib/active_merchant/billing/integrations/world_pay.rb +27 -0
  244. data/lib/active_merchant/billing/integrations/world_pay/helper.rb +100 -0
  245. data/lib/active_merchant/billing/integrations/world_pay/notification.rb +160 -0
  246. data/lib/active_merchant/billing/response.rb +64 -0
  247. data/lib/active_merchant/version.rb +3 -0
  248. data/lib/activemerchant.rb +1 -0
  249. data/lib/support/gateway_support.rb +65 -0
  250. data/lib/support/outbound_hosts.rb +25 -0
  251. data/lib/support/ssl_verify.rb +93 -0
  252. metadata +482 -0
@@ -0,0 +1,287 @@
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
+ # The transaction result is based on the cent value of the transaction. $10.15 will return a failed transaction
15
+ # with a response code of "15 – No Issuer", while $10.00 will return "00 – Transaction Approved."
16
+ #
17
+ # Next, create a credit card object using a eWay approved test card number (4444333322221111).
18
+ #
19
+ # creditcard = ActiveMerchant::Billing::CreditCard.new(
20
+ # :number => '4444333322221111',
21
+ # :month => 8,
22
+ # :year => 2006,
23
+ # :first_name => 'Longbob',
24
+ # :last_name => 'Longsen',
25
+ # :verification_value => '123'
26
+ # )
27
+ # options = {
28
+ # :order_id => '1230123',
29
+ # :email => 'bob@testbob.com',
30
+ # :address => { :address1 => '47 Bobway',
31
+ # :city => 'Bobville',
32
+ # :state => 'WA',
33
+ # :country => 'Australia',
34
+ # :zip => '2000'
35
+ # },
36
+ # :description => 'purchased items'
37
+ # }
38
+ #
39
+ # To finish setting up, create the active_merchant object you will be using, with the eWay gateway. If you have a
40
+ # functional eWay account, replace :login with your Customer ID.
41
+ #
42
+ # gateway = ActiveMerchant::Billing::Base.gateway(:eway).new(:login => '87654321')
43
+ #
44
+ # Now we are ready to process our transaction
45
+ #
46
+ # response = gateway.purchase(tendollar, creditcard, options)
47
+ #
48
+ # Sending a transaction to eWay with active_merchant returns a Response object, which consistently allows you to:
49
+ #
50
+ # 1) Check whether the transaction was successful
51
+ #
52
+ # response.success?
53
+ #
54
+ # 2) Retrieve any message returned by eWay, either a "transaction was successful" note or an explanation of why the
55
+ # transaction was rejected.
56
+ #
57
+ # response.message
58
+ #
59
+ # 3) Retrieve and store the unique transaction ID returned by eWway, for use in referencing the transaction in the future.
60
+ #
61
+ # response.authorization
62
+ #
63
+ # This should be enough to get you started with eWay and active_merchant. For further information, review the methods
64
+ # below and the rest of active_merchant's documentation.
65
+
66
+ class EwayGateway < Gateway
67
+ self.test_url = 'https://www.eway.com.au/gateway/xmltest/testpage.asp'
68
+ self.live_url = 'https://www.eway.com.au/gateway/xmlpayment.asp'
69
+
70
+ class_attribute :test_cvn_url, :live_cvn_url
71
+ self.test_cvn_url = 'https://www.eway.com.au/gateway_cvn/xmltest/testpage.asp'
72
+ self.live_cvn_url = 'https://www.eway.com.au/gateway_cvn/xmlpayment.asp'
73
+
74
+ MESSAGES = {
75
+ "00" => "Transaction Approved",
76
+ "01" => "Refer to Issuer",
77
+ "02" => "Refer to Issuer, special",
78
+ "03" => "No Merchant",
79
+ "04" => "Pick Up Card",
80
+ "05" => "Do Not Honour",
81
+ "06" => "Error",
82
+ "07" => "Pick Up Card, Special",
83
+ "08" => "Honour With Identification",
84
+ "09" => "Request In Progress",
85
+ "10" => "Approved For Partial Amount",
86
+ "11" => "Approved, VIP",
87
+ "12" => "Invalid Transaction",
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",
134
+ "96" => "System Error"
135
+ }
136
+
137
+ self.money_format = :cents
138
+ self.supported_countries = ['AU']
139
+ self.supported_cardtypes = [:visa, :master, :american_express, :diners_club]
140
+ self.homepage_url = 'http://www.eway.com.au/'
141
+ self.display_name = 'eWAY'
142
+
143
+ def initialize(options = {})
144
+ requires!(options, :login)
145
+ @options = options
146
+ super
147
+ end
148
+
149
+ # ewayCustomerEmail, ewayCustomerAddress, ewayCustomerPostcode
150
+ def purchase(money, creditcard, options = {})
151
+ requires_address!(options)
152
+
153
+ post = {}
154
+ add_creditcard(post, creditcard)
155
+ add_address(post, options)
156
+ add_customer_data(post, options)
157
+ add_invoice_data(post, options)
158
+ # The request fails if all of the fields aren't present
159
+ add_optional_data(post)
160
+
161
+ commit(money, post)
162
+ end
163
+
164
+ def test?
165
+ @options[:test] || super
166
+ end
167
+
168
+ private
169
+
170
+ def requires_address!(options)
171
+ raise ArgumentError.new("Missing eWay required parameters: address or billing_address") unless (options.has_key?(:address) or options.has_key?(:billing_address))
172
+ end
173
+
174
+ def add_creditcard(post, creditcard)
175
+ post[:CardNumber] = creditcard.number
176
+ post[:CardExpiryMonth] = sprintf("%.2i", creditcard.month)
177
+ post[:CardExpiryYear] = sprintf("%.4i", creditcard.year)[-2..-1]
178
+ post[:CustomerFirstName] = creditcard.first_name
179
+ post[:CustomerLastName] = creditcard.last_name
180
+ post[:CardHoldersName] = creditcard.name
181
+
182
+ post[:CVN] = creditcard.verification_value if creditcard.verification_value?
183
+ end
184
+
185
+ def add_address(post, options)
186
+ if address = options[:billing_address] || options[:address]
187
+ post[:CustomerAddress] = [ address[:address1], address[:address2], address[:city], address[:state], address[:country] ].compact.join(', ')
188
+ post[:CustomerPostcode] = address[:zip]
189
+ end
190
+ end
191
+
192
+ def add_customer_data(post, options)
193
+ post[:CustomerEmail] = options[:email]
194
+ end
195
+
196
+ def add_invoice_data(post, options)
197
+ post[:CustomerInvoiceRef] = options[:order_id]
198
+ post[:CustomerInvoiceDescription] = options[:description]
199
+ end
200
+
201
+ def add_optional_data(post)
202
+ post[:TrxnNumber] = nil
203
+ post[:Option1] = nil
204
+ post[:Option2] = nil
205
+ post[:Option3] = nil
206
+ end
207
+
208
+ def commit(money, parameters)
209
+ parameters[:TotalAmount] = amount(money)
210
+
211
+ response = parse( ssl_post(gateway_url(parameters[:CVN], test?), post_data(parameters)) )
212
+
213
+ Response.new(success?(response), message_from(response[:ewaytrxnerror]), response,
214
+ :authorization => response[:ewayauthcode],
215
+ :test => /\(Test( CVN)? Gateway\)/ === response[:ewaytrxnerror]
216
+ )
217
+ end
218
+
219
+ def success?(response)
220
+ response[:ewaytrxnstatus] == "True"
221
+ end
222
+
223
+ # Parse eway response xml into a convinient hash
224
+ def parse(xml)
225
+ # "<?xml version=\"1.0\"?>".
226
+ # <ewayResponse>
227
+ # <ewayTrxnError></ewayTrxnError>
228
+ # <ewayTrxnStatus>True</ewayTrxnStatus>
229
+ # <ewayTrxnNumber>10002</ewayTrxnNumber>
230
+ # <ewayTrxnOption1></ewayTrxnOption1>
231
+ # <ewayTrxnOption2></ewayTrxnOption2>
232
+ # <ewayTrxnOption3></ewayTrxnOption3>
233
+ # <ewayReturnAmount>10</ewayReturnAmount>
234
+ # <ewayAuthCode>123456</ewayAuthCode>
235
+ # <ewayTrxnReference>987654321</ewayTrxnReference>
236
+ # </ewayResponse>
237
+
238
+ response = {}
239
+ xml = REXML::Document.new(xml)
240
+ xml.elements.each('//ewayResponse/*') do |node|
241
+
242
+ response[node.name.downcase.to_sym] = normalize(node.text)
243
+
244
+ end unless xml.root.nil?
245
+
246
+ response
247
+ end
248
+
249
+ def post_data(parameters = {})
250
+ parameters[:CustomerID] = @options[:login]
251
+
252
+ xml = REXML::Document.new
253
+ root = xml.add_element("ewaygateway")
254
+
255
+ parameters.each do |key, value|
256
+ root.add_element("eway#{key}").text = value
257
+ end
258
+ xml.to_s
259
+ end
260
+
261
+ def message_from(message)
262
+ return '' if message.blank?
263
+ MESSAGES[message[0,2]] || message
264
+ end
265
+
266
+ # Make a ruby type out of the response string
267
+ def normalize(field)
268
+ case field
269
+ when "true" then true
270
+ when "false" then false
271
+ when "" then nil
272
+ when "null" then nil
273
+ else field
274
+ end
275
+ end
276
+
277
+ def gateway_url(cvn, test)
278
+ if cvn
279
+ test ? self.test_cvn_url : self.live_cvn_url
280
+ else
281
+ test ? self.test_url : self.live_url
282
+ end
283
+ end
284
+
285
+ end
286
+ end
287
+ end
@@ -0,0 +1,265 @@
1
+ module ActiveMerchant #:nodoc:
2
+ module Billing #:nodoc:
3
+ class EwayManagedGateway < Gateway
4
+ self.test_url = 'https://www.eway.com.au/gateway/ManagedPaymentService/test/managedCreditCardPayment.asmx'
5
+ self.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, options)
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, options)
67
+
68
+ commit("UpdateCustomer", post)
69
+ end
70
+
71
+ # Process a payment in the given amount against the stored credit card given by billing_id
72
+ #
73
+ # ==== Parameters
74
+ #
75
+ # * <tt>money</tt> -- The amount to be purchased as an Integer value in cents.
76
+ # * <tt>billing_id</tt> -- The eWay provided card/customer token to charge (managedCustomerID)
77
+ # * <tt>options</tt> -- A hash of optional parameters.
78
+ #
79
+ # ==== Options
80
+ #
81
+ # * <tt>:order_id</tt> -- The order number, passed to eWay as the "Invoice Reference"
82
+ # * <tt>:invoice</tt> -- The invoice number, passed to eWay as the "Invoice Reference" unless :order_id is also given
83
+ # * <tt>:description</tt> -- A description of the payment, passed to eWay as the "Invoice Description"
84
+ def purchase(money, billing_id, options={})
85
+ post = {}
86
+ post[:managedCustomerID] = billing_id.to_s
87
+ post[:amount]=money
88
+ add_invoice(post, options)
89
+
90
+ commit("ProcessPayment", post)
91
+ end
92
+
93
+ # TODO: eWay API also provides QueryCustomer
94
+ # TODO: eWay API also provides QueryPayment
95
+
96
+ def test?
97
+ @options[:test] || Base.gateway_mode == :test
98
+ end
99
+ private
100
+
101
+ def eway_requires!(hash)
102
+ raise ArgumentError.new("Missing eWay required parameter in `billing_address`: title") unless hash.has_key?(:title)
103
+ raise ArgumentError.new("Missing eWay required parameter in `billing_address`: country") unless hash.has_key?(:country)
104
+ end
105
+
106
+ def add_address(post, address)
107
+ post[:Address] = address[:address1].to_s
108
+ post[:Phone] = address[:phone].to_s
109
+ post[:PostCode] = address[:zip].to_s
110
+ post[:Suburb] = address[:city].to_s
111
+ post[:Country] = address[:country].to_s.downcase
112
+ post[:State] = address[:state].to_s
113
+ post[:Mobile] = address[:mobile].to_s
114
+ post[:Fax] = address[:fax].to_s
115
+ end
116
+
117
+ def add_misc_fields(post, options)
118
+ post[:CustomerRef]=options[:billing_address][:customer_ref] || options[:customer]
119
+ post[:Title]=options[:billing_address][:title]
120
+ post[:Company]=options[:billing_address][:company]
121
+ post[:JobDesc]=options[:billing_address][:job_desc]
122
+ post[:Email]=options[:billing_address][:email] || options[:email]
123
+ post[:URL]=options[:billing_address][:url]
124
+ post[:Comments]=options[:description]
125
+ end
126
+
127
+ def add_invoice(post, options)
128
+ post[:invoiceReference] = options[:order_id] || options[:invoice]
129
+ post[:invoiceDescription] = options[:description]
130
+ end
131
+
132
+
133
+ # add credit card details to be stored by eway. NOTE eway requires "title" field
134
+ def add_creditcard(post, creditcard)
135
+ post[:CCNumber] = creditcard.number
136
+ post[:CCExpiryMonth] = sprintf("%.2i", creditcard.month)
137
+ post[:CCExpiryYear] = sprintf("%.4i", creditcard.year)[-2..-1]
138
+ post[:CCNameOnCard] = creditcard.name
139
+ post[:FirstName] = creditcard.first_name
140
+ post[:LastName] = creditcard.last_name
141
+ end
142
+
143
+ def parse(body)
144
+ reply = {}
145
+ xml = REXML::Document.new(body)
146
+ if root = REXML::XPath.first(xml, "//soap:Fault") then
147
+ reply=parse_fault(root)
148
+ else
149
+ if root = REXML::XPath.first(xml, '//ProcessPaymentResponse/ewayResponse') then
150
+ # Successful payment
151
+ reply=parse_purchase(root)
152
+ else
153
+ if root = REXML::XPath.first(xml, '//CreateCustomerResult') then
154
+ reply[:message]='OK'
155
+ reply[:CreateCustomerResult]=root.text
156
+ reply[:success]=true
157
+ else
158
+ if root = REXML::XPath.first(xml, '//UpdateCustomerResult') then
159
+ if root.text.downcase == 'true' then
160
+ reply[:message]='OK'
161
+ reply[:success]=true
162
+ else
163
+ # ERROR: This state should never occur. If there is a problem,
164
+ # a soap:Fault will be returned. The presence of this
165
+ # element always means a success.
166
+ raise StandardError, "Unexpected \"false\" in UpdateCustomerResult"
167
+ end
168
+ else
169
+ # ERROR: This state should never occur currently. We have handled
170
+ # responses for all the methods which we support.
171
+ raise StandardError, "Unexpected response"
172
+ end
173
+ end
174
+ end
175
+ end
176
+ return reply
177
+ end
178
+
179
+ def parse_fault(node)
180
+ reply={}
181
+ reply[:message]=REXML::XPath.first(node, '//soap:Reason/soap:Text').text
182
+ reply[:success]=false
183
+ reply
184
+ end
185
+
186
+ def parse_purchase(node)
187
+ reply={}
188
+ reply[:message]=REXML::XPath.first(node, '//ewayTrxnError').text
189
+ reply[:success]=(REXML::XPath.first(node, '//ewayTrxnStatus').text == 'True')
190
+ reply[:auth_code]=REXML::XPath.first(node, '//ewayAuthCode').text
191
+ reply[:transaction_number]=REXML::XPath.first(node, '//ewayTrxnNumber').text
192
+ reply
193
+ end
194
+
195
+ def commit(action, post)
196
+ raw = begin
197
+ ssl_post(test? ? self.test_url : self.live_url, soap_request(post, action), 'Content-Type' => 'application/soap+xml; charset=utf-8')
198
+ rescue ResponseError => e
199
+ e.response.body
200
+ end
201
+ response = parse(raw)
202
+
203
+ EwayResponse.new(response[:success], response[:message], response,
204
+ :test => test?,
205
+ :authorization => response[:auth_code]
206
+ )
207
+ end
208
+
209
+ # Where we build the full SOAP 1.2 request using builder
210
+ def soap_request(arguments, action)
211
+ # eWay demands all fields be sent, but contain an empty string if blank
212
+ post = case action
213
+ when 'ProcessPayment'
214
+ default_payment_fields.merge(arguments)
215
+ else
216
+ default_customer_fields.merge(arguments)
217
+ end
218
+
219
+ xml = Builder::XmlMarkup.new :indent => 2
220
+ xml.instruct!
221
+ 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
222
+ xml.tag! 'soap12:Header' do
223
+ xml.tag! 'eWAYHeader', {'xmlns' => 'https://www.eway.com.au/gateway/managedpayment'} do
224
+ xml.tag! 'eWAYCustomerID', @options[:login]
225
+ xml.tag! 'Username', @options[:username]
226
+ xml.tag! 'Password', @options[:password]
227
+ end
228
+ end
229
+ xml.tag! 'soap12:Body' do |x|
230
+ x.tag! "#{action}", {'xmlns' => 'https://www.eway.com.au/gateway/managedpayment'} do |y|
231
+ post.each do |key, value|
232
+ y.tag! "#{key}", "#{value}"
233
+ end
234
+ end
235
+ end
236
+ end
237
+ xml.target!
238
+ end
239
+
240
+ def default_customer_fields
241
+ hash={}
242
+ %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|
243
+ hash[field.to_sym]=''
244
+ end
245
+ return hash
246
+ end
247
+
248
+ def default_payment_fields
249
+ hash={}
250
+ %w( managedCustomerID amount invoiceReference invoiceDescription ).each do |field|
251
+ hash[field.to_sym]=''
252
+ end
253
+ return hash
254
+ end
255
+
256
+ class EwayResponse < Response
257
+ # add a method to response so we can easily get the eway token "ManagedCustomerID"
258
+ def token
259
+ @params['CreateCustomerResult']
260
+ end
261
+ end
262
+
263
+ end
264
+ end
265
+ end