diff --git a/modules/ppcp-onboarding/src/State.php b/modules/ppcp-onboarding/src/State.php index 02bb23954..370fe95b4 100644 --- a/modules/ppcp-onboarding/src/State.php +++ b/modules/ppcp-onboarding/src/State.php @@ -48,6 +48,22 @@ class State { $this->settings = $settings; } + /** + * Returns the state of the specified environment (or the active environment if null). + * + * @param string|null $environment 'sandbox', 'production'. + * @return int + */ + public function environment_state( ?string $environment = null ): int { + switch ( $environment ) { + case Environment::PRODUCTION: + return $this->production_state(); + case Environment::SANDBOX: + return $this->sandbox_state(); + } + return $this->current_state(); + } + /** * Returns the current active onboarding state. * diff --git a/modules/ppcp-wc-gateway/services.php b/modules/ppcp-wc-gateway/services.php index 52e41da94..e4319ac8a 100644 --- a/modules/ppcp-wc-gateway/services.php +++ b/modules/ppcp-wc-gateway/services.php @@ -255,6 +255,8 @@ return array( 'wcgateway.settings.fields' => static function ( ContainerInterface $container ): array { $state = $container->get( 'onboarding.state' ); + assert( $state instanceof State ); + $messages_disclaimers = $container->get( 'button.helper.messages-disclaimers' ); $dcc_applies = $container->get( 'api.helpers.dccapplies' ); @@ -338,7 +340,8 @@ return array( 'screens' => array( State::STATE_START, ), - 'env' => 'production', + 'state_from' => Environment::PRODUCTION, + 'env' => Environment::PRODUCTION, 'products' => array( 'PPCP' ), 'requirements' => array(), 'gateway' => 'paypal', @@ -348,7 +351,8 @@ return array( 'screens' => array( State::STATE_START, ), - 'env' => 'production', + 'state_from' => Environment::PRODUCTION, + 'env' => Environment::PRODUCTION, 'products' => array( 'EXPRESS_CHECKOUT' ), 'requirements' => array(), 'gateway' => 'paypal', @@ -358,7 +362,8 @@ return array( 'screens' => array( State::STATE_START, ), - 'env' => 'sandbox', + 'state_from' => Environment::SANDBOX, + 'env' => Environment::SANDBOX, 'products' => array( 'PPCP' ), 'requirements' => array(), 'gateway' => 'paypal', @@ -369,7 +374,8 @@ return array( 'screens' => array( State::STATE_START, ), - 'env' => 'sandbox', + 'state_from' => Environment::SANDBOX, + 'env' => Environment::SANDBOX, 'products' => array( 'EXPRESS_CHECKOUT' ), 'requirements' => array(), 'gateway' => 'paypal', @@ -383,7 +389,8 @@ return array( 'screens' => array( State::STATE_ONBOARDED, ), - 'env' => 'production', + 'state_from' => Environment::PRODUCTION, + 'env' => Environment::PRODUCTION, 'requirements' => array(), 'gateway' => 'paypal', 'description' => __( 'Click to reset current credentials and use another account.', 'woocommerce-paypal-payments' ), @@ -395,7 +402,8 @@ return array( 'screens' => array( State::STATE_ONBOARDED, ), - 'env' => 'production', + 'state_from' => Environment::SANDBOX, + 'env' => Environment::SANDBOX, 'requirements' => array(), 'gateway' => 'paypal', 'description' => __( 'Click to reset current credentials and use another account.', 'woocommerce-paypal-payments' ), @@ -1909,14 +1917,6 @@ return array( unset( $fields['vault_enabled'] ); } - if ( State::STATE_ONBOARDED === $state->production_state() ) { - unset( $fields['ppcp_disconnect_sandbox'] ); - unset( $fields['credentials_sandbox_heading'] ); - } elseif ( State::STATE_ONBOARDED === $state->sandbox_state() ) { - unset( $fields['ppcp_disconnect_production'] ); - unset( $fields['credentials_production_heading'] ); - } - /** * Depending on your store location, some credit cards can't be used. * Here, we filter them out. diff --git a/modules/ppcp-wc-gateway/src/Settings/SettingsRenderer.php b/modules/ppcp-wc-gateway/src/Settings/SettingsRenderer.php index 04870b615..d5d68be4b 100644 --- a/modules/ppcp-wc-gateway/src/Settings/SettingsRenderer.php +++ b/modules/ppcp-wc-gateway/src/Settings/SettingsRenderer.php @@ -12,6 +12,7 @@ namespace WooCommerce\PayPalCommerce\WcGateway\Settings; use WooCommerce\PayPalCommerce\AdminNotices\Entity\Message; use WooCommerce\PayPalCommerce\ApiClient\Helper\DccApplies; use WooCommerce\PayPalCommerce\Button\Helper\MessagesApply; +use WooCommerce\PayPalCommerce\Onboarding\Environment; use WooCommerce\PayPalCommerce\Onboarding\State; use WooCommerce\PayPalCommerce\WcGateway\Gateway\CreditCardGateway; use Psr\Container\ContainerInterface; @@ -388,7 +389,7 @@ $data_rows_html fields as $field => $config ) : - if ( ! in_array( $this->state->current_state(), $config['screens'], true ) ) { + if ( ! in_array( $this->state->environment_state( $config['state_from'] ?? null ), $config['screens'], true ) ) { continue; } if ( ! $this->field_matches_page( $config, $this->page_id ) ) {