Problem/Motivation

Customers can not access Paypal payment because of commerce_payment error type :

Client error: `POST https://api.paypal.com/v2/checkout/orders/xxxxxxxxxxxxxxxx/capture` resulted in a `422 Unprocessable Entity` response: {"name":"UNPROCESSABLE_ENTITY","details":[{"issue":"INSTRUMENT_DECLINED","description":"The instrument presented was ei (truncated...)

Steps to reproduce

Working with Commerce PayPal 8.x-1.4
Having a Paypal payment gateway, Paypal Checkout plugin, Access Paypal Smart Payment Buttons ON, Collect Billing information, Transaction type Capture, Update billing and shipping address with information entered at PayPal, no restrictions.
It seems to happen when customer choose the Credit or debit card funding source.

Comments

Toki created an issue. See original summary.

toki’s picture

Issue summary: View changes
toki’s picture

The INSTRUMENT DECLINED issue has been documented by Paypal here.
According to this, the checkout flow could restart and prompts the buyer to select a different funding source if it failed.
Here it seems that there was only a message about an unexpected error and no clear message to switch to another option (leading to a little stress about the payment).
Is there a way to set this configuration somewhere?

toki’s picture

Title: 422 error Unprocessable entity » 422 error Unprocessable entity INSTRUMENT_DECLINED
jsacksick’s picture

Priority: Critical » Normal

I'm not really sure what you're asking here? I'm guessing an exception is currently thrown by the Paypal module and an error message is presented to the customer, then the customer is redirected to the previous step of the checkout? What's not correct in that flow?

toki’s picture

That seems OK to me but for end-user/customer (apparently) they are on Paypal, they complete the form and then land back to the Order review with a raw error message (The website encountered unexpected error...) without any message about choosing another option.
Then they are stressed about the payment hoping that it has not been taken (while the payment has been refused).
So, do you think a short message could be displayed (Paypal mentions the onApprove function if I am correct #sitebuilderhere)
Thanks for your response anyway and sorry for my approximate English.

jsacksick’s picture

Are you sure your customers are getting:

(The website encountered unexpected error...)

?

toki’s picture

You're right, after investigation, they get "We encountered an unexpected error processing your payment method. Please try again later."
Sorry for the approximation but it is sometimes complicated to get precise feedback on errors.
After this issue, the customer tried with another credit card (after a lot of tries with the same...) and finally completed the checkout.
So maybe this is only a "human" problem here...
Thus, if I get the Client Error in the Drupal log, can we say that the website is OK and that is only a typing error from customer?

josh.stewart’s picture

Is it possible to look into this a little bit further? I'm running into this issue (the error from OP), but I think the bigger problem that I'm seeing and I'm not sure where to start with debugging it or providing more information for it is that my site is not handling the error at all. Instead it's allowing the order to process with no payments attached.

Order moves into a state for validation and has the look and feel that it was "completed" as a transaction.

josh.stewart’s picture

I've dug deeper into this.

I’m testing a weird instance where orders can be placed through PayPal but if a specific error is fired off (Insufficient Funds like the one above), the code traceback will go through the process of throwing a PaymentGatewayException however it still proceeds through the code without redirecting back to a previous spot. It actually continues on and places the order, without payment at all.

When it gets to the part of code about redirecting to the $error_step_id, $this->redirectToPrevious() is set to false which I think is where the bug is as well. It should not continue on through the code to where $order->save() is called.

The question I have is… what should my checkout flow look like for Paypal Checkout (Preferred)? Is it possible I have the wrong order of things?

Kinda seems like a bug to me in tthis module, but could it be with commerce itself?

nicolas bouteille’s picture

I stumbled upon this error myself.
After reading your comment, I got scared and tested the insufficient funds case.
Fortunately, the order does not complete and the user gets a proper error message and is invited to try again.
FYI: I am using Commerce 2.36, Commerce Paypal 1.4.0, Drupal 9.5.10 with PHP 8.1

josh.stewart’s picture

I should have followed up. This was due to another module not handling errors properly. This was NOT an issue with commerce_paypal, instead was an issue from commerce_multi_payments and not handling errors well.

jsacksick’s picture

Status: Active » Closed (cannot reproduce)

So closing this per the comments.