activemerchant-est 1.4.2.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (320) hide show
  1. data/CHANGELOG +480 -0
  2. data/CONTRIBUTORS +126 -0
  3. data/MIT-LICENSE +20 -0
  4. data/README +136 -0
  5. data/Rakefile +154 -0
  6. data/gem-public_cert.pem +20 -0
  7. data/init.rb +3 -0
  8. data/lib/active_merchant.rb +66 -0
  9. data/lib/active_merchant/billing/avs_result.rb +98 -0
  10. data/lib/active_merchant/billing/base.rb +57 -0
  11. data/lib/active_merchant/billing/check.rb +68 -0
  12. data/lib/active_merchant/billing/credit_card.rb +159 -0
  13. data/lib/active_merchant/billing/credit_card_formatting.rb +21 -0
  14. data/lib/active_merchant/billing/credit_card_methods.rb +125 -0
  15. data/lib/active_merchant/billing/cvv_result.rb +38 -0
  16. data/lib/active_merchant/billing/expiry_date.rb +34 -0
  17. data/lib/active_merchant/billing/gateway.rb +158 -0
  18. data/lib/active_merchant/billing/gateways.rb +18 -0
  19. data/lib/active_merchant/billing/gateways/authorize_net.rb +657 -0
  20. data/lib/active_merchant/billing/gateways/authorize_net_cim.rb +736 -0
  21. data/lib/active_merchant/billing/gateways/beanstream.rb +102 -0
  22. data/lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb +233 -0
  23. data/lib/active_merchant/billing/gateways/beanstream_interac.rb +54 -0
  24. data/lib/active_merchant/billing/gateways/bogus.rb +98 -0
  25. data/lib/active_merchant/billing/gateways/braintree.rb +17 -0
  26. data/lib/active_merchant/billing/gateways/card_stream.rb +230 -0
  27. data/lib/active_merchant/billing/gateways/cyber_source.rb +406 -0
  28. data/lib/active_merchant/billing/gateways/data_cash.rb +595 -0
  29. data/lib/active_merchant/billing/gateways/efsnet.rb +229 -0
  30. data/lib/active_merchant/billing/gateways/elavon.rb +134 -0
  31. data/lib/active_merchant/billing/gateways/eway.rb +277 -0
  32. data/lib/active_merchant/billing/gateways/exact.rb +222 -0
  33. data/lib/active_merchant/billing/gateways/first_pay.rb +172 -0
  34. data/lib/active_merchant/billing/gateways/instapay.rb +164 -0
  35. data/lib/active_merchant/billing/gateways/jetpay.rb +270 -0
  36. data/lib/active_merchant/billing/gateways/linkpoint.rb +449 -0
  37. data/lib/active_merchant/billing/gateways/merchant_e_solutions.rb +154 -0
  38. data/lib/active_merchant/billing/gateways/merchant_ware.rb +283 -0
  39. data/lib/active_merchant/billing/gateways/modern_payments.rb +36 -0
  40. data/lib/active_merchant/billing/gateways/modern_payments_cim.rb +220 -0
  41. data/lib/active_merchant/billing/gateways/moneris.rb +205 -0
  42. data/lib/active_merchant/billing/gateways/net_registry.rb +189 -0
  43. data/lib/active_merchant/billing/gateways/netbilling.rb +168 -0
  44. data/lib/active_merchant/billing/gateways/ogone.rb +279 -0
  45. data/lib/active_merchant/billing/gateways/pay_junction.rb +392 -0
  46. data/lib/active_merchant/billing/gateways/pay_secure.rb +120 -0
  47. data/lib/active_merchant/billing/gateways/payflow.rb +236 -0
  48. data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +207 -0
  49. data/lib/active_merchant/billing/gateways/payflow/payflow_express_response.rb +39 -0
  50. data/lib/active_merchant/billing/gateways/payflow/payflow_response.rb +13 -0
  51. data/lib/active_merchant/billing/gateways/payflow_express.rb +138 -0
  52. data/lib/active_merchant/billing/gateways/payflow_express_uk.rb +15 -0
  53. data/lib/active_merchant/billing/gateways/payflow_uk.rb +21 -0
  54. data/lib/active_merchant/billing/gateways/payment_express.rb +230 -0
  55. data/lib/active_merchant/billing/gateways/paypal.rb +121 -0
  56. data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +326 -0
  57. data/lib/active_merchant/billing/gateways/paypal/paypal_express_response.rb +38 -0
  58. data/lib/active_merchant/billing/gateways/paypal_ca.rb +13 -0
  59. data/lib/active_merchant/billing/gateways/paypal_express.rb +130 -0
  60. data/lib/active_merchant/billing/gateways/paypal_express_common.rb +20 -0
  61. data/lib/active_merchant/billing/gateways/plugnpay.rb +292 -0
  62. data/lib/active_merchant/billing/gateways/psigate.rb +214 -0
  63. data/lib/active_merchant/billing/gateways/psl_card.rb +306 -0
  64. data/lib/active_merchant/billing/gateways/quickpay.rb +213 -0
  65. data/lib/active_merchant/billing/gateways/realex.rb +200 -0
  66. data/lib/active_merchant/billing/gateways/sage.rb +146 -0
  67. data/lib/active_merchant/billing/gateways/sage/sage_bankcard.rb +88 -0
  68. data/lib/active_merchant/billing/gateways/sage/sage_core.rb +116 -0
  69. data/lib/active_merchant/billing/gateways/sage/sage_virtual_check.rb +97 -0
  70. data/lib/active_merchant/billing/gateways/sage_pay.rb +308 -0
  71. data/lib/active_merchant/billing/gateways/sallie_mae.rb +144 -0
  72. data/lib/active_merchant/billing/gateways/secure_pay.rb +31 -0
  73. data/lib/active_merchant/billing/gateways/secure_pay_au.rb +157 -0
  74. data/lib/active_merchant/billing/gateways/secure_pay_tech.rb +113 -0
  75. data/lib/active_merchant/billing/gateways/skip_jack.rb +452 -0
  76. data/lib/active_merchant/billing/gateways/smart_ps.rb +265 -0
  77. data/lib/active_merchant/billing/gateways/trans_first.rb +127 -0
  78. data/lib/active_merchant/billing/gateways/transax.rb +26 -0
  79. data/lib/active_merchant/billing/gateways/trust_commerce.rb +418 -0
  80. data/lib/active_merchant/billing/gateways/usa_epay.rb +194 -0
  81. data/lib/active_merchant/billing/gateways/verifi.rb +228 -0
  82. data/lib/active_merchant/billing/gateways/viaklix.rb +189 -0
  83. data/lib/active_merchant/billing/gateways/wirecard.rb +318 -0
  84. data/lib/active_merchant/billing/integrations.rb +28 -0
  85. data/lib/active_merchant/billing/integrations/action_view_helper.rb +79 -0
  86. data/lib/active_merchant/billing/integrations/adyen.rb +29 -0
  87. data/lib/active_merchant/billing/integrations/adyen/helper.rb +103 -0
  88. data/lib/active_merchant/billing/integrations/adyen/notification.rb +91 -0
  89. data/lib/active_merchant/billing/integrations/adyen/return.rb +52 -0
  90. data/lib/active_merchant/billing/integrations/bogus.rb +23 -0
  91. data/lib/active_merchant/billing/integrations/bogus/helper.rb +17 -0
  92. data/lib/active_merchant/billing/integrations/bogus/notification.rb +11 -0
  93. data/lib/active_merchant/billing/integrations/bogus/return.rb +10 -0
  94. data/lib/active_merchant/billing/integrations/chronopay.rb +23 -0
  95. data/lib/active_merchant/billing/integrations/chronopay/helper.rb +81 -0
  96. data/lib/active_merchant/billing/integrations/chronopay/notification.rb +156 -0
  97. data/lib/active_merchant/billing/integrations/chronopay/return.rb +10 -0
  98. data/lib/active_merchant/billing/integrations/gestpay.rb +25 -0
  99. data/lib/active_merchant/billing/integrations/gestpay/common.rb +42 -0
  100. data/lib/active_merchant/billing/integrations/gestpay/helper.rb +70 -0
  101. data/lib/active_merchant/billing/integrations/gestpay/notification.rb +83 -0
  102. data/lib/active_merchant/billing/integrations/gestpay/return.rb +10 -0
  103. data/lib/active_merchant/billing/integrations/helper.rb +93 -0
  104. data/lib/active_merchant/billing/integrations/hi_trust.rb +27 -0
  105. data/lib/active_merchant/billing/integrations/hi_trust/helper.rb +58 -0
  106. data/lib/active_merchant/billing/integrations/hi_trust/notification.rb +59 -0
  107. data/lib/active_merchant/billing/integrations/hi_trust/return.rb +67 -0
  108. data/lib/active_merchant/billing/integrations/nochex.rb +88 -0
  109. data/lib/active_merchant/billing/integrations/nochex/helper.rb +68 -0
  110. data/lib/active_merchant/billing/integrations/nochex/notification.rb +94 -0
  111. data/lib/active_merchant/billing/integrations/nochex/return.rb +10 -0
  112. data/lib/active_merchant/billing/integrations/notification.rb +68 -0
  113. data/lib/active_merchant/billing/integrations/paypal.rb +39 -0
  114. data/lib/active_merchant/billing/integrations/paypal/helper.rb +119 -0
  115. data/lib/active_merchant/billing/integrations/paypal/notification.rb +154 -0
  116. data/lib/active_merchant/billing/integrations/paypal/return.rb +10 -0
  117. data/lib/active_merchant/billing/integrations/pizza.rb +116 -0
  118. data/lib/active_merchant/billing/integrations/pizza/helper.rb +117 -0
  119. data/lib/active_merchant/billing/integrations/pizza/notification.rb +101 -0
  120. data/lib/active_merchant/billing/integrations/quickpay.rb +17 -0
  121. data/lib/active_merchant/billing/integrations/quickpay/helper.rb +72 -0
  122. data/lib/active_merchant/billing/integrations/quickpay/notification.rb +74 -0
  123. data/lib/active_merchant/billing/integrations/return.rb +35 -0
  124. data/lib/active_merchant/billing/integrations/sampo_est.rb +101 -0
  125. data/lib/active_merchant/billing/integrations/sampo_est/helper.rb +17 -0
  126. data/lib/active_merchant/billing/integrations/sampo_est/notification.rb +12 -0
  127. data/lib/active_merchant/billing/integrations/seb_est.rb +100 -0
  128. data/lib/active_merchant/billing/integrations/seb_est/helper.rb +16 -0
  129. data/lib/active_merchant/billing/integrations/seb_est/notification.rb +12 -0
  130. data/lib/active_merchant/billing/integrations/swedbank_est.rb +99 -0
  131. data/lib/active_merchant/billing/integrations/swedbank_est/helper.rb +20 -0
  132. data/lib/active_merchant/billing/integrations/swedbank_est/notification.rb +12 -0
  133. data/lib/active_merchant/billing/integrations/two_checkout.rb +23 -0
  134. data/lib/active_merchant/billing/integrations/two_checkout/helper.rb +59 -0
  135. data/lib/active_merchant/billing/integrations/two_checkout/notification.rb +114 -0
  136. data/lib/active_merchant/billing/integrations/two_checkout/return.rb +17 -0
  137. data/lib/active_merchant/billing/response.rb +32 -0
  138. data/lib/active_merchant/lib/connection.rb +170 -0
  139. data/lib/active_merchant/lib/country.rb +319 -0
  140. data/lib/active_merchant/lib/error.rb +4 -0
  141. data/lib/active_merchant/lib/post_data.rb +22 -0
  142. data/lib/active_merchant/lib/posts_data.rb +47 -0
  143. data/lib/active_merchant/lib/requires_parameters.rb +16 -0
  144. data/lib/active_merchant/lib/utils.rb +18 -0
  145. data/lib/active_merchant/lib/validateable.rb +76 -0
  146. data/lib/certs/cacert.pem +7815 -0
  147. data/lib/support/gateway_support.rb +58 -0
  148. data/script/destroy +14 -0
  149. data/script/generate +14 -0
  150. data/test/fixtures.yml +355 -0
  151. data/test/remote/gateways/remote_authorize_net_cim_test.rb +460 -0
  152. data/test/remote/gateways/remote_authorize_net_test.rb +145 -0
  153. data/test/remote/gateways/remote_beanstream_interac_test.rb +53 -0
  154. data/test/remote/gateways/remote_beanstream_test.rb +150 -0
  155. data/test/remote/gateways/remote_braintree_test.rb +154 -0
  156. data/test/remote/gateways/remote_card_stream_test.rb +148 -0
  157. data/test/remote/gateways/remote_cyber_source_test.rb +144 -0
  158. data/test/remote/gateways/remote_data_cash_test.rb +357 -0
  159. data/test/remote/gateways/remote_efsnet_test.rb +81 -0
  160. data/test/remote/gateways/remote_elavon_test.rb +66 -0
  161. data/test/remote/gateways/remote_eway_test.rb +74 -0
  162. data/test/remote/gateways/remote_exact_test.rb +60 -0
  163. data/test/remote/gateways/remote_first_pay_test.rb +87 -0
  164. data/test/remote/gateways/remote_instapay_test.rb +61 -0
  165. data/test/remote/gateways/remote_jetpay_test.rb +103 -0
  166. data/test/remote/gateways/remote_linkpoint_test.rb +121 -0
  167. data/test/remote/gateways/remote_merchant_e_solutions_test.rb +173 -0
  168. data/test/remote/gateways/remote_merchant_ware_test.rb +113 -0
  169. data/test/remote/gateways/remote_modern_payments_cim_test.rb +58 -0
  170. data/test/remote/gateways/remote_modern_payments_test.rb +57 -0
  171. data/test/remote/gateways/remote_moneris_test.rb +82 -0
  172. data/test/remote/gateways/remote_net_registry_test.rb +85 -0
  173. data/test/remote/gateways/remote_netbilling_test.rb +70 -0
  174. data/test/remote/gateways/remote_ogone_test.rb +115 -0
  175. data/test/remote/gateways/remote_pay_junction_test.rb +143 -0
  176. data/test/remote/gateways/remote_pay_secure_test.rb +39 -0
  177. data/test/remote/gateways/remote_payflow_express_test.rb +50 -0
  178. data/test/remote/gateways/remote_payflow_test.rb +237 -0
  179. data/test/remote/gateways/remote_payflow_uk_test.rb +173 -0
  180. data/test/remote/gateways/remote_payment_express_test.rb +136 -0
  181. data/test/remote/gateways/remote_paypal_express_test.rb +49 -0
  182. data/test/remote/gateways/remote_paypal_test.rb +191 -0
  183. data/test/remote/gateways/remote_plugnpay_test.rb +72 -0
  184. data/test/remote/gateways/remote_psigate_test.rb +50 -0
  185. data/test/remote/gateways/remote_psl_card_test.rb +125 -0
  186. data/test/remote/gateways/remote_quickpay_test.rb +190 -0
  187. data/test/remote/gateways/remote_realex_test.rb +224 -0
  188. data/test/remote/gateways/remote_sage_bankcard_test.rb +109 -0
  189. data/test/remote/gateways/remote_sage_pay_test.rb +219 -0
  190. data/test/remote/gateways/remote_sage_test.rb +87 -0
  191. data/test/remote/gateways/remote_sage_virtual_check_test.rb +62 -0
  192. data/test/remote/gateways/remote_sallie_mae_test.rb +51 -0
  193. data/test/remote/gateways/remote_secure_pay_au_test.rb +40 -0
  194. data/test/remote/gateways/remote_secure_pay_tech_test.rb +37 -0
  195. data/test/remote/gateways/remote_secure_pay_test.rb +28 -0
  196. data/test/remote/gateways/remote_skipjack_test.rb +105 -0
  197. data/test/remote/gateways/remote_trans_first_test.rb +34 -0
  198. data/test/remote/gateways/remote_transax_test.rb +112 -0
  199. data/test/remote/gateways/remote_trust_commerce_test.rb +152 -0
  200. data/test/remote/gateways/remote_usa_epay_test.rb +46 -0
  201. data/test/remote/gateways/remote_verifi_test.rb +107 -0
  202. data/test/remote/gateways/remote_viaklix_test.rb +43 -0
  203. data/test/remote/gateways/remote_wirecard_test.rb +111 -0
  204. data/test/remote/integrations/remote_gestpay_integration_test.rb +37 -0
  205. data/test/remote/integrations/remote_paypal_integration_test.rb +26 -0
  206. data/test/test_helper.rb +182 -0
  207. data/test/unit/avs_result_test.rb +59 -0
  208. data/test/unit/base_test.rb +55 -0
  209. data/test/unit/check_test.rb +88 -0
  210. data/test/unit/connection_test.rb +129 -0
  211. data/test/unit/country_code_test.rb +33 -0
  212. data/test/unit/country_test.rb +64 -0
  213. data/test/unit/credit_card_formatting_test.rb +19 -0
  214. data/test/unit/credit_card_methods_test.rb +179 -0
  215. data/test/unit/credit_card_test.rb +318 -0
  216. data/test/unit/cvv_result_test.rb +33 -0
  217. data/test/unit/expiry_date_test.rb +32 -0
  218. data/test/unit/gateways/authorize_net_cim_test.rb +676 -0
  219. data/test/unit/gateways/authorize_net_test.rb +290 -0
  220. data/test/unit/gateways/beanstream_interac_test.rb +51 -0
  221. data/test/unit/gateways/beanstream_test.rb +108 -0
  222. data/test/unit/gateways/bogus_test.rb +46 -0
  223. data/test/unit/gateways/braintree_test.rb +126 -0
  224. data/test/unit/gateways/card_stream_test.rb +90 -0
  225. data/test/unit/gateways/cyber_source_test.rb +188 -0
  226. data/test/unit/gateways/data_cash_test.rb +133 -0
  227. data/test/unit/gateways/efsnet_test.rb +123 -0
  228. data/test/unit/gateways/elavon_test.rb +139 -0
  229. data/test/unit/gateways/eway_test.rb +118 -0
  230. data/test/unit/gateways/exact_test.rb +156 -0
  231. data/test/unit/gateways/first_pay_test.rb +125 -0
  232. data/test/unit/gateways/gateway_test.rb +48 -0
  233. data/test/unit/gateways/instapay_test.rb +102 -0
  234. data/test/unit/gateways/jetpay_test.rb +185 -0
  235. data/test/unit/gateways/linkpoint_test.rb +197 -0
  236. data/test/unit/gateways/merchant_e_solutions_test.rb +169 -0
  237. data/test/unit/gateways/merchant_ware_test.rb +188 -0
  238. data/test/unit/gateways/modern_payments_cim_test.rb +162 -0
  239. data/test/unit/gateways/moneris_test.rb +158 -0
  240. data/test/unit/gateways/net_registry_test.rb +416 -0
  241. data/test/unit/gateways/netbilling_test.rb +54 -0
  242. data/test/unit/gateways/ogone_test.rb +319 -0
  243. data/test/unit/gateways/pay_junction_test.rb +123 -0
  244. data/test/unit/gateways/pay_secure_test.rb +71 -0
  245. data/test/unit/gateways/payflow_express_test.rb +173 -0
  246. data/test/unit/gateways/payflow_express_uk_test.rb +86 -0
  247. data/test/unit/gateways/payflow_test.rb +305 -0
  248. data/test/unit/gateways/payflow_uk_test.rb +30 -0
  249. data/test/unit/gateways/payment_express_test.rb +195 -0
  250. data/test/unit/gateways/paypal_express_test.rb +382 -0
  251. data/test/unit/gateways/paypal_test.rb +569 -0
  252. data/test/unit/gateways/plugnpay_test.rb +86 -0
  253. data/test/unit/gateways/psigate_test.rb +169 -0
  254. data/test/unit/gateways/psl_card_test.rb +64 -0
  255. data/test/unit/gateways/quickpay_test.rb +112 -0
  256. data/test/unit/gateways/realex_test.rb +151 -0
  257. data/test/unit/gateways/sage_bankcard_test.rb +196 -0
  258. data/test/unit/gateways/sage_pay_test.rb +139 -0
  259. data/test/unit/gateways/sage_virtual_check_test.rb +71 -0
  260. data/test/unit/gateways/sallie_mae_test.rb +53 -0
  261. data/test/unit/gateways/secure_pay_au_test.rb +207 -0
  262. data/test/unit/gateways/secure_pay_tech_test.rb +44 -0
  263. data/test/unit/gateways/secure_pay_test.rb +87 -0
  264. data/test/unit/gateways/skip_jack_test.rb +213 -0
  265. data/test/unit/gateways/trans_first_test.rb +112 -0
  266. data/test/unit/gateways/trust_commerce_test.rb +90 -0
  267. data/test/unit/gateways/usa_epay_test.rb +128 -0
  268. data/test/unit/gateways/verifi_test.rb +96 -0
  269. data/test/unit/gateways/viaklix_test.rb +78 -0
  270. data/test/unit/gateways/wirecard_test.rb +250 -0
  271. data/test/unit/generators/test_gateway_generator.rb +46 -0
  272. data/test/unit/generators/test_generator_helper.rb +20 -0
  273. data/test/unit/generators/test_integration_generator.rb +53 -0
  274. data/test/unit/integrations/action_view_helper_test.rb +50 -0
  275. data/test/unit/integrations/adyen_module_test.rb +9 -0
  276. data/test/unit/integrations/bogus_module_test.rb +20 -0
  277. data/test/unit/integrations/chronopay_module_test.rb +13 -0
  278. data/test/unit/integrations/gestpay_module_test.rb +14 -0
  279. data/test/unit/integrations/helpers/adyen_helper_test.rb +35 -0
  280. data/test/unit/integrations/helpers/bogus_helper_test.rb +28 -0
  281. data/test/unit/integrations/helpers/chronopay_helper_test.rb +67 -0
  282. data/test/unit/integrations/helpers/gestpay_helper_test.rb +100 -0
  283. data/test/unit/integrations/helpers/hi_trust_helper_test.rb +16 -0
  284. data/test/unit/integrations/helpers/nochex_helper_test.rb +53 -0
  285. data/test/unit/integrations/helpers/paypal_helper_test.rb +171 -0
  286. data/test/unit/integrations/helpers/quickpay_helper_test.rb +40 -0
  287. data/test/unit/integrations/helpers/seb_est_helper_test.rb +69 -0
  288. data/test/unit/integrations/helpers/two_checkout_helper_test.rb +92 -0
  289. data/test/unit/integrations/hi_trust_module_test.rb +13 -0
  290. data/test/unit/integrations/nochex_module_test.rb +13 -0
  291. data/test/unit/integrations/notifications/adyen_notification_test.rb +25 -0
  292. data/test/unit/integrations/notifications/chronopay_notification_test.rb +66 -0
  293. data/test/unit/integrations/notifications/gestpay_notification_test.rb +60 -0
  294. data/test/unit/integrations/notifications/hi_trust_notification_test.rb +59 -0
  295. data/test/unit/integrations/notifications/nochex_notification_test.rb +51 -0
  296. data/test/unit/integrations/notifications/notification_test.rb +54 -0
  297. data/test/unit/integrations/notifications/paypal_notification_test.rb +85 -0
  298. data/test/unit/integrations/notifications/quickpay_notification_test.rb +69 -0
  299. data/test/unit/integrations/notifications/seb_est_notification_test.rb +87 -0
  300. data/test/unit/integrations/notifications/two_checkout_notification_test.rb +55 -0
  301. data/test/unit/integrations/paypal_module_test.rb +28 -0
  302. data/test/unit/integrations/quickpay_module_test.rb +9 -0
  303. data/test/unit/integrations/returns/adyen_return_test.rb +26 -0
  304. data/test/unit/integrations/returns/chronopay_return_test.rb +11 -0
  305. data/test/unit/integrations/returns/gestpay_return_test.rb +10 -0
  306. data/test/unit/integrations/returns/hi_trust_return_test.rb +24 -0
  307. data/test/unit/integrations/returns/nochex_return_test.rb +10 -0
  308. data/test/unit/integrations/returns/paypal_return_test.rb +10 -0
  309. data/test/unit/integrations/returns/return_test.rb +11 -0
  310. data/test/unit/integrations/returns/two_checkout_return_test.rb +24 -0
  311. data/test/unit/integrations/sampo_est_module_test.rb +9 -0
  312. data/test/unit/integrations/seb_est_module_test.rb +9 -0
  313. data/test/unit/integrations/swedbank_est_module_test.rb +9 -0
  314. data/test/unit/integrations/two_checkout_module_test.rb +13 -0
  315. data/test/unit/post_data_test.rb +55 -0
  316. data/test/unit/posts_data_test.rb +48 -0
  317. data/test/unit/response_test.rb +28 -0
  318. data/test/unit/utils_test.rb +7 -0
  319. data/test/unit/validateable_test.rb +60 -0
  320. metadata +392 -0
@@ -0,0 +1,17 @@
1
+ require File.join(File.dirname(__FILE__),'smart_ps.rb')
2
+ module ActiveMerchant #:nodoc:
3
+ module Billing #:nodoc:
4
+ class BraintreeGateway < SmartPs
5
+ def api_url
6
+ 'https://secure.braintreepaymentgateway.com/api/transact.php'
7
+ end
8
+
9
+ self.supported_countries = ['US']
10
+ self.supported_cardtypes = [:visa, :master, :american_express, :discover]
11
+ self.homepage_url = 'http://www.braintreepaymentsolutions.com'
12
+ self.display_name = 'Braintree'
13
+ end
14
+ BrainTreeGateway = BraintreeGateway
15
+ end
16
+ end
17
+
@@ -0,0 +1,230 @@
1
+ module ActiveMerchant #:nodoc:
2
+ module Billing #:nodoc:
3
+ #
4
+ # CardStream supports the following credit cards, which are auto-detected by
5
+ # the gateway based on the card number used:
6
+ # * AM American Express
7
+ # * Diners Club
8
+ # * Electron
9
+ # * JCB
10
+ # * UK Maestro
11
+ # * Maestro International
12
+ # * Mastercard
13
+ # * Solo
14
+ # * Style
15
+ # * Switch
16
+ # * Visa Credit
17
+ # * Visa Debit
18
+ # * Visa Purchasing
19
+ #
20
+ class CardStreamGateway < Gateway
21
+ URL = 'https://gateway.cardstream.com/process.ashx'
22
+
23
+ self.money_format = :cents
24
+ self.default_currency = 'GBP'
25
+ self.supported_countries = ['GB']
26
+ self.supported_cardtypes = [:visa, :master, :american_express, :diners_club, :discover, :jcb, :maestro, :solo, :switch]
27
+ self.homepage_url = 'http://www.cardstream.com/'
28
+ self.display_name = 'CardStream'
29
+
30
+ APPROVED = '00'
31
+
32
+ CURRENCY_CODES = {
33
+ "AUD"=> '036',
34
+ "CAD"=> '124',
35
+ "CZK"=> '203',
36
+ "DKK"=> '208',
37
+ "HKD"=> '344',
38
+ "ICK"=> '352',
39
+ "JPY"=> '392',
40
+ "NOK"=> '578',
41
+ "SGD"=> '702',
42
+ "SEK"=> '752',
43
+ "CHF"=> '756',
44
+ "GBP"=> '826',
45
+ "USD"=> '840',
46
+ "EUR"=> '978'
47
+ }
48
+
49
+ TRANSACTIONS = {
50
+ :purchase => 'ESALE_KEYED',
51
+ :refund => 'EREFUND_KEYED',
52
+ :authorization => 'ESALE_KEYED'
53
+ }
54
+
55
+ CVV_CODE = {
56
+ '0' => 'U',
57
+ '1' => 'P',
58
+ '2' => 'M',
59
+ '4' => 'N'
60
+ }
61
+
62
+ # 0 - No additional information available.
63
+ # 1 - Postcode not checked.
64
+ # 2 - Postcode matched.
65
+ # 4 - Postcode not matched.
66
+ # 8 - Postcode partially matched.
67
+ AVS_POSTAL_MATCH = {
68
+ "0" => nil,
69
+ "1" => nil,
70
+ "2" => "Y",
71
+ "4" => "N",
72
+ "8" => "N"
73
+ }
74
+
75
+ # 0 - No additional information available.
76
+ # 1 - Address numeric not checked.
77
+ # 2 - Address numeric matched.
78
+ # 4 - Address numeric not matched.
79
+ # 8 - Address numeric partially matched.
80
+ AVS_STREET_MATCH = {
81
+ "0" => nil,
82
+ "1" => nil,
83
+ "2" => "Y",
84
+ "4" => "N",
85
+ "8" => "N"
86
+ }
87
+
88
+ def initialize(options = {})
89
+ requires!(options, :login, :password)
90
+ @options = options
91
+ super
92
+ end
93
+
94
+ def purchase(money, credit_card, options = {})
95
+ requires!(options, :order_id)
96
+
97
+ post = {}
98
+
99
+ add_amount(post, money, options)
100
+ add_invoice(post, money, credit_card, options)
101
+ add_credit_card(post, credit_card)
102
+ add_address(post, options)
103
+ add_customer_data(post, options)
104
+
105
+ commit(:purchase, post)
106
+ end
107
+
108
+ private
109
+
110
+ def add_amount(post, money, options)
111
+ add_pair(post, :Amount, amount(money), :required => true)
112
+ add_pair(post, :CurrencyCode, currency_code(options[:currency] || currency(money)), :required => true)
113
+ end
114
+
115
+ def add_customer_data(post, options)
116
+ add_pair(post, :BillingEmail, options[:email])
117
+ add_pair(post, :BillingPhoneNumber, options[:phone])
118
+ end
119
+
120
+ def add_address(post, options)
121
+ address = options[:billing_address] || options[:address]
122
+
123
+ return if address.nil?
124
+
125
+ add_pair(post, :BillingStreet, address[:address1])
126
+ add_pair(post, :BillingHouseNumber, address[:address2])
127
+ add_pair(post, :BillingCity, address[:city])
128
+ add_pair(post, :BillingState, address[:state])
129
+ add_pair(post, :BillingPostCode, address[:zip])
130
+ end
131
+
132
+ def add_invoice(post, money, credit_card, options)
133
+ add_pair(post, :TransactionUnique, options[:order_id], :required => true)
134
+ add_pair(post, :OrderDesc, options[:description] || options[:order_id], :required => true)
135
+
136
+ if [ 'american_express', 'diners_club' ].include?(card_brand(credit_card).to_s)
137
+ add_pair(post, :AEIT1Quantity, 1)
138
+ add_pair(post, :AEIT1Description, (options[:description] || options[:order_id]).slice(0, 15))
139
+ add_pair(post, :AEIT1GrossValue, amount(money))
140
+ end
141
+ end
142
+
143
+ def add_credit_card(post, credit_card)
144
+ add_pair(post, :CardName, credit_card.name, :required => true)
145
+ add_pair(post, :CardNumber, credit_card.number, :required => true)
146
+
147
+ add_pair(post, :ExpiryDateMM, format(credit_card.month, :two_digits), :required => true)
148
+ add_pair(post, :ExpiryDateYY, format(credit_card.year, :two_digits), :required => true)
149
+
150
+ if requires_start_date_or_issue_number?(credit_card)
151
+ add_pair(post, :StartDateMM, format(credit_card.start_month, :two_digits))
152
+ add_pair(post, :StartDateYY, format(credit_card.start_year, :two_digits))
153
+
154
+ add_pair(post, :IssueNumber, credit_card.issue_number)
155
+ end
156
+
157
+ add_pair(post, :CV2, credit_card.verification_value)
158
+ end
159
+
160
+ def commit(action, parameters)
161
+ response = parse( ssl_post(URL, post_data(action, parameters)) )
162
+
163
+ Response.new(response[:response_code] == APPROVED, message_from(response), response,
164
+ :test => test?,
165
+ :authorization => response[:cross_reference],
166
+ :cvv_result => CVV_CODE[ response[:avscv2_response_code].to_s[0, 1] ],
167
+ :avs_result => {
168
+ :street_match => AVS_STREET_MATCH[ response[:avscv2_response_code].to_s[2, 1] ],
169
+ :postal_match => AVS_POSTAL_MATCH[ response[:avscv2_response_code].to_s[1, 1] ]
170
+ }
171
+ )
172
+ end
173
+
174
+ def message_from(results)
175
+ results[:response_code] == APPROVED ? "APPROVED" : results[:message]
176
+ end
177
+
178
+ def post_data(action, parameters = {})
179
+ parameters.update(
180
+ :MerchantPassword => @options[:password],
181
+ :MerchantID => @options[:login],
182
+ :MessageType => TRANSACTIONS[action],
183
+ :CallBack => "disable",
184
+ :DuplicateDelay => "0",
185
+ :EchoCardType => "YES",
186
+ :EchoAmount => "YES",
187
+ :EchoAVSCV2ResponseCode => "YES",
188
+ :ReturnAVSCV2Message => "YES",
189
+ :CountryCode => '826' # 826 for UK based merchant
190
+ )
191
+
192
+ add_pair(parameters, :Dispatch, action == :authorization ? "LATER" : "NOW")
193
+
194
+ parameters.collect { |key, value| "VP#{key}=#{CGI.escape(value.to_s)}" }.join("&")
195
+ end
196
+
197
+ # VPCrossReference
198
+ # The value in VPCrossReference on a success transaction will contain
199
+ # a unique reference that you may use to run future transactions.
200
+ # Please note that cross reference transactions must come a static IP
201
+ # addressed that has been pre-registered with Cardstream. To
202
+ # register an IP address please send it to support@cardstream.com
203
+ # with your Cardstream issued merchant ID and it will be added to
204
+ # your account.
205
+ def parse(body)
206
+ result = {}
207
+ pairs = body.split("&")
208
+ pairs.each do |pair|
209
+ a = pair.split("=")
210
+ result[a[0].gsub(/^VP/,'').underscore.to_sym] = a[1]
211
+ end
212
+
213
+ result
214
+ end
215
+
216
+ def test?
217
+ @options[:test] || Base.gateway_mode == :test
218
+ end
219
+
220
+ def currency_code(currency)
221
+ CURRENCY_CODES[currency]
222
+ end
223
+
224
+ def add_pair(post, key, value, options = {})
225
+ post[key] = value if !value.blank? || options[:required]
226
+ end
227
+ end
228
+ end
229
+ end
230
+
@@ -0,0 +1,406 @@
1
+ module ActiveMerchant #:nodoc:
2
+ module Billing #:nodoc:
3
+ # See the remote and mocked unit test files for example usage. Pay special attention to the contents of the options hash.
4
+ #
5
+ # Initial setup instructions can be found in http://cybersource.com/support_center/implementation/downloads/soap_api/SOAP_toolkits.pdf
6
+ #
7
+ # Debugging
8
+ # If you experience an issue with this gateway be sure to examine the transaction information from a general transaction search inside the CyberSource Business
9
+ # Center for the full error messages including field names.
10
+ #
11
+ # Important Notes
12
+ # * AVS and CVV only work against the production server. You will always get back X for AVS and no response for CVV against the test server.
13
+ # * Nexus is the list of states or provinces where you have a physical presence. Nexus is used to calculate tax. Leave blank to tax everyone.
14
+ # * If you want to calculate VAT for overseas customers you must supply a registration number in the options hash as vat_reg_number.
15
+ # * productCode is a value in the line_items hash that is used to tell CyberSource what kind of item you are selling. It is used when calculating tax/VAT.
16
+ # * All transactions use dollar values.
17
+ class CyberSourceGateway < Gateway
18
+ TEST_URL = 'https://ics2wstest.ic3.com/commerce/1.x/transactionProcessor'
19
+ LIVE_URL = 'https://ics2ws.ic3.com/commerce/1.x/transactionProcessor'
20
+
21
+ # visa, master, american_express, discover
22
+ self.supported_cardtypes = [:visa, :master, :american_express, :discover]
23
+ self.supported_countries = ['US']
24
+ self.default_currency = 'USD'
25
+ self.homepage_url = 'http://www.cybersource.com'
26
+ self.display_name = 'CyberSource'
27
+
28
+ # map credit card to the CyberSource expected representation
29
+ @@credit_card_codes = {
30
+ :visa => '001',
31
+ :master => '002',
32
+ :american_express => '003',
33
+ :discover => '004'
34
+ }
35
+
36
+ # map response codes to something humans can read
37
+ @@response_codes = {
38
+ :r100 => "Successful transaction",
39
+ :r101 => "Request is missing one or more required fields" ,
40
+ :r102 => "One or more fields contains invalid data",
41
+ :r150 => "General failure",
42
+ :r151 => "The request was received but a server time-out occurred",
43
+ :r152 => "The request was received, but a service timed out",
44
+ :r200 => "The authorization request was approved by the issuing bank but declined by CyberSource because it did not pass the AVS check",
45
+ :r201 => "The issuing bank has questions about the request",
46
+ :r202 => "Expired card",
47
+ :r203 => "General decline of the card",
48
+ :r204 => "Insufficient funds in the account",
49
+ :r205 => "Stolen or lost card",
50
+ :r207 => "Issuing bank unavailable",
51
+ :r208 => "Inactive card or card not authorized for card-not-present transactions",
52
+ :r209 => "American Express Card Identifiction Digits (CID) did not match",
53
+ :r210 => "The card has reached the credit limit",
54
+ :r211 => "Invalid card verification number",
55
+ :r221 => "The customer matched an entry on the processor's negative file",
56
+ :r230 => "The authorization request was approved by the issuing bank but declined by CyberSource because it did not pass the card verification check",
57
+ :r231 => "Invalid account number",
58
+ :r232 => "The card type is not accepted by the payment processor",
59
+ :r233 => "General decline by the processor",
60
+ :r234 => "A problem exists with your CyberSource merchant configuration",
61
+ :r235 => "The requested amount exceeds the originally authorized amount",
62
+ :r236 => "Processor failure",
63
+ :r237 => "The authorization has already been reversed",
64
+ :r238 => "The authorization has already been captured",
65
+ :r239 => "The requested transaction amount must match the previous transaction amount",
66
+ :r240 => "The card type sent is invalid or does not correlate with the credit card number",
67
+ :r241 => "The request ID is invalid",
68
+ :r242 => "You requested a capture, but there is no corresponding, unused authorization record.",
69
+ :r243 => "The transaction has already been settled or reversed",
70
+ :r244 => "The bank account number failed the validation check",
71
+ :r246 => "The capture or credit is not voidable because the capture or credit information has already been submitted to your processor",
72
+ :r247 => "You requested a credit for a capture that was previously voided",
73
+ :r250 => "The request was received, but a time-out occurred with the payment processor",
74
+ :r254 => "Your CyberSource account is prohibited from processing stand-alone refunds",
75
+ :r255 => "Your CyberSource account is not configured to process the service in the country you specified"
76
+ }
77
+
78
+ # These are the options that can be used when creating a new CyberSource Gateway object.
79
+ #
80
+ # :login => your username
81
+ #
82
+ # :password => the transaction key you generated in the Business Center
83
+ #
84
+ # :test => true sets the gateway to test mode
85
+ #
86
+ # :vat_reg_number => your VAT registration number
87
+ #
88
+ # :nexus => "WI CA QC" sets the states/provinces where you have a physical presense for tax purposes
89
+ #
90
+ # :ignore_avs => true don't want to use AVS so continue processing even if AVS would have failed
91
+ #
92
+ # :ignore_cvv => true don't want to use CVV so continue processing even if CVV would have failed
93
+ def initialize(options = {})
94
+ requires!(options, :login, :password)
95
+ @options = options
96
+ super
97
+ end
98
+
99
+ # Should run against the test servers or not?
100
+ def test?
101
+ @options[:test] || Base.gateway_mode == :test
102
+ end
103
+
104
+ # Request an authorization for an amount from CyberSource
105
+ #
106
+ # You must supply an :order_id in the options hash
107
+ def authorize(money, creditcard, options = {})
108
+ requires!(options, :order_id, :email)
109
+ setup_address_hash(options)
110
+ commit(build_auth_request(money, creditcard, options), options )
111
+ end
112
+
113
+ # Capture an authorization that has previously been requested
114
+ def capture(money, authorization, options = {})
115
+ setup_address_hash(options)
116
+ commit(build_capture_request(money, authorization, options), options)
117
+ end
118
+
119
+ # Purchase is an auth followed by a capture
120
+ # You must supply an order_id in the options hash
121
+ def purchase(money, creditcard, options = {})
122
+ requires!(options, :order_id, :email)
123
+ setup_address_hash(options)
124
+ commit(build_purchase_request(money, creditcard, options), options)
125
+ end
126
+
127
+ def void(identification, options = {})
128
+ commit(build_void_request(identification, options), options)
129
+ end
130
+
131
+ def credit(money, identification, options = {})
132
+ commit(build_credit_request(money, identification, options), options)
133
+ end
134
+
135
+
136
+ # CyberSource requires that you provide line item information for tax calculations
137
+ # If you do not have prices for each item or want to simplify the situation then pass in one fake line item that costs the subtotal of the order
138
+ #
139
+ # The line_item hash goes in the options hash and should look like
140
+ #
141
+ # :line_items => [
142
+ # {
143
+ # :declared_value => '1',
144
+ # :quantity => '2',
145
+ # :code => 'default',
146
+ # :description => 'Giant Walrus',
147
+ # :sku => 'WA323232323232323'
148
+ # },
149
+ # {
150
+ # :declared_value => '6',
151
+ # :quantity => '1',
152
+ # :code => 'default',
153
+ # :description => 'Marble Snowcone',
154
+ # :sku => 'FAKE1232132113123'
155
+ # }
156
+ # ]
157
+ #
158
+ # This functionality is only supported by this particular gateway may
159
+ # be changed at any time
160
+ def calculate_tax(creditcard, options)
161
+ requires!(options, :line_items)
162
+ setup_address_hash(options)
163
+ commit(build_tax_calculation_request(creditcard, options), options)
164
+ end
165
+
166
+ private
167
+ # Create all address hash key value pairs so that we still function if we were only provided with one or two of them
168
+ def setup_address_hash(options)
169
+ options[:billing_address] = options[:billing_address] || options[:address] || {}
170
+ options[:shipping_address] = options[:shipping_address] || {}
171
+ end
172
+
173
+ def build_auth_request(money, creditcard, options)
174
+ xml = Builder::XmlMarkup.new :indent => 2
175
+ add_address(xml, creditcard, options[:billing_address], options)
176
+ add_purchase_data(xml, money, true, options)
177
+ add_creditcard(xml, creditcard)
178
+ add_auth_service(xml)
179
+ add_business_rules_data(xml)
180
+ xml.target!
181
+ end
182
+
183
+ def build_tax_calculation_request(creditcard, options)
184
+ xml = Builder::XmlMarkup.new :indent => 2
185
+ add_address(xml, creditcard, options[:billing_address], options, false)
186
+ add_address(xml, creditcard, options[:shipping_address], options, true)
187
+ add_line_item_data(xml, options)
188
+ add_purchase_data(xml, 0, false, options)
189
+ add_tax_service(xml)
190
+ add_business_rules_data(xml)
191
+ xml.target!
192
+ end
193
+
194
+ def build_capture_request(money, authorization, options)
195
+ order_id, request_id, request_token = authorization.split(";")
196
+ options[:order_id] = order_id
197
+
198
+ xml = Builder::XmlMarkup.new :indent => 2
199
+ add_purchase_data(xml, money, true, options)
200
+ add_capture_service(xml, request_id, request_token)
201
+ add_business_rules_data(xml)
202
+ xml.target!
203
+ end
204
+
205
+ def build_purchase_request(money, creditcard, options)
206
+ xml = Builder::XmlMarkup.new :indent => 2
207
+ add_address(xml, creditcard, options[:billing_address], options)
208
+ add_purchase_data(xml, money, true, options)
209
+ add_creditcard(xml, creditcard)
210
+ add_purchase_service(xml, options)
211
+ add_business_rules_data(xml)
212
+ xml.target!
213
+ end
214
+
215
+ def build_void_request(identification, options)
216
+ order_id, request_id, request_token = identification.split(";")
217
+ options[:order_id] = order_id
218
+
219
+ xml = Builder::XmlMarkup.new :indent => 2
220
+ add_void_service(xml, request_id, request_token)
221
+ xml.target!
222
+ end
223
+
224
+ def build_credit_request(money, identification, options)
225
+ order_id, request_id, request_token = identification.split(";")
226
+ options[:order_id] = order_id
227
+
228
+ xml = Builder::XmlMarkup.new :indent => 2
229
+ add_purchase_data(xml, money, true, options)
230
+ add_credit_service(xml, request_id, request_token)
231
+
232
+ xml.target!
233
+ end
234
+
235
+ def add_business_rules_data(xml)
236
+ xml.tag! 'businessRules' do
237
+ xml.tag!('ignoreAVSResult', 'true') if @options[:ignore_avs]
238
+ xml.tag!('ignoreCVResult', 'true') if @options[:ignore_cvv]
239
+ end
240
+ end
241
+
242
+ def add_line_item_data(xml, options)
243
+ options[:line_items].each_with_index do |value, index|
244
+ xml.tag! 'item', {'id' => index} do
245
+ xml.tag! 'unitPrice', amount(value[:declared_value])
246
+ xml.tag! 'quantity', value[:quantity]
247
+ xml.tag! 'productCode', value[:code] || 'shipping_only'
248
+ xml.tag! 'productName', value[:description]
249
+ xml.tag! 'productSKU', value[:sku]
250
+ end
251
+ end
252
+ end
253
+
254
+ def add_merchant_data(xml, options)
255
+ xml.tag! 'merchantID', @options[:login]
256
+ xml.tag! 'merchantReferenceCode', options[:order_id]
257
+ xml.tag! 'clientLibrary' ,'Ruby Active Merchant'
258
+ xml.tag! 'clientLibraryVersion', '1.0'
259
+ xml.tag! 'clientEnvironment' , 'Linux'
260
+ end
261
+
262
+ def add_purchase_data(xml, money = 0, include_grand_total = false, options={})
263
+ xml.tag! 'purchaseTotals' do
264
+ xml.tag! 'currency', options[:currency] || currency(money)
265
+ xml.tag!('grandTotalAmount', amount(money)) if include_grand_total
266
+ end
267
+ end
268
+
269
+ def add_address(xml, creditcard, address, options, shipTo = false)
270
+ xml.tag! shipTo ? 'shipTo' : 'billTo' do
271
+ xml.tag! 'firstName', creditcard.first_name
272
+ xml.tag! 'lastName', creditcard.last_name
273
+ xml.tag! 'street1', address[:address1]
274
+ xml.tag! 'street2', address[:address2]
275
+ xml.tag! 'city', address[:city]
276
+ xml.tag! 'state', address[:state]
277
+ xml.tag! 'postalCode', address[:zip]
278
+ xml.tag! 'country', address[:country]
279
+ xml.tag! 'email', options[:email]
280
+ end
281
+ end
282
+
283
+ def add_creditcard(xml, creditcard)
284
+ xml.tag! 'card' do
285
+ xml.tag! 'accountNumber', creditcard.number
286
+ xml.tag! 'expirationMonth', format(creditcard.month, :two_digits)
287
+ xml.tag! 'expirationYear', format(creditcard.year, :four_digits)
288
+ xml.tag!('cvNumber', creditcard.verification_value) unless (@options[:ignore_cvv] || creditcard.verification_value.blank? )
289
+ xml.tag! 'cardType', @@credit_card_codes[card_brand(creditcard).to_sym]
290
+ end
291
+ end
292
+
293
+ def add_tax_service(xml)
294
+ xml.tag! 'taxService', {'run' => 'true'} do
295
+ xml.tag!('nexus', @options[:nexus]) unless @options[:nexus].blank?
296
+ xml.tag!('sellerRegistration', @options[:vat_reg_number]) unless @options[:vat_reg_number].blank?
297
+ end
298
+ end
299
+
300
+ def add_auth_service(xml)
301
+ xml.tag! 'ccAuthService', {'run' => 'true'}
302
+ end
303
+
304
+ def add_capture_service(xml, request_id, request_token)
305
+ xml.tag! 'ccCaptureService', {'run' => 'true'} do
306
+ xml.tag! 'authRequestID', request_id
307
+ xml.tag! 'authRequestToken', request_token
308
+ end
309
+ end
310
+
311
+ def add_purchase_service(xml, options)
312
+ xml.tag! 'ccAuthService', {'run' => 'true'}
313
+ xml.tag! 'ccCaptureService', {'run' => 'true'}
314
+ end
315
+
316
+ def add_void_service(xml, request_id, request_token)
317
+ xml.tag! 'voidService', {'run' => 'true'} do
318
+ xml.tag! 'voidRequestID', request_id
319
+ xml.tag! 'voidRequestToken', request_token
320
+ end
321
+ end
322
+
323
+ def add_credit_service(xml, request_id, request_token)
324
+ xml.tag! 'ccCreditService', {'run' => 'true'} do
325
+ xml.tag! 'captureRequestID', request_id
326
+ xml.tag! 'captureRequestToken', request_token
327
+ end
328
+ end
329
+
330
+
331
+ # Where we actually build the full SOAP request using builder
332
+ def build_request(body, options)
333
+ xml = Builder::XmlMarkup.new :indent => 2
334
+ xml.instruct!
335
+ xml.tag! 's:Envelope', {'xmlns:s' => 'http://schemas.xmlsoap.org/soap/envelope/'} do
336
+ xml.tag! 's:Header' do
337
+ xml.tag! 'wsse:Security', {'s:mustUnderstand' => '1', 'xmlns:wsse' => 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd'} do
338
+ xml.tag! 'wsse:UsernameToken' do
339
+ xml.tag! 'wsse:Username', @options[:login]
340
+ xml.tag! 'wsse:Password', @options[:password], 'Type' => 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText'
341
+ end
342
+ end
343
+ end
344
+ xml.tag! 's:Body', {'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance', 'xmlns:xsd' => 'http://www.w3.org/2001/XMLSchema'} do
345
+ xml.tag! 'requestMessage', {'xmlns' => 'urn:schemas-cybersource-com:transaction-data-1.32'} do
346
+ add_merchant_data(xml, options)
347
+ xml << body
348
+ end
349
+ end
350
+ end
351
+ xml.target!
352
+ end
353
+
354
+ # Contact CyberSource, make the SOAP request, and parse the reply into a Response object
355
+ def commit(request, options)
356
+ response = parse(ssl_post(test? ? TEST_URL : LIVE_URL, build_request(request, options)))
357
+
358
+ success = response[:decision] == "ACCEPT"
359
+ message = @@response_codes[('r' + response[:reasonCode]).to_sym] rescue response[:message]
360
+ authorization = success ? [ options[:order_id], response[:requestID], response[:requestToken] ].compact.join(";") : nil
361
+
362
+ Response.new(success, message, response,
363
+ :test => test?,
364
+ :authorization => authorization,
365
+ :avs_result => { :code => response[:avsCode] },
366
+ :cvv_result => response[:cvCode]
367
+ )
368
+ end
369
+
370
+ # Parse the SOAP response
371
+ # Technique inspired by the Paypal Gateway
372
+ def parse(xml)
373
+ reply = {}
374
+ xml = REXML::Document.new(xml)
375
+ if root = REXML::XPath.first(xml, "//c:replyMessage")
376
+ root.elements.to_a.each do |node|
377
+ case node.name
378
+ when 'c:reasonCode'
379
+ reply[:message] = reply(node.text)
380
+ else
381
+ parse_element(reply, node)
382
+ end
383
+ end
384
+ elsif root = REXML::XPath.first(xml, "//soap:Fault")
385
+ parse_element(reply, root)
386
+ reply[:message] = "#{reply[:faultcode]}: #{reply[:faultstring]}"
387
+ end
388
+ return reply
389
+ end
390
+
391
+ def parse_element(reply, node)
392
+ if node.has_elements?
393
+ node.elements.each{|e| parse_element(reply, e) }
394
+ else
395
+ if node.parent.name =~ /item/
396
+ parent = node.parent.name + (node.parent.attributes["id"] ? "_" + node.parent.attributes["id"] : '')
397
+ reply[(parent + '_' + node.name).to_sym] = node.text
398
+ else
399
+ reply[node.name.to_sym] = node.text
400
+ end
401
+ end
402
+ return reply
403
+ end
404
+ end
405
+ end
406
+ end