tanga_activemerchant 1.37.0

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