gitpod-io / gitpod

The developer platform for on-demand cloud development environments to create software faster and more securely.
https://www.gitpod.io
GNU Affero General Public License v3.0
12.78k stars 1.23k forks source link

Billing controller excludes WorkspaceInstances which are already included in previous invoices #10937

Closed easyCZ closed 2 years ago

easyCZ commented 2 years ago

The billing controller will need to be given the full set of WorkspaceInstances (which the UsageController fetched) to perform it's run. This is because in a given billing period (May 1 - May 31), a user can have potentially a large number of subscriptions (not in parallel) - create then cancel and repeat. For the cancelled subscriptions, they will of course need to settle it but we must not charge them for any usage from a cancelled subscription (but within that month). And the Billing Controller is the only component which should have access to Stripe to retrieve this data. In practice, the controller will need to exclude all WorkspaceInstances which match previously already billed WorkspaceInstances.

Architecture

System architecture:

regular-operation

Interactions with Stripe and the content-service:

invoice-created

Tasks

Done

Notes

easyCZ commented 2 years ago

Related (internal) conversation

easyCZ commented 2 years ago

Manually configured staging environment to send invoice.finalized webhooks

easyCZ commented 2 years ago

Stripe signing secret is now loaded into staging/production with https://github.com/gitpod-io/ops/pull/3974

easyCZ commented 2 years ago

A WIP for finalizing invoices. Currently, the finalization event doens't tell us which AttributionID it is for. It only gives us the Invoice ID.

We'll need to link the InvoiceID to the attribution ID used for the invoice. Likely, this will need to come from the subscription when it is made originally. This currently contains the teamId field which could be used.

easyCZ commented 2 years ago

We won't be going with this approach. Instead we'll approach it with https://github.com/gitpod-io/gitpod/issues/12741