tlconnor-activemerchant 1.20.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (195) hide show
  1. data/CHANGELOG +805 -0
  2. data/CONTRIBUTORS +274 -0
  3. data/MIT-LICENSE +20 -0
  4. data/gem-public_cert.pem +20 -0
  5. data/lib/active_merchant.rb +63 -0
  6. data/lib/active_merchant/billing.rb +9 -0
  7. data/lib/active_merchant/billing/avs_result.rb +98 -0
  8. data/lib/active_merchant/billing/base.rb +57 -0
  9. data/lib/active_merchant/billing/check.rb +68 -0
  10. data/lib/active_merchant/billing/credit_card.rb +264 -0
  11. data/lib/active_merchant/billing/credit_card_formatting.rb +21 -0
  12. data/lib/active_merchant/billing/credit_card_methods.rb +129 -0
  13. data/lib/active_merchant/billing/cvv_result.rb +38 -0
  14. data/lib/active_merchant/billing/expiry_date.rb +34 -0
  15. data/lib/active_merchant/billing/gateway.rb +170 -0
  16. data/lib/active_merchant/billing/gateways.rb +18 -0
  17. data/lib/active_merchant/billing/gateways/authorize_net.rb +694 -0
  18. data/lib/active_merchant/billing/gateways/authorize_net_cim.rb +944 -0
  19. data/lib/active_merchant/billing/gateways/barclays_epdq.rb +308 -0
  20. data/lib/active_merchant/billing/gateways/beanstream.rb +167 -0
  21. data/lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb +388 -0
  22. data/lib/active_merchant/billing/gateways/beanstream_interac.rb +54 -0
  23. data/lib/active_merchant/billing/gateways/blue_pay.rb +11 -0
  24. data/lib/active_merchant/billing/gateways/bogus.rb +142 -0
  25. data/lib/active_merchant/billing/gateways/braintree.rb +17 -0
  26. data/lib/active_merchant/billing/gateways/braintree/braintree_common.rb +9 -0
  27. data/lib/active_merchant/billing/gateways/braintree_blue.rb +308 -0
  28. data/lib/active_merchant/billing/gateways/braintree_orange.rb +21 -0
  29. data/lib/active_merchant/billing/gateways/card_save.rb +23 -0
  30. data/lib/active_merchant/billing/gateways/card_stream.rb +230 -0
  31. data/lib/active_merchant/billing/gateways/certo_direct.rb +279 -0
  32. data/lib/active_merchant/billing/gateways/cyber_source.rb +430 -0
  33. data/lib/active_merchant/billing/gateways/data_cash.rb +597 -0
  34. data/lib/active_merchant/billing/gateways/efsnet.rb +235 -0
  35. data/lib/active_merchant/billing/gateways/elavon.rb +135 -0
  36. data/lib/active_merchant/billing/gateways/epay.rb +274 -0
  37. data/lib/active_merchant/billing/gateways/eway.rb +277 -0
  38. data/lib/active_merchant/billing/gateways/eway_managed.rb +265 -0
  39. data/lib/active_merchant/billing/gateways/exact.rb +227 -0
  40. data/lib/active_merchant/billing/gateways/federated_canada.rb +168 -0
  41. data/lib/active_merchant/billing/gateways/first_pay.rb +177 -0
  42. data/lib/active_merchant/billing/gateways/garanti.rb +262 -0
  43. data/lib/active_merchant/billing/gateways/ideal/ideal_base.rb +250 -0
  44. data/lib/active_merchant/billing/gateways/ideal/ideal_rabobank.pem +13 -0
  45. data/lib/active_merchant/billing/gateways/ideal/ideal_response.rb +29 -0
  46. data/lib/active_merchant/billing/gateways/ideal_rabobank.rb +55 -0
  47. data/lib/active_merchant/billing/gateways/inspire.rb +221 -0
  48. data/lib/active_merchant/billing/gateways/instapay.rb +164 -0
  49. data/lib/active_merchant/billing/gateways/iridium.rb +258 -0
  50. data/lib/active_merchant/billing/gateways/jetpay.rb +276 -0
  51. data/lib/active_merchant/billing/gateways/linkpoint.rb +454 -0
  52. data/lib/active_merchant/billing/gateways/merchant_e_solutions.rb +157 -0
  53. data/lib/active_merchant/billing/gateways/merchant_ware.rb +289 -0
  54. data/lib/active_merchant/billing/gateways/modern_payments.rb +36 -0
  55. data/lib/active_merchant/billing/gateways/modern_payments_cim.rb +220 -0
  56. data/lib/active_merchant/billing/gateways/moneris.rb +239 -0
  57. data/lib/active_merchant/billing/gateways/nab_transact.rb +244 -0
  58. data/lib/active_merchant/billing/gateways/net_registry.rb +189 -0
  59. data/lib/active_merchant/billing/gateways/netaxept.rb +239 -0
  60. data/lib/active_merchant/billing/gateways/netbilling.rb +168 -0
  61. data/lib/active_merchant/billing/gateways/nmi.rb +13 -0
  62. data/lib/active_merchant/billing/gateways/ogone.rb +330 -0
  63. data/lib/active_merchant/billing/gateways/optimal_payment.rb +277 -0
  64. data/lib/active_merchant/billing/gateways/orbital.rb +344 -0
  65. data/lib/active_merchant/billing/gateways/orbital/orbital_soft_descriptors.rb +46 -0
  66. data/lib/active_merchant/billing/gateways/pay_junction.rb +397 -0
  67. data/lib/active_merchant/billing/gateways/pay_secure.rb +120 -0
  68. data/lib/active_merchant/billing/gateways/paybox_direct.rb +207 -0
  69. data/lib/active_merchant/billing/gateways/payflow.rb +261 -0
  70. data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +208 -0
  71. data/lib/active_merchant/billing/gateways/payflow/payflow_express_response.rb +39 -0
  72. data/lib/active_merchant/billing/gateways/payflow/payflow_response.rb +13 -0
  73. data/lib/active_merchant/billing/gateways/payflow_express.rb +222 -0
  74. data/lib/active_merchant/billing/gateways/payflow_express_uk.rb +15 -0
  75. data/lib/active_merchant/billing/gateways/payflow_uk.rb +21 -0
  76. data/lib/active_merchant/billing/gateways/payment_express.rb +235 -0
  77. data/lib/active_merchant/billing/gateways/paypal.rb +121 -0
  78. data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +354 -0
  79. data/lib/active_merchant/billing/gateways/paypal/paypal_express_response.rb +49 -0
  80. data/lib/active_merchant/billing/gateways/paypal_ca.rb +13 -0
  81. data/lib/active_merchant/billing/gateways/paypal_express.rb +229 -0
  82. data/lib/active_merchant/billing/gateways/paypal_express_common.rb +25 -0
  83. data/lib/active_merchant/billing/gateways/paystation.rb +201 -0
  84. data/lib/active_merchant/billing/gateways/plugnpay.rb +298 -0
  85. data/lib/active_merchant/billing/gateways/psigate.rb +219 -0
  86. data/lib/active_merchant/billing/gateways/psl_card.rb +304 -0
  87. data/lib/active_merchant/billing/gateways/qbms.rb +297 -0
  88. data/lib/active_merchant/billing/gateways/quantum.rb +282 -0
  89. data/lib/active_merchant/billing/gateways/quickpay.rb +298 -0
  90. data/lib/active_merchant/billing/gateways/realex.rb +315 -0
  91. data/lib/active_merchant/billing/gateways/sage.rb +146 -0
  92. data/lib/active_merchant/billing/gateways/sage/sage_bankcard.rb +88 -0
  93. data/lib/active_merchant/billing/gateways/sage/sage_core.rb +116 -0
  94. data/lib/active_merchant/billing/gateways/sage/sage_virtual_check.rb +97 -0
  95. data/lib/active_merchant/billing/gateways/sage_pay.rb +320 -0
  96. data/lib/active_merchant/billing/gateways/sallie_mae.rb +144 -0
  97. data/lib/active_merchant/billing/gateways/samurai.rb +121 -0
  98. data/lib/active_merchant/billing/gateways/secure_net.rb +330 -0
  99. data/lib/active_merchant/billing/gateways/secure_pay.rb +31 -0
  100. data/lib/active_merchant/billing/gateways/secure_pay_au.rb +280 -0
  101. data/lib/active_merchant/billing/gateways/secure_pay_tech.rb +113 -0
  102. data/lib/active_merchant/billing/gateways/skip_jack.rb +458 -0
  103. data/lib/active_merchant/billing/gateways/smart_ps.rb +271 -0
  104. data/lib/active_merchant/billing/gateways/stripe.rb +244 -0
  105. data/lib/active_merchant/billing/gateways/trans_first.rb +127 -0
  106. data/lib/active_merchant/billing/gateways/transax.rb +25 -0
  107. data/lib/active_merchant/billing/gateways/trust_commerce.rb +423 -0
  108. data/lib/active_merchant/billing/gateways/usa_epay.rb +23 -0
  109. data/lib/active_merchant/billing/gateways/usa_epay_advanced.rb +1496 -0
  110. data/lib/active_merchant/billing/gateways/usa_epay_transaction.rb +206 -0
  111. data/lib/active_merchant/billing/gateways/verifi.rb +233 -0
  112. data/lib/active_merchant/billing/gateways/viaklix.rb +189 -0
  113. data/lib/active_merchant/billing/gateways/wirecard.rb +318 -0
  114. data/lib/active_merchant/billing/gateways/worldpay.rb +280 -0
  115. data/lib/active_merchant/billing/integrations.rb +17 -0
  116. data/lib/active_merchant/billing/integrations/action_view_helper.rb +72 -0
  117. data/lib/active_merchant/billing/integrations/authorize_net_sim.rb +38 -0
  118. data/lib/active_merchant/billing/integrations/authorize_net_sim/helper.rb +228 -0
  119. data/lib/active_merchant/billing/integrations/authorize_net_sim/notification.rb +340 -0
  120. data/lib/active_merchant/billing/integrations/bogus.rb +23 -0
  121. data/lib/active_merchant/billing/integrations/bogus/helper.rb +17 -0
  122. data/lib/active_merchant/billing/integrations/bogus/notification.rb +11 -0
  123. data/lib/active_merchant/billing/integrations/bogus/return.rb +10 -0
  124. data/lib/active_merchant/billing/integrations/chronopay.rb +23 -0
  125. data/lib/active_merchant/billing/integrations/chronopay/helper.rb +120 -0
  126. data/lib/active_merchant/billing/integrations/chronopay/notification.rb +158 -0
  127. data/lib/active_merchant/billing/integrations/chronopay/return.rb +10 -0
  128. data/lib/active_merchant/billing/integrations/direc_pay.rb +41 -0
  129. data/lib/active_merchant/billing/integrations/direc_pay/helper.rb +200 -0
  130. data/lib/active_merchant/billing/integrations/direc_pay/notification.rb +76 -0
  131. data/lib/active_merchant/billing/integrations/direc_pay/return.rb +32 -0
  132. data/lib/active_merchant/billing/integrations/direc_pay/status.rb +37 -0
  133. data/lib/active_merchant/billing/integrations/directebanking.rb +47 -0
  134. data/lib/active_merchant/billing/integrations/directebanking/helper.rb +90 -0
  135. data/lib/active_merchant/billing/integrations/directebanking/notification.rb +120 -0
  136. data/lib/active_merchant/billing/integrations/directebanking/return.rb +11 -0
  137. data/lib/active_merchant/billing/integrations/dwolla.rb +30 -0
  138. data/lib/active_merchant/billing/integrations/dwolla/helper.rb +31 -0
  139. data/lib/active_merchant/billing/integrations/dwolla/notification.rb +55 -0
  140. data/lib/active_merchant/billing/integrations/dwolla/return.rb +38 -0
  141. data/lib/active_merchant/billing/integrations/e_payment_plans.rb +48 -0
  142. data/lib/active_merchant/billing/integrations/e_payment_plans/helper.rb +34 -0
  143. data/lib/active_merchant/billing/integrations/e_payment_plans/notification.rb +84 -0
  144. data/lib/active_merchant/billing/integrations/gestpay.rb +25 -0
  145. data/lib/active_merchant/billing/integrations/gestpay/common.rb +42 -0
  146. data/lib/active_merchant/billing/integrations/gestpay/helper.rb +70 -0
  147. data/lib/active_merchant/billing/integrations/gestpay/notification.rb +85 -0
  148. data/lib/active_merchant/billing/integrations/gestpay/return.rb +10 -0
  149. data/lib/active_merchant/billing/integrations/helper.rb +113 -0
  150. data/lib/active_merchant/billing/integrations/hi_trust.rb +27 -0
  151. data/lib/active_merchant/billing/integrations/hi_trust/helper.rb +58 -0
  152. data/lib/active_merchant/billing/integrations/hi_trust/notification.rb +59 -0
  153. data/lib/active_merchant/billing/integrations/hi_trust/return.rb +67 -0
  154. data/lib/active_merchant/billing/integrations/moneybookers.rb +26 -0
  155. data/lib/active_merchant/billing/integrations/moneybookers/helper.rb +59 -0
  156. data/lib/active_merchant/billing/integrations/moneybookers/notification.rb +129 -0
  157. data/lib/active_merchant/billing/integrations/nochex.rb +88 -0
  158. data/lib/active_merchant/billing/integrations/nochex/helper.rb +68 -0
  159. data/lib/active_merchant/billing/integrations/nochex/notification.rb +94 -0
  160. data/lib/active_merchant/billing/integrations/nochex/return.rb +10 -0
  161. data/lib/active_merchant/billing/integrations/notification.rb +62 -0
  162. data/lib/active_merchant/billing/integrations/payflow_link.rb +21 -0
  163. data/lib/active_merchant/billing/integrations/payflow_link/helper.rb +100 -0
  164. data/lib/active_merchant/billing/integrations/payflow_link/notification.rb +78 -0
  165. data/lib/active_merchant/billing/integrations/paypal.rb +39 -0
  166. data/lib/active_merchant/billing/integrations/paypal/helper.rb +119 -0
  167. data/lib/active_merchant/billing/integrations/paypal/notification.rb +154 -0
  168. data/lib/active_merchant/billing/integrations/paypal/return.rb +10 -0
  169. data/lib/active_merchant/billing/integrations/quickpay.rb +21 -0
  170. data/lib/active_merchant/billing/integrations/quickpay/helper.rb +72 -0
  171. data/lib/active_merchant/billing/integrations/quickpay/notification.rb +74 -0
  172. data/lib/active_merchant/billing/integrations/return.rb +42 -0
  173. data/lib/active_merchant/billing/integrations/sage_pay_form.rb +37 -0
  174. data/lib/active_merchant/billing/integrations/sage_pay_form/encryption.rb +33 -0
  175. data/lib/active_merchant/billing/integrations/sage_pay_form/helper.rb +127 -0
  176. data/lib/active_merchant/billing/integrations/sage_pay_form/notification.rb +210 -0
  177. data/lib/active_merchant/billing/integrations/sage_pay_form/return.rb +31 -0
  178. data/lib/active_merchant/billing/integrations/two_checkout.rb +22 -0
  179. data/lib/active_merchant/billing/integrations/two_checkout/helper.rb +59 -0
  180. data/lib/active_merchant/billing/integrations/two_checkout/notification.rb +114 -0
  181. data/lib/active_merchant/billing/integrations/two_checkout/return.rb +17 -0
  182. data/lib/active_merchant/billing/integrations/valitor.rb +33 -0
  183. data/lib/active_merchant/billing/integrations/valitor/helper.rb +86 -0
  184. data/lib/active_merchant/billing/integrations/valitor/notification.rb +13 -0
  185. data/lib/active_merchant/billing/integrations/valitor/response_fields.rb +97 -0
  186. data/lib/active_merchant/billing/integrations/valitor/return.rb +13 -0
  187. data/lib/active_merchant/billing/integrations/world_pay.rb +27 -0
  188. data/lib/active_merchant/billing/integrations/world_pay/helper.rb +100 -0
  189. data/lib/active_merchant/billing/integrations/world_pay/notification.rb +160 -0
  190. data/lib/active_merchant/billing/response.rb +32 -0
  191. data/lib/active_merchant/version.rb +3 -0
  192. data/lib/activemerchant.rb +1 -0
  193. data/lib/support/gateway_support.rb +58 -0
  194. data/lib/support/outbound_hosts.rb +25 -0
  195. metadata +411 -0
@@ -0,0 +1,944 @@
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
+ send("build_#{action}_request", xml, options)
490
+ end
491
+ end
492
+
493
+ # Contains the merchant’s payment gateway account authentication information
494
+ def add_merchant_authentication(xml)
495
+ xml.tag!('merchantAuthentication') do
496
+ xml.tag!('name', @options[:login])
497
+ xml.tag!('transactionKey', @options[:password])
498
+ end
499
+ end
500
+
501
+ def build_create_customer_profile_request(xml, options)
502
+ add_profile(xml, options[:profile])
503
+
504
+ xml.tag!('validationMode', CIM_VALIDATION_MODES[options[:validation_mode]]) if options[:validation_mode]
505
+
506
+ if options.has_key?(:payment_profile)
507
+ xml.tag!('paymentProfile') do
508
+ add_payment_profile(xml, options[:payment_profile])
509
+ end
510
+ end
511
+
512
+ xml.target!
513
+ end
514
+
515
+ def build_create_customer_payment_profile_request(xml, options)
516
+ xml.tag!('customerProfileId', options[:customer_profile_id])
517
+
518
+ xml.tag!('paymentProfile') do
519
+ add_payment_profile(xml, options[:payment_profile])
520
+ end
521
+
522
+ xml.tag!('validationMode', CIM_VALIDATION_MODES[options[:validation_mode]]) if options[:validation_mode]
523
+
524
+ xml.target!
525
+ end
526
+
527
+ def build_create_customer_shipping_address_request(xml, options)
528
+ xml.tag!('customerProfileId', options[:customer_profile_id])
529
+
530
+ xml.tag!('address') do
531
+ add_address(xml, options[:address])
532
+ end
533
+
534
+ xml.target!
535
+ end
536
+
537
+ def build_delete_customer_profile_request(xml, options)
538
+ xml.tag!('customerProfileId', options[:customer_profile_id])
539
+ xml.target!
540
+ end
541
+
542
+ def build_delete_customer_payment_profile_request(xml, options)
543
+ xml.tag!('customerProfileId', options[:customer_profile_id])
544
+ xml.tag!('customerPaymentProfileId', options[:customer_payment_profile_id])
545
+ xml.target!
546
+ end
547
+
548
+ def build_delete_customer_shipping_address_request(xml, options)
549
+ xml.tag!('customerProfileId', options[:customer_profile_id])
550
+ xml.tag!('customerAddressId', options[:customer_address_id])
551
+ xml.target!
552
+ end
553
+
554
+ def build_get_customer_profile_request(xml, options)
555
+ xml.tag!('customerProfileId', options[:customer_profile_id])
556
+ xml.target!
557
+ end
558
+
559
+ def build_get_customer_profile_ids_request(xml, options)
560
+ xml.target!
561
+ end
562
+
563
+ def build_get_customer_payment_profile_request(xml, options)
564
+ xml.tag!('customerProfileId', options[:customer_profile_id])
565
+ xml.tag!('customerPaymentProfileId', options[:customer_payment_profile_id])
566
+ xml.target!
567
+ end
568
+
569
+ def build_get_customer_shipping_address_request(xml, options)
570
+ xml.tag!('customerProfileId', options[:customer_profile_id])
571
+ xml.tag!('customerAddressId', options[:customer_address_id])
572
+ xml.target!
573
+ end
574
+
575
+ def build_update_customer_profile_request(xml, options)
576
+ add_profile(xml, options[:profile], true)
577
+
578
+ xml.target!
579
+ end
580
+
581
+ def build_update_customer_payment_profile_request(xml, options)
582
+ xml.tag!('customerProfileId', options[:customer_profile_id])
583
+
584
+ xml.tag!('paymentProfile') do
585
+ add_payment_profile(xml, options[:payment_profile])
586
+ end
587
+
588
+ xml.tag!('validationMode', CIM_VALIDATION_MODES[options[:validation_mode]]) if options[:validation_mode]
589
+
590
+ xml.target!
591
+ end
592
+
593
+ def build_update_customer_shipping_address_request(xml, options)
594
+ xml.tag!('customerProfileId', options[:customer_profile_id])
595
+
596
+ xml.tag!('address') do
597
+ add_address(xml, options[:address])
598
+ end
599
+
600
+ xml.target!
601
+ end
602
+
603
+ def build_create_customer_profile_transaction_request(xml, options)
604
+ add_transaction(xml, options[:transaction])
605
+ xml.tag!('extraOptions', "x_test_request=TRUE") if @options[:test]
606
+
607
+ xml.target!
608
+ end
609
+
610
+ def build_validate_customer_payment_profile_request(xml, options)
611
+ xml.tag!('customerProfileId', options[:customer_profile_id])
612
+ xml.tag!('customerPaymentProfileId', options[:customer_payment_profile_id])
613
+ xml.tag!('customerShippingAddressId', options[:customer_address_id]) if options[:customer_address_id]
614
+ tag_unless_blank(xml, 'cardCode', options[:card_code])
615
+ xml.tag!('validationMode', CIM_VALIDATION_MODES[options[:validation_mode]]) if options[:validation_mode]
616
+
617
+ xml.target!
618
+ end
619
+
620
+ # :merchant_customer_id (Optional)
621
+ # :description (Optional)
622
+ # :email (Optional)
623
+ # :payment_profiles (Optional)
624
+ def add_profile(xml, profile, update = false)
625
+ xml.tag!('profile') do
626
+ # Merchant assigned ID for the customer. Up to 20 characters. (optional)
627
+ xml.tag!('merchantCustomerId', profile[:merchant_customer_id]) if profile[:merchant_customer_id]
628
+ # Description of the customer. Up to 255 Characters (optional)
629
+ xml.tag!('description', profile[:description]) if profile[:description]
630
+ # Email Address for the customer. Up to 255 Characters (optional)
631
+ xml.tag!('email', profile[:email]) if profile[:email]
632
+
633
+ if update
634
+ xml.tag!('customerProfileId', profile[:customer_profile_id])
635
+ else
636
+ add_payment_profiles(xml, profile[:payment_profiles]) if profile[:payment_profiles]
637
+ add_ship_to_list(xml, profile[:ship_to_list]) if profile[:ship_to_list]
638
+ end
639
+ end
640
+ end
641
+
642
+ def add_transaction(xml, transaction)
643
+ unless CIM_TRANSACTION_TYPES.include?(transaction[:type])
644
+ raise StandardError, "Invalid Customer Information Manager Transaction Type: #{transaction[:type]}"
645
+ end
646
+
647
+ xml.tag!('transaction') do
648
+ xml.tag!(CIM_TRANSACTION_TYPES[transaction[:type]]) do
649
+ # The amount to be billed to the customer
650
+ case transaction[:type]
651
+ when :void
652
+ tag_unless_blank(xml,'customerProfileId', transaction[:customer_profile_id])
653
+ tag_unless_blank(xml,'customerPaymentProfileId', transaction[:customer_payment_profile_id])
654
+ tag_unless_blank(xml,'customerShippingAddressId', transaction[:customer_shipping_address_id])
655
+ xml.tag!('transId', transaction[:trans_id])
656
+ when :refund
657
+ #TODO - add lineItems and extraOptions fields
658
+ xml.tag!('amount', transaction[:amount])
659
+ tag_unless_blank(xml, 'customerProfileId', transaction[:customer_profile_id])
660
+ tag_unless_blank(xml, 'customerPaymentProfileId', transaction[:customer_payment_profile_id])
661
+ tag_unless_blank(xml, 'customerShippingAddressId', transaction[:customer_shipping_address_id])
662
+ tag_unless_blank(xml, 'creditCardNumberMasked', transaction[:credit_card_number_masked])
663
+ tag_unless_blank(xml, 'bankRoutingNumberMasked', transaction[:bank_routing_number_masked])
664
+ tag_unless_blank(xml, 'bankAccountNumberMasked', transaction[:bank_account_number_masked])
665
+ xml.tag!('transId', transaction[:trans_id])
666
+ add_tax(xml, transaction[:tax]) if transaction[:tax]
667
+ add_duty(xml, transaction[:duty]) if transaction[:duty]
668
+ add_shipping(xml, transaction[:shipping]) if transaction[:shipping]
669
+ when :prior_auth_capture
670
+ xml.tag!('amount', transaction[:amount])
671
+ xml.tag!('transId', transaction[:trans_id])
672
+ else
673
+ xml.tag!('amount', transaction[:amount])
674
+ xml.tag!('customerProfileId', transaction[:customer_profile_id])
675
+ xml.tag!('customerPaymentProfileId', transaction[:customer_payment_profile_id])
676
+ xml.tag!('approvalCode', transaction[:approval_code]) if transaction[:type] == :capture_only
677
+ tag_unless_blank(xml, 'cardCode', transaction[:card_code])
678
+ end
679
+ add_order(xml, transaction[:order]) if transaction[:order].present?
680
+ end
681
+ end
682
+ end
683
+
684
+ def add_tax(xml, tax)
685
+ xml.tag!('tax') do
686
+ xml.tag!('amount', tax[:amount]) if tax[:amount]
687
+ xml.tag!('name', tax[:name]) if tax[:name]
688
+ xml.tag!('description', tax[:description]) if tax[:description]
689
+ end
690
+ end
691
+
692
+ def add_duty(xml, duty)
693
+ xml.tag!('duty') do
694
+ xml.tag!('amount', duty[:amount]) if duty[:amount]
695
+ xml.tag!('name', duty[:name]) if duty[:name]
696
+ xml.tag!('description', duty[:description]) if duty[:description]
697
+ end
698
+ end
699
+
700
+ def add_shipping(xml, shipping)
701
+ xml.tag!('shipping') do
702
+ xml.tag!('amount', shipping[:amount]) if shipping[:amount]
703
+ xml.tag!('name', shipping[:name]) if shipping[:name]
704
+ xml.tag!('description', shipping[:description]) if shipping[:description]
705
+ end
706
+ end
707
+
708
+ def add_order(xml, order)
709
+ xml.tag!('order') do
710
+ xml.tag!('invoiceNumber', order[:invoice_number]) if order[:invoice_number]
711
+ xml.tag!('description', order[:description]) if order[:description]
712
+ xml.tag!('purchaseOrderNumber', order[:purchase_order_number]) if order[:purchase_order_number]
713
+ end
714
+ end
715
+
716
+ def add_payment_profiles(xml, payment_profiles)
717
+ xml.tag!('paymentProfiles') do
718
+ add_payment_profile(xml, payment_profiles)
719
+ end
720
+ end
721
+
722
+ # :customer_type => 'individual or business', # Optional
723
+ # :bill_to => @address,
724
+ # :payment => @payment
725
+ def add_payment_profile(xml, payment_profile)
726
+ # 'individual' or 'business' (optional)
727
+ xml.tag!('customerType', payment_profile[:customer_type]) if payment_profile[:customer_type]
728
+
729
+ if payment_profile[:bill_to]
730
+ xml.tag!('billTo') do
731
+ add_address(xml, payment_profile[:bill_to])
732
+ end
733
+ end
734
+
735
+ if payment_profile[:payment]
736
+ xml.tag!('payment') do
737
+ add_credit_card(xml, payment_profile[:payment][:credit_card]) if payment_profile[:payment].has_key?(:credit_card)
738
+ add_bank_account(xml, payment_profile[:payment][:bank_account]) if payment_profile[:payment].has_key?(:bank_account)
739
+ add_drivers_license(xml, payment_profile[:payment][:drivers_license]) if payment_profile[:payment].has_key?(:drivers_license)
740
+ # This element is only required for Wells Fargo SecureSource eCheck.Net merchants
741
+ # The customer's Social Security Number or Tax ID
742
+ xml.tag!('taxId', payment_profile[:payment]) if payment_profile[:payment].has_key?(:tax_id)
743
+ end
744
+ end
745
+
746
+ xml.tag!('customerPaymentProfileId', payment_profile[:customer_payment_profile_id]) if payment_profile[:customer_payment_profile_id]
747
+ end
748
+
749
+ def add_ship_to_list(xml, ship_to_list)
750
+ xml.tag!('shipToList') do
751
+ add_address(xml, ship_to_list)
752
+ end
753
+ end
754
+
755
+ def add_address(xml, address)
756
+ xml.tag!('firstName', address[:first_name])
757
+ xml.tag!('lastName', address[:last_name])
758
+ xml.tag!('company', address[:company])
759
+ xml.tag!('address', address[:address1]) if address[:address1]
760
+ xml.tag!('address', address[:address]) if address[:address]
761
+ xml.tag!('city', address[:city])
762
+ xml.tag!('state', address[:state])
763
+ xml.tag!('zip', address[:zip])
764
+ xml.tag!('country', address[:country])
765
+ xml.tag!('phoneNumber', address[:phone_number]) if address[:phone_number]
766
+ xml.tag!('faxNumber', address[:fax_number]) if address[:fax_number]
767
+
768
+ xml.tag!('customerAddressId', address[:customer_address_id]) if address[:customer_address_id]
769
+ end
770
+
771
+ # Adds customer’s credit card information
772
+ # Note: This element should only be included
773
+ # when the payment method is credit card.
774
+ def add_credit_card(xml, credit_card)
775
+ return unless credit_card
776
+ xml.tag!('creditCard') do
777
+ # The credit card number used for payment of the subscription
778
+ xml.tag!('cardNumber', credit_card.number)
779
+ # The expiration date of the credit card used for the subscription
780
+ xml.tag!('expirationDate', expdate(credit_card))
781
+ # Note that Authorize.net does not save CVV codes as part of the
782
+ # payment profile. Any transactions/validations after the payment
783
+ # profile is created that wish to use CVV verification must pass
784
+ # the CVV code to authorize.net again.
785
+ xml.tag!('cardCode', credit_card.verification_value) if credit_card.verification_value?
786
+ end
787
+ end
788
+
789
+ # Adds customer’s bank account information
790
+ # Note: This element should only be included
791
+ # when the payment method is bank account.
792
+ def add_bank_account(xml, bank_account)
793
+ raise StandardError, "Invalid Bank Account Type: #{bank_account[:account_type]}" unless BANK_ACCOUNT_TYPES.include?(bank_account[:account_type])
794
+ raise StandardError, "Invalid eCheck Type: #{bank_account[:echeck_type]}" unless ECHECK_TYPES.include?(bank_account[:echeck_type])
795
+
796
+ xml.tag!('bankAccount') do
797
+ # The type of bank account
798
+ xml.tag!('accountType', BANK_ACCOUNT_TYPES[bank_account[:account_type]])
799
+ # The routing number of the customer’s bank
800
+ xml.tag!('routingNumber', bank_account[:routing_number])
801
+ # The bank account number
802
+ xml.tag!('accountNumber', bank_account[:account_number])
803
+ # The full name of the individual associated
804
+ # with the bank account number
805
+ xml.tag!('nameOnAccount', bank_account[:name_on_account])
806
+ # The type of electronic check transaction
807
+ xml.tag!('echeckType', ECHECK_TYPES[bank_account[:echeck_type]])
808
+ # The full name of the individual associated
809
+ # with the bank account number (optional)
810
+ xml.tag!('bankName', bank_account[:bank_name]) if bank_account[:bank_name]
811
+ end
812
+ end
813
+
814
+ # Adds customer’s driver's license information
815
+ # Note: This element is only required for
816
+ # Wells Fargo SecureSource eCheck.Net merchants
817
+ def add_drivers_license(xml, drivers_license)
818
+ xml.tag!('driversLicense') do
819
+ # The state of the customer's driver's license
820
+ # A valid two character state code
821
+ xml.tag!('state', drivers_license[:state])
822
+ # The customer’s driver's license number
823
+ xml.tag!('number', drivers_license[:number])
824
+ # The date of birth listed on the customer's driver's license
825
+ # YYYY-MM-DD
826
+ xml.tag!('dateOfBirth', drivers_license[:date_of_birth])
827
+ end
828
+ end
829
+
830
+ def commit(action, request)
831
+ url = test? ? test_url : live_url
832
+ xml = ssl_post(url, request, "Content-Type" => "text/xml")
833
+
834
+ response_params = parse(action, xml)
835
+
836
+ message = response_params['messages']['message']['text']
837
+ test_mode = test? || message =~ /Test Mode/
838
+ success = response_params['messages']['result_code'] == 'Ok'
839
+ response_params['direct_response'] = parse_direct_response(response_params['direct_response']) if response_params['direct_response']
840
+ transaction_id = response_params['direct_response']['transaction_id'] if response_params['direct_response']
841
+
842
+ Response.new(success, message, response_params,
843
+ :test => test_mode,
844
+ :authorization => transaction_id || response_params['customer_profile_id'] || (response_params['profile'] ? response_params['profile']['customer_profile_id'] : nil)
845
+ )
846
+ end
847
+
848
+ def tag_unless_blank(xml, tag_name, data)
849
+ xml.tag!(tag_name, data) unless data.blank? || data.nil?
850
+ end
851
+
852
+ def parse_direct_response(params)
853
+ delimiter = @options[:delimiter] || ','
854
+ direct_response = {'raw' => params}
855
+ direct_response_fields = params.split(delimiter)
856
+ direct_response.merge(
857
+ {
858
+ 'response_code' => direct_response_fields[0],
859
+ 'response_subcode' => direct_response_fields[1],
860
+ 'response_reason_code' => direct_response_fields[2],
861
+ 'message' => direct_response_fields[3],
862
+ 'approval_code' => direct_response_fields[4],
863
+ 'avs_response' => direct_response_fields[5],
864
+ 'transaction_id' => direct_response_fields[6],
865
+ 'invoice_number' => direct_response_fields[7],
866
+ 'order_description' => direct_response_fields[8],
867
+ 'amount' => direct_response_fields[9],
868
+ 'method' => direct_response_fields[10],
869
+ 'transaction_type' => direct_response_fields[11],
870
+ 'customer_id' => direct_response_fields[12],
871
+ 'first_name' => direct_response_fields[13],
872
+ 'last_name' => direct_response_fields[14],
873
+ 'company' => direct_response_fields[15],
874
+ 'address' => direct_response_fields[16],
875
+ 'city' => direct_response_fields[17],
876
+ 'state' => direct_response_fields[18],
877
+ 'zip_code' => direct_response_fields[19],
878
+ 'country' => direct_response_fields[20],
879
+ 'phone' => direct_response_fields[21],
880
+ 'fax' => direct_response_fields[22],
881
+ 'email_address' => direct_response_fields[23],
882
+ 'ship_to_first_name' => direct_response_fields[24],
883
+ 'ship_to_last_name' => direct_response_fields[25],
884
+ 'ship_to_company' => direct_response_fields[26],
885
+ 'ship_to_address' => direct_response_fields[27],
886
+ 'ship_to_city' => direct_response_fields[28],
887
+ 'ship_to_state' => direct_response_fields[29],
888
+ 'ship_to_zip_code' => direct_response_fields[30],
889
+ 'ship_to_country' => direct_response_fields[31],
890
+ 'tax' => direct_response_fields[32],
891
+ 'duty' => direct_response_fields[33],
892
+ 'freight' => direct_response_fields[34],
893
+ 'tax_exempt' => direct_response_fields[35],
894
+ 'purchase_order_number' => direct_response_fields[36],
895
+ 'md5_hash' => direct_response_fields[37],
896
+ 'card_code' => direct_response_fields[38],
897
+ 'cardholder_authentication_verification_response' => direct_response_fields[39],
898
+ # The following direct response fields are only available in version 3.1 of the
899
+ # transaction response. Check your merchant account settings for details.
900
+ 'account_number' => direct_response_fields[50] || '',
901
+ 'card_type' => direct_response_fields[51] || '',
902
+ 'split_tender_id' => direct_response_fields[52] || '',
903
+ 'requested_amount' => direct_response_fields[53] || '',
904
+ 'balance_on_card' => direct_response_fields[54] || '',
905
+ }
906
+ )
907
+ end
908
+
909
+ def parse(action, xml)
910
+ xml = REXML::Document.new(xml)
911
+ root = REXML::XPath.first(xml, "//#{CIM_ACTIONS[action]}Response") ||
912
+ REXML::XPath.first(xml, "//ErrorResponse")
913
+ if root
914
+ response = parse_element(root)
915
+ end
916
+
917
+ response
918
+ end
919
+
920
+ def parse_element(node)
921
+ if node.has_elements?
922
+ response = {}
923
+ node.elements.each{ |e|
924
+ key = e.name.underscore
925
+ value = parse_element(e)
926
+ if response.has_key?(key)
927
+ if response[key].is_a?(Array)
928
+ response[key].push(value)
929
+ else
930
+ response[key] = [response[key], value]
931
+ end
932
+ else
933
+ response[key] = parse_element(e)
934
+ end
935
+ }
936
+ else
937
+ response = node.text
938
+ end
939
+
940
+ response
941
+ end
942
+ end
943
+ end
944
+ end