Testing Authorize.net with ActiveMerchant 1

Posted by Justin Cunningham Sun, 27 Apr 2008 22:55:00 GMT

I had some trouble testing Authorize.net with the excellent rails credit card processing gem ActiveMerchant. The documentation calls for the code ActiveMerchant::Billing::Base.mode = :test, however, this resulted in the following error: The merchant login ID or password is invalid or the account is inactive.

To solve the problem, a key test with the String value true can be added to the gateway initialization hash, as follows:

if ENV['RAILS_ENV'] != 'production'
  gateway = ActiveMerchant::Billing::Base.gateway(:authorize_net).new(
    :login => "login",
    :password => "transkey", :test => 'true')
else
  gateway = ActiveMerchant::Billing::Base.gateway(:authorize_net).new(
    :login => "login",
    :password => "transkey")
end

Using this code, the account is placed into test mode when not run in production mode.

Trackbacks

Use the following link to trackback from your own site:
http://littlebitofcode.com/trackbacks?article_id=testing-authorize-net-with-activemerchant&day=27&month=04&year=2008

Comments

Leave a comment

  1. mmo 5 months later:

    Thank you for this workaround. Learning all I can on Rails.

Comments