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,25 @@
1
+ module ActiveMerchant #:nodoc:
2
+ module Billing #:nodoc:
3
+ ##
4
+ # Delegates to the appropriate gateway, either the Transaction or Advanced
5
+ # depending on options passed to new.
6
+ #
7
+ class UsaEpayGateway < Gateway
8
+
9
+ self.abstract_class = true
10
+
11
+ ##
12
+ # Creates an instance of UsaEpayTransactionGateway by default, but if
13
+ # :software id or :live_url are passed in the options hash it will
14
+ # create an instance of UsaEpayAdvancedGateway.
15
+ #
16
+ def self.new(options={})
17
+ unless options.has_key?(:software_id) || options.has_key?(:live_url)
18
+ UsaEpayTransactionGateway.new(options)
19
+ else
20
+ UsaEpayAdvancedGateway.new(options)
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,1497 @@
1
+ require 'securerandom'
2
+ require 'digest'
3
+
4
+ module ActiveMerchant #:nodoc:
5
+ module Billing #:nodoc:
6
+ # ==== USA ePay Advanced SOAP Interface
7
+ #
8
+ # This class encapuslates USA ePay's Advanced SOAP Interface. The Advanced Soap Interface allows
9
+ # standard transactions, storing customer information, and recurring billing. Storing sensitive
10
+ # information on USA ePay's servers can help with PCI DSS compliance, since customer and card data
11
+ # do not need to be stored locally.
12
+ #
13
+ # Make sure you have enabled this functionality for your account with USA ePay.
14
+ #
15
+ # Information about the Advanced SOAP interface is available on the {USA ePay wiki}[http://wiki.usaepay.com/developer/soap].
16
+ #
17
+ # ==== Login, Password, and Software ID
18
+ #
19
+ # Please follow all of USA ePay's directions for acquiring all accounts and settings.
20
+ #
21
+ # The value used for <tt>:login</tt> is the Key value found in the Merchant Console under Settings > Source
22
+ # Key. You will have to add this key in the USA ePay Merchant Console.
23
+ #
24
+ # The value used for <tt>:password</tt> is the pin value also found and assigned in the Merchant Console under
25
+ # Settings > Source Key. The pin is required to use all but basic transactions in the SOAP interface.
26
+ # You will have to add the pin to your source key, as it defaults to none.
27
+ #
28
+ # The value used for the <tt>:software_id</tt> is found in the Developer's Login under the Developers Center
29
+ # in your WSDL. It is the 8 character value in <soap:address> tag. A masked example:
30
+ # <soap:address location="https://www.usaepay.com/soap/gate/XXXXXXXX"/>
31
+ # It is also found in the link to your WSDL. This is required as every account has a different path
32
+ # SOAP requests are submitted to. Optionally, you can provide the entire urls via <tt>:live_url</tt> and <tt>:test_url</tt>, if your prefer.
33
+ #
34
+ # ==== Responses
35
+ # * <tt>#success?</tt> -- +true+ if transmitted and returned correctly
36
+ # * <tt>#message</tt> -- response or fault message
37
+ # * <tt>#authorization</tt> -- reference_number or nil
38
+ # * <tt>#params</tt> -- hash of entire soap response contents
39
+ #
40
+ # ==== Address Options
41
+ # * <tt>:billing_address/:shipping_address</tt> -- contains some extra options
42
+ # * <tt>:name</tt> -- virtual attribute; will split to first and last name
43
+ # * <tt>:first_name</tt>
44
+ # * <tt>:last_name</tt>
45
+ # * <tt>:address1 </tt>
46
+ # * <tt>:address2 </tt>
47
+ # * <tt>:city </tt>
48
+ # * <tt>:state </tt>
49
+ # * <tt>:zip </tt>
50
+ # * <tt>:country </tt>
51
+ # * <tt>:phone</tt>
52
+ # * <tt>:email</tt>
53
+ # * <tt>:fax</tt>
54
+ # * <tt>:company</tt>
55
+ #
56
+ # ==== Support:
57
+ # * Questions: post to {active_merchant google group}[http://groups.google.com/group/activemerchant]
58
+ # * Feedback/fixes: matt (at) nearapogee (dot) com
59
+ #
60
+ # ==== Links:
61
+ # * {USA ePay Merchant Console}[https://sandbox.usaepay.com/login]
62
+ # * {USA ePay Developer Login}[https://www.usaepay.com/developer/login]
63
+ #
64
+ class UsaEpayAdvancedGateway < Gateway
65
+ API_VERSION = "1.4"
66
+
67
+ TEST_URL_BASE = 'https://sandbox.usaepay.com/soap/gate/' #:nodoc:
68
+ LIVE_URL_BASE = 'https://www.usaepay.com/soap/gate/' #:nodoc:
69
+
70
+ self.test_url = TEST_URL_BASE
71
+ self.live_url = LIVE_URL_BASE
72
+
73
+ FAILURE_MESSAGE = "Default Failure" #:nodoc:
74
+
75
+ self.supported_countries = ['US']
76
+ self.supported_cardtypes = [:visa, :master, :american_express, :discover, :diners_club, :jcb]
77
+ self.homepage_url = 'http://www.usaepay.com/'
78
+ self.display_name = 'USA ePay Advanced SOAP Interface'
79
+
80
+ CUSTOMER_OPTIONS = {
81
+ :id => [:string, 'CustomerID'], # merchant assigned number
82
+ :notes => [:string, 'Notes'],
83
+ :data => [:string, 'CustomData'],
84
+ :url => [:string, 'URL'],
85
+ # Recurring Billing
86
+ :enabled => [:boolean, 'Enabled'],
87
+ :schedule => [:string, 'Schedule'],
88
+ :number_left => [:integer, 'NumLeft'],
89
+ :currency => [:string, 'Currency'],
90
+ :description => [:string, 'Description'],
91
+ :order_id => [:string, 'OrderID'],
92
+ :user => [:string, 'User'],
93
+ :source => [:string, 'Source'],
94
+ :send_receipt => [:boolean, 'SendReceipt'],
95
+ :receipt_note => [:string, 'ReceiptNote'],
96
+ # Point of Sale
97
+ :price_tier => [:string, 'PriceTier'],
98
+ :tax_class => [:string, 'TaxClass'],
99
+ :lookup_code => [:string, 'LookupCode']
100
+ } #:nodoc:
101
+
102
+ ADDRESS_OPTIONS = {
103
+ :first_name => [:string, 'FirstName'],
104
+ :last_name => [:string, 'LastName'],
105
+ :address1 => [:string, 'Street'],
106
+ :address2 => [:string, 'Street2'],
107
+ :city => [:string, 'City'],
108
+ :state => [:string, 'State'],
109
+ :zip => [:string, 'Zip'],
110
+ :country => [:string, 'Country'],
111
+ :phone => [:string, 'Phone'],
112
+ :email => [:string, 'Email'],
113
+ :fax => [:string, 'Fax'],
114
+ :company => [:string, 'Company']
115
+ } #:nodoc:
116
+
117
+ CUSTOMER_TRANSACTION_REQUEST_OPTIONS = {
118
+ :command => [:string, 'Command'],
119
+ :ignore_duplicate => [:boolean, 'IgnoreDuplicate'],
120
+ :client_ip => [:string, 'ClientIP'],
121
+ :customer_receipt => [:boolean, 'CustReceipt'],
122
+ :customer_email => [:boolean, 'CustReceiptEmail'],
123
+ :customer_template => [:boolean, 'CustReceiptName'],
124
+ :merchant_receipt => [:boolean, 'MerchReceipt'],
125
+ :merchant_email => [:boolean, 'MerchReceiptEmail'],
126
+ :merchant_template => [:boolean, 'MerchReceiptName'],
127
+ :verification_value => [:boolean, 'isRecurring'],
128
+ :software => [:string, 'Software']
129
+ } #:nodoc:
130
+
131
+ TRANSACTION_REQUEST_OBJECT_OPTIONS = {
132
+ :command => [:string, 'Command'],
133
+ :ignore_duplicate => [:boolean, 'IgnoreDuplicate'],
134
+ :authorization_code => [:string, 'AuthCode'],
135
+ :reference_number => [:string, 'RefNum'],
136
+ :account_holder => [:string, 'AccountHolder'],
137
+ :client_ip => [:string, 'ClientIP'],
138
+ :customer_id => [:string, 'CustomerID'],
139
+ :customer_receipt => [:boolean, 'CustReceipt'],
140
+ :customer_template => [:boolean, 'CustReceiptName'],
141
+ :software => [:string, 'Software']
142
+ } #:nodoc:
143
+
144
+ TRANSACTION_DETAIL_OPTIONS = {
145
+ :invoice => [:string, 'Invoice'],
146
+ :po_number => [:string, 'PONum'],
147
+ :order_id => [:string, 'OrderID'],
148
+ :clerk => [:string, 'Clerk'],
149
+ :terminal => [:string, 'Terminal'],
150
+ :table => [:string, 'Table'],
151
+ :description => [:string, 'Description'],
152
+ :comments => [:string, 'Comments'],
153
+ :allow_partial_auth => [:boolean, 'AllowPartialAuth'],
154
+ :currency => [:string, 'Currency'],
155
+ :non_tax => [:boolean, 'NonTax'],
156
+ } #:nodoc:
157
+
158
+ TRANSACTION_DETAIL_MONEY_OPTIONS = {
159
+ :amount => [:double, 'Amount'],
160
+ :tax => [:double, 'Tax'],
161
+ :tip => [:double, 'Tip'],
162
+ :non_tax => [:boolean, 'NonTax'],
163
+ :shipping => [:double, 'Shipping'],
164
+ :discount => [:double, 'Discount'],
165
+ :subtotal => [:double, 'Subtotal']
166
+ } #:nodoc:
167
+
168
+ CREDIT_CARD_DATA_OPTIONS = {
169
+ :magnetic_stripe => [:string, 'MagStripe'],
170
+ :dukpt => [:string, 'DUKPT'],
171
+ :signature => [:string, 'Signature'],
172
+ :terminal_type => [:string, 'TermType'],
173
+ :magnetic_support => [:string, 'MagSupport'],
174
+ :xid => [:string, 'XID'],
175
+ :cavv => [:string, 'CAVV'],
176
+ :eci => [:integer, 'ECI'],
177
+ :internal_card_authorization => [:boolean, 'InternalCardAduth'],
178
+ :pares => [:string, 'Pares']
179
+ } #:nodoc:
180
+
181
+ CHECK_DATA_OPTIONS = {
182
+ :check_number => [:integer, 'CheckNumber'],
183
+ :drivers_license => [:string, 'DriversLicense'],
184
+ :drivers_license_state => [:string, 'DriversLicenseState'],
185
+ :record_type => [:string, 'RecordType'],
186
+ :aux_on_us => [:string, 'AuxOnUS'],
187
+ :epc_code => [:string, 'EpcCode'],
188
+ :front_image => [:string, 'FrontImage'],
189
+ :back_image => [:string, 'BackImage']
190
+ } #:nodoc:
191
+
192
+ RECURRING_BILLING_OPTIONS = {
193
+ :schedule => [:string, 'Schedule'],
194
+ :number_left => [:integer, 'NumLeft'],
195
+ :enabled => [:boolean, 'Enabled']
196
+ } #:nodoc:
197
+
198
+ AVS_RESULTS = {
199
+ 'Y' => %w( YYY Y YYA YYD ),
200
+ 'Z' => %w( NYZ Z ),
201
+ 'A' => %w( YNA A YNY ),
202
+ 'N' => %w( NNN N NN ),
203
+ 'X' => %w( YYX X ),
204
+ 'W' => %w( NYW W ),
205
+ 'XXW' => %w( XXW ),
206
+ 'XXU' => %w( XXU ),
207
+ 'R' => %w( XXR R U E ),
208
+ 'S' => %w( XXS S ),
209
+ 'XXE' => %w( XXE ),
210
+ 'G' => %w( XXG G C I ),
211
+ 'B' => %w( YYG B M ),
212
+ 'D' => %w( GGG D ),
213
+ 'P' => %w( YGG P )
214
+ }.inject({}) do |map, (type, codes)|
215
+ codes.each { |code| map[code] = type }
216
+ map
217
+ end #:nodoc:
218
+
219
+ AVS_CUSTOM_MESSAGES = {
220
+ 'XXW' => 'Card number not on file.',
221
+ 'XXU' => 'Address information not verified for domestic transaction.',
222
+ 'XXE' => 'Address verification not allowed for card type.'
223
+ } #:nodoc:
224
+
225
+ # Create a new gateway.
226
+ #
227
+ # ==== Required
228
+ # * At least the live_url OR the software_id must be present.
229
+ # * <tt>:software_id</tt> -- 8 character software id
230
+ # OR
231
+ # * <tt>:test_url</tt> -- full url for testing
232
+ # * <tt>:live_url</tt> -- full url for live/production
233
+ #
234
+ # ==== Optional
235
+ # * <tt>:soap_response</tt> -- set to +true+ to add :soap_response to the params hash containing the entire soap xml message
236
+ #
237
+ def initialize(options = {})
238
+ requires! options, :login, :password
239
+ @options = options
240
+
241
+ if @options[:software_id]
242
+ self.live_url = "#{LIVE_URL_BASE}#{@options[:software_id].to_s}"
243
+ self.test_url = "#{TEST_URL_BASE}#{@options[:software_id].to_s}"
244
+ else
245
+ self.live_url = @options[:live_url].to_s
246
+ self.test_url = @options[:test_url].to_s if @options[:test_url]
247
+ end
248
+
249
+ super
250
+ end
251
+
252
+ # Standard Gateway Methods ======================================
253
+
254
+ # Make a purchase with a credit card. (Authorize and
255
+ # capture for settlement.)
256
+ #
257
+ # Note: See run_transaction for additional options.
258
+ #
259
+ def purchase(money, creditcard, options={})
260
+ run_sale(options.merge!(:amount => money, :payment_method => creditcard))
261
+ end
262
+
263
+ # Authorize an amount on a credit card or account.
264
+ #
265
+ # Note: See run_transaction for additional options.
266
+ #
267
+ def authorize(money, creditcard, options={})
268
+ run_auth_only(options.merge!(:amount => money, :payment_method => creditcard))
269
+ end
270
+
271
+ # Capture an authorized transaction.
272
+ #
273
+ # Note: See run_transaction for additional options.
274
+ #
275
+ def capture(money, identification, options={})
276
+ capture_transaction(options.merge!(:amount => money, :reference_number => identification))
277
+ end
278
+
279
+ # Void a previous transaction that has not been settled.
280
+ #
281
+ # Note: See run_transaction for additional options.
282
+ #
283
+ def void(identification, options={})
284
+ void_transaction(options.merge!(:reference_number => identification))
285
+ end
286
+
287
+ # Credit a previous transaction.
288
+ #
289
+ # Note: See run_transaction for additional options.
290
+ #
291
+ def credit(money, identification, options={})
292
+ refund_transaction(options.merge!(:amount => money, :reference_number => identification))
293
+ end
294
+
295
+ # Customer ======================================================
296
+
297
+ # Add a customer.
298
+ #
299
+ # ==== Options
300
+ # * <tt>:id</tt> -- merchant assigned id
301
+ # * <tt>:notes</tt> -- notes about customer
302
+ # * <tt>:data</tt> -- base64 data about customer
303
+ # * <tt>:url</tt> -- customer website
304
+ # * <tt>:billing_address</tt> -- usual options
305
+ # * <tt>:payment_methods</tt> -- array of payment method hashes.
306
+ # * <tt>:method</tt> -- credit_card or check
307
+ # * <tt>:name</tt> -- optional name/label for the method
308
+ # * <tt>:sort</tt> -- optional integer value specifying the backup sort order, 0 is default
309
+ #
310
+ # ==== Recurring Options
311
+ # * <tt>:enabled</tt> -- +true+ enables recurring
312
+ # * <tt>:schedule</tt> -- daily, weekly, bi-weekly (every two weeks), monthly, bi-monthly (every two months), quarterly, bi-annually (every six months), annually, first of month, last day of month
313
+ # * <tt>:number_left</tt> -- number of payments left; -1 for unlimited
314
+ # * <tt>:next</tt> -- date of next payment (Date/Time)
315
+ # * <tt>:amount</tt> -- amount of recurring payment
316
+ # * <tt>:tax</tt> -- tax portion of amount
317
+ # * <tt>:currency</tt> -- numeric currency code
318
+ # * <tt>:description</tt> -- description of transaction
319
+ # * <tt>:order_id</tt> -- transaction order id
320
+ # * <tt>:user</tt> -- merchant username assigned to transaction
321
+ # * <tt>:source</tt> -- name of source key assigned to billing
322
+ # * <tt>:send_receipt</tt> -- +true+ to send client a receipt
323
+ # * <tt>:receipt_note</tt> -- leave a note on the receipt
324
+ #
325
+ # ==== Point of Sale Options
326
+ # * <tt>:price_tier</tt> -- name of customer price tier
327
+ # * <tt>:tax_class</tt> -- tax class
328
+ # * <tt>:lookup_code</tt> -- lookup code from customer/member id card; barcode or magnetic stripe; can be assigned by merchant; defaults to system assigned if blank
329
+ #
330
+ # ==== Response
331
+ # * <tt>#message</tt> -- customer number assigned by gateway
332
+ #
333
+ def add_customer(options={})
334
+ request = build_request(__method__, options)
335
+ commit(__method__, request)
336
+ end
337
+
338
+ # Update a customer by replacing all of the customer details..
339
+ #
340
+ # Use quickUpdateCustomer to just update a few attributes.
341
+ #
342
+ # ==== Options
343
+ # * Same as add_customer
344
+ #
345
+ def update_customer(options={})
346
+ requires! options, :customer_number
347
+
348
+ request = build_request(__method__, options)
349
+ commit(__method__, request)
350
+ end
351
+
352
+ # Enable a customer for recurring billing.
353
+ #
354
+ # Note: Customer does not need to have all recurring paramerters to succeed.
355
+ #
356
+ # ==== Required
357
+ # * <tt>:customer_number</tt>
358
+ #
359
+ def enable_customer(options={})
360
+ requires! options, :customer_number
361
+
362
+ request = build_request(__method__, options)
363
+ commit(__method__, request)
364
+ end
365
+
366
+ # Disable a customer for recurring billing.
367
+ #
368
+ # ==== Required
369
+ # * <tt>:customer_number</tt>
370
+ #
371
+ def disable_customer(options={})
372
+ requires! options, :customer_number
373
+
374
+ request = build_request(__method__, options)
375
+ commit(__method__, request)
376
+ end
377
+
378
+ # Add a payment method to a customer.
379
+ #
380
+ # ==== Required
381
+ # * <tt>:customer_number</tt> -- number returned by add_customer response.message
382
+ # * <tt>:payment_method</tt>
383
+ # * <tt>:method</tt> -- credit_card or check
384
+ # * <tt>:name</tt> -- optional name/label for the method
385
+ # * <tt>:sort</tt> -- an integer value specifying the backup sort order, 0 is default
386
+ #
387
+ # ==== Optional
388
+ # * <tt>:make_default</tt> -- set +true+ to make default
389
+ # * <tt>:verify</tt> -- set +true+ to run auth_only verification; throws fault if cannot verify
390
+ #
391
+ # ==== Response
392
+ # * <tt>#message</tt> -- method_id of new customer payment method
393
+ #
394
+ def add_customer_payment_method(options={})
395
+ requires! options, :customer_number
396
+
397
+ request = build_request(__method__, options)
398
+ commit(__method__, request)
399
+ end
400
+
401
+ # Retrive all of the payment methods belonging to a customer
402
+ #
403
+ # ==== Required
404
+ # * <tt>:customer_number</tt>
405
+ #
406
+ # ==== Response
407
+ # * <tt>#message</tt> -- either a single hash or an array of hashes of payment methods
408
+ #
409
+ def get_customer_payment_methods(options={})
410
+ requires! options, :customer_number
411
+
412
+ request = build_request(__method__, options)
413
+ commit(__method__, request)
414
+ end
415
+
416
+ # Retrive one of the payment methods belonging to a customer
417
+ #
418
+ # ==== Required
419
+ # * <tt>:customer_number</tt>
420
+ # * <tt>:method_id</tt>
421
+ #
422
+ # ==== Response
423
+ # * <tt>#message</tt> -- hash of payment method
424
+ #
425
+ def get_customer_payment_method(options={})
426
+ requires! options, :customer_number, :method_id
427
+
428
+ request = build_request(__method__, options)
429
+ commit(__method__, request)
430
+ end
431
+
432
+ # Update a customer payment method.
433
+ #
434
+ # ==== Required
435
+ # * <tt>:method_id</tt> -- method_id to update
436
+ #
437
+ # ==== Options
438
+ # * <tt>:method</tt> -- credit_card or check
439
+ # * <tt>:name</tt> -- optional name/label for the method
440
+ # * <tt>:sort</tt> -- an integer value specifying the backup sort order, 0 is default
441
+ # * <tt>:verify</tt> -- set +true+ to run auth_only verification; throws fault if cannot verify
442
+ #
443
+ # ==== Response
444
+ # * <tt>#message</tt> -- hash of payment method
445
+ #
446
+ def update_customer_payment_method(options={})
447
+ requires! options, :method_id
448
+
449
+ request = build_request(__method__, options)
450
+ commit(__method__, request)
451
+ end
452
+
453
+ # Delete one the payment methods beloning to a customer
454
+ #
455
+ # ==== Required
456
+ # * <tt>:customer_number</tt>
457
+ # * <tt>:method_id</tt>
458
+ #
459
+ def delete_customer_payment_method(options={})
460
+ requires! options, :customer_number, :method_id
461
+
462
+ request = build_request(__method__, options)
463
+ commit(__method__, request)
464
+ end
465
+
466
+ # Delete a customer.
467
+ #
468
+ # ==== Required
469
+ # * <tt>:customer_number</tt>
470
+ #
471
+ def delete_customer(options={})
472
+ requires! options, :customer_number
473
+
474
+ request = build_request(__method__, options)
475
+ commit(__method__, request)
476
+ end
477
+
478
+ # Run a transaction for an existing customer in the database.
479
+ #
480
+ # ==== Required Options
481
+ # * <tt>:customer_number</tt> -- gateway assigned identifier
482
+ # * <tt>:command</tt> -- Sale, AuthOnly, Credit, Check, CheckCredit
483
+ # * <tt>:amount</tt> -- total amount
484
+ #
485
+ # ==== Options
486
+ # * <tt>:method_id</tt> -- which payment method to use, 0/nil/omitted for default method
487
+ # * <tt>:ignore_duplicate</tt> -- +true+ overrides duplicate transaction
488
+ # * <tt>:client_ip</tt> -- client ip address
489
+ # * <tt>:customer_receipt</tt> -- +true+, sends receipt to customer. active_merchant defaults to +false+
490
+ # * <tt>:customer_email</tt> -- specify if different than customer record
491
+ # * <tt>:customer_template</tt> -- name of template
492
+ # * <tt>:merchant_receipt</tt> -- +true+, sends receipt to merchant. active_merchant defaults to +false+
493
+ # * <tt>:merchant_email</tt> -- required if :merchant_receipt set to +true+
494
+ # * <tt>:merchant_template</tt> -- name of template
495
+ # * <tt>:recurring</tt> -- defaults to +false+ *see documentation*
496
+ # * <tt>:verification_value</tt> -- pci forbids storage of this value, only required for CVV2 validation
497
+ # * <tt>:software</tt> -- active_merchant sets to required gateway option value
498
+ # * <tt>:line_items</tt> -- XXX not implemented yet
499
+ # * <tt>:custom_fields</tt> -- XXX not implemented yet
500
+ #
501
+ # ==== Transaction Options
502
+ # * <tt>:invoice</tt> -- transaction invoice number; truncated to 10 characters; defaults to reference_number
503
+ # * <tt>:po_number</tt> -- commercial purchase order number; upto 25 characters
504
+ # * <tt>:order_id</tt> -- should be used to assign a unique id; upto 64 characters
505
+ # * <tt>:clerk</tt> -- sales clerk
506
+ # * <tt>:terminal</tt> -- terminal name
507
+ # * <tt>:table</tt> -- table name/number
508
+ # * <tt>:description</tt> -- description
509
+ # * <tt>:comments</tt> -- comments
510
+ # * <tt>:allow_partial_auth</tt> -- allow partial authorization if full amount is not available; defaults +false+
511
+ # * <tt>:currency</tt> -- numeric currency code
512
+ # * <tt>:tax</tt> -- tax portion of amount
513
+ # * <tt>:tip</tt> -- tip portion of amount
514
+ # * <tt>:non_tax</tt> -- +true+ if transaction is non-taxable
515
+ # * <tt>:shipping</tt> -- shipping portion of amount
516
+ # * <tt>:discount</tt> -- amount of discount
517
+ # * <tt>:subtotal</tt> -- amount of transaction before tax, tip, shipping, and discount are applied
518
+ #
519
+ # ==== Response
520
+ # * <tt>#message</tt> -- transaction response hash
521
+ #
522
+ def run_customer_transaction(options={})
523
+ requires! options, :customer_number, :command, :amount
524
+
525
+ request = build_request(__method__, options)
526
+ commit(__method__, request)
527
+ end
528
+
529
+ # Transactions ==================================================
530
+
531
+ # Run a transaction.
532
+ #
533
+ # Note: run_sale, run_auth_only, run_credit, run_check_sale, run_check_credit
534
+ # methods are also available. Each takes the same options as
535
+ # run_transaction, but the :command option is not required.
536
+ #
537
+ # Recurring Note: If recurring options are included USA ePay will create a
538
+ # new customer record with the supplied information. The customer number
539
+ # will be returned in the response.
540
+ #
541
+ # ==== Options
542
+ # * <tt>:method</tt> -- credit_card or check
543
+ # * <tt>:command</tt> -- sale, credit, void, creditvoid, authonly, capture, postauth, check, checkcredit; defaults to sale; only required for run_transaction when other than sale
544
+ # * <tt>:reference_number</tt> -- for the original transaction; obtained by sale or authonly
545
+ # * <tt>:authorization_code</tt> -- required for postauth; obtained offline
546
+ # * <tt>:ignore_duplicate</tt> -- set +true+ if you want to override the duplicate tranaction handling
547
+ # * <tt>:account_holder</tt> -- name of account holder
548
+ # * <tt>:customer_id</tt> -- merchant assigned id
549
+ # * <tt>:customer_receipt</tt> -- set +true+ to email receipt to billing email address
550
+ # * <tt>:customer_template</tt> -- name of template
551
+ # * <tt>:software</tt> -- stamp merchant software version for tracking
552
+ # * <tt>:billing_address</tt> -- see UsaEpayCimGateway documentation for all address fields
553
+ # * <tt>:shipping_address</tt> -- see UsaEpayCimGateway documentation for all address fields
554
+ # * <tt>:recurring</tt> -- used for recurring billing transactions
555
+ # * <tt>:schedule</tt> -- disabled, daily, weekly, bi-weekly (every two weeks), monthly, bi-monthly (every two months), quarterly, bi-annually (every six months), annually
556
+ # * <tt>:next</tt> -- date customer billed next (Date/Time)
557
+ # * <tt>:expire</tt> -- date the recurring transactions end (Date/Time)
558
+ # * <tt>:number_left</tt> -- transactions remaining in billing cycle
559
+ # * <tt>:amount</tt> -- amount to be billed each recurring transaction
560
+ # * <tt>:enabled</tt> -- states if currently active
561
+ # * <tt>:line_items</tt> -- XXX not implemented yet
562
+ # * <tt>:custom_fields</tt> -- XXX not implemented yet
563
+ #
564
+ # ==== Transaction Options
565
+ # * <tt>:amount</tt> -- total amount
566
+ # * <tt>:invoice</tt> -- transaction invoice number; truncated to 10 characters; defaults to reference_number
567
+ # * <tt>:po_number</tt> -- commercial purchase order number; upto 25 characters
568
+ # * <tt>:order_id</tt> -- should be used to assign a unique id; upto 64 characters
569
+ # * <tt>:clerk</tt> -- sales clerk
570
+ # * <tt>:terminal</tt> -- terminal name
571
+ # * <tt>:table</tt> -- table name/number
572
+ # * <tt>:description</tt> -- description
573
+ # * <tt>:comments</tt> -- comments
574
+ # * <tt>:allow_partial_auth</tt> -- allow partial authorization if full amount is not available; defaults +false+
575
+ # * <tt>:currency</tt> -- numeric currency code
576
+ # * <tt>:tax</tt> -- tax portion of amount
577
+ # * <tt>:tip</tt> -- tip portion of amount
578
+ # * <tt>:non_tax</tt> -- +true+ if transaction is non-taxable
579
+ # * <tt>:shipping</tt> -- shipping portion of amount
580
+ # * <tt>:discount</tt> -- amount of discount
581
+ # * <tt>:subtotal</tt> -- amount of transaction before tax, tip, shipping, and discount are applied
582
+ #
583
+ # ==== Response
584
+ # * <tt>#message</tt> -- transaction response hash
585
+ #
586
+ def run_transaction(options={})
587
+ request = build_request(__method__, options)
588
+ commit(__method__, request)
589
+ end
590
+
591
+ TRANSACTION_METHODS = [
592
+ :run_sale, :run_auth_only, :run_credit,
593
+ :run_check_sale, :run_check_credit
594
+ ] #:nodoc:
595
+
596
+ TRANSACTION_METHODS.each do |method|
597
+ define_method method do |options|
598
+ request = build_request(method, options)
599
+ commit(method, request)
600
+ end
601
+ end
602
+
603
+ # Post an authorization code obtained offline.
604
+ #
605
+ # ==== Required
606
+ # * <tt>:authorization_code</tt> -- obtained offline
607
+ #
608
+ # ==== Options
609
+ # * Same as run_transaction
610
+ #
611
+ # ==== Response
612
+ # * <tt>#message</tt> -- transaction response hash
613
+ #
614
+ def post_auth(options={})
615
+ requires! options, :authorization_code
616
+
617
+ request = build_request(__method__, options)
618
+ commit(__method__, request)
619
+ end
620
+
621
+ # Capture an authorized transaction and move it into the current batch
622
+ # for settlement.
623
+ #
624
+ # Note: Check with merchant bank for details/restrictions on differing
625
+ # amounts than the original authorization.
626
+ #
627
+ # ==== Required
628
+ # * <tt>:reference_number</tt>
629
+ #
630
+ # ==== Options
631
+ # * <tt>:amount</tt> -- may be different than original amount; 0 will void authorization
632
+ #
633
+ # ==== Response
634
+ # * <tt>#message</tt> -- transaction response hash
635
+ #
636
+ def capture_transaction(options={})
637
+ requires! options, :reference_number
638
+
639
+ request = build_request(__method__, options)
640
+ commit(__method__, request)
641
+ end
642
+
643
+ # Void a transaction.
644
+ #
645
+ # Note: Can only be voided before being settled.
646
+ #
647
+ # ==== Required
648
+ # * <tt>:reference_number</tt>
649
+ #
650
+ # ==== Response
651
+ # * <tt>#message</tt> -- transaction response hash
652
+ #
653
+ def void_transaction(options={})
654
+ requires! options, :reference_number
655
+
656
+ request = build_request(__method__, options)
657
+ commit(__method__, request)
658
+ end
659
+
660
+ # Refund transaction.
661
+ #
662
+ # Note: Required after a transaction has been settled. Refunds
663
+ # both credit card and check transactions.
664
+ #
665
+ # ==== Required
666
+ # * <tt>:reference_number</tt>
667
+ # * <tt>:amount</tt> -- amount to refund; 0 will refund original amount
668
+ #
669
+ # ==== Response
670
+ # * <tt>#message</tt> -- transaction response hash
671
+ #
672
+ def refund_transaction(options={})
673
+ requires! options, :reference_number, :amount
674
+
675
+ request = build_request(__method__, options)
676
+ commit(__method__, request)
677
+ end
678
+
679
+ # Override transaction flagged for mananager approval.
680
+ #
681
+ # Note: Checks only!
682
+ #
683
+ # ==== Required
684
+ # * <tt>:reference_number</tt>
685
+ #
686
+ # ==== Options
687
+ # * <tt>:reason</tt>
688
+ #
689
+ # ==== Response
690
+ # * <tt>#message</tt> -- transaction response hash
691
+ #
692
+ def override_transaction(options={})
693
+ requires! options, :reference_number
694
+
695
+ request = build_request(__method__, options)
696
+ commit(__method__, request)
697
+ end
698
+
699
+ # Quick Transactions ============================================
700
+
701
+ # Run a sale transaction based off of a past transaction.
702
+ #
703
+ # Transfers referenced transaction's payment method to this
704
+ # transaction. As of 6/2011, USA ePay blocks credit card numbers
705
+ # at 3 years.
706
+ #
707
+ # ==== Required
708
+ # * <tt>:reference_number</tt> -- transaction to reference payment from
709
+ # * <tt>:amount</tt> -- total amount
710
+ #
711
+ # ==== Options
712
+ # * <tt>:authorize_only</tt> -- set +true+ if you just want to authorize
713
+ #
714
+ # ==== Transaction Options
715
+ # * <tt>:invoice</tt> -- transaction invoice number; truncated to 10 characters; defaults to reference_number
716
+ # * <tt>:po_number</tt> -- commercial purchase order number; upto 25 characters
717
+ # * <tt>:order_id</tt> -- should be used to assign a unique id; upto 64 characters
718
+ # * <tt>:clerk</tt> -- sales clerk
719
+ # * <tt>:terminal</tt> -- terminal name
720
+ # * <tt>:table</tt> -- table name/number
721
+ # * <tt>:description</tt> -- description
722
+ # * <tt>:comments</tt> -- comments
723
+ # * <tt>:allow_partial_auth</tt> -- allow partial authorization if full amount is not available; defaults +false+
724
+ # * <tt>:currency</tt> -- numeric currency code
725
+ # * <tt>:tax</tt> -- tax portion of amount
726
+ # * <tt>:tip</tt> -- tip portion of amount
727
+ # * <tt>:non_tax</tt> -- +true+ if transaction is non-taxable
728
+ # * <tt>:shipping</tt> -- shipping portion of amount
729
+ # * <tt>:discount</tt> -- amount of discount
730
+ # * <tt>:subtotal</tt> -- amount of transaction before tax, tip, shipping, and discount are applied
731
+ #
732
+ # ==== Response
733
+ # * <tt>#message</tt> -- transaction response hash
734
+ #
735
+ def run_quick_sale(options={})
736
+ requires! options, :reference_number, :amount
737
+
738
+ request = build_request(__method__, options)
739
+ commit(__method__, request)
740
+ end
741
+
742
+ # Run a credit based off of a past transaction.
743
+ #
744
+ # Transfers referenced transaction's payment method to this
745
+ # transaction. As of 6/2011, USA ePay blocks credit card numbers
746
+ # at 3 years.
747
+ #
748
+ # ==== Required
749
+ # * <tt>:reference_number</tt> -- transaction to reference payment from
750
+ #
751
+ # ==== Transaction Options
752
+ # * <tt>:amount</tt> -- total amount
753
+ # * <tt>:invoice</tt> -- transaction invoice number; truncated to 10 characters; defaults to reference_number
754
+ # * <tt>:po_number</tt> -- commercial purchase order number; upto 25 characters
755
+ # * <tt>:order_id</tt> -- should be used to assign a unique id; upto 64 characters
756
+ # * <tt>:clerk</tt> -- sales clerk
757
+ # * <tt>:terminal</tt> -- terminal name
758
+ # * <tt>:table</tt> -- table name/number
759
+ # * <tt>:description</tt> -- description
760
+ # * <tt>:comments</tt> -- comments
761
+ # * <tt>:allow_partial_auth</tt> -- allow partial authorization if full amount is not available; defaults +false+
762
+ # * <tt>:currency</tt> -- numeric currency code
763
+ # * <tt>:tax</tt> -- tax portion of amount
764
+ # * <tt>:tip</tt> -- tip portion of amount
765
+ # * <tt>:non_tax</tt> -- +true+ if transaction is non-taxable
766
+ # * <tt>:shipping</tt> -- shipping portion of amount
767
+ # * <tt>:discount</tt> -- amount of discount
768
+ # * <tt>:subtotal</tt> -- amount of transaction before tax, tip, shipping, and discount are applied
769
+ #
770
+ # ==== Response
771
+ # * <tt>#message</tt> -- transaction response hash
772
+ #
773
+ def run_quick_credit(options={})
774
+ requires! options, :reference_number
775
+
776
+ request = build_request(__method__, options)
777
+ commit(__method__, request)
778
+ end
779
+
780
+ # Transaction Status ============================================
781
+
782
+ # Retrieve details of a specified transaction.
783
+ #
784
+ # ==== Required
785
+ # * <tt>:reference_number</tt>
786
+ #
787
+ # ==== Response
788
+ # * <tt>#message</tt> -- transaction hash
789
+ #
790
+ def get_transaction(options={})
791
+ requires! options, :reference_number
792
+
793
+ request = build_request(__method__, options)
794
+ commit(__method__, request)
795
+ end
796
+
797
+ # Check status of a transaction.
798
+ #
799
+ # ==== Required
800
+ # * <tt>:reference_number</tt>
801
+ #
802
+ # ==== Response
803
+ # * <tt>response.success</tt> -- success of the referenced transaction
804
+ # * <tt>response.message</tt> -- message of the referenced transaction
805
+ # * <tt>response.authorization</tt> -- same as :reference_number in options
806
+ #
807
+ def get_transaction_status(options={})
808
+ requires! options, :reference_number
809
+
810
+ request = build_request(__method__, options)
811
+ commit(__method__, request)
812
+ end
813
+
814
+ # Check status of a transaction (custom).
815
+ #
816
+ # ==== Required
817
+ # * <tt>:reference_number</tt>
818
+ # * <tt>:fields</tt> -- string array of fields to retrieve
819
+ # * <tt>Response.AuthCode</tt>
820
+ # * <tt>Response.AvsResult</tt>
821
+ # * <tt>Response.AvsResultCode</tt>
822
+ # * <tt>Response.BatchNum</tt>
823
+ # * <tt>Response.CardCodeResult</tt>
824
+ # * <tt>Response.CardCodeResultCode</tt>
825
+ # * <tt>Response.ConversionRate</tt>
826
+ # * <tt>Response.ConvertedAmount</tt>
827
+ # * <tt>Response.ConvertedAmountCurrency</tt>
828
+ # * <tt>Response.Error</tt>
829
+ # * <tt>Response.ErrorCode</tt>
830
+ # * <tt>Response.RefNum</tt>
831
+ # * <tt>Response.Result</tt>
832
+ # * <tt>Response.ResultCode</tt>
833
+ # * <tt>Response.Status</tt>
834
+ # * <tt>Response.StatusCode</tt>
835
+ # * <tt>CheckTrace.TrackingNum</tt>
836
+ # * <tt>CheckTrace.Effective</tt>
837
+ # * <tt>CheckTrace.Processed</tt>
838
+ # * <tt>CheckTrace.Settled</tt>
839
+ # * <tt>CheckTrace.Returned</tt>
840
+ # * <tt>CheckTrace.BankNote</tt>
841
+ # * <tt>DateTime</tt>
842
+ # * <tt>AccountHolder</tt>
843
+ # * <tt>Details.Invoice</tt>
844
+ # * <tt>Details.PoNum</tt>
845
+ # * <tt>Details.OrderID</tt>
846
+ # * <tt>Details.Clerk</tt>
847
+ # * <tt>Details.Terminal</tt>
848
+ # * <tt>Details.Table</tt>
849
+ # * <tt>Details.Description</tt>
850
+ # * <tt>Details.Amount</tt>
851
+ # * <tt>Details.Currency</tt>
852
+ # * <tt>Details.Tax</tt>
853
+ # * <tt>Details.Tip</tt>
854
+ # * <tt>Details.NonTax</tt>
855
+ # * <tt>Details.Shipping</tt>
856
+ # * <tt>Details.Discount</tt>
857
+ # * <tt>Details.Subtotal</tt>
858
+ # * <tt>CreditCardData.CardType</tt>
859
+ # * <tt>CreditCardData.CardNumber</tt>
860
+ # * <tt>CreditCardData.CardExpiration</tt>
861
+ # * <tt>CreditCardData.CardCode</tt>
862
+ # * <tt>CreditCardData.AvsStreet</tt>
863
+ # * <tt>CreditCardData.AvsZip</tt>
864
+ # * <tt>CreditCardData.CardPresent</tt>
865
+ # * <tt>CheckData.CheckNumber</tt>
866
+ # * <tt>CheckData.Routing</tt>
867
+ # * <tt>CheckData.Account</tt>
868
+ # * <tt>CheckData.SSN</tt>
869
+ # * <tt>CheckData.DriversLicense</tt>
870
+ # * <tt>CheckData.DriversLicenseState</tt>
871
+ # * <tt>CheckData.RecordType</tt>
872
+ # * <tt>User</tt>
873
+ # * <tt>Source</tt>
874
+ # * <tt>ServerIP</tt>
875
+ # * <tt>ClientIP</tt>
876
+ # * <tt>CustomerID</tt>
877
+ # * <tt>BillingAddress.FirstName</tt>
878
+ # * <tt>BillingAddress.LastName</tt>
879
+ # * <tt>BillingAddress.Company</tt>
880
+ # * <tt>BillingAddress.Street</tt>
881
+ # * <tt>BillingAddress.Street2</tt>
882
+ # * <tt>BillingAddress.City</tt>
883
+ # * <tt>BillingAddress.State</tt>
884
+ # * <tt>BillingAddress.Zip</tt>
885
+ # * <tt>BillingAddress.Country</tt>
886
+ # * <tt>BillingAddress.Phone</tt>
887
+ # * <tt>BillingAddress.Fax</tt>
888
+ # * <tt>BillingAddress.Email</tt>
889
+ # * <tt>ShippingAddress.FirstName</tt>
890
+ # * <tt>ShippingAddress.LastName</tt>
891
+ # * <tt>ShippingAddress.Company</tt>
892
+ # * <tt>ShippingAddress.Street</tt>
893
+ # * <tt>ShippingAddress.Street2</tt>
894
+ # * <tt>ShippingAddress.City</tt>
895
+ # * <tt>ShippingAddress.State</tt>
896
+ # * <tt>ShippingAddress.Zip</tt>
897
+ # * <tt>ShippingAddress.Country</tt>
898
+ # * <tt>ShippingAddress.Phone</tt>
899
+ # * <tt>ShippingAddress.Fax</tt>
900
+ # * <tt>ShippingAddress.Email</tt>
901
+ #
902
+ # ==== Response
903
+ # * <tt>#message</tt> -- hash; keys are the field values
904
+ #
905
+ def get_transaction_custom(options={})
906
+ requires! options, :reference_number, :fields
907
+
908
+ request = build_request(__method__, options)
909
+ commit(__method__, request)
910
+ end
911
+
912
+ # Check status of a check transaction.
913
+ #
914
+ # ==== Required
915
+ # * <tt>:reference_number</tt>
916
+ #
917
+ # ==== Response
918
+ # * <tt>#message</tt> -- check trace hash
919
+ #
920
+ def get_check_trace(options={})
921
+ requires! options, :reference_number
922
+
923
+ request = build_request(__method__, options)
924
+ commit(__method__, request)
925
+ end
926
+
927
+ # Account =======================================================
928
+
929
+ # Retrieve merchant account details
930
+ #
931
+ # ==== Response
932
+ # * <tt>#message</tt> -- account hash
933
+ #
934
+ def get_account_details
935
+ request = build_request(__method__)
936
+ commit(__method__, request)
937
+ end
938
+
939
+ # Builders ======================================================
940
+
941
+ private
942
+
943
+ # Build soap header, etc.
944
+ def build_request(action, options = {})
945
+ soap = Builder::XmlMarkup.new
946
+ soap.instruct!(:xml, :version => '1.0', :encoding => 'utf-8')
947
+ soap.tag! "SOAP-ENV:Envelope",
948
+ 'xmlns:SOAP-ENV' => 'http://schemas.xmlsoap.org/soap/envelope/',
949
+ 'xmlns:ns1' => 'urn:usaepay',
950
+ 'xmlns:xsd' => 'http://www.w3.org/2001/XMLSchema',
951
+ 'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
952
+ 'xmlns:SOAP-ENC' => 'http://schemas.xmlsoap.org/soap/encoding/',
953
+ 'SOAP-ENV:encodingStyle' => 'http://schemas.xmlsoap.org/soap/encoding/' do |soap|
954
+ soap.tag! "SOAP-ENV:Body" do |soap|
955
+ send("build_#{action}", soap, options)
956
+ end
957
+ end
958
+ soap.target!
959
+ end
960
+
961
+ # Build generic tag.
962
+ def build_tag(soap, type, tag, value)
963
+ soap.tag!(tag, value, 'xsi:type' => "xsd:#{type}") if value != nil
964
+ end
965
+
966
+ # Build token.
967
+ def build_token(soap, options)
968
+ seed = SecureRandom.base64(32)
969
+ hash = Digest::SHA1.hexdigest("#{@options[:login]}#{seed}#{@options[:password].to_s.strip}")
970
+ soap.Token 'xsi:type' => 'ns1:ueSecurityToken' do |soap|
971
+ build_tag soap, :string, 'ClientIP', options[:client_ip]
972
+ soap.PinHash 'xsi:type' => 'ns1:ueHash' do |soap|
973
+ build_tag soap, :string, "HashValue", hash
974
+ build_tag soap, :string, "Seed", seed
975
+ build_tag soap, :string, "Type", 'sha1'
976
+ end
977
+ build_tag soap, :string, 'SourceKey', @options[:login]
978
+ end
979
+ end
980
+
981
+ # Customer ======================================================
982
+
983
+ def build_add_customer(soap, options)
984
+ soap.tag! "ns1:addCustomer" do |soap|
985
+ build_token soap, options
986
+ build_customer_data soap, options
987
+ build_tag soap, :double, 'Amount', amount(options[:amount])
988
+ build_tag soap, :double, 'Tax', amount(options[:tax])
989
+ build_tag soap, :string, 'Next', options[:next].strftime("%Y-%m-%d") if options[:next]
990
+ end
991
+ end
992
+
993
+ def build_customer(soap, options, type, add_customer_data=false)
994
+ soap.tag! "ns1:#{type}" do |soap|
995
+ build_token soap, options
996
+ build_tag soap, :integer, 'CustNum', options[:customer_number]
997
+ build_customer_data soap, options if add_customer_data
998
+ end
999
+ end
1000
+
1001
+ def build_update_customer(soap, options)
1002
+ build_customer(soap, options, 'updateCustomer', true)
1003
+ end
1004
+
1005
+ def build_enable_customer(soap, options)
1006
+ build_customer(soap, options, 'enableCustomer')
1007
+ end
1008
+
1009
+ def build_disable_customer(soap, options)
1010
+ build_customer(soap, options, 'disableCustomer')
1011
+ end
1012
+
1013
+ def build_delete_customer(soap, options)
1014
+ build_customer(soap, options, 'deleteCustomer')
1015
+ end
1016
+
1017
+ def build_add_customer_payment_method(soap, options)
1018
+ soap.tag! "ns1:addCustomerPaymentMethod" do |soap|
1019
+ build_token soap, options
1020
+ build_tag soap, :integer, 'CustNum', options[:customer_number]
1021
+ build_customer_payment_methods soap, options
1022
+ build_tag soap, :boolean, 'MakeDefault', options[:make_default]
1023
+ build_tag soap, :boolean, 'Verify', options[:verify]
1024
+ end
1025
+ end
1026
+
1027
+ def build_get_customer_payment_method(soap, options)
1028
+ soap.tag! 'ns1:getCustomerPaymentMethod' do |soap|
1029
+ build_token soap, options
1030
+ build_tag soap, :integer, 'CustNum', options[:customer_number]
1031
+ build_tag soap, :integer, 'MethodID', options[:method_id]
1032
+ end
1033
+ end
1034
+
1035
+ def build_get_customer_payment_methods(soap, options)
1036
+ build_customer(soap, options, 'getCustomerPaymentMethods')
1037
+ end
1038
+
1039
+ def build_update_customer_payment_method(soap, options)
1040
+ soap.tag! 'ns1:updateCustomerPaymentMethod' do |soap|
1041
+ build_token soap, options
1042
+ build_customer_payment_methods soap, options
1043
+ build_tag soap, :boolean, 'Verify', options[:verify]
1044
+ end
1045
+ end
1046
+
1047
+ def build_delete_customer_payment_method(soap, options)
1048
+ soap.tag! "ns1:deleteCustomerPaymentMethod" do |soap|
1049
+ build_token soap, options
1050
+ build_tag soap, :integer, 'Custnum', options[:customer_number]
1051
+ build_tag soap, :integer, 'PaymentMethodID', options[:method_id]
1052
+ end
1053
+ end
1054
+
1055
+ def build_run_customer_transaction(soap, options)
1056
+ soap.tag! "ns1:runCustomerTransaction" do |soap|
1057
+ build_token soap, options
1058
+ build_tag soap, :integer, 'CustNum', options[:customer_number]
1059
+ build_tag soap, :integer, 'PaymentMethodID', options[:method_id] || 0
1060
+ build_customer_transaction soap, options
1061
+ end
1062
+ end
1063
+
1064
+ # Transactions ==================================================
1065
+
1066
+ def build_run_transaction(soap, options)
1067
+ soap.tag! 'ns1:runTransaction' do |soap|
1068
+ build_token soap, options
1069
+ build_transaction_request_object soap, options, 'Parameters'
1070
+ end
1071
+ end
1072
+
1073
+ def build_run_sale(soap, options)
1074
+ soap.tag! 'ns1:runSale' do |soap|
1075
+ build_token soap, options
1076
+ build_transaction_request_object soap, options
1077
+ end
1078
+ end
1079
+
1080
+ def build_run_auth_only(soap, options)
1081
+ soap.tag! 'ns1:runAuthOnly' do |soap|
1082
+ build_token soap, options
1083
+ build_transaction_request_object soap, options
1084
+ end
1085
+ end
1086
+
1087
+ def build_run_credit(soap, options)
1088
+ soap.tag! 'ns1:runCredit' do |soap|
1089
+ build_token soap, options
1090
+ build_transaction_request_object soap, options
1091
+ end
1092
+ end
1093
+
1094
+ def build_run_check_sale(soap, options)
1095
+ soap.tag! 'ns1:runCheckSale' do |soap|
1096
+ build_token soap, options
1097
+ build_transaction_request_object soap, options
1098
+ end
1099
+ end
1100
+
1101
+ def build_run_check_credit(soap, options)
1102
+ soap.tag! 'ns1:runCheckCredit' do |soap|
1103
+ build_token soap, options
1104
+ build_transaction_request_object soap, options
1105
+ end
1106
+ end
1107
+
1108
+ def build_post_auth(soap, options)
1109
+ soap.tag! 'ns1:postAuth' do |soap|
1110
+ build_token soap, options
1111
+ build_transaction_request_object soap, options
1112
+ end
1113
+ end
1114
+
1115
+ def build_run_quick_sale(soap, options)
1116
+ soap.tag! 'ns1:runQuickSale' do |soap|
1117
+ build_token soap, options
1118
+ build_tag soap, :integer, 'RefNum', options[:reference_number]
1119
+ build_transaction_detail soap, options
1120
+ build_tag soap, :boolean, 'AuthOnly', options[:authorize_only] || false
1121
+ end
1122
+ end
1123
+
1124
+ def build_run_quick_credit(soap, options)
1125
+ soap.tag! 'ns1:runQuickCredit' do |soap|
1126
+ build_token soap, options
1127
+ build_tag soap, :integer, 'RefNum', options[:reference_number]
1128
+ build_transaction_detail soap, options
1129
+ end
1130
+ end
1131
+
1132
+ def build_get_transaction(soap, options)
1133
+ soap.tag! "ns1:getTransaction" do |soap|
1134
+ build_token soap, options
1135
+ build_tag soap, :integer, 'RefNum', options[:reference_number]
1136
+ end
1137
+ end
1138
+
1139
+ def build_get_transaction_status(soap, options)
1140
+ soap.tag! "ns1:getTransactionStatus" do |soap|
1141
+ build_token soap, options
1142
+ build_tag soap, :integer, 'RefNum', options[:reference_number]
1143
+ end
1144
+ end
1145
+
1146
+ def build_get_transaction_custom(soap, options)
1147
+ soap.tag! "ns1:getTransactionCustom" do |soap|
1148
+ build_token soap, options
1149
+ build_tag soap, :integer, 'RefNum', options[:reference_number]
1150
+ build_transaction_field_array soap, options
1151
+ end
1152
+ end
1153
+
1154
+ def build_get_check_trace(soap, options)
1155
+ soap.tag! "ns1:getCheckTrace" do |soap|
1156
+ build_token soap, options
1157
+ build_tag soap, :integer, 'RefNum', options[:reference_number]
1158
+ end
1159
+ end
1160
+
1161
+ def build_capture_transaction(soap, options)
1162
+ soap.tag! "ns1:captureTransaction" do |soap|
1163
+ build_token soap, options
1164
+ build_tag soap, :integer, 'RefNum', options[:reference_number]
1165
+ build_tag soap, :double, 'RefNum', amount(options[:amount])
1166
+ end
1167
+ end
1168
+
1169
+ def build_void_transaction(soap, options)
1170
+ soap.tag! "ns1:voidTransaction" do |soap|
1171
+ build_token soap, options
1172
+ build_tag soap, :integer, 'RefNum', options[:reference_number]
1173
+ end
1174
+ end
1175
+
1176
+ def build_refund_transaction(soap, options)
1177
+ soap.tag! "ns1:refundTransaction" do |soap|
1178
+ build_token soap, options
1179
+ build_tag soap, :integer, 'RefNum', options[:reference_number]
1180
+ build_tag soap, :integer, 'Amount', amount(options[:amount])
1181
+ end
1182
+ end
1183
+
1184
+ def build_override_transaction(soap, options)
1185
+ soap.tag! "ns1:overrideTransaction" do |soap|
1186
+ build_token soap, options
1187
+ build_tag soap, :integer, 'RefNum', options[:reference_number]
1188
+ build_tag soap, :string, 'Reason', options[:reason]
1189
+ end
1190
+ end
1191
+
1192
+ # Account =======================================================
1193
+
1194
+ def build_get_account_details(soap, options)
1195
+ soap.tag! "ns1:getAccountDetails" do |soap|
1196
+ build_token soap, options
1197
+ end
1198
+ end
1199
+
1200
+ # Customer Helpers ==============================================
1201
+
1202
+ def build_customer_data(soap, options)
1203
+ soap.CustomerData 'xsi:type' => 'ns1:CustomerObject' do
1204
+ CUSTOMER_OPTIONS.each do |k,v|
1205
+ build_tag soap, v[0], v[1], options[k]
1206
+ end
1207
+ build_billing_address soap, options
1208
+ build_customer_payments soap, options
1209
+ build_custom_fields soap, options
1210
+ end
1211
+ end
1212
+
1213
+ def build_customer_payments(soap, options)
1214
+ if options[:payment_methods]
1215
+ length = options[:payment_methods].length
1216
+ soap.PaymentMethods 'SOAP-ENC:arrayType' => "ns1:PaymentMethod[#{length}]",
1217
+ 'xsi:type' =>"ns1:PaymentMethodArray" do |soap|
1218
+ build_customer_payment_methods soap, options
1219
+ end
1220
+ end
1221
+ end
1222
+
1223
+ def extract_methods_and_tag(options)
1224
+ case
1225
+ when options[:payment_method] && !options[:payment_methods]
1226
+ payment_methods = [options[:payment_method]]
1227
+ tag_name = 'PaymentMethod'
1228
+ when options[:payment_methods] && !options[:payment_method]
1229
+ payment_methods = options[:payment_methods]
1230
+ tag_name = 'item'
1231
+ else
1232
+ payment_methods = [options]
1233
+ tag_name = 'PaymentMethod'
1234
+ end
1235
+ [payment_methods, tag_name]
1236
+ end
1237
+
1238
+ def build_credit_card_or_check(soap, payment_method)
1239
+ case
1240
+ when payment_method[:method].kind_of?(ActiveMerchant::Billing::CreditCard)
1241
+ build_tag soap, :string, 'CardNumber', payment_method[:method].number
1242
+ build_tag soap, :string, 'CardExpiration',
1243
+ "#{"%02d" % payment_method[:method].month}#{payment_method[:method].year}"
1244
+ if options[:billing_address]
1245
+ build_tag soap, :string, 'AvsStreet', options[:billing_address][:address1]
1246
+ build_tag soap, :string, 'AvsZip', options[:billing_address][:zip]
1247
+ end
1248
+ build_tag soap, :string, 'CardCode', payment_method[:method].verification_value
1249
+ when payment_method[:method].kind_of?(ActiveMerchant::Billing::Check)
1250
+ build_tag soap, :string, 'Account', payment_method[:method].number
1251
+ build_tag soap, :string, 'Routing', payment_method[:method].routing_number
1252
+ build_tag soap, :string, 'AccountType', payment_method[:method].account_type.capitalize
1253
+ build_tag soap, :string, 'DriversLicense', options[:drivers_license]
1254
+ build_tag soap, :string, 'DriversLicenseState', options[:drivers_license_state]
1255
+ build_tag soap, :string, 'RecordType', options[:record_type]
1256
+ end
1257
+ end
1258
+
1259
+ def build_customer_payment_methods(soap, options)
1260
+ payment_methods, tag_name = extract_methods_and_tag(options)
1261
+ payment_methods.each do |payment_method|
1262
+ soap.tag! tag_name, 'xsi:type' => "ns1:PaymentMethod" do |soap|
1263
+ build_tag soap, :integer, 'MethodID', payment_method[:method_id]
1264
+ build_tag soap, :string, 'MethodType', payment_method[:type]
1265
+ build_tag soap, :string, 'MethodName', payment_method[:name]
1266
+ build_tag soap, :integer, 'SecondarySort', payment_method[:sort]
1267
+ build_credit_card_or_check(soap, payment_method)
1268
+ end
1269
+ end
1270
+ end
1271
+
1272
+ def build_customer_transaction(soap, options)
1273
+ soap.Parameters 'xsi:type' => "ns1:CustomerTransactionRequest" do |soap|
1274
+ build_transaction_detail soap, options
1275
+ CUSTOMER_TRANSACTION_REQUEST_OPTIONS.each do |k,v|
1276
+ build_tag soap, v[0], v[1], options[k]
1277
+ end
1278
+ build_custom_fields soap, options
1279
+ build_line_items soap, options
1280
+ end
1281
+ end
1282
+
1283
+ # Transaction Helpers ===========================================
1284
+
1285
+ def build_transaction_request_object(soap, options, name='Params')
1286
+ soap.tag! name, 'xsi:type' => "ns1:TransactionRequestObject" do |soap|
1287
+ TRANSACTION_REQUEST_OBJECT_OPTIONS.each do |k,v|
1288
+ build_tag soap, v[0], v[1], options[k]
1289
+ end
1290
+ case
1291
+ when options[:payment_method] == nil
1292
+ when options[:payment_method].kind_of?(ActiveMerchant::Billing::CreditCard)
1293
+ build_credit_card_data soap, options
1294
+ when options[:payment_method].kind_of?(ActiveMerchant::Billing::Check)
1295
+ build_check_data soap, options
1296
+ else
1297
+ raise ArgumentError, 'options[:payment_method] must be a CreditCard or Check'
1298
+ end
1299
+ build_transaction_detail soap, options
1300
+ build_billing_address soap, options
1301
+ build_shipping_address soap, options
1302
+ build_recurring_billing soap, options
1303
+ build_line_items soap, options
1304
+ build_custom_fields soap, options
1305
+ end
1306
+ end
1307
+
1308
+ def build_transaction_detail(soap, options)
1309
+ soap.Details 'xsi:type' => "ns1:TransactionDetail" do |soap|
1310
+ TRANSACTION_DETAIL_OPTIONS.each do |k,v|
1311
+ build_tag soap, v[0], v[1], options[k]
1312
+ end
1313
+ TRANSACTION_DETAIL_MONEY_OPTIONS.each do |k,v|
1314
+ build_tag soap, v[0], v[1], amount(options[k])
1315
+ end
1316
+ end
1317
+ end
1318
+
1319
+ def build_credit_card_data(soap, options)
1320
+ soap.CreditCardData 'xsi:type' => "ns1:CreditCardData" do |soap|
1321
+ build_tag soap, :string, 'CardNumber', options[:payment_method].number
1322
+ build_tag soap, :string, 'CardExpiration',
1323
+ "#{"%02d" % options[:payment_method].month}#{options[:payment_method].year}"
1324
+ if options[:billing_address]
1325
+ build_tag soap, :string, 'AvsStreet', options[:billing_address][:address1]
1326
+ build_tag soap, :string, 'AvsZip', options[:billing_address][:zip]
1327
+ end
1328
+ build_tag soap, :string, 'CardCode', options[:payment_method].verification_value
1329
+ build_tag soap, :boolean, 'CardPresent', options[:card_present] || false
1330
+ CREDIT_CARD_DATA_OPTIONS.each do |k,v|
1331
+ build_tag soap, v[0], v[1], options[k]
1332
+ end
1333
+ end
1334
+ end
1335
+
1336
+ def build_check_data(soap, options)
1337
+ soap.CheckData 'xsi:type' => "ns1:CheckData" do |soap|
1338
+ build_tag soap, :string, 'Account', options[:payment_method].number
1339
+ build_tag soap, :string, 'Routing', options[:payment_method].routing_number
1340
+ build_tag soap, :string, 'AccountType', options[:payment_method].account_type.capitalize
1341
+ CHECK_DATA_OPTIONS.each do |k,v|
1342
+ build_tag soap, v[0], v[1], options[k]
1343
+ end
1344
+ end
1345
+ end
1346
+
1347
+ def build_recurring_billing(soap, options)
1348
+ if options[:recurring]
1349
+ soap.RecurringBilling 'xsi:type' => "ns1:RecurringBilling" do |soap|
1350
+ build_tag soap, :double, 'Amount', amount(options[:recurring][:amount])
1351
+ build_tag soap, :string, 'Next', options[:recurring][:next].strftime("%Y-%m-%d") if options[:recurring][:next]
1352
+ build_tag soap, :string, 'Expire', options[:recurring][:expire].strftime("%Y-%m-%d") if options[:recurring][:expire]
1353
+ RECURRING_BILLING_OPTIONS.each do |k,v|
1354
+ build_tag soap, v[0], v[1], options[:recurring][k]
1355
+ end
1356
+ end
1357
+ end
1358
+ end
1359
+
1360
+ def build_transaction_field_array(soap, options)
1361
+ soap.Fields 'SOAP-ENC:arryType' => "xsd:string[#{options[:fields].length}]", 'xsi:type' => 'ns1:stringArray' do |soap|
1362
+ options[:fields].each do |field|
1363
+ build_tag soap, :string, 'item', field
1364
+ end
1365
+ end
1366
+ end
1367
+
1368
+ # General Helpers ===============================================
1369
+
1370
+ def build_billing_address(soap, options)
1371
+ if options[:billing_address]
1372
+ if options[:billing_address][:name]
1373
+ name = options[:billing_address][:name].split(nil,2) # divide name
1374
+ options[:billing_address][:first_name], options[:billing_address][:last_name] = name[0], name[1]
1375
+ end
1376
+ soap.BillingAddress 'xsi:type' => "ns1:Address" do
1377
+ ADDRESS_OPTIONS.each do |k,v|
1378
+ build_tag soap, v[0], v[1], options[:billing_address][k]
1379
+ end
1380
+ end
1381
+ end
1382
+ end
1383
+
1384
+ def build_shipping_address(soap, options)
1385
+ if options[:shipping_address]
1386
+ if options[:shipping_address][:name]
1387
+ name = options[:shipping_address][:name].split(nil,2) # divide name
1388
+ options[:shipping_address][:first_name], options[:shipping_address][:last_name] = name[0], name[1]
1389
+ end
1390
+ soap.ShippingAddress 'xsi:type' => "ns1:Address" do
1391
+ ADDRESS_OPTIONS.each do |k,v|
1392
+ build_tag soap, v[0], v[1], options[:shipping_address][k]
1393
+ end
1394
+ end
1395
+ end
1396
+ end
1397
+
1398
+ def build_line_items(soap, options) # TODO
1399
+ end
1400
+
1401
+ def build_custom_fields(soap, options) # TODO
1402
+ end
1403
+
1404
+ # Request =======================================================
1405
+
1406
+ def commit(action, request)
1407
+ url = test? ? test_url : live_url
1408
+
1409
+ begin
1410
+ soap = ssl_post(url, request, "Content-Type" => "text/xml")
1411
+ rescue ActiveMerchant::ResponseError => error
1412
+ soap = error.response.body
1413
+ end
1414
+
1415
+ response = build_response(action, soap)
1416
+ end
1417
+
1418
+ def build_response(action, soap)
1419
+ response_params, success, message, authorization, avs, cvv = parse(action, soap)
1420
+
1421
+ response_params.merge!('soap_response' => soap) if @options[:soap_response]
1422
+
1423
+ response = Response.new(
1424
+ success, message, response_params,
1425
+ :test => test?, :authorization => authorization,
1426
+ :avs_result => avs_from(avs),
1427
+ :cvv_result => cvv
1428
+ )
1429
+ end
1430
+
1431
+ def avs_from(avs)
1432
+ avs_params = { :code => avs }
1433
+ avs_params.merge!(:message => AVS_CUSTOM_MESSAGES[avs]) if AVS_CUSTOM_MESSAGES.key?(avs)
1434
+ avs_params
1435
+ end
1436
+
1437
+ def parse(action, soap)
1438
+ xml = REXML::Document.new(soap)
1439
+ root = REXML::XPath.first(xml, "//SOAP-ENV:Body")
1440
+ response = root ? parse_element(root[0]) : { :response => soap }
1441
+
1442
+ success, message, authorization, avs, cvv = false, FAILURE_MESSAGE, nil, nil, nil
1443
+
1444
+ fault = (!response) || (response.length < 1) || response.has_key?('faultcode')
1445
+ return [response, success, response['faultstring'], authorization, avs, cvv] if fault
1446
+
1447
+ if response.respond_to?(:[]) && p = response["#{action}_return"]
1448
+ if p.respond_to?(:key?) && p.key?('result_code')
1449
+ success = p['result_code'] == 'A' ? true : false
1450
+ authorization = p['ref_num']
1451
+ avs = AVS_RESULTS[p['avs_result_code']]
1452
+ cvv = p['card_code_result_code']
1453
+ else
1454
+ success = true
1455
+ end
1456
+ message = case action
1457
+ when :get_customer_payment_methods
1458
+ p['item']
1459
+ when :get_transaction_custom
1460
+ p['item'].inject({}) { |map, field| map[field['field']] = field['value']; map }
1461
+ else
1462
+ p
1463
+ end
1464
+ elsif response.respond_to?(:[]) && p = response[:response]
1465
+ message = p # when response is html
1466
+ end
1467
+
1468
+ [response, success, message, authorization, avs, cvv]
1469
+ end
1470
+
1471
+ def parse_element(node)
1472
+ if node.has_elements?
1473
+ response = {}
1474
+ node.elements.each do |e|
1475
+ key = e.name.underscore
1476
+ value = parse_element(e)
1477
+ if response.has_key?(key)
1478
+ if response[key].is_a?(Array)
1479
+ response[key].push(value)
1480
+ else
1481
+ response[key] = [response[key], value]
1482
+ end
1483
+ else
1484
+ response[key] = parse_element(e)
1485
+ end
1486
+ end
1487
+ else
1488
+ response = node.text
1489
+ end
1490
+
1491
+ response
1492
+ end
1493
+
1494
+ end
1495
+ end
1496
+ end
1497
+