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

Jetpack Partner Coupon: prioritise coupon redirect #58552

Merged
merged 3 commits into from
Nov 26, 2021

Conversation

kallehauge
Copy link
Contributor

@kallehauge kallehauge commented Nov 26, 2021

Summary

The current implementation of catching a Jetpack partner coupon and redirecting users directly to checkout is having some issues. Specifically with sites that have a partner ID.

We would expect all from: jetpack-partner-coupon flows to be send over to the plans page after authorisation.
We specifically catch users on the plans page and redirect them because we expect to make special upsell offers on the plan page in the future, so we might as well make sure the flow works now - which will also allow us to do it async of Jetpack plugin releases.

An issue we currently face is that some redirect conditions take over the normal flow like; is it a partner hosted site? (the shouldRedirectJetpackStart redirect condition).
We should prioritise the coupon redirect over these conditions because the customer has specifically entered the partner coupon flow and is expected to "Go straight to checkout".

Aside: I would consider this a pretty low risk change since we require the "from" property to specifically be jetpack-partner-coupon, so I'm not too worried about actually messing with existing flows.

Changes proposed in this Pull Request

  • Prioritise "Jetpack Partner Coupon" condition in the Calypso redirect conditions after a user has authorized a Jetpack connection.

Testing instructions

Verify failing flow

  • Spin up a Jurassic Ninja site
    • Go to "Want more options?"
    • Select Include Jetpack Beta
    • Select add/partner-coupon-connection as the Jetpack branch
    • Go down to "Plugins" and select "Include Code Snippets"
  • Copy the Filters snippet found below to a Code Snippet (this will make the WordPress site recognise test coupons and the flow will not work without it).
  • Create a Site Connection with the Jetpack Licensing API or a free plan with Jetpack Start API.
    • We do this step so the site will be recognized as having special conditions due to partner provisioned plans.
  • Go to /wp-admin/admin.php?jetpack-partner-coupon=JPTST_JPTA_123AB.
  • Click the "Redeem " button.
  • Press the "Approve" / "Authorize" button in Calypso.
  • You should now be taken back to your WordPress site without seeing the checkout (this is the failure we want to fix).

Verify fixed flow
This assumes that you've just completed Verify failing flow and continues in the same flow.

  • Go through all the steps of Verify failing flow right up until you get redirected back to WP Admin.
  • Disconnect Jetpack.
  • Go to /wp-admin/admin.php?page=jetpack#/dashboard
  • You should now see the redeem component again.
  • Click the "Set up & redeem " button.
  • Spin up this branch.
  • Copy the URL and replace https://wordpress.com with http://calypso.localhost:3000 / the PR link.
  • Go to the development URL.
  • Press the "Approve" / "Authorize" button in Calypso.
  • You should now be taken directly to Jetpack Checkout (whereas you got redirect to WP Admin before in the live version).

Filters snippet

add_filter( 'jetpack_partner_coupon_supported_partners', function ( $partners ) {
	$partners['JPTST'] = 'Jetpack Test';

	return $partners;
} );

add_filter( 'jetpack_partner_coupon_supported_presets', function ( $presets ) {
	$presets['JPTA'] = 'jetpack_backup_daily';

	return $presets;
} );

Related to Automattic/jetpack#21813

The current implementation of the partner coupon URL is supposed to
just take over the entire flow and send directly to checkout.
This will happen by the partnerCouponRedirects controller logic if we just
redirect the customer without any special conditions.

The reason we have to do this is because e.g. "shouldRedirectJetpackStart" has
logic that will always go straight to the redirect URI after authorization which
means we never hit the "plans" page where our partner coupon logic takes over.
@kallehauge kallehauge requested a review from rcoll November 26, 2021 17:17
@matticbot matticbot added the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Nov 26, 2021
@github-actions
Copy link

github-actions bot commented Nov 26, 2021

@matticbot
Copy link
Contributor

matticbot commented Nov 26, 2021

Here is how your PR affects size of JS and CSS bundles shipped to the user's browser:

Sections (~76 bytes added 📈 [gzipped])

name             parsed_size           gzip_size
jetpack-connect       +337 B  (+0.0%)      +76 B  (+0.0%)

Sections contain code specific for a given set of routes. Is downloaded and parsed only when a particular route is navigated to.

Legend

What is parsed and gzip size?

Parsed Size: Uncompressed size of the JS and CSS files. This much code needs to be parsed and stored in memory.
Gzip Size: Compressed size of the JS and CSS files. This much data needs to be downloaded over network.

Generated by performance advisor bot at iscalypsofastyet.com.

@kallehauge
Copy link
Contributor Author

Just a note about the failing E2E Tests (mobile) (Web app) build: it's an unrelated test that failed 🙂

Copy link
Contributor

@rcanepa rcanepa left a comment

Choose a reason for hiding this comment

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

LGTM.

Code changes look reasonable and work as per instructions.

Aside: I would consider this a pretty low risk change since we require the "from" property to specifically be jetpack-partner-coupon, so I'm not too worried about actually messing with existing flows.

I agree with this statement so I think we can safely ship this.

Copy link
Contributor

@rcanepa rcanepa left a comment

Choose a reason for hiding this comment

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

After the last commit, I gave this PR a second review, and I can confirm that everything still works as expected. I appreciate the simplification introduced in the last commit.

@kallehauge kallehauge removed the request for review from rcoll November 26, 2021 20:35
@kallehauge kallehauge merged commit cd63961 into trunk Nov 26, 2021
@kallehauge kallehauge deleted the fix/prioritise-partner-coupon-redirct branch November 26, 2021 20:35
@github-actions github-actions bot removed the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Nov 26, 2021
nelsonec87 pushed a commit that referenced this pull request Dec 9, 2021
* Jetpack Partner Coupon: prioritise coupon redirect

The current implementation of the partner coupon URL is supposed to
just take over the entire flow and send directly to checkout.
This will happen by the partnerCouponRedirects controller logic if we just
redirect the customer without any special conditions.

The reason we have to do this is because e.g. "shouldRedirectJetpackStart" has
logic that will always go straight to the redirect URI after authorization which
means we never hit the "plans" page where our partner coupon logic takes over.

* Correct copy+paste comment error

* Support sites with unattached licenses by bypassing "getRedirectionTarget"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants