humanzz-activemerchant 1.7.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (139) hide show
  1. data/CHANGELOG +530 -0
  2. data/CONTRIBUTORS +142 -0
  3. data/MIT-LICENSE +20 -0
  4. data/README.rdoc +136 -0
  5. data/gem-public_cert.pem +20 -0
  6. data/lib/active_merchant/billing/avs_result.rb +98 -0
  7. data/lib/active_merchant/billing/base.rb +57 -0
  8. data/lib/active_merchant/billing/check.rb +68 -0
  9. data/lib/active_merchant/billing/credit_card.rb +159 -0
  10. data/lib/active_merchant/billing/credit_card_formatting.rb +21 -0
  11. data/lib/active_merchant/billing/credit_card_methods.rb +125 -0
  12. data/lib/active_merchant/billing/cvv_result.rb +38 -0
  13. data/lib/active_merchant/billing/expiry_date.rb +34 -0
  14. data/lib/active_merchant/billing/gateway.rb +163 -0
  15. data/lib/active_merchant/billing/gateways/authorize_net.rb +654 -0
  16. data/lib/active_merchant/billing/gateways/authorize_net_cim.rb +855 -0
  17. data/lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb +244 -0
  18. data/lib/active_merchant/billing/gateways/beanstream.rb +102 -0
  19. data/lib/active_merchant/billing/gateways/beanstream_interac.rb +54 -0
  20. data/lib/active_merchant/billing/gateways/bogus.rb +102 -0
  21. data/lib/active_merchant/billing/gateways/braintree/braintree_common.rb +9 -0
  22. data/lib/active_merchant/billing/gateways/braintree.rb +17 -0
  23. data/lib/active_merchant/billing/gateways/braintree_blue.rb +210 -0
  24. data/lib/active_merchant/billing/gateways/braintree_orange.rb +17 -0
  25. data/lib/active_merchant/billing/gateways/card_stream.rb +230 -0
  26. data/lib/active_merchant/billing/gateways/cyber_source.rb +406 -0
  27. data/lib/active_merchant/billing/gateways/data_cash.rb +593 -0
  28. data/lib/active_merchant/billing/gateways/efsnet.rb +229 -0
  29. data/lib/active_merchant/billing/gateways/elavon.rb +134 -0
  30. data/lib/active_merchant/billing/gateways/eway.rb +277 -0
  31. data/lib/active_merchant/billing/gateways/exact.rb +222 -0
  32. data/lib/active_merchant/billing/gateways/first_pay.rb +172 -0
  33. data/lib/active_merchant/billing/gateways/garanti.rb +222 -0
  34. data/lib/active_merchant/billing/gateways/instapay.rb +164 -0
  35. data/lib/active_merchant/billing/gateways/jetpay.rb +270 -0
  36. data/lib/active_merchant/billing/gateways/linkpoint.rb +449 -0
  37. data/lib/active_merchant/billing/gateways/merchant_e_solutions.rb +154 -0
  38. data/lib/active_merchant/billing/gateways/merchant_ware.rb +283 -0
  39. data/lib/active_merchant/billing/gateways/modern_payments.rb +36 -0
  40. data/lib/active_merchant/billing/gateways/modern_payments_cim.rb +220 -0
  41. data/lib/active_merchant/billing/gateways/moneris.rb +205 -0
  42. data/lib/active_merchant/billing/gateways/net_registry.rb +189 -0
  43. data/lib/active_merchant/billing/gateways/netbilling.rb +168 -0
  44. data/lib/active_merchant/billing/gateways/ogone.rb +279 -0
  45. data/lib/active_merchant/billing/gateways/pay_junction.rb +392 -0
  46. data/lib/active_merchant/billing/gateways/pay_secure.rb +120 -0
  47. data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +207 -0
  48. data/lib/active_merchant/billing/gateways/payflow/payflow_express_response.rb +39 -0
  49. data/lib/active_merchant/billing/gateways/payflow/payflow_response.rb +13 -0
  50. data/lib/active_merchant/billing/gateways/payflow.rb +236 -0
  51. data/lib/active_merchant/billing/gateways/payflow_express.rb +138 -0
  52. data/lib/active_merchant/billing/gateways/payflow_express_uk.rb +15 -0
  53. data/lib/active_merchant/billing/gateways/payflow_uk.rb +21 -0
  54. data/lib/active_merchant/billing/gateways/payment_express.rb +230 -0
  55. data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +326 -0
  56. data/lib/active_merchant/billing/gateways/paypal/paypal_express_response.rb +38 -0
  57. data/lib/active_merchant/billing/gateways/paypal.rb +121 -0
  58. data/lib/active_merchant/billing/gateways/paypal_ca.rb +13 -0
  59. data/lib/active_merchant/billing/gateways/paypal_express.rb +135 -0
  60. data/lib/active_merchant/billing/gateways/paypal_express_common.rb +20 -0
  61. data/lib/active_merchant/billing/gateways/plugnpay.rb +292 -0
  62. data/lib/active_merchant/billing/gateways/psigate.rb +214 -0
  63. data/lib/active_merchant/billing/gateways/psl_card.rb +304 -0
  64. data/lib/active_merchant/billing/gateways/quickpay.rb +213 -0
  65. data/lib/active_merchant/billing/gateways/realex.rb +200 -0
  66. data/lib/active_merchant/billing/gateways/sage/sage_bankcard.rb +88 -0
  67. data/lib/active_merchant/billing/gateways/sage/sage_core.rb +116 -0
  68. data/lib/active_merchant/billing/gateways/sage/sage_virtual_check.rb +97 -0
  69. data/lib/active_merchant/billing/gateways/sage.rb +146 -0
  70. data/lib/active_merchant/billing/gateways/sage_pay.rb +309 -0
  71. data/lib/active_merchant/billing/gateways/sallie_mae.rb +144 -0
  72. data/lib/active_merchant/billing/gateways/secure_pay.rb +31 -0
  73. data/lib/active_merchant/billing/gateways/secure_pay_au.rb +157 -0
  74. data/lib/active_merchant/billing/gateways/secure_pay_tech.rb +113 -0
  75. data/lib/active_merchant/billing/gateways/skip_jack.rb +453 -0
  76. data/lib/active_merchant/billing/gateways/smart_ps.rb +265 -0
  77. data/lib/active_merchant/billing/gateways/trans_first.rb +127 -0
  78. data/lib/active_merchant/billing/gateways/transax.rb +25 -0
  79. data/lib/active_merchant/billing/gateways/trust_commerce.rb +418 -0
  80. data/lib/active_merchant/billing/gateways/usa_epay.rb +194 -0
  81. data/lib/active_merchant/billing/gateways/verifi.rb +228 -0
  82. data/lib/active_merchant/billing/gateways/viaklix.rb +189 -0
  83. data/lib/active_merchant/billing/gateways/wirecard.rb +318 -0
  84. data/lib/active_merchant/billing/gateways.rb +18 -0
  85. data/lib/active_merchant/billing/integrations/action_view_helper.rb +79 -0
  86. data/lib/active_merchant/billing/integrations/bogus/helper.rb +17 -0
  87. data/lib/active_merchant/billing/integrations/bogus/notification.rb +11 -0
  88. data/lib/active_merchant/billing/integrations/bogus/return.rb +10 -0
  89. data/lib/active_merchant/billing/integrations/bogus.rb +23 -0
  90. data/lib/active_merchant/billing/integrations/chronopay/helper.rb +120 -0
  91. data/lib/active_merchant/billing/integrations/chronopay/notification.rb +158 -0
  92. data/lib/active_merchant/billing/integrations/chronopay/return.rb +10 -0
  93. data/lib/active_merchant/billing/integrations/chronopay.rb +23 -0
  94. data/lib/active_merchant/billing/integrations/gestpay/common.rb +42 -0
  95. data/lib/active_merchant/billing/integrations/gestpay/helper.rb +70 -0
  96. data/lib/active_merchant/billing/integrations/gestpay/notification.rb +85 -0
  97. data/lib/active_merchant/billing/integrations/gestpay/return.rb +10 -0
  98. data/lib/active_merchant/billing/integrations/gestpay.rb +25 -0
  99. data/lib/active_merchant/billing/integrations/helper.rb +93 -0
  100. data/lib/active_merchant/billing/integrations/hi_trust/helper.rb +58 -0
  101. data/lib/active_merchant/billing/integrations/hi_trust/notification.rb +59 -0
  102. data/lib/active_merchant/billing/integrations/hi_trust/return.rb +67 -0
  103. data/lib/active_merchant/billing/integrations/hi_trust.rb +27 -0
  104. data/lib/active_merchant/billing/integrations/nochex/helper.rb +68 -0
  105. data/lib/active_merchant/billing/integrations/nochex/notification.rb +94 -0
  106. data/lib/active_merchant/billing/integrations/nochex/return.rb +10 -0
  107. data/lib/active_merchant/billing/integrations/nochex.rb +88 -0
  108. data/lib/active_merchant/billing/integrations/notification.rb +62 -0
  109. data/lib/active_merchant/billing/integrations/paypal/helper.rb +119 -0
  110. data/lib/active_merchant/billing/integrations/paypal/notification.rb +154 -0
  111. data/lib/active_merchant/billing/integrations/paypal/return.rb +10 -0
  112. data/lib/active_merchant/billing/integrations/paypal.rb +39 -0
  113. data/lib/active_merchant/billing/integrations/quickpay/helper.rb +72 -0
  114. data/lib/active_merchant/billing/integrations/quickpay/notification.rb +74 -0
  115. data/lib/active_merchant/billing/integrations/quickpay.rb +17 -0
  116. data/lib/active_merchant/billing/integrations/return.rb +35 -0
  117. data/lib/active_merchant/billing/integrations/two_checkout/helper.rb +59 -0
  118. data/lib/active_merchant/billing/integrations/two_checkout/notification.rb +114 -0
  119. data/lib/active_merchant/billing/integrations/two_checkout/return.rb +17 -0
  120. data/lib/active_merchant/billing/integrations/two_checkout.rb +23 -0
  121. data/lib/active_merchant/billing/integrations.rb +29 -0
  122. data/lib/active_merchant/billing/response.rb +32 -0
  123. data/lib/active_merchant/billing.rb +9 -0
  124. data/lib/active_merchant/common/connection.rb +172 -0
  125. data/lib/active_merchant/common/country.rb +319 -0
  126. data/lib/active_merchant/common/error.rb +26 -0
  127. data/lib/active_merchant/common/post_data.rb +24 -0
  128. data/lib/active_merchant/common/posts_data.rb +47 -0
  129. data/lib/active_merchant/common/requires_parameters.rb +16 -0
  130. data/lib/active_merchant/common/utils.rb +18 -0
  131. data/lib/active_merchant/common/validateable.rb +76 -0
  132. data/lib/active_merchant/common.rb +14 -0
  133. data/lib/active_merchant/version.rb +3 -0
  134. data/lib/active_merchant.rb +47 -0
  135. data/lib/activemerchant.rb +1 -0
  136. data/lib/certs/cacert.pem +7815 -0
  137. data/lib/support/gateway_support.rb +58 -0
  138. data/lib/support/outbound_hosts.rb +25 -0
  139. metadata +251 -0
@@ -0,0 +1,855 @@
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_inheritable_accessor :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
+ }
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.target!
541
+ end
542
+
543
+ def build_update_customer_shipping_address_request(xml, options)
544
+ xml.tag!('customerProfileId', options[:customer_profile_id])
545
+
546
+ xml.tag!('address') do
547
+ add_address(xml, options[:address])
548
+ end
549
+
550
+ xml.target!
551
+ end
552
+
553
+ def build_create_customer_profile_transaction_request(xml, options)
554
+ add_transaction(xml, options[:transaction])
555
+ xml.tag!('extraOptions', "x_test_request=TRUE") if @options[:test]
556
+
557
+ xml.target!
558
+ end
559
+
560
+ def build_validate_customer_payment_profile_request(xml, options)
561
+ xml.tag!('customerProfileId', options[:customer_profile_id])
562
+ xml.tag!('customerPaymentProfileId', options[:customer_payment_profile_id])
563
+ xml.tag!('customerShippingAddressId', options[:customer_address_id]) if options[:customer_address_id]
564
+ xml.tag!('validationMode', CIM_VALIDATION_MODES[options[:validation_mode]]) if options[:validation_mode]
565
+
566
+ xml.target!
567
+ end
568
+
569
+ # :merchant_customer_id (Optional)
570
+ # :description (Optional)
571
+ # :email (Optional)
572
+ # :payment_profiles (Optional)
573
+ def add_profile(xml, profile, update = false)
574
+ xml.tag!('profile') do
575
+ # Merchant assigned ID for the customer. Up to 20 characters. (optional)
576
+ xml.tag!('merchantCustomerId', profile[:merchant_customer_id]) if profile[:merchant_customer_id]
577
+ # Description of the customer. Up to 255 Characters (optional)
578
+ xml.tag!('description', profile[:description]) if profile[:description]
579
+ # Email Address for the customer. Up to 255 Characters (optional)
580
+ xml.tag!('email', profile[:email]) if profile[:email]
581
+
582
+ if update
583
+ xml.tag!('customerProfileId', profile[:customer_profile_id])
584
+ else
585
+ add_payment_profiles(xml, profile[:payment_profiles]) if profile[:payment_profiles]
586
+ add_ship_to_list(xml, profile[:ship_to_list]) if profile[:ship_to_list]
587
+ end
588
+ end
589
+ end
590
+
591
+ def add_transaction(xml, transaction)
592
+ unless CIM_TRANSACTION_TYPES.include?(transaction[:type])
593
+ raise StandardError, "Invalid Customer Information Manager Transaction Type: #{transaction[:type]}"
594
+ end
595
+
596
+ xml.tag!('transaction') do
597
+ xml.tag!(CIM_TRANSACTION_TYPES[transaction[:type]]) do
598
+ # The amount to be billed to the customer
599
+ case transaction[:type]
600
+ when :void
601
+ tag_unless_blank(xml,'customerProfileId', transaction[:customer_profile_id])
602
+ tag_unless_blank(xml,'customerPaymentProfileId', transaction[:customer_payment_profile_id])
603
+ tag_unless_blank(xml,'customerShippingAddressId', transaction[:customer_shipping_address_id])
604
+ xml.tag!('transId', transaction[:trans_id])
605
+ when :refund
606
+ #TODO - add support for all the other options fields
607
+ xml.tag!('amount', transaction[:amount])
608
+ tag_unless_blank(xml, 'customerProfileId', transaction[:customer_profile_id])
609
+ tag_unless_blank(xml, 'customerPaymentProfileId', transaction[:customer_payment_profile_id])
610
+ tag_unless_blank(xml, 'customerShippingAddressId', transaction[:customer_shipping_address_id])
611
+ tag_unless_blank(xml, 'creditCardNumberMasked', transaction[:credit_card_number_masked])
612
+ tag_unless_blank(xml, 'bankRoutingNumberMasked', transaction[:bank_routing_number_masked])
613
+ tag_unless_blank(xml, 'bankAccountNumberMasked', transaction[:bank_account_number_masked])
614
+ xml.tag!('transId', transaction[:trans_id])
615
+ #when :prior_auth_capture
616
+ # xml.tag!('amount', transaction[:amount])
617
+ # xml.tag!('transId', transaction[:trans_id])
618
+ else
619
+ xml.tag!('amount', transaction[:amount])
620
+ xml.tag!('customerProfileId', transaction[:customer_profile_id])
621
+ xml.tag!('customerPaymentProfileId', transaction[:customer_payment_profile_id])
622
+ xml.tag!('approvalCode', transaction[:approval_code]) if transaction[:type] == :capture_only
623
+ end
624
+ add_order(xml, transaction[:order]) if transaction[:order]
625
+ end
626
+ end
627
+ end
628
+
629
+ def add_order(xml, order)
630
+ xml.tag!('order') do
631
+ xml.tag!('invoiceNumber', order[:invoice_number]) if order[:invoice_number]
632
+ xml.tag!('description', order[:description]) if order[:description]
633
+ xml.tag!('purchaseOrderNumber', order[:purchase_order_number]) if order[:purchase_order_number]
634
+ end
635
+ end
636
+
637
+ def add_payment_profiles(xml, payment_profiles)
638
+ xml.tag!('paymentProfiles') do
639
+ add_payment_profile(xml, payment_profiles)
640
+ end
641
+ end
642
+
643
+ # :customer_type => 'individual or business', # Optional
644
+ # :bill_to => @address,
645
+ # :payment => @payment
646
+ def add_payment_profile(xml, payment_profile)
647
+ # 'individual' or 'business' (optional)
648
+ xml.tag!('customerType', payment_profile[:customer_type]) if payment_profile[:customer_type]
649
+
650
+ if payment_profile[:bill_to]
651
+ xml.tag!('billTo') do
652
+ add_address(xml, payment_profile[:bill_to])
653
+ end
654
+ end
655
+
656
+ if payment_profile[:payment]
657
+ xml.tag!('payment') do
658
+ add_credit_card(xml, payment_profile[:payment][:credit_card]) if payment_profile[:payment].has_key?(:credit_card)
659
+ add_bank_account(xml, payment_profile[:payment][:bank_account]) if payment_profile[:payment].has_key?(:bank_account)
660
+ add_drivers_license(xml, payment_profile[:payment][:drivers_license]) if payment_profile[:payment].has_key?(:drivers_license)
661
+ # This element is only required for Wells Fargo SecureSource eCheck.Net merchants
662
+ # The customer's Social Security Number or Tax ID
663
+ xml.tag!('taxId', payment_profile[:payment]) if payment_profile[:payment].has_key?(:tax_id)
664
+ end
665
+ end
666
+
667
+ xml.tag!('customerPaymentProfileId', payment_profile[:customer_payment_profile_id]) if payment_profile[:customer_payment_profile_id]
668
+ end
669
+
670
+ def add_ship_to_list(xml, ship_to_list)
671
+ xml.tag!('shipToList') do
672
+ add_address(xml, ship_to_list)
673
+ end
674
+ end
675
+
676
+ def add_address(xml, address)
677
+ xml.tag!('firstName', address[:first_name])
678
+ xml.tag!('lastName', address[:last_name])
679
+ xml.tag!('company', address[:company])
680
+ xml.tag!('address', address[:address1]) if address[:address1]
681
+ xml.tag!('address', address[:address]) if address[:address]
682
+ xml.tag!('city', address[:city])
683
+ xml.tag!('state', address[:state])
684
+ xml.tag!('zip', address[:zip])
685
+ xml.tag!('country', address[:country])
686
+ xml.tag!('phoneNumber', address[:phone_number]) if address[:phone_number]
687
+ xml.tag!('faxNumber', address[:fax_number]) if address[:fax_number]
688
+
689
+ xml.tag!('customerAddressId', address[:customer_address_id]) if address[:customer_address_id]
690
+ end
691
+
692
+ # Adds customer’s credit card information
693
+ # Note: This element should only be included
694
+ # when the payment method is credit card.
695
+ def add_credit_card(xml, credit_card)
696
+ return unless credit_card
697
+ xml.tag!('creditCard') do
698
+ # The credit card number used for payment of the subscription
699
+ xml.tag!('cardNumber', credit_card.number)
700
+ # The expiration date of the credit card used for the subscription
701
+ xml.tag!('expirationDate', expdate(credit_card))
702
+ xml.tag!('cardCode', credit_card.verification_value) if credit_card.verification_value?
703
+ end
704
+ end
705
+
706
+ # Adds customer’s bank account information
707
+ # Note: This element should only be included
708
+ # when the payment method is bank account.
709
+ def add_bank_account(xml, bank_account)
710
+ raise StandardError, "Invalid Bank Account Type: #{bank_account[:account_type]}" unless BANK_ACCOUNT_TYPES.include?(bank_account[:account_type])
711
+ raise StandardError, "Invalid eCheck Type: #{bank_account[:echeck_type]}" unless ECHECK_TYPES.include?(bank_account[:echeck_type])
712
+
713
+ xml.tag!('bankAccount') do
714
+ # The type of bank account
715
+ xml.tag!('accountType', BANK_ACCOUNT_TYPES[bank_account[:account_type]])
716
+ # The routing number of the customer’s bank
717
+ xml.tag!('routingNumber', bank_account[:routing_number])
718
+ # The bank account number
719
+ xml.tag!('accountNumber', bank_account[:account_number])
720
+ # The full name of the individual associated
721
+ # with the bank account number
722
+ xml.tag!('nameOnAccount', bank_account[:name_on_account])
723
+ # The type of electronic check transaction
724
+ xml.tag!('echeckType', ECHECK_TYPES[bank_account[:echeck_type]])
725
+ # The full name of the individual associated
726
+ # with the bank account number (optional)
727
+ xml.tag!('bankName', bank_account[:bank_name]) if bank_account[:bank_name]
728
+ end
729
+ end
730
+
731
+ # Adds customer’s driver's license information
732
+ # Note: This element is only required for
733
+ # Wells Fargo SecureSource eCheck.Net merchants
734
+ def add_drivers_license(xml, drivers_license)
735
+ xml.tag!('driversLicense') do
736
+ # The state of the customer's driver's license
737
+ # A valid two character state code
738
+ xml.tag!('state', drivers_license[:state])
739
+ # The customer’s driver's license number
740
+ xml.tag!('number', drivers_license[:number])
741
+ # The date of birth listed on the customer's driver's license
742
+ # YYYY-MM-DD
743
+ xml.tag!('dateOfBirth', drivers_license[:date_of_birth])
744
+ end
745
+ end
746
+
747
+ def commit(action, request)
748
+ url = test? ? test_url : live_url
749
+ xml = ssl_post(url, request, "Content-Type" => "text/xml")
750
+
751
+ response_params = parse(action, xml)
752
+
753
+ message = response_params['messages']['message']['text']
754
+ test_mode = test? || message =~ /Test Mode/
755
+ success = response_params['messages']['result_code'] == 'Ok'
756
+
757
+ response = Response.new(success, message, response_params,
758
+ :test => test_mode,
759
+ :authorization => response_params['customer_profile_id'] || (response_params['profile'] ? response_params['profile']['customer_profile_id'] : nil)
760
+ )
761
+
762
+ response.params['direct_response'] = parse_direct_response(response) if response.params['direct_response']
763
+ response
764
+ end
765
+
766
+ def tag_unless_blank(xml, tag_name, data)
767
+ xml.tag!(tag_name, data) unless data.blank? || data.nil?
768
+ end
769
+
770
+ def parse_direct_response(response)
771
+ direct_response = {'raw' => response.params['direct_response']}
772
+ direct_response_fields = response.params['direct_response'].split(',')
773
+
774
+ direct_response.merge(
775
+ {
776
+ 'response_code' => direct_response_fields[0],
777
+ 'response_subcode' => direct_response_fields[1],
778
+ 'response_reason_code' => direct_response_fields[2],
779
+ 'message' => direct_response_fields[3],
780
+ 'approval_code' => direct_response_fields[4],
781
+ 'avs_response' => direct_response_fields[5],
782
+ 'transaction_id' => direct_response_fields[6],
783
+ 'invoice_number' => direct_response_fields[7],
784
+ 'order_description' => direct_response_fields[8],
785
+ 'amount' => direct_response_fields[9],
786
+ 'method' => direct_response_fields[10],
787
+ 'transaction_type' => direct_response_fields[11],
788
+ 'customer_id' => direct_response_fields[12],
789
+ 'first_name' => direct_response_fields[13],
790
+ 'last_name' => direct_response_fields[14],
791
+ 'company' => direct_response_fields[15],
792
+ 'address' => direct_response_fields[16],
793
+ 'city' => direct_response_fields[17],
794
+ 'state' => direct_response_fields[18],
795
+ 'zip_code' => direct_response_fields[19],
796
+ 'country' => direct_response_fields[20],
797
+ 'phone' => direct_response_fields[21],
798
+ 'fax' => direct_response_fields[22],
799
+ 'email_address' => direct_response_fields[23],
800
+ 'ship_to_first_name' => direct_response_fields[24],
801
+ 'ship_to_last_name' => direct_response_fields[25],
802
+ 'ship_to_company' => direct_response_fields[26],
803
+ 'ship_to_address' => direct_response_fields[27],
804
+ 'ship_to_city' => direct_response_fields[28],
805
+ 'ship_to_state' => direct_response_fields[29],
806
+ 'ship_to_zip_code' => direct_response_fields[30],
807
+ 'ship_to_country' => direct_response_fields[31],
808
+ 'tax' => direct_response_fields[32],
809
+ 'duty' => direct_response_fields[33],
810
+ 'freight' => direct_response_fields[34],
811
+ 'tax_exempt' => direct_response_fields[35],
812
+ 'purchase_order_number' => direct_response_fields[36],
813
+ 'md5_hash' => direct_response_fields[37],
814
+ 'card_code' => direct_response_fields[38],
815
+ 'cardholder_authentication_verification_response' => direct_response_fields[39]
816
+ }
817
+ )
818
+ end
819
+
820
+ def parse(action, xml)
821
+ xml = REXML::Document.new(xml)
822
+ root = REXML::XPath.first(xml, "//#{CIM_ACTIONS[action]}Response") ||
823
+ REXML::XPath.first(xml, "//ErrorResponse")
824
+ if root
825
+ response = parse_element(root)
826
+ end
827
+
828
+ response
829
+ end
830
+
831
+ def parse_element(node)
832
+ if node.has_elements?
833
+ response = {}
834
+ node.elements.each{ |e|
835
+ key = e.name.underscore
836
+ value = parse_element(e)
837
+ if response.has_key?(key)
838
+ if response[key].is_a?(Array)
839
+ response[key].push(value)
840
+ else
841
+ response[key] = [response[key], value]
842
+ end
843
+ else
844
+ response[key] = parse_element(e)
845
+ end
846
+ }
847
+ else
848
+ response = node.text
849
+ end
850
+
851
+ response
852
+ end
853
+ end
854
+ end
855
+ end