authorizenet 1.9.7 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/app/helpers/authorize_net_helper.rb +23 -23
- data/lib/authorize_net.rb +62 -107
- data/lib/authorize_net/api/LogHelper.rb +97 -97
- data/lib/authorize_net/api/SensitiveDataFilter.rb +92 -92
- data/lib/authorize_net/api/api_transaction.rb +129 -129
- data/lib/authorize_net/api/constants.yml +1 -1
- data/lib/authorize_net/api/schema.rb +5421 -5421
- data/lib/authorize_net/api/transaction.rb +265 -265
- data/lib/authorize_net/authorize_net.rb +154 -154
- data/lib/authorize_net/response.rb +23 -25
- data/lib/authorize_net/transaction.rb +64 -66
- data/lib/authorize_net/xml_response.rb +154 -154
- data/lib/authorize_net/xml_transaction.rb +279 -279
- data/lib/authorizenet.rb +4 -4
- metadata +3 -61
- data/lib/authorize_net/addresses/address.rb +0 -25
- data/lib/authorize_net/addresses/shipping_address.rb +0 -22
- data/lib/authorize_net/aim/response.rb +0 -120
- data/lib/authorize_net/aim/transaction.rb +0 -171
- data/lib/authorize_net/arb/fields.rb +0 -24
- data/lib/authorize_net/arb/paging.rb +0 -29
- data/lib/authorize_net/arb/response.rb +0 -26
- data/lib/authorize_net/arb/sorting.rb +0 -39
- data/lib/authorize_net/arb/subscription.rb +0 -68
- data/lib/authorize_net/arb/subscription_detail.rb +0 -10
- data/lib/authorize_net/arb/subscription_list_response.rb +0 -36
- data/lib/authorize_net/arb/transaction.rb +0 -171
- data/lib/authorize_net/cim/customer_profile.rb +0 -15
- data/lib/authorize_net/cim/payment_profile.rb +0 -35
- data/lib/authorize_net/cim/response.rb +0 -111
- data/lib/authorize_net/cim/transaction.rb +0 -721
- data/lib/authorize_net/customer.rb +0 -24
- data/lib/authorize_net/email_receipt.rb +0 -20
- data/lib/authorize_net/fields.rb +0 -760
- data/lib/authorize_net/key_value_response.rb +0 -109
- data/lib/authorize_net/key_value_transaction.rb +0 -281
- data/lib/authorize_net/line_item.rb +0 -21
- data/lib/authorize_net/order.rb +0 -38
- data/lib/authorize_net/payment_methods/credit_card.rb +0 -61
- data/lib/authorize_net/payment_methods/echeck.rb +0 -70
- data/lib/authorize_net/reporting/batch.rb +0 -16
- data/lib/authorize_net/reporting/batch_statistics.rb +0 -15
- data/lib/authorize_net/reporting/fds_filter.rb +0 -8
- data/lib/authorize_net/reporting/response.rb +0 -157
- data/lib/authorize_net/reporting/returned_item.rb +0 -45
- data/lib/authorize_net/reporting/transaction.rb +0 -131
- data/lib/authorize_net/reporting/transaction_details.rb +0 -22
- data/lib/authorize_net/sim/hosted_payment_form.rb +0 -34
- data/lib/authorize_net/sim/hosted_receipt_page.rb +0 -32
- data/lib/authorize_net/sim/response.rb +0 -133
- data/lib/authorize_net/sim/transaction.rb +0 -128
- data/lib/generators/authorize_net/direct_post/direct_post_generator.rb +0 -52
- 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 -46
- 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 -73
data/lib/authorizenet.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# This file is just here to avoid obnoxious gem name/require name issues. All this
|
2
|
-
# file does is require authorize_net.rb, the real initialization file.
|
3
|
-
|
4
|
-
require 'authorize_net'
|
1
|
+
# This file is just here to avoid obnoxious gem name/require name issues. All this
|
2
|
+
# file does is require authorize_net.rb, the real initialization file.
|
3
|
+
|
4
|
+
require 'authorize_net'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: authorizenet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Authorize.Net
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-03-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -143,76 +143,18 @@ extra_rdoc_files: []
|
|
143
143
|
files:
|
144
144
|
- lib/app/helpers/authorize_net_helper.rb
|
145
145
|
- lib/authorize_net.rb
|
146
|
-
- lib/authorize_net/addresses/address.rb
|
147
|
-
- lib/authorize_net/addresses/shipping_address.rb
|
148
|
-
- lib/authorize_net/aim/response.rb
|
149
|
-
- lib/authorize_net/aim/transaction.rb
|
150
146
|
- lib/authorize_net/api/LogHelper.rb
|
151
147
|
- lib/authorize_net/api/SensitiveDataFilter.rb
|
152
148
|
- lib/authorize_net/api/api_transaction.rb
|
153
149
|
- lib/authorize_net/api/constants.yml
|
154
150
|
- lib/authorize_net/api/schema.rb
|
155
151
|
- lib/authorize_net/api/transaction.rb
|
156
|
-
- lib/authorize_net/arb/fields.rb
|
157
|
-
- lib/authorize_net/arb/paging.rb
|
158
|
-
- lib/authorize_net/arb/response.rb
|
159
|
-
- lib/authorize_net/arb/sorting.rb
|
160
|
-
- lib/authorize_net/arb/subscription.rb
|
161
|
-
- lib/authorize_net/arb/subscription_detail.rb
|
162
|
-
- lib/authorize_net/arb/subscription_list_response.rb
|
163
|
-
- lib/authorize_net/arb/transaction.rb
|
164
152
|
- lib/authorize_net/authorize_net.rb
|
165
|
-
- lib/authorize_net/cim/customer_profile.rb
|
166
|
-
- lib/authorize_net/cim/payment_profile.rb
|
167
|
-
- lib/authorize_net/cim/response.rb
|
168
|
-
- lib/authorize_net/cim/transaction.rb
|
169
|
-
- lib/authorize_net/customer.rb
|
170
|
-
- lib/authorize_net/email_receipt.rb
|
171
|
-
- lib/authorize_net/fields.rb
|
172
|
-
- lib/authorize_net/key_value_response.rb
|
173
|
-
- lib/authorize_net/key_value_transaction.rb
|
174
|
-
- lib/authorize_net/line_item.rb
|
175
|
-
- lib/authorize_net/order.rb
|
176
|
-
- lib/authorize_net/payment_methods/credit_card.rb
|
177
|
-
- lib/authorize_net/payment_methods/echeck.rb
|
178
|
-
- lib/authorize_net/reporting/batch.rb
|
179
|
-
- lib/authorize_net/reporting/batch_statistics.rb
|
180
|
-
- lib/authorize_net/reporting/fds_filter.rb
|
181
|
-
- lib/authorize_net/reporting/response.rb
|
182
|
-
- lib/authorize_net/reporting/returned_item.rb
|
183
|
-
- lib/authorize_net/reporting/transaction.rb
|
184
|
-
- lib/authorize_net/reporting/transaction_details.rb
|
185
153
|
- lib/authorize_net/response.rb
|
186
|
-
- lib/authorize_net/sim/hosted_payment_form.rb
|
187
|
-
- lib/authorize_net/sim/hosted_receipt_page.rb
|
188
|
-
- lib/authorize_net/sim/response.rb
|
189
|
-
- lib/authorize_net/sim/transaction.rb
|
190
154
|
- lib/authorize_net/transaction.rb
|
191
155
|
- lib/authorize_net/xml_response.rb
|
192
156
|
- lib/authorize_net/xml_transaction.rb
|
193
157
|
- lib/authorizenet.rb
|
194
|
-
- lib/generators/authorize_net/direct_post/direct_post_generator.rb
|
195
|
-
- lib/generators/authorize_net/direct_post/templates/README-AuthorizeNet
|
196
|
-
- lib/generators/authorize_net/direct_post/templates/config.yml.erb
|
197
|
-
- lib/generators/authorize_net/direct_post/templates/config.yml.rails3.erb
|
198
|
-
- lib/generators/authorize_net/direct_post/templates/controller.rb.erb
|
199
|
-
- lib/generators/authorize_net/direct_post/templates/initializer.rb
|
200
|
-
- lib/generators/authorize_net/direct_post/templates/layout.erb
|
201
|
-
- lib/generators/authorize_net/direct_post/templates/payment.erb
|
202
|
-
- lib/generators/authorize_net/direct_post/templates/payment.rails3.erb
|
203
|
-
- lib/generators/authorize_net/direct_post/templates/receipt.erb
|
204
|
-
- lib/generators/authorize_net/direct_post/templates/relay_response.erb
|
205
|
-
- lib/generators/authorize_net/sim/sim_generator.rb
|
206
|
-
- lib/generators/authorize_net/sim/templates/README-AuthorizeNet
|
207
|
-
- lib/generators/authorize_net/sim/templates/config.yml.erb
|
208
|
-
- lib/generators/authorize_net/sim/templates/config.yml.rails3.erb
|
209
|
-
- lib/generators/authorize_net/sim/templates/controller.rb.erb
|
210
|
-
- lib/generators/authorize_net/sim/templates/initializer.rb
|
211
|
-
- lib/generators/authorize_net/sim/templates/layout.erb
|
212
|
-
- lib/generators/authorize_net/sim/templates/payment.erb
|
213
|
-
- lib/generators/authorize_net/sim/templates/payment.rails3.erb
|
214
|
-
- lib/generators/authorize_net/sim/templates/thank_you.erb
|
215
|
-
- lib/generators/generator_extensions.rb
|
216
158
|
homepage: https://github.com/AuthorizeNet/sdk-ruby
|
217
159
|
licenses:
|
218
160
|
- https://github.com/AuthorizeNet/sdk-ruby/blob/master/LICENSE.txt
|
@@ -233,7 +175,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
233
175
|
version: 1.3.6
|
234
176
|
requirements: []
|
235
177
|
rubyforge_project:
|
236
|
-
rubygems_version: 2.
|
178
|
+
rubygems_version: 2.5.2.3
|
237
179
|
signing_key:
|
238
180
|
specification_version: 4
|
239
181
|
summary: Authorize.Net Payments SDK
|
@@ -1,25 +0,0 @@
|
|
1
|
-
module AuthorizeNet
|
2
|
-
# Models an address.
|
3
|
-
class Address
|
4
|
-
include AuthorizeNet::Model
|
5
|
-
|
6
|
-
attr_accessor :first_name, :last_name, :company, :street_address, :city, :state, :zip, :country, :phone, :fax, :customer_address_id
|
7
|
-
|
8
|
-
def to_hash
|
9
|
-
hash = {
|
10
|
-
first_name: @first_name,
|
11
|
-
last_name: @last_name,
|
12
|
-
company: @company,
|
13
|
-
address: @street_address,
|
14
|
-
city: @city,
|
15
|
-
state: @state,
|
16
|
-
zip: @zip,
|
17
|
-
country: @country,
|
18
|
-
phone: @phone,
|
19
|
-
fax: @fax,
|
20
|
-
customer_address_id: @customer_address_id
|
21
|
-
}
|
22
|
-
hash.delete_if { |_k, v| v.nil? }
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
module AuthorizeNet
|
2
|
-
# Models a shipping address.
|
3
|
-
class ShippingAddress < Address
|
4
|
-
include AuthorizeNet::Model
|
5
|
-
|
6
|
-
def to_hash
|
7
|
-
hash = {
|
8
|
-
ship_to_first_name: @first_name,
|
9
|
-
ship_to_last_name: @last_name,
|
10
|
-
ship_to_company: @company,
|
11
|
-
ship_to_address: @street_address,
|
12
|
-
ship_to_city: @city,
|
13
|
-
ship_to_state: @state,
|
14
|
-
ship_to_zip: @zip,
|
15
|
-
ship_to_country: @country,
|
16
|
-
ship_to_phone: @phone,
|
17
|
-
ship_to_fax: @fax
|
18
|
-
}
|
19
|
-
hash.delete_if { |_k, v| v.nil? }
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
@@ -1,120 +0,0 @@
|
|
1
|
-
module AuthorizeNet::AIM
|
2
|
-
# The AIM response class. Handles parsing the response from the gateway.
|
3
|
-
class Response < AuthorizeNet::KeyValueResponse
|
4
|
-
# Our MD5 digest generator.
|
5
|
-
@@digest = OpenSSL::Digest.new('md5')
|
6
|
-
|
7
|
-
include AuthorizeNet::AIM::Fields
|
8
|
-
|
9
|
-
# Fields to convert to/from booleans.
|
10
|
-
@@boolean_fields = [:tax_exempt]
|
11
|
-
|
12
|
-
# Fields to convert to/from BigDecimal.
|
13
|
-
@@decimal_fields = %i[amount tax freight duty requested balance_on_card]
|
14
|
-
|
15
|
-
# Constructs a new response object from a +raw_response+ and the +transaction+ that generated
|
16
|
-
# the +raw_response+. You don't typically construct this object yourself, as AuthorizeNet::AIM::Transaction
|
17
|
-
# will build one for you when it makes the request to the gateway.
|
18
|
-
def initialize(raw_response, transaction)
|
19
|
-
@version = transaction.version
|
20
|
-
raise "AuthorizeNet gem only supports AIM version 3.1" unless @version.to_s == '3.1'
|
21
|
-
@raw_response = raw_response
|
22
|
-
@fields = {}
|
23
|
-
@transaction = transaction
|
24
|
-
custom_field_names = transaction.custom_fields.keys.collect(&:to_s).sort.collect(&:to_sym)
|
25
|
-
@custom_fields = {}
|
26
|
-
split_on = transaction.delimiter
|
27
|
-
if @raw_response.is_a?(Net::HTTPOK) || @raw_response.is_a?(Nokogiri::XML::Element)
|
28
|
-
if @raw_response.is_a?(Net::HTTPOK)
|
29
|
-
raw_data = @raw_response.body
|
30
|
-
else
|
31
|
-
raw_data = @raw_response.text
|
32
|
-
end
|
33
|
-
unless transaction.encapsulation_character.nil?
|
34
|
-
split_on = transaction.encapsulation_character + split_on + transaction.encapsulation_character
|
35
|
-
raw_data = raw_data[1..raw_data.length - 2]
|
36
|
-
end
|
37
|
-
raw_data.split(split_on).each_with_index do |field, index|
|
38
|
-
if transaction.cp_version.nil?
|
39
|
-
field_desc = FIELDS
|
40
|
-
else
|
41
|
-
field_desc = CP_FIELDS
|
42
|
-
end
|
43
|
-
if index < field_desc.length
|
44
|
-
@fields[field_desc[index]] = field
|
45
|
-
else
|
46
|
-
@custom_fields[custom_field_names[index - field_desc.length]] = field
|
47
|
-
end
|
48
|
-
end
|
49
|
-
@fields.delete(nil)
|
50
|
-
@fields.each do |k, v|
|
51
|
-
if @@boolean_fields.include?(k)
|
52
|
-
@fields[k] = value_to_boolean(v)
|
53
|
-
elsif @@decimal_fields.include?(k)
|
54
|
-
@fields[k] = value_to_decimal(v)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
# Returns True if the MD5 hash found in the response payload validates using
|
61
|
-
# the supplied api_login and secret merchant_value (THIS IS NOT YOUR API KEY).
|
62
|
-
def valid_md5?(api_login, merchant_value)
|
63
|
-
return false if @fields[:md5_hash].nil?
|
64
|
-
@@digest.hexdigest("#{merchant_value}#{api_login}#{@fields[:transaction_id]}#{@transaction.fields[:amount]}").casecmp(@fields[:md5_hash]).zero?
|
65
|
-
end
|
66
|
-
|
67
|
-
# Returns the current API version that we are adhering to.
|
68
|
-
attr_reader :version
|
69
|
-
|
70
|
-
# Check to see if the response indicated success. Success is defined as a 200 OK response indicating
|
71
|
-
# that the transaction was approved.
|
72
|
-
def success?
|
73
|
-
!connection_failure? && approved?
|
74
|
-
end
|
75
|
-
|
76
|
-
# Returns true if we failed to open a connection to the gateway or got back a non-200 OK HTTP response.
|
77
|
-
def connection_failure?
|
78
|
-
!@raw_response.is_a?(Net::HTTPOK) && !@raw_response.is_a?(Nokogiri::XML::Element)
|
79
|
-
end
|
80
|
-
|
81
|
-
# Returns the underlying Net::HTTPResponse object. This has the original response body along with
|
82
|
-
# headers and such. Note that if an exception is generated while making the request (which happens
|
83
|
-
# if there is no internet connection for example), you will get the exception object here instead of
|
84
|
-
# a Net::HTTPResponse object.
|
85
|
-
def raw
|
86
|
-
@raw_response
|
87
|
-
end
|
88
|
-
|
89
|
-
# Returns the AuthorizeNet::Transaction instance that owns this response.
|
90
|
-
attr_reader :transaction
|
91
|
-
|
92
|
-
# Returns the transaction's authorization code. This should be shown to the
|
93
|
-
# end user.
|
94
|
-
def authorization_code
|
95
|
-
@fields[:authorization_code]
|
96
|
-
end
|
97
|
-
|
98
|
-
# Returns the transaction's authorization id. You will need this for future void, refund
|
99
|
-
# and prior authorization capture requests.
|
100
|
-
def transaction_id
|
101
|
-
@fields[:transaction_id]
|
102
|
-
end
|
103
|
-
|
104
|
-
# Returns the customer id from the response.
|
105
|
-
def customer_id
|
106
|
-
@fields[:customer_id]
|
107
|
-
end
|
108
|
-
|
109
|
-
# Returns a response code (from AVSResponseCode) indicating the result of any Address Verification
|
110
|
-
# Service checks.
|
111
|
-
def avs_response
|
112
|
-
@fields[:avs_response]
|
113
|
-
end
|
114
|
-
|
115
|
-
# Returns the credit card type used in the transaction. The values returned can be found in CardType.
|
116
|
-
def card_type
|
117
|
-
@fields[:card_type]
|
118
|
-
end
|
119
|
-
end
|
120
|
-
end
|
@@ -1,171 +0,0 @@
|
|
1
|
-
module AuthorizeNet::AIM
|
2
|
-
# The AIM transaction class. Handles building the transaction payload and
|
3
|
-
# transmitting it to the gateway.
|
4
|
-
class Transaction < AuthorizeNet::KeyValueTransaction
|
5
|
-
# The default options for the constructor.
|
6
|
-
@@option_defaults = {
|
7
|
-
transaction_type: Type::AUTHORIZE_AND_CAPTURE,
|
8
|
-
gateway: :production,
|
9
|
-
test: false,
|
10
|
-
allow_split: false,
|
11
|
-
delimiter: ',',
|
12
|
-
encapsulation_character: nil,
|
13
|
-
verify_ssl: true,
|
14
|
-
device_type: DeviceType::UNKNOWN,
|
15
|
-
market_type: MarketType::RETAIL
|
16
|
-
}
|
17
|
-
|
18
|
-
# Fields to convert to/from booleans.
|
19
|
-
@@boolean_fields = %i[tax_exempt test_request recurring_billing allow_partial_auth delim_data email_customer relay_response]
|
20
|
-
|
21
|
-
# Fields to convert to/from BigDecimal.
|
22
|
-
@@decimal_fields = [:amount]
|
23
|
-
|
24
|
-
# Constructs an AIM transaction. You can use the new AIM transaction object
|
25
|
-
# to issue a request to the payment gateway and parse the response into a new
|
26
|
-
# AuthorizeNet::AIM::Response object.
|
27
|
-
#
|
28
|
-
# +api_login_id+:: Your API login ID, as a string.
|
29
|
-
# +api_transaction_key+:: Your API transaction key, as a string.
|
30
|
-
# +options+:: A hash of options. See below for values.
|
31
|
-
#
|
32
|
-
# Options
|
33
|
-
# +transaction_type+:: The type of transaction to perform. Defaults to AuthorizeNet::Type::AUTHORIZE_AND_CAPTURE. This value is only used if run is called directly.
|
34
|
-
# +gateway+:: The gateway to submit the transaction to. Can be a URL string, an AuthorizeNet::AIM::Transaction::Gateway constant, or one of the convenience symbols :sandbox, :test, :card_present_test, :card_present_live, :card_present_sandbox, :card_present_production, :production, or :live (:test is an alias for :sandbox, :card_present_test is an alias for :card_present_sandbox, :card_present_production is an alias for :card_present_live, and :live is an alias for :production).
|
35
|
-
# +test+:: A boolean indicating if the transaction should be run in test mode or not (defaults to false).
|
36
|
-
# +allow_split+:: A boolean indicating if split transactions should be allowed (defaults to false).
|
37
|
-
# +delimiter+:: A single character (as a string) that will be used to delimit the response from the gateway. Defaults to ','.
|
38
|
-
# +encapsulation_character+:: A single character (as a string) that will be used to encapsulate each field in the response from the gateway. Defaults to nil.
|
39
|
-
# +verify_ssl+:: A boolean indicating if the SSL certificate of the +gateway+ should be verified. Defaults to true.
|
40
|
-
# +device_type+:: A constant from DeviceType indicating the type of POS device used in a card present transaction. Defaults to DeviceType::UNKNOWN.
|
41
|
-
# +market_type+:: A constant from MarketType indicating your industry. Used for card present transactions. Defaults to MarketType::RETAIL.
|
42
|
-
#
|
43
|
-
def initialize(api_login_id, api_transaction_key, options = {})
|
44
|
-
ActiveSupport::Deprecation.warn "use AuthorizeNet::API::Transaction"
|
45
|
-
super()
|
46
|
-
options = @@option_defaults.merge(options)
|
47
|
-
@api_login_id = api_login_id
|
48
|
-
@api_transaction_key = api_transaction_key
|
49
|
-
@test_mode = options[:test]
|
50
|
-
@response ||= nil
|
51
|
-
@delimiter = options[:delimiter]
|
52
|
-
@type = options[:transaction_type]
|
53
|
-
@cp_version = nil
|
54
|
-
case options[:gateway]
|
55
|
-
when :sandbox, :test
|
56
|
-
@gateway = Gateway::TEST
|
57
|
-
when :production, :live
|
58
|
-
@gateway = Gateway::LIVE
|
59
|
-
when :card_present_live, :card_present_production
|
60
|
-
@gateway = Gateway::CARD_PRESENT_LIVE
|
61
|
-
@cp_version = '1.0'
|
62
|
-
when :card_present_test, :card_present_sandbox
|
63
|
-
@gateway = Gateway::CARD_PRESENT_TEST
|
64
|
-
@cp_version = '1.0'
|
65
|
-
else
|
66
|
-
@gateway = options[:gateway]
|
67
|
-
end
|
68
|
-
@allow_split_transaction = options[:allow_split]
|
69
|
-
@encapsulation_character = options[:encapsulation_character]
|
70
|
-
@verify_ssl = options[:verify_ssl]
|
71
|
-
@market_type = options[:market_type]
|
72
|
-
@device_type = options[:device_type]
|
73
|
-
@solution_id = options[:solution_id]
|
74
|
-
end
|
75
|
-
|
76
|
-
# Checks if the transaction has been configured for test mode or not. Return TRUE if the
|
77
|
-
# transaction is a test transaction, FALSE otherwise. All transactions run against the sandbox
|
78
|
-
# are considered test transactions.
|
79
|
-
def test?
|
80
|
-
super || @gateway == Gateway::TEST
|
81
|
-
end
|
82
|
-
|
83
|
-
# Returns TRUE if split transactions are allowed, FALSE otherwise.
|
84
|
-
def split_transaction_allowed?
|
85
|
-
!!@allow_split_transaction
|
86
|
-
end
|
87
|
-
|
88
|
-
# Returns the current encapsulation character unless there is none, in which case Nil is returned.
|
89
|
-
attr_reader :encapsulation_character
|
90
|
-
|
91
|
-
# Returns the gateway to be used for this transaction.
|
92
|
-
attr_reader :gateway
|
93
|
-
|
94
|
-
# Checks to see if the transaction has a response (meaning it has been submitted to the gateway).
|
95
|
-
# Returns TRUE if a response is present, FALSE otherwise.
|
96
|
-
def has_response?
|
97
|
-
!@response.nil?
|
98
|
-
end
|
99
|
-
|
100
|
-
# Retrieve the response object (or Nil if transaction hasn't been sent to the gateway).
|
101
|
-
attr_reader :response
|
102
|
-
|
103
|
-
# Returns the current delimiter we are using to parse the fields returned by the
|
104
|
-
# gateway.
|
105
|
-
attr_reader :delimiter
|
106
|
-
|
107
|
-
# Sets the delimiter used to parse the response from the gateway.
|
108
|
-
attr_writer :delimiter
|
109
|
-
|
110
|
-
# Submits the transaction to the gateway for processing. Returns a response object. If the transaction
|
111
|
-
# has already been run, it will return nil.
|
112
|
-
def run
|
113
|
-
make_request
|
114
|
-
end
|
115
|
-
|
116
|
-
# Returns the current card present API version that we are adhering to.
|
117
|
-
attr_reader :cp_version
|
118
|
-
|
119
|
-
attr_reader :solution_id
|
120
|
-
|
121
|
-
#:enddoc:
|
122
|
-
protected
|
123
|
-
|
124
|
-
# An internal method that builds the POST body, submits it to the gateway, and constructs a Response object with the response.
|
125
|
-
def make_request
|
126
|
-
return nil if has_response?
|
127
|
-
url = URI.parse(@gateway)
|
128
|
-
fields = @fields.merge(type: @type, delim_char: @delimiter, delim_data: "TRUE", login: @api_login_id, tran_key: @api_transaction_key, relay_response: "FALSE")
|
129
|
-
|
130
|
-
if @cp_version.nil?
|
131
|
-
fields[:version] = @version
|
132
|
-
else
|
133
|
-
fields.merge!(cp_version: @cp_version, market_type: @market_type, device_type: @device_type, response_format: "1")
|
134
|
-
end
|
135
|
-
fields[:test_request] = boolean_to_value(@test_mode)
|
136
|
-
fields[:allow_partial_auth] = 'TRUE' if @allow_split_transaction
|
137
|
-
fields[:encap_char] = @encapsulation_character unless @encapsulation_character.nil?
|
138
|
-
fields[:solution_id] = @solution_id unless @solution_id.nil?
|
139
|
-
fields.each do |k, v|
|
140
|
-
if @@boolean_fields.include?(k)
|
141
|
-
fields[k] = boolean_to_value(v)
|
142
|
-
elsif @@decimal_fields.include?(k)
|
143
|
-
fields[k] = decimal_to_value(v)
|
144
|
-
end
|
145
|
-
end
|
146
|
-
data = fields.collect do |key, val|
|
147
|
-
to_param(key, val)
|
148
|
-
end
|
149
|
-
custom_field_keys = @custom_fields.keys.collect(&:to_s).sort.collect(&:to_sym)
|
150
|
-
for key in custom_field_keys
|
151
|
-
data += [to_param(key, @custom_fields[key.to_sym], '')]
|
152
|
-
end
|
153
|
-
data.flatten!
|
154
|
-
request = Net::HTTP::Post.new(url.path)
|
155
|
-
request.content_type = 'application/x-www-form-urlencoded'
|
156
|
-
request.body = data.join("&")
|
157
|
-
connection = Net::HTTP.new(url.host, url.port)
|
158
|
-
connection.use_ssl = true
|
159
|
-
if @verify_ssl
|
160
|
-
connection.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
161
|
-
else
|
162
|
-
connection.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
163
|
-
end
|
164
|
-
begin
|
165
|
-
@response = AuthorizeNet::AIM::Response.new((connection.start { |http| http.request(request) }), self)
|
166
|
-
rescue StandardError
|
167
|
-
@response = AuthorizeNet::AIM::Response.new($ERROR_INFO, self)
|
168
|
-
end
|
169
|
-
end
|
170
|
-
end
|
171
|
-
end
|