Skip to content

Commit 1c72fca

Browse files
jankeromnesroboquat
authored andcommitted
[server] When a team enables usage-based billing, automatically re-attribute member usage to that team when the member has no explicit 'usageAttributionId' yet
1 parent b730785 commit 1c72fca

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

components/server/ee/src/workspace/gitpod-server-impl.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1960,6 +1960,20 @@ export class GitpodServerEEImpl extends GitpodServerImpl {
19601960
customer = await this.stripeService.createCustomerForTeam(user, team!, setupIntentId);
19611961
}
19621962
await this.stripeService.createSubscriptionForCustomer(customer.id, currency);
1963+
// For all team members that didn't explicitly choose yet where their usage should be attributed to,
1964+
// we simplify the UX by automatically attributing their usage to this recently-upgraded team.
1965+
// Note: This default choice can be changed at any time by members in their personal billing settings.
1966+
const members = await this.teamDB.findMembersByTeam(teamId);
1967+
await Promise.all(
1968+
members.map(async (m) => {
1969+
const u = await this.userDB.findUserById(m.userId);
1970+
if (u && !u.additionalData?.usageAttributionId) {
1971+
u.additionalData = u.additionalData || {};
1972+
u.additionalData.usageAttributionId = `team:${teamId}`;
1973+
await this.userDB.updateUserPartial(u);
1974+
}
1975+
}),
1976+
);
19631977
} catch (error) {
19641978
log.error(`Failed to subscribe team '${teamId}' to Stripe`, error);
19651979
throw new ResponseError(ErrorCodes.INTERNAL_SERVER_ERROR, `Failed to subscribe team '${teamId}' to Stripe`);

0 commit comments

Comments
 (0)