♻️ Refactor GatewayWithoutPayPalAdminNotice

This commit is contained in:
Philipp Stracker 2025-02-17 17:12:47 +01:00
parent bdd6c23e3c
commit cf90b1706c
No known key found for this signature in database
2 changed files with 9 additions and 10 deletions

View file

@ -351,7 +351,7 @@ return array(
'wcgateway.notice.dcc-without-paypal' => static function ( ContainerInterface $container ): GatewayWithoutPayPalAdminNotice {
return new GatewayWithoutPayPalAdminNotice(
CreditCardGateway::ID,
$container->get( 'onboarding.state' ),
$container->get( 'settings.flag.is-connected' ),
$container->get( 'wcgateway.settings' ),
$container->get( 'wcgateway.is-wc-payments-page' ),
$container->get( 'wcgateway.is-ppcp-settings-page' )
@ -360,7 +360,7 @@ return array(
'wcgateway.notice.card-button-without-paypal' => static function ( ContainerInterface $container ): GatewayWithoutPayPalAdminNotice {
return new GatewayWithoutPayPalAdminNotice(
CardButtonGateway::ID,
$container->get( 'onboarding.state' ),
$container->get( 'settings.flag.is-connected' ),
$container->get( 'wcgateway.settings' ),
$container->get( 'wcgateway.is-wc-payments-page' ),
$container->get( 'wcgateway.is-ppcp-settings-page' ),

View file

@ -11,7 +11,6 @@ namespace WooCommerce\PayPalCommerce\WcGateway\Notice;
use WC_Payment_Gateway;
use WooCommerce\PayPalCommerce\AdminNotices\Entity\Message;
use WooCommerce\PayPalCommerce\Onboarding\State;
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
use WooCommerce\PayPalCommerce\WcGateway\Helper\SettingsStatus;
@ -32,11 +31,11 @@ class GatewayWithoutPayPalAdminNotice {
private $id;
/**
* The state.
* Whether the merchant completed onboarding.
*
* @var State
* @var bool
*/
private $state;
private bool $is_connected;
/**
* The settings.
@ -70,7 +69,7 @@ class GatewayWithoutPayPalAdminNotice {
* ConnectAdminNotice constructor.
*
* @param string $id The gateway ID.
* @param State $state The state.
* @param bool $is_connected Whether onboading was completed.
* @param ContainerInterface $settings The settings.
* @param bool $is_payments_page Whether the current page is the WC payment page.
* @param bool $is_ppcp_settings_page Whether the current page is the PPCP settings page.
@ -78,14 +77,14 @@ class GatewayWithoutPayPalAdminNotice {
*/
public function __construct(
string $id,
State $state,
bool $is_connected,
ContainerInterface $settings,
bool $is_payments_page,
bool $is_ppcp_settings_page,
?SettingsStatus $settings_status = null
) {
$this->id = $id;
$this->state = $state;
$this->is_connected = $is_connected;
$this->settings = $settings;
$this->is_payments_page = $is_payments_page;
$this->is_ppcp_settings_page = $is_ppcp_settings_page;
@ -161,7 +160,7 @@ class GatewayWithoutPayPalAdminNotice {
* @return string One of the NOTICE_* constants.
*/
protected function check(): string {
if ( State::STATE_ONBOARDED !== $this->state->current_state() ||
if ( ! $this->is_connected ||
( ! $this->is_payments_page && ! $this->is_ppcp_settings_page ) ) {
return self::NOTICE_OK;
}