From 8f96f2b3a8db5cf467e4c322a25da8d0ee1c11ed Mon Sep 17 00:00:00 2001 From: Reinder Date: Mon, 29 Jun 2020 16:48:16 +0200 Subject: [PATCH] Fixed an issue where Mollie order statuses couldn't be taken over by Shopware anymore. Fixed an issue where order status updates through the Shopware API wouldn't ship the order to Klarna on the right status. --- Components/MollieApiFactory.php | 2 +- Components/Services/PaymentService.php | 6 +++++ Controllers/Frontend/Mollie.php | 12 +-------- MollieShopware.php | 2 ++ Resources/services.xml | 1 + Subscriber/OrderBackendSubscriber.php | 37 ++++++++++++++++++++------ plugin.xml | 8 +++--- 7 files changed, 44 insertions(+), 24 deletions(-) diff --git a/Components/MollieApiFactory.php b/Components/MollieApiFactory.php index f34549f0..b2f999b5 100644 --- a/Components/MollieApiFactory.php +++ b/Components/MollieApiFactory.php @@ -51,7 +51,7 @@ public function create($shopId = null) // add plugin name and version $this->apiClient->addVersionString( - 'MollieShopware/1.5.14' + 'MollieShopware/1.5.15' ); } catch (\Exception $ex) { diff --git a/Components/Services/PaymentService.php b/Components/Services/PaymentService.php index d0c29d98..daa0a2cf 100644 --- a/Components/Services/PaymentService.php +++ b/Components/Services/PaymentService.php @@ -624,6 +624,7 @@ protected function getCreditCardToken() */ public function updateOrderStatus(\Shopware\Models\Order\Order $order, $transactionId) { + $orderId = null; $paymentId = null; /** @var TransactionRepository $transactionRepo */ @@ -635,9 +636,14 @@ public function updateOrderStatus(\Shopware\Models\Order\Order $order, $transact $transaction = $transactionRepo->find($transactionId); if ($transaction !== null) { + $orderId = $transaction->getMollieId(); $paymentId = $transaction->getMolliePaymentId(); } + if ($orderId !== null) { + $this->checkOrderStatus($order); + } + return $this->checkPaymentStatus($order, $paymentId); } diff --git a/Controllers/Frontend/Mollie.php b/Controllers/Frontend/Mollie.php index 40e65c1f..5e42aedb 100644 --- a/Controllers/Frontend/Mollie.php +++ b/Controllers/Frontend/Mollie.php @@ -264,16 +264,6 @@ public function notifyAction() $paymentService = $this->container ->get('mollie_shopware.payment_service'); - try { - $order = $this->getOrder(); - } - catch(\Exception $e) { - Notifier::notifyException( - $e->getMessage(), - $e - ); - } - if ( $transactionNumber !== '' && ($order === null || !$order instanceof \Shopware\Models\Order\Order) @@ -310,7 +300,7 @@ public function notifyAction() ); } } else { - Notifier::notifyException( + Notifier::notifyOk( 'Order not found' ); } diff --git a/MollieShopware.php b/MollieShopware.php index 6a0824bd..7d571f73 100644 --- a/MollieShopware.php +++ b/MollieShopware.php @@ -151,6 +151,8 @@ public function install(InstallContext $context) /** * @param UpdateContext $context + * + * @throws Exception */ public function update(UpdateContext $context) { diff --git a/Resources/services.xml b/Resources/services.xml index b288a77f..eafe0466 100644 --- a/Resources/services.xml +++ b/Resources/services.xml @@ -93,6 +93,7 @@ + diff --git a/Subscriber/OrderBackendSubscriber.php b/Subscriber/OrderBackendSubscriber.php index d8f7cd7c..5fe35072 100644 --- a/Subscriber/OrderBackendSubscriber.php +++ b/Subscriber/OrderBackendSubscriber.php @@ -6,9 +6,14 @@ use MollieShopware\Components\Config; use MollieShopware\Components\Helpers\LogHelper; use MollieShopware\Components\Logger; +use MollieShopware\Components\Services\OrderService; +use Shopware\Models\Order\Order; class OrderBackendSubscriber implements SubscriberInterface { + /** @var OrderService */ + private $orderService; + public static function getSubscribedEvents() { return [ @@ -18,6 +23,11 @@ public static function getSubscribedEvents() ]; } + public function __construct(OrderService $orderService) + { + $this->orderService = $orderService; + } + /** * Catch mailvariables when the confirmation email is triggered and store * them in the database to use them when the order is fully processed. @@ -103,28 +113,39 @@ public function onOrderApiPut(\Enlight_Hook_HookArgs $args) return true; } + /** @var Order $order */ + $order = null; + + /** @var int|string $orderId */ $orderId = $request->getParam('id'); + /** @var bool $numberAsId */ + $numberAsId = (bool) $request->getParam('useNumberAsId', 0); + if (empty($orderId)) { return true; } + if ($numberAsId === true) { + $order = $this->orderService->getOrderByNumber($orderId); + } + + if ($order !== null) { + $orderId = $order->getId(); + } + return $this->shipOrderToMollie($orderId); } private function shipOrderToMollie($orderId) { + /** @var \Shopware\Models\Order\Order $order */ $order = null; try { - /** @var \MollieShopware\Components\Services\OrderService $orderService */ - $orderService = Shopware()->Container() - ->get('mollie_shopware.order_service'); - - /** @var \Shopware\Models\Order\Order $order */ - $order = $orderService->getOrderById($orderId); + $order = $this->orderService->getOrderById($orderId); } catch (\Exception $e) { - LogHelper::logMessage($e->getMessage(), LogHelper::LOG_ERROR, $e); + // } if ($order === null) { @@ -134,7 +155,7 @@ private function shipOrderToMollie($orderId) $mollieId = null; try { - $mollieId = $orderService->getMollieOrderId($order); + $mollieId = $this->orderService->getMollieOrderId($order->getId()); } catch (\Exception $e) { LogHelper::logMessage($e->getMessage(), LogHelper::LOG_ERROR, $e); } diff --git a/plugin.xml b/plugin.xml index 1599fd6a..036833be 100644 --- a/plugin.xml +++ b/plugin.xml @@ -6,14 +6,14 @@ - 1.5.14 + 1.5.15 (c) Mollie B.V. Kiener E-commerce https://www.kiener.nl - Plugin to allow iDeal payments using the Mollie API (1.5.14) - Plugin die iDealbetalingen via de Mollie API doorgeeft (1.5.14) - Plugin um Zahlungen mit der Mollie API zu ermöglichen (1.5.14) + Plugin to allow iDeal payments using the Mollie API (1.5.15) + Plugin die iDealbetalingen via de Mollie API doorgeeft (1.5.15) + Plugin um Zahlungen mit der Mollie API zu ermöglichen (1.5.15) \ No newline at end of file