Christian Fazzini
Christian Fazzini

Reputation: 19723

Config settings for active_merchant to be compatible with a Rails 3 app

I'm following http://railscasts.com/episodes/145-integrating-active-merchant

How do I set the configuration settings to be compatible with a Rails 3 app.

I tried putting the following in config/initializers/active_merchant.rb

if Rails.env == 'development'
  config.after_initialize do
    ActiveMerchant::Billing::Base.mode = :test
    ::GATEWAY = ActiveMerchant::Billing::PaypalGateway.new(
      :login     => 'seller12341234zxcv.foobar.com',
      :password  => 'pasword',
      :signature => 'abc123'
    )
  end
elsif Rails.env == 'test'
  config.after_initialize do
    ActiveMerchant::Billing::Base.mode = :test
    ::GATEWAY = ActiveMerchant::Billing::BogusGateway.new
  end
elsif Rails.env == 'production'
  config.after_initialize do
    ActiveMerchant::Billing::Base.mode = :test
    ::GATEWAY = ActiveMerchant::Billing::PaypalGateway.new(
      :login     => 'seller12341234zxcv.foobar.com',
      :password  => 'pasword',
      :signature => 'abc123'
    )
  end
end

The following renders an error:

config/initializers/active_merchant.rb:2:in `<top (required)>': undefined local variable or method `config' for main:Object (NameError)

Upvotes: 3

Views: 1716

Answers (3)

Mohd Anas
Mohd Anas

Reputation: 654

You can put this code in your environments file i.e config/environments/development.rb, production.rb , etc Just use

config.after_initialize do
  ActiveMerchant::Billing::Base.mode = :test
  ::GATEWAY = ActiveMerchant::Billing::PaypalGateway.new(
   :login     => 'seller12341234zxcv.foobar.com',
   :password  => 'pasword',
   :signature => 'abc123'
  )
end

Upvotes: 1

madgen
madgen

Reputation: 747

You need to change config.after_initialize to ApplicationName::Application.config.after_initialize and it should be working.

Upvotes: 0

Jon-Paul Lussier
Jon-Paul Lussier

Reputation: 225

Looks like you just need to get rid of the config.after_initialize do block -- should initialize fine after that.

Upvotes: 4

Related Questions