Merge pull request #821 from woocommerce/PCP-885-connection-tab-improvements

Connection tab improvements
This commit is contained in:
Emili Castells 2022-09-06 14:56:40 +02:00 committed by GitHub
commit bf4a94099f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 40 additions and 45 deletions

View file

@ -16,6 +16,7 @@ use WooCommerce\PayPalCommerce\ApiClient\Helper\DccApplies;
use WooCommerce\PayPalCommerce\Onboarding\Environment;
use WooCommerce\PayPalCommerce\Onboarding\Render\OnboardingOptionsRenderer;
use WooCommerce\PayPalCommerce\Onboarding\State;
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
return function ( ContainerInterface $container, array $fields ): array {
@ -63,7 +64,7 @@ return function ( ContainerInterface $container, array $fields ): array {
State::STATE_ONBOARDED,
),
'requirements' => array(),
'gateway' => 'connection',
'gateway' => Settings::CONNECTION_TAB_ID,
),
'credentials_production_heading' => array(
'heading' => __( 'API Credentials', 'woocommerce-paypal-payments' ),
@ -73,7 +74,7 @@ return function ( ContainerInterface $container, array $fields ): array {
),
'state_from' => Environment::PRODUCTION,
'requirements' => array(),
'gateway' => 'connection',
'gateway' => Settings::CONNECTION_TAB_ID,
),
'credentials_sandbox_heading' => array(
'heading' => __( 'Sandbox API Credentials', 'woocommerce-paypal-payments' ),
@ -83,7 +84,7 @@ return function ( ContainerInterface $container, array $fields ): array {
),
'state_from' => Environment::SANDBOX,
'requirements' => array(),
'gateway' => 'connection',
'gateway' => Settings::CONNECTION_TAB_ID,
'description' => __( 'Your account is connected to sandbox, no real charging takes place. To accept live payments, turn off sandbox mode and connect your live PayPal account.', 'woocommerce-paypal-payments' ),
),
@ -97,7 +98,7 @@ return function ( ContainerInterface $container, array $fields ): array {
State::STATE_ONBOARDED,
),
'requirements' => array(),
'gateway' => 'connection',
'gateway' => Settings::CONNECTION_TAB_ID,
),
// We need to have a button for each option (ppcp, express)
@ -113,7 +114,7 @@ return function ( ContainerInterface $container, array $fields ): array {
'env' => Environment::PRODUCTION,
'products' => array( 'PPCP' ),
'requirements' => array(),
'gateway' => 'connection',
'gateway' => Settings::CONNECTION_TAB_ID,
),
'ppcp_onboarding_production_express' => array(
'type' => 'ppcp_onboarding',
@ -125,7 +126,7 @@ return function ( ContainerInterface $container, array $fields ): array {
'env' => Environment::PRODUCTION,
'products' => array( 'EXPRESS_CHECKOUT' ),
'requirements' => array(),
'gateway' => 'connection',
'gateway' => Settings::CONNECTION_TAB_ID,
),
'ppcp_onboarding_sandbox_ppcp' => array(
'type' => 'ppcp_onboarding',
@ -137,7 +138,7 @@ return function ( ContainerInterface $container, array $fields ): array {
'env' => Environment::SANDBOX,
'products' => array( 'PPCP' ),
'requirements' => array(),
'gateway' => 'connection',
'gateway' => Settings::CONNECTION_TAB_ID,
'description' => __( 'Prior to accepting live payments, you can test payments on your WooCommerce platform in a safe PayPal sandbox environment.', 'woocommerce-paypal-payments' ),
),
'ppcp_onboarding_sandbox_express' => array(
@ -150,7 +151,7 @@ return function ( ContainerInterface $container, array $fields ): array {
'env' => Environment::SANDBOX,
'products' => array( 'EXPRESS_CHECKOUT' ),
'requirements' => array(),
'gateway' => 'connection',
'gateway' => Settings::CONNECTION_TAB_ID,
'description' => __( 'Prior to accepting live payments, you can test payments on your WooCommerce platform in a safe PayPal sandbox environment.', 'woocommerce-paypal-payments' ),
),
@ -168,7 +169,7 @@ return function ( ContainerInterface $container, array $fields ): array {
'state_from' => Environment::PRODUCTION,
'env' => Environment::PRODUCTION,
'requirements' => array(),
'gateway' => 'connection',
'gateway' => Settings::CONNECTION_TAB_ID,
'description' => __( 'Click to reset current credentials and use another account.', 'woocommerce-paypal-payments' ),
),
'ppcp_disconnect_sandbox' => array(
@ -185,7 +186,7 @@ return function ( ContainerInterface $container, array $fields ): array {
'state_from' => Environment::SANDBOX,
'env' => Environment::SANDBOX,
'requirements' => array(),
'gateway' => 'connection',
'gateway' => Settings::CONNECTION_TAB_ID,
'description' => __( 'Click to reset current credentials and use another account.', 'woocommerce-paypal-payments' ),
),
'toggle_manual_input' => array(
@ -197,7 +198,7 @@ return function ( ContainerInterface $container, array $fields ): array {
State::STATE_ONBOARDED,
),
'requirements' => array(),
'gateway' => 'connection',
'gateway' => Settings::CONNECTION_TAB_ID,
),
'error_label' => array(
'type' => 'ppcp-text',
@ -208,7 +209,7 @@ return function ( ContainerInterface $container, array $fields ): array {
State::STATE_ONBOARDED,
),
'requirements' => array(),
'gateway' => 'connection',
'gateway' => Settings::CONNECTION_TAB_ID,
),
'sandbox_on' => array(
'title' => __( 'Sandbox', 'woocommerce-paypal-payments' ),
@ -221,7 +222,7 @@ return function ( ContainerInterface $container, array $fields ): array {
State::STATE_ONBOARDED,
),
'requirements' => array(),
'gateway' => 'connection',
'gateway' => Settings::CONNECTION_TAB_ID,
),
'merchant_email_production' => array(
'title' => __( 'Live Email address', 'woocommerce-paypal-payments' ),
@ -236,7 +237,7 @@ return function ( ContainerInterface $container, array $fields ): array {
State::STATE_ONBOARDED,
),
'requirements' => array(),
'gateway' => 'connection',
'gateway' => Settings::CONNECTION_TAB_ID,
),
'merchant_id_production' => array(
'title' => __( 'Live Merchant Id', 'woocommerce-paypal-payments' ),
@ -250,7 +251,7 @@ return function ( ContainerInterface $container, array $fields ): array {
State::STATE_ONBOARDED,
),
'requirements' => array(),
'gateway' => 'connection',
'gateway' => Settings::CONNECTION_TAB_ID,
),
'client_id_production' => array(
'title' => __( 'Live Client Id', 'woocommerce-paypal-payments' ),
@ -264,7 +265,7 @@ return function ( ContainerInterface $container, array $fields ): array {
State::STATE_ONBOARDED,
),
'requirements' => array(),
'gateway' => 'connection',
'gateway' => Settings::CONNECTION_TAB_ID,
),
'client_secret_production' => array(
'title' => __( 'Live Secret Key', 'woocommerce-paypal-payments' ),
@ -278,7 +279,7 @@ return function ( ContainerInterface $container, array $fields ): array {
State::STATE_ONBOARDED,
),
'requirements' => array(),
'gateway' => 'connection',
'gateway' => Settings::CONNECTION_TAB_ID,
),
'merchant_email_sandbox' => array(
@ -294,7 +295,7 @@ return function ( ContainerInterface $container, array $fields ): array {
State::STATE_ONBOARDED,
),
'requirements' => array(),
'gateway' => 'connection',
'gateway' => Settings::CONNECTION_TAB_ID,
),
'merchant_id_sandbox' => array(
'title' => __( 'Sandbox Merchant Id', 'woocommerce-paypal-payments' ),
@ -308,7 +309,7 @@ return function ( ContainerInterface $container, array $fields ): array {
State::STATE_ONBOARDED,
),
'requirements' => array(),
'gateway' => 'connection',
'gateway' => Settings::CONNECTION_TAB_ID,
),
'client_id_sandbox' => array(
'title' => __( 'Sandbox Client Id', 'woocommerce-paypal-payments' ),
@ -322,7 +323,7 @@ return function ( ContainerInterface $container, array $fields ): array {
State::STATE_ONBOARDED,
),
'requirements' => array(),
'gateway' => 'connection',
'gateway' => Settings::CONNECTION_TAB_ID,
),
'client_secret_sandbox' => array(
'title' => __( 'Sandbox Secret Key', 'woocommerce-paypal-payments' ),
@ -336,7 +337,7 @@ return function ( ContainerInterface $container, array $fields ): array {
State::STATE_ONBOARDED,
),
'requirements' => array(),
'gateway' => 'connection',
'gateway' => Settings::CONNECTION_TAB_ID,
),
'credentials_feature_onboarding_heading' => array(
@ -346,7 +347,7 @@ return function ( ContainerInterface $container, array $fields ): array {
State::STATE_ONBOARDED,
),
'requirements' => array(),
'gateway' => 'connection',
'gateway' => Settings::CONNECTION_TAB_ID,
'description' => __( 'See which features are available.', 'woocommerce-paypal-payments' ),
),
'ppcp_dcc_status' => array(
@ -356,8 +357,8 @@ return function ( ContainerInterface $container, array $fields ): array {
'screens' => array(
State::STATE_ONBOARDED,
),
'requirements' => array(),
'gateway' => 'connection',
'requirements' => array( 'dcc' ),
'gateway' => Settings::CONNECTION_TAB_ID,
),
'ppcp_pui_status' => array(
'title' => __( 'Pay Upon Invoice', 'woocommerce-paypal-payments' ),
@ -367,7 +368,7 @@ return function ( ContainerInterface $container, array $fields ): array {
State::STATE_ONBOARDED,
),
'requirements' => array( 'pui_ready' ),
'gateway' => 'connection',
'gateway' => Settings::CONNECTION_TAB_ID,
),
'tracking_enabled' => array(
'title' => __( 'Tracking', 'woocommerce-paypal-payments' ),
@ -380,7 +381,7 @@ return function ( ContainerInterface $container, array $fields ): array {
State::STATE_ONBOARDED,
),
'requirements' => array(),
'gateway' => 'connection',
'gateway' => Settings::CONNECTION_TAB_ID,
'input_class' => $container->get( 'wcgateway.settings.should-disable-tracking-checkbox' ) ? array( 'ppcp-disabled-checkbox' ) : array(),
),
@ -391,7 +392,7 @@ return function ( ContainerInterface $container, array $fields ): array {
State::STATE_ONBOARDED,
),
'requirements' => array(),
'gateway' => 'connection',
'gateway' => Settings::CONNECTION_TAB_ID,
'description' => __( 'See which features are available.', 'woocommerce-paypal-payments' ),
),
'prefix' => array(
@ -415,7 +416,7 @@ return function ( ContainerInterface $container, array $fields ): array {
State::STATE_ONBOARDED,
),
'requirements' => array(),
'gateway' => 'connection',
'gateway' => Settings::CONNECTION_TAB_ID,
),
'logging_enabled' => array(
'title' => __( 'Logging', 'woocommerce-paypal-payments' ),
@ -430,7 +431,7 @@ return function ( ContainerInterface $container, array $fields ): array {
State::STATE_ONBOARDED,
),
'requirements' => array(),
'gateway' => 'connection',
'gateway' => Settings::CONNECTION_TAB_ID,
),
);

View file

@ -2146,13 +2146,13 @@ return array(
return 'https://www.paypal.com/bizsignup/entry?country.x=DE&product=payment_methods&capabilities=PAY_UPON_INVOICE';
},
'wcgateway.settings.connection.dcc-status-text' => static function ( ContainerInterface $container ): string {
$dcc_applies = $container->get( 'api.helpers.dccapplies' );
assert( $dcc_applies instanceof DccApplies );
$dcc_product_status = $container->get( 'wcgateway.helper.dcc-product-status' );
assert( $dcc_product_status instanceof DCCProductStatus );
$environment = $container->get( 'onboarding.environment' );
assert( $environment instanceof Environment );
$dcc_enabled = $dcc_applies->for_country_currency() || $dcc_applies->for_wc_payments();
$dcc_enabled = $dcc_product_status->dcc_is_active();
$enabled_status_text = esc_html__( 'Status: Enabled', 'woocommerce-paypal-payments' );
$disabled_status_text = esc_html__( 'Status: Not yet enabled', 'woocommerce-paypal-payments' );
@ -2185,9 +2185,7 @@ return array(
$environment = $container->get( 'onboarding.environment' );
assert( $environment instanceof Environment );
$shop_country = $container->get( 'api.shop.country' );
$pui_enabled = 'DE' === $shop_country && $pui_product_status->pui_is_active();
$pui_enabled = $pui_product_status->pui_is_active();
$enabled_status_text = esc_html__( 'Status: Enabled', 'woocommerce-paypal-payments' );
$disabled_status_text = esc_html__( 'Status: Not yet enabled', 'woocommerce-paypal-payments' );

View file

@ -62,6 +62,7 @@ class DCCProductStatus {
if ( is_bool( $this->current_status_cache ) ) {
return $this->current_status_cache;
}
if ( $this->settings->has( 'products_dcc_enabled' ) && $this->settings->get( 'products_dcc_enabled' ) ) {
$this->current_status_cache = true;
return true;

View file

@ -33,7 +33,7 @@ trait PageMatcherTrait {
}
$gateway_page_id_map = array(
Settings::CONNECTION_TAB_ID => 'connection',
Settings::CONNECTION_TAB_ID => Settings::CONNECTION_TAB_ID,
PayPalGateway::ID => 'paypal',
CreditCardGateway::ID => 'dcc', // TODO: consider using just the gateway ID for PayPal and DCC too.
CardButtonGateway::ID => CardButtonGateway::ID,

View file

@ -174,7 +174,7 @@ class SettingsListener {
/**
* The URL opened at the end of onboarding after saving the merchant ID/email.
*/
$redirect_url = apply_filters( 'woocommerce_paypal_payments_onboarding_redirect_url', admin_url( 'admin.php?page=wc-settings&tab=checkout&section=ppcp-gateway' ) );
$redirect_url = apply_filters( 'woocommerce_paypal_payments_onboarding_redirect_url', admin_url( 'admin.php?page=wc-settings&tab=checkout&section=ppcp-gateway&ppcp-tab=ppcp-connection' ) );
if ( ! $this->settings->has( 'client_id' ) || ! $this->settings->get( 'client_id' ) ) {
$redirect_url = add_query_arg( 'ppcp-onboarding-error', '1', $redirect_url );
}
@ -259,7 +259,7 @@ class SettingsListener {
$credentials_change_status = null; // Cannot detect on Card Processing page.
if ( PayPalGateway::ID === $this->page_id ) {
if ( PayPalGateway::ID === $this->page_id || Settings::CONNECTION_TAB_ID === $this->page_id ) {
$settings['enabled'] = isset( $_POST['woocommerce_ppcp-gateway_enabled'] )
&& 1 === absint( $_POST['woocommerce_ppcp-gateway_enabled'] );
@ -267,7 +267,6 @@ class SettingsListener {
}
// phpcs:enable phpcs:disable WordPress.Security.NonceVerification.Missing
// phpcs:enable phpcs:disable WordPress.Security.NonceVerification.Missing
if ( $credentials_change_status ) {
if ( self::CREDENTIALS_UNCHANGED !== $credentials_change_status ) {
$this->settings->set( 'products_dcc_enabled', null );

View file

@ -390,12 +390,6 @@ $data_rows_html
) {
continue;
}
if (
in_array( 'dcc', $config['requirements'], true )
&& ! $this->dcc_product_status->dcc_is_active()
) {
continue;
}
if (
in_array( 'messages', $config['requirements'], true )
&& ! $this->messages_apply->for_country()