module_url = $module_url; $this->version = $version; $this->subscription_helper = $subscription_helper; $this->client_id = $client_id; $this->currency = $currency; $this->country = $country; $this->is_pay_later_button_enabled = $is_pay_later_button_enabled; } /** * Register assets provided by this module. */ public function register_assets() { add_action( 'admin_enqueue_scripts', function() { if ( ! is_admin() || wp_doing_ajax() ) { return; } if ( ! $this->is_paypal_payment_method_page() ) { return; } $this->register_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->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 && 'ppcp-gateway' === $section; } /** * Register assets for admin pages. */ private function register_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', array( 'is_subscriptions_plugin_active' => $this->subscription_helper->plugin_is_active(), 'client_id' => $this->client_id, 'currency' => $this->currency, 'country' => $this->country, 'integration_date' => PAYPAL_INTEGRATION_DATE, 'is_pay_later_button_enabled' => $this->is_pay_later_button_enabled, ) ); } }