Skip to content

Instantly share code, notes, and snippets.

@janx
Created July 9, 2009 02:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save janx/143368 to your computer and use it in GitHub Desktop.
Save janx/143368 to your computer and use it in GitHub Desktop.
# application/moneyhats/config/environments/development.rb
# We want to use the BraintreeGateway in test mode so
# that we can simulate real transactions during development. The code
# needs to be placed in the to_prepare block so that it is executed on
# each reload of the OrderTransaction model in development mode. If
# the code had been placed in the after_initialize block then Order-
# Transaction.gateway would be properly set on the first request to the
# application, but would be nil on all subsequent requests.
config.after_initialize do
ActiveMerchant::Billing::Base.mode = :test
end
config.to_prepare do
OrderTransaction.gateway =
ActiveMerchant::Billing::BraintreeGateway.new(
:login => 'demo',
:password => 'password'
)
end
# application/moneyhats/config/environments/test.rb
# BogusGateway is a double provided by ActiveMerchant
config.after_initialize do
ActiveMerchant::Billing::Base.mode = :test
OrderTransaction.gateway =
ActiveMerchant::Billing::BogusGateway.new
end
# application/moneyhats/config/environments/production.rb
config.after_initialize do
# ActiveMerchant is in prod mode by default
# so this line is just for clarity
ActiveMerchant::Billing::Base.mode = :production
OrderTransaction.gateway =
ActiveMerchant::Billing::BraintreeGateway.new(
:login => 'LIVE_LOGIN',
:password => 'LIVE_PASSWORD'
)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment