authorizenet 1.9.4 → 1.9.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. data/lib/app/helpers/authorize_net_helper.rb +2 -3
  2. data/lib/authorize_net.rb +5 -5
  3. data/lib/authorize_net/addresses/address.rb +15 -19
  4. data/lib/authorize_net/addresses/shipping_address.rb +12 -16
  5. data/lib/authorize_net/aim/response.rb +27 -38
  6. data/lib/authorize_net/aim/transaction.rb +46 -65
  7. data/lib/authorize_net/api/api_transaction.rb +85 -90
  8. data/lib/authorize_net/api/constants.yml +1 -1
  9. data/lib/authorize_net/api/schema.rb +968 -936
  10. data/lib/authorize_net/api/transaction.rb +100 -102
  11. data/lib/authorize_net/arb/fields.rb +21 -21
  12. data/lib/authorize_net/arb/paging.rb +7 -11
  13. data/lib/authorize_net/arb/response.rb +7 -15
  14. data/lib/authorize_net/arb/sorting.rb +6 -10
  15. data/lib/authorize_net/arb/subscription.rb +27 -31
  16. data/lib/authorize_net/arb/subscription_detail.rb +1 -5
  17. data/lib/authorize_net/arb/subscription_list_response.rb +13 -20
  18. data/lib/authorize_net/arb/transaction.rb +50 -56
  19. data/lib/authorize_net/authorize_net.rb +20 -27
  20. data/lib/authorize_net/cim/customer_profile.rb +4 -8
  21. data/lib/authorize_net/cim/payment_profile.rb +10 -12
  22. data/lib/authorize_net/cim/response.rb +19 -24
  23. data/lib/authorize_net/cim/transaction.rb +168 -174
  24. data/lib/authorize_net/customer.rb +11 -14
  25. data/lib/authorize_net/email_receipt.rb +8 -12
  26. data/lib/authorize_net/fields.rb +483 -502
  27. data/lib/authorize_net/key_value_response.rb +54 -62
  28. data/lib/authorize_net/key_value_transaction.rb +87 -97
  29. data/lib/authorize_net/line_item.rb +10 -14
  30. data/lib/authorize_net/order.rb +21 -25
  31. data/lib/authorize_net/payment_methods/credit_card.rb +6 -7
  32. data/lib/authorize_net/payment_methods/echeck.rb +29 -31
  33. data/lib/authorize_net/reporting/batch.rb +4 -7
  34. data/lib/authorize_net/reporting/batch_statistics.rb +2 -6
  35. data/lib/authorize_net/reporting/fds_filter.rb +2 -5
  36. data/lib/authorize_net/reporting/response.rb +54 -60
  37. data/lib/authorize_net/reporting/returned_item.rb +11 -12
  38. data/lib/authorize_net/reporting/transaction.rb +27 -29
  39. data/lib/authorize_net/reporting/transaction_details.rb +3 -6
  40. data/lib/authorize_net/response.rb +6 -10
  41. data/lib/authorize_net/sim/hosted_payment_form.rb +16 -20
  42. data/lib/authorize_net/sim/hosted_receipt_page.rb +18 -23
  43. data/lib/authorize_net/sim/response.rb +24 -33
  44. data/lib/authorize_net/sim/transaction.rb +33 -43
  45. data/lib/authorize_net/transaction.rb +15 -21
  46. data/lib/authorize_net/xml_response.rb +36 -54
  47. data/lib/authorize_net/xml_transaction.rb +115 -134
  48. data/lib/generators/authorize_net/direct_post/direct_post_generator.rb +5 -6
  49. data/lib/generators/authorize_net/sim/sim_generator.rb +6 -7
  50. data/lib/generators/generator_extensions.rb +23 -25
  51. metadata +127 -81
  52. checksums.yaml +0 -7
@@ -1,13 +1,12 @@
1
1
  # The Authorize.Net Rails Helper module. Provides methods to assist with integrating the various APIs.
2
2
 
3
3
  module AuthorizeNetHelper
4
-
5
4
  # Generates a collection of hidden form fields (as a raw HTML string) for a AuthorizeNet::SIM::Transaction
6
5
  # (sim_transaction). You can specify any html_options that hidden_field_tag accepts, and the
7
6
  # hidden fields will be built with those options.
8
7
  def sim_fields(sim_transaction, html_options = {})
9
8
  fields = sim_transaction.form_fields.collect do |k, v|
10
- if v.kind_of? Array
9
+ if v.is_a? Array
11
10
  v.collect { |val| hidden_field_tag(k, val, html_options) }
12
11
  else
13
12
  hidden_field_tag(k, v, html_options)
@@ -21,4 +20,4 @@ module AuthorizeNetHelper
21
20
  return field_str
22
21
  end
23
22
  end
24
- end
23
+ end
@@ -2,7 +2,7 @@
2
2
  # the current runtime to see if Rails is present. If it is, we inject our helper into
3
3
  # ActiveSupport.
4
4
 
5
- #coverall
5
+ # coverall
6
6
  # require 'coveralls'
7
7
  # Coveralls.wear!
8
8
 
@@ -16,7 +16,7 @@ require 'date'
16
16
 
17
17
  # TODO: Add local data validation where possible
18
18
 
19
- $:.unshift File.dirname(__FILE__)
19
+ $LOAD_PATH.unshift File.dirname(__FILE__)
20
20
 
21
21
  require "authorize_net/authorize_net"
22
22
  require "authorize_net/payment_methods/credit_card"
@@ -86,8 +86,8 @@ if defined?(Rails)
86
86
  if defined?(Rails::Railtie)
87
87
  module AuthorizeNet
88
88
  class Railtie < Rails::Railtie
89
- initializer "authorize_net.load_path_initialize" do |app|
90
- %w{ models controllers helpers }.each do |dir|
89
+ initializer "authorize_net.load_path_initialize" do |_app|
90
+ %w[models controllers helpers].each do |dir|
91
91
  path = File.join(File.dirname(__FILE__), 'app', dir)
92
92
  $LOAD_PATH << path
93
93
  ActiveSupport::Dependencies.autoload_paths << path
@@ -97,7 +97,7 @@ if defined?(Rails)
97
97
  end
98
98
  end
99
99
  else
100
- %w{ models controllers helpers }.each do |dir|
100
+ %w[models controllers helpers].each do |dir|
101
101
  path = File.join(File.dirname(__FILE__), 'app', dir)
102
102
  $LOAD_PATH << path
103
103
  ActiveSupport::Dependencies.load_paths << path
@@ -1,29 +1,25 @@
1
1
  module AuthorizeNet
2
-
3
2
  # Models an address.
4
3
  class Address
5
-
6
4
  include AuthorizeNet::Model
7
-
5
+
8
6
  attr_accessor :first_name, :last_name, :company, :street_address, :city, :state, :zip, :country, :phone, :fax, :customer_address_id
9
-
7
+
10
8
  def to_hash
11
9
  hash = {
12
- :first_name => @first_name,
13
- :last_name => @last_name,
14
- :company => @company,
15
- :address => @street_address,
16
- :city => @city,
17
- :state => @state,
18
- :zip => @zip,
19
- :country => @country,
20
- :phone => @phone,
21
- :fax => @fax,
22
- :customer_address_id => @customer_address_id
10
+ first_name: @first_name,
11
+ last_name: @last_name,
12
+ company: @company,
13
+ address: @street_address,
14
+ city: @city,
15
+ state: @state,
16
+ zip: @zip,
17
+ country: @country,
18
+ phone: @phone,
19
+ fax: @fax,
20
+ customer_address_id: @customer_address_id
23
21
  }
24
- hash.delete_if {|k, v| v.nil?}
22
+ hash.delete_if { |_k, v| v.nil? }
25
23
  end
26
-
27
24
  end
28
-
29
- end
25
+ end
@@ -1,26 +1,22 @@
1
1
  module AuthorizeNet
2
-
3
2
  # Models a shipping address.
4
3
  class ShippingAddress < Address
5
-
6
4
  include AuthorizeNet::Model
7
5
 
8
6
  def to_hash
9
7
  hash = {
10
- :ship_to_first_name => @first_name,
11
- :ship_to_last_name => @last_name,
12
- :ship_to_company => @company,
13
- :ship_to_address => @street_address,
14
- :ship_to_city => @city,
15
- :ship_to_state => @state,
16
- :ship_to_zip => @zip,
17
- :ship_to_country => @country,
18
- :ship_to_phone => @phone,
19
- :ship_to_fax => @fax
8
+ ship_to_first_name: @first_name,
9
+ ship_to_last_name: @last_name,
10
+ ship_to_company: @company,
11
+ ship_to_address: @street_address,
12
+ ship_to_city: @city,
13
+ ship_to_state: @state,
14
+ ship_to_zip: @zip,
15
+ ship_to_country: @country,
16
+ ship_to_phone: @phone,
17
+ ship_to_fax: @fax
20
18
  }
21
- hash.delete_if {|k, v| v.nil?}
19
+ hash.delete_if { |_k, v| v.nil? }
22
20
  end
23
-
24
21
  end
25
-
26
- end
22
+ end
@@ -1,20 +1,17 @@
1
1
  module AuthorizeNet::AIM
2
-
3
2
  # The AIM response class. Handles parsing the response from the gateway.
4
3
  class Response < AuthorizeNet::KeyValueResponse
5
-
6
4
  # Our MD5 digest generator.
7
5
  @@digest = OpenSSL::Digest.new('md5')
8
6
 
9
7
  include AuthorizeNet::AIM::Fields
10
-
11
- # Fields to convert to/from booleans.
8
+
9
+ # Fields to convert to/from booleans.
12
10
  @@boolean_fields = [:tax_exempt]
13
-
11
+
14
12
  # Fields to convert to/from BigDecimal.
15
- @@decimal_fields = [:amount, :tax, :freight, :duty, :requested, :balance_on_card]
16
-
17
-
13
+ @@decimal_fields = %i[amount tax freight duty requested balance_on_card]
14
+
18
15
  # Constructs a new response object from a +raw_response+ and the +transaction+ that generated
19
16
  # the +raw_response+. You don't typically construct this object yourself, as AuthorizeNet::AIM::Transaction
20
17
  # will build one for you when it makes the request to the gateway.
@@ -27,9 +24,9 @@ module AuthorizeNet::AIM
27
24
  custom_field_names = transaction.custom_fields.keys.collect(&:to_s).sort.collect(&:to_sym)
28
25
  @custom_fields = {}
29
26
  split_on = transaction.delimiter
30
- if @raw_response.kind_of?(Net::HTTPOK) || @raw_response.kind_of?(Nokogiri::XML::Element)
31
- if @raw_response.kind_of?(Net::HTTPOK)
32
- raw_data = @raw_response.body
27
+ if @raw_response.is_a?(Net::HTTPOK) || @raw_response.is_a?(Nokogiri::XML::Element)
28
+ if @raw_response.is_a?(Net::HTTPOK)
29
+ raw_data = @raw_response.body
33
30
  else
34
31
  raw_data = @raw_response.text
35
32
  end
@@ -37,7 +34,7 @@ module AuthorizeNet::AIM
37
34
  split_on = transaction.encapsulation_character + split_on + transaction.encapsulation_character
38
35
  raw_data = raw_data[1..raw_data.length - 2]
39
36
  end
40
- raw_data.split(split_on).each_with_index do |field, index|
37
+ raw_data.split(split_on).each_with_index do |field, index|
41
38
  if transaction.cp_version.nil?
42
39
  field_desc = FIELDS
43
40
  else
@@ -59,32 +56,28 @@ module AuthorizeNet::AIM
59
56
  end
60
57
  end
61
58
  end
62
-
59
+
63
60
  # Returns True if the MD5 hash found in the response payload validates using
64
61
  # the supplied api_login and secret merchant_value (THIS IS NOT YOUR API KEY).
65
62
  def valid_md5?(api_login, merchant_value)
66
- if @fields[:md5_hash].nil?
67
- return false
68
- end
69
- @@digest.hexdigest("#{merchant_value}#{api_login}#{@fields[:transaction_id]}#{@transaction.fields[:amount]}").downcase == @fields[:md5_hash].downcase
63
+ return false if @fields[:md5_hash].nil?
64
+ @@digest.hexdigest("#{merchant_value}#{api_login}#{@fields[:transaction_id]}#{@transaction.fields[:amount]}").casecmp(@fields[:md5_hash]).zero?
70
65
  end
71
-
66
+
72
67
  # Returns the current API version that we are adhering to.
73
- def version
74
- @version
75
- end
76
-
68
+ attr_reader :version
69
+
77
70
  # Check to see if the response indicated success. Success is defined as a 200 OK response indicating
78
71
  # that the transaction was approved.
79
72
  def success?
80
73
  !connection_failure? && approved?
81
74
  end
82
-
75
+
83
76
  # Returns true if we failed to open a connection to the gateway or got back a non-200 OK HTTP response.
84
77
  def connection_failure?
85
- !@raw_response.kind_of?(Net::HTTPOK) && !@raw_response.kind_of?(Nokogiri::XML::Element)
78
+ !@raw_response.is_a?(Net::HTTPOK) && !@raw_response.is_a?(Nokogiri::XML::Element)
86
79
  end
87
-
80
+
88
81
  # Returns the underlying Net::HTTPResponse object. This has the original response body along with
89
82
  # headers and such. Note that if an exception is generated while making the request (which happens
90
83
  # if there is no internet connection for example), you will get the exception object here instead of
@@ -92,40 +85,36 @@ module AuthorizeNet::AIM
92
85
  def raw
93
86
  @raw_response
94
87
  end
95
-
88
+
96
89
  # Returns the AuthorizeNet::Transaction instance that owns this response.
97
- def transaction
98
- @transaction
99
- end
100
-
90
+ attr_reader :transaction
91
+
101
92
  # Returns the transaction's authorization code. This should be shown to the
102
93
  # end user.
103
94
  def authorization_code
104
95
  @fields[:authorization_code]
105
96
  end
106
-
97
+
107
98
  # Returns the transaction's authorization id. You will need this for future void, refund
108
99
  # and prior authorization capture requests.
109
100
  def transaction_id
110
101
  @fields[:transaction_id]
111
102
  end
112
-
103
+
113
104
  # Returns the customer id from the response.
114
105
  def customer_id
115
106
  @fields[:customer_id]
116
107
  end
117
-
108
+
118
109
  # Returns a response code (from AVSResponseCode) indicating the result of any Address Verification
119
- # Service checks.
110
+ # Service checks.
120
111
  def avs_response
121
112
  @fields[:avs_response]
122
113
  end
123
-
114
+
124
115
  # Returns the credit card type used in the transaction. The values returned can be found in CardType.
125
116
  def card_type
126
117
  @fields[:card_type]
127
118
  end
128
-
129
119
  end
130
-
131
- end
120
+ end
@@ -1,39 +1,37 @@
1
1
  module AuthorizeNet::AIM
2
-
3
2
  # The AIM transaction class. Handles building the transaction payload and
4
3
  # transmitting it to the gateway.
5
4
  class Transaction < AuthorizeNet::KeyValueTransaction
6
-
7
5
  # The default options for the constructor.
8
6
  @@option_defaults = {
9
- :transaction_type => Type::AUTHORIZE_AND_CAPTURE,
10
- :gateway => :production,
11
- :test => false,
12
- :allow_split => false,
13
- :delimiter => ',',
14
- :encapsulation_character => nil,
15
- :verify_ssl => true,
16
- :device_type => DeviceType::UNKNOWN,
17
- :market_type => MarketType::RETAIL
7
+ transaction_type: Type::AUTHORIZE_AND_CAPTURE,
8
+ gateway: :production,
9
+ test: false,
10
+ allow_split: false,
11
+ delimiter: ',',
12
+ encapsulation_character: nil,
13
+ verify_ssl: true,
14
+ device_type: DeviceType::UNKNOWN,
15
+ market_type: MarketType::RETAIL
18
16
  }
19
-
17
+
20
18
  # Fields to convert to/from booleans.
21
- @@boolean_fields = [:tax_exempt, :test_request, :recurring_billing, :allow_partial_auth, :delim_data, :email_customer, :relay_response]
22
-
19
+ @@boolean_fields = %i[tax_exempt test_request recurring_billing allow_partial_auth delim_data email_customer relay_response]
20
+
23
21
  # Fields to convert to/from BigDecimal.
24
22
  @@decimal_fields = [:amount]
25
-
23
+
26
24
  # Constructs an AIM transaction. You can use the new AIM transaction object
27
25
  # to issue a request to the payment gateway and parse the response into a new
28
26
  # AuthorizeNet::AIM::Response object.
29
- #
27
+ #
30
28
  # +api_login_id+:: Your API login ID, as a string.
31
29
  # +api_transaction_key+:: Your API transaction key, as a string.
32
30
  # +options+:: A hash of options. See below for values.
33
- #
31
+ #
34
32
  # Options
35
33
  # +transaction_type+:: The type of transaction to perform. Defaults to AuthorizeNet::Type::AUTHORIZE_AND_CAPTURE. This value is only used if run is called directly.
36
- # +gateway+:: The gateway to submit the transaction to. Can be a URL string, an AuthorizeNet::AIM::Transaction::Gateway constant, or one of the convenience symbols :sandbox, :test, :card_present_test, :card_present_live, :card_present_sandbox, :card_present_production, :production, or :live (:test is an alias for :sandbox, :card_present_test is an alias for :card_present_sandbox, :card_present_production is an alias for :card_present_live, and :live is an alias for :production).
34
+ # +gateway+:: The gateway to submit the transaction to. Can be a URL string, an AuthorizeNet::AIM::Transaction::Gateway constant, or one of the convenience symbols :sandbox, :test, :card_present_test, :card_present_live, :card_present_sandbox, :card_present_production, :production, or :live (:test is an alias for :sandbox, :card_present_test is an alias for :card_present_sandbox, :card_present_production is an alias for :card_present_live, and :live is an alias for :production).
37
35
  # +test+:: A boolean indicating if the transaction should be run in test mode or not (defaults to false).
38
36
  # +allow_split+:: A boolean indicating if split transactions should be allowed (defaults to false).
39
37
  # +delimiter+:: A single character (as a string) that will be used to delimit the response from the gateway. Defaults to ','.
@@ -43,6 +41,7 @@ module AuthorizeNet::AIM
43
41
  # +market_type+:: A constant from MarketType indicating your industry. Used for card present transactions. Defaults to MarketType::RETAIL.
44
42
  #
45
43
  def initialize(api_login_id, api_transaction_key, options = {})
44
+ ActiveSupport::Deprecation.warn "use AuthorizeNet::API::Transaction"
46
45
  super()
47
46
  options = @@option_defaults.merge(options)
48
47
  @api_login_id = api_login_id
@@ -73,81 +72,65 @@ module AuthorizeNet::AIM
73
72
  @device_type = options[:device_type]
74
73
  @solution_id = options[:solution_id]
75
74
  end
76
-
75
+
77
76
  # Checks if the transaction has been configured for test mode or not. Return TRUE if the
78
77
  # transaction is a test transaction, FALSE otherwise. All transactions run against the sandbox
79
78
  # are considered test transactions.
80
79
  def test?
81
80
  super || @gateway == Gateway::TEST
82
81
  end
83
-
82
+
84
83
  # Returns TRUE if split transactions are allowed, FALSE otherwise.
85
84
  def split_transaction_allowed?
86
85
  !!@allow_split_transaction
87
86
  end
88
-
87
+
89
88
  # Returns the current encapsulation character unless there is none, in which case Nil is returned.
90
- def encapsulation_character
91
- @encapsulation_character
92
- end
93
-
89
+ attr_reader :encapsulation_character
90
+
94
91
  # Returns the gateway to be used for this transaction.
95
- def gateway
96
- @gateway
97
- end
98
-
92
+ attr_reader :gateway
93
+
99
94
  # Checks to see if the transaction has a response (meaning it has been submitted to the gateway).
100
95
  # Returns TRUE if a response is present, FALSE otherwise.
101
96
  def has_response?
102
97
  !@response.nil?
103
98
  end
104
-
99
+
105
100
  # Retrieve the response object (or Nil if transaction hasn't been sent to the gateway).
106
- def response
107
- @response
108
- end
109
-
101
+ attr_reader :response
102
+
110
103
  # Returns the current delimiter we are using to parse the fields returned by the
111
104
  # gateway.
112
- def delimiter
113
- @delimiter
114
- end
115
-
105
+ attr_reader :delimiter
106
+
116
107
  # Sets the delimiter used to parse the response from the gateway.
117
- def delimiter=(delimiter)
118
- @delimiter = delimiter
119
- end
120
-
108
+ attr_writer :delimiter
109
+
121
110
  # Submits the transaction to the gateway for processing. Returns a response object. If the transaction
122
111
  # has already been run, it will return nil.
123
112
  def run
124
113
  make_request
125
114
  end
126
-
115
+
127
116
  # Returns the current card present API version that we are adhering to.
128
- def cp_version
129
- @cp_version
130
- end
117
+ attr_reader :cp_version
118
+
119
+ attr_reader :solution_id
131
120
 
132
- def solution_id
133
- @solution_id
134
- end
135
-
136
121
  #:enddoc:
137
122
  protected
138
-
123
+
139
124
  # An internal method that builds the POST body, submits it to the gateway, and constructs a Response object with the response.
140
125
  def make_request
141
- if has_response?
142
- return nil
143
- end
126
+ return nil if has_response?
144
127
  url = URI.parse(@gateway)
145
- fields = @fields.merge(:type => @type, :delim_char => @delimiter, :delim_data => "TRUE", :login => @api_login_id, :tran_key => @api_transaction_key, :relay_response => "FALSE")
146
-
128
+ fields = @fields.merge(type: @type, delim_char: @delimiter, delim_data: "TRUE", login: @api_login_id, tran_key: @api_transaction_key, relay_response: "FALSE")
129
+
147
130
  if @cp_version.nil?
148
- fields.merge!(:version => @version)
131
+ fields[:version] = @version
149
132
  else
150
- fields.merge!(:cp_version => @cp_version, :market_type => @market_type, :device_type => @device_type, :response_format => "1")
133
+ fields.merge!(cp_version: @cp_version, market_type: @market_type, device_type: @device_type, response_format: "1")
151
134
  end
152
135
  fields[:test_request] = boolean_to_value(@test_mode)
153
136
  fields[:allow_partial_auth] = 'TRUE' if @allow_split_transaction
@@ -161,11 +144,11 @@ module AuthorizeNet::AIM
161
144
  end
162
145
  end
163
146
  data = fields.collect do |key, val|
164
- self.to_param(key, val)
147
+ to_param(key, val)
165
148
  end
166
149
  custom_field_keys = @custom_fields.keys.collect(&:to_s).sort.collect(&:to_sym)
167
150
  for key in custom_field_keys
168
- data += [self.to_param(key, @custom_fields[key.to_sym], '')]
151
+ data += [to_param(key, @custom_fields[key.to_sym], '')]
169
152
  end
170
153
  data.flatten!
171
154
  request = Net::HTTP::Post.new(url.path)
@@ -179,12 +162,10 @@ module AuthorizeNet::AIM
179
162
  connection.verify_mode = OpenSSL::SSL::VERIFY_NONE
180
163
  end
181
164
  begin
182
- @response = AuthorizeNet::AIM::Response.new((connection.start {|http| http.request(request)}), self)
183
- rescue
184
- @response = AuthorizeNet::AIM::Response.new($!, self)
165
+ @response = AuthorizeNet::AIM::Response.new((connection.start { |http| http.request(request) }), self)
166
+ rescue StandardError
167
+ @response = AuthorizeNet::AIM::Response.new($ERROR_INFO, self)
185
168
  end
186
169
  end
187
-
188
170
  end
189
-
190
171
  end