I've integrated ActiveMerchant into my Rails 3 app more or less along the lines outlined in the RailsCast on the topic using Authorize.net as my gateway. I'm running the gateway in test mode (ActiveMerchant::Billing::Base.mode = :test
) in development, and everything seems to be working as expected for the success case. The credit card validation is working fine for incorrectly formatted input, but in order to fully verify my workflows, I'd like to also test purchase failure cases, such as insufficient funds or miss-matched CCV code. Unfortunately, it seems that I'm receiving response.success? == true
for any correctly formatted credit card number, at least when operating in test mode against my Authorize.net test account.
So, my question is: How should I simulate particular types of failures on my gateway.purchase()
call? Is there a test card number which always has insufficient funds? Do I just need to dummy up my own response
object? What's the most correct approach here?
Caveat: I'm new to Ruby, Rails, and credit card processing, so please forgive me if the answer is desperately obvious. Did a fair bit of Googling and couldn't find an example exercising the failure modes.
You have to pass the failure you want by using the proper zip code: