authorize-net 1.5.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. data/License.pdf +0 -0
  2. data/README.rdoc +124 -0
  3. data/Rakefile +74 -0
  4. data/generators/authorize_net_direct_post/USAGE +20 -0
  5. data/generators/authorize_net_direct_post/authorize_net_direct_post_generator.rb +21 -0
  6. data/generators/authorize_net_direct_post/templates/README-AuthorizeNet +49 -0
  7. data/generators/authorize_net_direct_post/templates/config.yml.erb +8 -0
  8. data/generators/authorize_net_direct_post/templates/config.yml.rails3.erb +8 -0
  9. data/generators/authorize_net_direct_post/templates/controller.rb.erb +31 -0
  10. data/generators/authorize_net_direct_post/templates/initializer.rb +4 -0
  11. data/generators/authorize_net_direct_post/templates/layout.erb +18 -0
  12. data/generators/authorize_net_direct_post/templates/payment.erb +10 -0
  13. data/generators/authorize_net_direct_post/templates/payment.rails3.erb +10 -0
  14. data/generators/authorize_net_direct_post/templates/receipt.erb +1 -0
  15. data/generators/authorize_net_direct_post/templates/relay_response.erb +1 -0
  16. data/generators/authorize_net_sim/USAGE +20 -0
  17. data/generators/authorize_net_sim/authorize_net_sim_generator.rb +19 -0
  18. data/generators/authorize_net_sim/templates/README-AuthorizeNet +52 -0
  19. data/generators/authorize_net_sim/templates/config.yml.erb +8 -0
  20. data/generators/authorize_net_sim/templates/config.yml.rails3.erb +8 -0
  21. data/generators/authorize_net_sim/templates/controller.rb.erb +21 -0
  22. data/generators/authorize_net_sim/templates/initializer.rb +4 -0
  23. data/generators/authorize_net_sim/templates/layout.erb +18 -0
  24. data/generators/authorize_net_sim/templates/payment.erb +6 -0
  25. data/generators/authorize_net_sim/templates/payment.rails3.erb +6 -0
  26. data/generators/authorize_net_sim/templates/thank_you.erb +1 -0
  27. data/generators/generator_extensions.rb +75 -0
  28. data/init.rb +2 -0
  29. data/install.rb +1 -0
  30. data/lib/app/helpers/authorize_net_helper.rb +24 -0
  31. data/lib/authorize-net.rb +4 -0
  32. data/lib/authorize_net.rb +92 -0
  33. data/lib/authorize_net/addresses/address.rb +29 -0
  34. data/lib/authorize_net/addresses/shipping_address.rb +26 -0
  35. data/lib/authorize_net/aim/response.rb +131 -0
  36. data/lib/authorize_net/aim/transaction.rb +184 -0
  37. data/lib/authorize_net/arb/response.rb +34 -0
  38. data/lib/authorize_net/arb/subscription.rb +72 -0
  39. data/lib/authorize_net/arb/transaction.rb +146 -0
  40. data/lib/authorize_net/authorize_net.rb +154 -0
  41. data/lib/authorize_net/cim/customer_profile.rb +19 -0
  42. data/lib/authorize_net/cim/payment_profile.rb +37 -0
  43. data/lib/authorize_net/cim/response.rb +110 -0
  44. data/lib/authorize_net/cim/transaction.rb +678 -0
  45. data/lib/authorize_net/customer.rb +27 -0
  46. data/lib/authorize_net/email_receipt.rb +24 -0
  47. data/lib/authorize_net/fields.rb +736 -0
  48. data/lib/authorize_net/key_value_response.rb +117 -0
  49. data/lib/authorize_net/key_value_transaction.rb +291 -0
  50. data/lib/authorize_net/line_item.rb +25 -0
  51. data/lib/authorize_net/order.rb +42 -0
  52. data/lib/authorize_net/payment_methods/credit_card.rb +74 -0
  53. data/lib/authorize_net/payment_methods/echeck.rb +72 -0
  54. data/lib/authorize_net/reporting/batch.rb +19 -0
  55. data/lib/authorize_net/reporting/batch_statistics.rb +19 -0
  56. data/lib/authorize_net/reporting/fds_filter.rb +11 -0
  57. data/lib/authorize_net/reporting/response.rb +127 -0
  58. data/lib/authorize_net/reporting/transaction.rb +116 -0
  59. data/lib/authorize_net/reporting/transaction_details.rb +25 -0
  60. data/lib/authorize_net/response.rb +27 -0
  61. data/lib/authorize_net/sim/hosted_payment_form.rb +38 -0
  62. data/lib/authorize_net/sim/hosted_receipt_page.rb +37 -0
  63. data/lib/authorize_net/sim/response.rb +142 -0
  64. data/lib/authorize_net/sim/transaction.rb +138 -0
  65. data/lib/authorize_net/transaction.rb +66 -0
  66. data/lib/authorize_net/xml_response.rb +172 -0
  67. data/lib/authorize_net/xml_transaction.rb +275 -0
  68. data/lib/generators/authorize_net/direct_post_generator.rb +51 -0
  69. data/lib/generators/authorize_net/sim_generator.rb +47 -0
  70. data/spec/aim_spec.rb +310 -0
  71. data/spec/arb_spec.rb +191 -0
  72. data/spec/authorize_net_spec.rb +200 -0
  73. data/spec/cim_spec.rb +450 -0
  74. data/spec/reporting_spec.rb +431 -0
  75. data/spec/sim_spec.rb +97 -0
  76. data/spec/spec.opts +5 -0
  77. data/spec/spec_helper.rb +2 -0
  78. data/uninstall.rb +1 -0
  79. metadata +223 -0
@@ -0,0 +1,19 @@
1
+ module AuthorizeNet::CIM
2
+
3
+ # Models a customer profile.
4
+ class CustomerProfile < AuthorizeNet::Customer
5
+
6
+ include AuthorizeNet::Model
7
+
8
+ attr_accessor :customer_profile_id, :payment_profiles
9
+
10
+ def to_hash
11
+ hash = super
12
+ hash.delete_if {|k, v| v.nil?}
13
+ hash[:payment_profiles] = handle_multivalue_hashing(@payment_profiles)
14
+ hash
15
+ end
16
+
17
+ end
18
+
19
+ end
@@ -0,0 +1,37 @@
1
+ module AuthorizeNet::CIM
2
+ # Models a payment profile.
3
+ class PaymentProfile
4
+
5
+ module CustomerType
6
+ INDIVIDUAL = 'individual'
7
+ BUSINESS = 'business'
8
+ end
9
+
10
+ include AuthorizeNet::Model
11
+
12
+ attr_accessor :cust_type, :billing_address, :payment_method, :customer_payment_profile_id
13
+
14
+ def cust_type=(type) #:nodoc:
15
+ case type
16
+ when :business
17
+ @cust_type = CustomerType::BUSINESS
18
+ when :individual
19
+ @cust_type = CustomerType::INDIVIDUAL
20
+ else
21
+ @cust_type = type
22
+ end
23
+ end
24
+
25
+ def to_hash
26
+ hash = {
27
+ :cust_type => @cust_type,
28
+ :customer_payment_profile_id => @customer_payment_profile_id
29
+ }
30
+ hash.delete_if {|k, v| v.nil?}
31
+ hash.merge!(@billing_address.to_hash) unless @billing_address.nil?
32
+ hash.merge!(@payment_method.to_hash) unless @payment_method.nil?
33
+ hash
34
+ end
35
+
36
+ end
37
+ end
@@ -0,0 +1,110 @@
1
+ module AuthorizeNet::CIM
2
+
3
+ # The CIM response class.
4
+ class Response < AuthorizeNet::XmlResponse
5
+
6
+ include AuthorizeNet::CIM::Fields
7
+
8
+ # Constructs a new response object from raw_response in the context of transaction.
9
+ # You don‘t typically construct this object yourself, as AuthorizeNet::CIM::Transaction
10
+ # will build one for you when it makes the request to the gateway.
11
+ def initialize(raw_response, transaction)
12
+ super
13
+ unless connection_failure?
14
+ begin
15
+ @customer_profile_id = node_content_unless_nil(@root.at_css('customerProfileId'))
16
+ @customer_payment_profile_id = node_content_unless_nil(@root.at_css('customerPaymentProfileId'))
17
+ @customer_payment_profile_id_list = node_child_content_unless_nil(@root.at_css('customerPaymentProfileIdList'))
18
+ @customer_shipping_address_id_list = node_child_content_unless_nil(@root.at_css('customerShippingAddressIdList'))
19
+ @customer_address_id = node_content_unless_nil(@root.at_css('customerAddressId'))
20
+ @validation_direct_response_list = @root.at_css('validationDirectResponseList')
21
+ @validation_direct_response = @root.at_css('validationDirectResponse')
22
+ @direct_response = @root.at_css('directResponse')
23
+ @customer_profile_id_list = node_child_content_unless_nil(@root.at_css('ids'))
24
+ @address = @root.at_css('address')
25
+ @payment_profile = @root.at_css('paymentProfile')
26
+ @profile = @root.at_css('profile')
27
+ rescue
28
+ @raw_response = $!
29
+ end
30
+ end
31
+ end
32
+
33
+ # Returns a CustomerProfile ID if one was returned by the gateway. Returns nil otherwise.
34
+ # Note that this method will return nil if we got back a list of IDs (see profile_ids).
35
+ def profile_id
36
+ @customer_profile_id
37
+ end
38
+
39
+ # Returns a list of CustomerProfile IDs if any were returned by the gateway. Returns nil otherwise.
40
+ def profile_ids
41
+ @customer_profile_id_list
42
+ end
43
+
44
+ # Returns an Address ID if one was returned by the gateway. Returns nil otherwise.
45
+ # Note that this method will return nil if we got back a list of IDs (see address_ids).
46
+ def address_id
47
+ @customer_address_id
48
+ end
49
+
50
+ # Returns a list of Address IDs if any were returned by the gateway. Returns nil otherwise.
51
+ def address_ids
52
+ @customer_shipping_address_id_list
53
+ end
54
+
55
+ # Returns a PaymentProfile ID if one was returned by the gateway. Returns nil otherwise.
56
+ # Note that this method will return nil if we got back a list of IDs (see payment_profile_ids).
57
+ def payment_profile_id
58
+ @customer_payment_profile_id
59
+ end
60
+
61
+ # Returns a list of PaymentProfile IDs if any were returned by the gateway. Returns nil otherwise.
62
+ def payment_profile_ids
63
+ @customer_payment_profile_id_list
64
+ end
65
+
66
+ # Returns a validation response as an AuthorizeNet::AIM::Response object if a validation response was returned
67
+ # by the gateway. Returns nil otherwise.
68
+ # Note that this method will return nil if we got back a list of IDs (see validation_responses).
69
+ def validation_response
70
+ AuthorizeNet::AIM::Response.new(@validation_direct_response.dup, @transaction) unless @validation_direct_response.nil?
71
+ end
72
+
73
+ # Returns a list of validation response as an AuthorizeNet::AIM::Response objects if a list of validation response was returned
74
+ # by the gateway. Returns nil otherwise.
75
+ def validation_responses
76
+ unless @validation_direct_response_list.nil?
77
+ responses = []
78
+ @validation_direct_response_list.element_children.each do |child|
79
+ responses <<= AuthorizeNet::AIM::Response.new(child.dup, @transaction) unless child.nil?
80
+ end
81
+ return responses unless responses.length == 0
82
+ end
83
+ end
84
+
85
+ # Returns the direct response as an AuthorizeNet::AIM::Response object if a direct response was returned
86
+ # by the gateway. Returns nil otherwise.
87
+ def direct_response
88
+ AuthorizeNet::AIM::Response.new(@direct_response.dup, @transaction) unless @direct_response.nil?
89
+ end
90
+
91
+ # Returns a CustomerProfile built from the entity returned by the gateway. Returns nil otherwise.
92
+ def profile
93
+ build_entity(@profile, Fields::PROFILE_ENTITY_DESCRIPTION) unless @profile.nil?
94
+ end
95
+
96
+ # Returns a PaymentProfile built from the entity returned by the gateway. Returns nil otherwise.
97
+ def payment_profile
98
+ build_entity(@payment_profile, Fields::PAYMENT_PROFILE_ENTITY_DESCRIPTION) unless @payment_profile.nil?
99
+ end
100
+
101
+ # Returns an Address built from the entity returned by the gateway. Returns nil otherwise.
102
+ def address
103
+ build_entity(@address, Fields::ADDRESS_ENTITY_DESCRIPTION) unless @address.nil?
104
+ end
105
+
106
+ #:enddoc:
107
+ protected
108
+
109
+ end
110
+ end
@@ -0,0 +1,678 @@
1
+ module AuthorizeNet::CIM
2
+
3
+ # The CIM transaction class.
4
+ class Transaction < AuthorizeNet::XmlTransaction
5
+
6
+ include AuthorizeNet::CIM::Fields
7
+
8
+ # The class to wrap our response in.
9
+ @response_class = AuthorizeNet::CIM::Response
10
+
11
+ # The default options for the constructor.
12
+ @@option_defaults = {
13
+ :gateway => :production,
14
+ :verify_ssl => false,
15
+ :reference_id => nil
16
+ }
17
+
18
+ # Constructs a CIM transaction. You can use the new CIM transaction object
19
+ # to issue a request to the payment gateway and parse the response into a new
20
+ # AuthorizeNet::CIM::Response object.
21
+ #
22
+ # +api_login_id+:: Your API login ID, as a string.
23
+ # +api_transaction_key+:: Your API transaction key, as a string.
24
+ # +options+:: A hash of options. See below for values.
25
+ #
26
+ # Options
27
+ # +gateway+:: The gateway to submit the transaction to. Can be a URL string, an AuthorizeNet::CIM::Transaction::Gateway constant, or one of the convenience symbols :sandbox, :test, :production, or :live (:test is an alias for :sandbox, and :live is an alias for :production).
28
+ # +verify_ssl+:: A boolean indicating if the SSL certificate of the +gateway+ should be verified. Defaults to false.
29
+ # +reference_id+:: A string that can be used to identify a particular transaction with its response. Will be echo'd in the response, only if it was provided in the transaction. Defaults to nil.
30
+ #
31
+ def initialize(api_login_id, api_transaction_key, options = {})
32
+ super
33
+ @delim_char = ','
34
+ @encap_char = nil
35
+ @custom_fields = {}
36
+ end
37
+
38
+ # The default options for create_profile.
39
+ @@create_profile_option_defaults = {
40
+ :validation_mode => :none
41
+ }
42
+
43
+ # The default options for create_payment_profile.
44
+ @@create_payment_profile_option_defaults = {
45
+ :validation_mode => :none
46
+ }
47
+
48
+ # The default options for update_payment_profile.
49
+ @@update_payment_profile_option_defaults = {
50
+ :validation_mode => :none
51
+ }
52
+
53
+ # The default options for create_transaction and the various type specific create transaction methods.
54
+ @@create_transaction_option_defaults = {
55
+ :address_id => nil,
56
+ :split_tender_id => nil,
57
+ :aim_options => nil,
58
+ :custom_fields => nil
59
+ }
60
+
61
+ # The default options for validate_payment_profile.
62
+ @@validate_payment_profile_option_defaults = {
63
+ :address_id => nil,
64
+ :card_code => nil,
65
+ :validation_mode => :testMode
66
+ }
67
+
68
+ # A list of keys that should be stored if passed as aim_options.
69
+ @@aim_response_options = [:delim_char, :encap_char]
70
+
71
+ # Sets up and submits a createCustomerProfileRequest transaction. If this transaction has already been
72
+ # run, this method will return nil. Otherwise it will return an AuthorizeNet::CIM::Response object. The
73
+ # response object will have a profile_id if the request was successful. If any PaymentProfiles or Addresses
74
+ # were included, you can find their IDs in the response objects payment_profile_ids and address_ids methods.
75
+ #
76
+ # +profile+:: An AuthorizeNet::CIM::CustomerProfile object describing the profile to create.
77
+ # +options+:: An optional hash of options.
78
+ #
79
+ # Options:
80
+ # +validation_mode+:: Set to :testMode, :liveMode or :none (the default) to indicate what sort of PaymentProfile validation to do (assuming a PaymentProfile is included with the CustomerProfile)
81
+ #
82
+ # Typical usage:
83
+ #
84
+ # profile = AuthorizeNet::CIM::CustomerProfile.new(
85
+ # :email => 'test@example.com',
86
+ # :id => 'userassignedid'
87
+ # )
88
+ # response = transaction.create_profile(profile)
89
+ # puts response.profile_id if response.success?
90
+ #
91
+ def create_profile(profile, options = {})
92
+ options = @@create_profile_option_defaults.merge(options)
93
+ @type = Type::CIM_CREATE_PROFILE
94
+ @fields.merge!(profile.to_hash)
95
+ set_fields(:validation_mode => options[:validation_mode])
96
+ make_request
97
+ end
98
+
99
+ # Sets up and submits a getCustomerProfileRequest transaction. If this transaction has already been
100
+ # run, this method will return nil. Otherwise it will return an AuthorizeNet::CIM::Response object. The
101
+ # response object will have the CustomerProfile object requested available via its profile method if
102
+ # the request was successful.
103
+ #
104
+ #
105
+ # +profile_id+:: Takes either a String containing the ID of the CustomerProfile you want to retrieve, or a CustomerProfile object with the ID populated.
106
+ # Typical usage:
107
+ #
108
+ # response = transaction.get_profile('123456')
109
+ # profile = response.profile if response.success?
110
+ #
111
+ def get_profile(profile_id)
112
+ @type = Type::CIM_GET_PROFILE
113
+ handle_profile_id(profile_id)
114
+ make_request
115
+ end
116
+
117
+ # Sets up and submits a updateCustomerProfileRequest transaction. If this transaction has already been
118
+ # run, this method will return nil. Otherwise it will return an AuthorizeNet::CIM::Response object. Note that
119
+ # any PaymentProfiles will NOT be updated using this method. This is a limitation of the CIM API. See
120
+ # update_payment_profile if you need to update a PaymentProfile.
121
+ #
122
+ #
123
+ # +profile+:: An AuthorizeNet::CIM::CustomerProfile object describing the profile to update. It must contain the customer_profile_id of the record to update.
124
+ # Typical usage:
125
+ #
126
+ # profile.fax = '5555551234'
127
+ # response = transaction.update_profile(profile)
128
+ # puts response.success?
129
+ #
130
+ def update_profile(profile)
131
+ @type = Type::CIM_UPDATE_PROFILE
132
+ @fields.merge!(profile.to_hash)
133
+ make_request
134
+ end
135
+
136
+ # Sets up and submits a deleteCustomerProfileRequest transaction. If this transaction has already been
137
+ # run, this method will return nil. Otherwise it will return an AuthorizeNet::CIM::Response object.
138
+ #
139
+ #
140
+ # +profile_id+:: Takes either a String containing the ID of the CustomerProfile you want to delete, or a CustomerProfile object with the ID populated.
141
+ # Typical usage:
142
+ #
143
+ # response = transaction.delete_profile('123456')
144
+ # puts response.success?
145
+ #
146
+ def delete_profile(profile_id)
147
+ @type = Type::CIM_DELETE_PROFILE
148
+ handle_profile_id(profile_id)
149
+ make_request
150
+ end
151
+
152
+ # Sets up and submits a createCustomerPaymentProfileRequest transaction. If this transaction has already been
153
+ # run, this method will return nil. Otherwise it will return an AuthorizeNet::CIM::Response object. The
154
+ # response object will have a payment_profile_id if the request was successful.
155
+ #
156
+ # +profile+:: An AuthorizeNet::CIM::PaymentProfile object describing the profile to create.
157
+ # +profile_id+:: Takes either a String containing the ID of the CustomerProfile who will own the PaymentProfile, or a CustomerProfile object with the ID populated.
158
+ # +options+:: An optional hash of options.
159
+ #
160
+ # Options:
161
+ # +validation_mode+:: Set to :testMode, :liveMode or :none (the default) to indicate what sort of PaymentProfile validation to do (assuming a PaymentProfile is included with the CustomerProfile)
162
+ #
163
+ # Typical usage:
164
+ #
165
+ # credit_card = AuthorizeNet::CreditCard.new('4111111111111111', '0120')
166
+ # payment_profile = AuthorizeNet::CIM::PaymentProfile.new(:payment_method => credit_card)
167
+ # response = transaction.create_payment_profile(payment_profile, '123456')
168
+ # puts response.payment_profile_id if response.success?
169
+ #
170
+ def create_payment_profile(payment_profile, profile_id, options = {})
171
+ options = @@create_payment_profile_option_defaults.merge(options)
172
+ @type = Type::CIM_CREATE_PAYMENT
173
+ @fields.merge!(payment_profile.to_hash)
174
+ set_fields(:validation_mode => options[:validation_mode])
175
+ handle_profile_id(profile_id)
176
+ make_request
177
+ end
178
+
179
+ # Sets up and submits a getCustomerPaymentProfileRequest transaction. If this transaction has already been
180
+ # run, this method will return nil. Otherwise it will return an AuthorizeNet::CIM::Response object. The
181
+ # response object will have the PaymentProfile object requested available via its payment_profile method if
182
+ # the request was successful.
183
+ #
184
+ # +payment_profile_id+:: Takes either a String containing the ID of the PaymentProfile you want to retrieve, or a PaymentProfile object with the ID populated.
185
+ # +profile_id+:: Takes either a String containing the ID of the CustomerProfile who owns this PaymentProfile, or a CustomerProfile object with the ID populated.
186
+ #
187
+ # Typical usage:
188
+ #
189
+ # response = transaction.get_payment_profile('654321', '123456')
190
+ # payment_profile = response.payment_profile if response.success?
191
+ #
192
+ def get_payment_profile(payment_profile_id, profile_id)
193
+ @type = Type::CIM_GET_PAYMENT
194
+ handle_payment_profile_id(payment_profile_id)
195
+ handle_profile_id(profile_id)
196
+ make_request
197
+ end
198
+
199
+ # Sets up and submits a updateCustomerPaymentProfileRequest transaction. If this transaction has already been
200
+ # run, this method will return nil. Otherwise it will return an AuthorizeNet::CIM::Response object.
201
+ #
202
+ #
203
+ # +payment_profile+:: An AuthorizeNet::CIM::PaymentProfile object describing the profile to update.
204
+ # +profile_id+:: Takes either a String containing the ID of the CustomerProfile who owns this PaymentProfile, or a CustomerProfile object with the ID populated.
205
+ #
206
+ # Typical usage:
207
+ #
208
+ # payment_profile.cust_type = :business
209
+ # response = transaction.update_payment_profile(payment_profile, '123456')
210
+ # puts response.success?
211
+ #
212
+ # Options:
213
+ # +validation_mode+:: Set to :testMode, :liveMode or :none (the default) to indicate what sort of PaymentProfile validation to do.
214
+ #
215
+ def update_payment_profile(payment_profile, profile_id, options = {})
216
+ options = @@create_payment_profile_option_defaults.merge(options)
217
+ @type = Type::CIM_UPDATE_PAYMENT
218
+ @fields.merge!(payment_profile.to_hash)
219
+ set_fields(:validation_mode => options[:validation_mode])
220
+ handle_profile_id(profile_id)
221
+ make_request
222
+ end
223
+
224
+ # Sets up and submits a deleteCustomerPaymentProfileRequest transaction. If this transaction has already been
225
+ # run, this method will return nil. Otherwise it will return an AuthorizeNet::CIM::Response object.
226
+ #
227
+ #
228
+ # +payment_profile_id+:: Takes either a String containing the ID of the PaymentProfile you want to retrieve, or a PaymentProfile object with the ID populated.
229
+ # +profile_id+:: Takes either a String containing the ID of the CustomerProfile who owns this PaymentProfile, or a CustomerProfile object with the ID populated.
230
+ #
231
+ # Typical usage:
232
+ #
233
+ # response = transaction.delete_profile('123456')
234
+ # puts response.success?
235
+ #
236
+ def delete_payment_profile(payment_profile_id, profile_id)
237
+ @type = Type::CIM_DELETE_PAYMENT
238
+ handle_payment_profile_id(payment_profile_id)
239
+ handle_profile_id(profile_id)
240
+ make_request
241
+ end
242
+
243
+ # Sets up and submits a validateCustomerPaymentProfileRequest transaction. If this transaction has already been
244
+ # run, this method will return nil. Otherwise it will return an AuthorizeNet::CIM::Response object. The results
245
+ # of the validation can be obtained via the direct_response method of the response object.
246
+ #
247
+ #
248
+ # +payment_profile_id+:: Takes either a String containing the ID of the PaymentProfile you want to validate, or a PaymentProfile object with the ID populated.
249
+ # +profile_id+:: Takes either a String containing the ID of the CustomerProfile who owns this PaymentProfile, or a CustomerProfile object with the ID populated.
250
+ #
251
+ # Typical usage:
252
+ #
253
+ # response = transaction.validate_payment_profile('654321', '123456')
254
+ # puts response.direct_response.success? if response.success?
255
+ #
256
+ # Options:
257
+ # +validation_mode+:: Set to :testMode (the default) or :liveMode to indicate what sort of PaymentProfile validation to do.
258
+ # +address_id+:: Set a shipping Address to be part of the validation transaction.
259
+ # +card_code+:: Set a CCV code if one is needed for validation. Defaults to nil.
260
+ #
261
+ def validate_payment_profile(payment_profile_id, profile_id, options = {})
262
+ @type = Type::CIM_VALIDATE_PAYMENT
263
+ options = @@validate_payment_profile_option_defaults.merge(options)
264
+ handle_payment_profile_id(payment_profile_id)
265
+ handle_profile_id(profile_id)
266
+ handle_address_id(options[:address_id]) unless options[:address_id].nil?
267
+ set_fields(:validation_mode => options[:validation_mode])
268
+ set_fields(:card_code => options[:card_code]) unless options[:card_code].nil?
269
+ make_request
270
+ end
271
+
272
+ # Sets up and submits a createCustomerShippingAddressRequest transaction. If this transaction has already been
273
+ # run, this method will return nil. Otherwise it will return an AuthorizeNet::CIM::Response object. The
274
+ # response object will have a address_id if the request was successful.
275
+ #
276
+ # +address+:: An AuthorizeNet::Address object describing the profile to create.
277
+ # +profile_id+:: Takes either a String containing the ID of the CustomerProfile who will own this Address, or a CustomerProfile object with the ID populated.
278
+ #
279
+ # Typical usage:
280
+ #
281
+ # address = AuthorizeNet::Address.new(:first_name => 'Jane', :last_name => 'Doe', :address => '123 Fake St', :city => 'Raccoon Junction', :state => 'WY', :zip => '99999')
282
+ # response = transaction.create_address(address, '123456')
283
+ # puts response.address_id if response.success?
284
+ #
285
+ def create_address(address, profile_id)
286
+ @type = Type::CIM_CREATE_ADDRESS
287
+ @fields.merge!(address.to_hash)
288
+ handle_profile_id(profile_id)
289
+ make_request
290
+ end
291
+
292
+ # Sets up and submits a getCustomerShippingAddressRequest transaction. If this transaction has already been
293
+ # run, this method will return nil. Otherwise it will return an AuthorizeNet::CIM::Response object. The
294
+ # response object will have the Address object requested available via its address method if
295
+ # the request was successful.
296
+ #
297
+ #
298
+ # +address_id+:: Takes either a String containing the ID of the Address you want to retrieve, or an Address object with the ID populated.
299
+ # +profile_id+:: Takes either a String containing the ID of the CustomerProfile who owns this Address, or a CustomerProfile object with the ID populated.
300
+ #
301
+ # Typical usage:
302
+ #
303
+ # response = transaction.get_address('654321', '123456')
304
+ # address = response.address if response.success?
305
+ #
306
+ def get_address(address_id, profile_id)
307
+ @type = Type::CIM_GET_ADDRESS
308
+ handle_address_id(address_id)
309
+ handle_profile_id(profile_id)
310
+ make_request
311
+ end
312
+
313
+ # Sets up and submits a updateCustomerShippingAddressRequest transaction. If this transaction has already been
314
+ # run, this method will return nil. Otherwise it will return an AuthorizeNet::CIM::Response object.
315
+ #
316
+ #
317
+ # +address+:: An Address object describing the address to update.
318
+ # +profile_id+:: Takes either a String containing the ID of the CustomerProfile who owns this Address, or a CustomerProfile object with the ID populated.
319
+ #
320
+ # Typical usage:
321
+ #
322
+ # address.city = 'Somewhere Else'
323
+ # response = transaction.update_address(address, '123456')
324
+ # puts response.success?
325
+ #
326
+ def update_address(address, profile_id)
327
+ @type = Type::CIM_UPDATE_ADDRESS
328
+ @fields.merge!(address.to_hash)
329
+ handle_profile_id(profile_id)
330
+ make_request
331
+ end
332
+
333
+ # Sets up and submits a deleteCustomerShippingAddressRequest transaction. If this transaction has already been
334
+ # run, this method will return nil. Otherwise it will return an AuthorizeNet::CIM::Response object.
335
+ #
336
+ #
337
+ # +address_id+:: Takes either a String containing the ID of the Address you want to delete, or an Address object with the ID populated.
338
+ # +profile_id+:: Takes either a String containing the ID of the CustomerProfile who owns this Address, or a CustomerProfile object with the ID populated.
339
+ #
340
+ # Typical usage:
341
+ #
342
+ # response = transaction.delete_address('654321', '123456')
343
+ # puts response.success?
344
+ #
345
+ def delete_address(address_id, profile_id)
346
+ @type = Type::CIM_DELETE_ADDRESS
347
+ handle_address_id(address_id)
348
+ handle_profile_id(profile_id)
349
+ make_request
350
+ end
351
+
352
+ # Sets up and submits a createCustomerProfileTransactionRequest transaction. If this transaction has already been
353
+ # run, this method will return nil. Otherwise it will return an AuthorizeNet::CIM::Response object. It is recommend
354
+ # to use the connivence methods for each type of payment transaction rather than this method.
355
+ #
356
+ # +type+:: The type of payment transaction to run. Can be :auth_capture, :auth_only, :prior_auth_capture, :void, or :refund.
357
+ # +amount+:: The amount of the transaction. This is required for every transaction type except :void.
358
+ # +profile_id+:: Takes either a String containing the ID of the CustomerProfile who owns the PaymentProfile to be charged, or a CustomerProfile object with the ID populated.
359
+ # +payment_profile_id+:: Takes either a String containing the ID of the PaymentProfile you want to charge, or a PaymentProfile object with the ID populated.
360
+ # +order+:: An Order object describing the order that this payment transaction is for. Pass nil for no order.
361
+ # +options+:: An optional hash of options.
362
+ #
363
+ # Options:
364
+ # +address_id+:: Takes either a String containing the ID of the an Address, or an Address object with the ID populated. Used as the shipping address for the payment transaction. Defaults to nil.
365
+ # +split_tender_id+:: A split tender transaction ID as a string. If the transaction is to be part of a split tender batch, this must be included. Defaults to nil.
366
+ # +aim_options+:: A hash of AIM options to be included with the payment transaction. Since the payment transactions in CIM are just encapsulated AIM transactions, any field used by AIM can be set here. Defaults to nil.
367
+ # +custom_fields+:: A hash of custom fields to pass along with the payment transaction. These fields will be stored with the AIM transaction generated by the CIM transaction. Defaults to nil.
368
+ #
369
+ # Typical usage:
370
+ #
371
+ # response = transaction.create_transaction(:auth_capture, 10.00, '123456', '654321', nil)
372
+ # if response.success?
373
+ # puts response.direct_response if direct_response.success?
374
+ #
375
+ #
376
+ def create_transaction(type, amount, profile_id, payment_profile_id, order, options = {})
377
+ @type = Type::CIM_CREATE_TRANSACTION
378
+ options = @@create_transaction_option_defaults.merge(options)
379
+ handle_profile_id(profile_id)
380
+ handle_payment_profile_id(payment_profile_id)
381
+ handle_address_id(options[:address_id]) unless options[:address_id].nil?
382
+ set_fields(:split_tender_id => options[:split_tender_id])
383
+ @transaction_type = type
384
+ @fields.merge!(order.to_hash) unless order.nil?
385
+ set_fields(:amount => amount)
386
+ handle_aim_options(options[:aim_options])
387
+ handle_custom_fields(options[:custom_fields])
388
+ make_request
389
+ end
390
+
391
+
392
+ # Sets up and submits an AUTHORIZE_AND_CAPTURE transaction using stored payment information. If this
393
+ # transaction has already been run, this method will return nil. Otherwise it will return an
394
+ # AuthorizeNet::CIM::Response object.
395
+ #
396
+ # +amount+:: The amount of the transaction.
397
+ # +profile_id+:: Takes either a String containing the ID of the CustomerProfile who owns the PaymentProfile to be charged, or a CustomerProfile object with the ID populated.
398
+ # +payment_profile_id+:: Takes either a String containing the ID of the PaymentProfile you want to charge, or a PaymentProfile object with the ID populated.
399
+ # +order+:: An Order object describing the order that this payment transaction is for. Pass nil for no order.
400
+ # +options+:: An optional hash of options.
401
+ #
402
+ # Options:
403
+ # +address_id+:: Takes either a String containing the ID of the an Address, or an Address object with the ID populated. Used as the shipping address for the payment transaction. Defaults to nil.
404
+ # +split_tender_id+:: A split tender transaction ID as a string. If the transaction is to be part of a split tender batch, this must be included. Defaults to nil.
405
+ # +aim_options+:: A hash of AIM options to be included with the payment transaction. Since the payment transactions in CIM are just encapsulated AIM transactions, any field used by AIM can be set here. Defaults to nil.
406
+ # +custom_fields+:: A hash of custom fields to pass along with the payment transaction. These fields will be stored with the AIM transaction generated by the CIM transaction. Defaults to nil.
407
+ #
408
+ # Typical usage:
409
+ #
410
+ # response = transaction.create_transaction_auth_capture(10.00, '123456', '654321', nil)
411
+ # if response.success?
412
+ # puts response.direct_response if direct_response.success?
413
+ #
414
+ def create_transaction_auth_capture(amount, profile_id, payment_profile_id, order = nil, options = {})
415
+ create_transaction(:auth_capture, amount, profile_id, payment_profile_id, order, options)
416
+ end
417
+
418
+ # Sets up and submits an AUTH_ONLY transaction using stored payment information. If this
419
+ # transaction has already been run, this method will return nil. Otherwise it will return an
420
+ # AuthorizeNet::CIM::Response object.
421
+ #
422
+ # +amount+:: The amount of the transaction.
423
+ # +profile_id+:: Takes either a String containing the ID of the CustomerProfile who owns the PaymentProfile to be charged, or a CustomerProfile object with the ID populated.
424
+ # +payment_profile_id+:: Takes either a String containing the ID of the PaymentProfile you want to charge, or a PaymentProfile object with the ID populated.
425
+ # +order+:: An Order object describing the order that this payment transaction is for. Pass nil for no order.
426
+ # +options+:: An optional hash of options.
427
+ #
428
+ # Options:
429
+ # +address_id+:: Takes either a String containing the ID of the an Address, or an Address object with the ID populated. Used as the shipping address for the payment transaction. Defaults to nil.
430
+ # +split_tender_id+:: A split tender transaction ID as a string. If the transaction is to be part of a split tender batch, this must be included. Defaults to nil.
431
+ # +aim_options+:: A hash of AIM options to be included with the payment transaction. Since the payment transactions in CIM are just encapsulated AIM transactions, any field used by AIM can be set here. Defaults to nil.
432
+ # +custom_fields+:: A hash of custom fields to pass along with the payment transaction. These fields will be stored with the AIM transaction generated by the CIM transaction. Defaults to nil.
433
+ #
434
+ # Typical usage:
435
+ #
436
+ # response = transaction.create_transaction_auth_only(10.00, '123456', '654321', nil)
437
+ # if response.success?
438
+ # puts response.direct_response if direct_response.success?
439
+ #
440
+ def create_transaction_auth_only(amount, profile_id, payment_profile_id, order = nil, options = {})
441
+ create_transaction(:auth_only, amount, profile_id, payment_profile_id, order, options)
442
+ end
443
+
444
+ # Sets up and submits a PRIOR_AUTHORIZATION_AND_CAPTURE transaction using stored payment information. If this
445
+ # transaction has already been run, this method will return nil. Otherwise it will return an
446
+ # AuthorizeNet::CIM::Response object.
447
+ #
448
+ # +transaction_id+:: A string containing a transaction ID that was generated via an AUTH_ONLY transaction.
449
+ # +amount+:: The amount to capture. Must be <= the amount authorized via the AUTH_ONLY transaction.
450
+ # +order+:: An Order object describing the order that this payment transaction is for. Pass nil for no order.
451
+ # +options+:: An optional hash of options.
452
+ #
453
+ # Options:
454
+ # +aim_options+:: A hash of AIM options to be included with the payment transaction. Since the payment transactions in CIM are just encapsulated AIM transactions, any field used by AIM can be set here. Defaults to nil.
455
+ # +custom_fields+:: A hash of custom fields to pass along with the payment transaction. These fields will be stored with the AIM transaction generated by the CIM transaction. Defaults to nil.
456
+ #
457
+ # Typical usage:
458
+ #
459
+ # response = transaction.create_transaction_prior_auth_capture('111222', 10.00)
460
+ # if response.success?
461
+ # puts response.direct_response if direct_response.success?
462
+ #
463
+ def create_transaction_prior_auth_capture(transaction_id, amount, order = nil, options = {})
464
+ handle_transaction_id(transaction_id)
465
+ create_transaction(:prior_auth_capture, amount, nil, nil, order, options)
466
+ end
467
+
468
+ # Sets up and submits a VOID transaction using stored payment information. If this
469
+ # transaction has already been run, this method will return nil. Otherwise it will return an
470
+ # AuthorizeNet::CIM::Response object.
471
+ #
472
+ # +transaction_id+:: A string containing a transaction ID to void.
473
+ # +options+:: An optional hash of options.
474
+ #
475
+ # Options:
476
+ # +aim_options+:: A hash of AIM options to be included with the payment transaction. Since the payment transactions in CIM are just encapsulated AIM transactions, any field used by AIM can be set here. Defaults to nil.
477
+ # +custom_fields+:: A hash of custom fields to pass along with the payment transaction. These fields will be stored with the AIM transaction generated by the CIM transaction. Defaults to nil.
478
+ #
479
+ # Typical usage:
480
+ #
481
+ # response = transaction.create_transaction_void('111222')
482
+ # if response.success?
483
+ # puts response.direct_response if direct_response.success?
484
+ #
485
+ def create_transaction_void(transaction_id, options = {})
486
+ handle_transaction_id(transaction_id)
487
+ create_transaction(:void, nil, nil, nil, nil, options)
488
+ end
489
+
490
+ # Sets up and submits a REFUND transaction using stored payment information. If this
491
+ # transaction has already been run, this method will return nil. Otherwise it will return an
492
+ # AuthorizeNet::CIM::Response object.
493
+ #
494
+ # +transaction_id+:: A string containing a transaction ID to refund. Pass nil for an unlinked refund.
495
+ # +amount+:: The amount to refund.
496
+ # +profile_id+:: Takes either a String containing the ID of the CustomerProfile who owns the PaymentProfile to be credited, or a CustomerProfile object with the ID populated. Pass nil for an unlinked refund.
497
+ # +payment_profile_id+:: Takes either a String containing the ID of the PaymentProfile you want to credit, or a PaymentProfile object with the ID populated. Pass nil for an unlinked refund.
498
+ # +order+:: An Order object describing the order that is being refunded. Pass nil for no order.
499
+ # +options+:: An optional hash of options.
500
+ #
501
+ # Options:
502
+ # +aim_options+:: A hash of AIM options to be included with the payment transaction. Since the payment transactions in CIM are just encapsulated AIM transactions, any field used by AIM can be set here. Defaults to nil.
503
+ # +custom_fields+:: A hash of custom fields to pass along with the payment transaction. These fields will be stored with the AIM transaction generated by the CIM transaction. Defaults to nil.
504
+ #
505
+ # Typical usage:
506
+ #
507
+ # response = transaction.create_transaction_refund('111222', 10.00, '123456', '654321')
508
+ # if response.success?
509
+ # puts response.direct_response if direct_response.success?
510
+ #
511
+ def create_transaction_refund(transaction_id, amount, profile_id, payment_profile_id, order = nil, options = {})
512
+ handle_transaction_id(transaction_id)
513
+ create_transaction(:refund, amount, profile_id, payment_profile_id, order, options)
514
+ end
515
+
516
+ # Sets up and submits a updateSplitTenderGroupRequest transaction. Use this to end or void a split
517
+ # tender batch. If this transaction has already been run, this method will return nil. Otherwise
518
+ # it will return an AuthorizeNet::CIM::Response object.
519
+ #
520
+ # +split_tender_id+:: The split tender batch ID you want to change the status of.
521
+ # +status+:: The new status to set for the batch. Options are :voided or :completed.
522
+ #
523
+ # Typical usage:
524
+ #
525
+ # response = transaction.update_split_tender('1111111', :voided)
526
+ # puts response if response.success?
527
+ #
528
+ def update_split_tender(split_tender_id, status)
529
+ @type = Type::CIM_UPDATE_SPLIT
530
+ set_fields(:split_tender_id => split_tender_id, :split_tender_status => status.to_s)
531
+ make_request
532
+ end
533
+
534
+ # Sets up and submits a getCustomerProfileIdsRequest transaction. If this transaction has already been
535
+ # run, this method will return nil. Otherwise it will return an AuthorizeNet::CIM::Response object. The
536
+ # response object will have a list of all CustomerProfile IDs available via its profile_ids method on success.
537
+ #
538
+ # Typical usage:
539
+ #
540
+ # response = transaction.get_profile_ids()
541
+ # puts response.profile_ids if response.success?
542
+ #
543
+ def get_profile_ids()
544
+ @type = Type::CIM_GET_PROFILE_IDS
545
+ make_request
546
+ end
547
+
548
+ # :stopdoc:
549
+ # Duck-type as an AIM transaction so we can build AIM responses easily
550
+
551
+ # No encapsulation_character.
552
+ def encapsulation_character
553
+ @encap_char
554
+ end
555
+
556
+ # Comma delimited.
557
+ def delimiter
558
+ @delim_char
559
+ end
560
+
561
+ # Custom fields accessor.
562
+ def custom_fields
563
+ @custom_fields
564
+ end
565
+
566
+ # Always version 3.1.
567
+ def version
568
+ 3.1
569
+ end
570
+
571
+ # Always nil.
572
+ def cp_version
573
+ nil
574
+ end
575
+ # :startdoc:
576
+
577
+ #:enddoc:
578
+ protected
579
+
580
+ # Handles profile id type massaging.
581
+ def handle_profile_id(id)
582
+ case id
583
+ when CustomerProfile
584
+ set_fields(:customer_profile_id => id.customer_profile_id.to_s)
585
+ when nil
586
+ nil
587
+ else
588
+ set_fields(:customer_profile_id => id.to_s)
589
+ end
590
+ end
591
+
592
+ # Handles payment profile id type massaging.
593
+ def handle_payment_profile_id(id)
594
+ case id
595
+ when PaymentProfile
596
+ set_fields(:customer_payment_profile_id => id.customer_payment_profile_id.to_s)
597
+ when nil
598
+ nil
599
+ else
600
+ set_fields(:customer_payment_profile_id => id.to_s)
601
+ end
602
+ end
603
+
604
+ # Handles address id type massaging.
605
+ def handle_address_id(id)
606
+ case id
607
+ when AuthorizeNet::Address
608
+ set_fields(:customer_address_id => id.customer_address_id.to_s)
609
+ when nil
610
+ nil
611
+ else
612
+ set_fields(:customer_address_id => id.to_s)
613
+ end
614
+ end
615
+
616
+ # Handles tranasction id type massaging.
617
+ def handle_transaction_id(id)
618
+ case id
619
+ when AuthorizeNet::AIM::Response
620
+ set_fields(:trans_id => id.transaction_id.to_s)
621
+ else
622
+ set_fields(:trans_id => id.to_s)
623
+ end
624
+ end
625
+
626
+ # Handles packing up aim options.
627
+ def handle_aim_options(options)
628
+ encoded_options = []
629
+ case options
630
+ when Hash
631
+ options.each_pair do |k,v|
632
+ if @@aim_response_options.include?(k)
633
+ self.instance_variable_set(('@' + k.to_s).to_sym, v)
634
+ end
635
+ end
636
+ when nil
637
+ return
638
+ else
639
+ return handle_aim_options(options.to_hash)
640
+ end
641
+
642
+ @fields[:extra_options] ||= {}
643
+ @fields[:extra_options].merge!(options)
644
+ end
645
+
646
+ # Handles packing up custom fields.
647
+ def handle_custom_fields(options)
648
+ encoded_options = []
649
+ case options
650
+ when Hash
651
+ @custom_fields.merge!(options)
652
+ when nil
653
+ return
654
+ else
655
+ return handle_custom_fields(options.to_hash)
656
+ end
657
+ end
658
+
659
+ # Callback for creating the right node structure for a given transaction type. `node` is ignored for now.
660
+ def select_transaction_type_fields(node)
661
+ case @transaction_type
662
+ when :auth_only
663
+ return TRANSACTION_AUTH_FIELDS
664
+ when :auth_capture
665
+ return TRANSACTION_AUTH_CAPTURE_FIELDS
666
+ when :void
667
+ return TRANSACTION_VOID_FIELDS
668
+ when :refund
669
+ return TRANSACTION_REFUND_FIELDS
670
+ when :capture_only
671
+ return TRASNACTION_CAPTURE_FIELDS
672
+ when :prior_auth_capture
673
+ return TRANSACTION_PRIOR_AUTH_CAPTURE_FIELDS
674
+ end
675
+ end
676
+
677
+ end
678
+ end