Automattic / woocommerce-subscriptions-core

Subscriptions core package for WooCommerce
Other
80 stars 29 forks source link

Make sure to fetch the order discount excluding tax if prices include tax #556

Closed james-allan closed 3 months ago

james-allan commented 5 months ago

Fixes https://github.com/woocommerce/woocommerce-subscriptions/issues/4227

Description

When you attempt to pay for a failed parent order where prices are inclusive of tax and there's a discount that applied, the total that appears on the checkout would be incorrect.

After some digging I discovered it's because we're pulling the order discount amount excluding tax so a $10 discount, for example, would be returned as $9.62. The customer would then only be discounted $9.62 not the full $10.

This PR fixes it.

How to test this PR

  1. Create a recurring discount of $10 in Marketing → Discounts.
  2. Create a $50 subscription product of any recurring frequency.
  3. In WooCommerce → General settings make sure tax calculations are enabled.
  4. In WooCommerce → Settings → Taxes make sure prices are inclusive of tax.
  5. Disable shipping or add a free shipping method.
  6. Add a 4% tax rate that applies.
  7. Add the product to your cart.
  8. Apply the coupon.
  9. Note that the total is $40 with $1.54 tax.
  10. Fail the payment using a Stripe test card like: 4000000000000002
  11. Go to the My Account > Orders page and attempt to pay for the order.
  12. On trunk you'll notice that a discount of $9.62.
  13. On this branch it should be correctly $10 with a total of $40.
trunk This branch
Screenshot 2024-01-11 at 5 56 31 pm Screenshot 2024-01-11 at 5 57 24 pm

[!NOTE] I've tested this with prices exclusive of tax and with % discounts and they also work with this change also works for those scenarios too.

Product impact