Deleting a card in parallel to an existing checkout flow throws an exception

Created on 2 September 2025, 11 days ago

Describe your bug or feature request.

If a payment method is deleted while a checkout is in progress, the checkout breaks with an exception. Instead, the checkout should revert to a previous step to select a new payment method.

While at first this seems like an incredible edge case (who would delete a payment method in a different tab?), it is more likely for customers who share accounts which is not uncommon unfortunately.

If a bug, provide steps to reproduce it from a clean install.

  1. Install Kickstart.
  2. Add a payment method at /user/1/payment-methods
  3. Start a checkout and get to the last step of the flow
  4. In a new tab, delete the saved payment method
  5. Submit the cart
  6. Enjoy your fresh exception!
The website encountered an unexpected error. Try again later.

InvalidArgumentException: The provided payment has no payment method referenced. in Drupal\commerce_payment\Plugin\Commerce\PaymentGateway\PaymentGatewayBase->assertPaymentMethod() (line 518 of modules/contrib/commerce/modules/payment/src/Plugin/Commerce/PaymentGateway/PaymentGatewayBase.php).

Drupal\commerce_payment_example\Plugin\Commerce\PaymentGateway\Onsite->createPayment() (Line: 148)
Drupal\commerce_payment\Plugin\Commerce\CheckoutPane\PaymentProcess->buildPaneForm() (Line: 567)
Drupal\commerce_checkout\Plugin\Commerce\CheckoutFlow\CheckoutFlowWithPanesBase->buildForm()
call_user_func_array() (Line: 528)
Drupal\Core\Form\FormBuilder->retrieveForm() (Line: 279)
Drupal\Core\Form\FormBuilder->buildForm() (Line: 219)
Drupal\Core\Form\FormBuilder->getForm() (Line: 143)
Drupal\commerce_checkout\Controller\CheckoutController->formPage()
call_user_func_array() (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 627)
Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 121)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext() (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 183)
Symfony\Component\HttpKernel\HttpKernel->handleRaw() (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 53)
Drupal\Core\StackMiddleware\Session->handle() (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 28)
Drupal\Core\StackMiddleware\ContentLength->handle() (Line: 32)
Drupal\big_pipe\StackMiddleware\ContentLength->handle() (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 53)
Drupal\Core\StackMiddleware\AjaxPageState->handle() (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle() (Line: 715)
Drupal\Core\DrupalKernel->handle() (Line: 19)
🐛 Bug report
Status

Active

Version

3.1

Component

Payment

Created by

🇨🇦Canada deviantintegral

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024