Redirect to connection tab after manual credentials input

This commit is contained in:
Alex P 2023-02-21 10:38:11 +02:00
parent ec04c02b3d
commit 3ca9b444fe
No known key found for this signature in database
GPG key ID: 54487A734A204D71

View file

@ -193,10 +193,7 @@ class SettingsListener {
*/
do_action( 'woocommerce_paypal_payments_onboarding_before_redirect' );
/**
* 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&ppcp-tab=' . Settings::CONNECTION_TAB_ID ) );
$redirect_url = $this->get_onboarding_redirect_url();
if ( ! $this->settings->has( 'client_id' ) || ! $this->settings->get( 'client_id' ) ) {
$redirect_url = add_query_arg( 'ppcp-onboarding-error', '1', $redirect_url );
}
@ -347,9 +344,17 @@ class SettingsListener {
$this->dcc_status_cache->delete( DCCProductStatus::DCC_STATUS_CACHE_KEY );
}
$redirect_url = false;
if ( self::CREDENTIALS_ADDED === $credentials_change_status ) {
$redirect_url = $this->get_onboarding_redirect_url();
}
if ( isset( $_GET['ppcp-onboarding-error'] ) ) {
$url = remove_query_arg( 'ppcp-onboarding-error' );
wp_safe_redirect( $url, 302 );
$redirect_url = remove_query_arg( 'ppcp-onboarding-error', $redirect_url );
}
if ( $redirect_url ) {
wp_safe_redirect( $redirect_url, 302 );
exit;
}
@ -357,6 +362,18 @@ class SettingsListener {
// phpcs:enable WordPress.Security.NonceVerification.Recommended
}
/**
* Returns the URL opened at the end of onboarding.
*
* @return string
*/
private function get_onboarding_redirect_url(): string {
/**
* The URL opened at the end of onboarding after saving the merchant ID/email.
*/
return apply_filters( 'woocommerce_paypal_payments_onboarding_redirect_url', admin_url( 'admin.php?page=wc-settings&tab=checkout&section=ppcp-gateway&ppcp-tab=' . Settings::CONNECTION_TAB_ID ) );
}
/**
* The actual used client credentials are stored in 'client_secret', 'client_id', 'merchant_id' and 'merchant_email'.
* This method populates those fields depending on the sandbox status.