mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-12 01:18:39 +08:00
Move webhook registration after checkout setting saved
This commit is contained in:
parent
4db3e828cd
commit
4b320f0f87
2 changed files with 33 additions and 11 deletions
|
@ -18,7 +18,6 @@ use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
|
|||
use WooCommerce\PayPalCommerce\WcGateway\Helper\DCCProductStatus;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Helper\PayUponInvoiceProductStatus;
|
||||
use WooCommerce\PayPalCommerce\Webhooks\WebhookRegistrar;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Exception\NotFoundException;
|
||||
|
||||
/**
|
||||
* Class SettingsListener
|
||||
|
@ -322,16 +321,6 @@ class SettingsListener {
|
|||
}
|
||||
$this->settings->persist();
|
||||
|
||||
if ( $credentials_change_status ) {
|
||||
if ( in_array(
|
||||
$credentials_change_status,
|
||||
array( self::CREDENTIALS_ADDED, self::CREDENTIALS_CHANGED ),
|
||||
true
|
||||
) ) {
|
||||
$this->webhook_registrar->register();
|
||||
}
|
||||
}
|
||||
|
||||
if ( $this->cache->has( PayPalBearer::CACHE_KEY ) ) {
|
||||
$this->cache->delete( PayPalBearer::CACHE_KEY );
|
||||
}
|
||||
|
@ -362,6 +351,38 @@ class SettingsListener {
|
|||
// phpcs:enable WordPress.Security.NonceVerification.Recommended
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs after checkout setting saved.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function after_checkout_settings_saved():void {
|
||||
if ( ! $this->is_valid_site_request() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// phpcs:disable WordPress.Security.NonceVerification.Missing
|
||||
// phpcs:disable WordPress.Security.NonceVerification.Recommended
|
||||
$raw_data = ( isset( $_POST['ppcp'] ) ) ? (array) wp_unslash( $_POST['ppcp'] ) : array();
|
||||
// phpcs:enable WordPress.Security.NonceVerification.Missing
|
||||
// phpcs:enable WordPress.Security.NonceVerification.Recommended
|
||||
|
||||
// phpcs:disable WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
|
||||
$settings = $this->retrieve_settings_from_raw_data( $raw_data );
|
||||
$credentials_change_status = null; // Cannot detect on Card Processing page.
|
||||
if ( Settings::CONNECTION_TAB_ID === $this->page_id ) {
|
||||
$credentials_change_status = $this->determine_credentials_change_status( $settings );
|
||||
}
|
||||
if ( in_array(
|
||||
$credentials_change_status,
|
||||
array( self::CREDENTIALS_REMOVED, self::CREDENTIALS_CHANGED ),
|
||||
true
|
||||
) ) {
|
||||
$this->webhook_registrar->unregister();
|
||||
$this->webhook_registrar->register();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the URL opened at the end of onboarding.
|
||||
*
|
||||
|
|
|
@ -461,6 +461,7 @@ class WCGatewayModule implements ModuleInterface {
|
|||
$listener->listen_for_merchant_id();
|
||||
$listener->listen_for_vaulting_enabled();
|
||||
$listener->listen_for_tracking_enabled();
|
||||
$listener->after_checkout_settings_saved();
|
||||
}
|
||||
);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue