-
Notifications
You must be signed in to change notification settings - Fork 212
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
Conversation
a939611
to
99489a6
Compare
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') { |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
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
99489a6
to
70f47f3
Compare
Because
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
a given plan
error to Sentry.
Issue that this pull request solves
Closes: #12015
Checklist
Put an
x
in the boxes that apply