id = $id; $this->state = $state; $this->settings = $settings; $this->is_payments_page = $is_payments_page; $this->is_ppcp_settings_page = $is_ppcp_settings_page; } /** * Returns the message. * * @return Message|null */ public function message(): ?Message { if ( ! $this->should_display() ) { return null; } $gateway = $this->get_gateway(); if ( ! $gateway ) { return null; } $name = $gateway->get_method_title(); $message = sprintf( /* translators: %1$s the gateway name, %2$s URL. */ __( '%1$s cannot be used without the PayPal gateway. Enable the PayPal gateway.', 'woocommerce-paypal-payments' ), $name, admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=ppcp-gateway' ) ); return new Message( $message, 'warning' ); } /** * Whether the message should be displayed. * * @return bool */ protected function should_display(): bool { if ( State::STATE_ONBOARDED !== $this->state->current_state() || ( ! $this->is_payments_page && ! $this->is_ppcp_settings_page ) ) { return false; } if ( $this->settings->has( 'enabled' ) && $this->settings->get( 'enabled' ) ) { return false; } $gateway = $this->get_gateway(); return $gateway && wc_string_to_bool( $gateway->get_option( 'enabled' ) ); } /** * Returns the gateway object or null. * * @return WC_Payment_Gateway|null */ protected function get_gateway(): ?WC_Payment_Gateway { $gateways = WC()->payment_gateways->payment_gateways(); if ( ! isset( $gateways[ $this->id ] ) ) { return null; } return $gateways[ $this->id ]; } }