20/06/2024 • eCommerce
WooCommerce PayPal Express Checkout Failing
I’ve recently been troubleshooting an ecommerce website built with WordPress and WooCommerce. Here’s what to do if you have a similar issue with PayPal payments.
I’ve recently been troubleshooting an ecommerce website built with WordPress and WooCommerce. The website was using the official WooCommerce PayPal plugin to process PayPal payments via the full checkout (which were working fine) and the ‘express’ checkout from the product pages. The express payments were failing.
TL;DR
The WooCommerce PayPal plugin is broken. Use the Payment Plugins PayPal plugin instead.
Enable the PayPal Log in WooCommerce
The first step I took in troubleshooting the issue was to enable the PayPal log, as follows:
- Login to WordPress
- Click WooCommerce from menu
- Click Settings from menu
- Click Payments tab
- Click PayPal Standard
- Click ‘Enable Logging’ checkbox and ‘Save changes’
This now ensures that all PayPal activity through the website is logged, here:
- Login to WordPress
- Click WooCommerce from menu
- Click Status from menu
- Click Logs tab
- Click any record named ‘woocommerce-paypal-payments’ – logs are ordered by date
Find the Error
Having activated the error logging I put through a payment, which failed. I then checked the log.
The error looked like this:
Warning Failed to capture order. PayPal API response: [UNPROCESSABLE_ENTITY] The requested action could not be performed, semantically incorrect, or failed business validation. https://developer.paypal.com/docs/api/orders/v2/#error-PAYER_ACTION_REQUIRED CONTEXT: {“args”:{“method”:”POST”,”headers”:{“Authorization”:”Bearer A21AAOf9L2MuZsJ8ChnUoYuOYWOqwk4wKw1b0U2igWnfF3xGNnH59Elj9_iug090fJJ33sy3DndyGuZ7utBQVeOy1B4-Jw0CA”,”Content-Type”:”application\/json”,”Prefer”:”return=representation”,”PayPal-Partner-Attribution-Id”:”Woo_PPCP”}},”response”:{“headers”:{},”body”:”{\”name\”:\”UNPROCESSABLE_ENTITY\”,\”details\”:[{\”issue\”:\”PAYER_ACTION_REQUIRED\”,\”description\”:\”Payer needs to perform the following action before proceeding with payment.\”}],\”message\”:\”The requested action could not be performed, semantically incorrect, or failed business validation.\”,\”debug_id\”:\”c28e3ef6a3501\”,\”links\”:[{\”href\”:\”https:\/\/developer.paypal.com\/docs\/api\/orders\/v2\/#error-PAYER_ACTION_REQUIRED\”,\”rel\”:\”information_link\”,\”method\”:\”GET\”},{\”href\”:\”https:\/\/www.paypal.com\/checkoutnow?token=56D15904TY832164C\”,\”rel\”:\”payer-action\”,\”method\”:\”GET\”}]}”,”response”:{“code”:422,”message”:”Unprocessable Entity”},”cookies”:[{“name”:”l7_az”, “value”:”ccg14.slc”, “expires”:1718877612, “path”:”\/”, “domain”:”paypal.com”, “port”:null, “host_only”:false}],”filename”:null, “http_response”:{“data”:null, “headers”:null, “status”:null}}}
The error [UNPROCESSABLE_ENTITY] is fairly generic. The PayPal API docs say:
‘The API cannot complete the requested action and might require interaction with APIs or processes outside of the current request. No systemic problems limit the API from completing the request. For example, this error occurs for any business validation errors, including errors that are not usually of the 400
type.’
This doesn’t offer much help in solving the problem.
From what I can gather, the PayPal express payments process pre-authorises a certain order value. If the final value (due to the addition of shipping costs) is greater than this amount then the order will fail. However, I tested this theory by trying to purchase something which didn’t have a shipping cost, but the error still occured. So I’m pretty sure it’s not (only) to do with the pre-authorisation process.
Out of Date Template Files
My first port of call was to update some out of date WooCommerce template files. These are copies of the core WooCommerce templates which have styling or additional layout options applied to them by the theme developers. My theory was that perhaps one of these out of date templates was responsible for handling the payment response from PayPal.
Unfortunately, updating the templates did not solve the problem. However, it’s always a good idea to keep your WooCommerce templates in line with the current versions, so make sure you check the Templates section of the WooCommerce Status page for details about your template versions.
Malware
There was an indication from the site owner that the website had previously been hacked and may still be harbouring some suspicious code. I checked the site over using a few security plugins and external sites (blacklist check and so on), but couldn’t find any indication that the site was compromised. Phew!
Setup Test Version of the Website
In order to thoroughly test the checkout flow I setup a minimal version of the website using a default theme and a bare-bones WooCommerce setup. The same error persisted. This was beginning to look like a problem with the plugin. Which of course, I could have checked earlier, but I think I can be forgiven that the official WooCommerce PayPal plugin would be kept up to date and work properly – seems not!
Broken WordPress Plugin
Sure enough, I installed an alternative PayPal payments plugin which worked first time. The WooCommerce PayPal plugin is broken. Use the Payment Plugins PayPal plugin instead.
Photo by Marques Thomas on Unsplash