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,725 @@
1
+ module ActiveMerchant #:nodoc:
2
+ module Billing #:nodoc:
3
+ # For more information on the Authorize.Net Gateway please visit their {Integration Center}[http://developer.authorize.net/]
4
+ #
5
+ # The login and password are not the username and password you use to
6
+ # login to the Authorize.Net Merchant Interface. Instead, you will
7
+ # use the API Login ID as the login and Transaction Key as the
8
+ # password.
9
+ #
10
+ # ==== How to Get Your API Login ID and Transaction Key
11
+ #
12
+ # 1. Log into the Merchant Interface
13
+ # 2. Select Settings from the Main Menu
14
+ # 3. Click on API Login ID and Transaction Key in the Security section
15
+ # 4. Type in the answer to the secret question configured on setup
16
+ # 5. Click Submit
17
+ #
18
+ # ==== Automated Recurring Billing (ARB)
19
+ #
20
+ # Automated Recurring Billing (ARB) is an optional service for submitting and managing recurring, or subscription-based, transactions.
21
+ #
22
+ # To use recurring, update_recurring, cancel_recurring and status_recurring ARB must be enabled for your account.
23
+ #
24
+ # Information about ARB is available on the {Authorize.Net website}[http://www.authorize.net/solutions/merchantsolutions/merchantservices/automatedrecurringbilling/].
25
+ # Information about the ARB API is available at the {Authorize.Net Integration Center}[http://developer.authorize.net/]
26
+ class AuthorizeNetGateway < Gateway
27
+ API_VERSION = '3.1'
28
+
29
+ class_attribute :arb_test_url, :arb_live_url
30
+
31
+ self.test_url = "https://test.authorize.net/gateway/transact.dll"
32
+ self.live_url = "https://secure.authorize.net/gateway/transact.dll"
33
+
34
+ self.arb_test_url = 'https://apitest.authorize.net/xml/v1/request.api'
35
+ self.arb_live_url = 'https://api.authorize.net/xml/v1/request.api'
36
+
37
+ class_attribute :duplicate_window
38
+
39
+ APPROVED, DECLINED, ERROR, FRAUD_REVIEW = 1, 2, 3, 4
40
+
41
+ RESPONSE_CODE, RESPONSE_REASON_CODE, RESPONSE_REASON_TEXT, AUTHORIZATION_CODE = 0, 2, 3, 4
42
+ AVS_RESULT_CODE, TRANSACTION_ID, CARD_CODE_RESPONSE_CODE = 5, 6, 38
43
+
44
+ self.default_currency = 'USD'
45
+
46
+ self.supported_countries = ['US', 'CA', 'GB']
47
+ self.supported_cardtypes = [:visa, :master, :american_express, :discover, :diners_club, :jcb]
48
+ self.homepage_url = 'http://www.authorize.net/'
49
+ self.display_name = 'Authorize.Net'
50
+
51
+ CARD_CODE_ERRORS = %w( N S )
52
+ AVS_ERRORS = %w( A E N R W Z )
53
+ AVS_REASON_CODES = %w(27 45)
54
+
55
+ AUTHORIZE_NET_ARB_NAMESPACE = 'AnetApi/xml/v1/schema/AnetApiSchema.xsd'
56
+
57
+ RECURRING_ACTIONS = {
58
+ :create => 'ARBCreateSubscription',
59
+ :update => 'ARBUpdateSubscription',
60
+ :cancel => 'ARBCancelSubscription',
61
+ :status => 'ARBGetSubscriptionStatus'
62
+ }
63
+
64
+ # Creates a new AuthorizeNetGateway
65
+ #
66
+ # The gateway requires that a valid login and password be passed
67
+ # in the +options+ hash.
68
+ #
69
+ # ==== Options
70
+ #
71
+ # * <tt>:login</tt> -- The Authorize.Net API Login ID (REQUIRED)
72
+ # * <tt>:password</tt> -- The Authorize.Net Transaction Key. (REQUIRED)
73
+ # * <tt>:test</tt> -- +true+ or +false+. If true, perform transactions against the test server.
74
+ # Otherwise, perform transactions against the production server.
75
+ def initialize(options = {})
76
+ requires!(options, :login, :password)
77
+ super
78
+ end
79
+
80
+ # Performs an authorization, which reserves the funds on the customer's credit card, but does not
81
+ # charge the card.
82
+ #
83
+ # ==== Parameters
84
+ #
85
+ # * <tt>money</tt> -- The amount to be authorized as an Integer value in cents.
86
+ # * <tt>paysource</tt> -- The CreditCard or Check details for the transaction.
87
+ # * <tt>options</tt> -- A hash of optional parameters.
88
+ def authorize(money, paysource, options = {})
89
+ post = {}
90
+ add_currency_code(post, money, options)
91
+ add_invoice(post, options)
92
+ add_payment_source(post, paysource, options)
93
+ add_address(post, options)
94
+ add_customer_data(post, options)
95
+ add_duplicate_window(post)
96
+
97
+ commit('AUTH_ONLY', money, post)
98
+ end
99
+
100
+ # Perform a purchase, which is essentially an authorization and capture in a single operation.
101
+ #
102
+ # ==== Parameters
103
+ #
104
+ # * <tt>money</tt> -- The amount to be purchased as an Integer value in cents.
105
+ # * <tt>paysource</tt> -- The CreditCard or Check details for the transaction.
106
+ # * <tt>options</tt> -- A hash of optional parameters.
107
+ def purchase(money, paysource, options = {})
108
+ post = {}
109
+ add_currency_code(post, money, options)
110
+ add_invoice(post, options)
111
+ add_payment_source(post, paysource, options)
112
+ add_address(post, options)
113
+ add_customer_data(post, options)
114
+ add_duplicate_window(post)
115
+
116
+ commit('AUTH_CAPTURE', money, post)
117
+ end
118
+
119
+ # Captures the funds from an authorized transaction.
120
+ #
121
+ # ==== Parameters
122
+ #
123
+ # * <tt>money</tt> -- The amount to be captured as an Integer value in cents.
124
+ # * <tt>authorization</tt> -- The authorization returned from the previous authorize request.
125
+ def capture(money, authorization, options = {})
126
+ post = {:trans_id => authorization}
127
+ add_customer_data(post, options)
128
+ add_invoice(post, options)
129
+ commit('PRIOR_AUTH_CAPTURE', money, post)
130
+ end
131
+
132
+ # Void a previous transaction
133
+ #
134
+ # ==== Parameters
135
+ #
136
+ # * <tt>authorization</tt> - The authorization returned from the previous authorize request.
137
+ def void(authorization, options = {})
138
+ post = {:trans_id => authorization}
139
+ add_duplicate_window(post)
140
+ commit('VOID', nil, post)
141
+ end
142
+
143
+ # Refund a transaction.
144
+ #
145
+ # This transaction indicates to the gateway that
146
+ # money should flow from the merchant to the customer.
147
+ #
148
+ # ==== Parameters
149
+ #
150
+ # * <tt>money</tt> -- The amount to be credited to the customer as an Integer value in cents.
151
+ # * <tt>identification</tt> -- The ID of the original transaction against which the refund is being issued.
152
+ # * <tt>options</tt> -- A hash of parameters.
153
+ #
154
+ # ==== Options
155
+ #
156
+ # * <tt>:card_number</tt> -- The credit card number the refund is being issued to. (REQUIRED)
157
+ # You can either pass the last four digits of the card number or the full card number.
158
+ # * <tt>:first_name</tt> -- The first name of the account being refunded.
159
+ # * <tt>:last_name</tt> -- The last name of the account being refunded.
160
+ # * <tt>:zip</tt> -- The postal code of the account being refunded.
161
+ def refund(money, identification, options = {})
162
+ requires!(options, :card_number)
163
+
164
+ post = { :trans_id => identification,
165
+ :card_num => options[:card_number]
166
+ }
167
+
168
+ post[:first_name] = options[:first_name] if options[:first_name]
169
+ post[:last_name] = options[:last_name] if options[:last_name]
170
+ post[:zip] = options[:zip] if options[:zip]
171
+
172
+ add_invoice(post, options)
173
+ add_duplicate_window(post)
174
+
175
+ commit('CREDIT', money, post)
176
+ end
177
+
178
+ def credit(money, identification, options = {})
179
+ deprecated CREDIT_DEPRECATION_MESSAGE
180
+ refund(money, identification, options)
181
+ end
182
+
183
+ # Create a recurring payment.
184
+ #
185
+ # This transaction creates a new Automated Recurring Billing (ARB) subscription. Your account must have ARB enabled.
186
+ #
187
+ # ==== Parameters
188
+ #
189
+ # * <tt>money</tt> -- The amount to be charged to the customer at each interval as an Integer value in cents.
190
+ # * <tt>creditcard</tt> -- The CreditCard details for the transaction.
191
+ # * <tt>options</tt> -- A hash of parameters.
192
+ #
193
+ # ==== Options
194
+ #
195
+ # * <tt>:interval</tt> -- A hash containing information about the interval of time between payments. Must
196
+ # contain the keys <tt>:length</tt> and <tt>:unit</tt>. <tt>:unit</tt> can be either <tt>:months</tt> or <tt>:days</tt>.
197
+ # If <tt>:unit</tt> is <tt>:months</tt> then <tt>:length</tt> must be an integer between 1 and 12 inclusive.
198
+ # If <tt>:unit</tt> is <tt>:days</tt> then <tt>:length</tt> must be an integer between 7 and 365 inclusive.
199
+ # For example, to charge the customer once every three months the hash would be
200
+ # +:interval => { :unit => :months, :length => 3 }+ (REQUIRED)
201
+ # * <tt>:duration</tt> -- A hash containing keys for the <tt>:start_date</tt> the subscription begins (also the date the
202
+ # initial billing occurs) and the total number of billing <tt>:occurences</tt> or payments for the subscription. (REQUIRED)
203
+ def recurring(money, creditcard, options={})
204
+ requires!(options, :interval, :duration, :billing_address)
205
+ requires!(options[:interval], :length, [:unit, :days, :months])
206
+ requires!(options[:duration], :start_date, :occurrences)
207
+ requires!(options[:billing_address], :first_name, :last_name)
208
+
209
+ options[:credit_card] = creditcard
210
+ options[:amount] = money
211
+
212
+ request = build_recurring_request(:create, options)
213
+ recurring_commit(:create, request)
214
+ end
215
+
216
+ # Update a recurring payment's details.
217
+ #
218
+ # This transaction updates an existing Automated Recurring Billing (ARB) subscription. Your account must have ARB enabled
219
+ # and the subscription must have already been created previously by calling +recurring()+. The ability to change certain
220
+ # details about a recurring payment is dependent on transaction history and cannot be determined until after calling
221
+ # +update_recurring()+. See the ARB XML Guide for such conditions.
222
+ #
223
+ # ==== Parameters
224
+ #
225
+ # * <tt>options</tt> -- A hash of parameters.
226
+ #
227
+ # ==== Options
228
+ #
229
+ # * <tt>:subscription_id</tt> -- A string containing the <tt>:subscription_id</tt> of the recurring payment already in place
230
+ # for a given credit card. (REQUIRED)
231
+ def update_recurring(options={})
232
+ requires!(options, :subscription_id)
233
+ request = build_recurring_request(:update, options)
234
+ recurring_commit(:update, request)
235
+ end
236
+
237
+ # Cancel a recurring payment.
238
+ #
239
+ # This transaction cancels an existing Automated Recurring Billing (ARB) subscription. Your account must have ARB enabled
240
+ # and the subscription must have already been created previously by calling recurring()
241
+ #
242
+ # ==== Parameters
243
+ #
244
+ # * <tt>subscription_id</tt> -- A string containing the +subscription_id+ of the recurring payment already in place
245
+ # for a given credit card. (REQUIRED)
246
+ def cancel_recurring(subscription_id)
247
+ request = build_recurring_request(:cancel, :subscription_id => subscription_id)
248
+ recurring_commit(:cancel, request)
249
+ end
250
+
251
+ # Get Subscription Status of a recurring payment.
252
+ #
253
+ # This transaction gets the status of an existing Automated Recurring Billing (ARB) subscription. Your account must have ARB enabled.
254
+ #
255
+ # ==== Parameters
256
+ #
257
+ # * <tt>subscription_id</tt> -- A string containing the +subscription_id+ of the recurring payment already in place
258
+ # for a given credit card. (REQUIRED)
259
+ def status_recurring(subscription_id)
260
+ request = build_recurring_request(:status, :subscription_id => subscription_id)
261
+ recurring_commit(:status, request)
262
+ end
263
+
264
+ private
265
+
266
+ def commit(action, money, parameters)
267
+ parameters[:amount] = amount(money) unless action == 'VOID'
268
+
269
+ # Only activate the test_request when the :test option is passed in
270
+ parameters[:test_request] = @options[:test] ? 'TRUE' : 'FALSE'
271
+
272
+ url = test? ? self.test_url : self.live_url
273
+ data = ssl_post url, post_data(action, parameters)
274
+
275
+ response = parse(data)
276
+ response[:action] = action
277
+
278
+ message = message_from(response)
279
+
280
+ # Return the response. The authorization can be taken out of the transaction_id
281
+ # Test Mode on/off is something we have to parse from the response text.
282
+ # It usually looks something like this
283
+ #
284
+ # (TESTMODE) Successful Sale
285
+ test_mode = test? || message =~ /TESTMODE/
286
+
287
+ Response.new(success?(response), message, response,
288
+ :test => test_mode,
289
+ :authorization => response[:transaction_id],
290
+ :fraud_review => fraud_review?(response),
291
+ :avs_result => { :code => response[:avs_result_code] },
292
+ :cvv_result => response[:card_code]
293
+ )
294
+ end
295
+
296
+ def success?(response)
297
+ response[:response_code] == APPROVED
298
+ end
299
+
300
+ def fraud_review?(response)
301
+ response[:response_code] == FRAUD_REVIEW
302
+ end
303
+
304
+ def parse(body)
305
+ fields = split(body)
306
+
307
+ results = {
308
+ :response_code => fields[RESPONSE_CODE].to_i,
309
+ :response_reason_code => fields[RESPONSE_REASON_CODE],
310
+ :response_reason_text => fields[RESPONSE_REASON_TEXT],
311
+ :avs_result_code => fields[AVS_RESULT_CODE],
312
+ :transaction_id => fields[TRANSACTION_ID],
313
+ :card_code => fields[CARD_CODE_RESPONSE_CODE],
314
+ :authorization_code => fields[AUTHORIZATION_CODE]
315
+ }
316
+ results
317
+ end
318
+
319
+ def post_data(action, parameters = {})
320
+ post = {}
321
+
322
+ post[:version] = API_VERSION
323
+ post[:login] = @options[:login]
324
+ post[:tran_key] = @options[:password]
325
+ post[:relay_response] = "FALSE"
326
+ post[:type] = action
327
+ post[:delim_data] = "TRUE"
328
+ post[:delim_char] = ","
329
+ post[:encap_char] = "$"
330
+ post[:solution_ID] = application_id if application_id.present? && application_id != "ActiveMerchant"
331
+
332
+ request = post.merge(parameters).collect { |key, value| "x_#{key}=#{CGI.escape(value.to_s)}" }.join("&")
333
+ request
334
+ end
335
+
336
+ def add_currency_code(post, money, options)
337
+ post[:currency_code] = options[:currency] || currency(money)
338
+ end
339
+
340
+ def add_invoice(post, options)
341
+ post[:invoice_num] = options[:order_id]
342
+ post[:description] = options[:description]
343
+ end
344
+
345
+ def add_creditcard(post, creditcard, options={})
346
+ post[:card_num] = creditcard.number
347
+ post[:card_code] = creditcard.verification_value if creditcard.verification_value?
348
+ post[:exp_date] = expdate(creditcard)
349
+ post[:first_name] = creditcard.first_name
350
+ post[:last_name] = creditcard.last_name
351
+ end
352
+
353
+ def add_payment_source(params, source, options={})
354
+ if card_brand(source) == "check"
355
+ add_check(params, source, options)
356
+ else
357
+ add_creditcard(params, source, options)
358
+ end
359
+ end
360
+
361
+ def add_check(post, check, options)
362
+ post[:method] = "ECHECK"
363
+ post[:bank_name] = check.bank_name
364
+ post[:bank_aba_code] = check.routing_number
365
+ post[:bank_acct_num] = check.account_number
366
+ post[:bank_acct_type] = check.account_type
367
+ post[:echeck_type] = "WEB"
368
+ post[:bank_acct_name] = check.name
369
+ post[:bank_check_number] = check.number if check.number.present?
370
+ post[:recurring_billing] = (options[:recurring] ? "TRUE" : "FALSE")
371
+ end
372
+
373
+ def add_customer_data(post, options)
374
+ if options.has_key? :email
375
+ post[:email] = options[:email]
376
+ post[:email_customer] = false
377
+ end
378
+
379
+ if options.has_key? :customer
380
+ post[:cust_id] = options[:customer] if Float(options[:customer]) rescue nil
381
+ end
382
+
383
+ if options.has_key? :ip
384
+ post[:customer_ip] = options[:ip]
385
+ end
386
+ end
387
+
388
+ # x_duplicate_window won't be sent by default, because sending it changes the response.
389
+ # "If this field is present in the request with or without a value, an enhanced duplicate transaction response will be sent."
390
+ # (as of 2008-12-30) http://www.authorize.net/support/AIM_guide_SCC.pdf
391
+ def add_duplicate_window(post)
392
+ unless duplicate_window.nil?
393
+ post[:duplicate_window] = duplicate_window
394
+ end
395
+ end
396
+
397
+ def add_address(post, options)
398
+ if address = options[:billing_address] || options[:address]
399
+ post[:address] = address[:address1].to_s
400
+ post[:company] = address[:company].to_s
401
+ post[:phone] = address[:phone].to_s
402
+ post[:zip] = address[:zip].to_s
403
+ post[:city] = address[:city].to_s
404
+ post[:country] = address[:country].to_s
405
+ post[:state] = address[:state].blank? ? 'n/a' : address[:state]
406
+ end
407
+
408
+ if address = options[:shipping_address]
409
+ post[:ship_to_first_name] = address[:first_name].to_s
410
+ post[:ship_to_last_name] = address[:last_name].to_s
411
+ post[:ship_to_address] = address[:address1].to_s
412
+ post[:ship_to_company] = address[:company].to_s
413
+ post[:ship_to_phone] = address[:phone].to_s
414
+ post[:ship_to_zip] = address[:zip].to_s
415
+ post[:ship_to_city] = address[:city].to_s
416
+ post[:ship_to_country] = address[:country].to_s
417
+ post[:ship_to_state] = address[:state].blank? ? 'n/a' : address[:state]
418
+ end
419
+ end
420
+
421
+ # Make a ruby type out of the response string
422
+ def normalize(field)
423
+ case field
424
+ when "true" then true
425
+ when "false" then false
426
+ when "" then nil
427
+ when "null" then nil
428
+ else field
429
+ end
430
+ end
431
+
432
+ def message_from(results)
433
+ if results[:response_code] == DECLINED
434
+ return CVVResult.messages[ results[:card_code] ] if CARD_CODE_ERRORS.include?(results[:card_code])
435
+ if AVS_REASON_CODES.include?(results[:response_reason_code]) && AVS_ERRORS.include?(results[:avs_result_code])
436
+ return AVSResult.messages[ results[:avs_result_code] ]
437
+ end
438
+ end
439
+
440
+ (results[:response_reason_text] ? results[:response_reason_text].chomp('.') : '')
441
+ end
442
+
443
+ def expdate(creditcard)
444
+ year = sprintf("%.4i", creditcard.year)
445
+ month = sprintf("%.2i", creditcard.month)
446
+
447
+ "#{month}#{year[-2..-1]}"
448
+ end
449
+
450
+ def split(response)
451
+ response[1..-2].split(/\$,\$/)
452
+ end
453
+
454
+ # ARB
455
+
456
+ # Builds recurring billing request
457
+ def build_recurring_request(action, options = {})
458
+ unless RECURRING_ACTIONS.include?(action)
459
+ raise StandardError, "Invalid Automated Recurring Billing Action: #{action}"
460
+ end
461
+
462
+ xml = Builder::XmlMarkup.new(:indent => 2)
463
+ xml.instruct!(:xml, :version => '1.0', :encoding => 'utf-8')
464
+ xml.tag!("#{RECURRING_ACTIONS[action]}Request", :xmlns => AUTHORIZE_NET_ARB_NAMESPACE) do
465
+ add_arb_merchant_authentication(xml)
466
+ # Merchant-assigned reference ID for the request
467
+ xml.tag!('refId', options[:ref_id]) if options[:ref_id]
468
+ send("build_arb_#{action}_subscription_request", xml, options)
469
+ end
470
+ end
471
+
472
+ # Contains the merchant’s payment gateway account authentication information
473
+ def add_arb_merchant_authentication(xml)
474
+ xml.tag!('merchantAuthentication') do
475
+ xml.tag!('name', @options[:login])
476
+ xml.tag!('transactionKey', @options[:password])
477
+ end
478
+ end
479
+
480
+ # Builds body for ARBCreateSubscriptionRequest
481
+ def build_arb_create_subscription_request(xml, options)
482
+ # Subscription
483
+ add_arb_subscription(xml, options)
484
+
485
+ xml.target!
486
+ end
487
+
488
+ # Builds body for ARBUpdateSubscriptionRequest
489
+ def build_arb_update_subscription_request(xml, options)
490
+ xml.tag!('subscriptionId', options[:subscription_id])
491
+ # Adds Subscription
492
+ add_arb_subscription(xml, options)
493
+
494
+ xml.target!
495
+ end
496
+
497
+ # Builds body for ARBCancelSubscriptionRequest
498
+ def build_arb_cancel_subscription_request(xml, options)
499
+ xml.tag!('subscriptionId', options[:subscription_id])
500
+
501
+ xml.target!
502
+ end
503
+
504
+ # Builds body for ARBGetSubscriptionStatusRequest
505
+ def build_arb_status_subscription_request(xml, options)
506
+ xml.tag!('subscriptionId', options[:subscription_id])
507
+
508
+ xml.target!
509
+ end
510
+
511
+ # Adds subscription information
512
+ def add_arb_subscription(xml, options)
513
+ xml.tag!('subscription') do
514
+ # Merchant-assigned name for the subscription (optional)
515
+ xml.tag!('name', options[:subscription_name]) if options[:subscription_name]
516
+ # Contains information about the payment schedule
517
+ add_arb_payment_schedule(xml, options)
518
+ # The amount to be billed to the customer
519
+ # for each payment in the subscription
520
+ xml.tag!('amount', amount(options[:amount])) if options[:amount]
521
+ if trial = options[:trial]
522
+ # The amount to be charged for each payment during a trial period (conditional)
523
+ xml.tag!('trialAmount', amount(trial[:amount])) if trial[:amount]
524
+ end
525
+ # Contains either the customer’s credit card
526
+ # or bank account payment information
527
+ add_arb_payment(xml, options)
528
+ # Contains order information (optional)
529
+ add_arb_order(xml, options)
530
+ # Contains information about the customer
531
+ add_arb_customer(xml, options)
532
+ # Contains the customer's billing address information
533
+ add_arb_address(xml, 'billTo', options[:billing_address])
534
+ # Contains the customer's shipping address information (optional)
535
+ add_arb_address(xml, 'shipTo', options[:shipping_address])
536
+ end
537
+ end
538
+
539
+ # Adds information about the interval of time between payments
540
+ def add_arb_interval(xml, options)
541
+ interval = options[:interval]
542
+ return unless interval
543
+ xml.tag!('interval') do
544
+ # The measurement of time, in association with the Interval Unit,
545
+ # that is used to define the frequency of the billing occurrences
546
+ xml.tag!('length', interval[:length])
547
+ # The unit of time, in association with the Interval Length,
548
+ # between each billing occurrence
549
+ xml.tag!('unit', interval[:unit].to_s)
550
+ end
551
+ end
552
+
553
+ # Adds information about the subscription duration
554
+ def add_arb_duration(xml, options)
555
+ duration = options[:duration]
556
+ return unless duration
557
+ # The date the subscription begins
558
+ # (also the date the initial billing occurs)
559
+ xml.tag!('startDate', duration[:start_date]) if duration[:start_date]
560
+ # Number of billing occurrences or payments for the subscription
561
+ xml.tag!('totalOccurrences', duration[:occurrences]) if duration[:occurrences]
562
+ end
563
+
564
+ def add_arb_payment_schedule(xml, options)
565
+ return unless options[:interval] || options[:duration]
566
+ xml.tag!('paymentSchedule') do
567
+ # Contains information about the interval of time between payments
568
+ add_arb_interval(xml, options)
569
+ add_arb_duration(xml, options)
570
+ if trial = options[:trial]
571
+ # Number of billing occurrences or payments in the trial period (optional)
572
+ xml.tag!('trialOccurrences', trial[:occurrences]) if trial[:occurrences]
573
+ end
574
+ end
575
+ end
576
+
577
+ # Adds customer's credit card or bank account payment information
578
+ def add_arb_payment(xml, options)
579
+ return unless options[:credit_card] || options[:bank_account]
580
+ xml.tag!('payment') do
581
+ # Contains the customer’s credit card information
582
+ add_arb_credit_card(xml, options)
583
+ # Contains the customer’s bank account information
584
+ add_arb_bank_account(xml, options)
585
+ end
586
+ end
587
+
588
+ # Adds customer’s credit card information
589
+ # Note: This element should only be included
590
+ # when the payment method is credit card.
591
+ def add_arb_credit_card(xml, options)
592
+ credit_card = options[:credit_card]
593
+ return unless credit_card
594
+ xml.tag!('creditCard') do
595
+ # The credit card number used for payment of the subscription
596
+ xml.tag!('cardNumber', credit_card.number)
597
+ # The expiration date of the credit card used for the subscription
598
+ xml.tag!('expirationDate', arb_expdate(credit_card))
599
+ end
600
+ end
601
+
602
+ # Adds customer’s bank account information
603
+ # Note: This element should only be included
604
+ # when the payment method is bank account.
605
+ def add_arb_bank_account(xml, options)
606
+ bank_account = options[:bank_account]
607
+ return unless bank_account
608
+ xml.tag!('bankAccount') do
609
+ # The type of bank account used for payment of the subscription
610
+ xml.tag!('accountType', bank_account[:account_type])
611
+ # The routing number of the customer’s bank
612
+ xml.tag!('routingNumber', bank_account[:routing_number])
613
+ # The bank account number used for payment of the subscription
614
+ xml.tag!('accountNumber', bank_account[:account_number])
615
+ # The full name of the individual associated
616
+ # with the bank account number
617
+ xml.tag!('nameOfAccount', bank_account[:name_of_account])
618
+ # The full name of the individual associated
619
+ # with the bank account number (optional)
620
+ xml.tag!('bankName', bank_account[:bank_name]) if bank_account[:bank_name]
621
+ # The type of electronic check transaction used for the subscription
622
+ xml.tag!('echeckType', bank_account[:echeck_type])
623
+ end
624
+ end
625
+
626
+ # Adds order information (optional)
627
+ def add_arb_order(xml, options)
628
+ order = options[:order]
629
+ return unless order
630
+ xml.tag!('order') do
631
+ # Merchant-assigned invoice number for the subscription (optional)
632
+ xml.tag!('invoiceNumber', order[:invoice_number])
633
+ # Description of the subscription (optional)
634
+ xml.tag!('description', order[:description])
635
+ end
636
+ end
637
+
638
+ # Adds information about the customer
639
+ def add_arb_customer(xml, options)
640
+ customer = options[:customer]
641
+ return unless customer
642
+ xml.tag!('customer') do
643
+ xml.tag!('type', customer[:type]) if customer[:type]
644
+ xml.tag!('id', customer[:id]) if customer[:id]
645
+ xml.tag!('email', customer[:email]) if customer[:email]
646
+ xml.tag!('phoneNumber', customer[:phone_number]) if customer[:phone_number]
647
+ xml.tag!('faxNumber', customer[:fax_number]) if customer[:fax_number]
648
+ add_arb_drivers_license(xml, options)
649
+ xml.tag!('taxId', customer[:tax_id]) if customer[:tax_id]
650
+ end
651
+ end
652
+
653
+ # Adds the customer's driver's license information (conditional)
654
+ def add_arb_drivers_license(xml, options)
655
+ return unless customer = options[:customer]
656
+ return unless drivers_license = customer[:drivers_license]
657
+ xml.tag!('driversLicense') do
658
+ # The customer's driver's license number
659
+ xml.tag!('number', drivers_license[:number])
660
+ # The customer's driver's license state
661
+ xml.tag!('state', drivers_license[:state])
662
+ # The customer's driver's license date of birth
663
+ xml.tag!('dateOfBirth', drivers_license[:date_of_birth])
664
+ end
665
+ end
666
+
667
+ # Adds address information
668
+ def add_arb_address(xml, container_name, address)
669
+ return if address.blank?
670
+ xml.tag!(container_name) do
671
+ xml.tag!('firstName', address[:first_name])
672
+ xml.tag!('lastName', address[:last_name])
673
+ xml.tag!('company', address[:company])
674
+ xml.tag!('address', address[:address1])
675
+ xml.tag!('city', address[:city])
676
+ xml.tag!('state', address[:state])
677
+ xml.tag!('zip', address[:zip])
678
+ xml.tag!('country', address[:country])
679
+ end
680
+ end
681
+
682
+ def arb_expdate(credit_card)
683
+ sprintf('%04d-%02d', credit_card.year, credit_card.month)
684
+ end
685
+
686
+ def recurring_commit(action, request)
687
+ url = test? ? arb_test_url : arb_live_url
688
+ xml = ssl_post(url, request, "Content-Type" => "text/xml")
689
+
690
+ response = recurring_parse(action, xml)
691
+
692
+ message = response[:message] || response[:text]
693
+ test_mode = test? || message =~ /Test Mode/
694
+ success = response[:result_code] == 'Ok'
695
+
696
+ Response.new(success, message, response,
697
+ :test => test_mode,
698
+ :authorization => response[:subscription_id]
699
+ )
700
+ end
701
+
702
+ def recurring_parse(action, xml)
703
+ response = {}
704
+ xml = REXML::Document.new(xml)
705
+ root = REXML::XPath.first(xml, "//#{RECURRING_ACTIONS[action]}Response") ||
706
+ REXML::XPath.first(xml, "//ErrorResponse")
707
+ if root
708
+ root.elements.to_a.each do |node|
709
+ recurring_parse_element(response, node)
710
+ end
711
+ end
712
+
713
+ response
714
+ end
715
+
716
+ def recurring_parse_element(response, node)
717
+ if node.has_elements?
718
+ node.elements.each{|e| recurring_parse_element(response, e) }
719
+ else
720
+ response[node.name.underscore.to_sym] = node.text
721
+ end
722
+ end
723
+ end
724
+ end
725
+ end