mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
Refactor settings element state requirements checking
This commit is contained in:
parent
72c9bd1bef
commit
70ef7dd367
3 changed files with 32 additions and 15 deletions
|
@ -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.
|
||||
|
|
|
@ -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
|
|||
<?php
|
||||
|
||||
foreach ( $this->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 ) ) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue