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:
- Keep my subscription by switching to a new/existing payment method
- Keep my subscription, I don't want to delete this payment method
- 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)