From c27045f28718d85e6a86c19671186565446a550c Mon Sep 17 00:00:00 2001 From: inpsyde-maticluznar Date: Thu, 16 Nov 2023 10:32:59 +0100 Subject: [PATCH 1/4] Add after no payment action hook. --- src/Payment/MollieOrderService.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Payment/MollieOrderService.php b/src/Payment/MollieOrderService.php index 277d7a4f..9ce0ba6e 100644 --- a/src/Payment/MollieOrderService.php +++ b/src/Payment/MollieOrderService.php @@ -153,6 +153,7 @@ public function onWebhookAction() if ($order->get_status() === 'processing' && $payment->isCompleted() && method_exists($payment_object, 'onWebhookCompleted')) { $payment_object->onWebhookCompleted($order, $payment, $payment_method_title); } + do_action($this->pluginId . '_after_webhook_no_payment_action', $payment, $order); return; } From 5bcf8f683d733f7d780fb1242d8ff3f400f0875d Mon Sep 17 00:00:00 2001 From: inpsyde-maticluznar Date: Thu, 16 Nov 2023 14:06:12 +0100 Subject: [PATCH 2/4] Fix capture payment badge, when captured from Mollie dasboard --- src/MerchantCapture/Capture/Type/StateChangeCapture.php | 9 +++++++++ src/MerchantCapture/MerchantCaptureModule.php | 7 +++++-- src/Payment/MollieOrderService.php | 2 +- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/MerchantCapture/Capture/Type/StateChangeCapture.php b/src/MerchantCapture/Capture/Type/StateChangeCapture.php index 9e9ec3e8..c1a01e04 100644 --- a/src/MerchantCapture/Capture/Type/StateChangeCapture.php +++ b/src/MerchantCapture/Capture/Type/StateChangeCapture.php @@ -19,7 +19,16 @@ class StateChangeCapture public function __construct(ContainerInterface $container) { $this->container = $container; + $pluginId = $container->get('shared.plugin_id'); + add_action('woocommerce_order_status_changed', [$this, "orderStatusChange"], 10, 3); + + /** When the webhook process is activated we don't need automatic status change. Status change is handled + * by the webhook logic. + */ + add_action($pluginId . '_before_webhook_payment_action', function(){ + remove_action('woocommerce_order_status_changed', [$this, "orderStatusChange"], 10, 3); + }); } public function orderStatusChange(int $orderId, string $oldStatus, string $newStatus) diff --git a/src/MerchantCapture/MerchantCaptureModule.php b/src/MerchantCapture/MerchantCaptureModule.php index 9232061c..f97fba83 100644 --- a/src/MerchantCapture/MerchantCaptureModule.php +++ b/src/MerchantCapture/MerchantCaptureModule.php @@ -145,7 +145,10 @@ static function (Payment $payment, WC_Order $order) use ($container) { ManualCaptureStatus::STATUS_AUTHORIZED ); $order->save(); - } elseif ($payment->isPaid() && ($container->get('merchant.manual_capture.is_waiting'))($order)) { + } elseif ($payment->isPaid() && ( + ($container->get('merchant.manual_capture.is_waiting'))($order) || + ($container->get('merchant.manual_capture.is_authorized'))($order) + )) { $order->update_meta_data( self::ORDER_PAYMENT_STATUS_META_KEY, ManualCaptureStatus::STATUS_CAPTURED @@ -198,7 +201,7 @@ static function ($disableShipAndCapture, WC_Order $order) use ($container) { if ($disableShipAndCapture) { return true; } - return $container->get('merchant.manual_capture.is_waiting')($order); + return $container->get('merchant.manual_capture.is_waiting')($order) || $container->get('merchant.manual_capture.is_authorized')($order); }, 10, 2 diff --git a/src/Payment/MollieOrderService.php b/src/Payment/MollieOrderService.php index 9ce0ba6e..a5f5cfec 100644 --- a/src/Payment/MollieOrderService.php +++ b/src/Payment/MollieOrderService.php @@ -153,7 +153,6 @@ public function onWebhookAction() if ($order->get_status() === 'processing' && $payment->isCompleted() && method_exists($payment_object, 'onWebhookCompleted')) { $payment_object->onWebhookCompleted($order, $payment, $payment_method_title); } - do_action($this->pluginId . '_after_webhook_no_payment_action', $payment, $order); return; } @@ -163,6 +162,7 @@ public function onWebhookAction() } if (method_exists($payment_object, $method_name)) { + do_action($this->pluginId . '_before_webhook_payment_action', $payment, $order); $payment_object->{$method_name}($order, $payment, $payment_method_title); } else { $order->add_order_note(sprintf( From 141374e0be1cf1bb356e5bf5c20da3e250d0c0a4 Mon Sep 17 00:00:00 2001 From: inpsyde-maticluznar Date: Wed, 22 Nov 2023 09:02:23 +0100 Subject: [PATCH 3/4] Code style --- src/MerchantCapture/Capture/Type/StateChangeCapture.php | 4 ++-- src/MerchantCapture/MerchantCaptureModule.php | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/MerchantCapture/Capture/Type/StateChangeCapture.php b/src/MerchantCapture/Capture/Type/StateChangeCapture.php index c1a01e04..1bafca2d 100644 --- a/src/MerchantCapture/Capture/Type/StateChangeCapture.php +++ b/src/MerchantCapture/Capture/Type/StateChangeCapture.php @@ -26,8 +26,8 @@ public function __construct(ContainerInterface $container) /** When the webhook process is activated we don't need automatic status change. Status change is handled * by the webhook logic. */ - add_action($pluginId . '_before_webhook_payment_action', function(){ - remove_action('woocommerce_order_status_changed', [$this, "orderStatusChange"], 10, 3); + add_action($pluginId . '_before_webhook_payment_action', function () { + remove_action('woocommerce_order_status_changed', [$this, "orderStatusChange"]); }); } diff --git a/src/MerchantCapture/MerchantCaptureModule.php b/src/MerchantCapture/MerchantCaptureModule.php index f97fba83..9c52e722 100644 --- a/src/MerchantCapture/MerchantCaptureModule.php +++ b/src/MerchantCapture/MerchantCaptureModule.php @@ -145,10 +145,12 @@ static function (Payment $payment, WC_Order $order) use ($container) { ManualCaptureStatus::STATUS_AUTHORIZED ); $order->save(); - } elseif ($payment->isPaid() && ( + } elseif ( + $payment->isPaid() && ( ($container->get('merchant.manual_capture.is_waiting'))($order) || ($container->get('merchant.manual_capture.is_authorized'))($order) - )) { + ) + ) { $order->update_meta_data( self::ORDER_PAYMENT_STATUS_META_KEY, ManualCaptureStatus::STATUS_CAPTURED From 8348ba16132f79c056e3742eae0dc87ccb543726 Mon Sep 17 00:00:00 2001 From: inpsyde-maticluznar Date: Wed, 22 Nov 2023 09:24:03 +0100 Subject: [PATCH 4/4] Cancel payment if cancel triggered from Mollie dashboard --- src/MerchantCapture/MerchantCaptureModule.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/MerchantCapture/MerchantCaptureModule.php b/src/MerchantCapture/MerchantCaptureModule.php index 9c52e722..b1a7231f 100644 --- a/src/MerchantCapture/MerchantCaptureModule.php +++ b/src/MerchantCapture/MerchantCaptureModule.php @@ -135,6 +135,7 @@ public function run(ContainerInterface $container): bool add_action( $pluginId . '_after_webhook_action', static function (Payment $payment, WC_Order $order) use ($container) { + if ($payment->isAuthorized()) { if (!$payment->getAmountCaptured() == 0.0) { return; @@ -156,6 +157,17 @@ static function (Payment $payment, WC_Order $order) use ($container) { ManualCaptureStatus::STATUS_CAPTURED ); $order->save(); + } elseif ( + $payment->isCanceled() && ( + ($container->get('merchant.manual_capture.is_waiting'))($order) || + ($container->get('merchant.manual_capture.is_authorized'))($order) + ) + ) { + $order->update_meta_data( + self::ORDER_PAYMENT_STATUS_META_KEY, + ManualCaptureStatus::STATUS_VOIDED + ); + $order->save(); } }, 10,