Testing Authorize.net with ActiveMerchant 3

Posted by jcnnghm 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=10

Comments

Leave a comment

  1. Avatar
    mmo 5 months later:

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

  2. Avatar
    Wes G over 1 year later:

    Sweet. Thanks for the pointer.

  3. Avatar
    Davis Zanetti Cabral over 1 year later:

    Thank you a lot man! ;)

Comments