authorizenet 1.8.7 → 1.8.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/app/helpers/authorize_net_helper.rb +23 -23
- data/lib/authorize_net.rb +107 -103
- data/lib/authorize_net/addresses/address.rb +28 -28
- data/lib/authorize_net/addresses/shipping_address.rb +25 -25
- data/lib/authorize_net/aim/response.rb +130 -130
- data/lib/authorize_net/aim/transaction.rb +190 -190
- data/lib/authorize_net/api/api_transaction.rb +103 -102
- data/lib/authorize_net/api/schema.rb +4283 -4283
- data/lib/authorize_net/api/transaction.rb +240 -240
- data/lib/authorize_net/arb/fields.rb +24 -24
- data/lib/authorize_net/arb/paging.rb +33 -33
- data/lib/authorize_net/arb/response.rb +33 -33
- data/lib/authorize_net/arb/sorting.rb +43 -43
- data/lib/authorize_net/arb/subscription.rb +71 -71
- data/lib/authorize_net/arb/subscription_detail.rb +14 -14
- data/lib/authorize_net/arb/subscription_list_response.rb +43 -43
- data/lib/authorize_net/arb/transaction.rb +177 -177
- data/lib/authorize_net/authorize_net.rb +153 -153
- data/lib/authorize_net/cim/customer_profile.rb +18 -18
- data/lib/authorize_net/cim/payment_profile.rb +36 -36
- data/lib/authorize_net/cim/response.rb +115 -115
- data/lib/authorize_net/cim/transaction.rb +727 -727
- data/lib/authorize_net/customer.rb +26 -26
- data/lib/authorize_net/email_receipt.rb +23 -23
- data/lib/authorize_net/fields.rb +779 -779
- data/lib/authorize_net/key_value_response.rb +116 -116
- data/lib/authorize_net/key_value_transaction.rb +290 -290
- data/lib/authorize_net/line_item.rb +24 -24
- data/lib/authorize_net/order.rb +41 -41
- data/lib/authorize_net/payment_methods/credit_card.rb +62 -62
- data/lib/authorize_net/payment_methods/echeck.rb +71 -71
- data/lib/authorize_net/reporting/batch.rb +18 -18
- data/lib/authorize_net/reporting/batch_statistics.rb +18 -18
- data/lib/authorize_net/reporting/fds_filter.rb +10 -10
- data/lib/authorize_net/reporting/response.rb +162 -162
- data/lib/authorize_net/reporting/returned_item.rb +46 -46
- data/lib/authorize_net/reporting/transaction.rb +133 -133
- data/lib/authorize_net/reporting/transaction_details.rb +24 -24
- data/lib/authorize_net/response.rb +26 -26
- data/lib/authorize_net/sim/hosted_payment_form.rb +37 -37
- data/lib/authorize_net/sim/hosted_receipt_page.rb +36 -36
- data/lib/authorize_net/sim/response.rb +141 -141
- data/lib/authorize_net/sim/transaction.rb +137 -137
- data/lib/authorize_net/transaction.rb +65 -65
- data/lib/authorize_net/xml_response.rb +171 -171
- data/lib/authorize_net/xml_transaction.rb +280 -280
- data/lib/authorizenet.rb +4 -4
- data/lib/generators/authorize_net/direct_post/direct_post_generator.rb +53 -53
- data/lib/generators/authorize_net/direct_post/templates/README-AuthorizeNet +48 -48
- data/lib/generators/authorize_net/direct_post/templates/config.yml.erb +8 -8
- data/lib/generators/authorize_net/direct_post/templates/config.yml.rails3.erb +8 -8
- data/lib/generators/authorize_net/direct_post/templates/controller.rb.erb +30 -30
- data/lib/generators/authorize_net/direct_post/templates/initializer.rb +4 -4
- data/lib/generators/authorize_net/direct_post/templates/layout.erb +17 -17
- data/lib/generators/authorize_net/direct_post/templates/payment.erb +9 -9
- data/lib/generators/authorize_net/direct_post/templates/payment.rails3.erb +9 -9
- data/lib/generators/authorize_net/sim/sim_generator.rb +47 -47
- data/lib/generators/authorize_net/sim/templates/README-AuthorizeNet +51 -51
- data/lib/generators/authorize_net/sim/templates/config.yml.erb +8 -8
- data/lib/generators/authorize_net/sim/templates/config.yml.rails3.erb +8 -8
- data/lib/generators/authorize_net/sim/templates/controller.rb.erb +20 -20
- data/lib/generators/authorize_net/sim/templates/initializer.rb +4 -4
- data/lib/generators/authorize_net/sim/templates/layout.erb +17 -17
- data/lib/generators/authorize_net/sim/templates/payment.erb +5 -5
- data/lib/generators/authorize_net/sim/templates/payment.rails3.erb +5 -5
- data/lib/generators/generator_extensions.rb +74 -74
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c159d2109c4b1bad12210b48a2e6401fc9033d17
|
4
|
+
data.tar.gz: 2ba908b03b0dec9f9c2c519977feecf4772adc29
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f2d6ca89a7968faaebb7dd1990ccbf2b99ecfe529f5ebb481859e6b2ca89e16e0f91c1873431289706d81fd53b4b93a61860352ae35f3d1b34edd1a431888be0
|
7
|
+
data.tar.gz: 8678ed7b91ab8f1c8578741f5cd529ecd0a7122de2a33c5f85d65f088d9cb551a0f0d61607a256fb03e3952001a3fa9bf5f8628863f3fb3a6d808da7c868458b
|
@@ -1,24 +1,24 @@
|
|
1
|
-
# The Authorize.Net Rails Helper module. Provides methods to assist with integrating the various APIs.
|
2
|
-
|
3
|
-
module AuthorizeNetHelper
|
4
|
-
|
5
|
-
# Generates a collection of hidden form fields (as a raw HTML string) for a AuthorizeNet::SIM::Transaction
|
6
|
-
# (sim_transaction). You can specify any html_options that hidden_field_tag accepts, and the
|
7
|
-
# hidden fields will be built with those options.
|
8
|
-
def sim_fields(sim_transaction, html_options = {})
|
9
|
-
fields = sim_transaction.form_fields.collect do |k, v|
|
10
|
-
if v.kind_of? Array
|
11
|
-
v.collect { |val| hidden_field_tag(k, val, html_options) }
|
12
|
-
else
|
13
|
-
hidden_field_tag(k, v, html_options)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
fields.flatten!
|
17
|
-
field_str = fields.join("\n")
|
18
|
-
if field_str.respond_to?(:html_safe)
|
19
|
-
return field_str.html_safe
|
20
|
-
else
|
21
|
-
return field_str
|
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
|
+
|
5
|
+
# Generates a collection of hidden form fields (as a raw HTML string) for a AuthorizeNet::SIM::Transaction
|
6
|
+
# (sim_transaction). You can specify any html_options that hidden_field_tag accepts, and the
|
7
|
+
# hidden fields will be built with those options.
|
8
|
+
def sim_fields(sim_transaction, html_options = {})
|
9
|
+
fields = sim_transaction.form_fields.collect do |k, v|
|
10
|
+
if v.kind_of? Array
|
11
|
+
v.collect { |val| hidden_field_tag(k, val, html_options) }
|
12
|
+
else
|
13
|
+
hidden_field_tag(k, v, html_options)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
fields.flatten!
|
17
|
+
field_str = fields.join("\n")
|
18
|
+
if field_str.respond_to?(:html_safe)
|
19
|
+
return field_str.html_safe
|
20
|
+
else
|
21
|
+
return field_str
|
22
|
+
end
|
23
|
+
end
|
24
24
|
end
|
data/lib/authorize_net.rb
CHANGED
@@ -1,103 +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
|
-
|
6
|
-
require
|
7
|
-
|
8
|
-
|
9
|
-
require
|
10
|
-
require
|
11
|
-
require
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
require "authorize_net/
|
22
|
-
require "authorize_net/
|
23
|
-
require "authorize_net/
|
24
|
-
require "authorize_net/
|
25
|
-
require "authorize_net/
|
26
|
-
require "authorize_net/
|
27
|
-
require "authorize_net/
|
28
|
-
require "authorize_net/
|
29
|
-
require "authorize_net/
|
30
|
-
require "authorize_net/
|
31
|
-
require "authorize_net/
|
32
|
-
require "authorize_net/reporting/
|
33
|
-
require "authorize_net/
|
34
|
-
require "authorize_net/
|
35
|
-
require "authorize_net/
|
36
|
-
require "authorize_net/
|
37
|
-
require "authorize_net/
|
38
|
-
require "authorize_net/
|
39
|
-
require "authorize_net/
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
require "authorize_net/
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
require "authorize_net/
|
48
|
-
require "authorize_net/
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
require "authorize_net/
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
require "authorize_net/
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
require "authorize_net/arb/
|
65
|
-
require "authorize_net/arb/
|
66
|
-
require "authorize_net/arb/
|
67
|
-
require "authorize_net/arb/
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
require "authorize_net/
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
require "authorize_net/
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
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
|
+
$:.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,29 +1,29 @@
|
|
1
|
-
module AuthorizeNet
|
2
|
-
|
3
|
-
# Models an address.
|
4
|
-
class Address
|
5
|
-
|
6
|
-
include AuthorizeNet::Model
|
7
|
-
|
8
|
-
attr_accessor :first_name, :last_name, :company, :street_address, :city, :state, :zip, :country, :phone, :fax, :customer_address_id
|
9
|
-
|
10
|
-
def to_hash
|
11
|
-
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
|
23
|
-
}
|
24
|
-
hash.delete_if {|k, v| v.nil?}
|
25
|
-
end
|
26
|
-
|
27
|
-
end
|
28
|
-
|
1
|
+
module AuthorizeNet
|
2
|
+
|
3
|
+
# Models an address.
|
4
|
+
class Address
|
5
|
+
|
6
|
+
include AuthorizeNet::Model
|
7
|
+
|
8
|
+
attr_accessor :first_name, :last_name, :company, :street_address, :city, :state, :zip, :country, :phone, :fax, :customer_address_id
|
9
|
+
|
10
|
+
def to_hash
|
11
|
+
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
|
23
|
+
}
|
24
|
+
hash.delete_if {|k, v| v.nil?}
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
29
|
end
|
@@ -1,26 +1,26 @@
|
|
1
|
-
module AuthorizeNet
|
2
|
-
|
3
|
-
# Models a shipping address.
|
4
|
-
class ShippingAddress < Address
|
5
|
-
|
6
|
-
include AuthorizeNet::Model
|
7
|
-
|
8
|
-
def to_hash
|
9
|
-
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
|
20
|
-
}
|
21
|
-
hash.delete_if {|k, v| v.nil?}
|
22
|
-
end
|
23
|
-
|
24
|
-
end
|
25
|
-
|
1
|
+
module AuthorizeNet
|
2
|
+
|
3
|
+
# Models a shipping address.
|
4
|
+
class ShippingAddress < Address
|
5
|
+
|
6
|
+
include AuthorizeNet::Model
|
7
|
+
|
8
|
+
def to_hash
|
9
|
+
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
|
20
|
+
}
|
21
|
+
hash.delete_if {|k, v| v.nil?}
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
26
|
end
|
@@ -1,131 +1,131 @@
|
|
1
|
-
module AuthorizeNet::AIM
|
2
|
-
|
3
|
-
# The AIM response class. Handles parsing the response from the gateway.
|
4
|
-
class Response < AuthorizeNet::KeyValueResponse
|
5
|
-
|
6
|
-
# Our MD5 digest generator.
|
7
|
-
@@digest = OpenSSL::Digest.new('md5')
|
8
|
-
|
9
|
-
include AuthorizeNet::AIM::Fields
|
10
|
-
|
11
|
-
# Fields to convert to/from booleans.
|
12
|
-
@@boolean_fields = [:tax_exempt]
|
13
|
-
|
14
|
-
# Fields to convert to/from BigDecimal.
|
15
|
-
@@decimal_fields = [:amount, :tax, :freight, :duty, :requested, :balance_on_card]
|
16
|
-
|
17
|
-
|
18
|
-
# Constructs a new response object from a +raw_response+ and the +transaction+ that generated
|
19
|
-
# the +raw_response+. You don't typically construct this object yourself, as AuthorizeNet::AIM::Transaction
|
20
|
-
# will build one for you when it makes the request to the gateway.
|
21
|
-
def initialize(raw_response, transaction)
|
22
|
-
@version = transaction.version
|
23
|
-
raise "AuthorizeNet gem only supports AIM version 3.1" unless @version.to_s == '3.1'
|
24
|
-
@raw_response = raw_response
|
25
|
-
@fields = {}
|
26
|
-
@transaction = transaction
|
27
|
-
custom_field_names = transaction.custom_fields.keys.collect(&:to_s).sort.collect(&:to_sym)
|
28
|
-
@custom_fields = {}
|
29
|
-
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
|
33
|
-
else
|
34
|
-
raw_data = @raw_response.text
|
35
|
-
end
|
36
|
-
unless transaction.encapsulation_character.nil?
|
37
|
-
split_on = transaction.encapsulation_character + split_on + transaction.encapsulation_character
|
38
|
-
raw_data = raw_data[1..raw_data.length - 2]
|
39
|
-
end
|
40
|
-
raw_data.split(split_on).each_with_index do |field, index|
|
41
|
-
if transaction.cp_version.nil?
|
42
|
-
field_desc = FIELDS
|
43
|
-
else
|
44
|
-
field_desc = CP_FIELDS
|
45
|
-
end
|
46
|
-
if index < field_desc.length
|
47
|
-
@fields[field_desc[index]] = field
|
48
|
-
else
|
49
|
-
@custom_fields[custom_field_names[index - field_desc.length]] = field
|
50
|
-
end
|
51
|
-
end
|
52
|
-
@fields.delete(nil)
|
53
|
-
@fields.each do |k, v|
|
54
|
-
if @@boolean_fields.include?(k)
|
55
|
-
@fields[k] = value_to_boolean(v)
|
56
|
-
elsif @@decimal_fields.include?(k)
|
57
|
-
@fields[k] = value_to_decimal(v)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
# Returns True if the MD5 hash found in the response payload validates using
|
64
|
-
# the supplied api_login and secret merchant_value (THIS IS NOT YOUR API KEY).
|
65
|
-
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
|
70
|
-
end
|
71
|
-
|
72
|
-
# Returns the current API version that we are adhering to.
|
73
|
-
def version
|
74
|
-
@version
|
75
|
-
end
|
76
|
-
|
77
|
-
# Check to see if the response indicated success. Success is defined as a 200 OK response indicating
|
78
|
-
# that the transaction was approved.
|
79
|
-
def success?
|
80
|
-
!connection_failure? && approved?
|
81
|
-
end
|
82
|
-
|
83
|
-
# Returns true if we failed to open a connection to the gateway or got back a non-200 OK HTTP response.
|
84
|
-
def connection_failure?
|
85
|
-
!@raw_response.kind_of?(Net::HTTPOK) && !@raw_response.kind_of?(Nokogiri::XML::Element)
|
86
|
-
end
|
87
|
-
|
88
|
-
# Returns the underlying Net::HTTPResponse object. This has the original response body along with
|
89
|
-
# headers and such. Note that if an exception is generated while making the request (which happens
|
90
|
-
# if there is no internet connection for example), you will get the exception object here instead of
|
91
|
-
# a Net::HTTPResponse object.
|
92
|
-
def raw
|
93
|
-
@raw_response
|
94
|
-
end
|
95
|
-
|
96
|
-
# Returns the AuthorizeNet::Transaction instance that owns this response.
|
97
|
-
def transaction
|
98
|
-
@transaction
|
99
|
-
end
|
100
|
-
|
101
|
-
# Returns the transaction's authorization code. This should be shown to the
|
102
|
-
# end user.
|
103
|
-
def authorization_code
|
104
|
-
@fields[:authorization_code]
|
105
|
-
end
|
106
|
-
|
107
|
-
# Returns the transaction's authorization id. You will need this for future void, refund
|
108
|
-
# and prior authorization capture requests.
|
109
|
-
def transaction_id
|
110
|
-
@fields[:transaction_id]
|
111
|
-
end
|
112
|
-
|
113
|
-
# Returns the customer id from the response.
|
114
|
-
def customer_id
|
115
|
-
@fields[:customer_id]
|
116
|
-
end
|
117
|
-
|
118
|
-
# Returns a response code (from AVSResponseCode) indicating the result of any Address Verification
|
119
|
-
# Service checks.
|
120
|
-
def avs_response
|
121
|
-
@fields[:avs_response]
|
122
|
-
end
|
123
|
-
|
124
|
-
# Returns the credit card type used in the transaction. The values returned can be found in CardType.
|
125
|
-
def card_type
|
126
|
-
@fields[:card_type]
|
127
|
-
end
|
128
|
-
|
129
|
-
end
|
130
|
-
|
1
|
+
module AuthorizeNet::AIM
|
2
|
+
|
3
|
+
# The AIM response class. Handles parsing the response from the gateway.
|
4
|
+
class Response < AuthorizeNet::KeyValueResponse
|
5
|
+
|
6
|
+
# Our MD5 digest generator.
|
7
|
+
@@digest = OpenSSL::Digest.new('md5')
|
8
|
+
|
9
|
+
include AuthorizeNet::AIM::Fields
|
10
|
+
|
11
|
+
# Fields to convert to/from booleans.
|
12
|
+
@@boolean_fields = [:tax_exempt]
|
13
|
+
|
14
|
+
# Fields to convert to/from BigDecimal.
|
15
|
+
@@decimal_fields = [:amount, :tax, :freight, :duty, :requested, :balance_on_card]
|
16
|
+
|
17
|
+
|
18
|
+
# Constructs a new response object from a +raw_response+ and the +transaction+ that generated
|
19
|
+
# the +raw_response+. You don't typically construct this object yourself, as AuthorizeNet::AIM::Transaction
|
20
|
+
# will build one for you when it makes the request to the gateway.
|
21
|
+
def initialize(raw_response, transaction)
|
22
|
+
@version = transaction.version
|
23
|
+
raise "AuthorizeNet gem only supports AIM version 3.1" unless @version.to_s == '3.1'
|
24
|
+
@raw_response = raw_response
|
25
|
+
@fields = {}
|
26
|
+
@transaction = transaction
|
27
|
+
custom_field_names = transaction.custom_fields.keys.collect(&:to_s).sort.collect(&:to_sym)
|
28
|
+
@custom_fields = {}
|
29
|
+
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
|
33
|
+
else
|
34
|
+
raw_data = @raw_response.text
|
35
|
+
end
|
36
|
+
unless transaction.encapsulation_character.nil?
|
37
|
+
split_on = transaction.encapsulation_character + split_on + transaction.encapsulation_character
|
38
|
+
raw_data = raw_data[1..raw_data.length - 2]
|
39
|
+
end
|
40
|
+
raw_data.split(split_on).each_with_index do |field, index|
|
41
|
+
if transaction.cp_version.nil?
|
42
|
+
field_desc = FIELDS
|
43
|
+
else
|
44
|
+
field_desc = CP_FIELDS
|
45
|
+
end
|
46
|
+
if index < field_desc.length
|
47
|
+
@fields[field_desc[index]] = field
|
48
|
+
else
|
49
|
+
@custom_fields[custom_field_names[index - field_desc.length]] = field
|
50
|
+
end
|
51
|
+
end
|
52
|
+
@fields.delete(nil)
|
53
|
+
@fields.each do |k, v|
|
54
|
+
if @@boolean_fields.include?(k)
|
55
|
+
@fields[k] = value_to_boolean(v)
|
56
|
+
elsif @@decimal_fields.include?(k)
|
57
|
+
@fields[k] = value_to_decimal(v)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
# Returns True if the MD5 hash found in the response payload validates using
|
64
|
+
# the supplied api_login and secret merchant_value (THIS IS NOT YOUR API KEY).
|
65
|
+
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
|
70
|
+
end
|
71
|
+
|
72
|
+
# Returns the current API version that we are adhering to.
|
73
|
+
def version
|
74
|
+
@version
|
75
|
+
end
|
76
|
+
|
77
|
+
# Check to see if the response indicated success. Success is defined as a 200 OK response indicating
|
78
|
+
# that the transaction was approved.
|
79
|
+
def success?
|
80
|
+
!connection_failure? && approved?
|
81
|
+
end
|
82
|
+
|
83
|
+
# Returns true if we failed to open a connection to the gateway or got back a non-200 OK HTTP response.
|
84
|
+
def connection_failure?
|
85
|
+
!@raw_response.kind_of?(Net::HTTPOK) && !@raw_response.kind_of?(Nokogiri::XML::Element)
|
86
|
+
end
|
87
|
+
|
88
|
+
# Returns the underlying Net::HTTPResponse object. This has the original response body along with
|
89
|
+
# headers and such. Note that if an exception is generated while making the request (which happens
|
90
|
+
# if there is no internet connection for example), you will get the exception object here instead of
|
91
|
+
# a Net::HTTPResponse object.
|
92
|
+
def raw
|
93
|
+
@raw_response
|
94
|
+
end
|
95
|
+
|
96
|
+
# Returns the AuthorizeNet::Transaction instance that owns this response.
|
97
|
+
def transaction
|
98
|
+
@transaction
|
99
|
+
end
|
100
|
+
|
101
|
+
# Returns the transaction's authorization code. This should be shown to the
|
102
|
+
# end user.
|
103
|
+
def authorization_code
|
104
|
+
@fields[:authorization_code]
|
105
|
+
end
|
106
|
+
|
107
|
+
# Returns the transaction's authorization id. You will need this for future void, refund
|
108
|
+
# and prior authorization capture requests.
|
109
|
+
def transaction_id
|
110
|
+
@fields[:transaction_id]
|
111
|
+
end
|
112
|
+
|
113
|
+
# Returns the customer id from the response.
|
114
|
+
def customer_id
|
115
|
+
@fields[:customer_id]
|
116
|
+
end
|
117
|
+
|
118
|
+
# Returns a response code (from AVSResponseCode) indicating the result of any Address Verification
|
119
|
+
# Service checks.
|
120
|
+
def avs_response
|
121
|
+
@fields[:avs_response]
|
122
|
+
end
|
123
|
+
|
124
|
+
# Returns the credit card type used in the transaction. The values returned can be found in CardType.
|
125
|
+
def card_type
|
126
|
+
@fields[:card_type]
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
130
|
+
|
131
131
|
end
|