jelaniharris-activemerchant 1.24.1

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