♻️ Refactor SectionsRenderer

This commit is contained in:
Philipp Stracker 2025-02-17 17:37:27 +01:00
parent cbe63eb080
commit 672b898eef
No known key found for this signature in database
2 changed files with 8 additions and 18 deletions

View file

@ -508,7 +508,7 @@ return array(
'wcgateway.settings.sections-renderer' => static function ( ContainerInterface $container ): SectionsRenderer { 'wcgateway.settings.sections-renderer' => static function ( ContainerInterface $container ): SectionsRenderer {
return new SectionsRenderer( return new SectionsRenderer(
$container->get( 'wcgateway.current-ppcp-settings-page-id' ), $container->get( 'wcgateway.current-ppcp-settings-page-id' ),
$container->get( 'onboarding.state' ), $container->get( 'settings.flag.is-connected' ),
$container->get( 'wcgateway.helper.dcc-product-status' ), $container->get( 'wcgateway.helper.dcc-product-status' ),
$container->get( 'api.helpers.dccapplies' ), $container->get( 'api.helpers.dccapplies' ),
$container->get( 'button.helper.messages-apply' ), $container->get( 'button.helper.messages-apply' ),

View file

@ -11,7 +11,6 @@ namespace WooCommerce\PayPalCommerce\WcGateway\Settings;
use WooCommerce\PayPalCommerce\ApiClient\Helper\DccApplies; use WooCommerce\PayPalCommerce\ApiClient\Helper\DccApplies;
use WooCommerce\PayPalCommerce\Button\Helper\MessagesApply; use WooCommerce\PayPalCommerce\Button\Helper\MessagesApply;
use WooCommerce\PayPalCommerce\Onboarding\State;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\CardButtonGateway; use WooCommerce\PayPalCommerce\WcGateway\Gateway\CardButtonGateway;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\CreditCardGateway; use WooCommerce\PayPalCommerce\WcGateway\Gateway\CreditCardGateway;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\OXXO\OXXOGateway; use WooCommerce\PayPalCommerce\WcGateway\Gateway\OXXO\OXXOGateway;
@ -35,11 +34,11 @@ class SectionsRenderer {
protected $page_id; protected $page_id;
/** /**
* The onboarding state. * Whether onboarding was completed and the merchant is connected to PayPal.
* *
* @var State * @var bool
*/ */
private $state; private bool $is_connected;
/** /**
* The DCC product status * The DCC product status
@ -69,18 +68,11 @@ class SectionsRenderer {
*/ */
private $pui_product_status; private $pui_product_status;
/**
* SectionsRenderer constructor.
*
* @param string $page_id ID of the current PPCP gateway settings page, or empty if it is not such page.
* @param State $state The onboarding state.
*/
/** /**
* SectionsRenderer constructor. * SectionsRenderer constructor.
* *
* @param string $page_id ID of the current PPCP gateway settings page, or empty if it is not such page. * @param string $page_id ID of the current PPCP gateway settings page, or empty if it is not such page.
* @param State $state The onboarding state. * @param bool $is_connected Whether the merchant completed onboarding.
* @param DCCProductStatus $dcc_product_status The DCC product status. * @param DCCProductStatus $dcc_product_status The DCC product status.
* @param DccApplies $dcc_applies The DCC applies. * @param DccApplies $dcc_applies The DCC applies.
* @param MessagesApply $messages_apply The Messages apply. * @param MessagesApply $messages_apply The Messages apply.
@ -88,14 +80,14 @@ class SectionsRenderer {
*/ */
public function __construct( public function __construct(
string $page_id, string $page_id,
State $state, bool $is_connected,
DCCProductStatus $dcc_product_status, DCCProductStatus $dcc_product_status,
DccApplies $dcc_applies, DccApplies $dcc_applies,
MessagesApply $messages_apply, MessagesApply $messages_apply,
PayUponInvoiceProductStatus $pui_product_status PayUponInvoiceProductStatus $pui_product_status
) { ) {
$this->page_id = $page_id; $this->page_id = $page_id;
$this->state = $state; $this->is_connected = $is_connected;
$this->dcc_product_status = $dcc_product_status; $this->dcc_product_status = $dcc_product_status;
$this->dcc_applies = $dcc_applies; $this->dcc_applies = $dcc_applies;
$this->messages_apply = $messages_apply; $this->messages_apply = $messages_apply;
@ -108,9 +100,7 @@ class SectionsRenderer {
* @return bool * @return bool
*/ */
public function should_render() : bool { public function should_render() : bool {
return ! empty( $this->page_id ) && return $this->page_id && $this->is_connected;
( $this->state->production_state() === State::STATE_ONBOARDED ||
$this->state->sandbox_state() === State::STATE_ONBOARDED );
} }
/** /**