activemerchant-nsp 1.27.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (252) hide show
  1. data/CHANGELOG +952 -0
  2. data/CONTRIBUTORS +347 -0
  3. data/MIT-LICENSE +20 -0
  4. data/README.md +204 -0
  5. data/gem-public_cert.pem +20 -0
  6. data/lib/active_merchant.rb +63 -0
  7. data/lib/active_merchant/billing.rb +9 -0
  8. data/lib/active_merchant/billing/avs_result.rb +98 -0
  9. data/lib/active_merchant/billing/base.rb +56 -0
  10. data/lib/active_merchant/billing/check.rb +68 -0
  11. data/lib/active_merchant/billing/credit_card.rb +274 -0
  12. data/lib/active_merchant/billing/credit_card_formatting.rb +21 -0
  13. data/lib/active_merchant/billing/credit_card_methods.rb +143 -0
  14. data/lib/active_merchant/billing/cvv_result.rb +38 -0
  15. data/lib/active_merchant/billing/expiry_date.rb +34 -0
  16. data/lib/active_merchant/billing/gateway.rb +176 -0
  17. data/lib/active_merchant/billing/gateways.rb +18 -0
  18. data/lib/active_merchant/billing/gateways/authorize_net.rb +695 -0
  19. data/lib/active_merchant/billing/gateways/authorize_net_cim.rb +943 -0
  20. data/lib/active_merchant/billing/gateways/balanced.rb +462 -0
  21. data/lib/active_merchant/billing/gateways/barclays_epdq.rb +308 -0
  22. data/lib/active_merchant/billing/gateways/beanstream.rb +167 -0
  23. data/lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb +389 -0
  24. data/lib/active_merchant/billing/gateways/beanstream_interac.rb +54 -0
  25. data/lib/active_merchant/billing/gateways/blue_pay.rb +492 -0
  26. data/lib/active_merchant/billing/gateways/bogus.rb +142 -0
  27. data/lib/active_merchant/billing/gateways/braintree.rb +19 -0
  28. data/lib/active_merchant/billing/gateways/braintree/braintree_common.rb +9 -0
  29. data/lib/active_merchant/billing/gateways/braintree_blue.rb +389 -0
  30. data/lib/active_merchant/billing/gateways/braintree_orange.rb +19 -0
  31. data/lib/active_merchant/billing/gateways/card_save.rb +23 -0
  32. data/lib/active_merchant/billing/gateways/card_stream.rb +230 -0
  33. data/lib/active_merchant/billing/gateways/certo_direct.rb +278 -0
  34. data/lib/active_merchant/billing/gateways/cyber_source.rb +576 -0
  35. data/lib/active_merchant/billing/gateways/data_cash.rb +597 -0
  36. data/lib/active_merchant/billing/gateways/efsnet.rb +235 -0
  37. data/lib/active_merchant/billing/gateways/elavon.rb +137 -0
  38. data/lib/active_merchant/billing/gateways/epay.rb +276 -0
  39. data/lib/active_merchant/billing/gateways/eway.rb +287 -0
  40. data/lib/active_merchant/billing/gateways/eway_managed.rb +265 -0
  41. data/lib/active_merchant/billing/gateways/exact.rb +227 -0
  42. data/lib/active_merchant/billing/gateways/fat_zebra.rb +152 -0
  43. data/lib/active_merchant/billing/gateways/federated_canada.rb +168 -0
  44. data/lib/active_merchant/billing/gateways/first_pay.rb +177 -0
  45. data/lib/active_merchant/billing/gateways/garanti.rb +262 -0
  46. data/lib/active_merchant/billing/gateways/ideal/ideal_base.rb +252 -0
  47. data/lib/active_merchant/billing/gateways/ideal/ideal_rabobank.pem +13 -0
  48. data/lib/active_merchant/billing/gateways/ideal/ideal_response.rb +29 -0
  49. data/lib/active_merchant/billing/gateways/ideal_rabobank.rb +55 -0
  50. data/lib/active_merchant/billing/gateways/inspire.rb +221 -0
  51. data/lib/active_merchant/billing/gateways/instapay.rb +164 -0
  52. data/lib/active_merchant/billing/gateways/iridium.rb +257 -0
  53. data/lib/active_merchant/billing/gateways/itransact.rb +450 -0
  54. data/lib/active_merchant/billing/gateways/jetpay.rb +276 -0
  55. data/lib/active_merchant/billing/gateways/linkpoint.rb +451 -0
  56. data/lib/active_merchant/billing/gateways/litle.rb +290 -0
  57. data/lib/active_merchant/billing/gateways/merchant_e_solutions.rb +157 -0
  58. data/lib/active_merchant/billing/gateways/merchant_ware.rb +289 -0
  59. data/lib/active_merchant/billing/gateways/metrics_global.rb +323 -0
  60. data/lib/active_merchant/billing/gateways/migs.rb +263 -0
  61. data/lib/active_merchant/billing/gateways/migs/migs_codes.rb +100 -0
  62. data/lib/active_merchant/billing/gateways/modern_payments.rb +38 -0
  63. data/lib/active_merchant/billing/gateways/modern_payments_cim.rb +220 -0
  64. data/lib/active_merchant/billing/gateways/moneris.rb +250 -0
  65. data/lib/active_merchant/billing/gateways/moneris_us.rb +211 -0
  66. data/lib/active_merchant/billing/gateways/nab_transact.rb +257 -0
  67. data/lib/active_merchant/billing/gateways/net_registry.rb +189 -0
  68. data/lib/active_merchant/billing/gateways/netaxept.rb +239 -0
  69. data/lib/active_merchant/billing/gateways/netbilling.rb +196 -0
  70. data/lib/active_merchant/billing/gateways/nmi.rb +13 -0
  71. data/lib/active_merchant/billing/gateways/ogone.rb +427 -0
  72. data/lib/active_merchant/billing/gateways/optimal_payment.rb +277 -0
  73. data/lib/active_merchant/billing/gateways/orbital.rb +351 -0
  74. data/lib/active_merchant/billing/gateways/orbital/orbital_soft_descriptors.rb +46 -0
  75. data/lib/active_merchant/billing/gateways/pay_gate_xml.rb +266 -0
  76. data/lib/active_merchant/billing/gateways/pay_junction.rb +397 -0
  77. data/lib/active_merchant/billing/gateways/pay_secure.rb +120 -0
  78. data/lib/active_merchant/billing/gateways/paybox_direct.rb +201 -0
  79. data/lib/active_merchant/billing/gateways/payflow.rb +268 -0
  80. data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +212 -0
  81. data/lib/active_merchant/billing/gateways/payflow/payflow_express_response.rb +39 -0
  82. data/lib/active_merchant/billing/gateways/payflow/payflow_response.rb +13 -0
  83. data/lib/active_merchant/billing/gateways/payflow_express.rb +224 -0
  84. data/lib/active_merchant/billing/gateways/payflow_express_uk.rb +15 -0
  85. data/lib/active_merchant/billing/gateways/payflow_uk.rb +21 -0
  86. data/lib/active_merchant/billing/gateways/payment_express.rb +282 -0
  87. data/lib/active_merchant/billing/gateways/paypal.rb +106 -0
  88. data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +653 -0
  89. data/lib/active_merchant/billing/gateways/paypal/paypal_express_response.rb +49 -0
  90. data/lib/active_merchant/billing/gateways/paypal/paypal_recurring_api.rb +245 -0
  91. data/lib/active_merchant/billing/gateways/paypal_ca.rb +13 -0
  92. data/lib/active_merchant/billing/gateways/paypal_digital_goods.rb +43 -0
  93. data/lib/active_merchant/billing/gateways/paypal_express.rb +178 -0
  94. data/lib/active_merchant/billing/gateways/paypal_express_common.rb +30 -0
  95. data/lib/active_merchant/billing/gateways/paystation.rb +201 -0
  96. data/lib/active_merchant/billing/gateways/payway.rb +214 -0
  97. data/lib/active_merchant/billing/gateways/plugnpay.rb +295 -0
  98. data/lib/active_merchant/billing/gateways/psigate.rb +219 -0
  99. data/lib/active_merchant/billing/gateways/psl_card.rb +304 -0
  100. data/lib/active_merchant/billing/gateways/qbms.rb +297 -0
  101. data/lib/active_merchant/billing/gateways/quantum.rb +282 -0
  102. data/lib/active_merchant/billing/gateways/quickpay.rb +298 -0
  103. data/lib/active_merchant/billing/gateways/realex.rb +313 -0
  104. data/lib/active_merchant/billing/gateways/sage.rb +148 -0
  105. data/lib/active_merchant/billing/gateways/sage/sage_bankcard.rb +88 -0
  106. data/lib/active_merchant/billing/gateways/sage/sage_core.rb +115 -0
  107. data/lib/active_merchant/billing/gateways/sage/sage_virtual_check.rb +97 -0
  108. data/lib/active_merchant/billing/gateways/sage_pay.rb +322 -0
  109. data/lib/active_merchant/billing/gateways/sallie_mae.rb +144 -0
  110. data/lib/active_merchant/billing/gateways/samurai.rb +121 -0
  111. data/lib/active_merchant/billing/gateways/secure_net.rb +330 -0
  112. data/lib/active_merchant/billing/gateways/secure_pay.rb +31 -0
  113. data/lib/active_merchant/billing/gateways/secure_pay_au.rb +284 -0
  114. data/lib/active_merchant/billing/gateways/secure_pay_tech.rb +113 -0
  115. data/lib/active_merchant/billing/gateways/skip_jack.rb +458 -0
  116. data/lib/active_merchant/billing/gateways/smart_ps.rb +273 -0
  117. data/lib/active_merchant/billing/gateways/stripe.rb +236 -0
  118. data/lib/active_merchant/billing/gateways/trans_first.rb +127 -0
  119. data/lib/active_merchant/billing/gateways/transax.rb +23 -0
  120. data/lib/active_merchant/billing/gateways/trust_commerce.rb +423 -0
  121. data/lib/active_merchant/billing/gateways/usa_epay.rb +25 -0
  122. data/lib/active_merchant/billing/gateways/usa_epay_advanced.rb +1497 -0
  123. data/lib/active_merchant/billing/gateways/usa_epay_transaction.rb +206 -0
  124. data/lib/active_merchant/billing/gateways/verifi.rb +233 -0
  125. data/lib/active_merchant/billing/gateways/viaklix.rb +194 -0
  126. data/lib/active_merchant/billing/gateways/vindicia.rb +359 -0
  127. data/lib/active_merchant/billing/gateways/wirecard.rb +313 -0
  128. data/lib/active_merchant/billing/gateways/worldpay.rb +271 -0
  129. data/lib/active_merchant/billing/integrations.rb +17 -0
  130. data/lib/active_merchant/billing/integrations/action_view_helper.rb +73 -0
  131. data/lib/active_merchant/billing/integrations/authorize_net_sim.rb +38 -0
  132. data/lib/active_merchant/billing/integrations/authorize_net_sim/helper.rb +228 -0
  133. data/lib/active_merchant/billing/integrations/authorize_net_sim/notification.rb +340 -0
  134. data/lib/active_merchant/billing/integrations/bogus.rb +23 -0
  135. data/lib/active_merchant/billing/integrations/bogus/helper.rb +17 -0
  136. data/lib/active_merchant/billing/integrations/bogus/notification.rb +11 -0
  137. data/lib/active_merchant/billing/integrations/bogus/return.rb +10 -0
  138. data/lib/active_merchant/billing/integrations/chronopay.rb +23 -0
  139. data/lib/active_merchant/billing/integrations/chronopay/helper.rb +120 -0
  140. data/lib/active_merchant/billing/integrations/chronopay/notification.rb +158 -0
  141. data/lib/active_merchant/billing/integrations/chronopay/return.rb +10 -0
  142. data/lib/active_merchant/billing/integrations/direc_pay.rb +41 -0
  143. data/lib/active_merchant/billing/integrations/direc_pay/helper.rb +200 -0
  144. data/lib/active_merchant/billing/integrations/direc_pay/notification.rb +76 -0
  145. data/lib/active_merchant/billing/integrations/direc_pay/return.rb +32 -0
  146. data/lib/active_merchant/billing/integrations/direc_pay/status.rb +37 -0
  147. data/lib/active_merchant/billing/integrations/directebanking.rb +47 -0
  148. data/lib/active_merchant/billing/integrations/directebanking/helper.rb +90 -0
  149. data/lib/active_merchant/billing/integrations/directebanking/notification.rb +120 -0
  150. data/lib/active_merchant/billing/integrations/directebanking/return.rb +11 -0
  151. data/lib/active_merchant/billing/integrations/dotpay.rb +22 -0
  152. data/lib/active_merchant/billing/integrations/dotpay/helper.rb +77 -0
  153. data/lib/active_merchant/billing/integrations/dotpay/notification.rb +86 -0
  154. data/lib/active_merchant/billing/integrations/dotpay/return.rb +11 -0
  155. data/lib/active_merchant/billing/integrations/dwolla.rb +30 -0
  156. data/lib/active_merchant/billing/integrations/dwolla/helper.rb +31 -0
  157. data/lib/active_merchant/billing/integrations/dwolla/notification.rb +55 -0
  158. data/lib/active_merchant/billing/integrations/dwolla/return.rb +38 -0
  159. data/lib/active_merchant/billing/integrations/e_payment_plans.rb +48 -0
  160. data/lib/active_merchant/billing/integrations/e_payment_plans/helper.rb +34 -0
  161. data/lib/active_merchant/billing/integrations/e_payment_plans/notification.rb +84 -0
  162. data/lib/active_merchant/billing/integrations/easy_pay.rb +30 -0
  163. data/lib/active_merchant/billing/integrations/easy_pay/common.rb +40 -0
  164. data/lib/active_merchant/billing/integrations/easy_pay/helper.rb +40 -0
  165. data/lib/active_merchant/billing/integrations/easy_pay/notification.rb +51 -0
  166. data/lib/active_merchant/billing/integrations/epay.rb +21 -0
  167. data/lib/active_merchant/billing/integrations/epay/helper.rb +55 -0
  168. data/lib/active_merchant/billing/integrations/epay/notification.rb +110 -0
  169. data/lib/active_merchant/billing/integrations/first_data.rb +38 -0
  170. data/lib/active_merchant/billing/integrations/first_data/helper.rb +63 -0
  171. data/lib/active_merchant/billing/integrations/first_data/notification.rb +56 -0
  172. data/lib/active_merchant/billing/integrations/gestpay.rb +25 -0
  173. data/lib/active_merchant/billing/integrations/gestpay/common.rb +42 -0
  174. data/lib/active_merchant/billing/integrations/gestpay/helper.rb +70 -0
  175. data/lib/active_merchant/billing/integrations/gestpay/notification.rb +85 -0
  176. data/lib/active_merchant/billing/integrations/gestpay/return.rb +10 -0
  177. data/lib/active_merchant/billing/integrations/helper.rb +117 -0
  178. data/lib/active_merchant/billing/integrations/hi_trust.rb +27 -0
  179. data/lib/active_merchant/billing/integrations/hi_trust/helper.rb +58 -0
  180. data/lib/active_merchant/billing/integrations/hi_trust/notification.rb +59 -0
  181. data/lib/active_merchant/billing/integrations/hi_trust/return.rb +67 -0
  182. data/lib/active_merchant/billing/integrations/maksuturva.rb +86 -0
  183. data/lib/active_merchant/billing/integrations/maksuturva/helper.rb +119 -0
  184. data/lib/active_merchant/billing/integrations/maksuturva/notification.rb +48 -0
  185. data/lib/active_merchant/billing/integrations/moneybookers.rb +26 -0
  186. data/lib/active_merchant/billing/integrations/moneybookers/helper.rb +59 -0
  187. data/lib/active_merchant/billing/integrations/moneybookers/notification.rb +129 -0
  188. data/lib/active_merchant/billing/integrations/nelnet.rb +40 -0
  189. data/lib/active_merchant/billing/integrations/nelnet/helper.rb +34 -0
  190. data/lib/active_merchant/billing/integrations/nelnet/notification.rb +100 -0
  191. data/lib/active_merchant/billing/integrations/nochex.rb +88 -0
  192. data/lib/active_merchant/billing/integrations/nochex/helper.rb +68 -0
  193. data/lib/active_merchant/billing/integrations/nochex/notification.rb +94 -0
  194. data/lib/active_merchant/billing/integrations/nochex/return.rb +10 -0
  195. data/lib/active_merchant/billing/integrations/notification.rb +62 -0
  196. data/lib/active_merchant/billing/integrations/paxum.rb +44 -0
  197. data/lib/active_merchant/billing/integrations/paxum/common.rb +24 -0
  198. data/lib/active_merchant/billing/integrations/paxum/helper.rb +42 -0
  199. data/lib/active_merchant/billing/integrations/paxum/notification.rb +33 -0
  200. data/lib/active_merchant/billing/integrations/payflow_link.rb +21 -0
  201. data/lib/active_merchant/billing/integrations/payflow_link/helper.rb +100 -0
  202. data/lib/active_merchant/billing/integrations/payflow_link/notification.rb +78 -0
  203. data/lib/active_merchant/billing/integrations/paypal.rb +39 -0
  204. data/lib/active_merchant/billing/integrations/paypal/helper.rb +119 -0
  205. data/lib/active_merchant/billing/integrations/paypal/notification.rb +155 -0
  206. data/lib/active_merchant/billing/integrations/paypal/return.rb +10 -0
  207. data/lib/active_merchant/billing/integrations/paypal_payments_advanced.rb +20 -0
  208. data/lib/active_merchant/billing/integrations/paypal_payments_advanced/helper.rb +15 -0
  209. data/lib/active_merchant/billing/integrations/pxpay.rb +31 -0
  210. data/lib/active_merchant/billing/integrations/pxpay/helper.rb +110 -0
  211. data/lib/active_merchant/billing/integrations/pxpay/notification.rb +157 -0
  212. data/lib/active_merchant/billing/integrations/pxpay/return.rb +25 -0
  213. data/lib/active_merchant/billing/integrations/quickpay.rb +21 -0
  214. data/lib/active_merchant/billing/integrations/quickpay/helper.rb +71 -0
  215. data/lib/active_merchant/billing/integrations/quickpay/notification.rb +74 -0
  216. data/lib/active_merchant/billing/integrations/return.rb +42 -0
  217. data/lib/active_merchant/billing/integrations/robokassa.rb +49 -0
  218. data/lib/active_merchant/billing/integrations/robokassa/common.rb +19 -0
  219. data/lib/active_merchant/billing/integrations/robokassa/helper.rb +50 -0
  220. data/lib/active_merchant/billing/integrations/robokassa/notification.rb +55 -0
  221. data/lib/active_merchant/billing/integrations/robokassa/return.rb +17 -0
  222. data/lib/active_merchant/billing/integrations/sage_pay_form.rb +37 -0
  223. data/lib/active_merchant/billing/integrations/sage_pay_form/encryption.rb +33 -0
  224. data/lib/active_merchant/billing/integrations/sage_pay_form/helper.rb +129 -0
  225. data/lib/active_merchant/billing/integrations/sage_pay_form/notification.rb +210 -0
  226. data/lib/active_merchant/billing/integrations/sage_pay_form/return.rb +31 -0
  227. data/lib/active_merchant/billing/integrations/two_checkout.rb +44 -0
  228. data/lib/active_merchant/billing/integrations/two_checkout/helper.rb +91 -0
  229. data/lib/active_merchant/billing/integrations/two_checkout/notification.rb +139 -0
  230. data/lib/active_merchant/billing/integrations/two_checkout/return.rb +17 -0
  231. data/lib/active_merchant/billing/integrations/valitor.rb +33 -0
  232. data/lib/active_merchant/billing/integrations/valitor/helper.rb +86 -0
  233. data/lib/active_merchant/billing/integrations/valitor/notification.rb +13 -0
  234. data/lib/active_merchant/billing/integrations/valitor/response_fields.rb +97 -0
  235. data/lib/active_merchant/billing/integrations/valitor/return.rb +13 -0
  236. data/lib/active_merchant/billing/integrations/verkkomaksut.rb +20 -0
  237. data/lib/active_merchant/billing/integrations/verkkomaksut/helper.rb +87 -0
  238. data/lib/active_merchant/billing/integrations/verkkomaksut/notification.rb +59 -0
  239. data/lib/active_merchant/billing/integrations/web_pay.rb +45 -0
  240. data/lib/active_merchant/billing/integrations/web_pay/common.rb +50 -0
  241. data/lib/active_merchant/billing/integrations/web_pay/helper.rb +68 -0
  242. data/lib/active_merchant/billing/integrations/web_pay/notification.rb +51 -0
  243. data/lib/active_merchant/billing/integrations/world_pay.rb +27 -0
  244. data/lib/active_merchant/billing/integrations/world_pay/helper.rb +100 -0
  245. data/lib/active_merchant/billing/integrations/world_pay/notification.rb +160 -0
  246. data/lib/active_merchant/billing/response.rb +64 -0
  247. data/lib/active_merchant/version.rb +3 -0
  248. data/lib/activemerchant.rb +1 -0
  249. data/lib/support/gateway_support.rb +65 -0
  250. data/lib/support/outbound_hosts.rb +25 -0
  251. data/lib/support/ssl_verify.rb +93 -0
  252. metadata +482 -0
@@ -0,0 +1,943 @@
1
+ # -*- coding: utf-8 -*-
2
+ module ActiveMerchant #:nodoc:
3
+ module Billing #:nodoc:
4
+ # ==== Customer Information Manager (CIM)
5
+ #
6
+ # The Authorize.Net Customer Information Manager (CIM) is an optional additional service that allows you to store sensitive payment information on
7
+ # Authorize.Net's servers, simplifying payments for returning customers and recurring transactions. It can also help with Payment Card Industry (PCI)
8
+ # Data Security Standard compliance, since customer data is no longer stored locally.
9
+ #
10
+ # To use the AuthorizeNetCimGateway CIM must be enabled for your account.
11
+ #
12
+ # Information about CIM is available on the {Authorize.Net website}[http://www.authorize.net/solutions/merchantsolutions/merchantservices/cim/].
13
+ # Information about the CIM API is available at the {Authorize.Net Integration Center}[http://developer.authorize.net/]
14
+ #
15
+ # ==== Login and Password
16
+ #
17
+ # The login and password are not the username and password you use to
18
+ # login to the Authorize.Net Merchant Interface. Instead, you will
19
+ # use the API Login ID as the login and Transaction Key as the
20
+ # password.
21
+ #
22
+ # ==== How to Get Your API Login ID and Transaction Key
23
+ #
24
+ # 1. Log into the Merchant Interface
25
+ # 2. Select Settings from the Main Menu
26
+ # 3. Click on API Login ID and Transaction Key in the Security section
27
+ # 4. Type in the answer to the secret question configured on setup
28
+ # 5. Click Submit
29
+ class AuthorizeNetCimGateway < Gateway
30
+ self.test_url = 'https://apitest.authorize.net/xml/v1/request.api'
31
+ self.live_url = 'https://api.authorize.net/xml/v1/request.api'
32
+
33
+ AUTHORIZE_NET_CIM_NAMESPACE = 'AnetApi/xml/v1/schema/AnetApiSchema.xsd'
34
+
35
+ CIM_ACTIONS = {
36
+ :create_customer_profile => 'createCustomerProfile',
37
+ :create_customer_payment_profile => 'createCustomerPaymentProfile',
38
+ :create_customer_shipping_address => 'createCustomerShippingAddress',
39
+ :get_customer_profile => 'getCustomerProfile',
40
+ :get_customer_profile_ids => 'getCustomerProfileIds',
41
+ :get_customer_payment_profile => 'getCustomerPaymentProfile',
42
+ :get_customer_shipping_address => 'getCustomerShippingAddress',
43
+ :delete_customer_profile => 'deleteCustomerProfile',
44
+ :delete_customer_payment_profile => 'deleteCustomerPaymentProfile',
45
+ :delete_customer_shipping_address => 'deleteCustomerShippingAddress',
46
+ :update_customer_profile => 'updateCustomerProfile',
47
+ :update_customer_payment_profile => 'updateCustomerPaymentProfile',
48
+ :update_customer_shipping_address => 'updateCustomerShippingAddress',
49
+ :create_customer_profile_transaction => 'createCustomerProfileTransaction',
50
+ :validate_customer_payment_profile => 'validateCustomerPaymentProfile'
51
+ }
52
+
53
+ CIM_TRANSACTION_TYPES = {
54
+ :auth_capture => 'profileTransAuthCapture',
55
+ :auth_only => 'profileTransAuthOnly',
56
+ :capture_only => 'profileTransCaptureOnly',
57
+ :prior_auth_capture => 'profileTransPriorAuthCapture',
58
+ :refund => 'profileTransRefund',
59
+ :void => 'profileTransVoid'
60
+ }
61
+
62
+ CIM_VALIDATION_MODES = {
63
+ :none => 'none',
64
+ :test => 'testMode',
65
+ :live => 'liveMode',
66
+ :old => 'oldLiveMode'
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
+ :web => 'WEB'
79
+ }
80
+
81
+ self.homepage_url = 'http://www.authorize.net/'
82
+ self.display_name = 'Authorize.Net CIM'
83
+ self.supported_countries = ['US']
84
+ self.supported_cardtypes = [:visa, :master, :american_express, :discover]
85
+
86
+ # Creates a new AuthorizeNetCimGateway
87
+ #
88
+ # The gateway requires that a valid API Login ID and Transaction Key be passed
89
+ # in the +options+ hash.
90
+ #
91
+ # ==== Options
92
+ #
93
+ # * <tt>:login</tt> -- The Authorize.Net API Login ID (REQUIRED)
94
+ # * <tt>:password</tt> -- The Authorize.Net Transaction Key. (REQUIRED)
95
+ # * <tt>:test</tt> -- +true+ or +false+. If true, perform transactions against the test server.
96
+ # * <tt>:delimiter</tt> -- The delimiter used in the direct response. Default is ',' (comma).
97
+ # Otherwise, perform transactions against the production server.
98
+ def initialize(options = {})
99
+ requires!(options, :login, :password)
100
+ @options = options
101
+ super
102
+ end
103
+
104
+ # Creates a new customer profile along with any customer payment profiles and customer shipping addresses
105
+ # for the customer profile.
106
+ #
107
+ # Returns a Response with the Customer Profile ID of the new customer profile in the authorization field.
108
+ # It is *CRITICAL* that you save this ID. There is no way to retrieve this through the API. You will not
109
+ # be able to create another Customer Profile with the same information.
110
+ #
111
+ #
112
+ #
113
+ # ==== Options
114
+ #
115
+ # * <tt>:profile</tt> -- A hash containing at least one of the CONDITIONAL profile options below (REQUIRED)
116
+ #
117
+ # ==== Profile
118
+ #
119
+ # * <tt>:email</tt> -- Email address associated with the customer profile (CONDITIONAL)
120
+ # * <tt>:description</tt> -- Description of the customer or customer profile (CONDITIONAL)
121
+ # * <tt>:merchant_customer_id</tt> -- Merchant assigned ID for the customer (CONDITIONAL)
122
+ # * <tt>:payment_profile</tt> -- A hash containing the elements of the new payment profile (optional)
123
+ #
124
+ # ==== Payment Profile
125
+ #
126
+ # * <tt>:payment</tt> -- A hash containing information on payment. Either :credit_card or :bank_account (optional)
127
+ def create_customer_profile(options)
128
+ requires!(options, :profile)
129
+ requires!(options[:profile], :email) unless options[:profile][:merchant_customer_id] || options[:profile][:description]
130
+ requires!(options[:profile], :description) unless options[:profile][:email] || options[:profile][:merchant_customer_id]
131
+ requires!(options[:profile], :merchant_customer_id) unless options[:profile][:description] || options[:profile][:email]
132
+
133
+ request = build_request(:create_customer_profile, options)
134
+ commit(:create_customer_profile, request)
135
+ end
136
+
137
+ # Creates a new customer payment profile for an existing customer profile.
138
+ #
139
+ # ==== Options
140
+ #
141
+ # * <tt>:customer_profile_id</tt> -- The Customer Profile ID of the customer the payment profile will be added to. (REQUIRED)
142
+ # * <tt>:payment_profile</tt> -- A hash containing the elements of the new payment profile (REQUIRED)
143
+ #
144
+ # ==== Payment Profile
145
+ #
146
+ # * <tt>:payment</tt> -- A hash containing information on payment. Either :credit_card or :bank_account (REQUIRED)
147
+ def create_customer_payment_profile(options)
148
+ requires!(options, :customer_profile_id)
149
+ requires!(options, :payment_profile)
150
+ requires!(options[:payment_profile], :payment)
151
+
152
+ request = build_request(:create_customer_payment_profile, options)
153
+ commit(:create_customer_payment_profile, request)
154
+ end
155
+
156
+ # Creates a new customer shipping address for an existing customer profile.
157
+ #
158
+ # ==== Options
159
+ #
160
+ # * <tt>:customer_profile_id</tt> -- The Customer Profile ID of the customer the payment profile will be added to. (REQUIRED)
161
+ # * <tt>:address</tt> -- A hash containing the elements of the shipping address (REQUIRED)
162
+ def create_customer_shipping_address(options)
163
+ requires!(options, :customer_profile_id)
164
+ requires!(options, :address)
165
+
166
+ request = build_request(:create_customer_shipping_address, options)
167
+ commit(:create_customer_shipping_address, request)
168
+ end
169
+
170
+ # Deletes an existing customer profile along with all associated customer payment profiles and customer shipping addresses.
171
+ #
172
+ # ==== Options
173
+ #
174
+ # * <tt>:customer_profile_id</tt> -- The Customer Profile ID of the customer to be deleted. (REQUIRED)
175
+ def delete_customer_profile(options)
176
+ requires!(options, :customer_profile_id)
177
+
178
+ request = build_request(:delete_customer_profile, options)
179
+ commit(:delete_customer_profile, request)
180
+ end
181
+
182
+ # Deletes a customer payment profile from an existing customer profile.
183
+ #
184
+ # ==== Options
185
+ #
186
+ # * <tt>:customer_profile_id</tt> -- The Customer Profile ID of the customer with the payment profile to be deleted. (REQUIRED)
187
+ # * <tt>:customer_payment_profile_id</tt> -- The Payment Profile ID of the payment profile to be deleted. (REQUIRED)
188
+ def delete_customer_payment_profile(options)
189
+ requires!(options, :customer_profile_id)
190
+ requires!(options, :customer_payment_profile_id)
191
+
192
+ request = build_request(:delete_customer_payment_profile, options)
193
+ commit(:delete_customer_payment_profile, request)
194
+ end
195
+
196
+ # Deletes a customer shipping address from an existing customer profile.
197
+ #
198
+ # ==== Options
199
+ #
200
+ # * <tt>:customer_profile_id</tt> -- The Customer Profile ID of the customer with the payment profile to be deleted. (REQUIRED)
201
+ # * <tt>:customer_address_id</tt> -- The Shipping Address ID of the shipping address to be deleted. (REQUIRED)
202
+ def delete_customer_shipping_address(options)
203
+ requires!(options, :customer_profile_id)
204
+ requires!(options, :customer_address_id)
205
+
206
+ request = build_request(:delete_customer_shipping_address, options)
207
+ commit(:delete_customer_shipping_address, request)
208
+ end
209
+
210
+ # Retrieves an existing customer profile along with all the associated customer payment profiles and customer shipping addresses.
211
+ #
212
+ # Returns a Response whose params hash contains all the profile information.
213
+ #
214
+ # ==== Options
215
+ #
216
+ # * <tt>:customer_profile_id</tt> -- The Customer Profile ID of the customer to retrieve. (REQUIRED)
217
+ def get_customer_profile(options)
218
+ requires!(options, :customer_profile_id)
219
+
220
+ request = build_request(:get_customer_profile, options)
221
+ commit(:get_customer_profile, request)
222
+ end
223
+
224
+ def get_customer_profile_ids(options = {})
225
+ request = build_request(:get_customer_profile_ids, options)
226
+ commit(:get_customer_profile_ids, request)
227
+ end
228
+
229
+ # Retrieve a customer payment profile for an existing customer profile.
230
+ #
231
+ # Returns a Response whose params hash contains all the payment profile information. Sensitive information such as credit card
232
+ # numbers will be masked.
233
+ #
234
+ # ==== Options
235
+ #
236
+ # * <tt>:customer_profile_id</tt> -- The Customer Profile ID of the customer with the payment profile to be retrieved. (REQUIRED)
237
+ # * <tt>:customer_payment_profile_id</tt> -- The Payment Profile ID of the payment profile to be retrieved. (REQUIRED)
238
+ def get_customer_payment_profile(options)
239
+ requires!(options, :customer_profile_id)
240
+ requires!(options, :customer_payment_profile_id)
241
+
242
+ request = build_request(:get_customer_payment_profile, options)
243
+ commit(:get_customer_payment_profile, request)
244
+ end
245
+
246
+ # Retrieve a customer shipping address for an existing customer profile.
247
+ #
248
+ # Returns a Response whose params hash contains all the shipping address information.
249
+ #
250
+ # ==== Options
251
+ #
252
+ # * <tt>:customer_profile_id</tt> -- The Customer Profile ID of the customer with the payment profile to be retrieved. (REQUIRED)
253
+ # * <tt>:customer_address_id</tt> -- The Shipping Address ID of the shipping address to be retrieved. (REQUIRED)
254
+ def get_customer_shipping_address(options)
255
+ requires!(options, :customer_profile_id)
256
+ requires!(options, :customer_address_id)
257
+
258
+ request = build_request(:get_customer_shipping_address, options)
259
+ commit(:get_customer_shipping_address, request)
260
+ end
261
+
262
+ # Updates an existing customer profile.
263
+ #
264
+ # Warning: if you do not provide a parameter in the <tt>:payment_profile</tt> hash, it is automatically set to nil at
265
+ # Authorize.Net. You will most likely want to first get the profile hash using get_customer_profile and then only change the
266
+ # elements you wish to change.
267
+ #
268
+ # ==== Options
269
+ #
270
+ # * <tt>:profile</tt> -- A hash containing the values the Customer Profile should be updated to. (REQUIRED)
271
+ #
272
+ # ==== Profile
273
+ #
274
+ # * <tt>:customer_profile_id</tt> -- The Customer Profile ID of the customer profile to update. (REQUIRED)
275
+ def update_customer_profile(options)
276
+ requires!(options, :profile)
277
+ requires!(options[:profile], :customer_profile_id)
278
+
279
+ request = build_request(:update_customer_profile, options)
280
+ commit(:update_customer_profile, request)
281
+ end
282
+
283
+ # Updates a customer payment profile for an existing customer profile.
284
+ #
285
+ # Warning: if you do not provide a parameter in the <tt>:payment_profile</tt> hash, it is automatically set to nil at
286
+ # Authorize.Net. You will most likely want to first get the profile hash using get_customer_payment_profile and then only
287
+ # change the elements you wish to change.
288
+ #
289
+ # ==== Options
290
+ #
291
+ # * <tt>:customer_profile_id</tt> -- The Customer Profile ID of the customer with the payment profile to be updated. (REQUIRED)
292
+ # * <tt>:payment_profile</tt> -- A hash containing the values the Customer Payment Profile should be updated to. (REQUIRED)
293
+ #
294
+ # ==== Payment Profile
295
+ #
296
+ # * <tt>:customer_payment_profile_id</tt> -- The Customer Payment Profile ID of the Customer Payment Profile to update. (REQUIRED)
297
+ def update_customer_payment_profile(options)
298
+ requires!(options, :customer_profile_id, :payment_profile)
299
+ requires!(options[:payment_profile], :customer_payment_profile_id)
300
+
301
+ request = build_request(:update_customer_payment_profile, options)
302
+ commit(:update_customer_payment_profile, request)
303
+ end
304
+
305
+ # Updates a customer shipping address for an existing customer profile.
306
+ #
307
+ # Warning: if you do not provide a parameter in the <tt>:address</tt> hash, it is automatically set to nil at
308
+ # Authorize.Net. You will most likely want to first get the profile hash using get_customer_shipping_address and then only
309
+ # change the elements you wish to change.
310
+ #
311
+ # ==== Options
312
+ #
313
+ # * <tt>:customer_profile_id</tt> -- The Customer Profile ID of the customer with the payment profile to be updated. (REQUIRED)
314
+ # * <tt>:address</tt> -- A hash containing the values the Customer Shipping Address should be updated to. (REQUIRED)
315
+ #
316
+ # ==== Address
317
+ #
318
+ # * <tt>:customer_address_id</tt> -- The Customer Address ID of the Customer Payment Profile to update. (REQUIRED)
319
+ def update_customer_shipping_address(options)
320
+ requires!(options, :customer_profile_id, :address)
321
+ requires!(options[:address], :customer_address_id)
322
+
323
+ request = build_request(:update_customer_shipping_address, options)
324
+ commit(:update_customer_shipping_address, request)
325
+ end
326
+
327
+ # Creates a new payment transaction from an existing customer profile
328
+ #
329
+ # This is what is used to charge a customer whose information you have stored in a Customer Profile.
330
+ #
331
+ # Returns a Response object that contains the result of the transaction in <tt>params['direct_response']</tt>
332
+ #
333
+ # ==== Options
334
+ #
335
+ # * <tt>:transaction</tt> -- A hash containing information on the transaction that is being requested. (REQUIRED)
336
+ #
337
+ # ==== Transaction
338
+ #
339
+ # * <tt>:type</tt> -- The type of transaction. Can be either <tt>:auth_only</tt>, <tt>:capture_only</tt>, <tt>:auth_capture</tt>, <tt>:prior_auth_capture</tt>, <tt>:refund</tt> or <tt>:void</tt>. (REQUIRED)
340
+ # * <tt>:amount</tt> -- The amount for the tranaction. Formatted with a decimal. For example "4.95" (CONDITIONAL)
341
+ # - :type == :void (NOT USED)
342
+ # - :type == (:refund, :auth_only, :capture_only, :auth_capture, :prior_auth_capture) (REQUIRED)
343
+ #
344
+ # * <tt>:customer_profile_id</tt> -- The Customer Profile ID of the customer to use in this transaction. (CONDITIONAL)
345
+ # - :type == (:void, :prior_auth_capture) (OPTIONAL)
346
+ # - :type == :refund (CONDITIONAL - required if masked information is not being submitted [see below])
347
+ # - :type == (:auth_only, :capture_only, :auth_capture) (REQUIRED)
348
+ #
349
+ # * <tt>:customer_payment_profile_id</tt> -- The Customer Payment Profile ID of the Customer Payment Profile to use in this transaction. (CONDITIONAL)
350
+ # - :type == (:void, :prior_auth_capture) (OPTIONAL)
351
+ # - :type == :refund (CONDITIONAL - required if masked information is not being submitted [see below])
352
+ # - :type == (:auth_only, :capture_only, :auth_capture) (REQUIRED)
353
+ #
354
+ # * <tt>:trans_id</tt> -- The payment gateway assigned transaction ID of the original transaction (CONDITIONAL):
355
+ # - :type = (:void, :refund, :prior_auth_capture) (REQUIRED)
356
+ # - :type = (:auth_only, :capture_only, :auth_capture) (NOT USED)
357
+ #
358
+ # * <tt>:card_code</tt> -- CVV/CCV code (OPTIONAL)
359
+ # - :type = (:void, :refund, :prior_auth_capture) (NOT USED)
360
+ # - :type = (:auth_only, :capture_only, :auth_capture) (OPTIONAL)
361
+ #
362
+ # * <tt>:customer_shipping_address_id</tt> -- Payment gateway assigned ID associated with the customer shipping address (CONDITIONAL)
363
+ # - :type = (:void, :refund) (OPTIONAL)
364
+ # - :type = (:auth_only, :capture_only, :auth_capture) (NOT USED)
365
+ # - :type = (:prior_auth_capture) (OPTIONAL)
366
+ #
367
+ # ==== For :type == :refund only
368
+ # * <tt>:credit_card_number_masked</tt> -- (CONDITIONAL - requied for credit card refunds is :customer_profile_id AND :customer_payment_profile_id are missing)
369
+ # * <tt>:bank_routing_number_masked && :bank_account_number_masked</tt> -- (CONDITIONAL - requied for electronic check refunds is :customer_profile_id AND :customer_payment_profile_id are missing) (NOT ABLE TO TEST - I keep getting "ACH transactions are not accepted by this merchant." when trying to make a payment and, until that's possible I can't refund (wiseleyb@gmail.com))
370
+ def create_customer_profile_transaction(options)
371
+ requires!(options, :transaction)
372
+ requires!(options[:transaction], :type)
373
+ case options[:transaction][:type]
374
+ when :void
375
+ requires!(options[:transaction], :trans_id)
376
+ when :refund
377
+ requires!(options[:transaction], :trans_id) &&
378
+ (
379
+ (options[:transaction][:customer_profile_id] && options[:transaction][:customer_payment_profile_id]) ||
380
+ options[:transaction][:credit_card_number_masked] ||
381
+ (options[:transaction][:bank_routing_number_masked] && options[:transaction][:bank_account_number_masked])
382
+ )
383
+ when :prior_auth_capture
384
+ requires!(options[:transaction], :amount, :trans_id)
385
+ else
386
+ requires!(options[:transaction], :amount, :customer_profile_id, :customer_payment_profile_id)
387
+ end
388
+ request = build_request(:create_customer_profile_transaction, options)
389
+ commit(:create_customer_profile_transaction, request)
390
+ end
391
+
392
+ # Creates a new payment transaction for refund from an existing customer profile
393
+ #
394
+ # This is what is used to refund a transaction you have stored in a Customer Profile.
395
+ #
396
+ # Returns a Response object that contains the result of the transaction in <tt>params['direct_response']</tt>
397
+ #
398
+ # ==== Options
399
+ #
400
+ # * <tt>:transaction</tt> -- A hash containing information on the transaction that is being requested. (REQUIRED)
401
+ #
402
+ # ==== Transaction
403
+ #
404
+ # * <tt>:amount</tt> -- The total amount to be refunded (REQUIRED)
405
+ #
406
+ # * <tt>:customer_profile_id</tt> -- The Customer Profile ID of the customer to use in this transaction. (CONDITIONAL :customer_payment_profile_id must be included if used)
407
+ # * <tt>:customer_payment_profile_id</tt> -- The Customer Payment Profile ID of the Customer Payment Profile to use in this transaction. (CONDITIONAL :customer_profile_id must be included if used)
408
+ #
409
+ # * <tt>:credit_card_number_masked</tt> -- Four Xs follwed by the last four digits of the credit card (CONDITIONAL - used if customer_profile_id and customer_payment_profile_id aren't given)
410
+ #
411
+ # * <tt>:bank_routing_number_masked</tt> -- The last four gidits of the routing number to be refunded (CONDITIONAL - must be used with :bank_account_number_masked)
412
+ # * <tt>:bank_account_number_masked</tt> -- The last four digis of the bank account number to be refunded, Ex. XXXX1234 (CONDITIONAL - must be used with :bank_routing_number_masked)
413
+ #
414
+ # * <tt>:tax</tt> - A hash containing tax information for the refund (OPTIONAL - <tt>:amount</tt>, <tt>:name</tt> (31 characters), <tt>:description</tt> (255 characters))
415
+ # * <tt>:duty</tt> - A hash containting duty information for the refund (OPTIONAL - <tt>:amount</tt>, <tt>:name</tt> (31 characters), <tt>:description</tt> (255 characters))
416
+ # * <tt>:shipping</tt> - A hash containing shipping information for the refund (OPTIONAL - <tt>:amount</tt>, <tt>:name</tt> (31 characters), <tt>:description</tt> (255 characters))
417
+ def create_customer_profile_transaction_for_refund(options)
418
+ requires!(options, :transaction)
419
+ options[:transaction][:type] = :refund
420
+ requires!(options[:transaction], :trans_id)
421
+ requires!(options[:transaction], :amount)
422
+ request = build_request(:create_customer_profile_transaction, options)
423
+ commit(:create_customer_profile_transaction, request)
424
+ end
425
+
426
+ # Creates a new payment transaction for void from an existing customer profile
427
+ #
428
+ # This is what is used to void a transaction you have stored in a Customer Profile.
429
+ #
430
+ # Returns a Response object that contains the result of the transaction in <tt>params['direct_response']</tt>
431
+ #
432
+ # ==== Options
433
+ #
434
+ # * <tt>:transaction</tt> -- A hash containing information on the transaction that is being requested. (REQUIRED)
435
+ #
436
+ # ==== Transaction
437
+ #
438
+ # * <tt>:trans_id</tt> -- The payment gateway assigned transaction id of the original transaction. (REQUIRED)
439
+ # * <tt>:customer_profile_id</tt> -- The Customer Profile ID of the customer to use in this transaction.
440
+ # * <tt>:customer_payment_profile_id</tt> -- The Customer Payment Profile ID of the Customer Payment Profile to use in this transaction.
441
+ # * <tt>:customer_shipping_address_id</tt> -- Payment gateway assigned ID associated with the customer shipping address.
442
+ def create_customer_profile_transaction_for_void(options)
443
+ requires!(options, :transaction)
444
+ options[:transaction][:type] = :void
445
+ requires!(options[:transaction], :trans_id)
446
+ request = build_request(:create_customer_profile_transaction, options)
447
+ commit(:create_customer_profile_transaction, request)
448
+ end
449
+
450
+ # Verifies an existing customer payment profile by generating a test transaction
451
+ #
452
+ # Returns a Response object that contains the result of the transaction in <tt>params['direct_response']</tt>
453
+ #
454
+ # ==== Options
455
+ #
456
+ # * <tt>:customer_profile_id</tt> -- The Customer Profile ID of the customer to use in this transaction. (REQUIRED)
457
+ # * <tt>:customer_payment_profile_id</tt> -- The Customer Payment Profile ID of the Customer Payment Profile to be verified. (REQUIRED)
458
+ # * <tt>:customer_address_id</tt> -- The Customer Address ID of the Customer Shipping Address to be verified. (OPTIONAL)
459
+ # * <tt>:card_code</tt> -- If the payment profile is a credit card, the CCV/CVV code to validate with (OPTIONAL)
460
+ # * <tt>:validation_mode</tt> -- <tt>:live</tt> or <tt>:test</tt> In Test Mode, only field validation is performed. (REQUIRED
461
+ # 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)
462
+ def validate_customer_payment_profile(options)
463
+ requires!(options, :customer_profile_id, :customer_payment_profile_id, :validation_mode)
464
+
465
+ request = build_request(:validate_customer_payment_profile, options)
466
+ commit(:validate_customer_payment_profile, request)
467
+ end
468
+
469
+ private
470
+
471
+ def expdate(credit_card)
472
+ sprintf('%04d-%02d', credit_card.year, credit_card.month)
473
+ end
474
+
475
+ def build_request(action, options = {})
476
+ unless CIM_ACTIONS.include?(action)
477
+ raise StandardError, "Invalid Customer Information Manager Action: #{action}"
478
+ end
479
+
480
+ xml = Builder::XmlMarkup.new(:indent => 2)
481
+ xml.instruct!(:xml, :version => '1.0', :encoding => 'utf-8')
482
+ xml.tag!("#{CIM_ACTIONS[action]}Request", :xmlns => AUTHORIZE_NET_CIM_NAMESPACE) do
483
+ add_merchant_authentication(xml)
484
+ # Merchant-assigned reference ID for the request
485
+ xml.tag!('refId', options[:ref_id]) if options[:ref_id]
486
+ # Order options
487
+ add_order(xml, options[:order]) if options[:order]
488
+ send("build_#{action}_request", xml, options)
489
+ end
490
+ end
491
+
492
+ # Contains the merchant’s payment gateway account authentication information
493
+ def add_merchant_authentication(xml)
494
+ xml.tag!('merchantAuthentication') do
495
+ xml.tag!('name', @options[:login])
496
+ xml.tag!('transactionKey', @options[:password])
497
+ end
498
+ end
499
+
500
+ def build_create_customer_profile_request(xml, options)
501
+ add_profile(xml, options[:profile])
502
+
503
+ xml.tag!('validationMode', CIM_VALIDATION_MODES[options[:validation_mode]]) if options[:validation_mode]
504
+
505
+ if options.has_key?(:payment_profile)
506
+ xml.tag!('paymentProfile') do
507
+ add_payment_profile(xml, options[:payment_profile])
508
+ end
509
+ end
510
+
511
+ xml.target!
512
+ end
513
+
514
+ def build_create_customer_payment_profile_request(xml, options)
515
+ xml.tag!('customerProfileId', options[:customer_profile_id])
516
+
517
+ xml.tag!('paymentProfile') do
518
+ add_payment_profile(xml, options[:payment_profile])
519
+ end
520
+
521
+ xml.tag!('validationMode', CIM_VALIDATION_MODES[options[:validation_mode]]) if options[:validation_mode]
522
+
523
+ xml.target!
524
+ end
525
+
526
+ def build_create_customer_shipping_address_request(xml, options)
527
+ xml.tag!('customerProfileId', options[:customer_profile_id])
528
+
529
+ xml.tag!('address') do
530
+ add_address(xml, options[:address])
531
+ end
532
+
533
+ xml.target!
534
+ end
535
+
536
+ def build_delete_customer_profile_request(xml, options)
537
+ xml.tag!('customerProfileId', options[:customer_profile_id])
538
+ xml.target!
539
+ end
540
+
541
+ def build_delete_customer_payment_profile_request(xml, options)
542
+ xml.tag!('customerProfileId', options[:customer_profile_id])
543
+ xml.tag!('customerPaymentProfileId', options[:customer_payment_profile_id])
544
+ xml.target!
545
+ end
546
+
547
+ def build_delete_customer_shipping_address_request(xml, options)
548
+ xml.tag!('customerProfileId', options[:customer_profile_id])
549
+ xml.tag!('customerAddressId', options[:customer_address_id])
550
+ xml.target!
551
+ end
552
+
553
+ def build_get_customer_profile_request(xml, options)
554
+ xml.tag!('customerProfileId', options[:customer_profile_id])
555
+ xml.target!
556
+ end
557
+
558
+ def build_get_customer_profile_ids_request(xml, options)
559
+ xml.target!
560
+ end
561
+
562
+ def build_get_customer_payment_profile_request(xml, options)
563
+ xml.tag!('customerProfileId', options[:customer_profile_id])
564
+ xml.tag!('customerPaymentProfileId', options[:customer_payment_profile_id])
565
+ xml.target!
566
+ end
567
+
568
+ def build_get_customer_shipping_address_request(xml, options)
569
+ xml.tag!('customerProfileId', options[:customer_profile_id])
570
+ xml.tag!('customerAddressId', options[:customer_address_id])
571
+ xml.target!
572
+ end
573
+
574
+ def build_update_customer_profile_request(xml, options)
575
+ add_profile(xml, options[:profile], true)
576
+
577
+ xml.target!
578
+ end
579
+
580
+ def build_update_customer_payment_profile_request(xml, options)
581
+ xml.tag!('customerProfileId', options[:customer_profile_id])
582
+
583
+ xml.tag!('paymentProfile') do
584
+ add_payment_profile(xml, options[:payment_profile])
585
+ end
586
+
587
+ xml.tag!('validationMode', CIM_VALIDATION_MODES[options[:validation_mode]]) if options[:validation_mode]
588
+
589
+ xml.target!
590
+ end
591
+
592
+ def build_update_customer_shipping_address_request(xml, options)
593
+ xml.tag!('customerProfileId', options[:customer_profile_id])
594
+
595
+ xml.tag!('address') do
596
+ add_address(xml, options[:address])
597
+ end
598
+
599
+ xml.target!
600
+ end
601
+
602
+ def build_create_customer_profile_transaction_request(xml, options)
603
+ add_transaction(xml, options[:transaction])
604
+ xml.tag!('extraOptions', "x_test_request=TRUE") if @options[:test]
605
+
606
+ xml.target!
607
+ end
608
+
609
+ def build_validate_customer_payment_profile_request(xml, options)
610
+ xml.tag!('customerProfileId', options[:customer_profile_id])
611
+ xml.tag!('customerPaymentProfileId', options[:customer_payment_profile_id])
612
+ xml.tag!('customerShippingAddressId', options[:customer_address_id]) if options[:customer_address_id]
613
+ tag_unless_blank(xml, 'cardCode', options[:card_code])
614
+ xml.tag!('validationMode', CIM_VALIDATION_MODES[options[:validation_mode]]) if options[:validation_mode]
615
+
616
+ xml.target!
617
+ end
618
+
619
+ # :merchant_customer_id (Optional)
620
+ # :description (Optional)
621
+ # :email (Optional)
622
+ # :payment_profiles (Optional)
623
+ def add_profile(xml, profile, update = false)
624
+ xml.tag!('profile') do
625
+ # Merchant assigned ID for the customer. Up to 20 characters. (optional)
626
+ xml.tag!('merchantCustomerId', profile[:merchant_customer_id]) if profile[:merchant_customer_id]
627
+ # Description of the customer. Up to 255 Characters (optional)
628
+ xml.tag!('description', profile[:description]) if profile[:description]
629
+ # Email Address for the customer. Up to 255 Characters (optional)
630
+ xml.tag!('email', profile[:email]) if profile[:email]
631
+
632
+ if update
633
+ xml.tag!('customerProfileId', profile[:customer_profile_id])
634
+ else
635
+ add_payment_profiles(xml, profile[:payment_profiles]) if profile[:payment_profiles]
636
+ add_ship_to_list(xml, profile[:ship_to_list]) if profile[:ship_to_list]
637
+ end
638
+ end
639
+ end
640
+
641
+ def add_transaction(xml, transaction)
642
+ unless CIM_TRANSACTION_TYPES.include?(transaction[:type])
643
+ raise StandardError, "Invalid Customer Information Manager Transaction Type: #{transaction[:type]}"
644
+ end
645
+
646
+ xml.tag!('transaction') do
647
+ xml.tag!(CIM_TRANSACTION_TYPES[transaction[:type]]) do
648
+ # The amount to be billed to the customer
649
+ case transaction[:type]
650
+ when :void
651
+ tag_unless_blank(xml,'customerProfileId', transaction[:customer_profile_id])
652
+ tag_unless_blank(xml,'customerPaymentProfileId', transaction[:customer_payment_profile_id])
653
+ tag_unless_blank(xml,'customerShippingAddressId', transaction[:customer_shipping_address_id])
654
+ xml.tag!('transId', transaction[:trans_id])
655
+ when :refund
656
+ #TODO - add lineItems and extraOptions fields
657
+ xml.tag!('amount', transaction[:amount])
658
+ tag_unless_blank(xml, 'customerProfileId', transaction[:customer_profile_id])
659
+ tag_unless_blank(xml, 'customerPaymentProfileId', transaction[:customer_payment_profile_id])
660
+ tag_unless_blank(xml, 'customerShippingAddressId', transaction[:customer_shipping_address_id])
661
+ tag_unless_blank(xml, 'creditCardNumberMasked', transaction[:credit_card_number_masked])
662
+ tag_unless_blank(xml, 'bankRoutingNumberMasked', transaction[:bank_routing_number_masked])
663
+ tag_unless_blank(xml, 'bankAccountNumberMasked', transaction[:bank_account_number_masked])
664
+ xml.tag!('transId', transaction[:trans_id])
665
+ add_tax(xml, transaction[:tax]) if transaction[:tax]
666
+ add_duty(xml, transaction[:duty]) if transaction[:duty]
667
+ add_shipping(xml, transaction[:shipping]) if transaction[:shipping]
668
+ when :prior_auth_capture
669
+ xml.tag!('amount', transaction[:amount])
670
+ xml.tag!('transId', transaction[:trans_id])
671
+ else
672
+ xml.tag!('amount', transaction[:amount])
673
+ xml.tag!('customerProfileId', transaction[:customer_profile_id])
674
+ xml.tag!('customerPaymentProfileId', transaction[:customer_payment_profile_id])
675
+ xml.tag!('approvalCode', transaction[:approval_code]) if transaction[:type] == :capture_only
676
+ tag_unless_blank(xml, 'cardCode', transaction[:card_code])
677
+ end
678
+ add_order(xml, transaction[:order]) if transaction[:order].present?
679
+ end
680
+ end
681
+ end
682
+
683
+ def add_tax(xml, tax)
684
+ xml.tag!('tax') do
685
+ xml.tag!('amount', tax[:amount]) if tax[:amount]
686
+ xml.tag!('name', tax[:name]) if tax[:name]
687
+ xml.tag!('description', tax[:description]) if tax[:description]
688
+ end
689
+ end
690
+
691
+ def add_duty(xml, duty)
692
+ xml.tag!('duty') do
693
+ xml.tag!('amount', duty[:amount]) if duty[:amount]
694
+ xml.tag!('name', duty[:name]) if duty[:name]
695
+ xml.tag!('description', duty[:description]) if duty[:description]
696
+ end
697
+ end
698
+
699
+ def add_shipping(xml, shipping)
700
+ xml.tag!('shipping') do
701
+ xml.tag!('amount', shipping[:amount]) if shipping[:amount]
702
+ xml.tag!('name', shipping[:name]) if shipping[:name]
703
+ xml.tag!('description', shipping[:description]) if shipping[:description]
704
+ end
705
+ end
706
+
707
+ def add_order(xml, order)
708
+ xml.tag!('order') do
709
+ xml.tag!('invoiceNumber', order[:invoice_number]) if order[:invoice_number]
710
+ xml.tag!('description', order[:description]) if order[:description]
711
+ xml.tag!('purchaseOrderNumber', order[:purchase_order_number]) if order[:purchase_order_number]
712
+ end
713
+ end
714
+
715
+ def add_payment_profiles(xml, payment_profiles)
716
+ xml.tag!('paymentProfiles') do
717
+ add_payment_profile(xml, payment_profiles)
718
+ end
719
+ end
720
+
721
+ # :customer_type => 'individual or business', # Optional
722
+ # :bill_to => @address,
723
+ # :payment => @payment
724
+ def add_payment_profile(xml, payment_profile)
725
+ # 'individual' or 'business' (optional)
726
+ xml.tag!('customerType', payment_profile[:customer_type]) if payment_profile[:customer_type]
727
+
728
+ if payment_profile[:bill_to]
729
+ xml.tag!('billTo') do
730
+ add_address(xml, payment_profile[:bill_to])
731
+ end
732
+ end
733
+
734
+ if payment_profile[:payment]
735
+ xml.tag!('payment') do
736
+ add_credit_card(xml, payment_profile[:payment][:credit_card]) if payment_profile[:payment].has_key?(:credit_card)
737
+ add_bank_account(xml, payment_profile[:payment][:bank_account]) if payment_profile[:payment].has_key?(:bank_account)
738
+ add_drivers_license(xml, payment_profile[:payment][:drivers_license]) if payment_profile[:payment].has_key?(:drivers_license)
739
+ # This element is only required for Wells Fargo SecureSource eCheck.Net merchants
740
+ # The customer's Social Security Number or Tax ID
741
+ xml.tag!('taxId', payment_profile[:payment]) if payment_profile[:payment].has_key?(:tax_id)
742
+ end
743
+ end
744
+
745
+ xml.tag!('customerPaymentProfileId', payment_profile[:customer_payment_profile_id]) if payment_profile[:customer_payment_profile_id]
746
+ end
747
+
748
+ def add_ship_to_list(xml, ship_to_list)
749
+ xml.tag!('shipToList') do
750
+ add_address(xml, ship_to_list)
751
+ end
752
+ end
753
+
754
+ def add_address(xml, address)
755
+ xml.tag!('firstName', address[:first_name])
756
+ xml.tag!('lastName', address[:last_name])
757
+ xml.tag!('company', address[:company])
758
+ xml.tag!('address', address[:address1]) if address[:address1]
759
+ xml.tag!('address', address[:address]) if address[:address]
760
+ xml.tag!('city', address[:city])
761
+ xml.tag!('state', address[:state])
762
+ xml.tag!('zip', address[:zip])
763
+ xml.tag!('country', address[:country])
764
+ xml.tag!('phoneNumber', address[:phone_number]) if address[:phone_number]
765
+ xml.tag!('faxNumber', address[:fax_number]) if address[:fax_number]
766
+
767
+ xml.tag!('customerAddressId', address[:customer_address_id]) if address[:customer_address_id]
768
+ end
769
+
770
+ # Adds customer’s credit card information
771
+ # Note: This element should only be included
772
+ # when the payment method is credit card.
773
+ def add_credit_card(xml, credit_card)
774
+ return unless credit_card
775
+ xml.tag!('creditCard') do
776
+ # The credit card number used for payment of the subscription
777
+ xml.tag!('cardNumber', credit_card.number)
778
+ # The expiration date of the credit card used for the subscription
779
+ xml.tag!('expirationDate', expdate(credit_card))
780
+ # Note that Authorize.net does not save CVV codes as part of the
781
+ # payment profile. Any transactions/validations after the payment
782
+ # profile is created that wish to use CVV verification must pass
783
+ # the CVV code to authorize.net again.
784
+ xml.tag!('cardCode', credit_card.verification_value) if credit_card.verification_value?
785
+ end
786
+ end
787
+
788
+ # Adds customer’s bank account information
789
+ # Note: This element should only be included
790
+ # when the payment method is bank account.
791
+ def add_bank_account(xml, bank_account)
792
+ raise StandardError, "Invalid Bank Account Type: #{bank_account[:account_type]}" unless BANK_ACCOUNT_TYPES.include?(bank_account[:account_type])
793
+ raise StandardError, "Invalid eCheck Type: #{bank_account[:echeck_type]}" unless ECHECK_TYPES.include?(bank_account[:echeck_type])
794
+
795
+ xml.tag!('bankAccount') do
796
+ # The type of bank account
797
+ xml.tag!('accountType', BANK_ACCOUNT_TYPES[bank_account[:account_type]])
798
+ # The routing number of the customer’s bank
799
+ xml.tag!('routingNumber', bank_account[:routing_number])
800
+ # The bank account number
801
+ xml.tag!('accountNumber', bank_account[:account_number])
802
+ # The full name of the individual associated
803
+ # with the bank account number
804
+ xml.tag!('nameOnAccount', bank_account[:name_on_account])
805
+ # The type of electronic check transaction
806
+ xml.tag!('echeckType', ECHECK_TYPES[bank_account[:echeck_type]])
807
+ # The full name of the individual associated
808
+ # with the bank account number (optional)
809
+ xml.tag!('bankName', bank_account[:bank_name]) if bank_account[:bank_name]
810
+ end
811
+ end
812
+
813
+ # Adds customer’s driver's license information
814
+ # Note: This element is only required for
815
+ # Wells Fargo SecureSource eCheck.Net merchants
816
+ def add_drivers_license(xml, drivers_license)
817
+ xml.tag!('driversLicense') do
818
+ # The state of the customer's driver's license
819
+ # A valid two character state code
820
+ xml.tag!('state', drivers_license[:state])
821
+ # The customer’s driver's license number
822
+ xml.tag!('number', drivers_license[:number])
823
+ # The date of birth listed on the customer's driver's license
824
+ # YYYY-MM-DD
825
+ xml.tag!('dateOfBirth', drivers_license[:date_of_birth])
826
+ end
827
+ end
828
+
829
+ def commit(action, request)
830
+ url = test? ? test_url : live_url
831
+ xml = ssl_post(url, request, "Content-Type" => "text/xml")
832
+
833
+ response_params = parse(action, xml)
834
+
835
+ message = response_params['messages']['message']['text']
836
+ test_mode = test? || message =~ /Test Mode/
837
+ success = response_params['messages']['result_code'] == 'Ok'
838
+ response_params['direct_response'] = parse_direct_response(response_params['direct_response']) if response_params['direct_response']
839
+ transaction_id = response_params['direct_response']['transaction_id'] if response_params['direct_response']
840
+
841
+ Response.new(success, message, response_params,
842
+ :test => test_mode,
843
+ :authorization => transaction_id || response_params['customer_profile_id'] || (response_params['profile'] ? response_params['profile']['customer_profile_id'] : nil)
844
+ )
845
+ end
846
+
847
+ def tag_unless_blank(xml, tag_name, data)
848
+ xml.tag!(tag_name, data) unless data.blank? || data.nil?
849
+ end
850
+
851
+ def parse_direct_response(params)
852
+ delimiter = @options[:delimiter] || ','
853
+ direct_response = {'raw' => params}
854
+ direct_response_fields = params.split(delimiter)
855
+ direct_response.merge(
856
+ {
857
+ 'response_code' => direct_response_fields[0],
858
+ 'response_subcode' => direct_response_fields[1],
859
+ 'response_reason_code' => direct_response_fields[2],
860
+ 'message' => direct_response_fields[3],
861
+ 'approval_code' => direct_response_fields[4],
862
+ 'avs_response' => direct_response_fields[5],
863
+ 'transaction_id' => direct_response_fields[6],
864
+ 'invoice_number' => direct_response_fields[7],
865
+ 'order_description' => direct_response_fields[8],
866
+ 'amount' => direct_response_fields[9],
867
+ 'method' => direct_response_fields[10],
868
+ 'transaction_type' => direct_response_fields[11],
869
+ 'customer_id' => direct_response_fields[12],
870
+ 'first_name' => direct_response_fields[13],
871
+ 'last_name' => direct_response_fields[14],
872
+ 'company' => direct_response_fields[15],
873
+ 'address' => direct_response_fields[16],
874
+ 'city' => direct_response_fields[17],
875
+ 'state' => direct_response_fields[18],
876
+ 'zip_code' => direct_response_fields[19],
877
+ 'country' => direct_response_fields[20],
878
+ 'phone' => direct_response_fields[21],
879
+ 'fax' => direct_response_fields[22],
880
+ 'email_address' => direct_response_fields[23],
881
+ 'ship_to_first_name' => direct_response_fields[24],
882
+ 'ship_to_last_name' => direct_response_fields[25],
883
+ 'ship_to_company' => direct_response_fields[26],
884
+ 'ship_to_address' => direct_response_fields[27],
885
+ 'ship_to_city' => direct_response_fields[28],
886
+ 'ship_to_state' => direct_response_fields[29],
887
+ 'ship_to_zip_code' => direct_response_fields[30],
888
+ 'ship_to_country' => direct_response_fields[31],
889
+ 'tax' => direct_response_fields[32],
890
+ 'duty' => direct_response_fields[33],
891
+ 'freight' => direct_response_fields[34],
892
+ 'tax_exempt' => direct_response_fields[35],
893
+ 'purchase_order_number' => direct_response_fields[36],
894
+ 'md5_hash' => direct_response_fields[37],
895
+ 'card_code' => direct_response_fields[38],
896
+ 'cardholder_authentication_verification_response' => direct_response_fields[39],
897
+ # The following direct response fields are only available in version 3.1 of the
898
+ # transaction response. Check your merchant account settings for details.
899
+ 'account_number' => direct_response_fields[50] || '',
900
+ 'card_type' => direct_response_fields[51] || '',
901
+ 'split_tender_id' => direct_response_fields[52] || '',
902
+ 'requested_amount' => direct_response_fields[53] || '',
903
+ 'balance_on_card' => direct_response_fields[54] || '',
904
+ }
905
+ )
906
+ end
907
+
908
+ def parse(action, xml)
909
+ xml = REXML::Document.new(xml)
910
+ root = REXML::XPath.first(xml, "//#{CIM_ACTIONS[action]}Response") ||
911
+ REXML::XPath.first(xml, "//ErrorResponse")
912
+ if root
913
+ response = parse_element(root)
914
+ end
915
+
916
+ response
917
+ end
918
+
919
+ def parse_element(node)
920
+ if node.has_elements?
921
+ response = {}
922
+ node.elements.each{ |e|
923
+ key = e.name.underscore
924
+ value = parse_element(e)
925
+ if response.has_key?(key)
926
+ if response[key].is_a?(Array)
927
+ response[key].push(value)
928
+ else
929
+ response[key] = [response[key], value]
930
+ end
931
+ else
932
+ response[key] = parse_element(e)
933
+ end
934
+ }
935
+ else
936
+ response = node.text
937
+ end
938
+
939
+ response
940
+ end
941
+ end
942
+ end
943
+ end