Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PIWOO-361] Disable authorisation when subscription product is in the cart #858

Merged
merged 5 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions inc/settings/mollie_advanced_settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@ class="mollie-settings-advanced-payment-desc-label button button-secondary butto
__('Clear now', 'mollie-payments-for-woocommerce')
) . '</a>)',
],
[
'id' => $pluginName . '_sectionend',
'type' => 'sectionend',
],
];

return apply_filters('inpsyde.mollie-advanced-settings', $mollieAdvancedSettings, $pluginName);
5 changes: 4 additions & 1 deletion src/MerchantCapture/Capture/Type/ManualCapture.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
22 changes: 21 additions & 1 deletion src/MerchantCapture/MerchantCaptureModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -127,6 +146,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;
Expand Down Expand Up @@ -205,7 +225,7 @@ static function ($disableShipAndCapture, WC_Order $order) use ($container) {
);
add_filter(
'inpsyde.mollie-advanced-settings',
['Mollie\WooCommerce\MerchantCapture\MollieCaptureSettings', 'settings'],
[$captureSettings, 'settings'],
10,
2
);
Expand Down
7 changes: 6 additions & 1 deletion src/MerchantCapture/MollieCaptureSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down Expand Up @@ -40,7 +45,7 @@ public function settings(array $advancedSettings, string $pluginName): array
),
],
[
'id' => $pluginName . '_sectionend',
'id' => $pluginName . '_capture_sectionend',
'type' => 'sectionend',
],
];
Expand Down
7 changes: 7 additions & 0 deletions src/MerchantCapture/OrderListPaymentColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Mollie\WooCommerce\MerchantCapture;

use Automattic\WooCommerce\Admin\Overrides\Order;
use Mollie\WooCommerce\MerchantCapture\UI\StatusRenderer;

class OrderListPaymentColumn
Expand All @@ -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
Expand Down
Loading