diff --git a/modules/ppcp-applepay/src/ApplepayModule.php b/modules/ppcp-applepay/src/ApplepayModule.php index b41ff09bc..9752642a3 100644 --- a/modules/ppcp-applepay/src/ApplepayModule.php +++ b/modules/ppcp-applepay/src/ApplepayModule.php @@ -14,6 +14,7 @@ use WooCommerce\PayPalCommerce\ApiClient\Helper\Cache; use WooCommerce\PayPalCommerce\Applepay\Assets\ApplePayButton; use WooCommerce\PayPalCommerce\Applepay\Assets\AppleProductStatus; use WooCommerce\PayPalCommerce\Button\Assets\ButtonInterface; +use WooCommerce\PayPalCommerce\Button\Assets\SmartButtonInterface; use WooCommerce\PayPalCommerce\Onboarding\Environment; use WooCommerce\PayPalCommerce\Vendor\Dhii\Container\ServiceProvider; use WooCommerce\PayPalCommerce\Vendor\Dhii\Modular\Module\ModuleInterface; @@ -90,12 +91,6 @@ class ApplepayModule implements ModuleInterface { $this->render_buttons( $c ); assert( $apple_payment_method instanceof ApplepayButton ); $apple_payment_method->bootstrap_ajax_request(); - add_action( - 'woocommerce_blocks_payment_method_type_registration', - function( PaymentMethodRegistry $payment_method_registry ) use ( $c ): void { - $payment_method_registry->register( $c->get( 'applepay.blocks-payment-method' ) ); - } - ); $this->remove_status_cache( $c ); } @@ -143,11 +138,19 @@ class ApplepayModule implements ModuleInterface { function () use ( $c ) { $button = $c->get( 'applepay.button' ); assert( $button instanceof ApplePayButton ); - if ( $button->should_load_script() ) { + $smart_button = $c->get( 'button.smart-button' ); + assert( $smart_button instanceof SmartButtonInterface ); + if ( $smart_button->should_load_ppcp_script() ) { $button->enqueue(); } } ); + add_action( + 'woocommerce_blocks_payment_method_type_registration', + function( PaymentMethodRegistry $payment_method_registry ) use ( $c ): void { + $payment_method_registry->register( $c->get( 'applepay.blocks-payment-method' ) ); + } + ); } /** diff --git a/modules/ppcp-applepay/src/Assets/ApplePayButton.php b/modules/ppcp-applepay/src/Assets/ApplePayButton.php index 3970fde35..a4b58f584 100644 --- a/modules/ppcp-applepay/src/Assets/ApplePayButton.php +++ b/modules/ppcp-applepay/src/Assets/ApplePayButton.php @@ -1052,7 +1052,11 @@ class ApplePayButton implements ButtonInterface { * @return bool */ public function is_enabled(): bool { - // TODO: Implement is_enabled() method. - return true; + try { + //todo add also onboarded apple and enabled buttons + return $this->settings->has( 'applepay_button_enabled' ) && $this->settings->get( 'applepay_button_enabled' ); + } catch ( Exception $e ) { + return false; + } } }