-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
billing-mode.ts
34 lines (29 loc) · 1.26 KB
/
billing-mode.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/**
* Copyright (c) 2022 Gitpod GmbH. All rights reserved.
* Licensed under the GNU Affero General Public License (AGPL).
* See License.AGPL.txt in the project root for license information.
*/
import { inject, injectable } from "inversify";
import { Config } from "../config";
import { BillingMode } from "@gitpod/gitpod-protocol/lib/billing-mode";
import { CostCenter_BillingStrategy } from "@gitpod/usage-api/lib/usage/v1/usage.pb";
import { UsageService } from "../orgs/usage-service";
/**
* Decides on a per org (legcay: also per-user) basis which BillingMode to use: "none" or "usage-based"
*/
@injectable()
export class BillingModes {
constructor(
@inject(Config) private readonly config: Config,
@inject(UsageService) private readonly usageService: UsageService,
) {}
public async getBillingMode(userId: string, organizationId: string): Promise<BillingMode> {
if (!this.config.enablePayment) {
// Payment is not enabled. E.g. Dedicated
return { mode: "none" };
}
const { billingStrategy } = await this.usageService.getCostCenter(userId, organizationId);
const paid = billingStrategy === CostCenter_BillingStrategy.BILLING_STRATEGY_STRIPE;
return { mode: "usage-based", paid };
}
}