authorizenet_blaq 1.9.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/app/helpers/authorize_net_helper.rb +24 -0
- data/lib/authorize_net/addresses/address.rb +29 -0
- data/lib/authorize_net/addresses/shipping_address.rb +26 -0
- data/lib/authorize_net/aim/response.rb +131 -0
- data/lib/authorize_net/aim/transaction.rb +190 -0
- data/lib/authorize_net/api/api_transaction.rb +123 -0
- data/lib/authorize_net/api/constants.yml +1 -0
- data/lib/authorize_net/api/schema.rb +4985 -0
- data/lib/authorize_net/api/transaction.rb +258 -0
- data/lib/authorize_net/arb/fields.rb +24 -0
- data/lib/authorize_net/arb/paging.rb +33 -0
- data/lib/authorize_net/arb/response.rb +34 -0
- data/lib/authorize_net/arb/sorting.rb +43 -0
- data/lib/authorize_net/arb/subscription.rb +72 -0
- data/lib/authorize_net/arb/subscription_detail.rb +14 -0
- data/lib/authorize_net/arb/subscription_list_response.rb +43 -0
- data/lib/authorize_net/arb/transaction.rb +177 -0
- data/lib/authorize_net/authorize_net.rb +154 -0
- data/lib/authorize_net/cim/customer_profile.rb +19 -0
- data/lib/authorize_net/cim/payment_profile.rb +37 -0
- data/lib/authorize_net/cim/response.rb +116 -0
- data/lib/authorize_net/cim/transaction.rb +727 -0
- data/lib/authorize_net/customer.rb +27 -0
- data/lib/authorize_net/email_receipt.rb +24 -0
- data/lib/authorize_net/fields.rb +779 -0
- data/lib/authorize_net/key_value_response.rb +117 -0
- data/lib/authorize_net/key_value_transaction.rb +291 -0
- data/lib/authorize_net/line_item.rb +25 -0
- data/lib/authorize_net/order.rb +42 -0
- data/lib/authorize_net/payment_methods/credit_card.rb +62 -0
- data/lib/authorize_net/payment_methods/echeck.rb +72 -0
- data/lib/authorize_net/reporting/batch.rb +19 -0
- data/lib/authorize_net/reporting/batch_statistics.rb +19 -0
- data/lib/authorize_net/reporting/fds_filter.rb +11 -0
- data/lib/authorize_net/reporting/response.rb +163 -0
- data/lib/authorize_net/reporting/returned_item.rb +46 -0
- data/lib/authorize_net/reporting/transaction.rb +133 -0
- data/lib/authorize_net/reporting/transaction_details.rb +25 -0
- data/lib/authorize_net/response.rb +27 -0
- data/lib/authorize_net/sim/hosted_payment_form.rb +38 -0
- data/lib/authorize_net/sim/hosted_receipt_page.rb +37 -0
- data/lib/authorize_net/sim/response.rb +142 -0
- data/lib/authorize_net/sim/transaction.rb +138 -0
- data/lib/authorize_net/transaction.rb +66 -0
- data/lib/authorize_net/xml_response.rb +172 -0
- data/lib/authorize_net/xml_transaction.rb +298 -0
- data/lib/authorize_net.rb +107 -0
- data/lib/authorizenet_blaq.rb +4 -0
- data/lib/generators/authorize_net/direct_post/direct_post_generator.rb +53 -0
- data/lib/generators/authorize_net/direct_post/templates/README-AuthorizeNet +49 -0
- data/lib/generators/authorize_net/direct_post/templates/config.yml.erb +8 -0
- data/lib/generators/authorize_net/direct_post/templates/config.yml.rails3.erb +8 -0
- data/lib/generators/authorize_net/direct_post/templates/controller.rb.erb +31 -0
- data/lib/generators/authorize_net/direct_post/templates/initializer.rb +4 -0
- data/lib/generators/authorize_net/direct_post/templates/layout.erb +18 -0
- data/lib/generators/authorize_net/direct_post/templates/payment.erb +10 -0
- data/lib/generators/authorize_net/direct_post/templates/payment.rails3.erb +10 -0
- data/lib/generators/authorize_net/direct_post/templates/receipt.erb +1 -0
- data/lib/generators/authorize_net/direct_post/templates/relay_response.erb +1 -0
- data/lib/generators/authorize_net/sim/sim_generator.rb +47 -0
- data/lib/generators/authorize_net/sim/templates/README-AuthorizeNet +52 -0
- data/lib/generators/authorize_net/sim/templates/config.yml.erb +8 -0
- data/lib/generators/authorize_net/sim/templates/config.yml.rails3.erb +8 -0
- data/lib/generators/authorize_net/sim/templates/controller.rb.erb +21 -0
- data/lib/generators/authorize_net/sim/templates/initializer.rb +4 -0
- data/lib/generators/authorize_net/sim/templates/layout.erb +18 -0
- data/lib/generators/authorize_net/sim/templates/payment.erb +6 -0
- data/lib/generators/authorize_net/sim/templates/payment.rails3.erb +6 -0
- data/lib/generators/authorize_net/sim/templates/thank_you.erb +1 -0
- data/lib/generators/generator_extensions.rb +75 -0
- metadata +196 -0
@@ -0,0 +1,727 @@
|
|
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 => true,
|
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 true.
|
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 get_hosted_profile_token.
|
44
|
+
@@get_hosted_profile_token_option_defaults = {
|
45
|
+
:border_visible => true,
|
46
|
+
:validation_mode => :none,
|
47
|
+
}
|
48
|
+
|
49
|
+
# The default options for create_payment_profile.
|
50
|
+
@@create_payment_profile_option_defaults = {
|
51
|
+
:validation_mode => :none
|
52
|
+
}
|
53
|
+
|
54
|
+
# The default options for update_payment_profile.
|
55
|
+
@@update_payment_profile_option_defaults = {
|
56
|
+
:validation_mode => :none
|
57
|
+
}
|
58
|
+
|
59
|
+
# The default options for create_transaction and the various type specific create transaction methods.
|
60
|
+
@@create_transaction_option_defaults = {
|
61
|
+
:address_id => nil,
|
62
|
+
:split_tender_id => nil,
|
63
|
+
:aim_options => nil,
|
64
|
+
:custom_fields => nil
|
65
|
+
}
|
66
|
+
|
67
|
+
# The default options for validate_payment_profile.
|
68
|
+
@@validate_payment_profile_option_defaults = {
|
69
|
+
:address_id => nil,
|
70
|
+
:card_code => nil,
|
71
|
+
:validation_mode => :testMode
|
72
|
+
}
|
73
|
+
|
74
|
+
# A list of keys that should be stored if passed as aim_options.
|
75
|
+
@@aim_response_options = [:delim_char, :encap_char]
|
76
|
+
|
77
|
+
# Sets up and submits a createCustomerProfileRequest transaction. If this transaction has already been
|
78
|
+
# run, this method will return nil. Otherwise it will return an AuthorizeNet::CIM::Response object. The
|
79
|
+
# response object will have a profile_id if the request was successful. If any PaymentProfiles or Addresses
|
80
|
+
# were included, you can find their IDs in the response objects payment_profile_ids and address_ids methods.
|
81
|
+
#
|
82
|
+
# +profile+:: An AuthorizeNet::CIM::CustomerProfile object describing the profile to create.
|
83
|
+
# +options+:: An optional hash of options.
|
84
|
+
#
|
85
|
+
# Options:
|
86
|
+
# +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)
|
87
|
+
#
|
88
|
+
# Typical usage:
|
89
|
+
#
|
90
|
+
# profile = AuthorizeNet::CIM::CustomerProfile.new(
|
91
|
+
# :email => 'test@example.com',
|
92
|
+
# :id => 'userassignedid'
|
93
|
+
# )
|
94
|
+
# response = transaction.create_profile(profile)
|
95
|
+
# puts response.profile_id if response.success?
|
96
|
+
#
|
97
|
+
def create_profile(profile, options = {})
|
98
|
+
options = @@create_profile_option_defaults.merge(options)
|
99
|
+
@type = Type::CIM_CREATE_PROFILE
|
100
|
+
@fields.merge!(profile.to_hash)
|
101
|
+
set_fields(:validation_mode => options[:validation_mode])
|
102
|
+
make_request
|
103
|
+
end
|
104
|
+
|
105
|
+
# Sets up and submits a getCustomerProfileRequest transaction. If this transaction has already been
|
106
|
+
# run, this method will return nil. Otherwise it will return an AuthorizeNet::CIM::Response object. The
|
107
|
+
# response object will have the CustomerProfile object requested available via its profile method if
|
108
|
+
# the request was successful.
|
109
|
+
#
|
110
|
+
#
|
111
|
+
# +profile_id+:: Takes either a String containing the ID of the CustomerProfile you want to retrieve, or a CustomerProfile object with the ID populated.
|
112
|
+
# Typical usage:
|
113
|
+
#
|
114
|
+
# response = transaction.get_profile('123456')
|
115
|
+
# profile = response.profile if response.success?
|
116
|
+
#
|
117
|
+
def get_profile(profile_id)
|
118
|
+
@type = Type::CIM_GET_PROFILE
|
119
|
+
handle_profile_id(profile_id)
|
120
|
+
make_request
|
121
|
+
end
|
122
|
+
|
123
|
+
# Sets up and submits a updateCustomerProfileRequest transaction. If this transaction has already been
|
124
|
+
# run, this method will return nil. Otherwise it will return an AuthorizeNet::CIM::Response object. Note that
|
125
|
+
# any PaymentProfiles will NOT be updated using this method. This is a limitation of the CIM API. See
|
126
|
+
# update_payment_profile if you need to update a PaymentProfile.
|
127
|
+
#
|
128
|
+
#
|
129
|
+
# +profile+:: An AuthorizeNet::CIM::CustomerProfile object describing the profile to update. It must contain the customer_profile_id of the record to update.
|
130
|
+
# Typical usage:
|
131
|
+
#
|
132
|
+
# profile.fax = '5555551234'
|
133
|
+
# response = transaction.update_profile(profile)
|
134
|
+
# puts response.success?
|
135
|
+
#
|
136
|
+
def update_profile(profile)
|
137
|
+
@type = Type::CIM_UPDATE_PROFILE
|
138
|
+
@fields.merge!(profile.to_hash)
|
139
|
+
make_request
|
140
|
+
end
|
141
|
+
|
142
|
+
# Sets up and submits a deleteCustomerProfileRequest transaction. If this transaction has already been
|
143
|
+
# run, this method will return nil. Otherwise it will return an AuthorizeNet::CIM::Response object.
|
144
|
+
#
|
145
|
+
#
|
146
|
+
# +profile_id+:: Takes either a String containing the ID of the CustomerProfile you want to delete, or a CustomerProfile object with the ID populated.
|
147
|
+
# Typical usage:
|
148
|
+
#
|
149
|
+
# response = transaction.delete_profile('123456')
|
150
|
+
# puts response.success?
|
151
|
+
#
|
152
|
+
def delete_profile(profile_id)
|
153
|
+
@type = Type::CIM_DELETE_PROFILE
|
154
|
+
handle_profile_id(profile_id)
|
155
|
+
make_request
|
156
|
+
end
|
157
|
+
|
158
|
+
# Sets up and submits a getHostedProfilePageRequest transaction. If this transaction has already been
|
159
|
+
# run, this method will return nil. Otherwise it will return an AuthorizeNet::CIM::Response object.
|
160
|
+
#
|
161
|
+
# +profile_id+:: Takes either a String containing the ID of the CustomerProfile you want to delete, or a CustomerProfile object with the ID populated.
|
162
|
+
#
|
163
|
+
# Options:
|
164
|
+
# +return_url+:: Enter the URL for the page that the customer returns to when the hosted session ends. Do not pass this setting for iframes or popups.
|
165
|
+
# +return_url_text+:: Enter the text to display on the button that returns the customer to your web site. The value can be any text up to 200 characters.
|
166
|
+
# If you do not pass this parameter, the default button text is Continue. Do not pass this setting for iframes or popups.
|
167
|
+
# +heading_color+:: Enter a hex color string such as #e0e0e0. The background color of the section headers changes from gray to a custom color.
|
168
|
+
# +border_visible+:: Enter true or false. Must be false for iframes or popups, and must be true for redirects.
|
169
|
+
# +iframe_communicator_url+:: Enter the URL to a page that can communicate with the merchant’s main page using javascript.
|
170
|
+
# This parameter enables you to dynamically change the size of the popup so that there are no scroll bars.
|
171
|
+
# This parameter is required only for iframe or lightbox applications.
|
172
|
+
# +validation_mode+:: Set to :testMode, :liveMode or :none (the default) to set hostedProfileValidationMode mode
|
173
|
+
|
174
|
+
def get_hosted_profile_token(profile_id, options = {})
|
175
|
+
options = @@get_hosted_profile_token_option_defaults.merge(options)
|
176
|
+
@type = Type::CIM_GET_HOSTED_PROFILE
|
177
|
+
handle_profile_id(profile_id)
|
178
|
+
handle_hosted_profile_settings(options)
|
179
|
+
make_request
|
180
|
+
end
|
181
|
+
|
182
|
+
# Sets up and submits a createCustomerPaymentProfileRequest transaction. If this transaction has already been
|
183
|
+
# run, this method will return nil. Otherwise it will return an AuthorizeNet::CIM::Response object. The
|
184
|
+
# response object will have a payment_profile_id if the request was successful.
|
185
|
+
#
|
186
|
+
# +profile+:: An AuthorizeNet::CIM::PaymentProfile object describing the profile to create.
|
187
|
+
# +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.
|
188
|
+
# +options+:: An optional hash of options.
|
189
|
+
#
|
190
|
+
# Options:
|
191
|
+
# +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)
|
192
|
+
#
|
193
|
+
# Typical usage:
|
194
|
+
#
|
195
|
+
# credit_card = AuthorizeNet::CreditCard.new('4111111111111111', '0120')
|
196
|
+
# payment_profile = AuthorizeNet::CIM::PaymentProfile.new(:payment_method => credit_card)
|
197
|
+
# response = transaction.create_payment_profile(payment_profile, '123456')
|
198
|
+
# puts response.payment_profile_id if response.success?
|
199
|
+
#
|
200
|
+
def create_payment_profile(payment_profile, profile_id, options = {})
|
201
|
+
options = @@create_payment_profile_option_defaults.merge(options)
|
202
|
+
@type = Type::CIM_CREATE_PAYMENT
|
203
|
+
@fields.merge!(payment_profile.to_hash)
|
204
|
+
set_fields(:validation_mode => options[:validation_mode])
|
205
|
+
handle_profile_id(profile_id)
|
206
|
+
make_request
|
207
|
+
end
|
208
|
+
|
209
|
+
# Sets up and submits a getCustomerPaymentProfileRequest transaction. If this transaction has already been
|
210
|
+
# run, this method will return nil. Otherwise it will return an AuthorizeNet::CIM::Response object. The
|
211
|
+
# response object will have the PaymentProfile object requested available via its payment_profile method if
|
212
|
+
# the request was successful.
|
213
|
+
#
|
214
|
+
# +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.
|
215
|
+
# +profile_id+:: Takes either a String containing the ID of the CustomerProfile who owns this PaymentProfile, or a CustomerProfile object with the ID populated.
|
216
|
+
#
|
217
|
+
# Typical usage:
|
218
|
+
#
|
219
|
+
# response = transaction.get_payment_profile('654321', '123456')
|
220
|
+
# payment_profile = response.payment_profile if response.success?
|
221
|
+
#
|
222
|
+
def get_payment_profile(payment_profile_id, profile_id)
|
223
|
+
@type = Type::CIM_GET_PAYMENT
|
224
|
+
handle_payment_profile_id(payment_profile_id)
|
225
|
+
handle_profile_id(profile_id)
|
226
|
+
make_request
|
227
|
+
end
|
228
|
+
|
229
|
+
# Sets up and submits a updateCustomerPaymentProfileRequest transaction. If this transaction has already been
|
230
|
+
# run, this method will return nil. Otherwise it will return an AuthorizeNet::CIM::Response object.
|
231
|
+
#
|
232
|
+
#
|
233
|
+
# +payment_profile+:: An AuthorizeNet::CIM::PaymentProfile object describing the profile to update.
|
234
|
+
# +profile_id+:: Takes either a String containing the ID of the CustomerProfile who owns this PaymentProfile, or a CustomerProfile object with the ID populated.
|
235
|
+
#
|
236
|
+
# Typical usage:
|
237
|
+
#
|
238
|
+
# payment_profile.cust_type = :business
|
239
|
+
# response = transaction.update_payment_profile(payment_profile, '123456')
|
240
|
+
# puts response.success?
|
241
|
+
#
|
242
|
+
# Options:
|
243
|
+
# +validation_mode+:: Set to :testMode, :liveMode or :none (the default) to indicate what sort of PaymentProfile validation to do.
|
244
|
+
#
|
245
|
+
def update_payment_profile(payment_profile, profile_id, options = {})
|
246
|
+
options = @@create_payment_profile_option_defaults.merge(options)
|
247
|
+
@type = Type::CIM_UPDATE_PAYMENT
|
248
|
+
@fields.merge!(payment_profile.to_hash)
|
249
|
+
set_fields(:validation_mode => options[:validation_mode])
|
250
|
+
handle_profile_id(profile_id)
|
251
|
+
make_request
|
252
|
+
end
|
253
|
+
|
254
|
+
# Sets up and submits a deleteCustomerPaymentProfileRequest transaction. If this transaction has already been
|
255
|
+
# run, this method will return nil. Otherwise it will return an AuthorizeNet::CIM::Response object.
|
256
|
+
#
|
257
|
+
#
|
258
|
+
# +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.
|
259
|
+
# +profile_id+:: Takes either a String containing the ID of the CustomerProfile who owns this PaymentProfile, or a CustomerProfile object with the ID populated.
|
260
|
+
#
|
261
|
+
# Typical usage:
|
262
|
+
#
|
263
|
+
# response = transaction.delete_profile('123456')
|
264
|
+
# puts response.success?
|
265
|
+
#
|
266
|
+
def delete_payment_profile(payment_profile_id, profile_id)
|
267
|
+
@type = Type::CIM_DELETE_PAYMENT
|
268
|
+
handle_payment_profile_id(payment_profile_id)
|
269
|
+
handle_profile_id(profile_id)
|
270
|
+
make_request
|
271
|
+
end
|
272
|
+
|
273
|
+
# Sets up and submits a validateCustomerPaymentProfileRequest transaction. If this transaction has already been
|
274
|
+
# run, this method will return nil. Otherwise it will return an AuthorizeNet::CIM::Response object. The results
|
275
|
+
# of the validation can be obtained via the direct_response method of the response object.
|
276
|
+
#
|
277
|
+
#
|
278
|
+
# +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.
|
279
|
+
# +profile_id+:: Takes either a String containing the ID of the CustomerProfile who owns this PaymentProfile, or a CustomerProfile object with the ID populated.
|
280
|
+
#
|
281
|
+
# Typical usage:
|
282
|
+
#
|
283
|
+
# response = transaction.validate_payment_profile('654321', '123456')
|
284
|
+
# puts response.direct_response.success? if response.success?
|
285
|
+
#
|
286
|
+
# Options:
|
287
|
+
# +validation_mode+:: Set to :testMode (the default) or :liveMode to indicate what sort of PaymentProfile validation to do.
|
288
|
+
# +address_id+:: Set a shipping Address to be part of the validation transaction.
|
289
|
+
# +card_code+:: Set a CCV code if one is needed for validation. Defaults to nil.
|
290
|
+
#
|
291
|
+
def validate_payment_profile(payment_profile_id, profile_id, options = {})
|
292
|
+
@type = Type::CIM_VALIDATE_PAYMENT
|
293
|
+
options = @@validate_payment_profile_option_defaults.merge(options)
|
294
|
+
handle_payment_profile_id(payment_profile_id)
|
295
|
+
handle_profile_id(profile_id)
|
296
|
+
handle_address_id(options[:address_id]) unless options[:address_id].nil?
|
297
|
+
set_fields(:validation_mode => options[:validation_mode])
|
298
|
+
set_fields(:card_code => options[:card_code]) unless options[:card_code].nil?
|
299
|
+
make_request
|
300
|
+
end
|
301
|
+
|
302
|
+
# Sets up and submits a createCustomerShippingAddressRequest transaction. If this transaction has already been
|
303
|
+
# run, this method will return nil. Otherwise it will return an AuthorizeNet::CIM::Response object. The
|
304
|
+
# response object will have a address_id if the request was successful.
|
305
|
+
#
|
306
|
+
# +address+:: An AuthorizeNet::Address object describing the profile to create.
|
307
|
+
# +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.
|
308
|
+
#
|
309
|
+
# Typical usage:
|
310
|
+
#
|
311
|
+
# address = AuthorizeNet::Address.new(:first_name => 'Jane', :last_name => 'Doe', :address => '123 Fake St', :city => 'Raccoon Junction', :state => 'WY', :zip => '99999')
|
312
|
+
# response = transaction.create_address(address, '123456')
|
313
|
+
# puts response.address_id if response.success?
|
314
|
+
#
|
315
|
+
def create_address(address, profile_id)
|
316
|
+
@type = Type::CIM_CREATE_ADDRESS
|
317
|
+
@fields.merge!(address.to_hash)
|
318
|
+
handle_profile_id(profile_id)
|
319
|
+
make_request
|
320
|
+
end
|
321
|
+
|
322
|
+
# Sets up and submits a getCustomerShippingAddressRequest transaction. If this transaction has already been
|
323
|
+
# run, this method will return nil. Otherwise it will return an AuthorizeNet::CIM::Response object. The
|
324
|
+
# response object will have the Address object requested available via its address method if
|
325
|
+
# the request was successful.
|
326
|
+
#
|
327
|
+
#
|
328
|
+
# +address_id+:: Takes either a String containing the ID of the Address you want to retrieve, or an Address object with the ID populated.
|
329
|
+
# +profile_id+:: Takes either a String containing the ID of the CustomerProfile who owns this Address, or a CustomerProfile object with the ID populated.
|
330
|
+
#
|
331
|
+
# Typical usage:
|
332
|
+
#
|
333
|
+
# response = transaction.get_address('654321', '123456')
|
334
|
+
# address = response.address if response.success?
|
335
|
+
#
|
336
|
+
def get_address(address_id, profile_id)
|
337
|
+
@type = Type::CIM_GET_ADDRESS
|
338
|
+
handle_address_id(address_id)
|
339
|
+
handle_profile_id(profile_id)
|
340
|
+
make_request
|
341
|
+
end
|
342
|
+
|
343
|
+
# Sets up and submits a updateCustomerShippingAddressRequest transaction. If this transaction has already been
|
344
|
+
# run, this method will return nil. Otherwise it will return an AuthorizeNet::CIM::Response object.
|
345
|
+
#
|
346
|
+
#
|
347
|
+
# +address+:: An Address object describing the address to update.
|
348
|
+
# +profile_id+:: Takes either a String containing the ID of the CustomerProfile who owns this Address, or a CustomerProfile object with the ID populated.
|
349
|
+
#
|
350
|
+
# Typical usage:
|
351
|
+
#
|
352
|
+
# address.city = 'Somewhere Else'
|
353
|
+
# response = transaction.update_address(address, '123456')
|
354
|
+
# puts response.success?
|
355
|
+
#
|
356
|
+
def update_address(address, profile_id)
|
357
|
+
@type = Type::CIM_UPDATE_ADDRESS
|
358
|
+
@fields.merge!(address.to_hash)
|
359
|
+
handle_profile_id(profile_id)
|
360
|
+
make_request
|
361
|
+
end
|
362
|
+
|
363
|
+
# Sets up and submits a deleteCustomerShippingAddressRequest transaction. If this transaction has already been
|
364
|
+
# run, this method will return nil. Otherwise it will return an AuthorizeNet::CIM::Response object.
|
365
|
+
#
|
366
|
+
#
|
367
|
+
# +address_id+:: Takes either a String containing the ID of the Address you want to delete, or an Address object with the ID populated.
|
368
|
+
# +profile_id+:: Takes either a String containing the ID of the CustomerProfile who owns this Address, or a CustomerProfile object with the ID populated.
|
369
|
+
#
|
370
|
+
# Typical usage:
|
371
|
+
#
|
372
|
+
# response = transaction.delete_address('654321', '123456')
|
373
|
+
# puts response.success?
|
374
|
+
#
|
375
|
+
def delete_address(address_id, profile_id)
|
376
|
+
@type = Type::CIM_DELETE_ADDRESS
|
377
|
+
handle_address_id(address_id)
|
378
|
+
handle_profile_id(profile_id)
|
379
|
+
make_request
|
380
|
+
end
|
381
|
+
|
382
|
+
# Sets up and submits a createCustomerProfileTransactionRequest transaction. If this transaction has already been
|
383
|
+
# run, this method will return nil. Otherwise it will return an AuthorizeNet::CIM::Response object. It is recommend
|
384
|
+
# to use the connivence methods for each type of payment transaction rather than this method.
|
385
|
+
#
|
386
|
+
# +type+:: The type of payment transaction to run. Can be :auth_capture, :auth_only, :prior_auth_capture, :void, or :refund.
|
387
|
+
# +amount+:: The amount of the transaction. This is required for every transaction type except :void.
|
388
|
+
# +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.
|
389
|
+
# +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.
|
390
|
+
# +order+:: An Order object describing the order that this payment transaction is for. Pass nil for no order.
|
391
|
+
# +options+:: An optional hash of options.
|
392
|
+
#
|
393
|
+
# Options:
|
394
|
+
# +address_id+:: Takes either a String containing the ID of an Address, or an Address object with the ID populated. Used as the shipping address for the payment transaction. Defaults to nil.
|
395
|
+
# +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.
|
396
|
+
# +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.
|
397
|
+
# +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.
|
398
|
+
#
|
399
|
+
# Typical usage:
|
400
|
+
#
|
401
|
+
# response = transaction.create_transaction(:auth_capture, 10.00, '123456', '654321', nil)
|
402
|
+
# if response.success?
|
403
|
+
# puts response.direct_response if direct_response.success?
|
404
|
+
#
|
405
|
+
#
|
406
|
+
def create_transaction(type, amount, profile_id, payment_profile_id, order, options = {})
|
407
|
+
@type = Type::CIM_CREATE_TRANSACTION
|
408
|
+
options = @@create_transaction_option_defaults.merge(options)
|
409
|
+
handle_profile_id(profile_id)
|
410
|
+
handle_payment_profile_id(payment_profile_id)
|
411
|
+
handle_address_id(options[:address_id]) unless options[:address_id].nil?
|
412
|
+
set_fields(:split_tender_id => options[:split_tender_id])
|
413
|
+
@transaction_type = type
|
414
|
+
@fields.merge!(order.to_hash) unless order.nil?
|
415
|
+
set_fields(:amount => amount)
|
416
|
+
handle_aim_options(options[:aim_options])
|
417
|
+
handle_custom_fields(options[:custom_fields])
|
418
|
+
make_request
|
419
|
+
end
|
420
|
+
|
421
|
+
|
422
|
+
# Sets up and submits an AUTHORIZE_AND_CAPTURE transaction using stored payment information. If this
|
423
|
+
# transaction has already been run, this method will return nil. Otherwise it will return an
|
424
|
+
# AuthorizeNet::CIM::Response object.
|
425
|
+
#
|
426
|
+
# +amount+:: The amount of the transaction.
|
427
|
+
# +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.
|
428
|
+
# +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.
|
429
|
+
# +order+:: An Order object describing the order that this payment transaction is for. Pass nil for no order.
|
430
|
+
# +options+:: An optional hash of options.
|
431
|
+
#
|
432
|
+
# Options:
|
433
|
+
# +address_id+:: Takes either a String containing the ID of an Address, or an Address object with the ID populated. Used as the shipping address for the payment transaction. Defaults to nil.
|
434
|
+
# +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.
|
435
|
+
# +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.
|
436
|
+
# +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.
|
437
|
+
#
|
438
|
+
# Typical usage:
|
439
|
+
#
|
440
|
+
# response = transaction.create_transaction_auth_capture(10.00, '123456', '654321', nil)
|
441
|
+
# if response.success?
|
442
|
+
# puts response.direct_response if direct_response.success?
|
443
|
+
#
|
444
|
+
def create_transaction_auth_capture(amount, profile_id, payment_profile_id, order = nil, options = {})
|
445
|
+
create_transaction(:auth_capture, amount, profile_id, payment_profile_id, order, options)
|
446
|
+
end
|
447
|
+
|
448
|
+
# Sets up and submits an AUTH_ONLY transaction using stored payment information. If this
|
449
|
+
# transaction has already been run, this method will return nil. Otherwise it will return an
|
450
|
+
# AuthorizeNet::CIM::Response object.
|
451
|
+
#
|
452
|
+
# +amount+:: The amount of the transaction.
|
453
|
+
# +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.
|
454
|
+
# +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.
|
455
|
+
# +order+:: An Order object describing the order that this payment transaction is for. Pass nil for no order.
|
456
|
+
# +options+:: An optional hash of options.
|
457
|
+
#
|
458
|
+
# Options:
|
459
|
+
# +address_id+:: Takes either a String containing the ID of an Address, or an Address object with the ID populated. Used as the shipping address for the payment transaction. Defaults to nil.
|
460
|
+
# +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.
|
461
|
+
# +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.
|
462
|
+
# +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.
|
463
|
+
#
|
464
|
+
# Typical usage:
|
465
|
+
#
|
466
|
+
# response = transaction.create_transaction_auth_only(10.00, '123456', '654321', nil)
|
467
|
+
# if response.success?
|
468
|
+
# puts response.direct_response if direct_response.success?
|
469
|
+
#
|
470
|
+
def create_transaction_auth_only(amount, profile_id, payment_profile_id, order = nil, options = {})
|
471
|
+
create_transaction(:auth_only, amount, profile_id, payment_profile_id, order, options)
|
472
|
+
end
|
473
|
+
|
474
|
+
# Sets up and submits a PRIOR_AUTHORIZATION_AND_CAPTURE transaction using stored payment information. If this
|
475
|
+
# transaction has already been run, this method will return nil. Otherwise it will return an
|
476
|
+
# AuthorizeNet::CIM::Response object.
|
477
|
+
#
|
478
|
+
# +transaction_id+:: A string containing a transaction ID that was generated via an AUTH_ONLY transaction.
|
479
|
+
# +amount+:: The amount to capture. Must be <= the amount authorized via the AUTH_ONLY transaction.
|
480
|
+
# +order+:: An Order object describing the order that this payment transaction is for. Pass nil for no order.
|
481
|
+
# +options+:: An optional hash of options.
|
482
|
+
#
|
483
|
+
# Options:
|
484
|
+
# +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.
|
485
|
+
# +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.
|
486
|
+
#
|
487
|
+
# Typical usage:
|
488
|
+
#
|
489
|
+
# response = transaction.create_transaction_prior_auth_capture('111222', 10.00)
|
490
|
+
# if response.success?
|
491
|
+
# puts response.direct_response if direct_response.success?
|
492
|
+
#
|
493
|
+
def create_transaction_prior_auth_capture(transaction_id, amount, order = nil, options = {})
|
494
|
+
handle_transaction_id(transaction_id)
|
495
|
+
create_transaction(:prior_auth_capture, amount, nil, nil, order, options)
|
496
|
+
end
|
497
|
+
|
498
|
+
# Sets up and submits a VOID transaction using stored payment information. If this
|
499
|
+
# transaction has already been run, this method will return nil. Otherwise it will return an
|
500
|
+
# AuthorizeNet::CIM::Response object.
|
501
|
+
#
|
502
|
+
# +transaction_id+:: A string containing a transaction ID to void.
|
503
|
+
# +options+:: An optional hash of options.
|
504
|
+
#
|
505
|
+
# Options:
|
506
|
+
# +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.
|
507
|
+
# +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.
|
508
|
+
#
|
509
|
+
# Typical usage:
|
510
|
+
#
|
511
|
+
# response = transaction.create_transaction_void('111222')
|
512
|
+
# if response.success?
|
513
|
+
# puts response.direct_response if direct_response.success?
|
514
|
+
#
|
515
|
+
def create_transaction_void(transaction_id, options = {})
|
516
|
+
handle_transaction_id(transaction_id)
|
517
|
+
create_transaction(:void, nil, nil, nil, nil, options)
|
518
|
+
end
|
519
|
+
|
520
|
+
# Sets up and submits a REFUND transaction using stored payment information. If this
|
521
|
+
# transaction has already been run, this method will return nil. Otherwise it will return an
|
522
|
+
# AuthorizeNet::CIM::Response object.
|
523
|
+
#
|
524
|
+
# +transaction_id+:: A string containing a transaction ID to refund. Pass nil for an unlinked refund.
|
525
|
+
# +amount+:: The amount to refund.
|
526
|
+
# +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.
|
527
|
+
# +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.
|
528
|
+
# +order+:: An Order object describing the order that is being refunded. Pass nil for no order.
|
529
|
+
# +options+:: An optional hash of options.
|
530
|
+
#
|
531
|
+
# Options:
|
532
|
+
# +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.
|
533
|
+
# +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.
|
534
|
+
#
|
535
|
+
# Typical usage:
|
536
|
+
#
|
537
|
+
# response = transaction.create_transaction_refund('111222', 10.00, '123456', '654321')
|
538
|
+
# if response.success?
|
539
|
+
# puts response.direct_response if direct_response.success?
|
540
|
+
#
|
541
|
+
def create_transaction_refund(transaction_id, amount, profile_id, payment_profile_id, order = nil, options = {})
|
542
|
+
handle_transaction_id(transaction_id)
|
543
|
+
create_transaction(:refund, amount, profile_id, payment_profile_id, order, options)
|
544
|
+
end
|
545
|
+
|
546
|
+
# Sets up and submits a updateSplitTenderGroupRequest transaction. Use this to end or void a split
|
547
|
+
# tender batch. If this transaction has already been run, this method will return nil. Otherwise
|
548
|
+
# it will return an AuthorizeNet::CIM::Response object.
|
549
|
+
#
|
550
|
+
# +split_tender_id+:: The split tender batch ID you want to change the status of.
|
551
|
+
# +status+:: The new status to set for the batch. Options are :voided or :completed.
|
552
|
+
#
|
553
|
+
# Typical usage:
|
554
|
+
#
|
555
|
+
# response = transaction.update_split_tender('1111111', :voided)
|
556
|
+
# puts response if response.success?
|
557
|
+
#
|
558
|
+
def update_split_tender(split_tender_id, status)
|
559
|
+
@type = Type::CIM_UPDATE_SPLIT
|
560
|
+
set_fields(:split_tender_id => split_tender_id, :split_tender_status => status.to_s)
|
561
|
+
make_request
|
562
|
+
end
|
563
|
+
|
564
|
+
# Sets up and submits a getCustomerProfileIdsRequest transaction. If this transaction has already been
|
565
|
+
# run, this method will return nil. Otherwise it will return an AuthorizeNet::CIM::Response object. The
|
566
|
+
# response object will have a list of all CustomerProfile IDs available via its profile_ids method on success.
|
567
|
+
#
|
568
|
+
# Typical usage:
|
569
|
+
#
|
570
|
+
# response = transaction.get_profile_ids()
|
571
|
+
# puts response.profile_ids if response.success?
|
572
|
+
#
|
573
|
+
def get_profile_ids()
|
574
|
+
@type = Type::CIM_GET_PROFILE_IDS
|
575
|
+
make_request
|
576
|
+
end
|
577
|
+
|
578
|
+
# :stopdoc:
|
579
|
+
# Duck-type as an AIM transaction so we can build AIM responses easily
|
580
|
+
|
581
|
+
# No encapsulation_character.
|
582
|
+
def encapsulation_character
|
583
|
+
@encap_char
|
584
|
+
end
|
585
|
+
|
586
|
+
# Comma delimited.
|
587
|
+
def delimiter
|
588
|
+
@delim_char
|
589
|
+
end
|
590
|
+
|
591
|
+
# Custom fields accessor.
|
592
|
+
def custom_fields
|
593
|
+
@custom_fields
|
594
|
+
end
|
595
|
+
|
596
|
+
# Always version 3.1.
|
597
|
+
def version
|
598
|
+
3.1
|
599
|
+
end
|
600
|
+
|
601
|
+
# Always nil.
|
602
|
+
def cp_version
|
603
|
+
nil
|
604
|
+
end
|
605
|
+
# :startdoc:
|
606
|
+
|
607
|
+
#:enddoc:
|
608
|
+
protected
|
609
|
+
|
610
|
+
# Handles profile id type massaging.
|
611
|
+
def handle_profile_id(id)
|
612
|
+
case id
|
613
|
+
when CustomerProfile
|
614
|
+
set_fields(:customer_profile_id => id.customer_profile_id.to_s)
|
615
|
+
when nil
|
616
|
+
nil
|
617
|
+
else
|
618
|
+
set_fields(:customer_profile_id => id.to_s)
|
619
|
+
end
|
620
|
+
end
|
621
|
+
|
622
|
+
# Handles payment profile id type massaging.
|
623
|
+
def handle_payment_profile_id(id)
|
624
|
+
case id
|
625
|
+
when PaymentProfile
|
626
|
+
set_fields(:customer_payment_profile_id => id.customer_payment_profile_id.to_s)
|
627
|
+
when nil
|
628
|
+
nil
|
629
|
+
else
|
630
|
+
set_fields(:customer_payment_profile_id => id.to_s)
|
631
|
+
end
|
632
|
+
end
|
633
|
+
|
634
|
+
# Handles address id type massaging.
|
635
|
+
def handle_address_id(id)
|
636
|
+
case id
|
637
|
+
when AuthorizeNet::Address
|
638
|
+
set_fields(:customer_address_id => id.customer_address_id.to_s)
|
639
|
+
when nil
|
640
|
+
nil
|
641
|
+
else
|
642
|
+
set_fields(:customer_address_id => id.to_s)
|
643
|
+
end
|
644
|
+
end
|
645
|
+
|
646
|
+
# Handles tranasction id type massaging.
|
647
|
+
def handle_transaction_id(id)
|
648
|
+
case id
|
649
|
+
when AuthorizeNet::AIM::Response
|
650
|
+
set_fields(:trans_id => id.transaction_id.to_s)
|
651
|
+
else
|
652
|
+
set_fields(:trans_id => id.to_s)
|
653
|
+
end
|
654
|
+
end
|
655
|
+
|
656
|
+
# Handles packing up aim options.
|
657
|
+
def handle_aim_options(options)
|
658
|
+
encoded_options = []
|
659
|
+
case options
|
660
|
+
when Hash
|
661
|
+
options.each_pair do |k,v|
|
662
|
+
if @@aim_response_options.include?(k)
|
663
|
+
self.instance_variable_set(('@' + k.to_s).to_sym, v)
|
664
|
+
end
|
665
|
+
end
|
666
|
+
when nil
|
667
|
+
return
|
668
|
+
else
|
669
|
+
return handle_aim_options(options.to_hash)
|
670
|
+
end
|
671
|
+
|
672
|
+
@fields[:extra_options] ||= {}
|
673
|
+
@fields[:extra_options].merge!(options)
|
674
|
+
end
|
675
|
+
|
676
|
+
def handle_hosted_profile_settings(options)
|
677
|
+
options_mapping = {
|
678
|
+
:return_url => :hostedProfileReturnUrl,
|
679
|
+
:return_url_text => :hostedProfileReturnUrlText,
|
680
|
+
:heading_color => :hostedProfileHeadingBgColor,
|
681
|
+
:border_visible => :hostedProfilePageBorderVisible,
|
682
|
+
:iframe_communicator_url => :hostedProfileIFrameCommunicatorUrl,
|
683
|
+
:validation_mode => :hostedProfileValidationMode,
|
684
|
+
}
|
685
|
+
set_fields(
|
686
|
+
:hosted_settings =>
|
687
|
+
options.select do |k,_|
|
688
|
+
options_mapping.keys.include? k
|
689
|
+
end.map do |k,v|
|
690
|
+
{ :setting_name => options_mapping[k], :setting_value => v }
|
691
|
+
end
|
692
|
+
)
|
693
|
+
end
|
694
|
+
|
695
|
+
# Handles packing up custom fields.
|
696
|
+
def handle_custom_fields(options)
|
697
|
+
encoded_options = []
|
698
|
+
case options
|
699
|
+
when Hash
|
700
|
+
@custom_fields.merge!(options)
|
701
|
+
when nil
|
702
|
+
return
|
703
|
+
else
|
704
|
+
return handle_custom_fields(options.to_hash)
|
705
|
+
end
|
706
|
+
end
|
707
|
+
|
708
|
+
# Callback for creating the right node structure for a given transaction type. `node` is ignored for now.
|
709
|
+
def select_transaction_type_fields(node)
|
710
|
+
case @transaction_type
|
711
|
+
when :auth_only
|
712
|
+
return TRANSACTION_AUTH_FIELDS
|
713
|
+
when :auth_capture
|
714
|
+
return TRANSACTION_AUTH_CAPTURE_FIELDS
|
715
|
+
when :void
|
716
|
+
return TRANSACTION_VOID_FIELDS
|
717
|
+
when :refund
|
718
|
+
return TRANSACTION_REFUND_FIELDS
|
719
|
+
when :capture_only
|
720
|
+
return TRASNACTION_CAPTURE_FIELDS
|
721
|
+
when :prior_auth_capture
|
722
|
+
return TRANSACTION_PRIOR_AUTH_CAPTURE_FIELDS
|
723
|
+
end
|
724
|
+
end
|
725
|
+
|
726
|
+
end
|
727
|
+
end
|