Problem/Motivation

In both PaymentElement and CardElement, when a PaymentIntent reaches a non-terminal, non-success status and last_payment_error is absent (null), we assign $decline_message = $intent->last_payment_error, leaving $decline_message as null. Passing null to the string $message parameter of HardDeclineException::createForPayment() throws a TypeError in PHP 8.2+.

Even in prior versions of PHP, this isn't really right, as we end up passing an empty string as the Hard Decline message.

If $intent->last_payment_error is not an object(and therefore NULL), we should return a friendlier error message.

Additionally, CardElement is on;your checking for the deprecated $intent->charges->data, and not the newer $intent->latest_charge, like PaymentElement.

We should make the handling here more consistent.

Note: we aren't carrying over other enhancements from PaymentElement to CardElement, like handling the processing status, as this is not applicable to card payment methods, which is the only payment method type supported by the CardElement.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

tomtech created an issue. See original summary.

  • 8cd660a6 committed on 2.x
    fix: #3591853 Properly handle non-success status in createPayment
    
    By:...
tomtech’s picture

Status: Active » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.