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

Ensure coupons are applied for all team subscriptions #1889

Merged
merged 10 commits into from
Mar 31, 2023
Merged

Conversation

knolleary
Copy link
Member

Fixes #1788

Description

The current coupon handling approach is broken. Accessing the sign-up page with ?code=BLAH doesn't guarantee that coupon gets applied when they eventually checkout on stripe.

This PR does the following:

  • Introduces UserBillingCode model - this is a simple table mapping UserID to a coupon code
  • When a user signs up having accessed the page with ?code=BLAH, we validate it is a valid code and then store the code in the UserBillingCode table. Note we store the code as-is - we do not store the stripe API id for the coupon.
  • Whenever that user creates a new Stripe checkout session we validate it is still an active/valid code and apply it. If the code is not valid, we don't try to apply it.
  • Stripped out the old cookie handling code that is no longer required. This includes some error handling when trying to apply invalid coupons - but given we now validate the coupon before trying to use it, we've removed the main failure case here.

As it stands, there is no ability to remove a user's coupon code. Given we validate it each time we try to use it, there is no issue of applying an invalid code and leaving them unable to checkout.

The most significant change in behaviour between this and previous coupon logic is that the coupon will be applied (if valid) every time the user sets up a billing session, not just the first time.

Checklist

  • I have read the contribution guidelines
  • Suitable unit/system level tests have been added and they pass
  • Documentation has been updated
    • Upgrade instructions
    • Configuration details
    • Concepts
  • Changes flowforge.yml?
    • Issue/PR raised on flowforge/helm to update ConfigMap Template
    • Issue/PR raised on flowforge/CloudProject to update values for Staging/Production

Labels

  • Backport needed? -> add the backport label
  • Includes a DB migration? -> add the area:migration label

@knolleary knolleary requested a review from Pezmc March 28, 2023 16:24
@knolleary
Copy link
Member Author

knolleary commented Mar 29, 2023

Just hit a failing scenario where a user tries to setup a new subscription for an existing team. You cannot reapply the coupon for the new subscription.

This happened because this particular coupon was marked as 'one time use only'. The problem is we don't have a sensible way to handle this combination. There are just too many combinations of how these things can be configured.

I'll check to see if we can detect this flag is set on the coupon and then automatically clear our record of it locally after then successfully setup stripe the first time.

@knolleary
Copy link
Member Author

I'll check to see if we can detect this flag is set on the coupon and then automatically clear our record of it locally after then successfully setup stripe the first time.

We know when setting up a team subscription if we're actually setting up the subscription for an existing team (ie preview sub has been cancelled). In that case, we can check the flag on the coupon to know if its restricted to first time only and then withhold the coupon from the request if needed. This allows the coupon to stay associated with the user so that it gets applied if they create a new team.

@knolleary knolleary merged commit 8c6bfc2 into main Mar 31, 2023
@knolleary knolleary deleted the fix-coupons branch March 31, 2023 08:40
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.

Sign-up coupons not guaranteed to be applied following team trial
2 participants