From 1ec0e43f8a4e3e49ea2017fb41d9d3029b8f3aeb Mon Sep 17 00:00:00 2001 From: inpsyde-maticluznar Date: Mon, 6 Nov 2023 16:47:20 +0100 Subject: [PATCH 1/4] Fix broken advanced settings. --- inc/settings/mollie_advanced_settings.php | 4 ++++ src/MerchantCapture/MerchantCaptureModule.php | 3 ++- src/MerchantCapture/MollieCaptureSettings.php | 7 ++++++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/inc/settings/mollie_advanced_settings.php b/inc/settings/mollie_advanced_settings.php index abfd156d..4b95b7a8 100644 --- a/inc/settings/mollie_advanced_settings.php +++ b/inc/settings/mollie_advanced_settings.php @@ -199,6 +199,10 @@ class="mollie-settings-advanced-payment-desc-label button button-secondary butto __('Clear now', 'mollie-payments-for-woocommerce') ) . ')', ], + [ + 'id' => $pluginName . '_sectionend', + 'type' => 'sectionend', + ] ]; return apply_filters('inpsyde.mollie-advanced-settings', $mollieAdvancedSettings, $pluginName); diff --git a/src/MerchantCapture/MerchantCaptureModule.php b/src/MerchantCapture/MerchantCaptureModule.php index 9232061c..15b3ca73 100644 --- a/src/MerchantCapture/MerchantCaptureModule.php +++ b/src/MerchantCapture/MerchantCaptureModule.php @@ -127,6 +127,7 @@ public function run(ContainerInterface $container): bool { add_action('init', static function () use ($container) { $pluginId = $container->get('shared.plugin_id'); + $captureSettings = new MollieCaptureSettings(); if (!apply_filters('mollie_wc_gateway_enable_merchant_capture_module', false)) { return; @@ -205,7 +206,7 @@ static function ($disableShipAndCapture, WC_Order $order) use ($container) { ); add_filter( 'inpsyde.mollie-advanced-settings', - ['Mollie\WooCommerce\MerchantCapture\MollieCaptureSettings', 'settings'], + [$captureSettings, 'settings'], 10, 2 ); diff --git a/src/MerchantCapture/MollieCaptureSettings.php b/src/MerchantCapture/MollieCaptureSettings.php index 8a9a2091..f263c1b4 100644 --- a/src/MerchantCapture/MollieCaptureSettings.php +++ b/src/MerchantCapture/MollieCaptureSettings.php @@ -9,6 +9,11 @@ class MollieCaptureSettings public function settings(array $advancedSettings, string $pluginName): array { $mollieCaptureSettings = [ + [ + 'id' => $pluginName . '_capture_empty_title', + 'title' => '', + 'type' => 'title', + ], [ 'id' => $pluginName . '_place_payment_onhold', 'title' => __('Placing payments on Hold', 'mollie-payments-for-woocommerce'), @@ -40,7 +45,7 @@ public function settings(array $advancedSettings, string $pluginName): array ), ], [ - 'id' => $pluginName . '_sectionend', + 'id' => $pluginName . '_capture_sectionend', 'type' => 'sectionend', ], ]; From fc5932ce6d959a5f621c79170f6fb5a129c024ca Mon Sep 17 00:00:00 2001 From: inpsyde-maticluznar Date: Mon, 6 Nov 2023 16:50:24 +0100 Subject: [PATCH 2/4] Code style --- inc/settings/mollie_advanced_settings.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/settings/mollie_advanced_settings.php b/inc/settings/mollie_advanced_settings.php index 4b95b7a8..553eb31c 100644 --- a/inc/settings/mollie_advanced_settings.php +++ b/inc/settings/mollie_advanced_settings.php @@ -202,7 +202,7 @@ class="mollie-settings-advanced-payment-desc-label button button-secondary butto [ 'id' => $pluginName . '_sectionend', 'type' => 'sectionend', - ] + ], ]; return apply_filters('inpsyde.mollie-advanced-settings', $mollieAdvancedSettings, $pluginName); From 93896bd209fab8d630038d8394adb3799af27d17 Mon Sep 17 00:00:00 2001 From: inpsyde-maticluznar Date: Tue, 7 Nov 2023 12:00:41 +0100 Subject: [PATCH 3/4] Set automatic capture when subscription product is in the cart --- .../Capture/Type/ManualCapture.php | 5 ++++- src/MerchantCapture/MerchantCaptureModule.php | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/MerchantCapture/Capture/Type/ManualCapture.php b/src/MerchantCapture/Capture/Type/ManualCapture.php index 70c890c2..81a782e9 100644 --- a/src/MerchantCapture/Capture/Type/ManualCapture.php +++ b/src/MerchantCapture/Capture/Type/ManualCapture.php @@ -37,7 +37,10 @@ public function enableOrderCaptureButton(array $actions, \WC_Order $order): arra public function sendManualCaptureMode(array $paymentData): array { - if ($this->container->get('merchant.manual_capture.enabled')) { + if ( + $this->container->get('merchant.manual_capture.enabled') && + $this->container->get('merchant.manual_capture.cart_can_be_captured') + ) { $paymentData['captureMode'] = 'manual'; } return $paymentData; diff --git a/src/MerchantCapture/MerchantCaptureModule.php b/src/MerchantCapture/MerchantCaptureModule.php index 9232061c..1c02ea3c 100644 --- a/src/MerchantCapture/MerchantCaptureModule.php +++ b/src/MerchantCapture/MerchantCaptureModule.php @@ -88,6 +88,25 @@ public function services(): array 'merchant.manual_capture.on_status_change_enabled' => static function () { return get_option('mollie-payments-for-woocommerce_capture_or_void', false); }, + 'merchant.manual_capture.cart_can_be_captured' => static function (): bool { + if (!class_exists(\WC_Product_Subscription::class)) { + return true; + } + $cart = WC()->cart; + if (!is_a($cart, \WC_Cart::class)) { + return false; + } + $cartItems = $cart->get_cart_contents(); + + foreach ($cartItems as $cartItemData) { + $cartItem = $cartItemData['data']; + + if (is_a($cartItem, \WC_Product_Subscription::class)) { + return false; + } + } + return true; + }, CapturePayment::class => static function ($container) { return static function (int $orderId) use ($container) { /** @var Api $api */ From 001dee4402020b53cff92f8cbf56d35d9a860703 Mon Sep 17 00:00:00 2001 From: inpsyde-maticluznar Date: Fri, 17 Nov 2023 12:00:22 +0100 Subject: [PATCH 4/4] Add HPOS filters for order colums --- src/MerchantCapture/OrderListPaymentColumn.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/MerchantCapture/OrderListPaymentColumn.php b/src/MerchantCapture/OrderListPaymentColumn.php index 6447336b..d74a9173 100644 --- a/src/MerchantCapture/OrderListPaymentColumn.php +++ b/src/MerchantCapture/OrderListPaymentColumn.php @@ -4,6 +4,7 @@ namespace Mollie\WooCommerce\MerchantCapture; +use Automattic\WooCommerce\Admin\Overrides\Order; use Mollie\WooCommerce\MerchantCapture\UI\StatusRenderer; class OrderListPaymentColumn @@ -12,6 +13,12 @@ public function __construct() { add_filter('manage_edit-shop_order_columns', [$this, 'renderColumn']); add_action('manage_shop_order_posts_custom_column', [$this, 'renderColumnValue'], 10, 2); + + # HPOS hooks + add_filter('woocommerce_shop_order_list_table_columns', [$this, 'renderColumn']); + add_action('woocommerce_shop_order_list_table_custom_column', function (string $column, Order $order) { + $this->renderColumnValue($column, $order->get_id()); + }, 10, 2); } public function renderColumn(array $columns): array