How to test “Failed” payments using Stripe & WooCommerce

I’m in the process of testing how our plugin Reserved Stock Pro behaves when payments via Stripe fail. Turns out there’s not a clear way to “fail” payments via the Stripe API and WooCommerce. So, I found another solution.

Firstly, I’m using a WooCommerce store in my local development enviroment. Therefore, I’ll be using the Stripe test API keys.

Once your WooCommerce store is ready and accepting test payments, we’ll want to block the next payment. We do using the Stripe Radar (also in test mode).

Setting up new Stripe Radar Rules

I want my payment to fail, so I poked around the Stripe Radar Rules to find an easy way to block my payment. I settled for an easy rule that will block my payment if the customer email matches mine. See the screenshots below.

Finding the Stripe Radar Rules
Finding the Stripe Radar Rules
Add a new Stripe Radar Rule
Add a new Stripe Radar Rule
Configure the new Stripe Radar Rule.
Configure the new Stripe Radar Rule.

As you can see in the screenshot, my test email is dev-email@flywheel.local and I’ve created a new rule which looks like this: Block if :email: = 'dev-email@flywheel.local

To save the new rule, we have to click the “Test Rule” button. All that does is run the rule against your previous Stripe payments to give you an indication of what would have been blocked if this rule was active. It’s a nice feature that will show you if your rule is too aggressive. You don’t want to accidentally block all future payments.

Check that your rule is correct.
Check that your rule is correct.

One of my previous test payments were made by the same email, which was me testing. This looks good to me. Go ahead and save the rule.

Now to checkout in WooCommerce

We’ll need to confirm that the rule is working and blocking our payment. I’ll checkout any product and use the customer email specified in the Stripe Radar Rule.

Next up, I’ll fill out the checkout form with test data and test credit card information. Bang! Success – WooCommerce lets us know that the card was declined.

Success! The payment was blocked and WooCommerce declined it.
Success! The payment was blocked and WooCommerce declined it.
Check the that the "Failed" order was created in WooCommerce
Check the that the “Failed” order was created in WooCommerce

WooCommerce did indeed create a new order and mark it as “Failed”. I’m now ready to move on to test failed payment with stock reservations.

I hope this helps other people who need to test failed/declined payments with Stripe. Let me know in the comments below!

Avatar photo
Morgan

I help eCommerce store owners to run their stores smoothly and get more sales. Let's discuss optimizing your store! Hit me up via the support page or on Twitter @morganhvidt