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

feat(coupons): check coupons apply entire plan interval #12512

Merged
merged 1 commit into from
Apr 20, 2022

Conversation

StaberindeZA
Copy link
Contributor

@StaberindeZA StaberindeZA commented Apr 15, 2022

Because

  • Currently monthly repeating coupons can be used even though they could
    be applied to only part of the plan interval. (eg. Coupon duration of
    3 months, applied to a 6 month plan.) This leads to possible confusion
    for the customer, and should not be allowed.

This pull request

  • Checks if the coupon duration will apply to the entire interval for
    a given plan
  • If the coupon duration does not apply to the entire interval, report an
    error to Sentry.

Issue that this pull request solves

Closes: #12015

Checklist

Put an x in the boxes that apply

  • My commit is GPG signed.
  • If applicable, I have modified or added tests which pass locally.
  • I have added necessary documentation (if appropriate).
  • I have verified that my changes render correctly in RTL (if appropriate).

@StaberindeZA StaberindeZA requested a review from a team as a code owner April 15, 2022 16:22
@StaberindeZA StaberindeZA requested a review from IvoJP April 15, 2022 16:22
@StaberindeZA StaberindeZA force-pushed the fxa-4647-coupon-block-nosense branch 2 times, most recently from a939611 to 99489a6 Compare April 15, 2022 17:24
@IvoJP
Copy link
Contributor

IvoJP commented Apr 19, 2022

Code looks good, test coverage looks good. I left one question and one comment about a variable name - neither of which require action necessarily. I'll leave it to you discretion. The question regards string comparisons but it might be outside the scope of this ticket, the second is about if the variable name might be confusing for us in the future - I am not sure it will be and debated leaving the comment.

I am going to approve the PR and leave it to you discretion if either of the comments need to be addressed. LGTM.

// If the coupon duration is repeating, check if the duration months will be
// applied for a whole plan interval. Currently we do not want to support
// coupons being applied for part of the plan interval.
if (couponDuration === 'repeating') {
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure if we do this anywhere else or if we enforce this, but should we be doing case insensitive string comparisons? Is the couponDuration property serialized by stripe or do we have anything that works with the stripe response and guarantees that its always all lower case?

@@ -970,7 +1020,16 @@ export class StripeHelper {
);
}

return validPromotionCodes.includes(code);
const valid = await this.validateCouponDurationForPlan(
Copy link
Contributor

Choose a reason for hiding this comment

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

this will likely seem like a pedantic (right adjective?) comment but i think it might go a long way in terms of readability/understandability in the future when we have to revisit any of this code. so this method (checkPromotionCodeForPlan) is called from both methods to retreive a promo code - the one that checks the valid promo code for plan which is used by previewInvoice and the method that returns the coupon info regardless of validity so that we can determine whether a coupon is expired or redeemed or whatever.

should we consider changing the name of this variable? up to you, the name of the promo codes is already validPromoCodes but im wondering if in the future we might wonder why a method that retrieves invalid coupon calls into this and has a variabe called valid which could be true even for a coupon that is invalid in the stripe sense of validity.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for your comments, and I agree a better name would make it more readable.

It also got me to thinking that this is actually the wrong place for this check to happen, since it actually validates the Coupon (coupon duration in this case), and doesn't actually have anything to do with the Promotion Code and shouldn't inhibit retrieving the Promotion Code for a plan.

I was thinking a better place could be the verifyPromotionAndCoupon method. What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

Good catch, I agree with the above, and took a look at the other commit for the alternative approach. I am not sure when any of these methods will be used in any other context but you're right about the appropriateness of where things are called and it should at least help us with debugging/call stacks later on.

Feel free to pull those changes into here and just ping me if I need to re-approve. I have already taken a look though, so if my approval stays after the change, feel free to merge when you're ready.

@StaberindeZA StaberindeZA changed the title feat(coupons): do not allow coupons no sense feat(coupons): check coupons apply entire plan interval Apr 19, 2022
Because:

* Currently monthly repeating coupons can be used even though they could
  be applied to only part of the plan interval. (eg. Coupon duration of
  3 months, applied to a 6 month plan.) This leads to possible confusion
  for the customer, and should not be allowed.

This commit:

* Checks if the coupon duration will apply to the entire interval for
  a given plan.

Closes #12015
@StaberindeZA StaberindeZA force-pushed the fxa-4647-coupon-block-nosense branch from 99489a6 to 70f47f3 Compare April 20, 2022 18:05
@StaberindeZA StaberindeZA merged commit 5334948 into main Apr 20, 2022
@StaberindeZA StaberindeZA deleted the fxa-4647-coupon-block-nosense branch April 20, 2022 22:44
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.

Coupons: Do not allow coupons that don't make sense to be applied.
2 participants