authorizenet 1.9.4 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/lib/app/helpers/authorize_net_helper.rb +2 -3
- data/lib/authorize_net.rb +11 -56
- data/lib/authorize_net/api/LogHelper.rb +97 -0
- data/lib/authorize_net/api/SensitiveDataFilter.rb +92 -0
- data/lib/authorize_net/api/api_transaction.rb +95 -90
- data/lib/authorize_net/api/constants.yml +1 -1
- data/lib/authorize_net/api/schema.rb +1353 -994
- data/lib/authorize_net/api/transaction.rb +104 -102
- data/lib/authorize_net/authorize_net.rb +20 -27
- data/lib/authorize_net/response.rb +9 -15
- data/lib/authorize_net/transaction.rb +18 -26
- data/lib/authorize_net/xml_response.rb +36 -54
- data/lib/authorize_net/xml_transaction.rb +115 -134
- metadata +59 -73
- data/lib/authorize_net/addresses/address.rb +0 -29
- data/lib/authorize_net/addresses/shipping_address.rb +0 -26
- data/lib/authorize_net/aim/response.rb +0 -131
- data/lib/authorize_net/aim/transaction.rb +0 -190
- data/lib/authorize_net/arb/fields.rb +0 -24
- data/lib/authorize_net/arb/paging.rb +0 -33
- data/lib/authorize_net/arb/response.rb +0 -34
- data/lib/authorize_net/arb/sorting.rb +0 -43
- data/lib/authorize_net/arb/subscription.rb +0 -72
- data/lib/authorize_net/arb/subscription_detail.rb +0 -14
- data/lib/authorize_net/arb/subscription_list_response.rb +0 -43
- data/lib/authorize_net/arb/transaction.rb +0 -177
- data/lib/authorize_net/cim/customer_profile.rb +0 -19
- data/lib/authorize_net/cim/payment_profile.rb +0 -37
- data/lib/authorize_net/cim/response.rb +0 -116
- data/lib/authorize_net/cim/transaction.rb +0 -727
- data/lib/authorize_net/customer.rb +0 -27
- data/lib/authorize_net/email_receipt.rb +0 -24
- data/lib/authorize_net/fields.rb +0 -779
- data/lib/authorize_net/key_value_response.rb +0 -117
- data/lib/authorize_net/key_value_transaction.rb +0 -291
- data/lib/authorize_net/line_item.rb +0 -25
- data/lib/authorize_net/order.rb +0 -42
- data/lib/authorize_net/payment_methods/credit_card.rb +0 -62
- data/lib/authorize_net/payment_methods/echeck.rb +0 -72
- data/lib/authorize_net/reporting/batch.rb +0 -19
- data/lib/authorize_net/reporting/batch_statistics.rb +0 -19
- data/lib/authorize_net/reporting/fds_filter.rb +0 -11
- data/lib/authorize_net/reporting/response.rb +0 -163
- data/lib/authorize_net/reporting/returned_item.rb +0 -46
- data/lib/authorize_net/reporting/transaction.rb +0 -133
- data/lib/authorize_net/reporting/transaction_details.rb +0 -25
- data/lib/authorize_net/sim/hosted_payment_form.rb +0 -38
- data/lib/authorize_net/sim/hosted_receipt_page.rb +0 -37
- data/lib/authorize_net/sim/response.rb +0 -142
- data/lib/authorize_net/sim/transaction.rb +0 -138
- data/lib/generators/authorize_net/direct_post/direct_post_generator.rb +0 -53
- data/lib/generators/authorize_net/direct_post/templates/README-AuthorizeNet +0 -49
- data/lib/generators/authorize_net/direct_post/templates/config.yml.erb +0 -8
- data/lib/generators/authorize_net/direct_post/templates/config.yml.rails3.erb +0 -8
- data/lib/generators/authorize_net/direct_post/templates/controller.rb.erb +0 -31
- data/lib/generators/authorize_net/direct_post/templates/initializer.rb +0 -4
- data/lib/generators/authorize_net/direct_post/templates/layout.erb +0 -18
- data/lib/generators/authorize_net/direct_post/templates/payment.erb +0 -10
- data/lib/generators/authorize_net/direct_post/templates/payment.rails3.erb +0 -10
- data/lib/generators/authorize_net/direct_post/templates/receipt.erb +0 -1
- data/lib/generators/authorize_net/direct_post/templates/relay_response.erb +0 -1
- data/lib/generators/authorize_net/sim/sim_generator.rb +0 -47
- data/lib/generators/authorize_net/sim/templates/README-AuthorizeNet +0 -52
- data/lib/generators/authorize_net/sim/templates/config.yml.erb +0 -8
- data/lib/generators/authorize_net/sim/templates/config.yml.rails3.erb +0 -8
- data/lib/generators/authorize_net/sim/templates/controller.rb.erb +0 -21
- data/lib/generators/authorize_net/sim/templates/initializer.rb +0 -4
- data/lib/generators/authorize_net/sim/templates/layout.erb +0 -18
- data/lib/generators/authorize_net/sim/templates/payment.erb +0 -6
- data/lib/generators/authorize_net/sim/templates/payment.rails3.erb +0 -6
- data/lib/generators/authorize_net/sim/templates/thank_you.erb +0 -1
- data/lib/generators/generator_extensions.rb +0 -75
@@ -1,29 +1,23 @@
|
|
1
1
|
module AuthorizeNet
|
2
|
-
|
3
|
-
#
|
4
|
-
# this one. Instead you should use AuthorizeNet::AIM::Response,
|
5
|
-
# AuthorizeNet::ARB::Response or AuthorizeNet::SIM::Response.
|
2
|
+
# The core, API agnostic response class.
|
3
|
+
# You shouldn't instantiate this one.
|
6
4
|
class Response
|
7
|
-
|
8
5
|
include AuthorizeNet::TypeConversions
|
9
|
-
|
6
|
+
|
10
7
|
# Fields to convert to/from booleans.
|
11
8
|
@@boolean_fields = []
|
12
9
|
|
13
10
|
# Fields to convert to/from BigDecimal.
|
14
11
|
@@decimal_fields = []
|
15
|
-
|
16
|
-
# DO NOT USE.
|
17
|
-
|
18
|
-
|
19
|
-
raise "#{self.class.to_s} should not be instantiated directly."
|
12
|
+
|
13
|
+
# DO NOT USE.
|
14
|
+
def initialize
|
15
|
+
raise "#{self.class} should not be instantiated directly."
|
20
16
|
end
|
21
|
-
|
17
|
+
|
22
18
|
# Check to see if the response indicated success.
|
23
19
|
def success?
|
24
20
|
false
|
25
21
|
end
|
26
|
-
|
27
22
|
end
|
28
|
-
|
29
|
-
end
|
23
|
+
end
|
@@ -1,24 +1,20 @@
|
|
1
1
|
module AuthorizeNet
|
2
|
-
|
3
|
-
#
|
4
|
-
# Instead you should use AuthorizeNet::AIM::Transaction,
|
5
|
-
# AuthorizeNet::SIM::Transaction or AuthorizeNet::ARB::Transaction.
|
2
|
+
# The core, API agnostic transaction class.
|
3
|
+
# You shouldn't instantiate this one.
|
6
4
|
class Transaction
|
7
|
-
|
8
5
|
include AuthorizeNet::TypeConversions
|
9
|
-
|
6
|
+
|
10
7
|
# Fields to convert to/from booleans.
|
11
8
|
@@boolean_fields = []
|
12
|
-
|
9
|
+
|
13
10
|
# Fields to convert to/from BigDecimal.
|
14
11
|
@@decimal_fields = []
|
15
|
-
|
16
|
-
# DO NOT USE.
|
17
|
-
|
18
|
-
def initialize()
|
12
|
+
|
13
|
+
# DO NOT USE.
|
14
|
+
def initialize
|
19
15
|
@fields ||= {}
|
20
16
|
end
|
21
|
-
|
17
|
+
|
22
18
|
# Sets arbitrary API fields, overwriting existing values if they exist.
|
23
19
|
# Takes a hash of key/value pairs, where the keys are the field names
|
24
20
|
# without the "x_" prefix. You can set a field to Nil to unset it. If the
|
@@ -29,44 +25,40 @@ module AuthorizeNet
|
|
29
25
|
# each value in the array.
|
30
26
|
def set_fields(fields = {})
|
31
27
|
@fields.merge!(fields)
|
32
|
-
@fields.reject! {|
|
28
|
+
@fields.reject! { |_k, v| v.nil? }
|
33
29
|
@fields
|
34
30
|
end
|
35
|
-
|
31
|
+
|
36
32
|
# Returns the current hash of API fields.
|
37
|
-
|
38
|
-
|
39
|
-
end
|
40
|
-
|
33
|
+
attr_reader :fields
|
34
|
+
|
41
35
|
# Takes an instance of AuthorizeNet::Address and adds it to the transaction.
|
42
36
|
def set_address(address)
|
43
37
|
@fields.merge!(address.to_hash)
|
44
38
|
end
|
45
|
-
|
39
|
+
|
46
40
|
# Takes an instance of AuthorizeNet::ShippingAddress and adds it to the
|
47
41
|
# transaction.
|
48
42
|
def set_shipping_address(address)
|
49
43
|
@fields.merge!(address.to_hash)
|
50
44
|
end
|
51
|
-
|
45
|
+
|
52
46
|
# Takes an instance of AuthorizeNet::Customer and adds it to the transaction.
|
53
47
|
def set_customer(customer)
|
54
48
|
@fields.merge!(customer.to_hash)
|
55
49
|
end
|
56
|
-
|
50
|
+
|
57
51
|
#:enddoc:
|
58
52
|
protected
|
59
|
-
|
53
|
+
|
60
54
|
# Internal method to handle multiple types of payment arguments.
|
61
55
|
def handle_payment_argument(payment)
|
62
56
|
case payment
|
63
57
|
when AuthorizeNet::CreditCard, AuthorizeNet::ECheck
|
64
58
|
set_fields(payment.to_hash)
|
65
59
|
else
|
66
|
-
set_fields(:
|
60
|
+
set_fields(card_num: payment)
|
67
61
|
end
|
68
62
|
end
|
69
|
-
|
70
63
|
end
|
71
|
-
|
72
|
-
end
|
64
|
+
end
|
@@ -1,9 +1,7 @@
|
|
1
1
|
module AuthorizeNet
|
2
|
-
|
3
2
|
# The core, xml response class. You shouldn't instantiate this one.
|
4
3
|
# Instead you should use AuthorizeNet::ARB::Response.
|
5
4
|
class XmlResponse < AuthorizeNet::Response
|
6
|
-
|
7
5
|
# DO NOT USE. Instantiate AuthorizeNet::ARB::Response or AuthorizeNet::CIM::Response instead.
|
8
6
|
def initialize(raw_response, transaction)
|
9
7
|
@raw_response = raw_response
|
@@ -19,23 +17,23 @@ module AuthorizeNet
|
|
19
17
|
@message_code = node_content_unless_nil(@root.at_css('messages message code'))
|
20
18
|
@message_text = node_content_unless_nil(@root.at_css('messages message text'))
|
21
19
|
@reference_id = node_content_unless_nil(@root.at_css('refId'))
|
22
|
-
rescue
|
23
|
-
@raw_response =
|
20
|
+
rescue StandardError
|
21
|
+
@raw_response = $ERROR_INFO
|
24
22
|
end
|
25
23
|
end
|
26
24
|
end
|
27
|
-
|
25
|
+
|
28
26
|
# Check to see if the response indicated success. Success is defined as a 200 OK response with a resultCode
|
29
27
|
# of 'Ok'.
|
30
28
|
def success?
|
31
29
|
!connection_failure? && @result_code == 'Ok'
|
32
30
|
end
|
33
|
-
|
31
|
+
|
34
32
|
# Returns true if we failed to open a connection to the gateway or got back a non-200 OK HTTP response.
|
35
33
|
def connection_failure?
|
36
|
-
!@raw_response.
|
34
|
+
!@raw_response.is_a?(Net::HTTPOK)
|
37
35
|
end
|
38
|
-
|
36
|
+
|
39
37
|
# Returns the underlying Net::HTTPResponse object. This has the original response body along with
|
40
38
|
# headers and such. Note that if an exception is generated while making the request (which happens
|
41
39
|
# if there is no internet connection for example), you will get the exception object here instead of
|
@@ -43,51 +41,43 @@ module AuthorizeNet
|
|
43
41
|
def raw
|
44
42
|
@raw_response
|
45
43
|
end
|
46
|
-
|
44
|
+
|
47
45
|
# Returns a deep-copy of the XML object received from the payment gateway. Or nil if there was no XML payload.
|
48
46
|
def xml
|
49
47
|
@root.dup unless @root.nil?
|
50
48
|
end
|
51
|
-
|
49
|
+
|
52
50
|
# Returns the resultCode from the XML response. resultCode will be either 'Ok' or 'Error'.
|
53
|
-
|
54
|
-
|
55
|
-
end
|
56
|
-
|
51
|
+
attr_reader :result_code
|
52
|
+
|
57
53
|
# Returns the messageCode from the XML response. This is a code indicating the details of an error
|
58
54
|
# or success.
|
59
|
-
|
60
|
-
|
61
|
-
end
|
62
|
-
|
55
|
+
attr_reader :message_code
|
56
|
+
|
63
57
|
# Returns the messageText from the XML response. This is a text description of the message_code.
|
64
|
-
|
65
|
-
|
66
|
-
end
|
67
|
-
|
58
|
+
attr_reader :message_text
|
59
|
+
|
68
60
|
# Alias for result_code.
|
69
61
|
def response_code
|
70
62
|
result_code
|
71
63
|
end
|
72
|
-
|
64
|
+
|
73
65
|
# Alias for message_code.
|
74
66
|
def response_reason_code
|
75
67
|
message_code
|
76
68
|
end
|
77
|
-
|
69
|
+
|
78
70
|
# Alias for message_text.
|
79
71
|
def response_reason_text
|
80
72
|
message_text
|
81
73
|
end
|
82
|
-
|
74
|
+
|
83
75
|
# Returns the refId from the response if there is one. Otherwise returns nil.
|
84
|
-
|
85
|
-
|
86
|
-
end
|
87
|
-
|
76
|
+
attr_reader :reference_id
|
77
|
+
|
88
78
|
#:enddoc:
|
89
79
|
protected
|
90
|
-
|
80
|
+
|
91
81
|
def node_content_unless_nil(node)
|
92
82
|
if node.nil?
|
93
83
|
nil
|
@@ -95,31 +85,25 @@ module AuthorizeNet
|
|
95
85
|
node.content
|
96
86
|
end
|
97
87
|
end
|
98
|
-
|
88
|
+
|
99
89
|
def node_child_content_unless_nil(node)
|
100
90
|
if node.nil?
|
101
91
|
nil
|
102
92
|
else
|
103
|
-
|
104
|
-
node.children.collect(&:content)
|
105
|
-
else
|
106
|
-
nil
|
107
|
-
end
|
93
|
+
node.children.collect(&:content) unless node.children.empty?
|
108
94
|
end
|
109
95
|
end
|
110
|
-
|
96
|
+
|
111
97
|
# Transforms a block of XML into a model Object defined by entity_desc.
|
112
98
|
def build_entity(xml, entity_desc)
|
113
99
|
args = {}
|
114
100
|
entity_desc.node_structure.each do |node_desc|
|
115
|
-
node_name = (node_desc.keys.reject {|k| k.to_s[0..0] == '_' }).first
|
101
|
+
node_name = (node_desc.keys.reject { |k| k.to_s[0..0] == '_' }).first
|
116
102
|
args.merge!(handle_node_type(xml, node_desc, node_name, args, ''))
|
117
103
|
end
|
118
|
-
|
119
|
-
if args.
|
120
|
-
|
121
|
-
end
|
122
|
-
|
104
|
+
|
105
|
+
return nil if args.empty?
|
106
|
+
|
123
107
|
if entity_desc.arg_mapping.nil?
|
124
108
|
return entity_desc.entity_class.new(args)
|
125
109
|
else
|
@@ -132,7 +116,7 @@ module AuthorizeNet
|
|
132
116
|
return entity_desc.entity_class.new(*args_list)
|
133
117
|
end
|
134
118
|
end
|
135
|
-
|
119
|
+
|
136
120
|
# Parses an XML fragment into an internal representation.
|
137
121
|
def handle_node_type(xml, node_desc, node_name, args, base_name)
|
138
122
|
case node_desc[node_name]
|
@@ -144,29 +128,27 @@ module AuthorizeNet
|
|
144
128
|
when Method, Proc
|
145
129
|
content = node_desc[:_converter].call(content)
|
146
130
|
when Symbol
|
147
|
-
content =
|
131
|
+
content = send(node_desc[:_converter], content)
|
148
132
|
end
|
149
133
|
args[node_desc[node_name]] = content unless content.nil?
|
150
134
|
end
|
151
135
|
when AuthorizeNet::EntityDescription
|
152
|
-
|
136
|
+
if node_desc[:_multivalue].nil?
|
137
|
+
entity = build_entity(xml.css(base_name + node_name.to_s), node_desc[node_name])
|
138
|
+
args[node_desc[:_value]] = entity unless entity.nil?
|
139
|
+
else
|
153
140
|
xml.css(base_name + node_name.to_s).each do |node|
|
154
141
|
entity = build_entity(node, node_desc[node_name])
|
155
142
|
args[node_desc[:_multivalue]] = args[node_desc[:_multivalue]].to_a + entity.to_a unless entity.nil?
|
156
143
|
end
|
157
|
-
else
|
158
|
-
entity = build_entity(xml.css(base_name + node_name.to_s), node_desc[node_name])
|
159
|
-
args[node_desc[:_value]] = entity unless entity.nil?
|
160
144
|
end
|
161
145
|
when Array
|
162
146
|
node_desc[node_name].each do |inner_node|
|
163
|
-
inner_node_name = (inner_node.keys.reject {|k| k.to_s[0..0] == '_' }).first
|
147
|
+
inner_node_name = (inner_node.keys.reject { |k| k.to_s[0..0] == '_' }).first
|
164
148
|
args.merge!(handle_node_type(xml, inner_node, inner_node_name, args, node_name.to_s + ' '))
|
165
149
|
end
|
166
150
|
end
|
167
|
-
|
151
|
+
args
|
168
152
|
end
|
169
|
-
|
170
153
|
end
|
171
|
-
|
172
|
-
end
|
154
|
+
end
|
@@ -1,163 +1,151 @@
|
|
1
1
|
module AuthorizeNet
|
2
|
-
|
3
2
|
# The ARB transaction class.
|
4
3
|
class XmlTransaction < AuthorizeNet::Transaction
|
5
|
-
|
6
4
|
# The XML namespace used by the ARB API.
|
7
|
-
XML_NAMESPACE = 'AnetApi/xml/v1/schema/AnetApiSchema.xsd'
|
8
|
-
|
5
|
+
XML_NAMESPACE = 'AnetApi/xml/v1/schema/AnetApiSchema.xsd'.freeze
|
6
|
+
|
9
7
|
# Constants for both the various Authorize.Net subscription gateways are defined here.
|
10
8
|
module Gateway
|
11
|
-
LIVE = 'https://api2.authorize.net/xml/v1/request.api'
|
12
|
-
TEST = 'https://apitest.authorize.net/xml/v1/request.api'
|
9
|
+
LIVE = 'https://api2.authorize.net/xml/v1/request.api'.freeze
|
10
|
+
TEST = 'https://apitest.authorize.net/xml/v1/request.api'.freeze
|
13
11
|
end
|
14
|
-
|
12
|
+
|
15
13
|
# Constants for both the various Authorize.Net transaction types are defined here.
|
16
14
|
module Type
|
17
|
-
ARB_CREATE = "ARBCreateSubscriptionRequest"
|
18
|
-
ARB_UPDATE = "ARBUpdateSubscriptionRequest"
|
19
|
-
ARB_GET_STATUS = "ARBGetSubscriptionStatusRequest"
|
20
|
-
ARB_CANCEL = "ARBCancelSubscriptionRequest"
|
21
|
-
ARB_GET_SUBSCRIPTION_LIST = "ARBGetSubscriptionListRequest"
|
22
|
-
CIM_CREATE_PROFILE = "createCustomerProfileRequest"
|
23
|
-
CIM_CREATE_PAYMENT = "createCustomerPaymentProfileRequest"
|
24
|
-
CIM_CREATE_ADDRESS = "createCustomerShippingAddressRequest"
|
25
|
-
CIM_CREATE_TRANSACTION = "createCustomerProfileTransactionRequest"
|
26
|
-
CIM_DELETE_PROFILE = "deleteCustomerProfileRequest"
|
27
|
-
CIM_DELETE_PAYMENT = "deleteCustomerPaymentProfileRequest"
|
28
|
-
CIM_DELETE_ADDRESS = "deleteCustomerShippingAddressRequest"
|
29
|
-
CIM_GET_PROFILE_IDS = "getCustomerProfileIdsRequest"
|
30
|
-
CIM_GET_PROFILE = "getCustomerProfileRequest"
|
31
|
-
CIM_GET_PAYMENT = "getCustomerPaymentProfileRequest"
|
32
|
-
CIM_GET_ADDRESS = "getCustomerShippingAddressRequest"
|
33
|
-
CIM_GET_HOSTED_PROFILE = "getHostedProfilePageRequest"
|
34
|
-
CIM_UPDATE_PROFILE = "updateCustomerProfileRequest"
|
35
|
-
CIM_UPDATE_PAYMENT = "updateCustomerPaymentProfileRequest"
|
36
|
-
CIM_UPDATE_ADDRESS = "updateCustomerShippingAddressRequest"
|
37
|
-
CIM_UPDATE_SPLIT = "updateSplitTenderGroupRequest"
|
38
|
-
CIM_VALIDATE_PAYMENT = "validateCustomerPaymentProfileRequest"
|
39
|
-
REPORT_GET_BATCH_LIST = "getSettledBatchListRequest"
|
40
|
-
REPORT_GET_TRANSACTION_LIST = "getTransactionListRequest"
|
41
|
-
REPORT_GET_UNSETTLED_TRANSACTION_LIST = "getUnsettledTransactionListRequest"
|
42
|
-
REPORT_GET_TRANSACTION_DETAILS = "getTransactionDetailsRequest"
|
15
|
+
ARB_CREATE = "ARBCreateSubscriptionRequest".freeze
|
16
|
+
ARB_UPDATE = "ARBUpdateSubscriptionRequest".freeze
|
17
|
+
ARB_GET_STATUS = "ARBGetSubscriptionStatusRequest".freeze
|
18
|
+
ARB_CANCEL = "ARBCancelSubscriptionRequest".freeze
|
19
|
+
ARB_GET_SUBSCRIPTION_LIST = "ARBGetSubscriptionListRequest".freeze
|
20
|
+
CIM_CREATE_PROFILE = "createCustomerProfileRequest".freeze
|
21
|
+
CIM_CREATE_PAYMENT = "createCustomerPaymentProfileRequest".freeze
|
22
|
+
CIM_CREATE_ADDRESS = "createCustomerShippingAddressRequest".freeze
|
23
|
+
CIM_CREATE_TRANSACTION = "createCustomerProfileTransactionRequest".freeze
|
24
|
+
CIM_DELETE_PROFILE = "deleteCustomerProfileRequest".freeze
|
25
|
+
CIM_DELETE_PAYMENT = "deleteCustomerPaymentProfileRequest".freeze
|
26
|
+
CIM_DELETE_ADDRESS = "deleteCustomerShippingAddressRequest".freeze
|
27
|
+
CIM_GET_PROFILE_IDS = "getCustomerProfileIdsRequest".freeze
|
28
|
+
CIM_GET_PROFILE = "getCustomerProfileRequest".freeze
|
29
|
+
CIM_GET_PAYMENT = "getCustomerPaymentProfileRequest".freeze
|
30
|
+
CIM_GET_ADDRESS = "getCustomerShippingAddressRequest".freeze
|
31
|
+
CIM_GET_HOSTED_PROFILE = "getHostedProfilePageRequest".freeze
|
32
|
+
CIM_UPDATE_PROFILE = "updateCustomerProfileRequest".freeze
|
33
|
+
CIM_UPDATE_PAYMENT = "updateCustomerPaymentProfileRequest".freeze
|
34
|
+
CIM_UPDATE_ADDRESS = "updateCustomerShippingAddressRequest".freeze
|
35
|
+
CIM_UPDATE_SPLIT = "updateSplitTenderGroupRequest".freeze
|
36
|
+
CIM_VALIDATE_PAYMENT = "validateCustomerPaymentProfileRequest".freeze
|
37
|
+
REPORT_GET_BATCH_LIST = "getSettledBatchListRequest".freeze
|
38
|
+
REPORT_GET_TRANSACTION_LIST = "getTransactionListRequest".freeze
|
39
|
+
REPORT_GET_UNSETTLED_TRANSACTION_LIST = "getUnsettledTransactionListRequest".freeze
|
40
|
+
REPORT_GET_TRANSACTION_DETAILS = "getTransactionDetailsRequest".freeze
|
43
41
|
end
|
44
|
-
|
42
|
+
|
45
43
|
# Fields to convert to/from booleans.
|
46
44
|
@@boolean_fields = []
|
47
|
-
|
45
|
+
|
48
46
|
# Fields to convert to/from BigDecimal.
|
49
47
|
@@decimal_fields = []
|
50
|
-
|
48
|
+
|
51
49
|
# Fields to convert to/from Date.
|
52
50
|
@@date_fields = []
|
53
|
-
|
51
|
+
|
54
52
|
# Fields to convert to/from DateTime.
|
55
53
|
@@datetime_fields = []
|
56
|
-
|
54
|
+
|
57
55
|
# The class to wrap our response in.
|
58
56
|
@response_class = AuthorizeNet::XmlResponse
|
59
|
-
|
57
|
+
|
60
58
|
# The default options for the constructor.
|
61
59
|
@@option_defaults = {
|
62
|
-
:
|
63
|
-
:
|
64
|
-
:
|
60
|
+
gateway: :production,
|
61
|
+
verify_ssl: true,
|
62
|
+
reference_id: nil
|
65
63
|
}
|
66
|
-
|
64
|
+
|
67
65
|
# DO NOT USE. Instantiate AuthorizeNet::ARB::Transaction or AuthorizeNet::CIM::Transaction instead.
|
68
66
|
def initialize(api_login_id, api_transaction_key, options = {})
|
69
67
|
super()
|
70
68
|
@api_login_id = api_login_id
|
71
69
|
@api_transaction_key = api_transaction_key
|
72
|
-
|
70
|
+
|
73
71
|
@response ||= nil
|
74
72
|
@type ||= nil
|
75
|
-
|
73
|
+
|
76
74
|
options = @@option_defaults.merge(options)
|
77
75
|
@verify_ssl = options[:verify_ssl]
|
78
76
|
@reference_id = options[:reference_id]
|
79
77
|
@gateway = case options[:gateway].to_s
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
78
|
+
when 'sandbox', 'test'
|
79
|
+
Gateway::TEST
|
80
|
+
when 'production', 'live'
|
81
|
+
Gateway::LIVE
|
82
|
+
else
|
83
|
+
@gateway = options[:gateway]
|
84
|
+
options[:gateway]
|
87
85
|
end
|
88
86
|
end
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
87
|
+
|
88
|
+
def setOAuthOptions
|
89
|
+
unless @options_OAuth.blank?
|
90
|
+
@options_OAuth = @@option_defaults.merge(@options_OAuth)
|
91
|
+
@verify_ssl = options_OAuth[:verify_ssl]
|
92
|
+
@reference_id = options_OAuth[:reference_id]
|
93
|
+
|
94
|
+
@gateway = case options_OAuth[:gateway].to_s
|
95
|
+
when 'sandbox', 'test'
|
96
|
+
Gateway::TEST
|
97
|
+
when 'production', 'live'
|
98
|
+
Gateway::LIVE
|
99
|
+
else
|
100
|
+
@gateway = options_OAuth[:gateway]
|
101
|
+
options_OAuth[:gateway]
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
108
106
|
# Checks if the transaction has been configured for the sandbox or not. Return FALSE if the
|
109
107
|
# transaction is running against the production, TRUE otherwise.
|
110
108
|
def test?
|
111
109
|
@gateway != Gateway::LIVE
|
112
110
|
end
|
113
|
-
|
111
|
+
|
114
112
|
# Checks to see if the transaction has a response (meaning it has been submitted to the gateway).
|
115
113
|
# Returns TRUE if a response is present, FALSE otherwise.
|
116
114
|
def has_response?
|
117
115
|
!@response.nil?
|
118
116
|
end
|
119
|
-
|
117
|
+
|
120
118
|
# Retrieve the response object (or Nil if transaction hasn't been sent to the gateway).
|
121
|
-
|
122
|
-
|
123
|
-
end
|
124
|
-
|
119
|
+
attr_reader :response
|
120
|
+
|
125
121
|
# Submits the transaction to the gateway for processing. Returns a response object. If the transaction
|
126
122
|
# has already been run, it will return nil.
|
127
123
|
def run
|
128
124
|
make_request
|
129
125
|
end
|
130
|
-
|
126
|
+
|
131
127
|
# Returns a deep-copy of the XML object sent to the payment gateway. Or nil if there was no XML payload.
|
132
|
-
|
133
|
-
|
134
|
-
end
|
135
|
-
|
128
|
+
attr_reader :xml
|
129
|
+
|
136
130
|
#:enddoc:
|
137
131
|
protected
|
138
|
-
|
132
|
+
|
139
133
|
# Takes a list of nodes (a Hash is a node, and Array is a list) and returns True if any nodes
|
140
134
|
# would be built by build_nodes. False if no new nodes would be generated.
|
141
135
|
def has_content(nodeList, data)
|
142
136
|
nodeList.each do |node|
|
143
|
-
nodeName = (node.keys.reject {|
|
137
|
+
nodeName = (node.keys.reject { |_k| nodeName.to_s[0..0] == '_' }).first
|
144
138
|
multivalue = node[:_multivalue]
|
145
139
|
conditional = node[:_conditional]
|
146
140
|
value = node[nodeName]
|
147
|
-
unless conditional.nil?
|
148
|
-
value = self.send(conditional, nodeName)
|
149
|
-
end
|
141
|
+
value = send(conditional, nodeName) unless conditional.nil?
|
150
142
|
case value
|
151
143
|
when Array
|
152
144
|
if multivalue.nil?
|
153
|
-
if has_content(value, data)
|
154
|
-
return true
|
155
|
-
end
|
145
|
+
return true if has_content(value, data)
|
156
146
|
else
|
157
147
|
data[multivalue].each do |v|
|
158
|
-
if has_content(value, v)
|
159
|
-
return true
|
160
|
-
end
|
148
|
+
return true if has_content(value, v)
|
161
149
|
end
|
162
150
|
end
|
163
151
|
when Symbol
|
@@ -169,33 +157,31 @@ module AuthorizeNet
|
|
169
157
|
end
|
170
158
|
false
|
171
159
|
end
|
172
|
-
|
160
|
+
|
173
161
|
# Takes a list of nodes (a Hash is a node, and Array is a list) and recursively builds the XML by pulling
|
174
162
|
# values as needed from data.
|
175
163
|
def build_nodes(builder, nodeList, data)
|
176
164
|
nodeList.each do |node|
|
177
|
-
# TODO - ADD COMMENTS HERE
|
178
|
-
nodeName = (node.keys.reject {|k| k.to_s[0..0] == '_' }).first
|
165
|
+
# TODO: - ADD COMMENTS HERE
|
166
|
+
nodeName = (node.keys.reject { |k| k.to_s[0..0] == '_' }).first
|
179
167
|
multivalue = node[:_multivalue]
|
180
168
|
conditional = node[:_conditional]
|
181
169
|
value = node[nodeName]
|
182
170
|
|
183
|
-
unless conditional.nil?
|
184
|
-
value = self.send(conditional, nodeName)
|
185
|
-
end
|
171
|
+
value = send(conditional, nodeName) unless conditional.nil?
|
186
172
|
case value
|
187
173
|
when Array # node containing other nodes
|
188
174
|
if multivalue.nil?
|
189
|
-
proc =
|
175
|
+
proc = proc { build_nodes(builder, value, data) }
|
190
176
|
builder.send(nodeName, &proc) if has_content(value, data)
|
191
177
|
else
|
192
178
|
data[multivalue].to_a.each do |v|
|
193
|
-
proc =
|
179
|
+
proc = proc { build_nodes(builder, value, v) }
|
194
180
|
builder.send(nodeName, &proc) if has_content(value, v)
|
195
181
|
end
|
196
182
|
end
|
197
183
|
when Symbol # node containing actual data
|
198
|
-
if data[value].
|
184
|
+
if data[value].is_a?(Array)
|
199
185
|
data[value].each do |v|
|
200
186
|
converted = convert_field(value, v)
|
201
187
|
builder.send(nodeName, converted) unless converted.nil?
|
@@ -209,32 +195,30 @@ module AuthorizeNet
|
|
209
195
|
end
|
210
196
|
end
|
211
197
|
end
|
212
|
-
|
198
|
+
|
213
199
|
def convert_field(field, value)
|
214
|
-
if @@boolean_fields.include?(field)
|
200
|
+
if @@boolean_fields.include?(field) && !value.nil?
|
215
201
|
return boolean_to_value(value)
|
216
|
-
elsif @@decimal_fields.include?(field)
|
202
|
+
elsif @@decimal_fields.include?(field) && !value.nil?
|
217
203
|
return decimal_to_value(value)
|
218
|
-
elsif @@date_fields.include?(field)
|
204
|
+
elsif @@date_fields.include?(field) && !value.nil?
|
219
205
|
return date_to_value(value)
|
220
|
-
elsif @@datetime_fields.include?(field)
|
206
|
+
elsif @@datetime_fields.include?(field) && !value.nil?
|
221
207
|
return datetime_to_value(value)
|
222
208
|
elsif field == :extra_options
|
223
209
|
# handle converting extra options
|
224
210
|
options = []
|
225
|
-
unless value.nil?
|
226
|
-
value.each_pair{|k,v| options <<= self.to_param(k, v)}
|
227
|
-
end
|
211
|
+
value.each_pair { |k, v| options <<= to_param(k, v) } unless value.nil?
|
228
212
|
unless @custom_fields.nil?
|
229
213
|
# special sort to maintain compatibility with AIM custom field ordering
|
230
214
|
# FIXME - This should be DRY'd up.
|
231
215
|
custom_field_keys = @custom_fields.keys.collect(&:to_s).sort.collect(&:to_sym)
|
232
216
|
for key in custom_field_keys
|
233
|
-
options <<=
|
217
|
+
options <<= to_param(key, @custom_fields[key.to_sym], '')
|
234
218
|
end
|
235
219
|
end
|
236
|
-
|
237
|
-
if options.
|
220
|
+
|
221
|
+
if !options.empty?
|
238
222
|
return options.join('&')
|
239
223
|
else
|
240
224
|
return nil
|
@@ -243,38 +227,36 @@ module AuthorizeNet
|
|
243
227
|
# convert MMYY expiration dates into the XML equivalent
|
244
228
|
unless value.nil?
|
245
229
|
begin
|
246
|
-
return value.to_s.
|
247
|
-
rescue
|
230
|
+
return value.to_s.casecmp('xxxx').zero? ? 'XXXX' : Date.strptime(value.to_s, '%m%y').strftime('%Y-%m')
|
231
|
+
rescue StandardError
|
248
232
|
# If we didn't get the exp_date in MMYY format, try our best to convert it
|
249
233
|
return Date.parse(value.to_s).strftime('%Y-%m')
|
250
234
|
end
|
251
235
|
end
|
252
236
|
end
|
253
|
-
|
237
|
+
|
254
238
|
value
|
255
239
|
end
|
256
|
-
|
240
|
+
|
257
241
|
# An internal method that builds the POST body, submits it to the gateway, and constructs a Response object with the response.
|
258
242
|
def make_request
|
259
|
-
if has_response?
|
260
|
-
|
261
|
-
end
|
262
|
-
|
243
|
+
return nil if has_response?
|
244
|
+
|
263
245
|
fields = @fields
|
264
|
-
|
265
|
-
builder = Nokogiri::XML::Builder.new(:
|
266
|
-
x.send(@type.to_sym, :
|
267
|
-
x.merchantAuthentication
|
246
|
+
|
247
|
+
builder = Nokogiri::XML::Builder.new(encoding: 'utf-8') do |x|
|
248
|
+
x.send(@type.to_sym, xmlns: XML_NAMESPACE) do
|
249
|
+
x.merchantAuthentication do
|
268
250
|
x.name @api_login_id
|
269
251
|
x.transactionKey @api_transaction_key
|
270
|
-
|
252
|
+
end
|
271
253
|
build_nodes(x, self.class.const_get(:FIELDS)[@type], fields)
|
272
|
-
|
254
|
+
end
|
273
255
|
end
|
274
|
-
@xml = builder.to_xml
|
256
|
+
@xml = builder.to_xml
|
275
257
|
|
276
258
|
url = URI.parse(@gateway)
|
277
|
-
|
259
|
+
|
278
260
|
request = Net::HTTP::Post.new(url.path)
|
279
261
|
request.content_type = 'text/xml'
|
280
262
|
request.body = @xml
|
@@ -285,14 +267,13 @@ module AuthorizeNet
|
|
285
267
|
else
|
286
268
|
connection.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
287
269
|
end
|
288
|
-
|
270
|
+
|
289
271
|
# Use our Class's @response_class variable to find the Response class we are supposed to use.
|
290
272
|
begin
|
291
|
-
@response = self.class.instance_variable_get(:@response_class).new((connection.start {|http| http.request(request)}), self)
|
292
|
-
rescue
|
293
|
-
@response = self.class.instance_variable_get(:@response_class).new(
|
273
|
+
@response = self.class.instance_variable_get(:@response_class).new((connection.start { |http| http.request(request) }), self)
|
274
|
+
rescue StandardError
|
275
|
+
@response = self.class.instance_variable_get(:@response_class).new($ERROR_INFO, self)
|
294
276
|
end
|
295
277
|
end
|
296
|
-
|
297
278
|
end
|
298
279
|
end
|