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,22 +1,22 @@
1
- module AuthorizeNet::Reporting
2
- # Models the details of a transaction.
3
- class TransactionDetails
4
- include AuthorizeNet::Model
5
-
6
- attr_accessor :id, :submitted_at, :status, :order, :customer, :account_type,
7
- :account_number, :settle_amount, :reference_id, :split_tender_id,
8
- :type, :response_code, :response_reason_code, :response_reason_description,
9
- :auth_code, :avs_response, :card_code_response, :cavv_response,
10
- :fds_filter_action, :fds_filters, :batch, :prepaid_balance_remaining,
11
- :payment_method, :recurring_billing, :bill_to, :ship_to, :auth_amount,
12
- :subscription_id, :subscription_paynum, :solution_id, :solution_name, :returns
13
-
14
- def submitted_at=(time)
15
- if time.is_a?(DateTime)
16
- @submitted_at = time
17
- else
18
- @submitted_at = DateTime.parse(time.to_s)
19
- end
20
- end
21
- end
22
- end
1
+ module AuthorizeNet::Reporting
2
+ # Models the details of a transaction.
3
+ class TransactionDetails
4
+ include AuthorizeNet::Model
5
+
6
+ attr_accessor :id, :submitted_at, :status, :order, :customer, :account_type,
7
+ :account_number, :settle_amount, :reference_id, :split_tender_id,
8
+ :type, :response_code, :response_reason_code, :response_reason_description,
9
+ :auth_code, :avs_response, :card_code_response, :cavv_response,
10
+ :fds_filter_action, :fds_filters, :batch, :prepaid_balance_remaining,
11
+ :payment_method, :recurring_billing, :bill_to, :ship_to, :auth_amount,
12
+ :subscription_id, :subscription_paynum, :solution_id, :solution_name, :returns
13
+
14
+ def submitted_at=(time)
15
+ if time.is_a?(DateTime)
16
+ @submitted_at = time
17
+ else
18
+ @submitted_at = DateTime.parse(time.to_s)
19
+ end
20
+ end
21
+ end
22
+ end
@@ -1,25 +1,25 @@
1
- module AuthorizeNet
2
- # The core, API agnostic response class. You shouldn't instantiate
3
- # this one. Instead you should use AuthorizeNet::AIM::Response,
4
- # AuthorizeNet::ARB::Response or AuthorizeNet::SIM::Response.
5
- class Response
6
- include AuthorizeNet::TypeConversions
7
-
8
- # Fields to convert to/from booleans.
9
- @@boolean_fields = []
10
-
11
- # Fields to convert to/from BigDecimal.
12
- @@decimal_fields = []
13
-
14
- # DO NOT USE. Instantiate AuthorizeNet::AIM::Response or
15
- # AuthorizeNet::SIM::Response instead.
16
- def initialize
17
- raise "#{self.class} should not be instantiated directly."
18
- end
19
-
20
- # Check to see if the response indicated success.
21
- def success?
22
- false
23
- end
24
- end
25
- end
1
+ module AuthorizeNet
2
+ # The core, API agnostic response class. You shouldn't instantiate
3
+ # this one. Instead you should use AuthorizeNet::AIM::Response,
4
+ # AuthorizeNet::ARB::Response or AuthorizeNet::SIM::Response.
5
+ class Response
6
+ include AuthorizeNet::TypeConversions
7
+
8
+ # Fields to convert to/from booleans.
9
+ @@boolean_fields = []
10
+
11
+ # Fields to convert to/from BigDecimal.
12
+ @@decimal_fields = []
13
+
14
+ # DO NOT USE. Instantiate AuthorizeNet::AIM::Response or
15
+ # AuthorizeNet::SIM::Response instead.
16
+ def initialize
17
+ raise "#{self.class} should not be instantiated directly."
18
+ end
19
+
20
+ # Check to see if the response indicated success.
21
+ def success?
22
+ false
23
+ end
24
+ end
25
+ end
@@ -1,34 +1,34 @@
1
- module AuthorizeNet::SIM
2
- # Models a hosted payment form.
3
- class HostedPaymentForm
4
- include AuthorizeNet::Model
5
-
6
- attr_accessor :header_html, :footer_html, :color_background, :color_link, :color_text, :logo_url, :background_url, :rename
7
-
8
- # Convenience method for adding field rename requests to the transaction. This renames a field shown on
9
- # the hosted payment form.
10
- def add_rename(field, name)
11
- rename = "#{field},#{name}"
12
- if @rename.nil?
13
- @rename = [rename]
14
- else
15
- @rename = @rename.to_a << rename
16
- end
17
- end
18
-
19
- def to_hash
20
- hash = {
21
- header_html_payment_form: @header_html,
22
- footer_html_payment_form: @footer_html,
23
- color_background: @color_background,
24
- color_link: @color_link,
25
- color_text: @color_text,
26
- logo_url: @logo_url,
27
- background_url: @background_url,
28
- rename: @rename
29
- }
30
- hash.delete_if { |_k, v| v.nil? }
31
- hash
32
- end
33
- end
34
- end
1
+ module AuthorizeNet::SIM
2
+ # Models a hosted payment form.
3
+ class HostedPaymentForm
4
+ include AuthorizeNet::Model
5
+
6
+ attr_accessor :header_html, :footer_html, :color_background, :color_link, :color_text, :logo_url, :background_url, :rename
7
+
8
+ # Convenience method for adding field rename requests to the transaction. This renames a field shown on
9
+ # the hosted payment form.
10
+ def add_rename(field, name)
11
+ rename = "#{field},#{name}"
12
+ if @rename.nil?
13
+ @rename = [rename]
14
+ else
15
+ @rename = @rename.to_a << rename
16
+ end
17
+ end
18
+
19
+ def to_hash
20
+ hash = {
21
+ header_html_payment_form: @header_html,
22
+ footer_html_payment_form: @footer_html,
23
+ color_background: @color_background,
24
+ color_link: @color_link,
25
+ color_text: @color_text,
26
+ logo_url: @logo_url,
27
+ background_url: @background_url,
28
+ rename: @rename
29
+ }
30
+ hash.delete_if { |_k, v| v.nil? }
31
+ hash
32
+ end
33
+ end
34
+ end
@@ -1,32 +1,32 @@
1
- module AuthorizeNet::SIM
2
- # Models a hosted receipt page.
3
- class HostedReceiptPage
4
- # Defines constants for each of the link methods used by the hosted receipt page.
5
- module LinkMethod
6
- LINK = 'LINK'.freeze
7
- POST = 'POST'.freeze
8
- GET = 'GET'.freeze
9
- end
10
-
11
- include AuthorizeNet::Model
12
-
13
- attr_accessor :header_html, :footer_html, :color_background, :color_link, :color_text, :logo_url, :background_url, :link_method, :link_text, :link_url
14
-
15
- def to_hash
16
- hash = {
17
- header_html_receipt: @header_html,
18
- footer_html_receipt: @footer_html,
19
- color_background: @color_background,
20
- color_link: @color_link,
21
- color_text: @color_text,
22
- logo_url: @logo_url,
23
- background_url: @background_url,
24
- receipt_link_method: @link_method,
25
- receipt_link_text: @link_text,
26
- receipt_link_url: @link_url
27
- }
28
- hash.delete_if { |_k, v| v.nil? }
29
- hash
30
- end
31
- end
32
- end
1
+ module AuthorizeNet::SIM
2
+ # Models a hosted receipt page.
3
+ class HostedReceiptPage
4
+ # Defines constants for each of the link methods used by the hosted receipt page.
5
+ module LinkMethod
6
+ LINK = 'LINK'.freeze
7
+ POST = 'POST'.freeze
8
+ GET = 'GET'.freeze
9
+ end
10
+
11
+ include AuthorizeNet::Model
12
+
13
+ attr_accessor :header_html, :footer_html, :color_background, :color_link, :color_text, :logo_url, :background_url, :link_method, :link_text, :link_url
14
+
15
+ def to_hash
16
+ hash = {
17
+ header_html_receipt: @header_html,
18
+ footer_html_receipt: @footer_html,
19
+ color_background: @color_background,
20
+ color_link: @color_link,
21
+ color_text: @color_text,
22
+ logo_url: @logo_url,
23
+ background_url: @background_url,
24
+ receipt_link_method: @link_method,
25
+ receipt_link_text: @link_text,
26
+ receipt_link_url: @link_url
27
+ }
28
+ hash.delete_if { |_k, v| v.nil? }
29
+ hash
30
+ end
31
+ end
32
+ end
@@ -1,133 +1,133 @@
1
- module AuthorizeNet::SIM
2
- # The SIM response class. Handles parsing the response from the gateway. Also
3
- # provides a few relay response helpers used to implement Direct Post Method.
4
- class Response < AuthorizeNet::KeyValueResponse
5
- # Our MD5 digest generator.
6
- @@digest = OpenSSL::Digest.new('md5')
7
-
8
- include AuthorizeNet::SIM::Fields
9
-
10
- # Constructs a new response object from a +raw_response+. Provides utility methods
11
- # for validating the response as authentic, and for handling the Direct Post Method
12
- # relay response.
13
- #
14
- # +raw_response+:: The raw response, either a string in POST body or GET query string format, or a hash of key/value pairs.
15
- #
16
- # Typical usage:
17
- # response = AuthorizeNet::SIM::Response("x_first_name=John&x_last_name=Doe")
18
- def initialize(raw_response)
19
- @raw_response = raw_response
20
- @custom_fields = {}
21
- @fields = {}
22
- parse_response(@raw_response)
23
- end
24
-
25
- # Returns True if the MD5 hash found in the response payload validates using
26
- # the supplied api_login and secret merchant_value (THIS IS NOT YOUR API KEY).
27
- def valid_md5?(api_login, merchant_value)
28
- return false if @fields[:MD5_Hash].nil?
29
- @@digest.hexdigest("#{merchant_value}#{api_login}#{@fields[:trans_id]}#{@fields[:amount]}").casecmp(@fields[:MD5_Hash]).zero?
30
- end
31
-
32
- # Returns an HTML string that can be returned to the gateway during the Relay Response,
33
- # and will send the user on to URL you specify. Takes a hash of options, currently the
34
- # only option is :include, which can be True to include all fields returned in the response
35
- # as query string parameters, or it can be an array of fields to include.
36
- def direct_post_reply(url, options = {})
37
- url = direct_post_url(url, options[:include]) if options.key?(:include)
38
- js_url = url.tr("'", '\'')
39
- html_url = url.gsub('&', '&amp;').tr('"', "\"")
40
- html = <<-HTML
41
- <html><head><script type="text/javascript" charset="utf-8">window.location='#{js_url}';</script><noscript><meta http-equiv="refresh" content="1;url=#{html_url}"></noscript></head><body></body></html>
42
- HTML
43
- end
44
-
45
- # Returns an URL with the fields found in the response and specified in include_fields attached as
46
- # part of the URL's query string. If you pass true instead of an array of fields, all fields will be
47
- # attached.
48
- def direct_post_url(base_url, include_fields = true)
49
- url = base_url
50
- if include_fields
51
- fields = []
52
- case include_fields
53
- when TrueClass
54
- fields = FIELDS.collect do |k|
55
- k_str = k.to_s
56
- k_str[2..k_str.length].to_sym
57
- end
58
- when Array
59
- fields = include_fields
60
- else
61
- fields = include_fields.to_a
62
- end
63
- parsed_url = URI.parse(url)
64
- if parsed_url.query.nil?
65
- parsed_url.query = ''
66
- elsif !parsed_url.query.empty?
67
- parsed_url.query = parsed_url.query.chomp('&') + '&'
68
- end
69
- parsed_url.query += ((fields.select { |k| @fields.key?(k) }).collect { |k| to_param(k, @fields[k]) }).join('&')
70
- parsed_url.query.chomp('&')
71
- url = parsed_url.to_s
72
- end
73
- url
74
- end
75
-
76
- # Check to see if the response indicated success. Success is defined as a valid MD5 hash
77
- # and an response code of AuthorizeNet::Response::ResponseCode::APPROVED.
78
- def success?(api_login, merchant_value)
79
- valid_md5?(api_login, merchant_value) && approved?
80
- end
81
-
82
- # Returns the transaction's authorization code. This should be shown to the
83
- # end user.
84
- def authorization_code
85
- @fields[:auth_code]
86
- end
87
-
88
- # Returns the transaction's authorization id. You will need this for future void, refund
89
- # and prior authorization capture requests.
90
- def transaction_id
91
- @fields[:trans_id]
92
- end
93
-
94
- # Returns the customer id from the response.
95
- def customer_id
96
- @fields[:cust_id]
97
- end
98
-
99
- # Returns a response code (from AVSResponseCode) indicating the result of any Address Verification
100
- # Service checks.
101
- def avs_response
102
- @fields[:avs_code]
103
- end
104
-
105
- #:enddoc:
106
- protected
107
-
108
- # Internal helper to parse the raw response object. It handles both raw POST bodies and
109
- # hashes.
110
- def parse_response(raw_response)
111
- case raw_response
112
- when Hash
113
- raw_response.each do |k, v|
114
- k = k.to_sym
115
- if FIELDS.include?(k)
116
- @fields[to_internal_field(k)] = v # remove x_ from sym and stick in @fields
117
- else
118
- @custom_fields[k] = v
119
- end
120
- end
121
- when String
122
- # convert to hash and re-parse
123
- hash = CGI.parse(raw_response)
124
- hash.each do |k, v|
125
- hash[k] = v[0] if v.is_a?(Array) && v.length == 1
126
- end
127
- parse_response(hash)
128
- else
129
- parse_response(@raw_response.to_s)
130
- end
131
- end
132
- end
133
- end
1
+ module AuthorizeNet::SIM
2
+ # The SIM response class. Handles parsing the response from the gateway. Also
3
+ # provides a few relay response helpers used to implement Direct Post Method.
4
+ class Response < AuthorizeNet::KeyValueResponse
5
+ # Our MD5 digest generator.
6
+ @@digest = OpenSSL::Digest.new('md5')
7
+
8
+ include AuthorizeNet::SIM::Fields
9
+
10
+ # Constructs a new response object from a +raw_response+. Provides utility methods
11
+ # for validating the response as authentic, and for handling the Direct Post Method
12
+ # relay response.
13
+ #
14
+ # +raw_response+:: The raw response, either a string in POST body or GET query string format, or a hash of key/value pairs.
15
+ #
16
+ # Typical usage:
17
+ # response = AuthorizeNet::SIM::Response("x_first_name=John&x_last_name=Doe")
18
+ def initialize(raw_response)
19
+ @raw_response = raw_response
20
+ @custom_fields = {}
21
+ @fields = {}
22
+ parse_response(@raw_response)
23
+ end
24
+
25
+ # Returns True if the MD5 hash found in the response payload validates using
26
+ # the supplied api_login and secret merchant_value (THIS IS NOT YOUR API KEY).
27
+ def valid_md5?(api_login, merchant_value)
28
+ return false if @fields[:MD5_Hash].nil?
29
+ @@digest.hexdigest("#{merchant_value}#{api_login}#{@fields[:trans_id]}#{@fields[:amount]}").casecmp(@fields[:MD5_Hash]).zero?
30
+ end
31
+
32
+ # Returns an HTML string that can be returned to the gateway during the Relay Response,
33
+ # and will send the user on to URL you specify. Takes a hash of options, currently the
34
+ # only option is :include, which can be True to include all fields returned in the response
35
+ # as query string parameters, or it can be an array of fields to include.
36
+ def direct_post_reply(url, options = {})
37
+ url = direct_post_url(url, options[:include]) if options.key?(:include)
38
+ js_url = url.tr("'", '\'')
39
+ html_url = url.gsub('&', '&amp;').tr('"', "\"")
40
+ html = <<-HTML
41
+ <html><head><script type="text/javascript" charset="utf-8">window.location='#{js_url}';</script><noscript><meta http-equiv="refresh" content="1;url=#{html_url}"></noscript></head><body></body></html>
42
+ HTML
43
+ end
44
+
45
+ # Returns an URL with the fields found in the response and specified in include_fields attached as
46
+ # part of the URL's query string. If you pass true instead of an array of fields, all fields will be
47
+ # attached.
48
+ def direct_post_url(base_url, include_fields = true)
49
+ url = base_url
50
+ if include_fields
51
+ fields = []
52
+ case include_fields
53
+ when TrueClass
54
+ fields = FIELDS.collect do |k|
55
+ k_str = k.to_s
56
+ k_str[2..k_str.length].to_sym
57
+ end
58
+ when Array
59
+ fields = include_fields
60
+ else
61
+ fields = include_fields.to_a
62
+ end
63
+ parsed_url = URI.parse(url)
64
+ if parsed_url.query.nil?
65
+ parsed_url.query = ''
66
+ elsif !parsed_url.query.empty?
67
+ parsed_url.query = parsed_url.query.chomp('&') + '&'
68
+ end
69
+ parsed_url.query += ((fields.select { |k| @fields.key?(k) }).collect { |k| to_param(k, @fields[k]) }).join('&')
70
+ parsed_url.query.chomp('&')
71
+ url = parsed_url.to_s
72
+ end
73
+ url
74
+ end
75
+
76
+ # Check to see if the response indicated success. Success is defined as a valid MD5 hash
77
+ # and an response code of AuthorizeNet::Response::ResponseCode::APPROVED.
78
+ def success?(api_login, merchant_value)
79
+ valid_md5?(api_login, merchant_value) && approved?
80
+ end
81
+
82
+ # Returns the transaction's authorization code. This should be shown to the
83
+ # end user.
84
+ def authorization_code
85
+ @fields[:auth_code]
86
+ end
87
+
88
+ # Returns the transaction's authorization id. You will need this for future void, refund
89
+ # and prior authorization capture requests.
90
+ def transaction_id
91
+ @fields[:trans_id]
92
+ end
93
+
94
+ # Returns the customer id from the response.
95
+ def customer_id
96
+ @fields[:cust_id]
97
+ end
98
+
99
+ # Returns a response code (from AVSResponseCode) indicating the result of any Address Verification
100
+ # Service checks.
101
+ def avs_response
102
+ @fields[:avs_code]
103
+ end
104
+
105
+ #:enddoc:
106
+ protected
107
+
108
+ # Internal helper to parse the raw response object. It handles both raw POST bodies and
109
+ # hashes.
110
+ def parse_response(raw_response)
111
+ case raw_response
112
+ when Hash
113
+ raw_response.each do |k, v|
114
+ k = k.to_sym
115
+ if FIELDS.include?(k)
116
+ @fields[to_internal_field(k)] = v # remove x_ from sym and stick in @fields
117
+ else
118
+ @custom_fields[k] = v
119
+ end
120
+ end
121
+ when String
122
+ # convert to hash and re-parse
123
+ hash = CGI.parse(raw_response)
124
+ hash.each do |k, v|
125
+ hash[k] = v[0] if v.is_a?(Array) && v.length == 1
126
+ end
127
+ parse_response(hash)
128
+ else
129
+ parse_response(@raw_response.to_s)
130
+ end
131
+ end
132
+ end
133
+ end