Skip to content

Commit 953614c

Browse files
author
Joe Van Dyk
committed
initial import from 1.5.2
0 parents  commit 953614c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+6765
-0
lines changed

License.pdf

222 KB
Binary file not shown.

README.rdoc

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
= Authorize.Net Ruby SDK
2+
3+
The Authorize.Net Ruby SDK is meant to offer an alternate object-oriented
4+
model of development with the Authorize.net APIs (Version 3.1). The SDK is
5+
based entirely off the name-value pair API, but performs the core payment
6+
activities (such as error handling/parsing, network communication, and data
7+
encoding) behind the scenes. Providing the end developer with this allows the
8+
developer to start integrating immediately without having to write out a mass
9+
of boiler plate code.
10+
11+
== Prerequisites
12+
13+
* Ruby 1.8.7 or higher
14+
* Nokogiri 1.4.3 or higher
15+
* RubyGem 1.3.7 or higher (to build the gem)
16+
* RDoc 1.0 or higher (to build documentation)
17+
* Rake 0.8.7 or higher (to use the rake tasks)
18+
19+
== Installation
20+
21+
Goto the Authorize.Net SDK download page and download the Ruby gem. Then
22+
23+
> gem install authorize-net-1.5.1.gem
24+
25+
== Usage
26+
27+
=== Advanced Merchant Integration (AIM)
28+
29+
require 'rubygems'
30+
require 'authorize_net'
31+
32+
transaction = AuthorizeNet::AIM::Transaction.new('API_LOGIN', 'API_KEY', :gateway => :sandbox)
33+
credit_card = AuthorizeNet::CreditCard.new('4111111111111111', '1120')
34+
response = transaction.purchase('10.00', credit_card)
35+
36+
if response.success?
37+
puts "Successfully made a purchase (authorization code: #{response.authorization_code})"
38+
else
39+
raise "Failed to make purchase."
40+
end
41+
42+
=== Direct Post Method (DPM)
43+
44+
A generator is provided to aid in setting up a Direct Post Method application. In the example below +payments+ is the name of the controller to generate.
45+
46+
> sudo gem install rails -v '~> 2.1'
47+
> rails my_direct_post_app
48+
> cd my_direct_post_app
49+
> script/generate authorize_net_direct_post payments YOUR_API_LOGIN_ID YOUR_TRANSACTION_KEY MERCH_HASH_KEY
50+
> script/server
51+
52+
After running the generator you will probably want to customize the payment form found in <tt>app/views/payments/payment.erb</tt> and the receipt found in <tt>app/views/payments/receipt.erb</tt>.
53+
54+
There is also a default layout generated, <tt>app/views/layouts/authorize_net.erb</tt>. If you already have your own layout, you can delete that file and the reference to it in the controller (<tt>app/controllers/payments_controller.rb</tt>).
55+
56+
=== Server Integration Method (SIM)
57+
58+
A generator is provided to aid in setting up a Server Integration Method application. In the example below +payments+ is the name of the controller to generate.
59+
60+
> sudo gem install rails -v '~> 2.1'
61+
> rails my_sim_app
62+
> cd my_sim_app
63+
> script/generate authorize_net_sim payments YOUR_API_LOGIN_ID YOUR_TRANSACTION_KEY MERCH_HASH_KEY
64+
> script/server
65+
66+
After running the generator you will probably want to customize the payment page found in <tt>app/views/payments/payment.erb</tt> and the thank you page found in <tt>app/views/payments/thank_you.erb</tt>.
67+
68+
You may also want to customize the actual payment form and receipt pages. That can be done by making the necessary changes to the AuthorizeNet::SIM::Transaction object (<tt>@sim_transaction</tt>) found in the +payment+ action in <tt>app/controllers/payments_controller.rb</tt>. The styling of those hosted pages are controlled by the AuthorizeNet::SIM::HostedReceiptPage and AuthorizeNet::SIM::HostedPaymentForm objects (which are passed to the AuthorizeNet::SIM::Transaction).
69+
70+
There is also a default layout generated, <tt>app/views/layouts/authorize_net.erb</tt>. If you already have your own layout, you can delete that file and the reference to it in the controller (<tt>app/controllers/payments_controller.rb</tt>).
71+
72+
=== Automated Recurring Billing (ARB)
73+
74+
require 'rubygems'
75+
require 'authorize_net'
76+
77+
transaction = AuthorizeNet::ARB::Transaction.new('API_LOGIN', 'API_KEY', :gateway => :sandbox)
78+
subscription = AuthorizeNet::ARB::Subscription.new(
79+
:name => "Monthly Gift Basket",
80+
:length => 1,
81+
:unit => :month,
82+
:start_date => Date.today,
83+
:total_occurrences => :unlimited,
84+
:amount => 100.00,
85+
:invoice_number => '1234567',
86+
:description => "John Doe's Monthly Gift Basket",
87+
:credit_card => AuthorizeNet::CreditCard.new('4111111111111111', '1120'),
88+
:billing_address => AuthorizeNet::Address.new(:first_name => 'John', :last_name => 'Doe')
89+
)
90+
response = transaction.create(subscription)
91+
92+
if response.success?
93+
puts "Successfully created a subscription (subscription id: #{response.subscription_id})"
94+
else
95+
raise "Failed to create a subscription."
96+
end
97+
98+
=== Card Present (CP)
99+
100+
require 'rubygems'
101+
require 'authorize_net'
102+
103+
transaction = AuthorizeNet::AIM::Transaction.new('API_LOGIN', 'API_KEY', :gateway => :card_present_sandbox)
104+
credit_card = AuthorizeNet::CreditCard.new(nil, nil, :track_1 => '%B4111111111111111^DOE/JOHN^1803101000000000020000831000000?')
105+
response = transaction.purchase('10.00', credit_card)
106+
107+
if response.success?
108+
puts "Successfully made a purchase (authorization code: #{response.authorization_code})"
109+
else
110+
raise "Failed to make purchase."
111+
end
112+
113+
== Credit Card Test Numbers
114+
115+
For your reference, you can use the following test credit card numbers.
116+
The expiration date must be set to the present date or later. Use 123 for
117+
the CCV code.
118+
119+
American Express:: 370000000000002
120+
Discover:: 6011000000000012
121+
Visa:: 4007000000027
122+
JCB:: 3088000000000017
123+
Diners Club/ Carte Blanche:: 38000000000006
124+
Visa (Card Present Track 1):: %B4111111111111111^DOE/JOHN^1803101000000000020000831000000?

Rakefile

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
require "rake"
2+
require "spec/rake/spectask"
3+
4+
task :default => :spec
5+
desc "Run all specs"
6+
Spec::Rake::SpecTask.new('spec') do |t|
7+
t.spec_files = FileList['spec/**/*_spec.rb']
8+
t.spec_opts = ['--options', 'spec/spec.opts']
9+
end
10+
11+
namespace "spec" do
12+
desc "Run the CIM spec"
13+
Spec::Rake::SpecTask.new('cim') do |t|
14+
t.spec_files = FileList['spec/cim_spec.rb']
15+
t.spec_opts = ['--options', 'spec/spec.opts']
16+
end
17+
18+
desc "Run the ARB spec"
19+
Spec::Rake::SpecTask.new('arb') do |t|
20+
t.spec_files = FileList['spec/arb_spec.rb']
21+
t.spec_opts = ['--options', 'spec/spec.opts']
22+
end
23+
24+
desc "Run the AIM spec"
25+
Spec::Rake::SpecTask.new('aim') do |t|
26+
t.spec_files = FileList['spec/aim_spec.rb']
27+
t.spec_opts = ['--options', 'spec/spec.opts']
28+
end
29+
30+
desc "Run the SIM spec"
31+
Spec::Rake::SpecTask.new('sim') do |t|
32+
t.spec_files = FileList['spec/sim_spec.rb']
33+
t.spec_opts = ['--options', 'spec/spec.opts']
34+
end
35+
36+
desc "Run the Reporting spec"
37+
Spec::Rake::SpecTask.new('reporting') do |t|
38+
t.spec_files = FileList['spec/reporting_spec.rb']
39+
t.spec_opts = ['--options', 'spec/spec.opts']
40+
end
41+
end
42+
43+
desc "Builds the gem"
44+
task :gem do
45+
%x"gem build authorize-net.gemspec"
46+
end
47+
48+
desc "Builds the documentation"
49+
task :doc do
50+
%x"rdoc -U -S --main=README.rdoc -A documented_accessor=RW README.rdoc lib/"
51+
end
52+
53+
namespace "doc" do
54+
desc "Builds the documentation with graphical class hierarchy"
55+
task :graph do
56+
%x"rdoc -U -d -S --main=README.rdoc -A documented_accessor=RW README.rdoc lib/"
57+
end
58+
end
59+
60+
desc "Builds the documentation (alias of :doc)"
61+
task :rdoc do
62+
Rake::Task[:doc].execute
63+
end
64+
65+
desc "Bundles the sample app."
66+
task :samples do
67+
%x". sample_app_version && zip -r anet_ruby_samples-$VERSION.zip sample_app -x '*/.*' -x '*/Icon' -x '*/__MACOSX'"
68+
end
69+
70+
desc "Bundles the sample app and gem."
71+
task :bundle do
72+
Rake::Task[:samples].execute
73+
Rake::Task[:gem].execute
74+
end
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Description:
2+
Generates a simple implementation of Authorize.Net's Direct Post Method integration method.
3+
4+
Example:
5+
./script/generate authorize_net_direct_post payments API_LOGIN_ID API_TRANSACTION_KEY MERCHANT_HASH_VALUE
6+
7+
This will create:
8+
README-AuthorizeNet
9+
app/views/payments
10+
app/views/payments/payment.erb
11+
app/views/payments/receipt.erb
12+
app/views/payments/relay_response.erb
13+
app/views/layouts/authorize_net.erb
14+
config/authorize_net.yml
15+
config/initializers/authorize_net.rb
16+
app/controller/payments_controller.rb
17+
route payment_payment
18+
route payment_receipt
19+
route payment_relay_response
20+
gem authorize-net
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
require File.join(File.dirname(__FILE__), '..', 'generator_extensions.rb')
2+
3+
class AuthorizeNetDirectPostGenerator < Rails::Generator::NamedBase
4+
def manifest
5+
record do |m|
6+
m.file "README-AuthorizeNet", "README-AuthorizeNet"
7+
m.directory "app/views/#{file_name}"
8+
m.file "payment.erb", "app/views/#{file_name}/payment.erb"
9+
m.file "receipt.erb", "app/views/#{file_name}/receipt.erb"
10+
m.file "relay_response.erb", "app/views/#{file_name}/relay_response.erb"
11+
m.file "layout.erb", "app/views/layouts/authorize_net.erb"
12+
m.template "config.yml.erb", "config/authorize_net.yml"
13+
m.file "initializer.rb", "config/initializers/authorize_net.rb"
14+
m.template "controller.rb.erb", "app/controllers/#{file_name}_controller.rb"
15+
m.route :name => "#{singular_name}_receipt", :path => "/#{plural_name}/receipt", :controller => file_name, :action => 'receipt', :conditions => "{:method => :get}"
16+
m.route :name => "#{singular_name}_relay_response", :path => "/#{plural_name}/relay_response", :controller => file_name, :action => 'relay_response', :conditions => "{:method => :post}"
17+
m.route :name => "#{singular_name}_payment", :path => "/#{plural_name}/payment", :controller => file_name, :action => 'payment', :conditions => "{:method => :get}"
18+
m.gem :name => 'authorize-net'
19+
end
20+
end
21+
end
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
= Authorize.Net Ruby SDK
2+
3+
The Authorize.Net Ruby SDK is meant to offer an alternate object-oriented
4+
model of development with the Authorize.net APIs (Version 3.1). The SDK is
5+
based entirely off the name-value pair API, but performs the core payment
6+
activities (such as error handling/parsing, network communication, and data
7+
encoding) behind the scenes. Providing the end developer with this allows the
8+
developer to start integrating immediately without having to write out a mass
9+
of boiler plate code.
10+
11+
== Prerequisites
12+
13+
* Ruby 1.8.7 or higher
14+
* RubyGem 1.3.7 or higher (to build the gem)
15+
* RDoc 1.0 or higher (to build documentation)
16+
* Rake 0.8.7 or higher (to use the rake tasks)
17+
18+
== Installation
19+
20+
Goto the Authorize.Net SDK download page and download the Ruby gem. Then
21+
22+
> gem install authorize-net-1.0.0.gem
23+
24+
== Usage
25+
26+
A generator is provided to aid in setting up a Direct Post Method application. In the example below 'payments' is the name of the controller to generate.
27+
28+
> sudo gem install rails -v '~> 2.1'
29+
> rails my_direct_post_app
30+
> cd my_direct_post_app
31+
> script/generate authorize_net_direct_post payments YOUR_API_LOGIN_ID YOUR_TRANSACTION_KEY MERCH_HASH_KEY
32+
> script/server
33+
34+
After running the generator you will probably want to customize the payment form found in 'app/views/payments/payment.erb' and the receipt found in 'app/views/payments/receipt.erb'.
35+
36+
There is also a default layout generated, 'app/views/layouts/authorize_net.erb'. If you already have your own layout, you can delete that file and the reference to it in the controller ('app/controllers/payments_controller.rb').
37+
38+
39+
== Credit Card Test Numbers
40+
41+
For your reference, you can use the following test credit card numbers.
42+
The expiration date must be set to the present date or later. Use 123 for
43+
the CCV code.
44+
45+
American Express:: 370000000000002
46+
Discover:: 6011000000000012
47+
Visa:: 4007000000027
48+
JCB:: 3088000000000017
49+
Diners Club/ Carte Blanche:: 38000000000006
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
default:
2+
api_login_id: <%= args[0] %>
3+
api_transaction_key: <%= args[1] %>
4+
merchant_hash_value: <%= args[2] %>
5+
6+
development:
7+
test:
8+
production:
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
default:
2+
api_login_id: <%= self.api_login_id %>
3+
api_transaction_key: <%= self.api_transaction_key %>
4+
merchant_hash_value: <%= self.merchant_hash_value %>
5+
6+
development:
7+
test:
8+
production:
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
class <%= class_name %>Controller < ApplicationController
2+
3+
layout 'authorize_net'
4+
helper :authorize_net
5+
protect_from_forgery :except => :relay_response
6+
7+
# GET
8+
# Displays a payment form.
9+
def payment
10+
@amount = 10.00
11+
@sim_transaction = AuthorizeNet::SIM::Transaction.new(AUTHORIZE_NET_CONFIG['api_login_id'], AUTHORIZE_NET_CONFIG['api_transaction_key'], @amount, :relay_url => <%= singular_name %>_relay_response_url(:only_path => false))
12+
end
13+
14+
# POST
15+
# Returns relay response when Authorize.Net POSTs to us.
16+
def relay_response
17+
sim_response = AuthorizeNet::SIM::Response.new(params)
18+
if sim_response.success?(AUTHORIZE_NET_CONFIG['api_login_id'], AUTHORIZE_NET_CONFIG['merchant_hash_value'])
19+
render :text => sim_response.direct_post_reply(<%= singular_name %>_receipt_url(:only_path => false), :include => true)
20+
else
21+
render
22+
end
23+
end
24+
25+
# GET
26+
# Displays a receipt.
27+
def receipt
28+
@auth_code = params[:x_auth_code]
29+
end
30+
31+
end
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
yml = YAML.load_file("#{RAILS_ROOT}/config/authorize_net.yml")
2+
AUTHORIZE_NET_CONFIG = yml['default']
3+
AUTHORIZE_NET_CONFIG.merge!(yml[RAILS_ENV]) unless yml[RAILS_ENV].nil?
4+
AUTHORIZE_NET_CONFIG.freeze

0 commit comments

Comments
 (0)