module_url = untrailingslashit( $module_url ); $this->version = $version; $this->state = $state; $this->environment = $environment; $this->login_seller_endpoint = $login_seller_endpoint; $this->page_id = $page_id; } /** * Registers the scripts. * * @return bool */ public function register(): bool { $url = untrailingslashit( $this->module_url ) . '/assets/css/onboarding.css'; wp_register_style( 'ppcp-onboarding', $url, array(), $this->version ); $url = untrailingslashit( $this->module_url ) . '/assets/js/settings.js'; wp_register_script( 'ppcp-settings', $url, array(), $this->version, true ); wp_localize_script( 'ppcp-settings', 'PayPalCommerceSettings', array( 'empty_smart_button_location_message' => sprintf( '
', __( 'Note: If no button location is selected, the PayPal gateway will not be available.', 'woocommerce-paypal-payments' ) ), ) ); $url = untrailingslashit( $this->module_url ) . '/assets/js/onboarding.js'; wp_register_script( 'ppcp-onboarding', $url, array( 'jquery' ), $this->version, true ); wp_localize_script( 'ppcp-onboarding', 'PayPalCommerceGatewayOnboarding', $this->get_script_data() ); return true; } /** * Returns the data associated to the onboarding script. * * @return array */ public function get_script_data() { return array( 'endpoint' => \WC_AJAX::get_endpoint( LoginSellerEndpoint::ENDPOINT ), 'nonce' => wp_create_nonce( $this->login_seller_endpoint::nonce() ), 'paypal_js_url' => 'https://www.paypal.com/webapps/merchantboarding/js/lib/lightbox/partner.js', 'sandbox_state' => State::get_state_name( $this->state->sandbox_state() ), 'production_state' => State::get_state_name( $this->state->production_state() ), 'current_state' => State::get_state_name( $this->state->current_state() ), 'current_env' => $this->environment->current_environment(), 'error_messages' => array( 'no_credentials' => __( 'API credentials must be entered to save the settings.', 'woocommerce-paypal-payments' ), ), 'update_signup_links_endpoint' => \WC_AJAX::get_endpoint( UpdateSignupLinksEndpoint::ENDPOINT ), 'update_signup_links_nonce' => wp_create_nonce( UpdateSignupLinksEndpoint::ENDPOINT ), ); } /** * Enqueues the necessary scripts. * * @return bool */ public function enqueue(): bool { wp_enqueue_style( 'ppcp-onboarding' ); wp_enqueue_script( 'ppcp-settings' ); if ( ! $this->should_render_onboarding_script() ) { return false; } wp_enqueue_script( 'ppcp-onboarding' ); return true; } /** * Whether the onboarding script should be rendered or not. * * @return bool */ private function should_render_onboarding_script(): bool { return Settings::CONNECTION_TAB_ID === $this->page_id; } }