Deleting payment method breaks order payments in back office

Created on 1 August 2025, 14 days ago

Problem/Motivation

If a customer deletes a payment method, a fatal error occurs when the canCapturePayment() method is called when accessing back-office functions such as viewing payments on the order or attempting a refund.

Error is:

Error: Call to a member function canCapturePayment() on null in Drupal\commerce_stripe\Plugin\Commerce\PaymentGateway\StripePaymentElement->canCapturePayment() (line 1453 of /var/www/html/docroot/modules/contrib/commerce_stripe/src/Plugin/Commerce/PaymentGateway/StripePaymentElement.php)

(Ignore the line number as this is on 2.0.1)

Steps to reproduce

  1. Check out and complete an order as a customer
  2. Delete the saved payment method used
  3. Log in as an admin and go to /admin/commerce/orders/{order_id}/payments
  4. Error is encountered as above

Proposed resolution

Extend the checking to ensure that, we don't call the canCapturePayment() method on a PaymentType that is NULL

Remaining tasks

Requires review

🐛 Bug report
Status

Active

Version

2.0

Component

Payment Element

Created by

🇬🇧United Kingdom alanhdev

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024