views:

619

answers:

1

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?

+4  A: 

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.

codehead
I dont know what the limits for PayPal are, but when I do ecommerce sites and need to test (I use Authorize.Net) I just do a live transaction on some arbitrarily low amount ($0.01) and then use my personal credit card. Cheap and easy.
Cody Caughlan
Great idea - that's what I have done. Now users with @my-domain.com are given a $0.01 price for my product, and I can test the live order pipeline end-to-end with minimal special-casing.
esilver
Another option would be to remove all special casing and charge your credit card as you do all other customers, and simply issue a refund once the payment has been processed. This won't cost you anything at all -- not even a cent! -- because Paypal refunds the fees.
Olly