BillwerkWebhookEventSubscriber->onCustomerChanged() throws error for non-Drupal user change events

Created on 3 July 2024, 10 months ago
Updated 31 July 2024, 9 months ago

Problem/Motivation

BillwerkWebhookEventSubscriber->onCustomerChanged() throws error for non-Drupal user change events

Drupal\billwerk_subscriptions\Exception\DataObjectException: The ExternalCustomerId of the Billwerk Customer ID #123456789123456789 is empty. ExternalCustomerId always has to match the Drupal user id (UID)! in Drupal\billwerk_subscriptions\BillwerkDataObjectFactory->billwerkLoadBillwerkCustomer() (Zeile 84 in /web/modules/contrib/billwerk_subscriptions/src/BillwerkDataObjectFactory.php).

#0 /web/modules/contrib/billwerk_subscriptions/src/EventSubscriber/BillwerkWebhookEventSubscriber.php(85): Drupal\billwerk_subscriptions\BillwerkDataObjectFactory->billwerkLoadBillwerkCustomer()
#1 [internal function]: Drupal\billwerk_subscriptions\EventSubscriber\BillwerkWebhookEventSubscriber->onCustomerChanged()
#2 /web/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php(111): call_user_func()
#3 /web/modules/contrib/billwerk_subscriptions/src/Controller/WebhookListenerController.php(71): Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch()
#4 [internal function]: Drupal\billwerk_subscriptions\Controller\WebhookListenerController->listen()
#5 /web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array()
#6 /web/core/lib/Drupal/Core/Render/Renderer.php(638): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#7 /web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(121): Drupal\Core\Render\Renderer->executeInRenderContext()
#8 /web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext()
#9 /vendor/symfony/http-kernel/HttpKernel.php(181): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#10 /vendor/symfony/http-kernel/HttpKernel.php(76): Symfony\Component\HttpKernel\HttpKernel->handleRaw()
#11 /web/core/lib/Drupal/Core/StackMiddleware/Session.php(53): Symfony\Component\HttpKernel\HttpKernel->handle()
#12 /web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle()
#13 /web/core/lib/Drupal/Core/StackMiddleware/ContentLength.php(28): Drupal\Core\StackMiddleware\KernelPreHandle->handle()
#14 /web/core/modules/big_pipe/src/StackMiddleware/ContentLength.php(32): Drupal\Core\StackMiddleware\ContentLength->handle()
#15 /web/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\big_pipe\StackMiddleware\ContentLength->handle()
#16 /web/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass()
#17 /web/core/modules/ban/src/BanMiddleware.php(50): Drupal\page_cache\StackMiddleware\PageCache->handle()
#18 /web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\ban\BanMiddleware->handle()
#19 /web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle()
#20 /web/core/lib/Drupal/Core/StackMiddleware/AjaxPageState.php(36): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle()
#21 /web/modules/contrib/remove_http_headers/src/StackMiddleware/RemoveHttpHeadersMiddleware.php(49): Drupal\Core\StackMiddleware\AjaxPageState->handle()
#22 /web/core/lib/Drupal/Core/StackMiddleware/StackedHttpKernel.php(51): Drupal\remove_http_headers\StackMiddleware\RemoveHttpHeadersMiddleware->handle()
#23 /web/core/lib/Drupal/Core/DrupalKernel.php(741): Drupal\Core\StackMiddleware\StackedHttpKernel->handle()
#24 /web/index.php(19): Drupal\Core\DrupalKernel->handle()
#25 {main}

The reason is:

public function billwerkLoadBillwerkCustomer(string $customerId): BillwerkCustomer {
    $customerArray = $this->api->getCustomer($customerId);
    if (!empty($customerArray)) {
      if ($customerArray['Id'] !== $customerId) {
        throw new DataObjectException('Given customer ID did not match the returned result.');
      }

      if (empty($customerArray['ExternalCustomerId'])) {
        throw new DataObjectException("The ExternalCustomerId of the Billwerk Customer ID #{$customerId} is empty. ExternalCustomerId always has to match the Drupal user id (UID)!");
      }

I think we need to throw a specific exception that can be catched in BillwerkDataObjectFactory->billwerkLoadBillwerkCustomer() so we can ignore such Billwerk Customers.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

🇩🇪Germany Anybody Porta Westfalica

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