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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checkout: Change plan upsell calculation to take volume and discounts into account #90893

Merged

Conversation

sirbrillig
Copy link
Member

@sirbrillig sirbrillig commented May 20, 2024

Proposed Changes

When you have a domain in your cart and no plan (pre-owned or in the cart), checkout displays an upsell that suggests adding a plan. It includes text that reads either "save X" or "pay an extra X" to inform the user what the price difference would be for their cart with the plan. However, the calculation currently is not accurate if the domain item is for multiple years.

The calculation is inaccurate because of the following reasons:

  1. Currently we subtract the discounted price of the domain from the price of the plan to figure out the extra amount that must be paid to have the plan because the plan will give you the first year free. However, for a multi-year plan, this subtracts too much since only one year of the plan is free and the price of the domain includes all the years.
  2. We cannot use the undiscounted price of the domain for one year in the above calculation because the price of the plan minus the undiscounted price of the domain will be too small when you consider that the domain currently has a discount.
  3. We also cannot use the discounted price of the domain for one year in the above calculation because the discount (if it comes from a first year sale) won't exist when the plan is added to the cart since a 30% first-year discount on top of a 100% first-year discount is 0.
  4. If there is another kind of percentage discount which is applied to the total and not only the first year, like a coupon code, then that discount will be applied to the domain currently in the cart, any number of the years of the domain that will remain in the cart when the plan is added, and the plan itself. Therefore, the calculation must take this into account.

In this PR we refactor the calculation to cover each of the above cases to better predict the savings or extra cost that will occur when adding a plan to the cart.

It's possible for this calculation to still be incorrect for discount types not covered above (introductory offers, maybe?), but since sale coupons and coupon code are probably the most common discounts applied to domains and wpcom plans, this should cover most scenarios.

Fixes the bug reported here: #89472 (review). That PR was never merged because I accidentally made a very similar refactor around the same time (#89874) for a different purpose which ended up causing the same bug reported in the original PR. Huge apologies to @chriskmnds and @aneeshd16 for that oversight! 馃檱

Screenshots

Here is an example with a sale coupon on the domain. Note the referenced price difference in the "Upgrade and save" box on the right side. Prior to this change, it reads "Save $11.40" and after this change it reads "Pay an extra $32.60". The actual difference in the cart total will be an increase from $59.40 to $92.00, an increase of $32.60.

Before After
before-upsell-fix after-upsell-fix

For reference, here's what my cart looks like after I accept the upsell:

cart-with-plan-and-domain

Here is another example with a coupon code instead of a sale coupon (a cart cannot have both at the same time). Note that the "Pay an extra X" now includes the 50% savings from the coupon. Prior to this change it read "Pay an extra $42" and after this change it reads "Pay an extra $18". The actual difference in the cart total will be an increase from $6 to $24, a difference of $18.

Before After
incorrect-upsell-with-coupon correct-upsell-with-coupon

Here's what the cart looks like after the upsell:

cart-after-upsell-with-coupon

Testing Instructions

  1. Using a site that has no plan, add a domain registration to your cart and visit checkout.
  2. Record the current cart total.
  3. Notice the "Upgrade and save" upsell in the sidebar and record the price difference written there ("Save X" or "Pay an extra X").
  4. Click "Add to Cart" in the upsell.
  5. Compare the actual price difference between the old cart total and the new cart total with the price difference that was in the upsell. Make sure that the math is correct.
  6. Remove the plan from your cart to make the upsell appear again.
  7. Change the volume of the domain from "One year" to a longer billing term.
  8. Repeat steps 2 - 5 and verify that the math is still correct.

It's a good idea to test this for a domain with a sale coupon and a domain without a sale coupon. It's also a good idea to try adding a coupon code to make sure the prices are still accurate.

@matticbot
Copy link
Contributor

matticbot commented May 20, 2024

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

Sections (~94 bytes added 馃搱 [gzipped])

name      parsed_size           gzip_size
checkout       +202 B  (+0.0%)      +94 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.

Async-loaded Components (~94 bytes added 馃搱 [gzipped])

name                                             parsed_size           gzip_size
async-load-calypso-my-sites-checkout-modal            +202 B  (+0.0%)      +94 B  (+0.0%)
async-load-calypso-blocks-editor-checkout-modal       +202 B  (+0.0%)      +94 B  (+0.0%)

React components that are loaded lazily, when a certain part of UI is displayed for the first time.

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.

@sirbrillig sirbrillig self-assigned this May 20, 2024
@sirbrillig sirbrillig added the [Feature] Checkout The checkout screen and process for purchases made on WordPress.com. label May 20, 2024
@sirbrillig sirbrillig force-pushed the fix/first-year-plan-upsell-with-volume-and-discounts branch from 3d2bb87 to 1836036 Compare May 20, 2024 17:19
@sirbrillig sirbrillig marked this pull request as ready for review May 20, 2024 17:32
@sirbrillig sirbrillig requested a review from a team as a code owner May 20, 2024 17:32
@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 May 20, 2024
@sirbrillig sirbrillig requested review from a team and southp May 20, 2024 17:47
Copy link
Contributor

@aneeshd16 aneeshd16 left a comment

Choose a reason for hiding this comment

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

Testing with a domain and sale coupon:
image

The subtotal is $4.84 and the extra price to pay is shown as $26.

If I add the plan to cart:
image

The subtotal is now $48, which is a $43.16 increase. This does not match the $26 shown earlier in the upsell.

This issue only happens when the term selected for the domain is 1 year. On longer terms, the upsell shows the correct price.

@sirbrillig
Copy link
Member Author

Thanks for noticing that, @aneeshd16! It turns out that single year domain registration sale coupons were not correctly being recorded as first-year-only. I believe I've fixed that with D149403-code. Can you try again?

Copy link
Contributor

@aneeshd16 aneeshd16 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 fixing this! LGTM.

I don't have the complete context for terms like item_subtotal_integer and item_original_subtotal_integer, but logically the change makes sense to me.

@sirbrillig sirbrillig merged commit 599fe0a into trunk May 22, 2024
22 checks passed
@sirbrillig sirbrillig deleted the fix/first-year-plan-upsell-with-volume-and-discounts branch May 22, 2024 14:49
@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 May 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Checkout The checkout screen and process for purchases made on WordPress.com.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants