Search code examples
ruby-on-railspaypalactivemerchant

Accepting dummy credit cards on a live site with ActiveMerchant & PayPal


I'm setting up a rails site that will accept credit cards with ActiveMerchant and PayPal Website Payments Pro. I am successfully testing against the PayPal sandbox, but need to be able to test on my live site as well. I'd like to implement a solution whereby registrations on my live site with email addresses from my own domain use the PayPal sandbox, but for everyone else it uses the live PayPal site. That way when I test my live site I'm not paying myself and getting taxed by PayPal in the process :-)

The problem, however, is that to get ActiveMerchant to use the test servers you write this line:

ActiveMerchant::Billing::Base.mode = :test

That sets a class variable which will apply to other transactions on the site, when I simply wish for one transaction to target the test servers.

Can anyone suggest an elegant solution? Or are there better ways to accomplish this other than the solution I have in mind?


Solution

  • It´s always dangerous to leave a backdoor open. I'd recommend against running your production environment against the sandbox under any circumstance. If you need to run an ocassional test do it against the live PayPal environment and process a refund immediately - no fuss and no charge.