Skip to content

Commit

Permalink
[server] remove use of isBillingModeEnabled
Browse files Browse the repository at this point in the history
  • Loading branch information
svenefftinge committed Sep 19, 2022
1 parent d745f7f commit af38e4d
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 34 deletions.
1 change: 0 additions & 1 deletion components/server/ee/src/billing/billing-mode.spec.db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,6 @@ class BillingModeSpec {
() =>
new ConfigCatClientMock({
isUsageBasedBillingEnabled: test.config.usageBasedPricingEnabled,
isBillingModeEnabled: true,
}),
);
}),
Expand Down
18 changes: 0 additions & 18 deletions components/server/ee/src/billing/billing-mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,26 +63,11 @@ export class BillingModesImpl implements BillingModes {
}
}

protected async isBillingModeEnabled(subject: { user?: User; team?: Team }): Promise<boolean> {
// This is a double safety-net to smoothen and de-risk the rollout of BillingMode, because it not only affects
// new behavior which is in focus and subject to test anyway (usage-based), but also old behavior (chargebee).
const teams = subject.user ? await this.teamDB.findTeamsByUser(subject.user.id) : undefined;
return await this.configCatClientFactory().getValueAsync("isBillingModeEnabled", false, {
user: subject.user,
teams,
teamId: subject.team?.id,
teamName: subject.team?.name,
});
}

async getBillingModeForUser(user: User, now: Date): Promise<BillingMode> {
if (!this.config.enablePayment) {
// Payment is not enabled. E.g. Self-Hosted.
return { mode: "none" };
}
if (!(await this.isBillingModeEnabled({ user }))) {
return { mode: "chargebee" };
}

// Is Usage Based Billing enabled for this user or not?
const teams = await this.teamDB.findTeamsByUser(user.id);
Expand Down Expand Up @@ -167,9 +152,6 @@ export class BillingModesImpl implements BillingModes {
// Payment is not enabled. E.g. Self-Hosted.
return { mode: "none" };
}
if (!(await this.isBillingModeEnabled({ team }))) {
return { mode: "chargebee" };
}
const now = _now.toISOString();

// Is Usage Based Billing enabled for this team?
Expand Down
15 changes: 0 additions & 15 deletions components/server/ee/src/workspace/gitpod-server-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2012,21 +2012,6 @@ export class GitpodServerEEImpl extends GitpodServerImpl {
return subscription;
}

protected async isUsageBasedFeatureFlagEnabled(user: User): Promise<boolean> {
const teams = await this.teamDB.findTeamsByUser(user.id);
return await getExperimentsClientForBackend().getValueAsync("isUsageBasedBillingEnabled", false, {
user,
teams: teams,
});
}

protected async ensureIsUsageBasedFeatureFlagEnabled(user: User): Promise<void> {
const isUsageBasedBillingEnabled = await this.isUsageBasedFeatureFlagEnabled(user);
if (!isUsageBasedBillingEnabled) {
throw new ResponseError(ErrorCodes.PERMISSION_DENIED, "not allowed");
}
}

protected async ensureChargebeeApiIsAllowed(sub: { user?: User; team?: Team }): Promise<void> {
await this.ensureBillingMode(sub, (m) => m.mode === "chargebee");
}
Expand Down

0 comments on commit af38e4d

Please sign in to comment.