Protect users from deleting a payment method of an active subscription

Created on 12 July 2018, over 6 years ago
Updated 20 September 2024, 3 months ago

Problem/Motivation

A user deletes the payment method that is used in an active subscription.
Later on, Cron will try processing the order (which cannot be fulfilled because there is no payment method).

Proposed resolution

When a user is trying to delete a payment method for an active membership, he should see the following message:

You are trying to delete a payment method that is being used in an active recurring order you have subscribed for.

Please choose one of the following options:

  1. Keep my subscription by switching to a new/existing payment method
  2. Keep my subscription, I don't want to delete this payment method
  3. Cancel my subscription

Additional Details

When trying to view the order that is missing a payment method, getting this error:

The website encountered an unexpected error. Please try again later.
Error: Call to a member function label() on null in commerce_payment_preprocess_commerce_order() (line 127 of modules/contrib/commerce/modules/payment/commerce_payment.module).
commerce_payment_preprocess_commerce_order(Array, 'commerce_order', Array) (Line: 284)
Drupal\Core\Theme\ThemeManager->render('commerce_order', Array) (Line: 437)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 195)
Drupal\Core\Render\Renderer->render(Array, ) (Line: 226)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 582)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 227)
Drupal\Core\Render\MainContent\HtmlRenderer->prepare(Array, Object, Object) (Line: 117)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object, Object) (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object, 'kernel.view', Object)
call_user_func(Array, Object, 'kernel.view', Object) (Line: 111)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch('kernel.view', Object) (Line: 156)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 68)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 99)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 78)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 52)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 666)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
Feature request
Status

Needs work

Version

1.0

Component

User interface

Created by

🇺🇸United States shaal Boca Raton, FL

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇨🇷Costa Rica thony1199

    The patch in this ticket was broken in Drupal 10 due to accessCheck, so I have added it to the proposed solution in this module.

  • Status changed to Needs work 4 months ago
  • 🇮🇱Israel jsacksick

    This isn't the right approach to me, we should implement a hook_entity_access() for that (i.e. forbid deleting payment methods that are referenced by active subscriptions).

  • 🇵🇰Pakistan Qaiser iqbal

    The patch got failed while applying via composer

Production build 0.71.5 2024