Skip to content

Commit 5af3c4a

Browse files
committed
[server] Implement cancelTeamSubscription
1 parent e4e0514 commit 5af3c4a

File tree

4 files changed

+24
-0
lines changed

4 files changed

+24
-0
lines changed

components/gitpod-protocol/src/gitpod-service.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ export interface GitpodServer extends JsonRpcServer<GitpodClient>, AdminServer,
266266
subscriptionCancelDowngrade(subscriptionId: string): Promise<void>;
267267

268268
getTeamSubscription(teamId: string): Promise<TeamSubscription2 | undefined>;
269+
cancelTeamSubscription(teamId: string): Promise<void>;
269270
tsCancel(teamSubscriptionId: string): Promise<void>;
270271
tsGet(): Promise<TeamSubscription[]>;
271272
tsGetSlots(): Promise<TeamSubscriptionSlotResolved[]>;

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1632,6 +1632,25 @@ export class GitpodServerEEImpl extends GitpodServerImpl {
16321632
return this.teamSubscription2DB.findForTeam(teamId, new Date().toISOString());
16331633
}
16341634

1635+
async cancelTeamSubscription(ctx: TraceContext, teamId: string): Promise<void> {
1636+
this.checkUser("cancelTeamSubscription", { teamId });
1637+
1638+
await this.guardTeamOperation(teamId, "update", "not_implemented");
1639+
const ts2 = await this.teamSubscription2DB.findForTeam(teamId, new Date().toISOString());
1640+
if (!ts2) {
1641+
throw new ResponseError(ErrorCodes.NOT_FOUND, "Cannot find Team Subscription!");
1642+
}
1643+
1644+
const chargebeeSubscriptionId = ts2.paymentReference;
1645+
await this.chargebeeService.cancelSubscription(
1646+
chargebeeSubscriptionId,
1647+
{},
1648+
{ teamId, chargebeeSubscriptionId },
1649+
);
1650+
1651+
// Cancellation of team memberships is handled here: https://github.com/gitpod-io/gitpod/blob/5c90cd56572f55749b39e5b7134ff6be6f247357/components/ee/payment-endpoint/src/chargebee/team-subscription-handler.ts#L136-L139
1652+
}
1653+
16351654
protected async onTeamMemberAdded(userId: string, teamId: string): Promise<void> {
16361655
const now = new Date();
16371656
const ts2 = await this.teamSubscription2DB.findForTeam(teamId, now.toISOString());

components/server/src/auth/rate-limiter.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ const defaultFunctions: FunctionsConfig = {
205205
tsAssignSlot: { group: "default", points: 1 },
206206
tsDeactivateSlot: { group: "default", points: 1 },
207207
getTeamSubscription: { group: "default", points: 1 },
208+
cancelTeamSubscription: { group: "default", points: 1 },
208209
tsGet: { group: "default", points: 1 },
209210
tsCancel: { group: "default", points: 1 },
210211
tsGetSlots: { group: "default", points: 1 },

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3417,6 +3417,9 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
34173417
async getTeamSubscription(ctx: TraceContext, teamId: string): Promise<TeamSubscription2 | undefined> {
34183418
throw new ResponseError(ErrorCodes.SAAS_FEATURE, `Not implemented in this version`);
34193419
}
3420+
async cancelTeamSubscription(ctx: TraceContext, teamId: string): Promise<void> {
3421+
throw new ResponseError(ErrorCodes.SAAS_FEATURE, `Not implemented in this version`);
3422+
}
34203423
protected async onTeamMemberAdded(userId: string, teamId: string): Promise<void> {
34213424
// Extension point for EE
34223425
}

0 commit comments

Comments
 (0)