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](https://puri.io/wp-content/uploads/2021/03/stripe-finding-radar-rules-1-1024x467.png)
![Add a new Stripe Radar Rule](https://puri.io/wp-content/uploads/2021/03/stripe-adding-new-radar-rule-1-1024x452.png)
![Configure the new Stripe Radar Rule.](https://puri.io/wp-content/uploads/2021/03/stripe-creating-radar-rules-1-1024x547.png)
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.](https://puri.io/wp-content/uploads/2021/03/stripe-matching-radar-rules-1.png)
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.](https://puri.io/wp-content/uploads/2021/03/stripe-card-declined-on-wc-1-1024x532.png)
![Check the that the "Failed" order was created in WooCommerce](https://puri.io/wp-content/uploads/2021/03/wc-failed-payment-1-1024x516.png)
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!