authorize-net 1.5.2
Sign up to get free protection for your applications and to get access to all the features.
- data/License.pdf +0 -0
- data/README.rdoc +124 -0
- data/Rakefile +74 -0
- data/generators/authorize_net_direct_post/USAGE +20 -0
- data/generators/authorize_net_direct_post/authorize_net_direct_post_generator.rb +21 -0
- data/generators/authorize_net_direct_post/templates/README-AuthorizeNet +49 -0
- data/generators/authorize_net_direct_post/templates/config.yml.erb +8 -0
- data/generators/authorize_net_direct_post/templates/config.yml.rails3.erb +8 -0
- data/generators/authorize_net_direct_post/templates/controller.rb.erb +31 -0
- data/generators/authorize_net_direct_post/templates/initializer.rb +4 -0
- data/generators/authorize_net_direct_post/templates/layout.erb +18 -0
- data/generators/authorize_net_direct_post/templates/payment.erb +10 -0
- data/generators/authorize_net_direct_post/templates/payment.rails3.erb +10 -0
- data/generators/authorize_net_direct_post/templates/receipt.erb +1 -0
- data/generators/authorize_net_direct_post/templates/relay_response.erb +1 -0
- data/generators/authorize_net_sim/USAGE +20 -0
- data/generators/authorize_net_sim/authorize_net_sim_generator.rb +19 -0
- data/generators/authorize_net_sim/templates/README-AuthorizeNet +52 -0
- data/generators/authorize_net_sim/templates/config.yml.erb +8 -0
- data/generators/authorize_net_sim/templates/config.yml.rails3.erb +8 -0
- data/generators/authorize_net_sim/templates/controller.rb.erb +21 -0
- data/generators/authorize_net_sim/templates/initializer.rb +4 -0
- data/generators/authorize_net_sim/templates/layout.erb +18 -0
- data/generators/authorize_net_sim/templates/payment.erb +6 -0
- data/generators/authorize_net_sim/templates/payment.rails3.erb +6 -0
- data/generators/authorize_net_sim/templates/thank_you.erb +1 -0
- data/generators/generator_extensions.rb +75 -0
- data/init.rb +2 -0
- data/install.rb +1 -0
- data/lib/app/helpers/authorize_net_helper.rb +24 -0
- data/lib/authorize-net.rb +4 -0
- data/lib/authorize_net.rb +92 -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 +184 -0
- data/lib/authorize_net/arb/response.rb +34 -0
- data/lib/authorize_net/arb/subscription.rb +72 -0
- data/lib/authorize_net/arb/transaction.rb +146 -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 +110 -0
- data/lib/authorize_net/cim/transaction.rb +678 -0
- data/lib/authorize_net/customer.rb +27 -0
- data/lib/authorize_net/email_receipt.rb +24 -0
- data/lib/authorize_net/fields.rb +736 -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 +74 -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 +127 -0
- data/lib/authorize_net/reporting/transaction.rb +116 -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 +275 -0
- data/lib/generators/authorize_net/direct_post_generator.rb +51 -0
- data/lib/generators/authorize_net/sim_generator.rb +47 -0
- data/spec/aim_spec.rb +310 -0
- data/spec/arb_spec.rb +191 -0
- data/spec/authorize_net_spec.rb +200 -0
- data/spec/cim_spec.rb +450 -0
- data/spec/reporting_spec.rb +431 -0
- data/spec/sim_spec.rb +97 -0
- data/spec/spec.opts +5 -0
- data/spec/spec_helper.rb +2 -0
- data/uninstall.rb +1 -0
- metadata +223 -0
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
require 'rails/generators/named_base'
|
3
|
+
|
4
|
+
module AuthorizeNet
|
5
|
+
module Generators
|
6
|
+
class SimGenerator < Rails::Generators::NamedBase
|
7
|
+
source_root File.expand_path("../../../../generators/authorize_net_sim/templates", __FILE__)
|
8
|
+
argument :api_login_id, :type => :string, :desc => 'Your Authorize.Net API login ID.', :optional => true
|
9
|
+
argument :api_transaction_key, :type => :string, :desc => 'Your Authorize.Net API transaction key.', :optional => true
|
10
|
+
argument :merchant_hash_value, :type => :string, :desc => 'Your Authorize.Net merchant hash value.', :optional => true
|
11
|
+
desc <<-DESC
|
12
|
+
Description
|
13
|
+
Generates a simple implementation of Authorize.Net's SIM integration method.
|
14
|
+
|
15
|
+
Example:
|
16
|
+
rails generate authorize_net:sim payments API_LOGIN_ID API_TRANSACTION_KEY MERCHANT_HASH_VALUE
|
17
|
+
|
18
|
+
This will create:
|
19
|
+
create README-AuthorizeNet
|
20
|
+
create app/views/payments
|
21
|
+
create app/views/payments/payment.erb
|
22
|
+
create app/views/payments/thank_you.erb
|
23
|
+
create app/views/layouts/authorize_net.erb
|
24
|
+
create config/authorize_net.yml
|
25
|
+
create config/initializers/authorize_net.rb
|
26
|
+
create app/controllers/payments_controller.rb
|
27
|
+
route match '/payments/thank_you', :to => 'payments#thank_you', :as => 'payments_thank_you', :via => [:get]
|
28
|
+
route match '/payments/payment', :to => 'payments#payment', :as => 'paymentspayment', :via => [:get]
|
29
|
+
|
30
|
+
DESC
|
31
|
+
|
32
|
+
def manifest
|
33
|
+
copy_file "README-AuthorizeNet", "README-AuthorizeNet"
|
34
|
+
empty_directory "app/views/#{file_name}"
|
35
|
+
copy_file "payment.rails3.erb", "app/views/#{file_name}/payment.erb"
|
36
|
+
copy_file "thank_you.erb", "app/views/#{file_name}/thank_you.erb"
|
37
|
+
copy_file "layout.erb", "app/views/layouts/authorize_net.erb"
|
38
|
+
template "config.yml.rails3.erb", "config/authorize_net.yml"
|
39
|
+
copy_file "initializer.rb", "config/initializers/authorize_net.rb"
|
40
|
+
template "controller.rb.erb", "app/controllers/#{file_name}_controller.rb"
|
41
|
+
route "match '/#{plural_name}/thank_you', :to => '#{file_name}#thank_you', :as => '#{singular_name}_thank_you', :via => [:get]"
|
42
|
+
route "match '/#{plural_name}/payment', :to => '#{file_name}#payment', :as => '#{singular_name}payment', :via => [:get]"
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/spec/aim_spec.rb
ADDED
@@ -0,0 +1,310 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe AuthorizeNet::AIM::Transaction do
|
4
|
+
|
5
|
+
before :all do
|
6
|
+
begin
|
7
|
+
creds = YAML.load_file(File.dirname(__FILE__) + "/credentials.yml")
|
8
|
+
@api_key = creds['api_transaction_key']
|
9
|
+
@api_login = creds['api_login_id']
|
10
|
+
@cp_api_key = creds['cp_api_transaction_key']
|
11
|
+
@cp_api_login = creds['cp_api_login_id']
|
12
|
+
@md5_value = creds['md5_value']
|
13
|
+
@cp_md5_value = creds['cp_md5_value']
|
14
|
+
rescue Errno::ENOENT => e
|
15
|
+
@api_key = "TEST"
|
16
|
+
@api_login = "TEST"
|
17
|
+
@cp_api_key = "TEST"
|
18
|
+
@cp_api_login = "TEST"
|
19
|
+
@md5_value = "TEST"
|
20
|
+
@cp_md5_value = "TEST"
|
21
|
+
warn "WARNING: Running w/o valid AuthorizeNet sandbox credentials. Create spec/credentials.yml."
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
before do
|
26
|
+
@type = AuthorizeNet::AIM::Transaction::Type::AUTHORIZE_AND_CAPTURE
|
27
|
+
@test_mode = false
|
28
|
+
@gateway = :sandbox
|
29
|
+
@amount = (rand(10000) + 100) / 100.0
|
30
|
+
@credit_card = AuthorizeNet::CreditCard.new('4111111111111111', '01' + (Time.now + (3600 * 24 * 365)).strftime('%y'))
|
31
|
+
@response = '1,1,1,(TESTMODE) This transaction has been approved.,000000,P,0,,,10.00,CC,auth_capture,,,,,,,,,,,,,,,,,,,,,,,,,,7A3C09A367FED29C9902038440CD8A52,,,,,,,,,,,,,XXXX0027,Visa,,,,,,,,,,,,,,,,'
|
32
|
+
@echeck = AuthorizeNet::ECheck.new('322271627', '123456789', 'JPMorgan Chase Bank', 'John Doe')
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should support instantiation" do
|
36
|
+
AuthorizeNet::AIM::Transaction.new(@api_login, @api_key).should be_instance_of(AuthorizeNet::AIM::Transaction)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should know if its in test mode" do
|
40
|
+
transaction = AuthorizeNet::AIM::Transaction.new(@api_login, @api_key, :transaction_type => @type, :gateway => AuthorizeNet::AIM::Transaction::Gateway::TEST, :test => true)
|
41
|
+
transaction.test?.should be_true
|
42
|
+
transaction = AuthorizeNet::AIM::Transaction.new(@api_login, @api_key, :transaction_type => @type, :gateway => AuthorizeNet::AIM::Transaction::Gateway::TEST, :test => false)
|
43
|
+
transaction.test?.should be_true
|
44
|
+
transaction = AuthorizeNet::AIM::Transaction.new(@api_login, @api_key, :transaction_type => @type, :gateway => AuthorizeNet::AIM::Transaction::Gateway::LIVE, :test => true)
|
45
|
+
transaction.test?.should be_true
|
46
|
+
transaction = AuthorizeNet::AIM::Transaction.new(@api_login, @api_key, :transaction_type => @type, :gateway => AuthorizeNet::AIM::Transaction::Gateway::LIVE, :test => false)
|
47
|
+
transaction.test?.should be_false
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should not have a response if the transaciton hasn't been run" do
|
51
|
+
transaction = AuthorizeNet::AIM::Transaction.new(@api_login, @api_key, :transaction_type => @type, :gateway => @gateway, :test => @test_mode)
|
52
|
+
transaction.has_response?.should be_false
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should support the addition of fields to the transaction body" do
|
56
|
+
transaction = AuthorizeNet::AIM::Transaction.new(@api_login, @api_key, :transaction_type => @type, :gateway => @gateway, :test => @test_mode)
|
57
|
+
transaction.should respond_to(:set_fields)
|
58
|
+
transaction.set_fields({:test => 123}).should == {:test => 123}
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should support the addition of mulitple line_item fields" do
|
62
|
+
transaction = AuthorizeNet::AIM::Transaction.new(@api_login, @api_key, :transaction_type => @type, :gateway => @gateway, :test => @test_mode)
|
63
|
+
transaction.set_fields({:line_item => [123, 123]}).should == {:line_item => [123, 123]}
|
64
|
+
transaction.set_fields({:line_item => "abc"}).should == {:line_item => "abc"}
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should not support the addition of mulitple fields for non-line-item fields" do
|
68
|
+
transaction = AuthorizeNet::AIM::Transaction.new(@api_login, @api_key, :transaction_type => @type, :gateway => @gateway, :test => @test_mode)
|
69
|
+
transaction.set_fields({:test => 123}).should == {:test => 123}
|
70
|
+
transaction.set_fields({:test => 123}).should == {:test => 123}
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should support custom fields" do
|
74
|
+
transaction = AuthorizeNet::AIM::Transaction.new(@api_login, @api_key, :transaction_type => @type, :gateway => @gateway, :test => @test_mode)
|
75
|
+
transaction.should respond_to(:set_custom_fields)
|
76
|
+
transaction.set_custom_fields(:test => 123).should == {:test => 123}
|
77
|
+
transaction.fields.should == {}
|
78
|
+
transaction.custom_fields.should == {:test => 123}
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should support the returning its response object" do
|
82
|
+
transaction = AuthorizeNet::AIM::Transaction.new(@api_login, @api_key, :transaction_type => @type, :gateway => @gateway, :test => @test_mode)
|
83
|
+
transaction.should respond_to(:response)
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should parse the response properly" do
|
87
|
+
Net::HTTP.stub!(:start).and_return(@response)
|
88
|
+
transaction = AuthorizeNet::AIM::Transaction.new(@api_login, @api_key, :transaction_type => @type, :gateway => @gateway, :test => @test_mode)
|
89
|
+
response = transaction.purchase(@amount, @credit_card)
|
90
|
+
response.should be_kind_of(AuthorizeNet::AIM::Response)
|
91
|
+
response.transaction_id.length.should >= 3
|
92
|
+
response.success?.should be_true
|
93
|
+
response.avs_response.should == AuthorizeNet::AIM::Response::AVSResponseCode::ADDRESS_AND_ZIP5_MATCH
|
94
|
+
response.card_type.should == AuthorizeNet::AIM::Response::CardType::VISA
|
95
|
+
response.card_type.should_not == AuthorizeNet::AIM::Response::CardType::MASTER_CARD
|
96
|
+
end
|
97
|
+
|
98
|
+
it "should support different transaction types" do
|
99
|
+
transaction = AuthorizeNet::AIM::Transaction.new(@api_login, @api_key, :transaction_type => @type, :gateway => @gateway, :test => @test_mode)
|
100
|
+
transaction.should respond_to(:type)
|
101
|
+
transaction.type.should == AuthorizeNet::AIM::Transaction::Type::AUTHORIZE_AND_CAPTURE
|
102
|
+
transaction.type = AuthorizeNet::AIM::Transaction::Type::VOID
|
103
|
+
transaction.type.should == AuthorizeNet::AIM::Transaction::Type::VOID
|
104
|
+
transaction.type = AuthorizeNet::AIM::Transaction::Type::AUTHORIZE_ONLY
|
105
|
+
transaction.type.should == AuthorizeNet::AIM::Transaction::Type::AUTHORIZE_ONLY
|
106
|
+
transaction.type = AuthorizeNet::AIM::Transaction::Type::CAPTURE_ONLY
|
107
|
+
transaction.type.should == AuthorizeNet::AIM::Transaction::Type::CAPTURE_ONLY
|
108
|
+
transaction.type = AuthorizeNet::AIM::Transaction::Type::CREDIT
|
109
|
+
transaction.type.should == AuthorizeNet::AIM::Transaction::Type::CREDIT
|
110
|
+
transaction.type = AuthorizeNet::AIM::Transaction::Type::PRIOR_AUTHORIZATION_AND_CAPTURE
|
111
|
+
transaction.type.should == AuthorizeNet::AIM::Transaction::Type::PRIOR_AUTHORIZATION_AND_CAPTURE
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should be able to run a transaction" do
|
115
|
+
transaction = AuthorizeNet::AIM::Transaction.new(@api_login, @api_key, :transaction_type => @type, :gateway => @gateway, :test => @test_mode)
|
116
|
+
transaction.run.should be_kind_of(AuthorizeNet::AIM::Response)
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should not be able to run a transaction a second time" do
|
120
|
+
transaction = AuthorizeNet::AIM::Transaction.new(@api_login, @api_key, :transaction_type => @type, :gateway => @gateway, :test => @test_mode)
|
121
|
+
transaction.run.should be_kind_of(AuthorizeNet::AIM::Response)
|
122
|
+
transaction.run.should be_nil
|
123
|
+
end
|
124
|
+
|
125
|
+
it "should be able to make a purchase" do
|
126
|
+
transaction = AuthorizeNet::AIM::Transaction.new(@api_login, @api_key, :transaction_type => @type, :gateway => @gateway, :test => @test_mode)
|
127
|
+
transaction.purchase(@amount, @credit_card).should be_kind_of(AuthorizeNet::AIM::Response)
|
128
|
+
transaction.response.fields[:amount].should == @amount
|
129
|
+
transaction.response.success?.should be_true
|
130
|
+
end
|
131
|
+
|
132
|
+
it "should support custom fields in the response" do
|
133
|
+
transaction = AuthorizeNet::AIM::Transaction.new(@api_login, @api_key, :transaction_type => @type, :gateway => @gateway, :test => @test_mode)
|
134
|
+
transaction.set_custom_fields(:funkey => '123')
|
135
|
+
transaction.set_custom_fields(:winker => 'ABC')
|
136
|
+
transaction.set_custom_fields(:bean => '!!!')
|
137
|
+
transaction.purchase(@amount, @credit_card).should be_kind_of(AuthorizeNet::AIM::Response)
|
138
|
+
fields = transaction.response.custom_fields
|
139
|
+
fields.should have_key(:funkey)
|
140
|
+
fields[:funkey].should == '123'
|
141
|
+
fields.should have_key(:winker)
|
142
|
+
fields[:winker].should == 'ABC'
|
143
|
+
fields.should have_key(:bean)
|
144
|
+
fields[:bean].should == '!!!'
|
145
|
+
end
|
146
|
+
|
147
|
+
it "should support an encapsulation character in the response" do
|
148
|
+
transaction = AuthorizeNet::AIM::Transaction.new(@api_login, @api_key, :transaction_type => @type, :gateway => @gateway, :test => @test_mode, :encapsulation_character => '"')
|
149
|
+
transaction.set_custom_fields(:funkey => '12,3')
|
150
|
+
transaction.purchase(@amount, @credit_card).should be_kind_of(AuthorizeNet::AIM::Response)
|
151
|
+
fields = transaction.response.custom_fields
|
152
|
+
fields.should have_key(:funkey)
|
153
|
+
fields[:funkey].should == '12,3'
|
154
|
+
end
|
155
|
+
|
156
|
+
it "should accept an ECheck for a purchase" do
|
157
|
+
transaction = AuthorizeNet::AIM::Transaction.new(@api_login, @api_key, :transaction_type => @type, :gateway => @gateway, :test => @test_mode)
|
158
|
+
transaction.purchase(@amount, @echeck).should be_kind_of(AuthorizeNet::AIM::Response)
|
159
|
+
transaction.response.success?.should be_true
|
160
|
+
end
|
161
|
+
|
162
|
+
it "should support adding line items" do
|
163
|
+
transaction = AuthorizeNet::AIM::Transaction.new(@api_login, @api_key, :transaction_type => @type, :gateway => @gateway, :test => @test_mode)
|
164
|
+
transaction.add_line_item("item1", "Foo", "Bar", "5", "5.00", "TRUE")
|
165
|
+
transaction.purchase(@amount, @credit_card).should be_kind_of(AuthorizeNet::AIM::Response)
|
166
|
+
transaction.response.success?.should be_true
|
167
|
+
transaction.fields[:line_item].should == ["item1<|>Foo<|>Bar<|>5<|>5.00<|>TRUE"]
|
168
|
+
end
|
169
|
+
|
170
|
+
it "should support setting a customer" do
|
171
|
+
transaction = AuthorizeNet::AIM::Transaction.new(@api_login, @api_key, :transaction_type => @type, :gateway => @gateway, :test => @test_mode)
|
172
|
+
customer = AuthorizeNet::Customer.new(:ip => '127.0.0.1')
|
173
|
+
transaction.set_customer(customer)
|
174
|
+
transaction.purchase(@amount, @credit_card).should be_kind_of(AuthorizeNet::AIM::Response)
|
175
|
+
transaction.response.success?.should be_true
|
176
|
+
end
|
177
|
+
|
178
|
+
it "should support setting an address" do
|
179
|
+
transaction = AuthorizeNet::AIM::Transaction.new(@api_login, @api_key, :transaction_type => @type, :gateway => @gateway, :test => @test_mode)
|
180
|
+
address = AuthorizeNet::Address.new(:city => 'San Francisco', :state => 'NY')
|
181
|
+
transaction.set_address(address)
|
182
|
+
transaction.purchase(@amount, @credit_card).should be_kind_of(AuthorizeNet::AIM::Response)
|
183
|
+
transaction.response.success?.should be_true
|
184
|
+
end
|
185
|
+
|
186
|
+
it "should support setting a shipping address" do
|
187
|
+
transaction = AuthorizeNet::AIM::Transaction.new(@api_login, @api_key, :transaction_type => @type, :gateway => @gateway, :test => @test_mode)
|
188
|
+
address = AuthorizeNet::ShippingAddress.new(:city => 'San Francisco', :state => 'NY', :tax => 10.00)
|
189
|
+
transaction.set_shipping_address(address)
|
190
|
+
transaction.purchase(@amount, @credit_card).should be_kind_of(AuthorizeNet::AIM::Response)
|
191
|
+
transaction.response.success?.should be_true
|
192
|
+
end
|
193
|
+
|
194
|
+
it "should support adding an email receipt" do
|
195
|
+
transaction = AuthorizeNet::AIM::Transaction.new(@api_login, @api_key, :transaction_type => @type, :gateway => @gateway, :test => @test_mode)
|
196
|
+
email = AuthorizeNet::EmailReceipt.new(:header => 'TEST!')
|
197
|
+
transaction.set_email_receipt(email)
|
198
|
+
transaction.purchase(@amount, @credit_card).should be_kind_of(AuthorizeNet::AIM::Response)
|
199
|
+
transaction.response.success?.should be_true
|
200
|
+
end
|
201
|
+
|
202
|
+
it "should be able to void a purchase" do
|
203
|
+
purchase = AuthorizeNet::AIM::Transaction.new(@api_login, @api_key, :transaction_type => @type, :gateway => @gateway, :test => false)
|
204
|
+
purchase.purchase(@amount, @credit_card).should be_kind_of(AuthorizeNet::AIM::Response)
|
205
|
+
purchase.response.fields[:amount].should == @amount
|
206
|
+
purchase.response.success?.should be_true
|
207
|
+
void = AuthorizeNet::AIM::Transaction.new(@api_login, @api_key, :gateway => @gateway, :test => false)
|
208
|
+
void.void(purchase.response.transaction_id)
|
209
|
+
void.response.success?.should be_true
|
210
|
+
end
|
211
|
+
|
212
|
+
it "should be able to capture a prior authorization" do
|
213
|
+
auth = AuthorizeNet::AIM::Transaction.new(@api_login, @api_key, :transaction_type => @type, :gateway => @gateway, :test => false)
|
214
|
+
auth.authorize(@amount, @credit_card).should be_kind_of(AuthorizeNet::AIM::Response)
|
215
|
+
auth.response.fields[:amount].should == @amount
|
216
|
+
auth.response.success?.should be_true
|
217
|
+
capture = AuthorizeNet::AIM::Transaction.new(@api_login, @api_key, :gateway => @gateway, :test => false)
|
218
|
+
capture.prior_auth_capture(auth.response.transaction_id)
|
219
|
+
capture.response.success?.should be_true
|
220
|
+
end
|
221
|
+
|
222
|
+
it "should be able to run a card present purchase with track 1 data" do
|
223
|
+
@credit_card = AuthorizeNet::CreditCard.new(nil, nil, :track_1 => '%B4111111111111111^DOE/JOHN^1803101000000000020000831000000?')
|
224
|
+
purchase = AuthorizeNet::AIM::Transaction.new(@cp_api_login, @cp_api_key, :gateway => :card_present_test, :test => false)
|
225
|
+
response = purchase.purchase(@amount, @credit_card)
|
226
|
+
response.success?.should be_true
|
227
|
+
end
|
228
|
+
|
229
|
+
it "should be able to run a card present purchase with LRC codes in the track 1 data" do
|
230
|
+
@credit_card = AuthorizeNet::CreditCard.new(nil, nil, :track_1 => "%B4111111111111111^DOE/JOHN^1803101000000000020000831000000?\xAA")
|
231
|
+
purchase = AuthorizeNet::AIM::Transaction.new(@cp_api_login, @cp_api_key, :gateway => :card_present_test, :test => false)
|
232
|
+
response = purchase.purchase(@amount, @credit_card)
|
233
|
+
response.success?.should be_true
|
234
|
+
end
|
235
|
+
|
236
|
+
it "should be able to run a card present purchase with no LRC or Start/End Sentinels in track 1 data" do
|
237
|
+
@credit_card = AuthorizeNet::CreditCard.new(nil, nil, :track_1 => "B4111111111111111^DOE/JOHN^1803101000000000020000831000000")
|
238
|
+
purchase = AuthorizeNet::AIM::Transaction.new(@cp_api_login, @cp_api_key, :gateway => :card_present_test, :test => false)
|
239
|
+
response = purchase.purchase(@amount, @credit_card)
|
240
|
+
response.success?.should be_true
|
241
|
+
end
|
242
|
+
|
243
|
+
it "should be able to run a card present purchase with track 2 data" do
|
244
|
+
@credit_card = AuthorizeNet::CreditCard.new(nil, nil, :track_2 => ';4111111111111111=1803101000020000831?')
|
245
|
+
purchase = AuthorizeNet::AIM::Transaction.new(@cp_api_login, @cp_api_key, :gateway => :card_present_test, :test => false)
|
246
|
+
response = purchase.purchase(@amount, @credit_card)
|
247
|
+
response.success?.should be_true
|
248
|
+
end
|
249
|
+
|
250
|
+
it "should be able to run a card present purchase with LRC codes in the track 2 data" do
|
251
|
+
@credit_card = AuthorizeNet::CreditCard.new(nil, nil, :track_2 => ";4111111111111111=1803101000020000831?\x33")
|
252
|
+
purchase = AuthorizeNet::AIM::Transaction.new(@cp_api_login, @cp_api_key, :gateway => :card_present_test, :test => false)
|
253
|
+
response = purchase.purchase(@amount, @credit_card)
|
254
|
+
response.success?.should be_true
|
255
|
+
end
|
256
|
+
|
257
|
+
it "should be able to run a card present purchase with no LRC or Start/End Sentinels in track 2 data" do
|
258
|
+
@credit_card = AuthorizeNet::CreditCard.new(nil, nil, :track_2 => "4111111111111111=1803101000020000831")
|
259
|
+
purchase = AuthorizeNet::AIM::Transaction.new(@cp_api_login, @cp_api_key, :gateway => :card_present_test, :test => false)
|
260
|
+
response = purchase.purchase(@amount, @credit_card)
|
261
|
+
response.success?.should be_true
|
262
|
+
end
|
263
|
+
|
264
|
+
it "should be able to validate the passed MD5 hash" do
|
265
|
+
transaction = AuthorizeNet::AIM::Transaction.new(@api_login, @api_key, :transaction_type => @type, :gateway => @gateway, :test => @test_mode)
|
266
|
+
transaction.purchase(@amount, @credit_card).should be_kind_of(AuthorizeNet::AIM::Response)
|
267
|
+
transaction.response.success?.should be_true
|
268
|
+
transaction.response.valid_md5?(@api_login, @md5_value).should be_true
|
269
|
+
end
|
270
|
+
|
271
|
+
it "should be able to validate the passed MD5 hash for card present transactions" do
|
272
|
+
@credit_card = AuthorizeNet::CreditCard.new(nil, nil, :track_1 => '%B4111111111111111^DOE/JOHN^1803101000000000020000831000000?')
|
273
|
+
purchase = AuthorizeNet::AIM::Transaction.new(@cp_api_login, @cp_api_key, :gateway => :card_present_test, :test => false)
|
274
|
+
response = purchase.purchase(@amount, @credit_card)
|
275
|
+
response.success?.should be_true
|
276
|
+
response.valid_md5?(@cp_api_login, @cp_md5_value).should be_true
|
277
|
+
end
|
278
|
+
end
|
279
|
+
|
280
|
+
|
281
|
+
describe AuthorizeNet::AIM::Response do
|
282
|
+
|
283
|
+
before :all do
|
284
|
+
begin
|
285
|
+
creds = YAML.load_file(File.dirname(__FILE__) + "/credentials.yml")
|
286
|
+
@api_key = creds['api_transaction_key']
|
287
|
+
@api_login = creds['api_login_id']
|
288
|
+
rescue Errno::ENOENT => e
|
289
|
+
@api_key = "TEST"
|
290
|
+
@api_login = "TEST"
|
291
|
+
warn "WARNING: Running w/o valid AuthorizeNet sandbox credentials. Create spec/credentials.yml."
|
292
|
+
end
|
293
|
+
end
|
294
|
+
|
295
|
+
before do
|
296
|
+
@cim_response = '1,1,1,This transaction has been approved.,000000,Y,2000000000,none,Test transaction for ValidateCustomerPaymentProfile.,0.01,CC,auth_only,custId123,John,Doe,,123 Main St.,Bellevue,WA,98004,USA,000-000-0000,,mark@example.com,,,,,,,,,0.00,0.00,0.00,,none,D18EB6B211FE0BBF556B271FDA6F92EE,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,'
|
297
|
+
end
|
298
|
+
|
299
|
+
it "should support a Nokogiri based raw_response" do
|
300
|
+
builder = Nokogiri::XML::Builder.new(:encoding => 'utf-8') do |x|
|
301
|
+
x.directResponse(@cim_response)
|
302
|
+
end
|
303
|
+
@element = builder.doc.children[0]
|
304
|
+
@element.should be_kind_of(Nokogiri::XML::Element)
|
305
|
+
transaction = AuthorizeNet::AIM::Transaction.new(@api_login, @api_key, :test => false)
|
306
|
+
response = AuthorizeNet::AIM::Response.new(@element, transaction)
|
307
|
+
response.success?.should be_true
|
308
|
+
response.response_reason_text.should == 'This transaction has been approved.'
|
309
|
+
end
|
310
|
+
end
|
data/spec/arb_spec.rb
ADDED
@@ -0,0 +1,191 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe AuthorizeNet::ARB::Transaction do
|
4
|
+
|
5
|
+
before :all do
|
6
|
+
begin
|
7
|
+
creds = YAML.load_file(File.dirname(__FILE__) + "/credentials.yml")
|
8
|
+
@api_key = creds['api_transaction_key']
|
9
|
+
@api_login = creds['api_login_id']
|
10
|
+
rescue Errno::ENOENT => e
|
11
|
+
@api_key = "TEST"
|
12
|
+
@api_login = "TEST"
|
13
|
+
warn "WARNING: Running w/o valid AuthorizeNet sandbox credentials. Create spec/credentials.yml."
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
before do
|
18
|
+
@gateway = :sandbox
|
19
|
+
@subscription = AuthorizeNet::ARB::Subscription.new(
|
20
|
+
:name => "monthly foo",
|
21
|
+
:length => 1,
|
22
|
+
:unit => AuthorizeNet::ARB::Subscription::IntervalUnits::MONTH,
|
23
|
+
:start_date => Date.today,
|
24
|
+
:total_occurrences => 1,
|
25
|
+
:trial_occurrences => nil,
|
26
|
+
:amount => 10.00,
|
27
|
+
:trial_amount => nil,
|
28
|
+
:invoice_number => rand(),
|
29
|
+
:description => "a test subscription",
|
30
|
+
:subscription_id => nil,
|
31
|
+
:credit_card => AuthorizeNet::CreditCard.new('4111111111111111', '01' + (Time.now + (3600 * 24 * 365)).strftime('%y')),
|
32
|
+
:billing_address => AuthorizeNet::Address.new(:first_name => 'John', :last_name => 'Doe')
|
33
|
+
)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should support instantiation" do
|
37
|
+
AuthorizeNet::ARB::Transaction.new(@api_login, @api_key).should be_instance_of(AuthorizeNet::ARB::Transaction)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should not have a response if the transaction hasn't been run" do
|
41
|
+
transaction = AuthorizeNet::ARB::Transaction.new(@api_login, @api_key, :gateway => @gateway)
|
42
|
+
transaction.has_response?.should be_false
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should support the returning its response object" do
|
46
|
+
transaction = AuthorizeNet::ARB::Transaction.new(@api_login, @api_key, :gateway => @gateway)
|
47
|
+
transaction.should respond_to(:response)
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should know if its running against the sandbox or not" do
|
51
|
+
transaction = AuthorizeNet::ARB::Transaction.new(@api_login, @api_key, :gateway => :sandbox)
|
52
|
+
transaction.test?.should be_true
|
53
|
+
transaction = AuthorizeNet::ARB::Transaction.new(@api_login, @api_key, :gateway => :live)
|
54
|
+
transaction.test?.should be_false
|
55
|
+
transaction = AuthorizeNet::ARB::Transaction.new(@api_login, @api_key, :gateway => 'moose')
|
56
|
+
transaction.test?.should be_true
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should have a response after running a transaction" do
|
60
|
+
transaction = AuthorizeNet::ARB::Transaction.new(@api_login, @api_key, :gateway => :sandbox)
|
61
|
+
response = transaction.create({})
|
62
|
+
response.should be_instance_of(AuthorizeNet::ARB::Response)
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should support creating a subscription" do
|
66
|
+
transaction = AuthorizeNet::ARB::Transaction.new(@api_login, @api_key, :gateway => :sandbox)
|
67
|
+
response = transaction.create(@subscription)
|
68
|
+
response.success?.should be_true
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should support canceling a subscription" do
|
72
|
+
transaction = AuthorizeNet::ARB::Transaction.new(@api_login, @api_key, :gateway => :sandbox)
|
73
|
+
response = transaction.create(@subscription)
|
74
|
+
response.success?.should be_true
|
75
|
+
cancel = AuthorizeNet::ARB::Transaction.new(@api_login, @api_key, :gateway => :sandbox)
|
76
|
+
response = cancel.cancel(response.subscription_id)
|
77
|
+
response.success?.should be_true
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should support getting the status of a subscription" do
|
81
|
+
create = AuthorizeNet::ARB::Transaction.new(@api_login, @api_key, :gateway => :sandbox)
|
82
|
+
response = create.create(@subscription)
|
83
|
+
response.success?.should be_true
|
84
|
+
status = AuthorizeNet::ARB::Transaction.new(@api_login, @api_key, :gateway => :sandbox)
|
85
|
+
response = status.get_status(response.subscription_id)
|
86
|
+
response.success?.should be_true
|
87
|
+
response.subscription_status.should == AuthorizeNet::ARB::Subscription::Status::ACTIVE
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should support updating a subscription" do
|
91
|
+
create = AuthorizeNet::ARB::Transaction.new(@api_login, @api_key, :gateway => :sandbox)
|
92
|
+
response = create.create(@subscription)
|
93
|
+
response.success?.should be_true
|
94
|
+
update = AuthorizeNet::ARB::Transaction.new(@api_login, @api_key, :gateway => :sandbox)
|
95
|
+
subscription = AuthorizeNet::ARB::Subscription.new(:subscription_id => response.subscription_id, :billing_address => AuthorizeNet::Address.new(:first_name => 'Jane', :last_name => 'Doe'))
|
96
|
+
response = update.update(subscription)
|
97
|
+
response.success?.should be_true
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
describe AuthorizeNet::ARB::Response do
|
102
|
+
|
103
|
+
before :all do
|
104
|
+
begin
|
105
|
+
creds = YAML.load_file(File.dirname(__FILE__) + "/credentials.yml")
|
106
|
+
@api_key = creds['api_transaction_key']
|
107
|
+
@api_login = creds['api_login_id']
|
108
|
+
rescue Errno::ENOENT => e
|
109
|
+
@api_key = "TEST"
|
110
|
+
@api_login = "TEST"
|
111
|
+
warn "WARNING: Running w/o valid AuthorizeNet sandbox credentials. Create spec/credentials.yml."
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
before do
|
116
|
+
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should support instantiation" do
|
120
|
+
AuthorizeNet::ARB::Response.new('', nil).should be_instance_of(AuthorizeNet::ARB::Response)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
describe AuthorizeNet::ARB::Subscription do
|
125
|
+
|
126
|
+
before do
|
127
|
+
@attributes = [:name, :length, :unit, :start_date, :total_occurrences, :trial_occurrences, :amount, :trial_amount, :invoice_number, :description, :subscription_id]
|
128
|
+
@attribute_values = {
|
129
|
+
:name => "daily foo",
|
130
|
+
:length => 1,
|
131
|
+
:unit => AuthorizeNet::ARB::Subscription::IntervalUnits::DAY,
|
132
|
+
:start_date => Date.today,
|
133
|
+
:total_occurrences => 1,
|
134
|
+
:trial_occurrences => nil,
|
135
|
+
:amount => 10.00,
|
136
|
+
:trial_amount => nil,
|
137
|
+
:invoice_number => '123456',
|
138
|
+
:description => "a test subscription",
|
139
|
+
:subscription_id => nil,
|
140
|
+
:credit_card => AuthorizeNet::CreditCard.new('4111111111111111', '01' + (Time.now + (3600 * 24 * 365)).strftime('%y')),
|
141
|
+
:billing_address => AuthorizeNet::Address.new(:first_name => 'John', :last_name => 'Doe')
|
142
|
+
}
|
143
|
+
end
|
144
|
+
|
145
|
+
it "should support instantiation" do
|
146
|
+
AuthorizeNet::ARB::Subscription.new().should be_instance_of(AuthorizeNet::ARB::Subscription)
|
147
|
+
end
|
148
|
+
|
149
|
+
it "should support access to its attributes" do
|
150
|
+
subscription = AuthorizeNet::ARB::Subscription.new(@attribute_values)
|
151
|
+
@attribute_values.each do |k, v|
|
152
|
+
subscription.send(k).should == v
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
it "should support connivence values for unlimited subscription length" do
|
157
|
+
subscription = AuthorizeNet::ARB::Subscription.new(:length => :unlimited)
|
158
|
+
subscription.length.should == AuthorizeNet::ARB::Subscription::UNLIMITED_OCCURRENCES
|
159
|
+
subscription = AuthorizeNet::ARB::Subscription.new()
|
160
|
+
subscription.length = :unlimited
|
161
|
+
subscription.length.should == AuthorizeNet::ARB::Subscription::UNLIMITED_OCCURRENCES
|
162
|
+
end
|
163
|
+
|
164
|
+
it "should support connivence values for day interval units" do
|
165
|
+
subscription = AuthorizeNet::ARB::Subscription.new(:unit => :day)
|
166
|
+
subscription.unit.should == AuthorizeNet::ARB::Subscription::IntervalUnits::DAY
|
167
|
+
subscription = AuthorizeNet::ARB::Subscription.new(:unit => :days)
|
168
|
+
subscription.unit.should == AuthorizeNet::ARB::Subscription::IntervalUnits::DAY
|
169
|
+
subscription = AuthorizeNet::ARB::Subscription.new()
|
170
|
+
subscription.unit = :day
|
171
|
+
subscription.unit.should == AuthorizeNet::ARB::Subscription::IntervalUnits::DAY
|
172
|
+
subscription = AuthorizeNet::ARB::Subscription.new()
|
173
|
+
subscription.unit = :days
|
174
|
+
subscription.unit.should == AuthorizeNet::ARB::Subscription::IntervalUnits::DAY
|
175
|
+
end
|
176
|
+
|
177
|
+
it "should support connivence values for month interval units" do
|
178
|
+
subscription = AuthorizeNet::ARB::Subscription.new(:unit => :month)
|
179
|
+
subscription.unit.should == AuthorizeNet::ARB::Subscription::IntervalUnits::MONTH
|
180
|
+
subscription = AuthorizeNet::ARB::Subscription.new(:unit => :months)
|
181
|
+
subscription.unit.should == AuthorizeNet::ARB::Subscription::IntervalUnits::MONTH
|
182
|
+
subscription = AuthorizeNet::ARB::Subscription.new()
|
183
|
+
subscription.unit = :month
|
184
|
+
subscription.unit.should == AuthorizeNet::ARB::Subscription::IntervalUnits::MONTH
|
185
|
+
subscription = AuthorizeNet::ARB::Subscription.new()
|
186
|
+
subscription.unit = :months
|
187
|
+
subscription.unit.should == AuthorizeNet::ARB::Subscription::IntervalUnits::MONTH
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
|