fishman-activemerchant 1.18.0

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