authorizenet 1.8.7 → 1.8.8

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