module_url = $module_url; $this->version = $version; $this->subscription_helper = $subscription_helper; $this->client_id = $client_id; $this->currency = $currency; $this->country = $country; $this->environment = $environment; $this->is_pay_later_button_enabled = $is_pay_later_button_enabled; $this->disabled_sources = $disabled_sources; $this->all_funding_sources = $all_funding_sources; $this->is_settings_page = $is_settings_page; $this->is_acdc_enabled = $is_acdc_enabled; $this->billing_agreements_endpoint = $billing_agreements_endpoint; } /** * Register assets provided by this module. * * @return void */ public function register_assets(): void { add_action( 'admin_enqueue_scripts', function() { if ( ! is_admin() || wp_doing_ajax() ) { return; } if ( $this->is_settings_page ) { $this->register_admin_assets(); } if ( $this->is_paypal_payment_method_page() ) { $this->register_paypal_admin_assets(); } } ); } /** * Check whether the current page is PayPal payment method settings. * * @return bool */ private function is_paypal_payment_method_page(): bool { if ( ! function_exists( 'get_current_screen' ) ) { return false; } $screen = get_current_screen(); if ( ! $screen || $screen->id !== 'woocommerce_page_wc-settings' ) { return false; } // phpcs:disable WordPress.Security.NonceVerification.Recommended $tab = wc_clean( wp_unslash( $_GET['tab'] ?? '' ) ); $section = wc_clean( wp_unslash( $_GET['section'] ?? '' ) ); // phpcs:enable WordPress.Security.NonceVerification.Recommended return 'checkout' === $tab && in_array( $section, array( PayPalGateway::ID, CardButtonGateway::ID ), true ); } /** * Register assets for PayPal admin pages. */ private function register_paypal_admin_assets(): void { wp_enqueue_style( 'ppcp-gateway-settings', trailingslashit( $this->module_url ) . 'assets/css/gateway-settings.css', array(), $this->version ); wp_enqueue_script( 'ppcp-gateway-settings', trailingslashit( $this->module_url ) . 'assets/js/gateway-settings.js', array(), $this->version, true ); /** * Psalm cannot find it for some reason. * * @psalm-suppress UndefinedConstant */ wp_localize_script( 'ppcp-gateway-settings', 'PayPalCommerceGatewaySettings', apply_filters( 'woocommerce_paypal_payments_admin_gateway_settings', array( 'is_subscriptions_plugin_active' => $this->subscription_helper->plugin_is_active(), 'client_id' => $this->client_id, 'currency' => $this->currency, 'country' => $this->country, 'environment' => $this->environment->current_environment(), 'integration_date' => PAYPAL_INTEGRATION_DATE, 'is_pay_later_button_enabled' => $this->is_pay_later_button_enabled, 'is_acdc_enabled' => $this->is_acdc_enabled, 'disabled_sources' => $this->disabled_sources, 'all_funding_sources' => $this->all_funding_sources, 'components' => array( 'buttons', 'funding-eligibility', 'messages' ), 'ajax' => array( 'refresh_feature_status' => array( 'endpoint' => \WC_AJAX::get_endpoint( RefreshFeatureStatusEndpoint::ENDPOINT ), 'nonce' => wp_create_nonce( RefreshFeatureStatusEndpoint::nonce() ), 'button' => '.ppcp-refresh-feature-status', 'messages' => array( 'waiting' => __( 'Checking features...', 'woocommerce-paypal-payments' ), 'success' => __( 'Feature status refreshed.', 'woocommerce-paypal-payments' ), ), ), ), 'reference_transaction_enabled' => $this->billing_agreements_endpoint->reference_transaction_enabled(), 'vaulting_must_enable_advanced_wallet_message' => sprintf( // translators: %1$s and %2$s are the opening and closing of HTML tag. esc_html__( 'Your PayPal account must be enabled for the %1$sAdvanced PayPal Wallet%2$s to use PayPal Vaulting.', 'woocommerce-paypal-payments' ), '', '' ), ) ) ); } /** * Register assets for PayPal admin pages. */ private function register_admin_assets(): void { wp_enqueue_style( 'ppcp-admin-common', trailingslashit( $this->module_url ) . 'assets/css/common.css', array(), $this->version ); wp_enqueue_script( 'ppcp-admin-common', trailingslashit( $this->module_url ) . 'assets/js/common.js', array(), $this->version, true ); } }