authorizenet_blaq 1.9.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/app/helpers/authorize_net_helper.rb +24 -0
- data/lib/authorize_net/addresses/address.rb +29 -0
- data/lib/authorize_net/addresses/shipping_address.rb +26 -0
- data/lib/authorize_net/aim/response.rb +131 -0
- data/lib/authorize_net/aim/transaction.rb +190 -0
- data/lib/authorize_net/api/api_transaction.rb +123 -0
- data/lib/authorize_net/api/constants.yml +1 -0
- data/lib/authorize_net/api/schema.rb +4985 -0
- data/lib/authorize_net/api/transaction.rb +258 -0
- data/lib/authorize_net/arb/fields.rb +24 -0
- data/lib/authorize_net/arb/paging.rb +33 -0
- data/lib/authorize_net/arb/response.rb +34 -0
- data/lib/authorize_net/arb/sorting.rb +43 -0
- data/lib/authorize_net/arb/subscription.rb +72 -0
- data/lib/authorize_net/arb/subscription_detail.rb +14 -0
- data/lib/authorize_net/arb/subscription_list_response.rb +43 -0
- data/lib/authorize_net/arb/transaction.rb +177 -0
- data/lib/authorize_net/authorize_net.rb +154 -0
- data/lib/authorize_net/cim/customer_profile.rb +19 -0
- data/lib/authorize_net/cim/payment_profile.rb +37 -0
- data/lib/authorize_net/cim/response.rb +116 -0
- data/lib/authorize_net/cim/transaction.rb +727 -0
- data/lib/authorize_net/customer.rb +27 -0
- data/lib/authorize_net/email_receipt.rb +24 -0
- data/lib/authorize_net/fields.rb +779 -0
- data/lib/authorize_net/key_value_response.rb +117 -0
- data/lib/authorize_net/key_value_transaction.rb +291 -0
- data/lib/authorize_net/line_item.rb +25 -0
- data/lib/authorize_net/order.rb +42 -0
- data/lib/authorize_net/payment_methods/credit_card.rb +62 -0
- data/lib/authorize_net/payment_methods/echeck.rb +72 -0
- data/lib/authorize_net/reporting/batch.rb +19 -0
- data/lib/authorize_net/reporting/batch_statistics.rb +19 -0
- data/lib/authorize_net/reporting/fds_filter.rb +11 -0
- data/lib/authorize_net/reporting/response.rb +163 -0
- data/lib/authorize_net/reporting/returned_item.rb +46 -0
- data/lib/authorize_net/reporting/transaction.rb +133 -0
- data/lib/authorize_net/reporting/transaction_details.rb +25 -0
- data/lib/authorize_net/response.rb +27 -0
- data/lib/authorize_net/sim/hosted_payment_form.rb +38 -0
- data/lib/authorize_net/sim/hosted_receipt_page.rb +37 -0
- data/lib/authorize_net/sim/response.rb +142 -0
- data/lib/authorize_net/sim/transaction.rb +138 -0
- data/lib/authorize_net/transaction.rb +66 -0
- data/lib/authorize_net/xml_response.rb +172 -0
- data/lib/authorize_net/xml_transaction.rb +298 -0
- data/lib/authorize_net.rb +107 -0
- data/lib/authorizenet_blaq.rb +4 -0
- data/lib/generators/authorize_net/direct_post/direct_post_generator.rb +53 -0
- data/lib/generators/authorize_net/direct_post/templates/README-AuthorizeNet +49 -0
- data/lib/generators/authorize_net/direct_post/templates/config.yml.erb +8 -0
- data/lib/generators/authorize_net/direct_post/templates/config.yml.rails3.erb +8 -0
- data/lib/generators/authorize_net/direct_post/templates/controller.rb.erb +31 -0
- data/lib/generators/authorize_net/direct_post/templates/initializer.rb +4 -0
- data/lib/generators/authorize_net/direct_post/templates/layout.erb +18 -0
- data/lib/generators/authorize_net/direct_post/templates/payment.erb +10 -0
- data/lib/generators/authorize_net/direct_post/templates/payment.rails3.erb +10 -0
- data/lib/generators/authorize_net/direct_post/templates/receipt.erb +1 -0
- data/lib/generators/authorize_net/direct_post/templates/relay_response.erb +1 -0
- data/lib/generators/authorize_net/sim/sim_generator.rb +47 -0
- data/lib/generators/authorize_net/sim/templates/README-AuthorizeNet +52 -0
- data/lib/generators/authorize_net/sim/templates/config.yml.erb +8 -0
- data/lib/generators/authorize_net/sim/templates/config.yml.rails3.erb +8 -0
- data/lib/generators/authorize_net/sim/templates/controller.rb.erb +21 -0
- data/lib/generators/authorize_net/sim/templates/initializer.rb +4 -0
- data/lib/generators/authorize_net/sim/templates/layout.erb +18 -0
- data/lib/generators/authorize_net/sim/templates/payment.erb +6 -0
- data/lib/generators/authorize_net/sim/templates/payment.rails3.erb +6 -0
- data/lib/generators/authorize_net/sim/templates/thank_you.erb +1 -0
- data/lib/generators/generator_extensions.rb +75 -0
- metadata +196 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f3e7311d5353b9e0358dbabb9e3e152be3108cc4
|
4
|
+
data.tar.gz: a02ae11482a20bbc3eaef29b1fb0e71bcc2a46ba
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3570517a47c34050a6b3db4cbb23125e6b0bdf9f1963ecff67c8e294d7e71c6229a0b3d1cff304b76b56aa885ae319c619654d7874b9d6c6237b146012f46750
|
7
|
+
data.tar.gz: fa3716815b981163d5b0a27eb5b82879a7ceb85b63e47e0d05826b0ebbd1afcaca9d318a2b7a656b59acbcd5706423a0e90a16b8f324609c8663fc2f1607fe6a
|
@@ -0,0 +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
|
24
|
+
end
|
@@ -0,0 +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
|
+
|
29
|
+
end
|
@@ -0,0 +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
|
+
|
26
|
+
end
|
@@ -0,0 +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
|
+
|
131
|
+
end
|
@@ -0,0 +1,190 @@
|
|
1
|
+
module AuthorizeNet::AIM
|
2
|
+
|
3
|
+
# The AIM transaction class. Handles building the transaction payload and
|
4
|
+
# transmitting it to the gateway.
|
5
|
+
class Transaction < AuthorizeNet::KeyValueTransaction
|
6
|
+
|
7
|
+
# The default options for the constructor.
|
8
|
+
@@option_defaults = {
|
9
|
+
:transaction_type => Type::AUTHORIZE_AND_CAPTURE,
|
10
|
+
:gateway => :production,
|
11
|
+
:test => false,
|
12
|
+
:allow_split => false,
|
13
|
+
:delimiter => ',',
|
14
|
+
:encapsulation_character => nil,
|
15
|
+
:verify_ssl => true,
|
16
|
+
:device_type => DeviceType::UNKNOWN,
|
17
|
+
:market_type => MarketType::RETAIL
|
18
|
+
}
|
19
|
+
|
20
|
+
# Fields to convert to/from booleans.
|
21
|
+
@@boolean_fields = [:tax_exempt, :test_request, :recurring_billing, :allow_partial_auth, :delim_data, :email_customer, :relay_response]
|
22
|
+
|
23
|
+
# Fields to convert to/from BigDecimal.
|
24
|
+
@@decimal_fields = [:amount]
|
25
|
+
|
26
|
+
# Constructs an AIM transaction. You can use the new AIM transaction object
|
27
|
+
# to issue a request to the payment gateway and parse the response into a new
|
28
|
+
# AuthorizeNet::AIM::Response object.
|
29
|
+
#
|
30
|
+
# +api_login_id+:: Your API login ID, as a string.
|
31
|
+
# +api_transaction_key+:: Your API transaction key, as a string.
|
32
|
+
# +options+:: A hash of options. See below for values.
|
33
|
+
#
|
34
|
+
# Options
|
35
|
+
# +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.
|
36
|
+
# +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).
|
37
|
+
# +test+:: A boolean indicating if the transaction should be run in test mode or not (defaults to false).
|
38
|
+
# +allow_split+:: A boolean indicating if split transactions should be allowed (defaults to false).
|
39
|
+
# +delimiter+:: A single character (as a string) that will be used to delimit the response from the gateway. Defaults to ','.
|
40
|
+
# +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.
|
41
|
+
# +verify_ssl+:: A boolean indicating if the SSL certificate of the +gateway+ should be verified. Defaults to true.
|
42
|
+
# +device_type+:: A constant from DeviceType indicating the type of POS device used in a card present transaction. Defaults to DeviceType::UNKNOWN.
|
43
|
+
# +market_type+:: A constant from MarketType indicating your industry. Used for card present transactions. Defaults to MarketType::RETAIL.
|
44
|
+
#
|
45
|
+
def initialize(api_login_id, api_transaction_key, options = {})
|
46
|
+
super()
|
47
|
+
options = @@option_defaults.merge(options)
|
48
|
+
@api_login_id = api_login_id
|
49
|
+
@api_transaction_key = api_transaction_key
|
50
|
+
@test_mode = options[:test]
|
51
|
+
@response ||= nil
|
52
|
+
@delimiter = options[:delimiter]
|
53
|
+
@type = options[:transaction_type]
|
54
|
+
@cp_version = nil
|
55
|
+
case options[:gateway]
|
56
|
+
when :sandbox, :test
|
57
|
+
@gateway = Gateway::TEST
|
58
|
+
when :production, :live
|
59
|
+
@gateway = Gateway::LIVE
|
60
|
+
when :card_present_live, :card_present_production
|
61
|
+
@gateway = Gateway::CARD_PRESENT_LIVE
|
62
|
+
@cp_version = '1.0'
|
63
|
+
when :card_present_test, :card_present_sandbox
|
64
|
+
@gateway = Gateway::CARD_PRESENT_TEST
|
65
|
+
@cp_version = '1.0'
|
66
|
+
else
|
67
|
+
@gateway = options[:gateway]
|
68
|
+
end
|
69
|
+
@allow_split_transaction = options[:allow_split]
|
70
|
+
@encapsulation_character = options[:encapsulation_character]
|
71
|
+
@verify_ssl = options[:verify_ssl]
|
72
|
+
@market_type = options[:market_type]
|
73
|
+
@device_type = options[:device_type]
|
74
|
+
@solution_id = options[:solution_id]
|
75
|
+
end
|
76
|
+
|
77
|
+
# Checks if the transaction has been configured for test mode or not. Return TRUE if the
|
78
|
+
# transaction is a test transaction, FALSE otherwise. All transactions run against the sandbox
|
79
|
+
# are considered test transactions.
|
80
|
+
def test?
|
81
|
+
super || @gateway == Gateway::TEST
|
82
|
+
end
|
83
|
+
|
84
|
+
# Returns TRUE if split transactions are allowed, FALSE otherwise.
|
85
|
+
def split_transaction_allowed?
|
86
|
+
!!@allow_split_transaction
|
87
|
+
end
|
88
|
+
|
89
|
+
# Returns the current encapsulation character unless there is none, in which case Nil is returned.
|
90
|
+
def encapsulation_character
|
91
|
+
@encapsulation_character
|
92
|
+
end
|
93
|
+
|
94
|
+
# Returns the gateway to be used for this transaction.
|
95
|
+
def gateway
|
96
|
+
@gateway
|
97
|
+
end
|
98
|
+
|
99
|
+
# Checks to see if the transaction has a response (meaning it has been submitted to the gateway).
|
100
|
+
# Returns TRUE if a response is present, FALSE otherwise.
|
101
|
+
def has_response?
|
102
|
+
!@response.nil?
|
103
|
+
end
|
104
|
+
|
105
|
+
# Retrieve the response object (or Nil if transaction hasn't been sent to the gateway).
|
106
|
+
def response
|
107
|
+
@response
|
108
|
+
end
|
109
|
+
|
110
|
+
# Returns the current delimiter we are using to parse the fields returned by the
|
111
|
+
# gateway.
|
112
|
+
def delimiter
|
113
|
+
@delimiter
|
114
|
+
end
|
115
|
+
|
116
|
+
# Sets the delimiter used to parse the response from the gateway.
|
117
|
+
def delimiter=(delimiter)
|
118
|
+
@delimiter = delimiter
|
119
|
+
end
|
120
|
+
|
121
|
+
# Submits the transaction to the gateway for processing. Returns a response object. If the transaction
|
122
|
+
# has already been run, it will return nil.
|
123
|
+
def run
|
124
|
+
make_request
|
125
|
+
end
|
126
|
+
|
127
|
+
# Returns the current card present API version that we are adhering to.
|
128
|
+
def cp_version
|
129
|
+
@cp_version
|
130
|
+
end
|
131
|
+
|
132
|
+
def solution_id
|
133
|
+
@solution_id
|
134
|
+
end
|
135
|
+
|
136
|
+
#:enddoc:
|
137
|
+
protected
|
138
|
+
|
139
|
+
# An internal method that builds the POST body, submits it to the gateway, and constructs a Response object with the response.
|
140
|
+
def make_request
|
141
|
+
if has_response?
|
142
|
+
return nil
|
143
|
+
end
|
144
|
+
url = URI.parse(@gateway)
|
145
|
+
fields = @fields.merge(:type => @type, :delim_char => @delimiter, :delim_data => "TRUE", :login => @api_login_id, :tran_key => @api_transaction_key, :relay_response => "FALSE")
|
146
|
+
|
147
|
+
if @cp_version.nil?
|
148
|
+
fields.merge!(:version => @version)
|
149
|
+
else
|
150
|
+
fields.merge!(:cp_version => @cp_version, :market_type => @market_type, :device_type => @device_type, :response_format => "1")
|
151
|
+
end
|
152
|
+
fields[:test_request] = boolean_to_value(@test_mode)
|
153
|
+
fields[:allow_partial_auth] = 'TRUE' if @allow_split_transaction
|
154
|
+
fields[:encap_char] = @encapsulation_character unless @encapsulation_character.nil?
|
155
|
+
fields[:solution_id] = @solution_id unless @solution_id.nil?
|
156
|
+
fields.each do |k, v|
|
157
|
+
if @@boolean_fields.include?(k)
|
158
|
+
fields[k] = boolean_to_value(v)
|
159
|
+
elsif @@decimal_fields.include?(k)
|
160
|
+
fields[k] = decimal_to_value(v)
|
161
|
+
end
|
162
|
+
end
|
163
|
+
data = fields.collect do |key, val|
|
164
|
+
self.to_param(key, val)
|
165
|
+
end
|
166
|
+
custom_field_keys = @custom_fields.keys.collect(&:to_s).sort.collect(&:to_sym)
|
167
|
+
for key in custom_field_keys
|
168
|
+
data += [self.to_param(key, @custom_fields[key.to_sym], '')]
|
169
|
+
end
|
170
|
+
data.flatten!
|
171
|
+
request = Net::HTTP::Post.new(url.path)
|
172
|
+
request.content_type = 'application/x-www-form-urlencoded'
|
173
|
+
request.body = data.join("&")
|
174
|
+
connection = Net::HTTP.new(url.host, url.port)
|
175
|
+
connection.use_ssl = true
|
176
|
+
if @verify_ssl
|
177
|
+
connection.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
178
|
+
else
|
179
|
+
connection.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
180
|
+
end
|
181
|
+
begin
|
182
|
+
@response = AuthorizeNet::AIM::Response.new((connection.start {|http| http.request(request)}), self)
|
183
|
+
rescue
|
184
|
+
@response = AuthorizeNet::AIM::Response.new($!, self)
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
end
|
189
|
+
|
190
|
+
end
|
@@ -0,0 +1,123 @@
|
|
1
|
+
module AuthorizeNet::API
|
2
|
+
class ApiTransaction < AuthorizeNet::XmlTransaction
|
3
|
+
|
4
|
+
module Type
|
5
|
+
API_CREATE_TRANSACTION = "createTransactionRequest"
|
6
|
+
API_UPDATE_SPLIT_TENDER_GROUP = "updateSplitTenderGroupRequest"
|
7
|
+
|
8
|
+
API_CREATE_SUBSCRIPTION = "ARBCreateSubscriptionRequest"
|
9
|
+
API_UPDATE_SUBSCRIPTION = "ARBUpdateSubscriptionRequest"
|
10
|
+
API_CANCEL_SUBSCRIPTION = "ARBCancelSubscriptionRequest"
|
11
|
+
API_GET_SUBSCRIPTION_STATUS = "ARBGetSubscriptionStatusRequest"
|
12
|
+
API_GET_SUBSCRIPTION_LIST = "ARBGetSubscriptionListRequest"
|
13
|
+
|
14
|
+
API_GET_CUSTOMER_PROFILE_IDS = "getCustomerProfileIdsRequest"
|
15
|
+
|
16
|
+
API_CREATE_CUSTOMER_PROFILE = "createCustomerProfileRequest"
|
17
|
+
API_GET_CUSTOMER_PROFILE = "getCustomerProfileRequest"
|
18
|
+
API_UPDATE_CUSTOMER_PROFILE = "updateCustomerProfileRequest"
|
19
|
+
API_DELETE_CUSTOMER_PROFILE = "deleteCustomerProfileRequest"
|
20
|
+
|
21
|
+
API_CREATE_CUSTOMER_PAYMENT_PROFILE = "createCustomerPaymentProfileRequest"
|
22
|
+
API_GET_CUSTOMER_PAYMENT_PROFILE = "getCustomerPaymentProfileRequest"
|
23
|
+
API_UPDATE_CUSTOMER_PAYMENT_PROFILE = "updateCustomerPaymentProfileRequest"
|
24
|
+
API_VALIDATE_CUSTOMER_PAYMENT_PROFILE = "validateCustomerPaymentProfileRequest"
|
25
|
+
API_DELETE_CUSTOMER_PAYMENT_PROFILE = "deleteCustomerPaymentProfileRequest"
|
26
|
+
|
27
|
+
API_CREATE_CUSTOMER_SHIPPING_PROFILE = "createCustomerShippingAddressRequest"
|
28
|
+
API_GET_CUSTOMER_SHIPPING_PROFILE = "getCustomerShippingAddressRequest"
|
29
|
+
API_UPDATE_CUSTOMER_SHIPPING_PROFILE = "updateCustomerShippingAddressRequest"
|
30
|
+
API_DELETE_CUSTOMER_SHIPPING_PROFILE = "deleteCustomerShippingAddressRequest"
|
31
|
+
|
32
|
+
API_CREATE_CUSTOMER_PROFILE_FROM_TRANSACTION = "createCustomerProfileFromTransactionRequest"
|
33
|
+
|
34
|
+
API_GET_SETTLED_BATCH_LIST = "getSettledBatchListRequest"
|
35
|
+
API_GET_TRANSACTION_LIST = "getTransactionListRequest"
|
36
|
+
API_GET_TRANSACTION_DETAILS = "getTransactionDetailsRequest"
|
37
|
+
API_GET_UNSETTLED_TRANSACTION_LIST = "getUnsettledTransactionListRequest"
|
38
|
+
API_GET_BATCH_STATISTICS = "getBatchStatisticsRequest"
|
39
|
+
API_GET_TRANSACTION_LIST_FOR_CUSTOMER = "getTransactionListForCustomerRequest"
|
40
|
+
|
41
|
+
API_GET_HOSTED_PROFILE_PAGE = "getHostedProfilePageRequest"
|
42
|
+
|
43
|
+
|
44
|
+
API_DECRYPT_PAYMENT_DATA = "decryptPaymentDataRequest"
|
45
|
+
API_AUTHENTICATE_TEST_REQUEST = "authenticateTestRequest"
|
46
|
+
|
47
|
+
API_GET_CUSTOMER_PAYMENT_PROFILE_LIST = "getCustomerPaymentProfileListRequest"
|
48
|
+
|
49
|
+
API_ARB_GET_SUBSCRIPTION_REQUEST = "ARBGetSubscriptionRequest"
|
50
|
+
|
51
|
+
API_GET_MERCHANT_DETAILS = "getMerchantDetailsRequest"
|
52
|
+
API_GET_HOSTED_PAYMENT_PAGE = "getHostedPaymentPageRequest"
|
53
|
+
API_UDPATE_HELD_TRANSACTION = "updateHeldTransactionRequest"
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
def initialize(api_login_id = nil, api_transaction_key = nil, options = {})
|
58
|
+
super
|
59
|
+
end
|
60
|
+
|
61
|
+
def setOAuthOptions()
|
62
|
+
super
|
63
|
+
end
|
64
|
+
|
65
|
+
def make_request(request,responseClass,type)
|
66
|
+
setOAuthOptions()
|
67
|
+
unless responseClass.nil? or request.nil?
|
68
|
+
begin
|
69
|
+
@xml = serialize(request,type)
|
70
|
+
respXml = send_request(@xml)
|
71
|
+
@response = deserialize(respXml.body,responseClass)
|
72
|
+
rescue Exception => ex
|
73
|
+
ex
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def serialize(object,type)
|
79
|
+
doc = Nokogiri::XML::Document.new
|
80
|
+
doc.root = object.to_xml
|
81
|
+
constants = YAML.load_file(File.dirname(__FILE__) + "/constants.yml")
|
82
|
+
clientId = constants['clientId']
|
83
|
+
|
84
|
+
builder = Nokogiri::XML::Builder.new(:encoding => 'utf-8') do |x|
|
85
|
+
x.send(type.to_sym, :xmlns => XML_NAMESPACE) {
|
86
|
+
x.merchantAuthentication {
|
87
|
+
if !@access_token.blank?
|
88
|
+
x.accessToken @access_token
|
89
|
+
end
|
90
|
+
if !@api_login_id.blank? || (@access_token.blank? && @api_login_id.blank?)
|
91
|
+
x.name @api_login_id
|
92
|
+
x.transactionKey @api_transaction_key
|
93
|
+
end
|
94
|
+
}
|
95
|
+
x.clientId clientId
|
96
|
+
x.send:insert, doc.root.element_children
|
97
|
+
}
|
98
|
+
end
|
99
|
+
builder.to_xml
|
100
|
+
end
|
101
|
+
|
102
|
+
def send_request(xml)
|
103
|
+
url = URI.parse(@gateway)
|
104
|
+
|
105
|
+
httpRequest = Net::HTTP::Post.new(url.path)
|
106
|
+
httpRequest.content_type = 'text/xml'
|
107
|
+
httpRequest.body = xml
|
108
|
+
connection = Net::HTTP.new(url.host, url.port)
|
109
|
+
connection.use_ssl = true
|
110
|
+
if @verify_ssl
|
111
|
+
connection.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
112
|
+
else
|
113
|
+
connection.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
114
|
+
end
|
115
|
+
|
116
|
+
response = connection.start {|http| http.request(httpRequest)}
|
117
|
+
end
|
118
|
+
|
119
|
+
def deserialize(xml,responseClass)
|
120
|
+
responseClass.from_xml(xml)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
clientId: sdk-ruby-1.9.3
|