Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor redirects logic in payments #8590

Merged
merged 12 commits into from
Jun 27, 2024

Conversation

oaratovskyi
Copy link
Contributor

@oaratovskyi oaratovskyi commented Apr 7, 2024

Fixes #7654

Changes proposed in this Pull Request

Refactor logic of redirects in payments admin: centralize it in one place, remove duplications, cover with tests what uncovered.

Testing instructions

Pre-requisites

  • Checkout to dev/7654-refactor-redirects-logic-in-payments
  • Remove the local account if you have any, clear the cache

Main flow

  • Go to local settings page, find WooPayments gateway, click Manage/Finish setup (depending on Core version). You should get redirected to connect page. Check from=WCADMIN_PAYMENT_SETTINGS exists in the URL.
  • Go to the WC Core home page, click Get paid with WooPayments - you should be redirected to the connect page
  • Try manually accessing overview page, you should get redirected to the connect page, since you don't have account. The same should work with disputes page.
  • Perform steps 5-19 as described in Onboard using payments connect and check that everything worked according to the critical flow description
  • Try manually accessing payments/onboarding page, you should be redirected to the overview page, check from=WCPAY_ONBOARDING_FLOW exists in the URL.
  • Manage button on Settings page (All payment methods) should redirect to WooPayments settings
  • Go to the WC Core home page, click Get paid with WooPayments - you should be redirected to the overview page

Builder flow

  • Click reset account in account tools, go to payments/connect page
  • Perform steps 4-13 as described in Onboard as a builder + go live and check that everything worked according to the critical flow description

Redirect to capital offer

image

Redirect to server link

Redirect to continue Stripe KYC from KYC reminder

Bonus flow - this is also worth testing manually, but it's a bit trickier (since you'll need to recover the Jetpack connection with tube). We have unit tests covering this and I tested it manually, but sharing how to test it, too:

Shows error when no Jetpack connected

  • Remove the local account if you have any, clear the cache
  • Empty the Jetpack connection using Jetpack Debug Tools Broken Token utility
  • Try manually accessing payments/onboarding page. Since you don't have Jetpack connection, it should redirect you back to connect page with an error Please connect to WordPress.com to start using WooPayments..
  • After that you'll need to recover Jetpack connection, you can do that by upping the tube npm run tube:start and public site will allow you to pass the Jetpack step. After getting that, you can stop the tube with npm run tube:stop

  • Run npm run changelog to add a changelog file, choose patch to leave it empty if the change is not significant. You can add multiple changelog files in one PR by running this command a few times.
  • Covered with tests (or have a good reason not to test in description ☝️)
  • Tested on mobile (or does not apply)

Post merge

@botwoo
Copy link
Collaborator

botwoo commented Apr 7, 2024

Test the build

Option 1. Jetpack Beta

  • Install and activate Jetpack Beta.
  • Use this build by searching for PR number 8590 or branch name dev/7654-refactor-redirects-logic-in-payments in your-test.site/wp-admin/admin.php?page=jetpack-beta&plugin=woocommerce-payments

Option 2. Jurassic Ninja - available for logged-in A12s

🚀 Launch a JN site with this branch 🚀

ℹ️ Install this Tampermonkey script to get more options.


Build info:

  • Latest commit: a15fbd6
  • Build time: 2024-06-27 08:36:00 UTC

Note: the build is updated when a new commit is pushed to this PR.

Copy link
Contributor

github-actions bot commented Apr 7, 2024

Size Change: 0 B

Total Size: 1.25 MB

ℹ️ View Unchanged
Filename Size
release/woocommerce-payments/assets/css/admin.css 1.08 kB
release/woocommerce-payments/assets/css/admin.rtl.css 1.08 kB
release/woocommerce-payments/assets/css/success.css 172 B
release/woocommerce-payments/assets/css/success.rtl.css 172 B
release/woocommerce-payments/dist/blocks-checkout-rtl.css 2.07 kB
release/woocommerce-payments/dist/blocks-checkout.css 2.07 kB
release/woocommerce-payments/dist/blocks-checkout.js 51.9 kB
release/woocommerce-payments/dist/bnpl-announcement-rtl.css 530 B
release/woocommerce-payments/dist/bnpl-announcement.css 531 B
release/woocommerce-payments/dist/bnpl-announcement.js 20 kB
release/woocommerce-payments/dist/cart-block.js 15.3 kB
release/woocommerce-payments/dist/cart.js 4.57 kB
release/woocommerce-payments/dist/checkout-rtl.css 599 B
release/woocommerce-payments/dist/checkout.css 599 B
release/woocommerce-payments/dist/checkout.js 31.5 kB
release/woocommerce-payments/dist/express-checkout-rtl.css 155 B
release/woocommerce-payments/dist/express-checkout.css 155 B
release/woocommerce-payments/dist/express-checkout.js 5.14 kB
release/woocommerce-payments/dist/index-rtl.css 41.3 kB
release/woocommerce-payments/dist/index.css 41.3 kB
release/woocommerce-payments/dist/index.js 295 kB
release/woocommerce-payments/dist/multi-currency-analytics.js 1.05 kB
release/woocommerce-payments/dist/multi-currency-rtl.css 3.42 kB
release/woocommerce-payments/dist/multi-currency-switcher-block.js 59.5 kB
release/woocommerce-payments/dist/multi-currency.css 3.42 kB
release/woocommerce-payments/dist/multi-currency.js 54.7 kB
release/woocommerce-payments/dist/order-rtl.css 733 B
release/woocommerce-payments/dist/order.css 735 B
release/woocommerce-payments/dist/order.js 41.8 kB
release/woocommerce-payments/dist/payment-gateways-rtl.css 1.36 kB
release/woocommerce-payments/dist/payment-gateways.css 1.36 kB
release/woocommerce-payments/dist/payment-gateways.js 38.6 kB
release/woocommerce-payments/dist/payment-request-rtl.css 155 B
release/woocommerce-payments/dist/payment-request.css 155 B
release/woocommerce-payments/dist/payment-request.js 5.92 kB
release/woocommerce-payments/dist/plugins-page-rtl.css 388 B
release/woocommerce-payments/dist/plugins-page.css 388 B
release/woocommerce-payments/dist/plugins-page.js 19.3 kB
release/woocommerce-payments/dist/product-details-rtl.css 398 B
release/woocommerce-payments/dist/product-details.css 402 B
release/woocommerce-payments/dist/product-details.js 11.2 kB
release/woocommerce-payments/dist/settings-rtl.css 11.1 kB
release/woocommerce-payments/dist/settings.css 11 kB
release/woocommerce-payments/dist/settings.js 201 kB
release/woocommerce-payments/dist/subscription-edit-page.js 669 B
release/woocommerce-payments/dist/subscription-product-onboarding-modal-rtl.css 527 B
release/woocommerce-payments/dist/subscription-product-onboarding-modal.css 527 B
release/woocommerce-payments/dist/subscription-product-onboarding-modal.js 19.4 kB
release/woocommerce-payments/dist/subscription-product-onboarding-toast.js 693 B
release/woocommerce-payments/dist/subscriptions-empty-state-rtl.css 120 B
release/woocommerce-payments/dist/subscriptions-empty-state.css 120 B
release/woocommerce-payments/dist/subscriptions-empty-state.js 18.5 kB
release/woocommerce-payments/dist/tokenized-payment-request-rtl.css 155 B
release/woocommerce-payments/dist/tokenized-payment-request.css 155 B
release/woocommerce-payments/dist/tokenized-payment-request.js 6.69 kB
release/woocommerce-payments/dist/tos-rtl.css 235 B
release/woocommerce-payments/dist/tos.css 236 B
release/woocommerce-payments/dist/tos.js 21 kB
release/woocommerce-payments/dist/woopay-direct-checkout.js 4.94 kB
release/woocommerce-payments/dist/woopay-express-button-rtl.css 155 B
release/woocommerce-payments/dist/woopay-express-button.css 155 B
release/woocommerce-payments/dist/woopay-express-button.js 15.2 kB
release/woocommerce-payments/dist/woopay-rtl.css 4.25 kB
release/woocommerce-payments/dist/woopay.css 4.22 kB
release/woocommerce-payments/dist/woopay.js 69.4 kB
release/woocommerce-payments/includes/subscriptions/assets/css/plugin-page.css 622 B
release/woocommerce-payments/includes/subscriptions/assets/js/plugin-page.js 815 B
release/woocommerce-payments/vendor/automattic/jetpack-assets/build/i18n-loader.js 2.44 kB
release/woocommerce-payments/vendor/automattic/jetpack-assets/src/js/i18n-loader.js 1.01 kB
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/jetpack-sso-admin-create-user.css 196 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/jetpack-sso-admin-create-user.js 20 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/jetpack-sso-admin-create-user.rtl.css 196 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/jetpack-sso-login.css 627 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/jetpack-sso-login.js 20 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/jetpack-sso-login.rtl.css 628 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/jetpack-sso-users.js 390 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/tracks-ajax.js 522 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/tracks-callables.js 581 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/src/sso/jetpack-sso-admin-create-user.css 214 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/src/sso/jetpack-sso-admin-create-user.js 523 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/src/sso/jetpack-sso-login.css 722 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/src/sso/jetpack-sso-login.js 408 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/src/sso/jetpack-sso-users.js 517 B
release/woocommerce-payments/vendor/automattic/jetpack-identity-crisis/babel.config.js 160 B
release/woocommerce-payments/vendor/automattic/jetpack-identity-crisis/build/index.css 2.36 kB
release/woocommerce-payments/vendor/automattic/jetpack-identity-crisis/build/index.js 13.5 kB
release/woocommerce-payments/vendor/automattic/jetpack-identity-crisis/build/index.rtl.css 2.36 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/about.css 1.03 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/admin-empty-state.css 291 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/admin-order-statuses.css 403 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/admin.css 3.6 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/checkout.css 299 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/modal.css 742 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/view-subscription.css 572 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/wcs-upgrade.css 411 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/admin-pointers.js 544 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/admin.js 9.4 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/jstz.js 6.8 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/jstz.min.js 3.83 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/meta-boxes-coupon.js 544 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/meta-boxes-subscription.js 2.52 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/moment.js 22.1 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/moment.min.js 11.6 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/payment-method-restrictions.js 1.29 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/wcs-meta-boxes-order.js 502 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/frontend/payment-methods.js 355 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/frontend/single-product.js 429 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/frontend/view-subscription.js 1.38 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/frontend/wcs-cart.js 781 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/modal.js 1.1 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/wcs-upgrade.js 1.27 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/build/index.css 392 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/build/index.js 3.05 kB

compressed-size-action

@oaratovskyi oaratovskyi marked this pull request as ready for review June 20, 2024 16:26
@oaratovskyi oaratovskyi self-assigned this Jun 20, 2024
add_action( 'admin_init', [ $this, 'maybe_redirect_onboarding_flow_to_connect' ] );

add_action( 'admin_init', [ $this, 'maybe_redirect_after_plugin_activation' ], 11 ); // Run this after the WC setup wizard and onboarding redirection logic.
add_action( 'admin_init', [ $this, 'maybe_redirect_by_get_param' ], 12 ); // Run this after the redirect to onboarding logic.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reduced next actions that depend on GET param: maybe_redirect_to_wcpay_connect, maybe_redirect_to_capital_offer and maybe_redirect_to_server_link
to one action maybe_redirect_by_get_param

add_action( 'admin_init', [ $this, 'maybe_redirect_after_plugin_activation' ], 11 ); // Run this after the WC setup wizard and onboarding redirection logic.
add_action( 'admin_init', [ $this, 'maybe_redirect_by_get_param' ], 12 ); // Run this after the redirect to onboarding logic.
add_action( 'admin_init', [ $this, 'maybe_redirect_from_settings_page' ] );
add_action( 'admin_init', [ $this, 'maybe_redirect_from_onboarding_page' ] );
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reduced maybe_redirect_onboarding_flow_to_overview and maybe_redirect_onboarding_flow_to_connect to maybe_redirect_from_onboarding_page. we can add more logic about redirect from onboarding page to this action

add_action( 'admin_init', [ $this, 'maybe_redirect_onboarding_flow_to_overview' ] );
add_action( 'admin_init', [ $this, 'maybe_redirect_onboarding_flow_to_connect' ] );

add_action( 'admin_init', [ $this, 'maybe_redirect_after_plugin_activation' ], 11 ); // Run this after the WC setup wizard and onboarding redirection logic.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe_redirect_to_onboarding -> maybe_redirect_after_plugin_activation to make it more readable

}

$this->redirect_to_login();
// Clear account transient when generating Stripe dashboard's login link.
$this->clear_cache();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extracted this call from redirect_to_login function to remove dependency from WC_Payments_Account

*
* @param string $location The URL to redirect to.
*/
protected function redirect_to( $location ) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved to Redirect_Service

/**
* For the connected account, fetches the login url from the API and redirects to it
*/
private function redirect_to_login() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved to Redirect_Service

*
* @see self::add_payments_menu()
*/
public function maybe_redirect_overview_to_connect() {
Copy link
Contributor Author

@oaratovskyi oaratovskyi Jun 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this function is not needed because this redirect (from overview to connect) is handled in a different way in maybe_redirect_from_payments_admin_child_pages, confirmed by manual testing

/**
* @dataProvider data_maybe_redirect_overview_to_connect
*/
public function test_maybe_redirect_overview_to_connect( $expected_times_redirect_called, $is_wc_registered_page, $get_params ) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this test is removed since the function was removed

}

public function test_maybe_redirect_to_capital_offer_redirects_to_capital_offer() {
$request = $this->mock_wcpay_request( Get_Account_Capital_Link::class );
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved to WC_Payments_Redirect_Service_Test

$this->wcpay_account->maybe_redirect_to_server_link();
}

public function test_maybe_redirect_to_server_link_redirects_to_overview_on_error() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved to WC_Payments_Redirect_Service_Test

/**
* Data provider for test_maybe_redirect_onboarding_flow_to_overview
*/
public function data_maybe_redirect_onboarding_flow_to_overview() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unique test cases reduced into data_maybe_redirect_from_onboarding_page

@dmallory42 dmallory42 requested a review from a team June 24, 2024 13:55
Copy link
Contributor

@dmallory42 dmallory42 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this! The logic is very tricky and it looks a lot more organised now after these changes.

I noticed one small error while testing, but everything else worked as expected. Details as follows:

When testing the final scenario, I got to the personal details step of the Stripe KYC then clicked "Return to WooPayments" on the KYC. This took me to a Sorry, you are not allowed to access this page. error. I guess this is because it is redirecting back to the Payments Connect page, but I think that this should redirect to the payments overview page (and I think it did in the past but can't say I'm 100% sure!)

Everything else worked great! Let's make sure this is merged so that GlobalStep can have a couple of rounds of testing before the next release. 🙂

@oaratovskyi
Copy link
Contributor Author

oaratovskyi commented Jun 26, 2024

When testing the final scenario, I got to the personal details step of the Stripe KYC then clicked "Return to WooPayments" on the KYC. This took me to a Sorry, you are not allowed to access this page. error. I guess this is because it is redirecting back to the Payments Connect page, but I think that this should redirect to the payments overview page (and I think it did in the past but can't say I'm 100% sure!)

@dmallory42 I couldn't reproduce this one
Is the npm run listen running on server?

@dmallory42
Copy link
Contributor

Thanks for getting back to me! I was testing on a JN branch. As we spoke about on Slack, it looks like an issue which also happens in the current environment, so we agreed to create a follow-up issue to tackle it.

Copy link
Contributor

@dmallory42 dmallory42 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for working on this!

@oaratovskyi
Copy link
Contributor Author

@dmallory42 created the issue as agreed

@oaratovskyi
Copy link
Contributor Author

Addressed conflicts with develop after @vladolaru's changes
Tested one more time manually (all the instructions) - works well!

@oaratovskyi oaratovskyi added this pull request to the merge queue Jun 27, 2024
Merged via the queue into develop with commit c17029a Jun 27, 2024
23 checks passed
@oaratovskyi oaratovskyi deleted the dev/7654-refactor-redirects-logic-in-payments branch June 27, 2024 09:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve redirects logic in payments
3 participants