vibedeck-activemerchant 1.18.2

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