abtain_billing 1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (294) hide show
  1. data/CHANGELOG +473 -0
  2. data/CONTRIBUTORS +126 -0
  3. data/MIT-LICENSE +20 -0
  4. data/README +3 -0
  5. data/Rakefile +153 -0
  6. data/init.rb +3 -0
  7. data/lib/active_merchant.rb +60 -0
  8. data/lib/active_merchant/billing/avs_result.rb +98 -0
  9. data/lib/active_merchant/billing/base.rb +57 -0
  10. data/lib/active_merchant/billing/check.rb +68 -0
  11. data/lib/active_merchant/billing/credit_card.rb +159 -0
  12. data/lib/active_merchant/billing/credit_card_formatting.rb +21 -0
  13. data/lib/active_merchant/billing/credit_card_methods.rb +125 -0
  14. data/lib/active_merchant/billing/cvv_result.rb +38 -0
  15. data/lib/active_merchant/billing/expiry_date.rb +34 -0
  16. data/lib/active_merchant/billing/gateway.rb +158 -0
  17. data/lib/active_merchant/billing/gateways.rb +3 -0
  18. data/lib/active_merchant/billing/gateways/authorize_net.rb +657 -0
  19. data/lib/active_merchant/billing/gateways/authorize_net_cim.rb +813 -0
  20. data/lib/active_merchant/billing/gateways/beanstream.rb +102 -0
  21. data/lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb +233 -0
  22. data/lib/active_merchant/billing/gateways/beanstream_interac.rb +54 -0
  23. data/lib/active_merchant/billing/gateways/bogus.rb +98 -0
  24. data/lib/active_merchant/billing/gateways/braintree.rb +17 -0
  25. data/lib/active_merchant/billing/gateways/card_stream.rb +230 -0
  26. data/lib/active_merchant/billing/gateways/cyber_source.rb +406 -0
  27. data/lib/active_merchant/billing/gateways/data_cash.rb +595 -0
  28. data/lib/active_merchant/billing/gateways/efsnet.rb +229 -0
  29. data/lib/active_merchant/billing/gateways/elavon.rb +106 -0
  30. data/lib/active_merchant/billing/gateways/eway.rb +277 -0
  31. data/lib/active_merchant/billing/gateways/exact.rb +222 -0
  32. data/lib/active_merchant/billing/gateways/first_pay.rb +172 -0
  33. data/lib/active_merchant/billing/gateways/instapay.rb +164 -0
  34. data/lib/active_merchant/billing/gateways/jetpay.rb +270 -0
  35. data/lib/active_merchant/billing/gateways/linkpoint.rb +449 -0
  36. data/lib/active_merchant/billing/gateways/merchant_e_solutions.rb +154 -0
  37. data/lib/active_merchant/billing/gateways/merchant_ware.rb +283 -0
  38. data/lib/active_merchant/billing/gateways/modern_payments.rb +36 -0
  39. data/lib/active_merchant/billing/gateways/modern_payments_cim.rb +214 -0
  40. data/lib/active_merchant/billing/gateways/moneris.rb +205 -0
  41. data/lib/active_merchant/billing/gateways/net_registry.rb +189 -0
  42. data/lib/active_merchant/billing/gateways/netbilling.rb +168 -0
  43. data/lib/active_merchant/billing/gateways/ogone.rb +279 -0
  44. data/lib/active_merchant/billing/gateways/pay_junction.rb +392 -0
  45. data/lib/active_merchant/billing/gateways/pay_secure.rb +120 -0
  46. data/lib/active_merchant/billing/gateways/payflow.rb +236 -0
  47. data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +207 -0
  48. data/lib/active_merchant/billing/gateways/payflow/payflow_express_response.rb +39 -0
  49. data/lib/active_merchant/billing/gateways/payflow/payflow_response.rb +13 -0
  50. data/lib/active_merchant/billing/gateways/payflow_express.rb +138 -0
  51. data/lib/active_merchant/billing/gateways/payflow_express_uk.rb +15 -0
  52. data/lib/active_merchant/billing/gateways/payflow_uk.rb +21 -0
  53. data/lib/active_merchant/billing/gateways/payment_express.rb +230 -0
  54. data/lib/active_merchant/billing/gateways/paypal.rb +121 -0
  55. data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +326 -0
  56. data/lib/active_merchant/billing/gateways/paypal/paypal_express_response.rb +38 -0
  57. data/lib/active_merchant/billing/gateways/paypal_ca.rb +13 -0
  58. data/lib/active_merchant/billing/gateways/paypal_express.rb +130 -0
  59. data/lib/active_merchant/billing/gateways/paypal_express_common.rb +20 -0
  60. data/lib/active_merchant/billing/gateways/plugnpay.rb +292 -0
  61. data/lib/active_merchant/billing/gateways/psigate.rb +214 -0
  62. data/lib/active_merchant/billing/gateways/psl_card.rb +306 -0
  63. data/lib/active_merchant/billing/gateways/quickpay.rb +213 -0
  64. data/lib/active_merchant/billing/gateways/realex.rb +200 -0
  65. data/lib/active_merchant/billing/gateways/sage.rb +146 -0
  66. data/lib/active_merchant/billing/gateways/sage/sage_bankcard.rb +88 -0
  67. data/lib/active_merchant/billing/gateways/sage/sage_core.rb +116 -0
  68. data/lib/active_merchant/billing/gateways/sage/sage_virtual_check.rb +97 -0
  69. data/lib/active_merchant/billing/gateways/sage_pay.rb +308 -0
  70. data/lib/active_merchant/billing/gateways/sallie_mae.rb +144 -0
  71. data/lib/active_merchant/billing/gateways/secure_pay.rb +31 -0
  72. data/lib/active_merchant/billing/gateways/secure_pay_au.rb +157 -0
  73. data/lib/active_merchant/billing/gateways/secure_pay_tech.rb +113 -0
  74. data/lib/active_merchant/billing/gateways/skip_jack.rb +452 -0
  75. data/lib/active_merchant/billing/gateways/smart_ps.rb +254 -0
  76. data/lib/active_merchant/billing/gateways/trans_first.rb +127 -0
  77. data/lib/active_merchant/billing/gateways/transax.rb +26 -0
  78. data/lib/active_merchant/billing/gateways/trust_commerce.rb +418 -0
  79. data/lib/active_merchant/billing/gateways/usa_epay.rb +194 -0
  80. data/lib/active_merchant/billing/gateways/verifi.rb +228 -0
  81. data/lib/active_merchant/billing/gateways/viaklix.rb +189 -0
  82. data/lib/active_merchant/billing/gateways/wirecard.rb +318 -0
  83. data/lib/active_merchant/billing/integrations.rb +22 -0
  84. data/lib/active_merchant/billing/integrations/action_view_helper.rb +79 -0
  85. data/lib/active_merchant/billing/integrations/bogus.rb +22 -0
  86. data/lib/active_merchant/billing/integrations/bogus/helper.rb +17 -0
  87. data/lib/active_merchant/billing/integrations/bogus/notification.rb +11 -0
  88. data/lib/active_merchant/billing/integrations/bogus/return.rb +10 -0
  89. data/lib/active_merchant/billing/integrations/chronopay.rb +22 -0
  90. data/lib/active_merchant/billing/integrations/chronopay/helper.rb +81 -0
  91. data/lib/active_merchant/billing/integrations/chronopay/notification.rb +156 -0
  92. data/lib/active_merchant/billing/integrations/chronopay/return.rb +10 -0
  93. data/lib/active_merchant/billing/integrations/gestpay.rb +26 -0
  94. data/lib/active_merchant/billing/integrations/gestpay/common.rb +42 -0
  95. data/lib/active_merchant/billing/integrations/gestpay/helper.rb +70 -0
  96. data/lib/active_merchant/billing/integrations/gestpay/notification.rb +83 -0
  97. data/lib/active_merchant/billing/integrations/gestpay/return.rb +10 -0
  98. data/lib/active_merchant/billing/integrations/helper.rb +93 -0
  99. data/lib/active_merchant/billing/integrations/hi_trust.rb +26 -0
  100. data/lib/active_merchant/billing/integrations/hi_trust/helper.rb +58 -0
  101. data/lib/active_merchant/billing/integrations/hi_trust/notification.rb +59 -0
  102. data/lib/active_merchant/billing/integrations/hi_trust/return.rb +67 -0
  103. data/lib/active_merchant/billing/integrations/nochex.rb +87 -0
  104. data/lib/active_merchant/billing/integrations/nochex/helper.rb +68 -0
  105. data/lib/active_merchant/billing/integrations/nochex/notification.rb +94 -0
  106. data/lib/active_merchant/billing/integrations/nochex/return.rb +10 -0
  107. data/lib/active_merchant/billing/integrations/notification.rb +62 -0
  108. data/lib/active_merchant/billing/integrations/paypal.rb +40 -0
  109. data/lib/active_merchant/billing/integrations/paypal/helper.rb +119 -0
  110. data/lib/active_merchant/billing/integrations/paypal/notification.rb +154 -0
  111. data/lib/active_merchant/billing/integrations/paypal/return.rb +10 -0
  112. data/lib/active_merchant/billing/integrations/quickpay.rb +18 -0
  113. data/lib/active_merchant/billing/integrations/quickpay/helper.rb +72 -0
  114. data/lib/active_merchant/billing/integrations/quickpay/notification.rb +74 -0
  115. data/lib/active_merchant/billing/integrations/return.rb +35 -0
  116. data/lib/active_merchant/billing/integrations/two_checkout.rb +23 -0
  117. data/lib/active_merchant/billing/integrations/two_checkout/helper.rb +59 -0
  118. data/lib/active_merchant/billing/integrations/two_checkout/notification.rb +114 -0
  119. data/lib/active_merchant/billing/integrations/two_checkout/return.rb +17 -0
  120. data/lib/active_merchant/billing/response.rb +32 -0
  121. data/lib/active_merchant/lib/connection.rb +170 -0
  122. data/lib/active_merchant/lib/country.rb +319 -0
  123. data/lib/active_merchant/lib/error.rb +4 -0
  124. data/lib/active_merchant/lib/post_data.rb +22 -0
  125. data/lib/active_merchant/lib/posts_data.rb +47 -0
  126. data/lib/active_merchant/lib/requires_parameters.rb +16 -0
  127. data/lib/active_merchant/lib/utils.rb +18 -0
  128. data/lib/active_merchant/lib/validateable.rb +76 -0
  129. data/lib/certs/cacert.pem +7815 -0
  130. data/lib/support/gateway_support.rb +58 -0
  131. data/script/destroy +14 -0
  132. data/script/generate +14 -0
  133. data/test/fixtures.yml +355 -0
  134. data/test/remote/gateways/remote_authorize_net_cim_test.rb +460 -0
  135. data/test/remote/gateways/remote_authorize_net_test.rb +145 -0
  136. data/test/remote/gateways/remote_beanstream_interac_test.rb +53 -0
  137. data/test/remote/gateways/remote_beanstream_test.rb +150 -0
  138. data/test/remote/gateways/remote_braintree_test.rb +154 -0
  139. data/test/remote/gateways/remote_card_stream_test.rb +148 -0
  140. data/test/remote/gateways/remote_cyber_source_test.rb +144 -0
  141. data/test/remote/gateways/remote_data_cash_test.rb +357 -0
  142. data/test/remote/gateways/remote_efsnet_test.rb +81 -0
  143. data/test/remote/gateways/remote_elavon_test.rb +66 -0
  144. data/test/remote/gateways/remote_eway_test.rb +74 -0
  145. data/test/remote/gateways/remote_exact_test.rb +60 -0
  146. data/test/remote/gateways/remote_first_pay_test.rb +87 -0
  147. data/test/remote/gateways/remote_instapay_test.rb +61 -0
  148. data/test/remote/gateways/remote_jetpay_test.rb +103 -0
  149. data/test/remote/gateways/remote_linkpoint_test.rb +121 -0
  150. data/test/remote/gateways/remote_merchant_e_solutions_test.rb +173 -0
  151. data/test/remote/gateways/remote_merchant_ware_test.rb +113 -0
  152. data/test/remote/gateways/remote_modern_payments_cim_test.rb +58 -0
  153. data/test/remote/gateways/remote_modern_payments_test.rb +43 -0
  154. data/test/remote/gateways/remote_moneris_test.rb +82 -0
  155. data/test/remote/gateways/remote_net_registry_test.rb +85 -0
  156. data/test/remote/gateways/remote_netbilling_test.rb +70 -0
  157. data/test/remote/gateways/remote_ogone_test.rb +115 -0
  158. data/test/remote/gateways/remote_pay_junction_test.rb +143 -0
  159. data/test/remote/gateways/remote_pay_secure_test.rb +39 -0
  160. data/test/remote/gateways/remote_payflow_express_test.rb +50 -0
  161. data/test/remote/gateways/remote_payflow_test.rb +237 -0
  162. data/test/remote/gateways/remote_payflow_uk_test.rb +173 -0
  163. data/test/remote/gateways/remote_payment_express_test.rb +136 -0
  164. data/test/remote/gateways/remote_paypal_express_test.rb +49 -0
  165. data/test/remote/gateways/remote_paypal_test.rb +191 -0
  166. data/test/remote/gateways/remote_plugnpay_test.rb +72 -0
  167. data/test/remote/gateways/remote_psigate_test.rb +50 -0
  168. data/test/remote/gateways/remote_psl_card_test.rb +125 -0
  169. data/test/remote/gateways/remote_quickpay_test.rb +190 -0
  170. data/test/remote/gateways/remote_realex_test.rb +224 -0
  171. data/test/remote/gateways/remote_sage_bankcard_test.rb +109 -0
  172. data/test/remote/gateways/remote_sage_pay_test.rb +219 -0
  173. data/test/remote/gateways/remote_sage_test.rb +87 -0
  174. data/test/remote/gateways/remote_sage_virtual_check_test.rb +62 -0
  175. data/test/remote/gateways/remote_sallie_mae_test.rb +51 -0
  176. data/test/remote/gateways/remote_secure_pay_au_test.rb +40 -0
  177. data/test/remote/gateways/remote_secure_pay_tech_test.rb +37 -0
  178. data/test/remote/gateways/remote_secure_pay_test.rb +28 -0
  179. data/test/remote/gateways/remote_skipjack_test.rb +105 -0
  180. data/test/remote/gateways/remote_trans_first_test.rb +34 -0
  181. data/test/remote/gateways/remote_transax_test.rb +112 -0
  182. data/test/remote/gateways/remote_trust_commerce_test.rb +152 -0
  183. data/test/remote/gateways/remote_usa_epay_test.rb +46 -0
  184. data/test/remote/gateways/remote_verifi_test.rb +107 -0
  185. data/test/remote/gateways/remote_viaklix_test.rb +43 -0
  186. data/test/remote/gateways/remote_wirecard_test.rb +111 -0
  187. data/test/remote/integrations/remote_gestpay_integration_test.rb +37 -0
  188. data/test/remote/integrations/remote_paypal_integration_test.rb +26 -0
  189. data/test/test_helper.rb +182 -0
  190. data/test/unit/avs_result_test.rb +59 -0
  191. data/test/unit/base_test.rb +55 -0
  192. data/test/unit/check_test.rb +88 -0
  193. data/test/unit/connection_test.rb +129 -0
  194. data/test/unit/country_code_test.rb +33 -0
  195. data/test/unit/country_test.rb +64 -0
  196. data/test/unit/credit_card_formatting_test.rb +19 -0
  197. data/test/unit/credit_card_methods_test.rb +179 -0
  198. data/test/unit/credit_card_test.rb +318 -0
  199. data/test/unit/cvv_result_test.rb +33 -0
  200. data/test/unit/expiry_date_test.rb +32 -0
  201. data/test/unit/gateways/authorize_net_cim_test.rb +676 -0
  202. data/test/unit/gateways/authorize_net_test.rb +290 -0
  203. data/test/unit/gateways/beanstream_interac_test.rb +51 -0
  204. data/test/unit/gateways/beanstream_test.rb +108 -0
  205. data/test/unit/gateways/bogus_test.rb +46 -0
  206. data/test/unit/gateways/braintree_test.rb +126 -0
  207. data/test/unit/gateways/card_stream_test.rb +90 -0
  208. data/test/unit/gateways/cyber_source_test.rb +188 -0
  209. data/test/unit/gateways/data_cash_test.rb +133 -0
  210. data/test/unit/gateways/efsnet_test.rb +123 -0
  211. data/test/unit/gateways/elavon_test.rb +139 -0
  212. data/test/unit/gateways/eway_test.rb +118 -0
  213. data/test/unit/gateways/exact_test.rb +156 -0
  214. data/test/unit/gateways/first_pay_test.rb +125 -0
  215. data/test/unit/gateways/gateway_test.rb +48 -0
  216. data/test/unit/gateways/instapay_test.rb +102 -0
  217. data/test/unit/gateways/jetpay_test.rb +185 -0
  218. data/test/unit/gateways/linkpoint_test.rb +184 -0
  219. data/test/unit/gateways/merchant_e_solutions_test.rb +169 -0
  220. data/test/unit/gateways/merchant_ware_test.rb +188 -0
  221. data/test/unit/gateways/modern_payments_cim_test.rb +171 -0
  222. data/test/unit/gateways/moneris_test.rb +158 -0
  223. data/test/unit/gateways/net_registry_test.rb +416 -0
  224. data/test/unit/gateways/netbilling_test.rb +54 -0
  225. data/test/unit/gateways/ogone_test.rb +319 -0
  226. data/test/unit/gateways/pay_junction_test.rb +123 -0
  227. data/test/unit/gateways/pay_secure_test.rb +71 -0
  228. data/test/unit/gateways/payflow_express_test.rb +173 -0
  229. data/test/unit/gateways/payflow_express_uk_test.rb +86 -0
  230. data/test/unit/gateways/payflow_test.rb +305 -0
  231. data/test/unit/gateways/payflow_uk_test.rb +30 -0
  232. data/test/unit/gateways/payment_express_test.rb +195 -0
  233. data/test/unit/gateways/paypal_express_test.rb +382 -0
  234. data/test/unit/gateways/paypal_test.rb +569 -0
  235. data/test/unit/gateways/plugnpay_test.rb +86 -0
  236. data/test/unit/gateways/psigate_test.rb +169 -0
  237. data/test/unit/gateways/psl_card_test.rb +64 -0
  238. data/test/unit/gateways/quickpay_test.rb +112 -0
  239. data/test/unit/gateways/realex_test.rb +151 -0
  240. data/test/unit/gateways/sage_bankcard_test.rb +196 -0
  241. data/test/unit/gateways/sage_pay_test.rb +139 -0
  242. data/test/unit/gateways/sage_virtual_check_test.rb +71 -0
  243. data/test/unit/gateways/sallie_mae_test.rb +53 -0
  244. data/test/unit/gateways/secure_pay_au_test.rb +207 -0
  245. data/test/unit/gateways/secure_pay_tech_test.rb +44 -0
  246. data/test/unit/gateways/secure_pay_test.rb +87 -0
  247. data/test/unit/gateways/skip_jack_test.rb +213 -0
  248. data/test/unit/gateways/trans_first_test.rb +112 -0
  249. data/test/unit/gateways/trust_commerce_test.rb +90 -0
  250. data/test/unit/gateways/usa_epay_test.rb +128 -0
  251. data/test/unit/gateways/verifi_test.rb +96 -0
  252. data/test/unit/gateways/viaklix_test.rb +78 -0
  253. data/test/unit/gateways/wirecard_test.rb +250 -0
  254. data/test/unit/generators/test_gateway_generator.rb +46 -0
  255. data/test/unit/generators/test_generator_helper.rb +20 -0
  256. data/test/unit/generators/test_integration_generator.rb +53 -0
  257. data/test/unit/integrations/action_view_helper_test.rb +50 -0
  258. data/test/unit/integrations/bogus_module_test.rb +20 -0
  259. data/test/unit/integrations/chronopay_module_test.rb +13 -0
  260. data/test/unit/integrations/gestpay_module_test.rb +14 -0
  261. data/test/unit/integrations/helpers/bogus_helper_test.rb +28 -0
  262. data/test/unit/integrations/helpers/chronopay_helper_test.rb +67 -0
  263. data/test/unit/integrations/helpers/gestpay_helper_test.rb +100 -0
  264. data/test/unit/integrations/helpers/hi_trust_helper_test.rb +16 -0
  265. data/test/unit/integrations/helpers/nochex_helper_test.rb +53 -0
  266. data/test/unit/integrations/helpers/paypal_helper_test.rb +171 -0
  267. data/test/unit/integrations/helpers/quickpay_helper_test.rb +40 -0
  268. data/test/unit/integrations/helpers/two_checkout_helper_test.rb +92 -0
  269. data/test/unit/integrations/hi_trust_module_test.rb +13 -0
  270. data/test/unit/integrations/nochex_module_test.rb +13 -0
  271. data/test/unit/integrations/notifications/chronopay_notification_test.rb +66 -0
  272. data/test/unit/integrations/notifications/gestpay_notification_test.rb +60 -0
  273. data/test/unit/integrations/notifications/hi_trust_notification_test.rb +59 -0
  274. data/test/unit/integrations/notifications/nochex_notification_test.rb +51 -0
  275. data/test/unit/integrations/notifications/notification_test.rb +54 -0
  276. data/test/unit/integrations/notifications/paypal_notification_test.rb +85 -0
  277. data/test/unit/integrations/notifications/quickpay_notification_test.rb +69 -0
  278. data/test/unit/integrations/notifications/two_checkout_notification_test.rb +55 -0
  279. data/test/unit/integrations/paypal_module_test.rb +28 -0
  280. data/test/unit/integrations/quickpay_module_test.rb +9 -0
  281. data/test/unit/integrations/returns/chronopay_return_test.rb +11 -0
  282. data/test/unit/integrations/returns/gestpay_return_test.rb +10 -0
  283. data/test/unit/integrations/returns/hi_trust_return_test.rb +24 -0
  284. data/test/unit/integrations/returns/nochex_return_test.rb +10 -0
  285. data/test/unit/integrations/returns/paypal_return_test.rb +10 -0
  286. data/test/unit/integrations/returns/return_test.rb +11 -0
  287. data/test/unit/integrations/returns/two_checkout_return_test.rb +24 -0
  288. data/test/unit/integrations/two_checkout_module_test.rb +13 -0
  289. data/test/unit/post_data_test.rb +55 -0
  290. data/test/unit/posts_data_test.rb +48 -0
  291. data/test/unit/response_test.rb +28 -0
  292. data/test/unit/utils_test.rb +7 -0
  293. data/test/unit/validateable_test.rb +60 -0
  294. metadata +366 -0
@@ -0,0 +1,813 @@
1
+ require 'digest/sha1'
2
+
3
+ module ActiveMerchant #:nodoc:
4
+ module Billing #:nodoc:
5
+ # ==== Customer Information Manager (CIM)
6
+ #
7
+ # The Authorize.Net Customer Information Manager (CIM) is an optional additional service that allows you to store sensitive payment information on
8
+ # Authorize.Net's servers, simplifying payments for returning customers and recurring transactions. It can also help with Payment Card Industry (PCI)
9
+ # Data Security Standard compliance, since customer data is no longer stored locally.
10
+ #
11
+ # To use the AuthorizeNetCimGateway CIM must be enabled for your account.
12
+ #
13
+ # Information about CIM is available on the {Authorize.Net website}[http://www.authorize.net/solutions/merchantsolutions/merchantservices/cim/].
14
+ # Information about the CIM API is available at the {Authorize.Net Integration Center}[http://developer.authorize.net/]
15
+ #
16
+ # ==== Login and Password
17
+ #
18
+ # The login and password are not the username and password you use to
19
+ # login to the Authorize.Net Merchant Interface. Instead, you will
20
+ # use the API Login ID as the login and Transaction Key as the
21
+ # password.
22
+ #
23
+ # ==== How to Get Your API Login ID and Transaction Key
24
+ #
25
+ # 1. Log into the Merchant Interface
26
+ # 2. Select Settings from the Main Menu
27
+ # 3. Click on API Login ID and Transaction Key in the Security section
28
+ # 4. Type in the answer to the secret question configured on setup
29
+ # 5. Click Submit
30
+ class AuthorizeNetCimGateway < Gateway
31
+
32
+ class_inheritable_accessor :test_url, :live_url
33
+
34
+ self.test_url = 'https://apitest.authorize.net/xml/v1/request.api'
35
+ self.live_url = 'https://api.authorize.net/xml/v1/request.api'
36
+
37
+ AUTHORIZE_NET_CIM_NAMESPACE = 'AnetApi/xml/v1/schema/AnetApiSchema.xsd'
38
+
39
+ CIM_ACTIONS = {
40
+ :create_customer_profile => 'createCustomerProfile',
41
+ :create_customer_payment_profile => 'createCustomerPaymentProfile',
42
+ :create_customer_shipping_address => 'createCustomerShippingAddress',
43
+ :get_customer_profile => 'getCustomerProfile',
44
+ :get_customer_profile_ids => 'getCustomerProfileIds',
45
+ :get_customer_payment_profile => 'getCustomerPaymentProfile',
46
+ :get_customer_shipping_address => 'getCustomerShippingAddress',
47
+ :delete_customer_profile => 'deleteCustomerProfile',
48
+ :delete_customer_payment_profile => 'deleteCustomerPaymentProfile',
49
+ :delete_customer_shipping_address => 'deleteCustomerShippingAddress',
50
+ :update_customer_profile => 'updateCustomerProfile',
51
+ :update_customer_payment_profile => 'updateCustomerPaymentProfile',
52
+ :update_customer_shipping_address => 'updateCustomerShippingAddress',
53
+ :create_customer_profile_transaction => 'createCustomerProfileTransaction',
54
+ :validate_customer_payment_profile => 'validateCustomerPaymentProfile'
55
+ }
56
+
57
+ CIM_TRANSACTION_TYPES = {
58
+ :auth_capture => 'profileTransAuthCapture',
59
+ :auth_only => 'profileTransAuthOnly',
60
+ :capture_only => 'profileTransCaptureOnly'
61
+ }
62
+
63
+ CIM_VALIDATION_MODES = {
64
+ :none => 'none',
65
+ :test => 'testMode',
66
+ :live => 'liveMode'
67
+ }
68
+
69
+ BANK_ACCOUNT_TYPES = {
70
+ :checking => 'checking',
71
+ :savings => 'savings',
72
+ :business_checking => 'businessChecking'
73
+ }
74
+
75
+ ECHECK_TYPES = {
76
+ :ccd => 'CCD',
77
+ :ppd => 'PPD'
78
+ }
79
+
80
+ self.homepage_url = 'http://www.authorize.net/'
81
+ self.display_name = 'Authorize.Net CIM'
82
+ self.supported_countries = ['US']
83
+ self.supported_cardtypes = [:visa, :master, :american_express, :discover]
84
+
85
+ # Creates a new AuthorizeNetCimGateway
86
+ #
87
+ # The gateway requires that a valid API Login ID and Transaction Key be passed
88
+ # in the +options+ hash.
89
+ #
90
+ # ==== Options
91
+ #
92
+ # * <tt>:login</tt> -- The Authorize.Net API Login ID (REQUIRED)
93
+ # * <tt>:password</tt> -- The Authorize.Net Transaction Key. (REQUIRED)
94
+ # * <tt>:test</tt> -- +true+ or +false+. If true, perform transactions against the test server.
95
+ # Otherwise, perform transactions against the production server.
96
+ def initialize(options = {})
97
+ requires!(options, :login, :password)
98
+ @options = options
99
+ super
100
+ end
101
+
102
+ # The following methods are for compatibility with
103
+ # other stored-value gateways
104
+
105
+ # Create a payment profile
106
+ def store(creditcard, options = {})
107
+ profile = {
108
+ :payment_profiles => {
109
+ :payment => { :credit_card => creditcard }
110
+ }
111
+ }
112
+ profile[:payment_profiles][:bill_to] = options[:billing_address] if options[:billing_address]
113
+ profile[:ship_to_list] = options[:shipping_address] if options[:shipping_address]
114
+
115
+ # CIM actually does require a unique ID to be passed in,
116
+ # either merchant_customer_id or email, so generate it, if necessary
117
+ if options[:billing_id]
118
+ profile[:merchant_customer_id] = options[:billing_id]
119
+ elsif options[:email]
120
+ profile[:email] = options[:email]
121
+ else
122
+ profile[:merchant_customer_id] = Digest::SHA1.hexdigest("#{creditcard.number}#{Time.now.to_i}").first(20)
123
+ end
124
+
125
+ create_customer_profile(:profile => profile)
126
+ end
127
+
128
+ # Update an existing payment profile
129
+ def update(billing_id, creditcard, options = {})
130
+ if (response = get_customer_profile(:customer_profile_id => billing_id)).success?
131
+ update_customer_payment_profile(
132
+ :customer_profile_id => billing_id,
133
+ :payment_profile => {
134
+ :customer_payment_profile_id => response.params['profile']['payment_profiles']['customer_payment_profile_id'],
135
+ :payment => {
136
+ :credit_card => creditcard
137
+ }
138
+ }.merge(options[:billing_address] ? {:bill_to => options[:billing_address]} : {})
139
+ )
140
+ else
141
+ response
142
+ end
143
+ end
144
+
145
+ # Run an auth and capture transaction against the stored CC
146
+ def purchase(money, billing_id)
147
+ if (response = get_customer_profile(:customer_profile_id => billing_id)).success?
148
+ create_customer_profile_transaction(:transaction => { :customer_profile_id => billing_id, :customer_payment_profile_id => response.params['profile']['payment_profiles']['customer_payment_profile_id'], :type => :auth_capture, :amount => amount(money) })
149
+ else
150
+ response
151
+ end
152
+ end
153
+
154
+ # Destroy a customer profile
155
+ def unstore(billing_id)
156
+ delete_customer_profile(:customer_profile_id => billing_id)
157
+ end
158
+
159
+ # Creates a new customer profile along with any customer payment profiles and customer shipping addresses
160
+ # for the customer profile.
161
+ #
162
+ # Returns a Response with the Customer Profile ID of the new customer profile in the authorization field.
163
+ # It is *CRITICAL* that you save this ID. There is no way to retrieve this through the API. You will not
164
+ # be able to create another Customer Profile with the same information.
165
+ #
166
+ # ==== Options
167
+ #
168
+ # TODO
169
+ def create_customer_profile(options)
170
+ # TODO Add requires
171
+ request = build_request(:create_customer_profile, options)
172
+ commit(:create_customer_profile, request)
173
+ end
174
+
175
+ # Creates a new customer payment profile for an existing customer profile.
176
+ #
177
+ # ==== Options
178
+ #
179
+ # * <tt>:customer_profile_id</tt> -- The Customer Profile ID of the customer the payment profile will be added to. (REQUIRED)
180
+ # * <tt>:payment_profile</tt> -- A hash containing the elements of the new payment profile (REQUIRED)
181
+ #
182
+ # ==== Payment Profile
183
+ #
184
+ # * <tt>:payment</tt> -- A hash containing information on payment. Either :credit_card or :bank_account (REQUIRED)
185
+ def create_customer_payment_profile(options)
186
+ requires!(options, :customer_profile_id)
187
+ requires!(options, :payment_profile)
188
+ requires!(options[:payment_profile], :payment)
189
+
190
+ request = build_request(:create_customer_payment_profile, options)
191
+ commit(:create_customer_payment_profile, request)
192
+ end
193
+
194
+ # Creates a new customer shipping address for an existing customer profile.
195
+ #
196
+ # ==== Options
197
+ #
198
+ # * <tt>:customer_profile_id</tt> -- The Customer Profile ID of the customer the payment profile will be added to. (REQUIRED)
199
+ # * <tt>:address</tt> -- A hash containing the elements of the shipping address (REQUIRED)
200
+ def create_customer_shipping_address(options)
201
+ requires!(options, :customer_profile_id)
202
+ requires!(options, :address)
203
+
204
+ request = build_request(:create_customer_shipping_address, options)
205
+ commit(:create_customer_shipping_address, request)
206
+ end
207
+
208
+ # Deletes an existing customer profile along with all associated customer payment profiles and customer shipping addresses.
209
+ #
210
+ # ==== Options
211
+ #
212
+ # * <tt>:customer_profile_id</tt> -- The Customer Profile ID of the customer to be deleted. (REQUIRED)
213
+ def delete_customer_profile(options)
214
+ requires!(options, :customer_profile_id)
215
+
216
+ request = build_request(:delete_customer_profile, options)
217
+ commit(:delete_customer_profile, request)
218
+ end
219
+
220
+ # Deletes a customer payment profile from an existing customer profile.
221
+ #
222
+ # ==== Options
223
+ #
224
+ # * <tt>:customer_profile_id</tt> -- The Customer Profile ID of the customer with the payment profile to be deleted. (REQUIRED)
225
+ # * <tt>:customer_payment_profile_id</tt> -- The Payment Profile ID of the payment profile to be deleted. (REQUIRED)
226
+ def delete_customer_payment_profile(options)
227
+ requires!(options, :customer_profile_id)
228
+ requires!(options, :customer_payment_profile_id)
229
+
230
+ request = build_request(:delete_customer_payment_profile, options)
231
+ commit(:delete_customer_payment_profile, request)
232
+ end
233
+
234
+ # Deletes a customer shipping address from an existing customer profile.
235
+ #
236
+ # ==== Options
237
+ #
238
+ # * <tt>:customer_profile_id</tt> -- The Customer Profile ID of the customer with the payment profile to be deleted. (REQUIRED)
239
+ # * <tt>:customer_address_id</tt> -- The Shipping Address ID of the shipping address to be deleted. (REQUIRED)
240
+ def delete_customer_shipping_address(options)
241
+ requires!(options, :customer_profile_id)
242
+ requires!(options, :customer_address_id)
243
+
244
+ request = build_request(:delete_customer_shipping_address, options)
245
+ commit(:delete_customer_shipping_address, request)
246
+ end
247
+
248
+ # Retrieves an existing customer profile along with all the associated customer payment profiles and customer shipping addresses.
249
+ #
250
+ # Returns a Response whose params hash contains all the profile information.
251
+ #
252
+ # ==== Options
253
+ #
254
+ # * <tt>:customer_profile_id</tt> -- The Customer Profile ID of the customer to retrieve. (REQUIRED)
255
+ def get_customer_profile(options)
256
+ requires!(options, :customer_profile_id)
257
+
258
+ request = build_request(:get_customer_profile, options)
259
+ commit(:get_customer_profile, request)
260
+ end
261
+
262
+ # Retrieves a list of all Customer Profile IDs from the gateway
263
+ #
264
+ # The response's params["ids"] contains the list of Customer Profile IDs
265
+ #
266
+ # ==== Options - none
267
+ #
268
+ def get_customer_profile_ids
269
+ request = build_request(:get_customer_profile_ids)
270
+ commit(:get_customer_profile_ids, request)
271
+ end
272
+
273
+ # Retrieve a customer payment profile for an existing customer profile.
274
+ #
275
+ # Returns a Response whose params hash contains all the payment profile information. Sensitive information such as credit card
276
+ # numbers will be masked.
277
+ #
278
+ # ==== Options
279
+ #
280
+ # * <tt>:customer_profile_id</tt> -- The Customer Profile ID of the customer with the payment profile to be retrieved. (REQUIRED)
281
+ # * <tt>:customer_payment_profile_id</tt> -- The Payment Profile ID of the payment profile to be retrieved. (REQUIRED)
282
+ def get_customer_payment_profile(options)
283
+ requires!(options, :customer_profile_id)
284
+ requires!(options, :customer_payment_profile_id)
285
+
286
+ request = build_request(:get_customer_payment_profile, options)
287
+ commit(:get_customer_payment_profile, request)
288
+ end
289
+
290
+ # Retrieve a customer shipping address for an existing customer profile.
291
+ #
292
+ # Returns a Response whose params hash contains all the shipping address information.
293
+ #
294
+ # ==== Options
295
+ #
296
+ # * <tt>:customer_profile_id</tt> -- The Customer Profile ID of the customer with the payment profile to be retrieved. (REQUIRED)
297
+ # * <tt>:customer_address_id</tt> -- The Shipping Address ID of the shipping address to be retrieved. (REQUIRED)
298
+ def get_customer_shipping_address(options)
299
+ requires!(options, :customer_profile_id)
300
+ requires!(options, :customer_address_id)
301
+
302
+ request = build_request(:get_customer_shipping_address, options)
303
+ commit(:get_customer_shipping_address, request)
304
+ end
305
+
306
+ # Updates an existing customer profile.
307
+ #
308
+ # Warning: if you do not provide a parameter in the <tt>:payment_profile</tt> hash, it is automatically set to nil at
309
+ # Authorize.Net. You will most likely want to first get the profile hash using get_customer_profile and then only change the
310
+ # elements you wish to change.
311
+ #
312
+ # ==== Options
313
+ #
314
+ # * <tt>:profile</tt> -- A hash containing the values the Customer Profile should be updated to. (REQUIRED)
315
+ #
316
+ # ==== Profile
317
+ #
318
+ # * <tt>:customer_profile_id</tt> -- The Customer Profile ID of the customer profile to update. (REQUIRED)
319
+ def update_customer_profile(options)
320
+ requires!(options, :profile)
321
+ requires!(options[:profile], :customer_profile_id)
322
+
323
+ request = build_request(:update_customer_profile, options)
324
+ commit(:update_customer_profile, request)
325
+ end
326
+
327
+ # Updates a customer payment profile for an existing customer profile.
328
+ #
329
+ # Warning: if you do not provide a parameter in the <tt>:payment_profile</tt> hash, it is automatically set to nil at
330
+ # Authorize.Net. You will most likely want to first get the profile hash using get_customer_payment_profile and then only
331
+ # change the elements you wish to change.
332
+ #
333
+ # ==== Options
334
+ #
335
+ # * <tt>:customer_profile_id</tt> -- The Customer Profile ID of the customer with the payment profile to be updated. (REQUIRED)
336
+ # * <tt>:payment_profile</tt> -- A hash containing the values the Customer Payment Profile should be updated to. (REQUIRED)
337
+ #
338
+ # ==== Payment Profile
339
+ #
340
+ # * <tt>:customer_payment_profile_id</tt> -- The Customer Payment Profile ID of the Customer Payment Profile to update. (REQUIRED)
341
+ def update_customer_payment_profile(options)
342
+ requires!(options, :customer_profile_id, :payment_profile)
343
+ requires!(options[:payment_profile], :customer_payment_profile_id)
344
+
345
+ request = build_request(:update_customer_payment_profile, options)
346
+ commit(:update_customer_payment_profile, request)
347
+ end
348
+
349
+ # Updates a customer shipping address for an existing customer profile.
350
+ #
351
+ # Warning: if you do not provide a parameter in the <tt>:address</tt> hash, it is automatically set to nil at
352
+ # Authorize.Net. You will most likely want to first get the profile hash using get_customer_shipping_address and then only
353
+ # change the elements you wish to change.
354
+ #
355
+ # ==== Options
356
+ #
357
+ # * <tt>:customer_profile_id</tt> -- The Customer Profile ID of the customer with the payment profile to be updated. (REQUIRED)
358
+ # * <tt>:address</tt> -- A hash containing the values the Customer Shipping Address should be updated to. (REQUIRED)
359
+ #
360
+ # ==== Address
361
+ #
362
+ # * <tt>:customer_address_id</tt> -- The Customer Address ID of the Customer Payment Profile to update. (REQUIRED)
363
+ def update_customer_shipping_address(options)
364
+ requires!(options, :customer_profile_id, :address)
365
+ requires!(options[:address], :customer_address_id)
366
+
367
+ request = build_request(:update_customer_shipping_address, options)
368
+ commit(:update_customer_shipping_address, request)
369
+ end
370
+
371
+ # Creates a new payment transaction from an existing customer profile
372
+ #
373
+ # This is what is used to charge a customer whose information you have stored in a Customer Profile.
374
+ #
375
+ # Returns a Response object that contains the result of the transaction in <tt>params['direct_response']</tt>
376
+ #
377
+ # ==== Options
378
+ #
379
+ # * <tt>:transaction</tt> -- A hash containing information on the transaction that is being requested. (REQUIRED)
380
+ #
381
+ # ==== Transaction
382
+ #
383
+ # * <tt>:type</tt> -- The type of transaction. Can be either <tt>:auth_only</tt>, <tt>:capture_only</tt>, or <tt>:auth_capture</tt>. (REQUIRED)
384
+ # * <tt>:amount</tt> -- The amount for the tranaction. Formatted with a decimal. For example "4.95" (REQUIRED)
385
+ # * <tt>:customer_profile_id</tt> -- The Customer Profile ID of the customer to use in this transaction. (REQUIRED)
386
+ # * <tt>:customer_payment_profile_id</tt> -- The Customer Payment Profile ID of the Customer Payment Profile to use in this transaction. (REQUIRED)
387
+ def create_customer_profile_transaction(options)
388
+ requires!(options, :transaction)
389
+ requires!(options[:transaction], :type, :amount, :customer_profile_id, :customer_payment_profile_id)
390
+
391
+ request = build_request(:create_customer_profile_transaction, options)
392
+ commit(:create_customer_profile_transaction, request)
393
+ end
394
+
395
+ # Verifies an existing customer payment profile by generating a test transaction
396
+ #
397
+ # Returns a Response object that contains the result of the transaction in <tt>params['direct_response']</tt>
398
+ #
399
+ # ==== Options
400
+ #
401
+ # * <tt>:customer_profile_id</tt> -- The Customer Profile ID of the customer to use in this transaction. (REQUIRED)
402
+ # * <tt>:customer_payment_profile_id</tt> -- The Customer Payment Profile ID of the Customer Payment Profile to be verified. (REQUIRED)
403
+ # * <tt>:customer_address_id</tt> -- The Customer Address ID of the Customer Shipping Address to be verified.
404
+ # * <tt>:validation_mode</tt> -- <tt>:live</tt> or <tt>:test</tt> In Test Mode, only field validation is performed.
405
+ # In Live Mode, a transaction is generated and submitted to the processor with the amount of $0.01. If successful, the transaction is immediately voided. (REQUIRED)
406
+ def validate_customer_payment_profile(options)
407
+ requires!(options, :customer_profile_id, :customer_payment_profile_id, :validation_mode)
408
+
409
+ request = build_request(:validate_customer_payment_profile, options)
410
+ commit(:validate_customer_payment_profile, request)
411
+ end
412
+
413
+ private
414
+
415
+ def expdate(credit_card)
416
+ sprintf('%04d-%02d', credit_card.year, credit_card.month)
417
+ end
418
+
419
+ def build_request(action, options = {})
420
+ unless CIM_ACTIONS.include?(action)
421
+ raise StandardError, "Invalid Customer Information Manager Action: #{action}"
422
+ end
423
+
424
+ xml = Builder::XmlMarkup.new(:indent => 2)
425
+ xml.instruct!(:xml, :version => '1.0', :encoding => 'utf-8')
426
+ xml.tag!("#{CIM_ACTIONS[action]}Request", :xmlns => AUTHORIZE_NET_CIM_NAMESPACE) do
427
+ add_merchant_authentication(xml)
428
+ # Merchant-assigned reference ID for the request
429
+ xml.tag!('refId', options[:ref_id]) if options[:ref_id]
430
+ send("build_#{action}_request", xml, options)
431
+ end
432
+ end
433
+
434
+ # Contains the merchant’s payment gateway account authentication information
435
+ def add_merchant_authentication(xml)
436
+ xml.tag!('merchantAuthentication') do
437
+ xml.tag!('name', @options[:login])
438
+ xml.tag!('transactionKey', @options[:password])
439
+ end
440
+ end
441
+
442
+ def build_create_customer_profile_request(xml, options)
443
+ add_profile(xml, options[:profile])
444
+
445
+ xml.target!
446
+ end
447
+
448
+ def build_create_customer_payment_profile_request(xml, options)
449
+ xml.tag!('customerProfileId', options[:customer_profile_id])
450
+
451
+ xml.tag!('paymentProfile') do
452
+ add_payment_profile(xml, options[:payment_profile])
453
+ end
454
+
455
+ xml.tag!('validationMode', CIM_VALIDATION_MODES[options[:validation_mode]]) if options[:validation_mode]
456
+
457
+ xml.target!
458
+ end
459
+
460
+ def build_create_customer_shipping_address_request(xml, options)
461
+ xml.tag!('customerProfileId', options[:customer_profile_id])
462
+
463
+ xml.tag!('address') do
464
+ add_address(xml, options[:address])
465
+ end
466
+
467
+ xml.target!
468
+ end
469
+
470
+ def build_delete_customer_profile_request(xml, options)
471
+ xml.tag!('customerProfileId', options[:customer_profile_id])
472
+ xml.target!
473
+ end
474
+
475
+ def build_delete_customer_payment_profile_request(xml, options)
476
+ xml.tag!('customerProfileId', options[:customer_profile_id])
477
+ xml.tag!('customerPaymentProfileId', options[:customer_payment_profile_id])
478
+ xml.target!
479
+ end
480
+
481
+ def build_delete_customer_shipping_address_request(xml, options)
482
+ xml.tag!('customerProfileId', options[:customer_profile_id])
483
+ xml.tag!('customerAddressId', options[:customer_address_id])
484
+ xml.target!
485
+ end
486
+
487
+ def build_get_customer_profile_request(xml, options)
488
+ xml.tag!('customerProfileId', options[:customer_profile_id])
489
+ xml.target!
490
+ end
491
+
492
+ # The get customer profile IDs request does not need any additional XML
493
+ def build_get_customer_profile_ids_request(xml, options) end
494
+
495
+ def build_get_customer_payment_profile_request(xml, options)
496
+ xml.tag!('customerProfileId', options[:customer_profile_id])
497
+ xml.tag!('customerPaymentProfileId', options[:customer_payment_profile_id])
498
+ xml.target!
499
+ end
500
+
501
+ def build_get_customer_shipping_address_request(xml, options)
502
+ xml.tag!('customerProfileId', options[:customer_profile_id])
503
+ xml.tag!('customerAddressId', options[:customer_address_id])
504
+ xml.target!
505
+ end
506
+
507
+ def build_update_customer_profile_request(xml, options)
508
+ add_profile(xml, options[:profile], true)
509
+
510
+ xml.target!
511
+ end
512
+
513
+ def build_update_customer_payment_profile_request(xml, options)
514
+ xml.tag!('customerProfileId', options[:customer_profile_id])
515
+
516
+ xml.tag!('paymentProfile') do
517
+ add_payment_profile(xml, options[:payment_profile])
518
+ end
519
+
520
+ xml.target!
521
+ end
522
+
523
+ def build_update_customer_shipping_address_request(xml, options)
524
+ xml.tag!('customerProfileId', options[:customer_profile_id])
525
+
526
+ xml.tag!('address') do
527
+ add_address(xml, options[:address])
528
+ end
529
+
530
+ xml.target!
531
+ end
532
+
533
+ def build_create_customer_profile_transaction_request(xml, options)
534
+ add_transaction(xml, options[:transaction])
535
+ xml.tag!('extraOptions', "x_test_request=TRUE") if @options[:test]
536
+
537
+ xml.target!
538
+ end
539
+
540
+ def build_validate_customer_payment_profile_request(xml, options)
541
+ xml.tag!('customerProfileId', options[:customer_profile_id])
542
+ xml.tag!('customerPaymentProfileId', options[:customer_payment_profile_id])
543
+ xml.tag!('customerShippingAddressId', options[:customer_address_id]) if options[:customer_address_id]
544
+ xml.tag!('validationMode', CIM_VALIDATION_MODES[options[:validation_mode]]) if options[:validation_mode]
545
+
546
+ xml.target!
547
+ end
548
+
549
+ # :merchant_customer_id (Optional)
550
+ # :description (Optional)
551
+ # :email (Optional)
552
+ # :payment_profiles (Optional)
553
+ def add_profile(xml, profile, update = false)
554
+ xml.tag!('profile') do
555
+ # Merchant assigned ID for the customer. Up to 20 characters. (optional)
556
+ xml.tag!('merchantCustomerId', profile[:merchant_customer_id]) if profile[:merchant_customer_id]
557
+ # Description of the customer. Up to 255 Characters (optional)
558
+ xml.tag!('description', profile[:description]) if profile[:description]
559
+ # Email Address for the customer. Up to 255 Characters (optional)
560
+ xml.tag!('email', profile[:email]) if profile[:email]
561
+
562
+ if update
563
+ xml.tag!('customerProfileId', profile[:customer_profile_id])
564
+ else
565
+ add_payment_profiles(xml, profile[:payment_profiles]) if profile[:payment_profiles]
566
+ add_ship_to_list(xml, profile[:ship_to_list]) if profile[:ship_to_list]
567
+ end
568
+ end
569
+ end
570
+
571
+ def add_transaction(xml, transaction)
572
+ unless CIM_TRANSACTION_TYPES.include?(transaction[:type])
573
+ raise StandardError, "Invalid Customer Information Manager Transaction Type: #{transaction[:type]}"
574
+ end
575
+
576
+ xml.tag!('transaction') do
577
+ xml.tag!(CIM_TRANSACTION_TYPES[transaction[:type]]) do
578
+ # The amount to be billed to the customer
579
+ xml.tag!('amount', transaction[:amount])
580
+ xml.tag!('customerProfileId', transaction[:customer_profile_id])
581
+ xml.tag!('customerPaymentProfileId', transaction[:customer_payment_profile_id])
582
+ xml.tag!('approvalCode', transaction[:approval_code]) if transaction[:type] == :capture_only
583
+ add_order(xml, transaction[:order]) if transaction[:order]
584
+ end
585
+ end
586
+ xml.tag!('extraOptions') do
587
+ xml.cdata!("x_customer_ip=#{transaction[:customer_ip]}") if transaction[:customer_ip]
588
+ end
589
+ end
590
+
591
+ def add_order(xml, order)
592
+ xml.tag!('order') do
593
+ xml.tag!('invoiceNumber', order[:invoice_number]) if order[:invoice_number]
594
+ xml.tag!('description', order[:description]) if order[:description]
595
+ xml.tag!('purchaseOrderNumber', order[:purchase_order_number]) if order[:purchase_order_number]
596
+ end
597
+ end
598
+
599
+ def add_payment_profiles(xml, payment_profiles)
600
+ xml.tag!('paymentProfiles') do
601
+ add_payment_profile(xml, payment_profiles)
602
+ end
603
+ end
604
+
605
+ # :customer_type => 'individual or business', # Optional
606
+ # :bill_to => @address,
607
+ # :payment => @payment
608
+ def add_payment_profile(xml, payment_profile)
609
+ # 'individual' or 'business' (optional)
610
+ xml.tag!('customerType', payment_profile[:customer_type]) if payment_profile[:customer_type]
611
+
612
+ if payment_profile[:bill_to]
613
+ xml.tag!('billTo') do
614
+ add_address(xml, payment_profile[:bill_to])
615
+ end
616
+ end
617
+
618
+ if payment_profile[:payment]
619
+ xml.tag!('payment') do
620
+ add_credit_card(xml, payment_profile[:payment][:credit_card]) if payment_profile[:payment].has_key?(:credit_card)
621
+ add_bank_account(xml, payment_profile[:payment][:bank_account]) if payment_profile[:payment].has_key?(:bank_account)
622
+ add_drivers_license(xml, payment_profile[:payment][:drivers_license]) if payment_profile[:payment].has_key?(:drivers_license)
623
+ # This element is only required for Wells Fargo SecureSource eCheck.Net merchants
624
+ # The customer's Social Security Number or Tax ID
625
+ xml.tag!('taxId', payment_profile[:payment]) if payment_profile[:payment].has_key?(:tax_id)
626
+ end
627
+ end
628
+
629
+ xml.tag!('customerPaymentProfileId', payment_profile[:customer_payment_profile_id]) if payment_profile[:customer_payment_profile_id]
630
+ end
631
+
632
+ def add_ship_to_list(xml, ship_to_list)
633
+ xml.tag!('shipToList') do
634
+ add_address(xml, ship_to_list)
635
+ end
636
+ end
637
+
638
+ def add_address(xml, address)
639
+ xml.tag!('firstName', address[:first_name])
640
+ xml.tag!('lastName', address[:last_name])
641
+ xml.tag!('company', address[:company])
642
+ xml.tag!('address', address[:address1]) if address[:address1]
643
+ xml.tag!('address', address[:address]) if address[:address]
644
+ xml.tag!('city', address[:city])
645
+ xml.tag!('state', address[:state])
646
+ xml.tag!('zip', address[:zip])
647
+ xml.tag!('country', address[:country])
648
+ xml.tag!('phoneNumber', address[:phone_number]) if address[:phone_number]
649
+ xml.tag!('faxNumber', address[:fax_number]) if address[:fax_number]
650
+
651
+ xml.tag!('customerAddressId', address[:customer_address_id]) if address[:customer_address_id]
652
+ end
653
+
654
+ # Adds customer’s credit card information
655
+ # Note: This element should only be included
656
+ # when the payment method is credit card.
657
+ def add_credit_card(xml, credit_card)
658
+ return unless credit_card
659
+ xml.tag!('creditCard') do
660
+ # The credit card number used for payment of the subscription
661
+ xml.tag!('cardNumber', credit_card.number)
662
+ # The expiration date of the credit card used for the subscription
663
+ xml.tag!('expirationDate', expdate(credit_card))
664
+ xml.tag!('cardCode', credit_card.verification_value) if credit_card.verification_value?
665
+ end
666
+ end
667
+
668
+ # Adds customer’s bank account information
669
+ # Note: This element should only be included
670
+ # when the payment method is bank account.
671
+ def add_bank_account(xml, bank_account)
672
+ raise StandardError, "Invalid Bank Account Type: #{bank_account[:account_type]}" unless BANK_ACCOUNT_TYPES.include?(bank_account[:account_type])
673
+ raise StandardError, "Invalid eCheck Type: #{bank_account[:echeck_type]}" unless ECHECK_TYPES.include?(bank_account[:echeck_type])
674
+
675
+ xml.tag!('bankAccount') do
676
+ # The type of bank account
677
+ xml.tag!('accountType', BANK_ACCOUNT_TYPES[bank_account[:account_type]])
678
+ # The routing number of the customer’s bank
679
+ xml.tag!('routingNumber', bank_account[:routing_number])
680
+ # The bank account number
681
+ xml.tag!('accountNumber', bank_account[:account_number])
682
+ # The full name of the individual associated
683
+ # with the bank account number
684
+ xml.tag!('nameOnAccount', bank_account[:name_on_account])
685
+ # The type of electronic check transaction
686
+ xml.tag!('echeckType', ECHECK_TYPES[bank_account[:echeck_type]])
687
+ # The full name of the individual associated
688
+ # with the bank account number (optional)
689
+ xml.tag!('bankName', bank_account[:bank_name]) if bank_account[:bank_name]
690
+ end
691
+ end
692
+
693
+ # Adds customer’s driver's license information
694
+ # Note: This element is only required for
695
+ # Wells Fargo SecureSource eCheck.Net merchants
696
+ def add_drivers_license(xml, drivers_license)
697
+ xml.tag!('driversLicense') do
698
+ # The state of the customer's driver's license
699
+ # A valid two character state code
700
+ xml.tag!('state', drivers_license[:state])
701
+ # The customer’s driver's license number
702
+ xml.tag!('number', drivers_license[:number])
703
+ # The date of birth listed on the customer's driver's license
704
+ # YYYY-MM-DD
705
+ xml.tag!('dateOfBirth', drivers_license[:date_of_birth])
706
+ end
707
+ end
708
+
709
+ def commit(action, request)
710
+ url = test? ? test_url : live_url
711
+ xml = ssl_post(url, request, "Content-Type" => "text/xml")
712
+
713
+ response_params = parse(action, xml)
714
+
715
+ message = response_params['messages']['message']['text']
716
+ test_mode = test? || message =~ /Test Mode/
717
+ success = response_params['messages']['result_code'] == 'Ok'
718
+
719
+ response = Response.new(success, message, response_params,
720
+ :test => test_mode,
721
+ :authorization => response_params['customer_profile_id'] || (response_params['profile'] ? response_params['profile']['customer_profile_id'] : nil)
722
+ )
723
+
724
+ response.params['direct_response'] = parse_direct_response(response) if response.params['direct_response']
725
+ response
726
+ end
727
+
728
+ def parse_direct_response(response)
729
+ direct_response = {'raw' => response.params['direct_response']}
730
+ direct_response_fields = response.params['direct_response'].split(',')
731
+
732
+ direct_response.merge(
733
+ {
734
+ 'response_code' => direct_response_fields[0],
735
+ 'response_subcode' => direct_response_fields[1],
736
+ 'response_reason_code' => direct_response_fields[2],
737
+ 'message' => direct_response_fields[3],
738
+ 'approval_code' => direct_response_fields[4],
739
+ 'avs_response' => direct_response_fields[5],
740
+ 'transaction_id' => direct_response_fields[6],
741
+ 'invoice_number' => direct_response_fields[7],
742
+ 'order_description' => direct_response_fields[8],
743
+ 'amount' => direct_response_fields[9],
744
+ 'method' => direct_response_fields[10],
745
+ 'transaction_type' => direct_response_fields[11],
746
+ 'customer_id' => direct_response_fields[12],
747
+ 'first_name' => direct_response_fields[13],
748
+ 'last_name' => direct_response_fields[14],
749
+ 'company' => direct_response_fields[15],
750
+ 'address' => direct_response_fields[16],
751
+ 'city' => direct_response_fields[17],
752
+ 'state' => direct_response_fields[18],
753
+ 'zip_code' => direct_response_fields[19],
754
+ 'country' => direct_response_fields[20],
755
+ 'phone' => direct_response_fields[21],
756
+ 'fax' => direct_response_fields[22],
757
+ 'email_address' => direct_response_fields[23],
758
+ 'ship_to_first_name' => direct_response_fields[24],
759
+ 'ship_to_last_name' => direct_response_fields[25],
760
+ 'ship_to_company' => direct_response_fields[26],
761
+ 'ship_to_address' => direct_response_fields[27],
762
+ 'ship_to_city' => direct_response_fields[28],
763
+ 'ship_to_state' => direct_response_fields[29],
764
+ 'ship_to_zip_code' => direct_response_fields[30],
765
+ 'ship_to_country' => direct_response_fields[31],
766
+ 'tax' => direct_response_fields[32],
767
+ 'duty' => direct_response_fields[33],
768
+ 'freight' => direct_response_fields[34],
769
+ 'tax_exempt' => direct_response_fields[35],
770
+ 'purchase_order_number' => direct_response_fields[36],
771
+ 'md5_hash' => direct_response_fields[37],
772
+ 'card_code' => direct_response_fields[38],
773
+ 'cardholder_authentication_verification_response' => direct_response_fields[39]
774
+ }
775
+ )
776
+ end
777
+
778
+ def parse(action, xml)
779
+ xml = REXML::Document.new(xml)
780
+ root = REXML::XPath.first(xml, "//#{CIM_ACTIONS[action]}Response") ||
781
+ REXML::XPath.first(xml, "//ErrorResponse")
782
+ if root
783
+ response = parse_element(root)
784
+ end
785
+
786
+ response
787
+ end
788
+
789
+ def parse_element(node)
790
+ if node.has_elements?
791
+ response = {}
792
+ node.elements.each{ |e|
793
+ key = e.name.underscore
794
+ value = parse_element(e)
795
+ if response.has_key?(key)
796
+ if response[key].is_a?(Array)
797
+ response[key].push(value)
798
+ else
799
+ response[key] = [response[key], value]
800
+ end
801
+ else
802
+ response[key] = parse_element(e)
803
+ end
804
+ }
805
+ else
806
+ response = node.text
807
+ end
808
+
809
+ response
810
+ end
811
+ end
812
+ end
813
+ end