Skip to content

Commit

Permalink
Polish logic of redirect when click Set Up WooPayments from WC Home (#…
Browse files Browse the repository at this point in the history
…7659)

Co-authored-by: Vlad Olaru <[email protected]>
  • Loading branch information
oaratovskyi and vladolaru authored Nov 8, 2023
1 parent 0ad6573 commit da7ba25
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: fix
Comment: Addition to 7625 - polish logic of redirect when click Set Up WooPayments from WC Home


24 changes: 5 additions & 19 deletions includes/class-wc-payments-account.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,21 +222,6 @@ public function is_account_rejected(): bool {
return strpos( $account['status'] ?? '', 'rejected' ) === 0;
}

/**
* Checks if the account has been completed.
* Returns false if the account is not connected.
*
* @return bool True if the account is connected and complete, false otherwise or on error.
*/
public function is_account_complete(): bool {
if ( ! $this->is_stripe_connected() ) {
return false;
}

$account = $this->get_cached_account_data();
return 'complete' === $account['status'];
}

/**
* Checks if the account has not completed onboarding due to users abandoning the process half way.
* Returns true if the onboarding is started but did not finish.
Expand Down Expand Up @@ -949,11 +934,12 @@ public function maybe_handle_onboarding() {
$from_wc_admin_task = 'WCADMIN_PAYMENT_TASK' === $wcpay_connect_param;
$from_wc_pay_connect_page = false !== strpos( wp_get_referer(), 'path=%2Fpayments%2Fconnect' );
if ( ( $from_wc_admin_task || $from_wc_pay_connect_page ) ) {
// Redirect complete accounts to payments overview page, otherwise to the onboarding flow.
if ( $this->is_account_complete() ) {
$this->redirect_to( static::get_overview_page_url() );
} else {
// Redirect non-onboarded account to the onboarding flow, otherwise to payments overview page.
if ( ! $this->is_stripe_connected() ) {
$this->redirect_to_onboarding_flow_page();
} else {
// Accounts with Stripe account connected will be redirected to the overview page.
$this->redirect_to( static::get_overview_page_url() );
}
}

Expand Down

0 comments on commit da7ba25

Please sign in to comment.