Merge pull request #2718 from woocommerce/PCP-3742-disable-gpay-sub

Remove Google Pay for subscriptions
This commit is contained in:
Emili Castells 2024-10-23 15:31:16 +02:00 committed by GitHub
commit 53b102402f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 90 additions and 36 deletions

View file

@ -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() {
}
}

View file

@ -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;
@ -1319,7 +1322,7 @@ document.querySelector("#payment").before(document.querySelector(".ppcp-messages
'needShipping' => $this->need_shipping(),
'vaultingEnabled' => $this->settings->has( 'vault_enabled' ) && $this->settings->get( 'vault_enabled' ),
'productType' => null,
'manualRenewalEnabled' => false,
'manualRenewalEnabled' => $this->subscription_helper->accept_manual_renewals(),
);
if ( is_product() ) {
@ -1329,15 +1332,6 @@ document.querySelector("#payment").before(document.querySelector(".ppcp-messages
}
}
if ( class_exists( '\WCS_Manual_Renewal_Manager' ) ) {
/**
* We verify the existence of the class prior to invoking a static method.
*
* @psalm-suppress UndefinedClass
*/
$localize['manualRenewalEnabled'] = \WCS_Manual_Renewal_Manager::is_manual_renewal_enabled();
}
if ( 'pay-now' === $this->context() ) {
$localize['pay_now'] = $this->pay_now_script_data();
}

View file

@ -174,6 +174,7 @@ return array(
$container->get( 'googlepay.sdk_url' ),
$container->get( 'ppcp.asset-version' ),
$container->get( 'session.handler' ),
$container->get( 'wc-subscriptions.helper' ),
$container->get( 'wcgateway.settings' ),
$container->get( 'onboarding.environment' ),
$container->get( 'wcgateway.settings.status' ),

View file

@ -21,6 +21,7 @@ use WooCommerce\PayPalCommerce\Session\SessionHandler;
use WooCommerce\PayPalCommerce\WcGateway\Exception\NotFoundException;
use WooCommerce\PayPalCommerce\WcGateway\Helper\SettingsStatus;
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
use WooCommerce\PayPalCommerce\WcSubscriptions\Helper\SubscriptionHelper;
/**
* Class Button
@ -85,37 +86,47 @@ class Button implements ButtonInterface {
*/
private $session_handler;
/**
* The Subscription Helper.
*
* @var SubscriptionHelper
*/
private $subscription_helper;
/**
* SmartButton constructor.
*
* @param string $module_url The URL to the module.
* @param string $sdk_url The URL to the SDK.
* @param string $version The assets version.
* @param SessionHandler $session_handler The Session handler.
* @param Settings $settings The Settings.
* @param Environment $environment The environment object.
* @param SettingsStatus $settings_status The Settings status helper.
* @param LoggerInterface $logger The logger.
* @param string $module_url The URL to the module.
* @param string $sdk_url The URL to the SDK.
* @param string $version The assets version.
* @param SessionHandler $session_handler The Session handler.
* @param SubscriptionHelper $subscription_helper The subscription helper.
* @param Settings $settings The Settings.
* @param Environment $environment The environment object.
* @param SettingsStatus $settings_status The Settings status helper.
* @param LoggerInterface $logger The logger.
*/
public function __construct(
string $module_url,
string $sdk_url,
string $version,
SessionHandler $session_handler,
SubscriptionHelper $subscription_helper,
Settings $settings,
Environment $environment,
SettingsStatus $settings_status,
LoggerInterface $logger
) {
$this->module_url = $module_url;
$this->sdk_url = $sdk_url;
$this->version = $version;
$this->session_handler = $session_handler;
$this->settings = $settings;
$this->environment = $environment;
$this->settings_status = $settings_status;
$this->logger = $logger;
$this->module_url = $module_url;
$this->sdk_url = $sdk_url;
$this->version = $version;
$this->session_handler = $session_handler;
$this->subscription_helper = $subscription_helper;
$this->settings = $settings;
$this->environment = $environment;
$this->settings_status = $settings_status;
$this->logger = $logger;
}
/**
@ -233,6 +244,21 @@ class Button implements ButtonInterface {
$button_enabled_payorder = true;
$button_enabled_minicart = $this->settings_status->is_smart_button_enabled_for_location( 'mini-cart' );
if (
$this->subscription_helper->plugin_is_active()
&& ! $this->subscription_helper->accept_manual_renewals()
) {
if ( is_product() && $this->subscription_helper->current_product_is_subscription() ) {
return false;
}
if ( $this->subscription_helper->order_pay_contains_subscription() ) {
return false;
}
if ( $this->subscription_helper->cart_contains_subscription() ) {
return false;
}
}
/**
* Param types removed to avoid third-party issues.
*

View file

@ -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();
}
/**