authorizenet 1.9.5 → 1.9.6

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