Sync onboarding completion with connection state

This commit is contained in:
Philipp Stracker 2025-01-08 17:49:04 +01:00
parent b3e766d08a
commit a9c2a8e8fe
No known key found for this signature in database
2 changed files with 35 additions and 7 deletions

View file

@ -398,11 +398,15 @@ class AuthenticationManager {
$this->common_settings->set_merchant_data( $connection ); $this->common_settings->set_merchant_data( $connection );
$this->common_settings->save(); $this->common_settings->save();
/** if ( $this->common_settings->is_merchant_connected() ) {
* Broadcast that the plugin connected to a new PayPal merchant account. $this->logger->info( 'Merchant successfully connected to PayPal' );
* This is the right time to initialize merchant relative flags for the
* first time. /**
*/ * Broadcast that the plugin connected to a new PayPal merchant account.
do_action( 'woocommerce_paypal_payments_authenticated_merchant' ); * This is the right time to initialize merchant relative flags for the
* first time.
*/
do_action( 'woocommerce_paypal_payments_authenticated_merchant' );
}
} }
} }

View file

@ -9,8 +9,9 @@ declare( strict_types = 1 );
namespace WooCommerce\PayPalCommerce\Settings; namespace WooCommerce\PayPalCommerce\Settings;
use WooCommerce\PayPalCommerce\Settings\Endpoint\RestEndpoint;
use WooCommerce\PayPalCommerce\Settings\Ajax\SwitchSettingsUiEndpoint; use WooCommerce\PayPalCommerce\Settings\Ajax\SwitchSettingsUiEndpoint;
use WooCommerce\PayPalCommerce\Settings\Data\OnboardingProfile;
use WooCommerce\PayPalCommerce\Settings\Endpoint\RestEndpoint;
use WooCommerce\PayPalCommerce\Settings\Handler\ConnectionListener; use WooCommerce\PayPalCommerce\Settings\Handler\ConnectionListener;
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ExecutableModule; use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ExecutableModule;
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ModuleClassNameIdTrait; use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ModuleClassNameIdTrait;
@ -203,6 +204,29 @@ class SettingsModule implements ServiceModule, ExecutableModule {
} }
); );
add_action(
'woocommerce_paypal_payments_merchant_disconnected',
static function () use ( $container ) : void {
$onboarding_profile = $container->get( 'settings.data.onboarding' );
assert( $onboarding_profile instanceof OnboardingProfile );
$onboarding_profile->set_completed( false );
$onboarding_profile->set_step( 0 );
$onboarding_profile->save();
}
);
add_action(
'woocommerce_paypal_payments_authenticated_merchant',
static function () use ( $container ) : void {
$onboarding_profile = $container->get( 'settings.data.onboarding' );
assert( $onboarding_profile instanceof OnboardingProfile );
$onboarding_profile->set_completed( true );
$onboarding_profile->save();
}
);
return true; return true;
} }