Testing Authorize.net with ActiveMerchant 6

Posted by jcnnghm Sun, 27 Apr 2008 18: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=10

  1. mmo Thu, 18 Sep 2008 20:40:04 GMT

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

  2. Wes G Wed, 26 Aug 2009 16:51:12 GMT

    Sweet. Thanks for the pointer.

  3. Davis Zanetti Cabral Sat, 23 Jan 2010 15:37:51 GMT

    Thank you a lot man! ;)

  4. Aryk Grosz Thu, 16 Sep 2010 19:36:20 GMT

    Is this a bug with ActiveMerchant?

    Shouldn’t active merchant be using the ActiveMerchant::Billing::Base.mode to set this parameter?

  5. Aryk Grosz Thu, 16 Sep 2010 19:47:33 GMT

    nevermind, it’s explained in the API…

  6. Gavin Morrice Fri, 12 Nov 2010 13:30:15 GMT

    Thanks for the tip!

    …Here’s a DRYer solution:

    ActiveMerchant::Billing::Base.gateway(:authorize_net).new(:login => "login", :password => "transkey", :test => Rails.env == "production")