From 54915d8361f6da95e340d3b3bff24d5ff013caa4 Mon Sep 17 00:00:00 2001 From: Aleksey Kotsuba Date: Fri, 9 Oct 2020 10:58:30 +0300 Subject: [PATCH 1/3] SUPESC-180: Updated notification process. --- .../Computop/Transfer/computop.transfer.xml | 1 + .../Computop/Controller/CallbackController.php | 8 ++++++-- .../Processor/NotificationProcessor.php | 17 ++++++++++------- .../Persistence/ComputopEntityManager.php | 10 ++++++++-- .../ComputopEntityManagerInterface.php | 4 ++-- 5 files changed, 27 insertions(+), 13 deletions(-) diff --git a/src/SprykerEco/Shared/Computop/Transfer/computop.transfer.xml b/src/SprykerEco/Shared/Computop/Transfer/computop.transfer.xml index 9a7706cba..f9545ce86 100644 --- a/src/SprykerEco/Shared/Computop/Transfer/computop.transfer.xml +++ b/src/SprykerEco/Shared/Computop/Transfer/computop.transfer.xml @@ -566,6 +566,7 @@ + diff --git a/src/SprykerEco/Yves/Computop/Controller/CallbackController.php b/src/SprykerEco/Yves/Computop/Controller/CallbackController.php index 4f8d64127..ed8d32a65 100644 --- a/src/SprykerEco/Yves/Computop/Controller/CallbackController.php +++ b/src/SprykerEco/Yves/Computop/Controller/CallbackController.php @@ -213,9 +213,13 @@ public function notifyAction(Request $request) ->fromArray($responseHeaderTransfer->toArray(), true) ->setType($decryptedArray[ComputopApiConfig::NOTIFICATION_PARAMETER_PAYMENT_TYPE] ?? ''); - $this->getClient()->processNotification($computopNotificationTransfer); + $computopNotificationTransfer = $this->getClient()->processNotification($computopNotificationTransfer); - return new Response(); + if ($computopNotificationTransfer->getIsProcessed()) { + return new Response(); + } + + return new Response('', Response::HTTP_NOT_ACCEPTABLE); } /** diff --git a/src/SprykerEco/Zed/Computop/Business/Processor/NotificationProcessor.php b/src/SprykerEco/Zed/Computop/Business/Processor/NotificationProcessor.php index ea4c451dd..2dae01d88 100644 --- a/src/SprykerEco/Zed/Computop/Business/Processor/NotificationProcessor.php +++ b/src/SprykerEco/Zed/Computop/Business/Processor/NotificationProcessor.php @@ -36,24 +36,27 @@ public function __construct(ComputopEntityManagerInterface $computopEntityManage public function processNotification( ComputopNotificationTransfer $computopNotificationTransfer ): ComputopNotificationTransfer { - $this->getTransactionHandler()->handleTransaction( + return $this->getTransactionHandler()->handleTransaction( function () use ($computopNotificationTransfer): void { - $this->executeSaveComputopNotificationTransaction($computopNotificationTransfer); + return $this->executeSaveComputopNotificationTransaction($computopNotificationTransfer); } ); - - return $computopNotificationTransfer; } /** * @param \Generated\Shared\Transfer\ComputopNotificationTransfer $computopNotificationTransfer * - * @return void + * @return \Generated\Shared\Transfer\ComputopNotificationTransfer */ protected function executeSaveComputopNotificationTransaction( ComputopNotificationTransfer $computopNotificationTransfer - ): void { + ): ComputopNotificationTransfer { $this->computopEntityManager->savePaymentComputopNotification($computopNotificationTransfer); - $this->computopEntityManager->updatePaymentComputopOrderItemPaymentConfirmation($computopNotificationTransfer); + $isProcessed = $this->computopEntityManager + ->updatePaymentComputopOrderItemPaymentConfirmation($computopNotificationTransfer); + + $computopNotificationTransfer->setIsProcessed($isProcessed); + + return $computopNotificationTransfer; } } diff --git a/src/SprykerEco/Zed/Computop/Persistence/ComputopEntityManager.php b/src/SprykerEco/Zed/Computop/Persistence/ComputopEntityManager.php index 7f8751394..8818d39cd 100644 --- a/src/SprykerEco/Zed/Computop/Persistence/ComputopEntityManager.php +++ b/src/SprykerEco/Zed/Computop/Persistence/ComputopEntityManager.php @@ -38,11 +38,11 @@ public function savePaymentComputopNotification(ComputopNotificationTransfer $co /** * @param \Generated\Shared\Transfer\ComputopNotificationTransfer $computopNotificationTransfer * - * @return void + * @return bool */ public function updatePaymentComputopOrderItemPaymentConfirmation( ComputopNotificationTransfer $computopNotificationTransfer - ): void { + ): bool { $paymentComputopOrderItemEntities = $this->getFactory() ->createPaymentComputopOrderItemQuery() ->useSpyPaymentComputopQuery() @@ -51,9 +51,15 @@ public function updatePaymentComputopOrderItemPaymentConfirmation( ->endUse() ->find(); + if (!$paymentComputopOrderItemEntities->count()) { + return false; + } + foreach ($paymentComputopOrderItemEntities as $paymentComputopOrderItemEntity) { $paymentComputopOrderItemEntity->setIsPaymentConfirmed($computopNotificationTransfer->getIsSuccess()); $paymentComputopOrderItemEntity->save(); } + + return true; } } diff --git a/src/SprykerEco/Zed/Computop/Persistence/ComputopEntityManagerInterface.php b/src/SprykerEco/Zed/Computop/Persistence/ComputopEntityManagerInterface.php index b4b94955c..84bf7b8a0 100644 --- a/src/SprykerEco/Zed/Computop/Persistence/ComputopEntityManagerInterface.php +++ b/src/SprykerEco/Zed/Computop/Persistence/ComputopEntityManagerInterface.php @@ -21,9 +21,9 @@ public function savePaymentComputopNotification(ComputopNotificationTransfer $co /** * @param \Generated\Shared\Transfer\ComputopNotificationTransfer $computopNotificationTransfer * - * @return void + * @return bool */ public function updatePaymentComputopOrderItemPaymentConfirmation( ComputopNotificationTransfer $computopNotificationTransfer - ): void; + ): bool; } From 070ed8c2c3e2a07ea4aee6ec4dd08eb11cd8042f Mon Sep 17 00:00:00 2001 From: Aleksey Kotsuba Date: Fri, 9 Oct 2020 11:39:29 +0300 Subject: [PATCH 2/3] SUPESC-180: Fix return type. --- .../Zed/Computop/Business/Processor/NotificationProcessor.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SprykerEco/Zed/Computop/Business/Processor/NotificationProcessor.php b/src/SprykerEco/Zed/Computop/Business/Processor/NotificationProcessor.php index 2dae01d88..1e7fdacdd 100644 --- a/src/SprykerEco/Zed/Computop/Business/Processor/NotificationProcessor.php +++ b/src/SprykerEco/Zed/Computop/Business/Processor/NotificationProcessor.php @@ -37,7 +37,7 @@ public function processNotification( ComputopNotificationTransfer $computopNotificationTransfer ): ComputopNotificationTransfer { return $this->getTransactionHandler()->handleTransaction( - function () use ($computopNotificationTransfer): void { + function () use ($computopNotificationTransfer): ComputopNotificationTransfer { return $this->executeSaveComputopNotificationTransaction($computopNotificationTransfer); } ); From 58e6a7d75fab8e1f758104e0b5e1d63f33ff45a3 Mon Sep 17 00:00:00 2001 From: Aleksey Kotsuba Date: Fri, 9 Oct 2020 11:44:31 +0300 Subject: [PATCH 3/3] Updated license. --- LICENSE | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/LICENSE b/LICENSE index c678ef8f0..73dcc7bf7 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ -MIT License +The MIT License (MIT) -Copyright (c) 2017 SPRYKER SYSTEMS GMBH +Copyright (c) 2016-present Spryker Systems GmbH Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. \ No newline at end of file +SOFTWARE.