diff --git a/CHANGELOG.md b/CHANGELOG.md index b4594b9..c66f3d5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +# 1.1.9 +- Put try catch on webhook install + # 1.1.8 - Remove unhelpful tickets info in release comments diff --git a/composer.json b/composer.json index 7af1feb..e0fa7b5 100644 --- a/composer.json +++ b/composer.json @@ -46,5 +46,5 @@ "postfinancecheckout/sdk": "2.1.*" }, "type": "shopware-platform-plugin", - "version": "1.1.8" + "version": "1.1.9" } \ No newline at end of file diff --git a/src/Core/Api/WebHooks/Service/WebHooksService.php b/src/Core/Api/WebHooks/Service/WebHooksService.php index ae11e38..5cb1990 100644 --- a/src/Core/Api/WebHooks/Service/WebHooksService.php +++ b/src/Core/Api/WebHooks/Service/WebHooksService.php @@ -243,38 +243,39 @@ public function setSalesChannelId(?string $salesChannelId = null): WebHooksServi * Install Listeners * * @return array - * @throws \PostFinanceCheckout\Sdk\ApiException - * @throws \PostFinanceCheckout\Sdk\Http\ConnectionException - * @throws \PostFinanceCheckout\Sdk\VersioningException */ protected function installListeners(): array { - $webHookUrlId = $this->getOrCreateWebHookUrl()->getId(); - $installedWebHooks = $this->getInstalledWebHookListeners($webHookUrlId); - $webHookEntityIds = array_map(function (WebhookListener $webHook) { - return $webHook->getEntity(); - }, $installedWebHooks); - $returnValue = []; - - /** - * @var $data Entity - */ - foreach ($this->webHookEntitiesConfig as $data) { - - if (in_array($data->getId(), $webHookEntityIds)) { - continue; + $returnValue = []; + try { + $webHookUrlId = $this->getOrCreateWebHookUrl()->getId(); + $installedWebHooks = $this->getInstalledWebHookListeners($webHookUrlId); + $webHookEntityIds = array_map(function (WebhookListener $webHook) { + return $webHook->getEntity(); + }, $installedWebHooks); + + + /** + * @var \PostFinanceCheckoutPayment\Core\Api\WebHooks\Struct\Entity $data + */ + foreach ($this->webHookEntitiesConfig as $data) { + + if (in_array($data->getId(), $webHookEntityIds)) { + continue; + } + + $entity = (new WebhookListenerCreate()) + ->setName($data->getName()) + ->setEntity($data->getId()) + ->setNotifyEveryChange($data->isNotifyEveryChange()) + ->setState(CreationEntityState::CREATE) + ->setEntityStates($data->getStates()) + ->setUrl($webHookUrlId); + + $returnValue[] = $this->apiClient->getWebhookListenerService()->create($this->spaceId, $entity); } - - /** @noinspection PhpParamsInspection */ - $entity = (new WebhookListenerCreate()) - ->setName($data->getName()) - ->setEntity($data->getId()) - ->setNotifyEveryChange($data->isNotifyEveryChange()) - ->setState(CreationEntityState::CREATE) - ->setEntityStates($data->getStates()) - ->setUrl($webHookUrlId); - - $returnValue[] = $this->apiClient->getWebhookListenerService()->create($this->spaceId, $entity); + } catch (\Exception $exception) { + $this->logger->critical($exception->getTraceAsString()); } return $returnValue; @@ -290,13 +291,13 @@ protected function installListeners(): array */ protected function getOrCreateWebHookUrl(): WebhookUrl { - + $url = $this->getWebHookCallBackUrl(); /** @noinspection PhpParamsInspection */ $entityQueryFilter = (new EntityQueryFilter()) ->setType(EntityQueryFilterType::_AND) ->setChildren([ $this->getEntityFilter('state', CreationEntityState::ACTIVE), - $this->getEntityFilter('url', $this->getWebHookCallBackUrl()), + $this->getEntityFilter('url', $url), ]); $query = (new EntityQuery())->setFilter($entityQueryFilter)->setNumberOfEntities(1); @@ -310,7 +311,7 @@ protected function getOrCreateWebHookUrl(): WebhookUrl /** @noinspection PhpParamsInspection */ $entity = (new WebhookUrlCreate()) ->setName('Shopware6::WebHookURL') - ->setUrl($this->getWebHookCallBackUrl()) + ->setUrl($url) ->setState(CreationEntityState::ACTIVE); return $this->apiClient->getWebhookUrlService()->create($this->spaceId, $entity);