authorizenet 1.9.6 → 1.9.7
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 +107 -107
- data/lib/authorize_net/addresses/address.rb +25 -25
- data/lib/authorize_net/addresses/shipping_address.rb +22 -22
- data/lib/authorize_net/aim/response.rb +120 -120
- data/lib/authorize_net/aim/transaction.rb +171 -171
- 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 +129 -119
- data/lib/authorize_net/api/constants.yml +1 -1
- data/lib/authorize_net/api/schema.rb +5421 -5165
- data/lib/authorize_net/api/transaction.rb +265 -261
- data/lib/authorize_net/arb/fields.rb +24 -24
- data/lib/authorize_net/arb/paging.rb +29 -29
- data/lib/authorize_net/arb/response.rb +26 -26
- data/lib/authorize_net/arb/sorting.rb +39 -39
- data/lib/authorize_net/arb/subscription.rb +68 -68
- data/lib/authorize_net/arb/subscription_detail.rb +10 -10
- data/lib/authorize_net/arb/subscription_list_response.rb +36 -36
- data/lib/authorize_net/arb/transaction.rb +171 -171
- data/lib/authorize_net/authorize_net.rb +154 -154
- data/lib/authorize_net/cim/customer_profile.rb +15 -15
- data/lib/authorize_net/cim/payment_profile.rb +35 -35
- data/lib/authorize_net/cim/response.rb +111 -111
- data/lib/authorize_net/cim/transaction.rb +721 -721
- data/lib/authorize_net/customer.rb +24 -24
- data/lib/authorize_net/email_receipt.rb +20 -20
- data/lib/authorize_net/fields.rb +760 -760
- data/lib/authorize_net/key_value_response.rb +109 -109
- data/lib/authorize_net/key_value_transaction.rb +281 -281
- data/lib/authorize_net/line_item.rb +21 -21
- data/lib/authorize_net/order.rb +38 -38
- data/lib/authorize_net/payment_methods/credit_card.rb +61 -61
- data/lib/authorize_net/payment_methods/echeck.rb +70 -70
- data/lib/authorize_net/reporting/batch.rb +16 -16
- data/lib/authorize_net/reporting/batch_statistics.rb +15 -15
- data/lib/authorize_net/reporting/fds_filter.rb +8 -8
- data/lib/authorize_net/reporting/response.rb +157 -157
- data/lib/authorize_net/reporting/returned_item.rb +45 -45
- data/lib/authorize_net/reporting/transaction.rb +131 -131
- data/lib/authorize_net/reporting/transaction_details.rb +22 -22
- data/lib/authorize_net/response.rb +25 -25
- data/lib/authorize_net/sim/hosted_payment_form.rb +34 -34
- data/lib/authorize_net/sim/hosted_receipt_page.rb +32 -32
- data/lib/authorize_net/sim/response.rb +133 -133
- data/lib/authorize_net/sim/transaction.rb +128 -128
- data/lib/authorize_net/transaction.rb +66 -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
- data/lib/generators/authorize_net/direct_post/direct_post_generator.rb +52 -52
- 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 +46 -46
- 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 +73 -73
- metadata +5 -3
@@ -1,128 +1,128 @@
|
|
1
|
-
module AuthorizeNet::SIM
|
2
|
-
# The SIM transaction class. Handles building the transaction payload and
|
3
|
-
# generating a set of hidden form fields to be POSTed to the gateway.
|
4
|
-
class Transaction < AuthorizeNet::KeyValueTransaction
|
5
|
-
RANDOM_SEQUENCE_MAX = (1 << 32) - 1
|
6
|
-
|
7
|
-
# Our MD5 digest generator.
|
8
|
-
@@digest = OpenSSL::Digest.new('md5')
|
9
|
-
|
10
|
-
# The default options for the constructor.
|
11
|
-
@@option_defaults = {
|
12
|
-
sequence: nil,
|
13
|
-
timestamp: nil,
|
14
|
-
test: false,
|
15
|
-
hosted_payment_form: false,
|
16
|
-
relay_response: true,
|
17
|
-
relay_url: nil,
|
18
|
-
transaction_type: Type::AUTHORIZE_AND_CAPTURE
|
19
|
-
}
|
20
|
-
|
21
|
-
# Constructs a SIM transaction. You can use the new SIM transaction object
|
22
|
-
# to build the hidden field payload needed to process a SIM transaction with
|
23
|
-
# the gateway. In particular, this class handles generating the MD5 fingerprint
|
24
|
-
# used to authenticate transactions at the gateway. Since the fingerprint includes
|
25
|
-
# the amount to charge, you should not construct this object until you know EXACTLY
|
26
|
-
# how much you want to charge (or authorize).
|
27
|
-
#
|
28
|
-
# +api_login_id+:: Your API login ID, as a string.
|
29
|
-
# +api_transaction_key+:: Your API transaction key, as a string.
|
30
|
-
# +amount+:: The amount of the transaction, as a string, Float or BigDecimal.
|
31
|
-
# +options+:: A hash of options. See below for values.
|
32
|
-
#
|
33
|
-
# Options
|
34
|
-
# +sequence+:: The sequence number of the transaction as a string or Integer. This is usually something like an invoice number. If none is provided, the SDK generates one at random.
|
35
|
-
# +timestamp+:: The time the transaction was initiated as a string or Integer. This needs to be within 15 minutes of when the gateway receives the transaction. If no value is provided, the SDK defaults it to Time.now().
|
36
|
-
# +test+:: A boolean indicating if the transaction should be run in test mode or not (defaults to false).
|
37
|
-
# +hosted_payment_form+:: A boolean indicating if the transaction should use a hosted payment form (defaults to false).
|
38
|
-
# +relay_response+:: A boolean indicating if the transaction should use the relay response feature to return a receipt to the customer (defaults to true). Direct Post Method requires using a relay response.
|
39
|
-
# +relay_url+:: A string of the URL that the gateway should hit to get the relay response (defaults to nil).
|
40
|
-
# +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.
|
41
|
-
#
|
42
|
-
def initialize(api_login_id, api_transaction_key, amount, options = {})
|
43
|
-
ActiveSupport::Deprecation.warn "use AuthorizeNet::API::Transaction"
|
44
|
-
super()
|
45
|
-
@api_transaction_key = api_transaction_key
|
46
|
-
@api_login_id = api_login_id
|
47
|
-
@amount = decimal_to_value(amount)
|
48
|
-
options = @@option_defaults.merge(options)
|
49
|
-
@sequence = options[:sequence]
|
50
|
-
@timestamp = options[:timestamp]
|
51
|
-
@test_mode = options[:test]
|
52
|
-
@hosted_payment_form = options[:hosted_payment_form]
|
53
|
-
@relay_url = options[:relay_url]
|
54
|
-
@type = options[:transaction_type]
|
55
|
-
if @relay_url.nil?
|
56
|
-
@relay_response = !!options[:relay_response]
|
57
|
-
else
|
58
|
-
@relay_response = true
|
59
|
-
end
|
60
|
-
@delim_data = !@relay_response
|
61
|
-
end
|
62
|
-
|
63
|
-
# Calculates and returns the HMAC-MD5 fingerprint needed to authenticate the transaction
|
64
|
-
# with the SIM gateway.
|
65
|
-
def fingerprint
|
66
|
-
@timestamp = Time.now.to_i if @timestamp.nil?
|
67
|
-
|
68
|
-
@sequence = rand(RANDOM_SEQUENCE_MAX) if @sequence.nil?
|
69
|
-
OpenSSL::HMAC.hexdigest(@@digest, @api_transaction_key, "#{@api_login_id.to_s.rstrip}^#{@sequence.to_s.rstrip}^#{@timestamp.to_s.rstrip}^#{@amount.to_s.rstrip}^")
|
70
|
-
end
|
71
|
-
|
72
|
-
# Returns all the fields needed for the fingerprint. These must all be passed to the SIM
|
73
|
-
# exactly as returned. And these values are time sensitive.
|
74
|
-
def fingerprint_fields
|
75
|
-
{
|
76
|
-
login: @api_login_id,
|
77
|
-
fp_hash: fingerprint,
|
78
|
-
fp_sequence: @sequence,
|
79
|
-
fp_timestamp: @timestamp,
|
80
|
-
amount: @amount
|
81
|
-
}
|
82
|
-
end
|
83
|
-
|
84
|
-
# Returns all the fields (including custom) exactly as they should be named
|
85
|
-
# in the SIM form. Fields with multiple values are returned with an array
|
86
|
-
# for the key's value.
|
87
|
-
def form_fields
|
88
|
-
form_fields = {}
|
89
|
-
form_fields[:x_test_request] = boolean_to_value(@test_mode)
|
90
|
-
form_fields[:x_show_form] = 'PAYMENT_FORM' if @hosted_payment_form
|
91
|
-
if @relay_response && !@relay_url.nil?
|
92
|
-
form_fields[:x_relay_url] = @relay_url
|
93
|
-
end
|
94
|
-
fields.merge(type: @type, version: @version, delim_data: boolean_to_value(@delim_data), relay_response: boolean_to_value(@relay_response)).each do |k, v|
|
95
|
-
form_fields[to_external_field(k)] = v
|
96
|
-
end
|
97
|
-
fingerprint_fields.each do |k, v|
|
98
|
-
form_fields[to_external_field(k)] = v
|
99
|
-
end
|
100
|
-
form_fields.merge(custom_fields)
|
101
|
-
end
|
102
|
-
|
103
|
-
# Takes an instance of AuthorizeNet::SIM::HostedPaymentForm and adds it to the transaction. Note that
|
104
|
-
# many of the fields in AuthorizeNet::SIM::HostedPaymentForm are shared with those in
|
105
|
-
# AuthorizeNet::SIM::HostedReceiptPage. For the duplicate fields, which ever value
|
106
|
-
# is added to the transaction last will be the one used.
|
107
|
-
def set_hosted_payment_form(form)
|
108
|
-
@fields.merge!(form.to_hash)
|
109
|
-
@hosted_payment_form = true
|
110
|
-
end
|
111
|
-
|
112
|
-
# Takes an instance of AuthorizeNet::SIM::HostedReceiptPage and adds it to the transaction. Note that
|
113
|
-
# many of the fields in AuthorizeNet::SIM::HostedReceiptPage are shared with those in
|
114
|
-
# AuthorizeNet::SIM::HostedPaymentForm. For the duplicate fields, which ever value
|
115
|
-
# is added to the transaction last will be the one used. If you set a hosted payment receipt,
|
116
|
-
# the relay response will be disabled.
|
117
|
-
def set_hosted_payment_receipt(form)
|
118
|
-
@fields.merge!(form.to_hash)
|
119
|
-
@relay_response = false
|
120
|
-
@delim_data = true
|
121
|
-
end
|
122
|
-
|
123
|
-
# An alias for form_fields.
|
124
|
-
def run
|
125
|
-
form_fields
|
126
|
-
end
|
127
|
-
end
|
128
|
-
end
|
1
|
+
module AuthorizeNet::SIM
|
2
|
+
# The SIM transaction class. Handles building the transaction payload and
|
3
|
+
# generating a set of hidden form fields to be POSTed to the gateway.
|
4
|
+
class Transaction < AuthorizeNet::KeyValueTransaction
|
5
|
+
RANDOM_SEQUENCE_MAX = (1 << 32) - 1
|
6
|
+
|
7
|
+
# Our MD5 digest generator.
|
8
|
+
@@digest = OpenSSL::Digest.new('md5')
|
9
|
+
|
10
|
+
# The default options for the constructor.
|
11
|
+
@@option_defaults = {
|
12
|
+
sequence: nil,
|
13
|
+
timestamp: nil,
|
14
|
+
test: false,
|
15
|
+
hosted_payment_form: false,
|
16
|
+
relay_response: true,
|
17
|
+
relay_url: nil,
|
18
|
+
transaction_type: Type::AUTHORIZE_AND_CAPTURE
|
19
|
+
}
|
20
|
+
|
21
|
+
# Constructs a SIM transaction. You can use the new SIM transaction object
|
22
|
+
# to build the hidden field payload needed to process a SIM transaction with
|
23
|
+
# the gateway. In particular, this class handles generating the MD5 fingerprint
|
24
|
+
# used to authenticate transactions at the gateway. Since the fingerprint includes
|
25
|
+
# the amount to charge, you should not construct this object until you know EXACTLY
|
26
|
+
# how much you want to charge (or authorize).
|
27
|
+
#
|
28
|
+
# +api_login_id+:: Your API login ID, as a string.
|
29
|
+
# +api_transaction_key+:: Your API transaction key, as a string.
|
30
|
+
# +amount+:: The amount of the transaction, as a string, Float or BigDecimal.
|
31
|
+
# +options+:: A hash of options. See below for values.
|
32
|
+
#
|
33
|
+
# Options
|
34
|
+
# +sequence+:: The sequence number of the transaction as a string or Integer. This is usually something like an invoice number. If none is provided, the SDK generates one at random.
|
35
|
+
# +timestamp+:: The time the transaction was initiated as a string or Integer. This needs to be within 15 minutes of when the gateway receives the transaction. If no value is provided, the SDK defaults it to Time.now().
|
36
|
+
# +test+:: A boolean indicating if the transaction should be run in test mode or not (defaults to false).
|
37
|
+
# +hosted_payment_form+:: A boolean indicating if the transaction should use a hosted payment form (defaults to false).
|
38
|
+
# +relay_response+:: A boolean indicating if the transaction should use the relay response feature to return a receipt to the customer (defaults to true). Direct Post Method requires using a relay response.
|
39
|
+
# +relay_url+:: A string of the URL that the gateway should hit to get the relay response (defaults to nil).
|
40
|
+
# +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.
|
41
|
+
#
|
42
|
+
def initialize(api_login_id, api_transaction_key, amount, options = {})
|
43
|
+
ActiveSupport::Deprecation.warn "use AuthorizeNet::API::Transaction"
|
44
|
+
super()
|
45
|
+
@api_transaction_key = api_transaction_key
|
46
|
+
@api_login_id = api_login_id
|
47
|
+
@amount = decimal_to_value(amount)
|
48
|
+
options = @@option_defaults.merge(options)
|
49
|
+
@sequence = options[:sequence]
|
50
|
+
@timestamp = options[:timestamp]
|
51
|
+
@test_mode = options[:test]
|
52
|
+
@hosted_payment_form = options[:hosted_payment_form]
|
53
|
+
@relay_url = options[:relay_url]
|
54
|
+
@type = options[:transaction_type]
|
55
|
+
if @relay_url.nil?
|
56
|
+
@relay_response = !!options[:relay_response]
|
57
|
+
else
|
58
|
+
@relay_response = true
|
59
|
+
end
|
60
|
+
@delim_data = !@relay_response
|
61
|
+
end
|
62
|
+
|
63
|
+
# Calculates and returns the HMAC-MD5 fingerprint needed to authenticate the transaction
|
64
|
+
# with the SIM gateway.
|
65
|
+
def fingerprint
|
66
|
+
@timestamp = Time.now.to_i if @timestamp.nil?
|
67
|
+
|
68
|
+
@sequence = rand(RANDOM_SEQUENCE_MAX) if @sequence.nil?
|
69
|
+
OpenSSL::HMAC.hexdigest(@@digest, @api_transaction_key, "#{@api_login_id.to_s.rstrip}^#{@sequence.to_s.rstrip}^#{@timestamp.to_s.rstrip}^#{@amount.to_s.rstrip}^")
|
70
|
+
end
|
71
|
+
|
72
|
+
# Returns all the fields needed for the fingerprint. These must all be passed to the SIM
|
73
|
+
# exactly as returned. And these values are time sensitive.
|
74
|
+
def fingerprint_fields
|
75
|
+
{
|
76
|
+
login: @api_login_id,
|
77
|
+
fp_hash: fingerprint,
|
78
|
+
fp_sequence: @sequence,
|
79
|
+
fp_timestamp: @timestamp,
|
80
|
+
amount: @amount
|
81
|
+
}
|
82
|
+
end
|
83
|
+
|
84
|
+
# Returns all the fields (including custom) exactly as they should be named
|
85
|
+
# in the SIM form. Fields with multiple values are returned with an array
|
86
|
+
# for the key's value.
|
87
|
+
def form_fields
|
88
|
+
form_fields = {}
|
89
|
+
form_fields[:x_test_request] = boolean_to_value(@test_mode)
|
90
|
+
form_fields[:x_show_form] = 'PAYMENT_FORM' if @hosted_payment_form
|
91
|
+
if @relay_response && !@relay_url.nil?
|
92
|
+
form_fields[:x_relay_url] = @relay_url
|
93
|
+
end
|
94
|
+
fields.merge(type: @type, version: @version, delim_data: boolean_to_value(@delim_data), relay_response: boolean_to_value(@relay_response)).each do |k, v|
|
95
|
+
form_fields[to_external_field(k)] = v
|
96
|
+
end
|
97
|
+
fingerprint_fields.each do |k, v|
|
98
|
+
form_fields[to_external_field(k)] = v
|
99
|
+
end
|
100
|
+
form_fields.merge(custom_fields)
|
101
|
+
end
|
102
|
+
|
103
|
+
# Takes an instance of AuthorizeNet::SIM::HostedPaymentForm and adds it to the transaction. Note that
|
104
|
+
# many of the fields in AuthorizeNet::SIM::HostedPaymentForm are shared with those in
|
105
|
+
# AuthorizeNet::SIM::HostedReceiptPage. For the duplicate fields, which ever value
|
106
|
+
# is added to the transaction last will be the one used.
|
107
|
+
def set_hosted_payment_form(form)
|
108
|
+
@fields.merge!(form.to_hash)
|
109
|
+
@hosted_payment_form = true
|
110
|
+
end
|
111
|
+
|
112
|
+
# Takes an instance of AuthorizeNet::SIM::HostedReceiptPage and adds it to the transaction. Note that
|
113
|
+
# many of the fields in AuthorizeNet::SIM::HostedReceiptPage are shared with those in
|
114
|
+
# AuthorizeNet::SIM::HostedPaymentForm. For the duplicate fields, which ever value
|
115
|
+
# is added to the transaction last will be the one used. If you set a hosted payment receipt,
|
116
|
+
# the relay response will be disabled.
|
117
|
+
def set_hosted_payment_receipt(form)
|
118
|
+
@fields.merge!(form.to_hash)
|
119
|
+
@relay_response = false
|
120
|
+
@delim_data = true
|
121
|
+
end
|
122
|
+
|
123
|
+
# An alias for form_fields.
|
124
|
+
def run
|
125
|
+
form_fields
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
@@ -1,66 +1,66 @@
|
|
1
|
-
module AuthorizeNet
|
2
|
-
# The core, API agnostic transaction class. You shouldn't instantiate this one.
|
3
|
-
# Instead you should use AuthorizeNet::AIM::Transaction,
|
4
|
-
# AuthorizeNet::SIM::Transaction or AuthorizeNet::ARB::Transaction.
|
5
|
-
class Transaction
|
6
|
-
include AuthorizeNet::TypeConversions
|
7
|
-
|
8
|
-
# Fields to convert to/from booleans.
|
9
|
-
@@boolean_fields = []
|
10
|
-
|
11
|
-
# Fields to convert to/from BigDecimal.
|
12
|
-
@@decimal_fields = []
|
13
|
-
|
14
|
-
# DO NOT USE. Instantiate AuthorizeNet::AIM::Transaction,
|
15
|
-
# AuthorizeNet::SIM::Transaction or AuthorizeNet::ARB::Transaction instead.
|
16
|
-
def initialize
|
17
|
-
@fields ||= {}
|
18
|
-
end
|
19
|
-
|
20
|
-
# Sets arbitrary API fields, overwriting existing values if they exist.
|
21
|
-
# Takes a hash of key/value pairs, where the keys are the field names
|
22
|
-
# without the "x_" prefix. You can set a field to Nil to unset it. If the
|
23
|
-
# value is an array, each value in the array will be added. For example,
|
24
|
-
# set_fields({:line_item => ["item1<|>golf balls<|><|>2<|>18.95<|>Y",
|
25
|
-
# "item2<|>golf bag<|>Wilson golf carry bag, red<|>1<|>39.99<|>"]})
|
26
|
-
# would generate two x_line_item fields in the transaction, one for
|
27
|
-
# each value in the array.
|
28
|
-
def set_fields(fields = {})
|
29
|
-
@fields.merge!(fields)
|
30
|
-
@fields.reject! { |_k, v| v.nil? }
|
31
|
-
@fields
|
32
|
-
end
|
33
|
-
|
34
|
-
# Returns the current hash of API fields.
|
35
|
-
attr_reader :fields
|
36
|
-
|
37
|
-
# Takes an instance of AuthorizeNet::Address and adds it to the transaction.
|
38
|
-
def set_address(address)
|
39
|
-
@fields.merge!(address.to_hash)
|
40
|
-
end
|
41
|
-
|
42
|
-
# Takes an instance of AuthorizeNet::ShippingAddress and adds it to the
|
43
|
-
# transaction.
|
44
|
-
def set_shipping_address(address)
|
45
|
-
@fields.merge!(address.to_hash)
|
46
|
-
end
|
47
|
-
|
48
|
-
# Takes an instance of AuthorizeNet::Customer and adds it to the transaction.
|
49
|
-
def set_customer(customer)
|
50
|
-
@fields.merge!(customer.to_hash)
|
51
|
-
end
|
52
|
-
|
53
|
-
#:enddoc:
|
54
|
-
protected
|
55
|
-
|
56
|
-
# Internal method to handle multiple types of payment arguments.
|
57
|
-
def handle_payment_argument(payment)
|
58
|
-
case payment
|
59
|
-
when AuthorizeNet::CreditCard, AuthorizeNet::ECheck
|
60
|
-
set_fields(payment.to_hash)
|
61
|
-
else
|
62
|
-
set_fields(card_num: payment)
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
1
|
+
module AuthorizeNet
|
2
|
+
# The core, API agnostic transaction class. You shouldn't instantiate this one.
|
3
|
+
# Instead you should use AuthorizeNet::AIM::Transaction,
|
4
|
+
# AuthorizeNet::SIM::Transaction or AuthorizeNet::ARB::Transaction.
|
5
|
+
class Transaction
|
6
|
+
include AuthorizeNet::TypeConversions
|
7
|
+
|
8
|
+
# Fields to convert to/from booleans.
|
9
|
+
@@boolean_fields = []
|
10
|
+
|
11
|
+
# Fields to convert to/from BigDecimal.
|
12
|
+
@@decimal_fields = []
|
13
|
+
|
14
|
+
# DO NOT USE. Instantiate AuthorizeNet::AIM::Transaction,
|
15
|
+
# AuthorizeNet::SIM::Transaction or AuthorizeNet::ARB::Transaction instead.
|
16
|
+
def initialize
|
17
|
+
@fields ||= {}
|
18
|
+
end
|
19
|
+
|
20
|
+
# Sets arbitrary API fields, overwriting existing values if they exist.
|
21
|
+
# Takes a hash of key/value pairs, where the keys are the field names
|
22
|
+
# without the "x_" prefix. You can set a field to Nil to unset it. If the
|
23
|
+
# value is an array, each value in the array will be added. For example,
|
24
|
+
# set_fields({:line_item => ["item1<|>golf balls<|><|>2<|>18.95<|>Y",
|
25
|
+
# "item2<|>golf bag<|>Wilson golf carry bag, red<|>1<|>39.99<|>"]})
|
26
|
+
# would generate two x_line_item fields in the transaction, one for
|
27
|
+
# each value in the array.
|
28
|
+
def set_fields(fields = {})
|
29
|
+
@fields.merge!(fields)
|
30
|
+
@fields.reject! { |_k, v| v.nil? }
|
31
|
+
@fields
|
32
|
+
end
|
33
|
+
|
34
|
+
# Returns the current hash of API fields.
|
35
|
+
attr_reader :fields
|
36
|
+
|
37
|
+
# Takes an instance of AuthorizeNet::Address and adds it to the transaction.
|
38
|
+
def set_address(address)
|
39
|
+
@fields.merge!(address.to_hash)
|
40
|
+
end
|
41
|
+
|
42
|
+
# Takes an instance of AuthorizeNet::ShippingAddress and adds it to the
|
43
|
+
# transaction.
|
44
|
+
def set_shipping_address(address)
|
45
|
+
@fields.merge!(address.to_hash)
|
46
|
+
end
|
47
|
+
|
48
|
+
# Takes an instance of AuthorizeNet::Customer and adds it to the transaction.
|
49
|
+
def set_customer(customer)
|
50
|
+
@fields.merge!(customer.to_hash)
|
51
|
+
end
|
52
|
+
|
53
|
+
#:enddoc:
|
54
|
+
protected
|
55
|
+
|
56
|
+
# Internal method to handle multiple types of payment arguments.
|
57
|
+
def handle_payment_argument(payment)
|
58
|
+
case payment
|
59
|
+
when AuthorizeNet::CreditCard, AuthorizeNet::ECheck
|
60
|
+
set_fields(payment.to_hash)
|
61
|
+
else
|
62
|
+
set_fields(card_num: payment)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -1,154 +1,154 @@
|
|
1
|
-
module AuthorizeNet
|
2
|
-
# The core, xml response class. You shouldn't instantiate this one.
|
3
|
-
# Instead you should use AuthorizeNet::ARB::Response.
|
4
|
-
class XmlResponse < AuthorizeNet::Response
|
5
|
-
# DO NOT USE. Instantiate AuthorizeNet::ARB::Response or AuthorizeNet::CIM::Response instead.
|
6
|
-
def initialize(raw_response, transaction)
|
7
|
-
@raw_response = raw_response
|
8
|
-
@transaction = transaction
|
9
|
-
unless connection_failure?
|
10
|
-
begin
|
11
|
-
xml = Nokogiri::XML(@raw_response.body) do |config|
|
12
|
-
# confirm noent is the right flag
|
13
|
-
config.recover.noent.nonet
|
14
|
-
end
|
15
|
-
@root = xml.children[0]
|
16
|
-
@result_code = node_content_unless_nil(@root.at_css('messages resultCode'))
|
17
|
-
@message_code = node_content_unless_nil(@root.at_css('messages message code'))
|
18
|
-
@message_text = node_content_unless_nil(@root.at_css('messages message text'))
|
19
|
-
@reference_id = node_content_unless_nil(@root.at_css('refId'))
|
20
|
-
rescue StandardError
|
21
|
-
@raw_response = $ERROR_INFO
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
# Check to see if the response indicated success. Success is defined as a 200 OK response with a resultCode
|
27
|
-
# of 'Ok'.
|
28
|
-
def success?
|
29
|
-
!connection_failure? && @result_code == 'Ok'
|
30
|
-
end
|
31
|
-
|
32
|
-
# Returns true if we failed to open a connection to the gateway or got back a non-200 OK HTTP response.
|
33
|
-
def connection_failure?
|
34
|
-
!@raw_response.is_a?(Net::HTTPOK)
|
35
|
-
end
|
36
|
-
|
37
|
-
# Returns the underlying Net::HTTPResponse object. This has the original response body along with
|
38
|
-
# headers and such. Note that if an exception is generated while making the request (which happens
|
39
|
-
# if there is no internet connection for example), you will get the exception object here instead of
|
40
|
-
# a Net::HTTPResponse object.
|
41
|
-
def raw
|
42
|
-
@raw_response
|
43
|
-
end
|
44
|
-
|
45
|
-
# Returns a deep-copy of the XML object received from the payment gateway. Or nil if there was no XML payload.
|
46
|
-
def xml
|
47
|
-
@root.dup unless @root.nil?
|
48
|
-
end
|
49
|
-
|
50
|
-
# Returns the resultCode from the XML response. resultCode will be either 'Ok' or 'Error'.
|
51
|
-
attr_reader :result_code
|
52
|
-
|
53
|
-
# Returns the messageCode from the XML response. This is a code indicating the details of an error
|
54
|
-
# or success.
|
55
|
-
attr_reader :message_code
|
56
|
-
|
57
|
-
# Returns the messageText from the XML response. This is a text description of the message_code.
|
58
|
-
attr_reader :message_text
|
59
|
-
|
60
|
-
# Alias for result_code.
|
61
|
-
def response_code
|
62
|
-
result_code
|
63
|
-
end
|
64
|
-
|
65
|
-
# Alias for message_code.
|
66
|
-
def response_reason_code
|
67
|
-
message_code
|
68
|
-
end
|
69
|
-
|
70
|
-
# Alias for message_text.
|
71
|
-
def response_reason_text
|
72
|
-
message_text
|
73
|
-
end
|
74
|
-
|
75
|
-
# Returns the refId from the response if there is one. Otherwise returns nil.
|
76
|
-
attr_reader :reference_id
|
77
|
-
|
78
|
-
#:enddoc:
|
79
|
-
protected
|
80
|
-
|
81
|
-
def node_content_unless_nil(node)
|
82
|
-
if node.nil?
|
83
|
-
nil
|
84
|
-
else
|
85
|
-
node.content
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
def node_child_content_unless_nil(node)
|
90
|
-
if node.nil?
|
91
|
-
nil
|
92
|
-
else
|
93
|
-
node.children.collect(&:content) unless node.children.empty?
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
# Transforms a block of XML into a model Object defined by entity_desc.
|
98
|
-
def build_entity(xml, entity_desc)
|
99
|
-
args = {}
|
100
|
-
entity_desc.node_structure.each do |node_desc|
|
101
|
-
node_name = (node_desc.keys.reject { |k| k.to_s[0..0] == '_' }).first
|
102
|
-
args.merge!(handle_node_type(xml, node_desc, node_name, args, ''))
|
103
|
-
end
|
104
|
-
|
105
|
-
return nil if args.empty?
|
106
|
-
|
107
|
-
if entity_desc.arg_mapping.nil?
|
108
|
-
return entity_desc.entity_class.new(args)
|
109
|
-
else
|
110
|
-
args_list = []
|
111
|
-
entity_desc.arg_mapping.each do |arg|
|
112
|
-
args_list <<= args[arg]
|
113
|
-
args.delete(arg)
|
114
|
-
end
|
115
|
-
args_list <<= args
|
116
|
-
return entity_desc.entity_class.new(*args_list)
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
# Parses an XML fragment into an internal representation.
|
121
|
-
def handle_node_type(xml, node_desc, node_name, args, base_name)
|
122
|
-
case node_desc[node_name]
|
123
|
-
when Symbol
|
124
|
-
node = xml.at_css(base_name + node_name.to_s)
|
125
|
-
unless node.nil?
|
126
|
-
content = node.content
|
127
|
-
case node_desc[:_converter]
|
128
|
-
when Method, Proc
|
129
|
-
content = node_desc[:_converter].call(content)
|
130
|
-
when Symbol
|
131
|
-
content = send(node_desc[:_converter], content)
|
132
|
-
end
|
133
|
-
args[node_desc[node_name]] = content unless content.nil?
|
134
|
-
end
|
135
|
-
when AuthorizeNet::EntityDescription
|
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
|
140
|
-
xml.css(base_name + node_name.to_s).each do |node|
|
141
|
-
entity = build_entity(node, node_desc[node_name])
|
142
|
-
args[node_desc[:_multivalue]] = args[node_desc[:_multivalue]].to_a + entity.to_a unless entity.nil?
|
143
|
-
end
|
144
|
-
end
|
145
|
-
when Array
|
146
|
-
node_desc[node_name].each do |inner_node|
|
147
|
-
inner_node_name = (inner_node.keys.reject { |k| k.to_s[0..0] == '_' }).first
|
148
|
-
args.merge!(handle_node_type(xml, inner_node, inner_node_name, args, node_name.to_s + ' '))
|
149
|
-
end
|
150
|
-
end
|
151
|
-
args
|
152
|
-
end
|
153
|
-
end
|
154
|
-
end
|
1
|
+
module AuthorizeNet
|
2
|
+
# The core, xml response class. You shouldn't instantiate this one.
|
3
|
+
# Instead you should use AuthorizeNet::ARB::Response.
|
4
|
+
class XmlResponse < AuthorizeNet::Response
|
5
|
+
# DO NOT USE. Instantiate AuthorizeNet::ARB::Response or AuthorizeNet::CIM::Response instead.
|
6
|
+
def initialize(raw_response, transaction)
|
7
|
+
@raw_response = raw_response
|
8
|
+
@transaction = transaction
|
9
|
+
unless connection_failure?
|
10
|
+
begin
|
11
|
+
xml = Nokogiri::XML(@raw_response.body) do |config|
|
12
|
+
# confirm noent is the right flag
|
13
|
+
config.recover.noent.nonet
|
14
|
+
end
|
15
|
+
@root = xml.children[0]
|
16
|
+
@result_code = node_content_unless_nil(@root.at_css('messages resultCode'))
|
17
|
+
@message_code = node_content_unless_nil(@root.at_css('messages message code'))
|
18
|
+
@message_text = node_content_unless_nil(@root.at_css('messages message text'))
|
19
|
+
@reference_id = node_content_unless_nil(@root.at_css('refId'))
|
20
|
+
rescue StandardError
|
21
|
+
@raw_response = $ERROR_INFO
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# Check to see if the response indicated success. Success is defined as a 200 OK response with a resultCode
|
27
|
+
# of 'Ok'.
|
28
|
+
def success?
|
29
|
+
!connection_failure? && @result_code == 'Ok'
|
30
|
+
end
|
31
|
+
|
32
|
+
# Returns true if we failed to open a connection to the gateway or got back a non-200 OK HTTP response.
|
33
|
+
def connection_failure?
|
34
|
+
!@raw_response.is_a?(Net::HTTPOK)
|
35
|
+
end
|
36
|
+
|
37
|
+
# Returns the underlying Net::HTTPResponse object. This has the original response body along with
|
38
|
+
# headers and such. Note that if an exception is generated while making the request (which happens
|
39
|
+
# if there is no internet connection for example), you will get the exception object here instead of
|
40
|
+
# a Net::HTTPResponse object.
|
41
|
+
def raw
|
42
|
+
@raw_response
|
43
|
+
end
|
44
|
+
|
45
|
+
# Returns a deep-copy of the XML object received from the payment gateway. Or nil if there was no XML payload.
|
46
|
+
def xml
|
47
|
+
@root.dup unless @root.nil?
|
48
|
+
end
|
49
|
+
|
50
|
+
# Returns the resultCode from the XML response. resultCode will be either 'Ok' or 'Error'.
|
51
|
+
attr_reader :result_code
|
52
|
+
|
53
|
+
# Returns the messageCode from the XML response. This is a code indicating the details of an error
|
54
|
+
# or success.
|
55
|
+
attr_reader :message_code
|
56
|
+
|
57
|
+
# Returns the messageText from the XML response. This is a text description of the message_code.
|
58
|
+
attr_reader :message_text
|
59
|
+
|
60
|
+
# Alias for result_code.
|
61
|
+
def response_code
|
62
|
+
result_code
|
63
|
+
end
|
64
|
+
|
65
|
+
# Alias for message_code.
|
66
|
+
def response_reason_code
|
67
|
+
message_code
|
68
|
+
end
|
69
|
+
|
70
|
+
# Alias for message_text.
|
71
|
+
def response_reason_text
|
72
|
+
message_text
|
73
|
+
end
|
74
|
+
|
75
|
+
# Returns the refId from the response if there is one. Otherwise returns nil.
|
76
|
+
attr_reader :reference_id
|
77
|
+
|
78
|
+
#:enddoc:
|
79
|
+
protected
|
80
|
+
|
81
|
+
def node_content_unless_nil(node)
|
82
|
+
if node.nil?
|
83
|
+
nil
|
84
|
+
else
|
85
|
+
node.content
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def node_child_content_unless_nil(node)
|
90
|
+
if node.nil?
|
91
|
+
nil
|
92
|
+
else
|
93
|
+
node.children.collect(&:content) unless node.children.empty?
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
# Transforms a block of XML into a model Object defined by entity_desc.
|
98
|
+
def build_entity(xml, entity_desc)
|
99
|
+
args = {}
|
100
|
+
entity_desc.node_structure.each do |node_desc|
|
101
|
+
node_name = (node_desc.keys.reject { |k| k.to_s[0..0] == '_' }).first
|
102
|
+
args.merge!(handle_node_type(xml, node_desc, node_name, args, ''))
|
103
|
+
end
|
104
|
+
|
105
|
+
return nil if args.empty?
|
106
|
+
|
107
|
+
if entity_desc.arg_mapping.nil?
|
108
|
+
return entity_desc.entity_class.new(args)
|
109
|
+
else
|
110
|
+
args_list = []
|
111
|
+
entity_desc.arg_mapping.each do |arg|
|
112
|
+
args_list <<= args[arg]
|
113
|
+
args.delete(arg)
|
114
|
+
end
|
115
|
+
args_list <<= args
|
116
|
+
return entity_desc.entity_class.new(*args_list)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
# Parses an XML fragment into an internal representation.
|
121
|
+
def handle_node_type(xml, node_desc, node_name, args, base_name)
|
122
|
+
case node_desc[node_name]
|
123
|
+
when Symbol
|
124
|
+
node = xml.at_css(base_name + node_name.to_s)
|
125
|
+
unless node.nil?
|
126
|
+
content = node.content
|
127
|
+
case node_desc[:_converter]
|
128
|
+
when Method, Proc
|
129
|
+
content = node_desc[:_converter].call(content)
|
130
|
+
when Symbol
|
131
|
+
content = send(node_desc[:_converter], content)
|
132
|
+
end
|
133
|
+
args[node_desc[node_name]] = content unless content.nil?
|
134
|
+
end
|
135
|
+
when AuthorizeNet::EntityDescription
|
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
|
140
|
+
xml.css(base_name + node_name.to_s).each do |node|
|
141
|
+
entity = build_entity(node, node_desc[node_name])
|
142
|
+
args[node_desc[:_multivalue]] = args[node_desc[:_multivalue]].to_a + entity.to_a unless entity.nil?
|
143
|
+
end
|
144
|
+
end
|
145
|
+
when Array
|
146
|
+
node_desc[node_name].each do |inner_node|
|
147
|
+
inner_node_name = (inner_node.keys.reject { |k| k.to_s[0..0] == '_' }).first
|
148
|
+
args.merge!(handle_node_type(xml, inner_node, inner_node_name, args, node_name.to_s + ' '))
|
149
|
+
end
|
150
|
+
end
|
151
|
+
args
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|