From 2dc42cf072a58bddec172bed51ca3256d5aa60c7 Mon Sep 17 00:00:00 2001 From: Alex P Date: Mon, 21 Oct 2024 09:45:09 +0300 Subject: [PATCH] Refactor manual renewal check --- .psalm/wcs.php | 37 +++++++++++++++++++ .../ppcp-button/src/Assets/SmartButton.php | 5 ++- .../src/Helper/SubscriptionHelper.php | 14 +++---- 3 files changed, 46 insertions(+), 10 deletions(-) diff --git a/.psalm/wcs.php b/.psalm/wcs.php index 1698c98c0..07c3c044c 100644 --- a/.psalm/wcs.php +++ b/.psalm/wcs.php @@ -2120,3 +2120,40 @@ class WC_Product_Subscription_Variation extends WC_Product_Variation {} * */ class WC_Product_Variable_Subscription extends WC_Product_Variable {} + +class WCS_Manual_Renewal_Manager { + + /** + * Initalise the class and attach callbacks. + */ + public static function init() { + } + + /** + * Adds the manual renewal settings. + * + * @since 4.0.0 + * @param $settings The full subscription settings array. + * @return $settings. + */ + public static function add_settings( $settings ) { + } + + /** + * Checks if manual renewals are required - automatic renewals are disabled. + * + * @since 4.0.0 + * @return bool Weather manual renewal is required. + */ + public static function is_manual_renewal_required() { + } + + /** + * Checks if manual renewals are enabled. + * + * @since 4.0.0 + * @return bool Weather manual renewal is enabled. + */ + public static function is_manual_renewal_enabled() { + } +} diff --git a/modules/ppcp-button/src/Assets/SmartButton.php b/modules/ppcp-button/src/Assets/SmartButton.php index 5884ad317..c37be80d6 100644 --- a/modules/ppcp-button/src/Assets/SmartButton.php +++ b/modules/ppcp-button/src/Assets/SmartButton.php @@ -1031,8 +1031,11 @@ document.querySelector("#payment").before(document.querySelector(".ppcp-messages * @return bool */ private function has_subscriptions(): bool { + if ( ! $this->subscription_helper->plugin_is_active() ) { + return false; + } if ( - ! $this->subscription_helper->accept_only_automatic_payment_gateways() + $this->subscription_helper->accept_manual_renewals() && $this->paypal_subscriptions_enabled() !== true ) { return false; diff --git a/modules/ppcp-wc-subscriptions/src/Helper/SubscriptionHelper.php b/modules/ppcp-wc-subscriptions/src/Helper/SubscriptionHelper.php index 969727d63..900e64214 100644 --- a/modules/ppcp-wc-subscriptions/src/Helper/SubscriptionHelper.php +++ b/modules/ppcp-wc-subscriptions/src/Helper/SubscriptionHelper.php @@ -17,6 +17,7 @@ use WC_Product_Subscription_Variation; use WC_Subscription; use WC_Subscriptions; use WC_Subscriptions_Product; +use WCS_Manual_Renewal_Manager; use WooCommerce\PayPalCommerce\WcGateway\Exception\NotFoundException; /** @@ -83,20 +84,15 @@ class SubscriptionHelper { } /** - * Whether only automatic payment gateways are accepted. + * Whether manual renewals are accepted. * * @return bool */ - public function accept_only_automatic_payment_gateways(): bool { - - if ( ! $this->plugin_is_active() ) { + public function accept_manual_renewals(): bool { + if ( ! class_exists( WCS_Manual_Renewal_Manager::class ) ) { return false; } - $accept_manual_renewals = 'no' !== get_option( - \WC_Subscriptions_Admin::$option_prefix . '_accept_manual_renewals', - 'no' - ); - return ! $accept_manual_renewals; + return WCS_Manual_Renewal_Manager::is_manual_renewal_enabled(); } /**