Authorize.Net ActiveMerchant ARB, Where's my bug? vol. 2

6 views
Skip to first unread message

Jeushy

unread,
May 7, 2008, 2:22:44 AM5/7/08
to Active Merchant
I'm also having a little trouble implementing ARB with Authorize.Net.
I keep getting a "uninitialized constant
Subscription::AuthorizeNetGateway" error, but I must be missing
something or chalk it up to my noobness on ActiveMerchant, but if
anyone can point out where my bug is I would really appreciate the
help:


Below is code from my app/models/subscription.rb

def process_recurring
ActiveMerchant::Billing::Base.mode = :production

amount = (self.total_to_charge)


# read api key and transaction # from config file
c = YAML::load(File.open("#{RAILS_ROOT}/config/config.yml"))
user = c[RAILS_ENV]['auth_net_user']
pass = c[RAILS_ENV]['auth_net_pass']

creditcard = ActiveMerchant::Billing::CreditCard.new(
:first_name => self.bill_to_fname,
:last_name => self.bill_to_lname,
:number=> self.card_number,
:verification_value => self.card_verification_value,
:type => self.card_type,
:month => self.card_expiration_month,
:year => self.card_expiration_year
)

if creditcard.valid?
options = {
:interval => {
:length => 1,
:unit => "months"
},
:duration => {
:startDate => "2008-06-08",
:totalOccurences => 9999,
},
:billing_address => {
:firstName => self.bill_to_fname,
:lastName => self.bill_to_lname,
}
}

# Create a gateway object to the Authorize.net service
gateway = AuthorizeNetGateway.new( { :login => user, :password
=> pass} )

# Authorize and Capture payment for the total amount (in cents)
response = gateway.recurring(amount, creditcard, options)

if response.success?
self.total_amount = amount
self.subscription_id = response.subscriptionId
self.status = 'processed'
else
self.status = 'failed'
self.error_message = response.message
end
else
self.status = 'failed'
self.error_message = 'Invalid credit card'
end
end

Thanks for the help.

Cody Fauser

unread,
May 10, 2008, 9:07:34 AM5/10/08
to activem...@googlegroups.com
You're missing the namespace on the gateway class:

# Create a gateway object to the Authorize.net service

gateway = ActiveMerchant::Billing::AuthorizeNetGateway.new( {


:login => user, :password
=> pass} )

--
Cody Fauser
http://shopify.com - e-commerce done right
http://www.codyfauser.com - blog
http://peepcode.com/products/activemerchant-pdf - ActiveMerchant PeepCode
http://www.oreilly.com/catalog/rjsrails - RJS Templates for Rails

Reply all
Reply to author
Forward
0 new messages