2020use WooCommerce \PayPalCommerce \Settings \Data \PaymentSettings ;
2121use WooCommerce \PayPalCommerce \Settings \Data \SettingsProvider ;
2222use WooCommerce \PayPalCommerce \WcGateway \Processor \OrderProcessor ;
23+ use WooCommerce \PayPalCommerce \WcSubscriptions \Helper \SubscriptionHelper ;
2324use WooCommerce \PayPalCommerce \Webhooks \Handler \RequestHandlerTrait ;
2425
2526class ApplePayButton implements ButtonInterface {
@@ -40,6 +41,7 @@ class ApplePayButton implements ButtonInterface {
4041 private DataToAppleButtonScripts $ script_data ;
4142 protected CartProductsHelper $ cart_products ;
4243 private Context $ context ;
44+ private SubscriptionHelper $ subscription_helper ;
4345
4446 public function __construct (
4547 SettingsProvider $ settings_provider ,
@@ -50,20 +52,22 @@ public function __construct(
5052 string $ version ,
5153 DataToAppleButtonScripts $ data ,
5254 CartProductsHelper $ cart_products ,
53- Context $ context
55+ Context $ context ,
56+ SubscriptionHelper $ subscription_helper
5457 ) {
55- $ this ->settings_provider = $ settings_provider ;
56- $ this ->payment_settings = $ payment_settings ;
57- $ this ->response_templates = new ResponsesToApple ();
58- $ this ->logger = $ logger ;
59- $ this ->id = 'applepay ' ;
60- $ this ->method_title = __ ( 'Apple Pay ' , 'woocommerce-paypal-payments ' );
61- $ this ->order_processor = $ order_processor ;
62- $ this ->asset_getter = $ asset_getter ;
63- $ this ->version = $ version ;
64- $ this ->script_data = $ data ;
65- $ this ->cart_products = $ cart_products ;
66- $ this ->context = $ context ;
58+ $ this ->settings_provider = $ settings_provider ;
59+ $ this ->payment_settings = $ payment_settings ;
60+ $ this ->response_templates = new ResponsesToApple ();
61+ $ this ->logger = $ logger ;
62+ $ this ->id = 'applepay ' ;
63+ $ this ->method_title = __ ( 'Apple Pay ' , 'woocommerce-paypal-payments ' );
64+ $ this ->order_processor = $ order_processor ;
65+ $ this ->asset_getter = $ asset_getter ;
66+ $ this ->version = $ version ;
67+ $ this ->script_data = $ data ;
68+ $ this ->cart_products = $ cart_products ;
69+ $ this ->context = $ context ;
70+ $ this ->subscription_helper = $ subscription_helper ;
6771 }
6872
6973 public function initialize (): void {
@@ -783,6 +787,21 @@ public function render(): bool {
783787 return false ;
784788 }
785789
790+ if (
791+ $ this ->subscription_helper ->plugin_is_active ()
792+ && ! $ this ->subscription_helper ->accept_manual_renewals ()
793+ ) {
794+ if ( is_product () && $ this ->subscription_helper ->current_product_is_subscription () ) {
795+ return false ;
796+ }
797+ if ( $ this ->subscription_helper ->order_pay_contains_subscription () ) {
798+ return false ;
799+ }
800+ if ( $ this ->subscription_helper ->cart_contains_subscription () ) {
801+ return false ;
802+ }
803+ }
804+
786805 add_filter (
787806 'woocommerce_paypal_payments_sdk_components_hook ' ,
788807 function ( array $ components ) {
0 commit comments