From 5540c3d59a71e55af10a85a0750caacf433af7bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81ngel=20Campos?= Date: Tue, 23 Feb 2021 10:38:26 +0100 Subject: [PATCH 1/2] AP-264 add psp reference in a unified way --- Components/Manager/OrderManager.php | 41 ++++++++++++++++ Components/Manager/OrderManagerInterface.php | 15 ++++++ Controllers/Frontend/Process.php | 16 ++++-- Resources/services/managers.xml | 4 ++ Resources/services/subscribers.xml | 4 ++ Subscriber/Cronjob/ProcessNotifications.php | 1 - .../Notification/UpdateOrderPsPSubscriber.php | 49 +++++++++++++++++++ 7 files changed, 124 insertions(+), 6 deletions(-) create mode 100644 Components/Manager/OrderManager.php create mode 100644 Components/Manager/OrderManagerInterface.php create mode 100644 Subscriber/Notification/UpdateOrderPsPSubscriber.php diff --git a/Components/Manager/OrderManager.php b/Components/Manager/OrderManager.php new file mode 100644 index 00000000..cdd9bdba --- /dev/null +++ b/Components/Manager/OrderManager.php @@ -0,0 +1,41 @@ +modelManager = $modelManager; + } + + public function save(Order $order) + { + $this->modelManager->persist($order); + $this->modelManager->flush($order); + } + + public function updatePspReference(Order $order, string $pspReference) + { + $order = $order->setTransactionId($pspReference); + $this->modelManager->persist($order); + } + + public function updateOrderPayment(Order $order, string $pspReference, Status $paymentStatus) + { + $order->setPaymentStatus($paymentStatus); + $order = $order->setTransactionId($pspReference); + $this->modelManager->persist($order); + } +} diff --git a/Components/Manager/OrderManagerInterface.php b/Components/Manager/OrderManagerInterface.php new file mode 100644 index 00000000..89d89d8d --- /dev/null +++ b/Components/Manager/OrderManagerInterface.php @@ -0,0 +1,15 @@ +basketService = $this->get('adyen_payment.components.basket_service'); $this->orderMailService = $this->get('adyen_payment.components.order_mail_service'); $this->logger = $this->get('adyen_payment.logger'); + $this->orderManager = $this->get('AdyenPayment\Components\Manager\OrderManager'); } /** @@ -142,9 +146,11 @@ private function handleReturnResult(array $result, $order) break; } - $order->setPaymentStatus($paymentStatus); - $order->setTransactionId($result['pspReference']); - $this->getModelManager()->persist($order); + $this->orderManager->updateOrderPayment( + $order, + (string) ($result['pspReference'] ?? ''), + $paymentStatus + ); } /** diff --git a/Resources/services/managers.xml b/Resources/services/managers.xml index 13ce85e5..bdeff574 100644 --- a/Resources/services/managers.xml +++ b/Resources/services/managers.xml @@ -11,6 +11,10 @@ class="AdyenPayment\Components\NotificationManager"> + + + + diff --git a/Resources/services/subscribers.xml b/Resources/services/subscribers.xml index 0aa3273a..4874eff4 100644 --- a/Resources/services/subscribers.xml +++ b/Resources/services/subscribers.xml @@ -66,5 +66,9 @@ + + + + diff --git a/Subscriber/Cronjob/ProcessNotifications.php b/Subscriber/Cronjob/ProcessNotifications.php index 9793eab4..49ff6aee 100644 --- a/Subscriber/Cronjob/ProcessNotifications.php +++ b/Subscriber/Cronjob/ProcessNotifications.php @@ -81,7 +81,6 @@ public static function getSubscribedEvents() public function runCronjob(Shopware_Components_Cron_CronJob $job) { $textNotifications = $this->fifoTextNotificationLoader->get(); - $this->incomingNotificationManager->convertNotifications($textNotifications); /** @var \Generator $feedback */ diff --git a/Subscriber/Notification/UpdateOrderPsPSubscriber.php b/Subscriber/Notification/UpdateOrderPsPSubscriber.php new file mode 100644 index 00000000..1cf7d3ee --- /dev/null +++ b/Subscriber/Notification/UpdateOrderPsPSubscriber.php @@ -0,0 +1,49 @@ +orderManager = $orderManager; + } + + public static function getSubscribedEvents(): array + { + return [ + Event::NOTIFICATION_PROCESS_AUTHORISATION => '__invoke', + ]; + } + + public function __invoke(Enlight_Event_EventArgs $args) + { + /** + * @var \Shopware\Models\Order\Order $order + * @var \AdyenPayment\Models\Notification $notification + */ + $order = $args->get('order'); + $notification = $args->get('notification'); + if (!$notification->isSuccess()) { + return; + } + + if ($order->getTransactionId() === $notification->getPspReference()) { + return; + } + + $this->orderManager->updatePspReference($order, $notification->getPspReference()); + } +} From 2ed1faae19c0ca8319692818227d9fa3884cc2dd Mon Sep 17 00:00:00 2001 From: Filippe Bortels Date: Thu, 25 Feb 2021 15:42:02 +0100 Subject: [PATCH 2/2] AP-264 clean name --- Components/Manager/OrderManager.php | 2 +- Components/Manager/OrderManagerInterface.php | 2 +- Controllers/Frontend/Process.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Components/Manager/OrderManager.php b/Components/Manager/OrderManager.php index cdd9bdba..fc6f15cd 100644 --- a/Components/Manager/OrderManager.php +++ b/Components/Manager/OrderManager.php @@ -32,7 +32,7 @@ public function updatePspReference(Order $order, string $pspReference) $this->modelManager->persist($order); } - public function updateOrderPayment(Order $order, string $pspReference, Status $paymentStatus) + public function updatePayment(Order $order, string $pspReference, Status $paymentStatus) { $order->setPaymentStatus($paymentStatus); $order = $order->setTransactionId($pspReference); diff --git a/Components/Manager/OrderManagerInterface.php b/Components/Manager/OrderManagerInterface.php index 89d89d8d..dbee8f5e 100644 --- a/Components/Manager/OrderManagerInterface.php +++ b/Components/Manager/OrderManagerInterface.php @@ -11,5 +11,5 @@ interface OrderManagerInterface { public function save(Order $order); public function updatePspReference(Order $order, string $pspReference); - public function updateOrderPayment(Order $order, string $pspReference, Status $paymentStatus); + public function updatePayment(Order $order, string $pspReference, Status $paymentStatus); } diff --git a/Controllers/Frontend/Process.php b/Controllers/Frontend/Process.php index e5e7fa90..7623f0fb 100644 --- a/Controllers/Frontend/Process.php +++ b/Controllers/Frontend/Process.php @@ -146,7 +146,7 @@ private function handleReturnResult(array $result, $order) break; } - $this->orderManager->updateOrderPayment( + $this->orderManager->updatePayment( $order, (string) ($result['pspReference'] ?? ''), $paymentStatus