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
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: '0447819f05222ba77684fdcb29d927c51577121d'
4
+ data.tar.gz: 7e907b6be636c114956c2c7578ca478f63bebba0
5
+ SHA512:
6
+ metadata.gz: d3b8e8b4520bd6b84cf3cc0c78f6a16474f05b9da18223cf91d302a4d578928b288b7ed2a41073f7bf5f55d6500ecfbb0ac47089e4b9adb11b382628b8a9f6df
7
+ data.tar.gz: e252f9b251c7a000a1ecc1c0645b91915b9f769131a69f816eb421ac560a2851b1bab501bb89a544ff8da1e9f8b2388800a582ec1a256465259ed36eafe2812c
@@ -1,23 +1,23 @@
1
- # The Authorize.Net Rails Helper module. Provides methods to assist with integrating the various APIs.
2
-
3
- module AuthorizeNetHelper
4
- # Generates a collection of hidden form fields (as a raw HTML string) for a AuthorizeNet::SIM::Transaction
5
- # (sim_transaction). You can specify any html_options that hidden_field_tag accepts, and the
6
- # hidden fields will be built with those options.
7
- def sim_fields(sim_transaction, html_options = {})
8
- fields = sim_transaction.form_fields.collect do |k, v|
9
- if v.is_a? Array
10
- v.collect { |val| hidden_field_tag(k, val, html_options) }
11
- else
12
- hidden_field_tag(k, v, html_options)
13
- end
14
- end
15
- fields.flatten!
16
- field_str = fields.join("\n")
17
- if field_str.respond_to?(:html_safe)
18
- return field_str.html_safe
19
- else
20
- return field_str
21
- end
22
- end
23
- end
1
+ # The Authorize.Net Rails Helper module. Provides methods to assist with integrating the various APIs.
2
+
3
+ module AuthorizeNetHelper
4
+ # Generates a collection of hidden form fields (as a raw HTML string) for a AuthorizeNet::SIM::Transaction
5
+ # (sim_transaction). You can specify any html_options that hidden_field_tag accepts, and the
6
+ # hidden fields will be built with those options.
7
+ def sim_fields(sim_transaction, html_options = {})
8
+ fields = sim_transaction.form_fields.collect do |k, v|
9
+ if v.is_a? Array
10
+ v.collect { |val| hidden_field_tag(k, val, html_options) }
11
+ else
12
+ hidden_field_tag(k, v, html_options)
13
+ end
14
+ end
15
+ fields.flatten!
16
+ field_str = fields.join("\n")
17
+ if field_str.respond_to?(:html_safe)
18
+ return field_str.html_safe
19
+ else
20
+ return field_str
21
+ end
22
+ end
23
+ end
@@ -1,107 +1,107 @@
1
- # The SDK initialization enters here. Loads all needed libraries and files. Inspects
2
- # the current runtime to see if Rails is present. If it is, we inject our helper into
3
- # ActiveSupport.
4
-
5
- # coverall
6
- # require 'coveralls'
7
- # Coveralls.wear!
8
-
9
- require "cgi"
10
- require "net/https"
11
- require "uri"
12
- require "openssl"
13
- require 'bigdecimal'
14
- require 'nokogiri'
15
- require 'date'
16
-
17
- # TODO: Add local data validation where possible
18
-
19
- $LOAD_PATH.unshift File.dirname(__FILE__)
20
-
21
- require "authorize_net/authorize_net"
22
- require "authorize_net/payment_methods/credit_card"
23
- require "authorize_net/payment_methods/echeck"
24
- require "authorize_net/addresses/address"
25
- require "authorize_net/addresses/shipping_address"
26
- require "authorize_net/customer"
27
- require "authorize_net/email_receipt"
28
- require "authorize_net/order"
29
- require "authorize_net/line_item"
30
- require "authorize_net/cim/payment_profile"
31
- require "authorize_net/cim/customer_profile"
32
- require "authorize_net/reporting/batch"
33
- require "authorize_net/reporting/batch_statistics"
34
- require "authorize_net/reporting/transaction_details"
35
- require "authorize_net/reporting/fds_filter"
36
- require "authorize_net/reporting/returned_item"
37
- require "authorize_net/response"
38
- require "authorize_net/key_value_response"
39
- require "authorize_net/xml_response"
40
- require "authorize_net/transaction"
41
- require "authorize_net/key_value_transaction"
42
- require "authorize_net/xml_transaction"
43
- require "authorize_net/fields"
44
-
45
- # AIM
46
-
47
- require "authorize_net/aim/transaction"
48
- require "authorize_net/aim/response"
49
-
50
- # API
51
- require "authorize_net/api/schema"
52
- require "authorize_net/api/api_transaction"
53
- require "authorize_net/api/transaction"
54
-
55
- # SIM
56
-
57
- require "authorize_net/sim/hosted_payment_form"
58
- require "authorize_net/sim/hosted_receipt_page"
59
- require "authorize_net/sim/transaction"
60
- require "authorize_net/sim/response"
61
-
62
- # ARB
63
-
64
- require "authorize_net/arb/paging"
65
- require "authorize_net/arb/sorting"
66
- require "authorize_net/arb/subscription_list_response"
67
- require "authorize_net/arb/subscription_detail"
68
- require "authorize_net/arb/fields"
69
- require "authorize_net/arb/subscription"
70
- require "authorize_net/arb/response"
71
- require "authorize_net/arb/transaction"
72
-
73
- # CIM
74
-
75
- require "authorize_net/cim/response"
76
- require "authorize_net/cim/transaction"
77
-
78
- # Reporting
79
-
80
- require "authorize_net/reporting/response"
81
- require "authorize_net/reporting/transaction"
82
-
83
- # Load our Rails plugin
84
-
85
- if defined?(Rails)
86
- if defined?(Rails::Railtie)
87
- module AuthorizeNet
88
- class Railtie < Rails::Railtie
89
- initializer "authorize_net.load_path_initialize" do |_app|
90
- %w[models controllers helpers].each do |dir|
91
- path = File.join(File.dirname(__FILE__), 'app', dir)
92
- $LOAD_PATH << path
93
- ActiveSupport::Dependencies.autoload_paths << path
94
- ActiveSupport::Dependencies.autoload_once_paths.delete(path)
95
- end
96
- end
97
- end
98
- end
99
- else
100
- %w[models controllers helpers].each do |dir|
101
- path = File.join(File.dirname(__FILE__), 'app', dir)
102
- $LOAD_PATH << path
103
- ActiveSupport::Dependencies.load_paths << path
104
- ActiveSupport::Dependencies.load_once_paths.delete(path)
105
- end
106
- end
107
- end
1
+ # The SDK initialization enters here. Loads all needed libraries and files. Inspects
2
+ # the current runtime to see if Rails is present. If it is, we inject our helper into
3
+ # ActiveSupport.
4
+
5
+ # coverall
6
+ # require 'coveralls'
7
+ # Coveralls.wear!
8
+
9
+ require "cgi"
10
+ require "net/https"
11
+ require "uri"
12
+ require "openssl"
13
+ require 'bigdecimal'
14
+ require 'nokogiri'
15
+ require 'date'
16
+
17
+ # TODO: Add local data validation where possible
18
+
19
+ $LOAD_PATH.unshift File.dirname(__FILE__)
20
+
21
+ require "authorize_net/authorize_net"
22
+ require "authorize_net/payment_methods/credit_card"
23
+ require "authorize_net/payment_methods/echeck"
24
+ require "authorize_net/addresses/address"
25
+ require "authorize_net/addresses/shipping_address"
26
+ require "authorize_net/customer"
27
+ require "authorize_net/email_receipt"
28
+ require "authorize_net/order"
29
+ require "authorize_net/line_item"
30
+ require "authorize_net/cim/payment_profile"
31
+ require "authorize_net/cim/customer_profile"
32
+ require "authorize_net/reporting/batch"
33
+ require "authorize_net/reporting/batch_statistics"
34
+ require "authorize_net/reporting/transaction_details"
35
+ require "authorize_net/reporting/fds_filter"
36
+ require "authorize_net/reporting/returned_item"
37
+ require "authorize_net/response"
38
+ require "authorize_net/key_value_response"
39
+ require "authorize_net/xml_response"
40
+ require "authorize_net/transaction"
41
+ require "authorize_net/key_value_transaction"
42
+ require "authorize_net/xml_transaction"
43
+ require "authorize_net/fields"
44
+
45
+ # AIM
46
+
47
+ require "authorize_net/aim/transaction"
48
+ require "authorize_net/aim/response"
49
+
50
+ # API
51
+ require "authorize_net/api/schema"
52
+ require "authorize_net/api/api_transaction"
53
+ require "authorize_net/api/transaction"
54
+
55
+ # SIM
56
+
57
+ require "authorize_net/sim/hosted_payment_form"
58
+ require "authorize_net/sim/hosted_receipt_page"
59
+ require "authorize_net/sim/transaction"
60
+ require "authorize_net/sim/response"
61
+
62
+ # ARB
63
+
64
+ require "authorize_net/arb/paging"
65
+ require "authorize_net/arb/sorting"
66
+ require "authorize_net/arb/subscription_list_response"
67
+ require "authorize_net/arb/subscription_detail"
68
+ require "authorize_net/arb/fields"
69
+ require "authorize_net/arb/subscription"
70
+ require "authorize_net/arb/response"
71
+ require "authorize_net/arb/transaction"
72
+
73
+ # CIM
74
+
75
+ require "authorize_net/cim/response"
76
+ require "authorize_net/cim/transaction"
77
+
78
+ # Reporting
79
+
80
+ require "authorize_net/reporting/response"
81
+ require "authorize_net/reporting/transaction"
82
+
83
+ # Load our Rails plugin
84
+
85
+ if defined?(Rails)
86
+ if defined?(Rails::Railtie)
87
+ module AuthorizeNet
88
+ class Railtie < Rails::Railtie
89
+ initializer "authorize_net.load_path_initialize" do |_app|
90
+ %w[models controllers helpers].each do |dir|
91
+ path = File.join(File.dirname(__FILE__), 'app', dir)
92
+ $LOAD_PATH << path
93
+ ActiveSupport::Dependencies.autoload_paths << path
94
+ ActiveSupport::Dependencies.autoload_once_paths.delete(path)
95
+ end
96
+ end
97
+ end
98
+ end
99
+ else
100
+ %w[models controllers helpers].each do |dir|
101
+ path = File.join(File.dirname(__FILE__), 'app', dir)
102
+ $LOAD_PATH << path
103
+ ActiveSupport::Dependencies.load_paths << path
104
+ ActiveSupport::Dependencies.load_once_paths.delete(path)
105
+ end
106
+ end
107
+ end
@@ -1,25 +1,25 @@
1
- module AuthorizeNet
2
- # Models an address.
3
- class Address
4
- include AuthorizeNet::Model
5
-
6
- attr_accessor :first_name, :last_name, :company, :street_address, :city, :state, :zip, :country, :phone, :fax, :customer_address_id
7
-
8
- def to_hash
9
- hash = {
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
21
- }
22
- hash.delete_if { |_k, v| v.nil? }
23
- end
24
- end
25
- end
1
+ module AuthorizeNet
2
+ # Models an address.
3
+ class Address
4
+ include AuthorizeNet::Model
5
+
6
+ attr_accessor :first_name, :last_name, :company, :street_address, :city, :state, :zip, :country, :phone, :fax, :customer_address_id
7
+
8
+ def to_hash
9
+ hash = {
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
21
+ }
22
+ hash.delete_if { |_k, v| v.nil? }
23
+ end
24
+ end
25
+ end
@@ -1,22 +1,22 @@
1
- module AuthorizeNet
2
- # Models a shipping address.
3
- class ShippingAddress < Address
4
- include AuthorizeNet::Model
5
-
6
- def to_hash
7
- hash = {
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
18
- }
19
- hash.delete_if { |_k, v| v.nil? }
20
- end
21
- end
22
- end
1
+ module AuthorizeNet
2
+ # Models a shipping address.
3
+ class ShippingAddress < Address
4
+ include AuthorizeNet::Model
5
+
6
+ def to_hash
7
+ hash = {
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
18
+ }
19
+ hash.delete_if { |_k, v| v.nil? }
20
+ end
21
+ end
22
+ end
@@ -1,120 +1,120 @@
1
- module AuthorizeNet::AIM
2
- # The AIM response class. Handles parsing the response from the gateway.
3
- class Response < AuthorizeNet::KeyValueResponse
4
- # Our MD5 digest generator.
5
- @@digest = OpenSSL::Digest.new('md5')
6
-
7
- include AuthorizeNet::AIM::Fields
8
-
9
- # Fields to convert to/from booleans.
10
- @@boolean_fields = [:tax_exempt]
11
-
12
- # Fields to convert to/from BigDecimal.
13
- @@decimal_fields = %i[amount tax freight duty requested balance_on_card]
14
-
15
- # Constructs a new response object from a +raw_response+ and the +transaction+ that generated
16
- # the +raw_response+. You don't typically construct this object yourself, as AuthorizeNet::AIM::Transaction
17
- # will build one for you when it makes the request to the gateway.
18
- def initialize(raw_response, transaction)
19
- @version = transaction.version
20
- raise "AuthorizeNet gem only supports AIM version 3.1" unless @version.to_s == '3.1'
21
- @raw_response = raw_response
22
- @fields = {}
23
- @transaction = transaction
24
- custom_field_names = transaction.custom_fields.keys.collect(&:to_s).sort.collect(&:to_sym)
25
- @custom_fields = {}
26
- split_on = transaction.delimiter
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
30
- else
31
- raw_data = @raw_response.text
32
- end
33
- unless transaction.encapsulation_character.nil?
34
- split_on = transaction.encapsulation_character + split_on + transaction.encapsulation_character
35
- raw_data = raw_data[1..raw_data.length - 2]
36
- end
37
- raw_data.split(split_on).each_with_index do |field, index|
38
- if transaction.cp_version.nil?
39
- field_desc = FIELDS
40
- else
41
- field_desc = CP_FIELDS
42
- end
43
- if index < field_desc.length
44
- @fields[field_desc[index]] = field
45
- else
46
- @custom_fields[custom_field_names[index - field_desc.length]] = field
47
- end
48
- end
49
- @fields.delete(nil)
50
- @fields.each do |k, v|
51
- if @@boolean_fields.include?(k)
52
- @fields[k] = value_to_boolean(v)
53
- elsif @@decimal_fields.include?(k)
54
- @fields[k] = value_to_decimal(v)
55
- end
56
- end
57
- end
58
- end
59
-
60
- # Returns True if the MD5 hash found in the response payload validates using
61
- # the supplied api_login and secret merchant_value (THIS IS NOT YOUR API KEY).
62
- def valid_md5?(api_login, merchant_value)
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?
65
- end
66
-
67
- # Returns the current API version that we are adhering to.
68
- attr_reader :version
69
-
70
- # Check to see if the response indicated success. Success is defined as a 200 OK response indicating
71
- # that the transaction was approved.
72
- def success?
73
- !connection_failure? && approved?
74
- end
75
-
76
- # Returns true if we failed to open a connection to the gateway or got back a non-200 OK HTTP response.
77
- def connection_failure?
78
- !@raw_response.is_a?(Net::HTTPOK) && !@raw_response.is_a?(Nokogiri::XML::Element)
79
- end
80
-
81
- # Returns the underlying Net::HTTPResponse object. This has the original response body along with
82
- # headers and such. Note that if an exception is generated while making the request (which happens
83
- # if there is no internet connection for example), you will get the exception object here instead of
84
- # a Net::HTTPResponse object.
85
- def raw
86
- @raw_response
87
- end
88
-
89
- # Returns the AuthorizeNet::Transaction instance that owns this response.
90
- attr_reader :transaction
91
-
92
- # Returns the transaction's authorization code. This should be shown to the
93
- # end user.
94
- def authorization_code
95
- @fields[:authorization_code]
96
- end
97
-
98
- # Returns the transaction's authorization id. You will need this for future void, refund
99
- # and prior authorization capture requests.
100
- def transaction_id
101
- @fields[:transaction_id]
102
- end
103
-
104
- # Returns the customer id from the response.
105
- def customer_id
106
- @fields[:customer_id]
107
- end
108
-
109
- # Returns a response code (from AVSResponseCode) indicating the result of any Address Verification
110
- # Service checks.
111
- def avs_response
112
- @fields[:avs_response]
113
- end
114
-
115
- # Returns the credit card type used in the transaction. The values returned can be found in CardType.
116
- def card_type
117
- @fields[:card_type]
118
- end
119
- end
120
- end
1
+ module AuthorizeNet::AIM
2
+ # The AIM response class. Handles parsing the response from the gateway.
3
+ class Response < AuthorizeNet::KeyValueResponse
4
+ # Our MD5 digest generator.
5
+ @@digest = OpenSSL::Digest.new('md5')
6
+
7
+ include AuthorizeNet::AIM::Fields
8
+
9
+ # Fields to convert to/from booleans.
10
+ @@boolean_fields = [:tax_exempt]
11
+
12
+ # Fields to convert to/from BigDecimal.
13
+ @@decimal_fields = %i[amount tax freight duty requested balance_on_card]
14
+
15
+ # Constructs a new response object from a +raw_response+ and the +transaction+ that generated
16
+ # the +raw_response+. You don't typically construct this object yourself, as AuthorizeNet::AIM::Transaction
17
+ # will build one for you when it makes the request to the gateway.
18
+ def initialize(raw_response, transaction)
19
+ @version = transaction.version
20
+ raise "AuthorizeNet gem only supports AIM version 3.1" unless @version.to_s == '3.1'
21
+ @raw_response = raw_response
22
+ @fields = {}
23
+ @transaction = transaction
24
+ custom_field_names = transaction.custom_fields.keys.collect(&:to_s).sort.collect(&:to_sym)
25
+ @custom_fields = {}
26
+ split_on = transaction.delimiter
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
30
+ else
31
+ raw_data = @raw_response.text
32
+ end
33
+ unless transaction.encapsulation_character.nil?
34
+ split_on = transaction.encapsulation_character + split_on + transaction.encapsulation_character
35
+ raw_data = raw_data[1..raw_data.length - 2]
36
+ end
37
+ raw_data.split(split_on).each_with_index do |field, index|
38
+ if transaction.cp_version.nil?
39
+ field_desc = FIELDS
40
+ else
41
+ field_desc = CP_FIELDS
42
+ end
43
+ if index < field_desc.length
44
+ @fields[field_desc[index]] = field
45
+ else
46
+ @custom_fields[custom_field_names[index - field_desc.length]] = field
47
+ end
48
+ end
49
+ @fields.delete(nil)
50
+ @fields.each do |k, v|
51
+ if @@boolean_fields.include?(k)
52
+ @fields[k] = value_to_boolean(v)
53
+ elsif @@decimal_fields.include?(k)
54
+ @fields[k] = value_to_decimal(v)
55
+ end
56
+ end
57
+ end
58
+ end
59
+
60
+ # Returns True if the MD5 hash found in the response payload validates using
61
+ # the supplied api_login and secret merchant_value (THIS IS NOT YOUR API KEY).
62
+ def valid_md5?(api_login, merchant_value)
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?
65
+ end
66
+
67
+ # Returns the current API version that we are adhering to.
68
+ attr_reader :version
69
+
70
+ # Check to see if the response indicated success. Success is defined as a 200 OK response indicating
71
+ # that the transaction was approved.
72
+ def success?
73
+ !connection_failure? && approved?
74
+ end
75
+
76
+ # Returns true if we failed to open a connection to the gateway or got back a non-200 OK HTTP response.
77
+ def connection_failure?
78
+ !@raw_response.is_a?(Net::HTTPOK) && !@raw_response.is_a?(Nokogiri::XML::Element)
79
+ end
80
+
81
+ # Returns the underlying Net::HTTPResponse object. This has the original response body along with
82
+ # headers and such. Note that if an exception is generated while making the request (which happens
83
+ # if there is no internet connection for example), you will get the exception object here instead of
84
+ # a Net::HTTPResponse object.
85
+ def raw
86
+ @raw_response
87
+ end
88
+
89
+ # Returns the AuthorizeNet::Transaction instance that owns this response.
90
+ attr_reader :transaction
91
+
92
+ # Returns the transaction's authorization code. This should be shown to the
93
+ # end user.
94
+ def authorization_code
95
+ @fields[:authorization_code]
96
+ end
97
+
98
+ # Returns the transaction's authorization id. You will need this for future void, refund
99
+ # and prior authorization capture requests.
100
+ def transaction_id
101
+ @fields[:transaction_id]
102
+ end
103
+
104
+ # Returns the customer id from the response.
105
+ def customer_id
106
+ @fields[:customer_id]
107
+ end
108
+
109
+ # Returns a response code (from AVSResponseCode) indicating the result of any Address Verification
110
+ # Service checks.
111
+ def avs_response
112
+ @fields[:avs_response]
113
+ end
114
+
115
+ # Returns the credit card type used in the transaction. The values returned can be found in CardType.
116
+ def card_type
117
+ @fields[:card_type]
118
+ end
119
+ end
120
+ end