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,200 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe AuthorizeNet do
|
4
|
+
|
5
|
+
it "should have a module called AuthorizeNet" do
|
6
|
+
defined?(AuthorizeNet).should be_true
|
7
|
+
AuthorizeNet.class.should equal(Module)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should have a module called AIM" do
|
11
|
+
defined?(AuthorizeNet::AIM).should be_true
|
12
|
+
AuthorizeNet::AIM.class.should equal(Module)
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
describe AuthorizeNet::CreditCard do
|
18
|
+
|
19
|
+
before do
|
20
|
+
@card_number = '4111111111111111'
|
21
|
+
@expiry = '01' + (Time.now + (3600 * 24 * 365)).strftime('%y')
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should support instantiation" do
|
25
|
+
AuthorizeNet::CreditCard.new(@card_number, @expiry).should be_instance_of(AuthorizeNet::CreditCard)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should support converting itself into a hash" do
|
29
|
+
card = AuthorizeNet::CreditCard.new(@card_number, @expiry)
|
30
|
+
card.should respond_to(:to_hash)
|
31
|
+
card.to_hash.should be_kind_of(Hash)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should have the right payment method type" do
|
35
|
+
card = AuthorizeNet::CreditCard.new(@card_number, @expiry)
|
36
|
+
fields = card.to_hash
|
37
|
+
fields[:method].should == AuthorizeNet::PaymentMethodType::CREDIT_CARD
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should respond to attributes" do
|
41
|
+
card = AuthorizeNet::CreditCard.new(@card_number, @expiry)
|
42
|
+
card.card_number.should == @card_number
|
43
|
+
card.expiration.should == @expiry
|
44
|
+
card.card_code.should be_nil
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe AuthorizeNet::ECheck do
|
49
|
+
|
50
|
+
before do
|
51
|
+
@routing_number = '322271627'
|
52
|
+
@account_number = '123456789'
|
53
|
+
@bank_name = 'JPMorgan Chase Bank'
|
54
|
+
@account_holder_name = 'John Doe'
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should support instantiation" do
|
58
|
+
AuthorizeNet::ECheck.new(@routing_number, @account_number, @bank_name, @account_holder_name).should be_instance_of(AuthorizeNet::ECheck)
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should support converting itself into a hash" do
|
62
|
+
echeck = AuthorizeNet::ECheck.new(@routing_number, @account_number, @bank_name, @account_holder_name)
|
63
|
+
echeck.should respond_to(:to_hash)
|
64
|
+
echeck.to_hash.should be_kind_of(Hash)
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should support payment method code retrival" do
|
68
|
+
echeck = AuthorizeNet::ECheck.new(@routing_number, @account_number, @bank_name, @account_holder_name)
|
69
|
+
fields = echeck.to_hash
|
70
|
+
fields[:method].should == AuthorizeNet::PaymentMethodType::ECHECK
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe AuthorizeNet::Address do
|
75
|
+
|
76
|
+
before do
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should support instantiation" do
|
80
|
+
AuthorizeNet::Address.new.should be_instance_of(AuthorizeNet::Address)
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should support converting itself into a hash" do
|
84
|
+
address = AuthorizeNet::Address.new
|
85
|
+
address.should respond_to(:to_hash)
|
86
|
+
address.to_hash.should be_kind_of(Hash)
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should ignore unknown fields" do
|
90
|
+
address = AuthorizeNet::Address.new(:tax => '123')
|
91
|
+
hash = address.to_hash
|
92
|
+
hash.should be_kind_of(Hash)
|
93
|
+
hash.should == {}
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should accept known fields" do
|
97
|
+
address = AuthorizeNet::Address.new(:first_name => '123')
|
98
|
+
hash = address.to_hash
|
99
|
+
hash.should be_kind_of(Hash)
|
100
|
+
hash.should == {:first_name => '123'}
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
describe AuthorizeNet::ShippingAddress do
|
105
|
+
|
106
|
+
before do
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should support instantiation" do
|
110
|
+
AuthorizeNet::ShippingAddress.new.should be_instance_of(AuthorizeNet::ShippingAddress)
|
111
|
+
end
|
112
|
+
|
113
|
+
it "should support converting itself into a hash" do
|
114
|
+
address = AuthorizeNet::ShippingAddress.new
|
115
|
+
address.should respond_to(:to_hash)
|
116
|
+
address.to_hash.should be_kind_of(Hash)
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should ignore unknown fields" do
|
120
|
+
address = AuthorizeNet::ShippingAddress.new(:pie => '123')
|
121
|
+
hash = address.to_hash
|
122
|
+
hash.should be_kind_of(Hash)
|
123
|
+
hash.should == {}
|
124
|
+
end
|
125
|
+
|
126
|
+
it "should accept known fields" do
|
127
|
+
address = AuthorizeNet::ShippingAddress.new(:first_name => '123')
|
128
|
+
hash = address.to_hash
|
129
|
+
hash.should be_kind_of(Hash)
|
130
|
+
hash.should == {:ship_to_first_name => '123'}
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
describe AuthorizeNet::Customer do
|
135
|
+
|
136
|
+
before do
|
137
|
+
end
|
138
|
+
|
139
|
+
it "should support instantiation" do
|
140
|
+
AuthorizeNet::Customer.new.should be_instance_of(AuthorizeNet::Customer)
|
141
|
+
end
|
142
|
+
|
143
|
+
it "should support converting itself into a hash" do
|
144
|
+
customer = AuthorizeNet::Customer.new
|
145
|
+
customer.should respond_to(:to_hash)
|
146
|
+
customer.to_hash.should be_kind_of(Hash)
|
147
|
+
end
|
148
|
+
|
149
|
+
it "should ignore unknown fields" do
|
150
|
+
customer = AuthorizeNet::Customer.new(:name => '123')
|
151
|
+
hash = customer.to_hash
|
152
|
+
hash.should be_kind_of(Hash)
|
153
|
+
hash.should == {}
|
154
|
+
end
|
155
|
+
|
156
|
+
it "should accept known fields" do
|
157
|
+
customer = AuthorizeNet::Customer.new(:id => '123')
|
158
|
+
hash = customer.to_hash
|
159
|
+
hash.should be_kind_of(Hash)
|
160
|
+
hash.should == {:cust_id => '123'}
|
161
|
+
end
|
162
|
+
|
163
|
+
it "should accept an address record" do
|
164
|
+
address = AuthorizeNet::Address.new(:first_name => 'Tester', :last_name => 'Testerson')
|
165
|
+
customer = AuthorizeNet::Customer.new(:address => address)
|
166
|
+
hash = customer.to_hash
|
167
|
+
hash.should be_kind_of(Hash)
|
168
|
+
hash.should == {:first_name => 'Tester', :last_name => 'Testerson'}
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
describe AuthorizeNet::EmailReceipt do
|
173
|
+
|
174
|
+
before do
|
175
|
+
end
|
176
|
+
|
177
|
+
it "should support instantiation" do
|
178
|
+
AuthorizeNet::EmailReceipt.new.should be_instance_of(AuthorizeNet::EmailReceipt)
|
179
|
+
end
|
180
|
+
|
181
|
+
it "should support converting itself into a hash" do
|
182
|
+
email = AuthorizeNet::EmailReceipt.new
|
183
|
+
email.should respond_to(:to_hash)
|
184
|
+
email.to_hash.should be_kind_of(Hash)
|
185
|
+
end
|
186
|
+
|
187
|
+
it "should ignore unknown fields" do
|
188
|
+
email = AuthorizeNet::EmailReceipt.new(:name => '123')
|
189
|
+
hash = email.to_hash
|
190
|
+
hash.should be_kind_of(Hash)
|
191
|
+
hash.should == {}
|
192
|
+
end
|
193
|
+
|
194
|
+
it "should accept known fields" do
|
195
|
+
email = AuthorizeNet::EmailReceipt.new(:header => '123')
|
196
|
+
hash = email.to_hash
|
197
|
+
hash.should be_kind_of(Hash)
|
198
|
+
hash.should == {:header => '123'}
|
199
|
+
end
|
200
|
+
end
|
data/spec/cim_spec.rb
ADDED
@@ -0,0 +1,450 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe AuthorizeNet::CIM::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
|
+
@chrs = [('a'..'z'),('A'..'Z'),('0'..'9')].map{|i| i.to_a}.flatten
|
16
|
+
end
|
17
|
+
|
18
|
+
before do
|
19
|
+
@gateway = :sandbox
|
20
|
+
@credit_card = AuthorizeNet::CreditCard.new('4111111111111111', '01' + (Time.now + (3600 * 24 * 365)).strftime('%y'))
|
21
|
+
@profile = AuthorizeNet::CIM::CustomerProfile.new(:email => 'test@example.com', :id => (0..19).map{@chrs[rand(@chrs.length)]}.join)
|
22
|
+
@address = AuthorizeNet::Address.new(:first_name => 'Jane', :last_name => 'Doe', :address => '123 Fake St', :city => 'Raccoon Junction', :state => 'WY', :zip => '99999')
|
23
|
+
@partial_auth_address = AuthorizeNet::Address.new(:first_name => 'Jane', :last_name => 'Doe', :address => '123 Fake St', :city => 'Raccoon Junction', :state => 'WY', :zip => '46225')
|
24
|
+
@payment_profile = AuthorizeNet::CIM::PaymentProfile.new(:payment_method => @credit_card)
|
25
|
+
@partial_auth_payment_profile = AuthorizeNet::CIM::PaymentProfile.new(:payment_method => @credit_card, :billing_address => @partial_auth_address)
|
26
|
+
end
|
27
|
+
|
28
|
+
def create_profile(profile)
|
29
|
+
transaction = AuthorizeNet::CIM::Transaction.new(@api_login, @api_key, :gateway => :sandbox)
|
30
|
+
transaction.should respond_to(:create_profile)
|
31
|
+
response = transaction.create_profile(profile)
|
32
|
+
response.success?.should be_true
|
33
|
+
response.profile_id.nil?.should be_false
|
34
|
+
return response.profile_id
|
35
|
+
end
|
36
|
+
|
37
|
+
def delete_profile(profile)
|
38
|
+
transaction = AuthorizeNet::CIM::Transaction.new(@api_login, @api_key, :gateway => :sandbox)
|
39
|
+
response = transaction.delete_profile(profile)
|
40
|
+
response.success?.should be_true
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should support instantiation" do
|
44
|
+
AuthorizeNet::CIM::Transaction.new(@api_login, @api_key).should be_instance_of(AuthorizeNet::CIM::Transaction)
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should not have a response if the transaction hasn't been run" do
|
48
|
+
transaction = AuthorizeNet::CIM::Transaction.new(@api_login, @api_key, :gateway => @gateway)
|
49
|
+
transaction.has_response?.should be_false
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should support the returning its response object" do
|
53
|
+
transaction = AuthorizeNet::CIM::Transaction.new(@api_login, @api_key, :gateway => @gateway)
|
54
|
+
transaction.should respond_to(:response)
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should know if its running against the sandbox or not" do
|
58
|
+
transaction = AuthorizeNet::CIM::Transaction.new(@api_login, @api_key, :gateway => :sandbox)
|
59
|
+
transaction.test?.should be_true
|
60
|
+
transaction = AuthorizeNet::CIM::Transaction.new(@api_login, @api_key, :gateway => :live)
|
61
|
+
transaction.test?.should be_false
|
62
|
+
transaction = AuthorizeNet::CIM::Transaction.new(@api_login, @api_key, :gateway => 'moose')
|
63
|
+
transaction.test?.should be_true
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should be able to create customer profiles" do
|
67
|
+
transaction = AuthorizeNet::CIM::Transaction.new(@api_login, @api_key, :gateway => :sandbox)
|
68
|
+
transaction.should respond_to(:create_profile)
|
69
|
+
response = transaction.create_profile(@profile)
|
70
|
+
response.success?.should be_true
|
71
|
+
response.profile_id.nil?.should be_false
|
72
|
+
response.address_ids.nil?.should be_true
|
73
|
+
response.payment_profile_ids.nil?.should be_true
|
74
|
+
response.validation_responses.nil?.should be_true
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should be able to create customer profiles with payment profiles included" do
|
78
|
+
transaction = AuthorizeNet::CIM::Transaction.new(@api_login, @api_key, :gateway => :sandbox)
|
79
|
+
transaction.should respond_to(:create_profile)
|
80
|
+
@profile.payment_profiles = AuthorizeNet::CIM::PaymentProfile.new(:payment_method => @credit_card)
|
81
|
+
response = transaction.create_profile(@profile)
|
82
|
+
response.success?.should be_true
|
83
|
+
response.profile_id.nil?.should be_false
|
84
|
+
response.address_ids.nil?.should be_true
|
85
|
+
response.payment_profile_ids.nil?.should be_false
|
86
|
+
response.validation_responses.nil?.should be_true
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should be able to create customer profiles with payment profiles included and validated" do
|
90
|
+
transaction = AuthorizeNet::CIM::Transaction.new(@api_login, @api_key, :gateway => :sandbox)
|
91
|
+
transaction.should respond_to(:create_profile)
|
92
|
+
@profile.payment_profiles = AuthorizeNet::CIM::PaymentProfile.new(:payment_method => @credit_card)
|
93
|
+
response = transaction.create_profile(@profile, :validation_mode => :testMode)
|
94
|
+
response.success?.should be_true
|
95
|
+
response.profile_id.nil?.should be_false
|
96
|
+
response.address_ids.nil?.should be_true
|
97
|
+
response.payment_profile_ids.nil?.should be_false
|
98
|
+
valdiation_responses = response.validation_responses
|
99
|
+
valdiation_responses.nil?.should be_false
|
100
|
+
valdiation_responses.length.should == 1
|
101
|
+
valdiation_responses[0].should be_instance_of(AuthorizeNet::AIM::Response)
|
102
|
+
valdiation_responses[0].success?.should be_true
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should be able to delete customer profiles" do
|
106
|
+
# create a profile to delete
|
107
|
+
profile_id = create_profile(@profile)
|
108
|
+
|
109
|
+
# delete it
|
110
|
+
transaction = AuthorizeNet::CIM::Transaction.new(@api_login, @api_key, :gateway => :sandbox)
|
111
|
+
transaction.should respond_to(:delete_profile)
|
112
|
+
response = transaction.delete_profile(profile_id)
|
113
|
+
response.success?.should be_true
|
114
|
+
end
|
115
|
+
|
116
|
+
it "should be able to retrieve customer profiles" do
|
117
|
+
# create a profile to fetch
|
118
|
+
@profile.payment_profiles = AuthorizeNet::CIM::PaymentProfile.new(:payment_method => @credit_card)
|
119
|
+
profile_id = create_profile(@profile)
|
120
|
+
|
121
|
+
# fetch the profile
|
122
|
+
transaction = AuthorizeNet::CIM::Transaction.new(@api_login, @api_key, :gateway => :sandbox)
|
123
|
+
transaction.should respond_to(:get_profile)
|
124
|
+
response = transaction.get_profile(profile_id)
|
125
|
+
response.success?.should be_true
|
126
|
+
profile = response.profile
|
127
|
+
profile.should be_instance_of(AuthorizeNet::CIM::CustomerProfile)
|
128
|
+
profile.payment_profiles.length.should == 1
|
129
|
+
profile.payment_profiles.first.should be_instance_of(AuthorizeNet::CIM::PaymentProfile)
|
130
|
+
|
131
|
+
# delete it
|
132
|
+
delete_profile(profile)
|
133
|
+
end
|
134
|
+
|
135
|
+
it "should be able to update customer profiles" do
|
136
|
+
# build a profile
|
137
|
+
profile_id = create_profile(@profile)
|
138
|
+
|
139
|
+
@profile.customer_profile_id = profile_id
|
140
|
+
@profile.fax = '5551112222'
|
141
|
+
transaction = AuthorizeNet::CIM::Transaction.new(@api_login, @api_key, :gateway => :sandbox)
|
142
|
+
transaction.should respond_to(:update_profile)
|
143
|
+
response = transaction.update_profile(@profile)
|
144
|
+
response.success?.should be_true
|
145
|
+
|
146
|
+
delete_profile(profile_id)
|
147
|
+
end
|
148
|
+
|
149
|
+
describe "performing actions on payment profiles" do
|
150
|
+
|
151
|
+
def create_payment_profile(payment_profile, profile, validation_mode = :none)
|
152
|
+
transaction = AuthorizeNet::CIM::Transaction.new(@api_login, @api_key, :gateway => :sandbox)
|
153
|
+
transaction.should respond_to(:create_payment_profile)
|
154
|
+
response = transaction.create_payment_profile(payment_profile, profile, :validation_mode => validation_mode)
|
155
|
+
response.success?.should be_true
|
156
|
+
response.payment_profile_id.nil?.should be_false
|
157
|
+
response.validation_responses.nil?.should be_true
|
158
|
+
return response.payment_profile_id
|
159
|
+
end
|
160
|
+
|
161
|
+
before do
|
162
|
+
@profile.customer_profile_id = create_profile(@profile)
|
163
|
+
@payment_profile.customer_payment_profile_id = create_payment_profile(@payment_profile, @profile)
|
164
|
+
end
|
165
|
+
|
166
|
+
after do
|
167
|
+
delete_profile(@profile)
|
168
|
+
end
|
169
|
+
|
170
|
+
it "should be able to create payment profiles" do
|
171
|
+
# handled by our before/after filters
|
172
|
+
end
|
173
|
+
|
174
|
+
it "should be able to delete payment profiles" do
|
175
|
+
# delete the payment profile
|
176
|
+
transaction = AuthorizeNet::CIM::Transaction.new(@api_login, @api_key, :gateway => :sandbox)
|
177
|
+
transaction.should respond_to(:delete_payment_profile)
|
178
|
+
response = transaction.delete_payment_profile(@payment_profile, @profile)
|
179
|
+
response.success?.should be_true
|
180
|
+
end
|
181
|
+
|
182
|
+
it "should be able to retrieve payment profiles" do
|
183
|
+
# get the payment profile
|
184
|
+
transaction = AuthorizeNet::CIM::Transaction.new(@api_login, @api_key, :gateway => :sandbox)
|
185
|
+
transaction.should respond_to(:get_payment_profile)
|
186
|
+
response = transaction.get_payment_profile(@payment_profile, @profile)
|
187
|
+
response.success?.should be_true
|
188
|
+
response.payment_profile.should be_kind_of(AuthorizeNet::CIM::PaymentProfile)
|
189
|
+
end
|
190
|
+
|
191
|
+
it "should be able to update payment profiles" do
|
192
|
+
@payment_profile.cust_type = :business
|
193
|
+
|
194
|
+
transaction = AuthorizeNet::CIM::Transaction.new(@api_login, @api_key, :gateway => :sandbox)
|
195
|
+
transaction.should respond_to(:update_payment_profile)
|
196
|
+
response = transaction.update_payment_profile(@payment_profile, @profile)
|
197
|
+
response.success?.should be_true
|
198
|
+
end
|
199
|
+
|
200
|
+
it "should be able to validate payment profiles" do
|
201
|
+
@payment_profile.cust_type = :business
|
202
|
+
|
203
|
+
transaction = AuthorizeNet::CIM::Transaction.new(@api_login, @api_key, :gateway => :sandbox)
|
204
|
+
transaction.should respond_to(:update_payment_profile)
|
205
|
+
response = transaction.update_payment_profile(@payment_profile, @profile, :validation_mode => :testMode)
|
206
|
+
response.success?.should be_true
|
207
|
+
response.validation_response.nil?.should be_false
|
208
|
+
response.validation_response.should be_instance_of(AuthorizeNet::AIM::Response)
|
209
|
+
response.validation_response.success?.should be_true
|
210
|
+
end
|
211
|
+
|
212
|
+
describe "should be able to create payment transactions" do
|
213
|
+
|
214
|
+
before do
|
215
|
+
@amount = (rand(10000) + 100) / 100.0
|
216
|
+
end
|
217
|
+
|
218
|
+
it "should support authorization and capture transactions" do
|
219
|
+
transaction = AuthorizeNet::CIM::Transaction.new(@api_login, @api_key, :gateway => :sandbox)
|
220
|
+
transaction.should respond_to(:create_transaction_auth_capture)
|
221
|
+
response = transaction.create_transaction_auth_capture(@amount, @profile, @payment_profile, AuthorizeNet::Order.new())
|
222
|
+
response.success?.should be_true
|
223
|
+
direct_response = response.direct_response
|
224
|
+
direct_response.should be_instance_of(AuthorizeNet::AIM::Response)
|
225
|
+
direct_response.success?.should be_true
|
226
|
+
end
|
227
|
+
|
228
|
+
it "should support authorization only transactions" do
|
229
|
+
transaction = AuthorizeNet::CIM::Transaction.new(@api_login, @api_key, :gateway => :sandbox)
|
230
|
+
transaction.should respond_to(:create_transaction_auth_only)
|
231
|
+
response = transaction.create_transaction_auth_only(@amount, @profile, @payment_profile, AuthorizeNet::Order.new())
|
232
|
+
response.success?.should be_true
|
233
|
+
direct_response = response.direct_response
|
234
|
+
direct_response.should be_instance_of(AuthorizeNet::AIM::Response)
|
235
|
+
direct_response.success?.should be_true
|
236
|
+
end
|
237
|
+
|
238
|
+
it "should support prior authorization capture transactions" do
|
239
|
+
# create an auth only transaction
|
240
|
+
transaction = AuthorizeNet::CIM::Transaction.new(@api_login, @api_key, :gateway => :sandbox)
|
241
|
+
response = transaction.create_transaction_auth_only(@amount + 10, @profile, @payment_profile, AuthorizeNet::Order.new())
|
242
|
+
response.success?.should be_true
|
243
|
+
direct_response = response.direct_response
|
244
|
+
direct_response.success?.should be_true
|
245
|
+
|
246
|
+
# capture it
|
247
|
+
transaction = AuthorizeNet::CIM::Transaction.new(@api_login, @api_key, :gateway => :sandbox)
|
248
|
+
transaction.should respond_to(:create_transaction_prior_auth_capture)
|
249
|
+
response = transaction.create_transaction_prior_auth_capture(direct_response.transaction_id, @amount)
|
250
|
+
response.success?.should be_true
|
251
|
+
direct_response = response.direct_response
|
252
|
+
direct_response.should be_instance_of(AuthorizeNet::AIM::Response)
|
253
|
+
direct_response.success?.should be_true
|
254
|
+
end
|
255
|
+
|
256
|
+
it "should support voiding a transaction" do
|
257
|
+
# create a transaction
|
258
|
+
transaction = AuthorizeNet::CIM::Transaction.new(@api_login, @api_key, :gateway => :sandbox)
|
259
|
+
response = transaction.create_transaction_auth_capture(@amount, @profile, @payment_profile, AuthorizeNet::Order.new())
|
260
|
+
response.success?.should be_true
|
261
|
+
direct_response = response.direct_response
|
262
|
+
direct_response.success?.should be_true
|
263
|
+
|
264
|
+
# void it
|
265
|
+
transaction = AuthorizeNet::CIM::Transaction.new(@api_login, @api_key, :gateway => :sandbox)
|
266
|
+
transaction.should respond_to(:create_transaction_void)
|
267
|
+
response = transaction.create_transaction_void(direct_response.transaction_id)
|
268
|
+
response.success?.should be_true
|
269
|
+
direct_response = response.direct_response
|
270
|
+
direct_response.should be_instance_of(AuthorizeNet::AIM::Response)
|
271
|
+
direct_response.success?.should be_true
|
272
|
+
end
|
273
|
+
|
274
|
+
it "should support refunding a transaction"
|
275
|
+
|
276
|
+
it "should support capture only transactions"
|
277
|
+
|
278
|
+
it "should be able to support multiple payment profiles" do
|
279
|
+
@partial_auth_payment_profile.customer_payment_profile_id = create_payment_profile(@partial_auth_payment_profile, @profile)
|
280
|
+
@partial_auth_payment_profile.customer_payment_profile_id.nil?.should be_false
|
281
|
+
end
|
282
|
+
|
283
|
+
it "should support validating a payment profile" do
|
284
|
+
transaction = AuthorizeNet::CIM::Transaction.new(@api_login, @api_key, :gateway => :sandbox)
|
285
|
+
transaction.should respond_to(:validate_payment_profile)
|
286
|
+
response = transaction.validate_payment_profile(@payment_profile, @profile)
|
287
|
+
response.success?.should be_true
|
288
|
+
direct_response = response.direct_response
|
289
|
+
direct_response.should be_instance_of(AuthorizeNet::AIM::Response)
|
290
|
+
direct_response.success?.should be_true
|
291
|
+
end
|
292
|
+
|
293
|
+
it "should support custom delimiters" do
|
294
|
+
transaction = AuthorizeNet::CIM::Transaction.new(@api_login, @api_key, :gateway => :sandbox)
|
295
|
+
response = transaction.create_transaction_auth_capture(@amount, @profile, @payment_profile, AuthorizeNet::Order.new(), :aim_options => {:delim_char => '$'})
|
296
|
+
response.success?.should be_true
|
297
|
+
direct_response = response.direct_response
|
298
|
+
direct_response.success?.should be_true
|
299
|
+
end
|
300
|
+
|
301
|
+
it "should support custom fields" do
|
302
|
+
transaction = AuthorizeNet::CIM::Transaction.new(@api_login, @api_key, :gateway => :sandbox)
|
303
|
+
response = transaction.create_transaction_auth_capture(@amount, @profile, @payment_profile, AuthorizeNet::Order.new(), :custom_fields => {:foo => '123', :bar => '456'})
|
304
|
+
response.success?.should be_true
|
305
|
+
direct_response = response.direct_response
|
306
|
+
direct_response.success?.should be_true
|
307
|
+
direct_response.custom_fields[:foo].should == '123'
|
308
|
+
direct_response.custom_fields[:bar].should == '456'
|
309
|
+
end
|
310
|
+
|
311
|
+
it "should support custom fields with custom delimeters" do
|
312
|
+
transaction = AuthorizeNet::CIM::Transaction.new(@api_login, @api_key, :gateway => :sandbox)
|
313
|
+
response = transaction.create_transaction_auth_capture(@amount, @profile, @payment_profile, AuthorizeNet::Order.new(), :custom_fields => {:foo => '123', :bar => '456'}, :aim_options => {:delim_char => '$'})
|
314
|
+
response.success?.should be_true
|
315
|
+
direct_response = response.direct_response
|
316
|
+
direct_response.success?.should be_true
|
317
|
+
direct_response.custom_fields[:foo].should == '123'
|
318
|
+
direct_response.custom_fields[:bar].should == '456'
|
319
|
+
end
|
320
|
+
|
321
|
+
describe "should be able to update split transaction statuses" do
|
322
|
+
|
323
|
+
before do
|
324
|
+
# create partial payment profile
|
325
|
+
@partial_auth_payment_profile.customer_payment_profile_id = create_payment_profile(@partial_auth_payment_profile, @profile)
|
326
|
+
|
327
|
+
# create partial payment transaciton
|
328
|
+
transaction = AuthorizeNet::CIM::Transaction.new(@api_login, @api_key, :gateway => :sandbox)
|
329
|
+
transaction.should respond_to(:create_transaction_auth_capture)
|
330
|
+
response = transaction.create_transaction_auth_capture(@amount, @profile, @partial_auth_payment_profile, AuthorizeNet::Order.new(), :aim_options => {:allow_partial_auth => true})
|
331
|
+
response.success?.should be_true
|
332
|
+
direct_response = response.direct_response
|
333
|
+
direct_response.should be_instance_of(AuthorizeNet::AIM::Response)
|
334
|
+
direct_response.success?.should be_false
|
335
|
+
direct_response.response_code.should == AuthorizeNet::AIM::Response::ResponseCode::HELD
|
336
|
+
direct_response.fields[:amount].should == 1.23
|
337
|
+
direct_response.fields[:split_tender_id].nil?.should be_false
|
338
|
+
new_amount = @amount - direct_response.fields[:amount]
|
339
|
+
@split_tender_id = direct_response.fields[:split_tender_id]
|
340
|
+
|
341
|
+
# create transaction for the remaining value
|
342
|
+
|
343
|
+
transaction = AuthorizeNet::CIM::Transaction.new(@api_login, @api_key, :gateway => :sandbox)
|
344
|
+
transaction.should respond_to(:create_transaction_auth_capture)
|
345
|
+
response = transaction.create_transaction_auth_capture(new_amount, @profile, @partial_auth_payment_profile, AuthorizeNet::Order.new(), :aim_options => {:split_tender_id => @split_tender_id})
|
346
|
+
response.success?.should be_true
|
347
|
+
direct_response = response.direct_response
|
348
|
+
direct_response.should be_instance_of(AuthorizeNet::AIM::Response)
|
349
|
+
direct_response.success?.should be_true
|
350
|
+
end
|
351
|
+
|
352
|
+
it "should be able to complete a split transaction" do
|
353
|
+
transaction = AuthorizeNet::CIM::Transaction.new(@api_login, @api_key, :gateway => :sandbox)
|
354
|
+
transaction.should respond_to(:update_split_tender)
|
355
|
+
response = transaction.update_split_tender(@split_tender_id, :completed)
|
356
|
+
response.success?.should be_true
|
357
|
+
end
|
358
|
+
|
359
|
+
it "should be able to void a split transaction" do
|
360
|
+
transaction = AuthorizeNet::CIM::Transaction.new(@api_login, @api_key, :gateway => :sandbox)
|
361
|
+
transaction.should respond_to(:update_split_tender)
|
362
|
+
response = transaction.update_split_tender(@split_tender_id, :voided)
|
363
|
+
response.success?.should be_true
|
364
|
+
end
|
365
|
+
end
|
366
|
+
end
|
367
|
+
end
|
368
|
+
|
369
|
+
describe "performing actions on addresses" do
|
370
|
+
|
371
|
+
def create_address(address, profile)
|
372
|
+
transaction = AuthorizeNet::CIM::Transaction.new(@api_login, @api_key, :gateway => :sandbox)
|
373
|
+
transaction.should respond_to(:create_address)
|
374
|
+
response = transaction.create_address(address, profile)
|
375
|
+
response.success?.should be_true
|
376
|
+
response.address_id.nil?.should be_false
|
377
|
+
|
378
|
+
return response.address_id
|
379
|
+
end
|
380
|
+
|
381
|
+
before do
|
382
|
+
@profile.customer_profile_id = create_profile(@profile)
|
383
|
+
@address.customer_address_id = create_address(@address, @profile)
|
384
|
+
end
|
385
|
+
|
386
|
+
after do
|
387
|
+
delete_profile(@profile)
|
388
|
+
end
|
389
|
+
|
390
|
+
it "should be able to create addresses" do
|
391
|
+
# our before and after filters handle it all
|
392
|
+
end
|
393
|
+
|
394
|
+
it "should be able to delete addresses" do
|
395
|
+
transaction = AuthorizeNet::CIM::Transaction.new(@api_login, @api_key, :gateway => :sandbox)
|
396
|
+
transaction.should respond_to(:delete_address)
|
397
|
+
response = transaction.delete_address(@address, @profile)
|
398
|
+
response.success?.should be_true
|
399
|
+
end
|
400
|
+
|
401
|
+
it "should be able to retrieve addresses" do
|
402
|
+
transaction = AuthorizeNet::CIM::Transaction.new(@api_login, @api_key, :gateway => :sandbox)
|
403
|
+
transaction.should respond_to(:get_address)
|
404
|
+
response = transaction.get_address(@address, @profile)
|
405
|
+
response.success?.should be_true
|
406
|
+
response.address.should be_kind_of(AuthorizeNet::Address)
|
407
|
+
end
|
408
|
+
|
409
|
+
it "should be able to update addresses" do
|
410
|
+
@address.zip = '55555'
|
411
|
+
transaction = AuthorizeNet::CIM::Transaction.new(@api_login, @api_key, :gateway => :sandbox)
|
412
|
+
transaction.should respond_to(:update_address)
|
413
|
+
response = transaction.update_address(@address, @profile)
|
414
|
+
response.success?.should be_true
|
415
|
+
end
|
416
|
+
|
417
|
+
end
|
418
|
+
|
419
|
+
it "should be able to get all profile ids" do
|
420
|
+
transaction = AuthorizeNet::CIM::Transaction.new(@api_login, @api_key, :gateway => :sandbox)
|
421
|
+
transaction.should respond_to(:get_profile_ids)
|
422
|
+
response = transaction.get_profile_ids
|
423
|
+
response.should be_kind_of(AuthorizeNet::CIM::Response)
|
424
|
+
response.success?.should be_true
|
425
|
+
response.profile_ids.nil?.should be_false
|
426
|
+
end
|
427
|
+
end
|
428
|
+
|
429
|
+
describe AuthorizeNet::CIM::Response do
|
430
|
+
|
431
|
+
before :all do
|
432
|
+
begin
|
433
|
+
creds = YAML.load_file(File.dirname(__FILE__) + "/credentials.yml")
|
434
|
+
@api_key = creds['api_transaction_key']
|
435
|
+
@api_login = creds['api_login_id']
|
436
|
+
rescue Errno::ENOENT => e
|
437
|
+
@api_key = "TEST"
|
438
|
+
@api_login = "TEST"
|
439
|
+
warn "WARNING: Running w/o valid AuthorizeNet sandbox credentials. Create spec/credentials.yml."
|
440
|
+
end
|
441
|
+
end
|
442
|
+
|
443
|
+
before do
|
444
|
+
|
445
|
+
end
|
446
|
+
|
447
|
+
it "should support instantiation" do
|
448
|
+
AuthorizeNet::CIM::Response.new('', nil).should be_instance_of(AuthorizeNet::CIM::Response)
|
449
|
+
end
|
450
|
+
end
|