🔀 Merge branch 'trunk'

This commit is contained in:
Philipp Stracker 2025-02-18 15:08:27 +01:00
commit cdcc523956
No known key found for this signature in database
54 changed files with 523 additions and 401 deletions

View file

@ -1,7 +1,13 @@
import { ToggleControl } from '@wordpress/components';
import { Action, Description } from '../Elements';
const ControlToggleButton = ( { label, description, value, onChange } ) => (
const ControlToggleButton = ( {
label,
description,
value,
onChange,
disabled = false,
} ) => (
<Action>
<ToggleControl
className="ppcp--control-toggle"
@ -12,6 +18,7 @@ const ControlToggleButton = ( { label, description, value, onChange } ) => (
help={
description ? <Description>{ description }</Description> : null
}
disabled={ disabled }
/>
</Action>
);

View file

@ -1,4 +1,5 @@
import { __ } from '@wordpress/i18n';
import { useEffect } from 'react';
import { ControlToggleButton } from '../../../../../ReusableComponents/Controls';
import SettingsBlock from '../../../../../ReusableComponents/SettingsBlock';
@ -12,6 +13,12 @@ const OrderIntent = () => {
setCaptureVirtualOnlyOrders,
} = SettingsHooks.useSettings();
useEffect( () => {
if ( ! authorizeOnly && captureVirtualOnlyOrders ) {
setCaptureVirtualOnlyOrders( false );
}
}, [ authorizeOnly ] );
return (
<SettingsBlock
title={ __( 'Order Intent', 'woocommerce-paypal-payments' ) }
@ -34,6 +41,7 @@ const OrderIntent = () => {
) }
onChange={ setCaptureVirtualOnlyOrders }
value={ captureVirtualOnlyOrders }
disabled={ ! authorizeOnly }
/>
</SettingsBlock>
);

View file

@ -20,13 +20,11 @@ use WooCommerce\PayPalCommerce\Settings\Data\TodosModel;
use WooCommerce\PayPalCommerce\Settings\Data\Definition\TodosDefinition;
use WooCommerce\PayPalCommerce\Settings\Endpoint\AuthenticationRestEndpoint;
use WooCommerce\PayPalCommerce\Settings\Endpoint\CommonRestEndpoint;
use WooCommerce\PayPalCommerce\Settings\Endpoint\CompleteOnClickEndpoint;
use WooCommerce\PayPalCommerce\Settings\Endpoint\LoginLinkRestEndpoint;
use WooCommerce\PayPalCommerce\Settings\Endpoint\OnboardingRestEndpoint;
use WooCommerce\PayPalCommerce\Settings\Endpoint\PayLaterMessagingEndpoint;
use WooCommerce\PayPalCommerce\Settings\Endpoint\PaymentRestEndpoint;
use WooCommerce\PayPalCommerce\Settings\Endpoint\RefreshFeatureStatusEndpoint;
use WooCommerce\PayPalCommerce\Settings\Endpoint\ResetDismissedTodosEndpoint;
use WooCommerce\PayPalCommerce\Settings\Endpoint\WebhookSettingsEndpoint;
use WooCommerce\PayPalCommerce\Settings\Endpoint\SettingsRestEndpoint;
use WooCommerce\PayPalCommerce\Settings\Endpoint\StylingRestEndpoint;
@ -43,6 +41,8 @@ use WooCommerce\PayPalCommerce\Settings\Data\Definition\PaymentMethodsDefinition
use WooCommerce\PayPalCommerce\PayLaterConfigurator\Factory\ConfigFactory;
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
use WooCommerce\PayPalCommerce\PayLaterConfigurator\Endpoint\SaveConfig;
use WooCommerce\PayPalCommerce\WcGateway\Helper\Environment;
use WooCommerce\PayPalCommerce\WcGateway\Helper\ConnectionState;
return array(
'settings.url' => static function ( ContainerInterface $container ) : string {
@ -116,13 +116,51 @@ return array(
);
},
/**
* Checks if valid merchant connection details are stored in the DB.
* Merchant connection details, which includes the connection status
* (onboarding/connected) and connection-aware environment checks.
* This is the preferred solution to check environment and connection state.
*/
'settings.flag.is-connected' => static function ( ContainerInterface $container ) : bool {
'settings.connection-state' => static function ( ContainerInterface $container ) : ConnectionState {
$data = $container->get( 'settings.data.general' );
assert( $data instanceof GeneralSettings );
return $data->is_merchant_connected();
$is_connected = $data->is_merchant_connected();
$environment = new Environment( $data->is_sandbox_merchant() );
return new ConnectionState( $is_connected, $environment );
},
'settings.environment' => static function ( ContainerInterface $container ) : Environment {
// We should remove this service in favor of directly using `settings.connection-state`.
$state = $container->get( 'settings.connection-state' );
assert( $state instanceof ConnectionState );
return $state->get_environment();
},
/**
* Checks if valid merchant connection details are stored in the DB.
*/
'settings.flag.is-connected' => static function ( ContainerInterface $container ) : bool {
/*
* This service only resolves the connection status once per request.
* We should remove this service in favor of directly using `settings.connection-state`.
*/
$state = $container->get( 'settings.connection-state' );
assert( $state instanceof ConnectionState );
return $state->is_connected();
},
/**
* Checks if the merchant is connected to a sandbox environment.
*/
'settings.flag.is-sandbox' => static function ( ContainerInterface $container ) : bool {
/*
* This service only resolves the sandbox flag once per request.
* We should remove this service in favor of directly using `settings.connection-state`.
*/
$state = $container->get( 'settings.connection-state' );
assert( $state instanceof ConnectionState );
return $state->is_sandbox();
},
'settings.rest.onboarding' => static function ( ContainerInterface $container ) : OnboardingRestEndpoint {
return new OnboardingRestEndpoint( $container->get( 'settings.data.onboarding' ) );
@ -268,6 +306,7 @@ return array(
$container->get( 'api.env.paypal-host' ),
$container->get( 'api.env.endpoint.login-seller' ),
$container->get( 'api.repository.partner-referrals-data' ),
$container->get( 'settings.connection-state' ),
$container->get( 'woocommerce.logger.woocommerce' ),
);
},

View file

@ -24,6 +24,7 @@ use WooCommerce\WooCommerce\Logging\Logger\NullLogger;
use WooCommerce\PayPalCommerce\Settings\DTO\MerchantConnectionDTO;
use WooCommerce\PayPalCommerce\Webhooks\WebhookRegistrar;
use WooCommerce\PayPalCommerce\Settings\Enum\SellerTypeEnum;
use WooCommerce\PayPalCommerce\WcGateway\Helper\ConnectionState;
/**
* Class that manages the connection to PayPal.
@ -64,27 +65,37 @@ class AuthenticationManager {
*/
private PartnerReferralsData $referrals_data;
/**
* The connection state manager.
*
* @var ConnectionState
*/
private ConnectionState $connection_state;
/**
* Constructor.
*
* @param GeneralSettings $common_settings Data model that stores the connection details.
* @param EnvironmentConfig $connection_host API host for direct authentication.
* @param EnvironmentConfig $login_endpoint API handler to fetch merchant credentials.
* @param PartnerReferralsData $referrals_data Partner referrals data.
* @param ?LoggerInterface $logger Logging instance.
* @param GeneralSettings $common_settings Data model that stores the connection details.
* @param EnvironmentConfig $connection_host API host for direct authentication.
* @param EnvironmentConfig $login_endpoint API handler to fetch merchant credentials.
* @param PartnerReferralsData $referrals_data Partner referrals data.
* @param ConnectionState $connection_state Connection state manager.
* @param ?LoggerInterface $logger Logging instance.
*/
public function __construct(
GeneralSettings $common_settings,
EnvironmentConfig $connection_host,
EnvironmentConfig $login_endpoint,
PartnerReferralsData $referrals_data,
ConnectionState $connection_state,
?LoggerInterface $logger = null
) {
$this->common_settings = $common_settings;
$this->connection_host = $connection_host;
$this->login_endpoint = $login_endpoint;
$this->referrals_data = $referrals_data;
$this->logger = $logger ?: new NullLogger();
$this->common_settings = $common_settings;
$this->connection_host = $connection_host;
$this->login_endpoint = $login_endpoint;
$this->referrals_data = $referrals_data;
$this->connection_state = $connection_state;
$this->logger = $logger ?: new NullLogger();
}
/**
@ -112,6 +123,9 @@ class AuthenticationManager {
$this->common_settings->reset_merchant_data();
$this->common_settings->save();
// Update the connection status and clear the environment flags.
$this->connection_state->disconnect();
/**
* Broadcast, that the plugin disconnected from PayPal. This allows other
* modules to clean up merchant-related details, such as eligibility flags.
@ -420,6 +434,9 @@ class AuthenticationManager {
if ( $this->common_settings->is_merchant_connected() ) {
$this->logger->info( 'Merchant successfully connected to PayPal' );
// Update the connection status and set the environment flags.
$this->connection_state->connect( $connection->is_sandbox );
/**
* Request to flush caches before authenticating the merchant, to
* ensure the new merchant does not use stale data from previous