Setting up Stripe for a client on WooCommerce we ran into a Stripe 402 Error. So what does a 402 error mean and how can we solve this issue? Well Let’s get into the finer details shall we.
Keys used In our case this happened using a live publishable and private key. So this meant we had to use a real credit card and enter details properly. Sometimes people run test mode and forget to use a dummy credit card for testing or forget to turn on testing. So please do check what mode you are using and use the proper payment details.
Stripe 402 Code
When the payment does fail with a Stripe 402 error it means the payment went wrong.
I quote Stripe:
Not all errors map cleanly onto HTTP response codes, however. When a request is valid but does not complete successfully (e.g., a card is declined), we return a 402 error code. To understand why a card is declined, refer to the list of codes in the documentation.
So as there are multiple problems that can cause this error you need to find out what the error was you had. And for that you need to get the possible decline code.
Source of the Error
We can see in the page source what the issue is once the payment is done. To view the source just after a failure use command+alt+i on Chrome on your Mac to open the inspector for this. Sometimes it is just the wrong credit card details entered. Again, check the decline code / message.
Also, when you have error message recording turned on you can check your WooCommerce system logs. These are located at /srv/www/domain.com/shared/uploads/wc-logs for those using Trellis. For others at wp-content/uploads/wc-logs. In our case we found:
01-24-2018 @ 13:54:48 - ====Start Log==== Error: stdClass Object ( [error] => stdClass Object ( [message] => Your card's security code is incorrect. [type] => card_error [param] => cvc [code] => incorrect_cvc [charge] => ch_111111111111111111111 ) )
So the client did not enter the proper security code or cvc. In other cases it could be an incorrect card number or something else related tot the payment.
Well, as soon as you have the decline code or error found in the source of the page or in your WooCommerce error logs or other payment logs you will be able to add details properly. As stated we had an issue with the cvc code. Once the client entered the proper security code the payment went through.