Skip to content

[Usage-based] Adjust Stripe usage limits to spec #13746

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

Merged
merged 5 commits into from
Oct 13, 2022
Merged

Conversation

jankeromnes
Copy link
Contributor

@jankeromnes jankeromnes commented Oct 11, 2022

Description

Adjust Stripe usage limits to spec

Related Issue(s)

Part of #13389
Depends on #13798

How to test

  1. Create a team called "Gitpod [Something]"
  2. Go to team billing
  3. There shouldn't be a visible usage limit
  4. Upgrade the team by adding a payment method
  5. The default usage limit should be 1000 * team_size (but you can set it to any value)
  6. Go to your individual billing settings
  7. The usage limit should be 500 (not editable)
  8. Upgrade by adding a payment method
  9. The usage limit should now be 1000, and you should be able to set any value >= 1000 (but not < )
  10. Cancel your individual user subscription
  11. The limit should be back to 500 (not editable)

Release Notes

NONE

Documentation

Werft options:

  • /werft with-local-preview
    If enabled this will build install/preview
  • /werft with-preview
  • /werft with-payment
  • /werft with-integration-tests=all
    Valid options are all, workspace, webapp, ide

@werft-gitpod-dev-com
Copy link

started the job as gitpod-build-jx-adjust-usage-limits.1 because the annotations in the pull request description changed
(with .werft/ from main)

@jankeromnes jankeromnes force-pushed the jx/adjust-usage-limits branch from 3695ea1 to 3a08597 Compare October 11, 2022 08:50
@roboquat roboquat added size/M and removed size/S labels Oct 11, 2022
@jankeromnes jankeromnes force-pushed the jx/adjust-usage-limits branch from 3a08597 to a73cbac Compare October 11, 2022 09:01
@jankeromnes
Copy link
Contributor Author

Issue: Immediately after upgrading, the limit shows up wrong. After a refresh it's okay. I guess we need to refresh that state somehow.

@roboquat roboquat added size/L and removed size/M labels Oct 11, 2022
@jankeromnes
Copy link
Contributor Author

jankeromnes commented Oct 11, 2022

Okay, this now works almost as expected. 🎉

Except for the final step:

  1. The limit should be back to 500 (not editable)

(When you cancel, the limit seems to remain unchanged? I think this should be fixed in the CostCenter as part of #13389)

@jankeromnes jankeromnes marked this pull request as ready for review October 11, 2022 15:32
@jankeromnes jankeromnes requested a review from a team October 11, 2022 15:32
@github-actions github-actions bot added the team: webapp Issue belongs to the WebApp team label Oct 11, 2022
Comment on lines 549 to 558
const [newLimit, setNewLimit] = useState<string | undefined>(
props.currentValue ? String(props.currentValue) : undefined,
typeof props.currentValue === "number" ? String(props.currentValue) : undefined,
);
Copy link
Member

Choose a reason for hiding this comment

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

Why is the limit a string?

Copy link
Contributor Author

@jankeromnes jankeromnes Oct 12, 2022

Choose a reason for hiding this comment

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

That's how the modal code was initially written 🤷 I left it unchanged, but I assume it's because <input> natively deal with strings (i.e. when you get the value of an input, it's always a string, even if it's of type="number").

My personal preference would be to have it a number, and always parse whatever value we get out of the input, but I generally tend not to change existing code based on my sole personal preference. Happy to refactor that bit if you also have a preference for a number state.

Copy link
Contributor

@jldec jldec left a comment

Choose a reason for hiding this comment

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

LGTM with the exception of step 11 (usage limit does not revert to 500 when you cancel)
I think that's ok for this PR - we have to decide if we will refund or give users the remaining credits.

Thank you @jankeromnes 🙏

/hold for final technical 👍

Comment on lines 97 to 105
let limit = 1000;
const attrId = AttributionId.parse(attributionId);
if (attrId?.kind === "team") {
const members = await getGitpodService().server.getTeamMembers(attrId.teamId);
limit = 1000 * members.length;
}
await getGitpodService().server.subscribeToStripe(attributionId, setupIntentId, limit);
Copy link
Member

Choose a reason for hiding this comment

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

Thinking about this, I think we can shift this to server also.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! But I moved this out of server and into dashboard at Sven's request, because maybe in the future we'll want to ask users to define or confirm their usage limit while they're upgrading. I think we can leave this as is for now.

Copy link
Member

Choose a reason for hiding this comment

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

IMO, we should move it. If we'd like to suggest a limit which the user then confirms, we can suggest it in the Intent flow (teamSize * X), and send along with the subscribeToStripe call for actual persistence. We make the UI unnecessarily complex with the extra logic and introduce more failure modes.

Would like to also understand the context of Sven's request, do you have a link? What held true then, may no longer be the case. In general, the less logic the client side has, the better and given we're not doing the suggestion now .. YAGNI

Copy link
Contributor Author

@jankeromnes jankeromnes Oct 13, 2022

Choose a reason for hiding this comment

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

Hmm, if the code works as is, I'd be keen to merge it as is, then figure out how to improve it in follow-up PRs. Happy to file a follow-up issue for this! 😇

Would like to also understand the context of Sven's request, do you have a link?

#13535 (comment)

YAGNI

Sorry, I can never remember what those acronyms mean, and I'm too lazy to look them up, so I just glaze over them and lose their meaning 😝 (also reminds me of https://acronyms-suck.com 😇)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Follow-up issue is here: #13835

@easyCZ
Copy link
Member

easyCZ commented Oct 12, 2022

The counterpart PR which adds validation is here #13798

@geropl
Copy link
Member

geropl commented Oct 13, 2022

Having a look here as well.

@geropl

This comment was marked as resolved.

Copy link
Member

@geropl geropl left a comment

Choose a reason for hiding this comment

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

Code LGTM, tested and:

/hold for this nit.

@easyCZ
Copy link
Member

easyCZ commented Oct 13, 2022

Before landing this, we'll want to do a rebase to avoid having to do a get after set, and we should also shift more of the logic into server - we want these calls to be "transactional" on the server side, not on the client side (when one fails, we don't want it to fail in the client without the subsequent requests being done and us not having visibility into it)

@jankeromnes
Copy link
Contributor Author

Many thanks for the reviews! Briefly taking this back to Draft in order to:

@jankeromnes jankeromnes marked this pull request as draft October 13, 2022 08:36
@jankeromnes jankeromnes force-pushed the jx/adjust-usage-limits branch from eaf0685 to 7e53b57 Compare October 13, 2022 08:40
@roboquat roboquat added size/XL and removed size/L labels Oct 13, 2022
@jankeromnes jankeromnes changed the base branch from main to mp/usage-cost-center-validations October 13, 2022 08:41
@roboquat roboquat added size/L and removed size/XL labels Oct 13, 2022
@jankeromnes jankeromnes force-pushed the jx/adjust-usage-limits branch from 7e53b57 to f0b4217 Compare October 13, 2022 09:15
@roboquat roboquat added size/XXL and removed size/L labels Oct 13, 2022
@jankeromnes jankeromnes changed the base branch from mp/usage-cost-center-validations to main October 13, 2022 09:15
@roboquat roboquat added size/L and removed size/XXL labels Oct 13, 2022
@jankeromnes
Copy link
Contributor Author

jankeromnes commented Oct 13, 2022

Usage Limit input type

@geropl Fixed (it's now an <input type="text">)

Error message on personal upgrade

@geropl Known issue: #13177

Before landing this, we'll want to do a rebase to avoid having to do a get after set

@easyCZ Rebased and now using the new limit returned by subscribeToStripe

I've also uncoupled the Pull Requests again due to https://github.com/gitpod-io/gitpod/pull/13798/files -- happy to pair on that one if you'd like. Maybe it's a missing webhook? I see that the user cost center never goes back to other after cancel 👀

@jankeromnes
Copy link
Contributor Author

Okay, majority of nits addressed, and this works 90% in preview environments (with a chance to work 100% in staging/production if webhooks work there -- in any case this problem pre-dates & is unrelated to this PR).

Happy to make any further adjustments as follow-up issues. I'll file these today, but please let me know if you think I forgot anything.

/unhold

@jankeromnes jankeromnes marked this pull request as ready for review October 13, 2022 09:39
@roboquat roboquat merged commit 53c1a1f into main Oct 13, 2022
@roboquat roboquat deleted the jx/adjust-usage-limits branch October 13, 2022 09:45
Comment on lines +2116 to +2121
async subscribeToStripe(
ctx: TraceContext,
attributionId: string,
setupIntentId: string,
usageLimit: number,
): Promise<number | undefined> {
Copy link
Member

Choose a reason for hiding this comment

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

FWIW, this API is now super awkward in terms of the response. A consumer wouldn't expect to get a number as a response to subscribeToStripe. subscribe should return a Subscription, which can have a property of usageLimit.

@roboquat roboquat added deployed: webapp Meta team change is running in production deployed Change is completely running in production labels Oct 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deployed: webapp Meta team change is running in production deployed Change is completely running in production release-note-none size/L team: webapp Issue belongs to the WebApp team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants