Skip to content

[ubp] add chargebee cost center on cancellation #15067

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

Closed
wants to merge 1 commit into from

Conversation

svenefftinge
Copy link
Member

@svenefftinge svenefftinge commented Nov 30, 2022

Description

Create a chargebee cost center when the plan gets cancelled. This is so that our usage component treats any accumulated usage as covered and resets to a fresh UBP free plan at the endDate.

Related Issue(s)

Fixes #15055

How to test

Release Notes

NONE

Documentation

Werft options:

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

@svenefftinge svenefftinge requested a review from a team November 30, 2022 12:30
@github-actions github-actions bot added the team: webapp Issue belongs to the WebApp team label Nov 30, 2022
@@ -4,30 +4,30 @@
* See License.enterprise.txt in the project root folder.
*/

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry for all the formatter changes. seems like this component didn't get the big formatting update last time.

Copy link
Contributor

@jankeromnes jankeromnes left a comment

Choose a reason for hiding this comment

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

Thanks! Code changes look good to me.

Now I'll try to test this and make sure I can't find any bugs. 🔍


readonly maxTeamSlotsOnCreation: number = !!process.env.TS_MAX_SLOTS_ON_CREATION ? parseInt(process.env.TS_MAX_SLOTS_ON_CREATION) : 1000;
readonly maxTeamSlotsOnCreation: number = !!process.env.TS_MAX_SLOTS_ON_CREATION
? parseInt(process.env.TS_MAX_SLOTS_ON_CREATION)
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: pre-existing unsafe parseInt without a radix (can accidentally parse as octal or hex in some edge cases)

Suggested change
? parseInt(process.env.TS_MAX_SLOTS_ON_CREATION)
? parseInt(process.env.TS_MAX_SLOTS_ON_CREATION, 10)

@jankeromnes
Copy link
Contributor

@svenefftinge Follow-up question: What did you have in mind regarding how this PR can be tested? (I see no "How to test" instructions and no PR preview, but I'm happy to help you set up a Chargebee webhook so that we can exercise the new code path once)

@werft-gitpod-dev-com
Copy link

started the job as gitpod-build-se-on-cancellation.2 because the annotations in the pull request description changed
(with .werft/ from main)

@jankeromnes
Copy link
Contributor

jankeromnes commented Nov 30, 2022

/werft run cert-issuer=letsencrypt recreate-preview

👍 started the job as gitpod-build-se-on-cancellation.3
(with .werft/ from main)

@jankeromnes
Copy link
Contributor

jankeromnes commented Nov 30, 2022

Okay, we now have a preview environment with:

  • payment
  • a chargebee webhook
    🎉

I was able to use it to test this PR. Here is what I did:

  1. Create a Team
  2. Upgrade this team to "Unleashed EUR"
  3. Invite a second team member

At this point, the d_b_cost_center looked like this:

mysql> select * from d_b_cost_center;
+-------------------------------------------+---------------+---------+----------------------------+--------------------------+-----------------+--------------------------+--------------------------+
| id                                        | spendingLimit | deleted | _lastModified              | creationTime             | billingStrategy | nextBillingTime          | billingCycleStart        |
+-------------------------------------------+---------------+---------+----------------------------+--------------------------+-----------------+--------------------------+--------------------------+
| team:deb8b396-0739-43f6-9c5e-7346e4adf8d3 |             0 |       0 | 2022-11-30 15:28:13.120132 | 2022-11-30T15:28:13.113Z | other           | 2022-12-30T15:28:13.113Z | 2022-11-30T15:28:13.113Z |
| user:189ad1d0-d345-4fe4-981d-a765be8713c3 |           500 |       0 | 2022-11-30 15:30:47.099930 | 2022-11-30T15:30:47.095Z | other           | 2022-12-30T15:30:47.095Z | 2022-11-30T15:30:47.095Z |
| user:6ed86c44-781b-40d9-89d4-5baca8edc74a |           500 |       0 | 2022-11-30 15:21:28.154066 | 2022-11-30T15:21:28.150Z | other           | 2022-12-30T15:21:28.150Z | 2022-11-30T15:21:28.150Z |
+-------------------------------------------+---------------+---------+----------------------------+--------------------------+-----------------+--------------------------+--------------------------+
  1. Enable usage-based flag for this team in ConfigCat (waited for the flag to become active, but nothing changed in Gitpod's Team UI, as expected)
  2. Cancelled the Chargebee team plan
  3. ... refreshed the Team Billing page until the cancellation came through

Eventually, the Chargebee cancellation came through, and I landed on the empty "Upgrade to pay-as-you-go" team billing page, as expected. 👍

However, nothing changed in d_b_cost_center 🤔 is this a bug? 🐛

mysql> select * from d_b_cost_center;
+-------------------------------------------+---------------+---------+----------------------------+--------------------------+-----------------+--------------------------+--------------------------+
| id                                        | spendingLimit | deleted | _lastModified              | creationTime             | billingStrategy | nextBillingTime          | billingCycleStart        |
+-------------------------------------------+---------------+---------+----------------------------+--------------------------+-----------------+--------------------------+--------------------------+
| team:deb8b396-0739-43f6-9c5e-7346e4adf8d3 |             0 |       0 | 2022-11-30 15:28:13.120132 | 2022-11-30T15:28:13.113Z | other           | 2022-12-30T15:28:13.113Z | 2022-11-30T15:28:13.113Z |
| user:189ad1d0-d345-4fe4-981d-a765be8713c3 |           500 |       0 | 2022-11-30 15:30:47.099930 | 2022-11-30T15:30:47.095Z | other           | 2022-12-30T15:30:47.095Z | 2022-11-30T15:30:47.095Z |
| user:6ed86c44-781b-40d9-89d4-5baca8edc74a |           500 |       0 | 2022-11-30 15:21:28.154066 | 2022-11-30T15:21:28.150Z | other           | 2022-12-30T15:21:28.150Z | 2022-11-30T15:21:28.150Z |
+-------------------------------------------+---------------+---------+----------------------------+--------------------------+-----------------+--------------------------+--------------------------+

@jankeromnes
Copy link
Contributor

Another test, this time with an individual Chargebee plan:

  1. Log in as a new user
  2. Upgrade to Professional EUR (individual plan)
  3. Create a team called "Gitpod [Something]" (in order to enable usage-based flag for user)
  4. In /plans, manage billing, then cancel the Professional EUR plan
  5. Refresh page until the cancellation is effective
  6. ... there was still no change in d_b_cost_center:
+-------------------------------------------+---------------+---------+----------------------------+--------------------------+-----------------+--------------------------+--------------------------+
| id                                        | spendingLimit | deleted | _lastModified              | creationTime             | billingStrategy | nextBillingTime          | billingCycleStart        |
+-------------------------------------------+---------------+---------+----------------------------+--------------------------+-----------------+--------------------------+--------------------------+
| user:0d25e4cf-d6cf-42e5-97c0-60e0e3444020 |           500 |       0 | 2022-11-30 15:59:44.365184 | 2022-11-30T15:59:44.359Z | other           | 2022-12-30T15:59:44.359Z | 2022-11-30T15:59:44.359Z |
+-------------------------------------------+---------------+---------+----------------------------+--------------------------+-----------------+--------------------------+--------------------------+

@svenefftinge svenefftinge requested a review from a team December 2, 2022 11:43
@svenefftinge
Copy link
Member Author

We decided to handle this maually in the admin dashboard #15055

@svenefftinge svenefftinge deleted the se/on-cancellation branch December 2, 2022 14:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[UBP] Handle Chargebee cancellations
3 participants