Skip to content

Commit 53c1a1f

Browse files
jankeromnesroboquat
authored andcommitted
[server] Make 'subscribeToStripe' return the new usage limit
1 parent ecf4d96 commit 53c1a1f

File tree

4 files changed

+10
-7
lines changed

4 files changed

+10
-7
lines changed

components/dashboard/src/components/UsageBasedBillingConfig.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,10 @@ export default function UsageBasedBillingConfig({ attributionId }: Props) {
102102
const members = await getGitpodService().server.getTeamMembers(attrId.teamId);
103103
limit = BASE_USAGE_LIMIT_FOR_STRIPE_USERS * members.length;
104104
}
105-
await getGitpodService().server.subscribeToStripe(attributionId, setupIntentId, limit);
106-
const newLimit = await getGitpodService().server.getUsageLimit(attributionId);
107-
setUsageLimit(newLimit);
105+
const newLimit = await getGitpodService().server.subscribeToStripe(attributionId, setupIntentId, limit);
106+
if (newLimit) {
107+
setUsageLimit(newLimit);
108+
}
108109
} catch (error) {
109110
console.error("Could not subscribe to Stripe", error);
110111
window.localStorage.removeItem(localStorageKey);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ export interface GitpodServer extends JsonRpcServer<GitpodClient>, AdminServer,
278278
getStripeSetupIntentClientSecret(): Promise<string>;
279279
findStripeSubscriptionId(attributionId: string): Promise<string | undefined>;
280280
createStripeCustomerIfNeeded(attributionId: string, currency: string): Promise<void>;
281-
subscribeToStripe(attributionId: string, setupIntentId: string, usageLimit: number): Promise<void>;
281+
subscribeToStripe(attributionId: string, setupIntentId: string, usageLimit: number): Promise<number | undefined>;
282282
getStripePortalUrl(attributionId: string): Promise<string>;
283283
getUsageLimit(attributionId: string): Promise<number | undefined>;
284284
setUsageLimit(attributionId: string, usageLimit: number): Promise<void>;

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2118,7 +2118,7 @@ export class GitpodServerEEImpl extends GitpodServerImpl {
21182118
attributionId: string,
21192119
setupIntentId: string,
21202120
usageLimit: number,
2121-
): Promise<void> {
2121+
): Promise<number | undefined> {
21222122
const attrId = AttributionId.parse(attributionId);
21232123
if (attrId === undefined) {
21242124
log.error(`Invalid attribution id: ${attributionId}`);
@@ -2143,7 +2143,7 @@ export class GitpodServerEEImpl extends GitpodServerImpl {
21432143
await this.stripeService.createSubscriptionForCustomer(customerId, attributionId);
21442144

21452145
// Creating a cost center for this customer
2146-
await this.usageService.setCostCenter({
2146+
const { costCenter } = await this.usageService.setCostCenter({
21472147
costCenter: {
21482148
attributionId: attributionId,
21492149
spendingLimit: usageLimit,
@@ -2152,6 +2152,8 @@ export class GitpodServerEEImpl extends GitpodServerImpl {
21522152
});
21532153

21542154
this.messageBus.notifyOnSubscriptionUpdate(ctx, attrId).catch();
2155+
2156+
return costCenter?.spendingLimit;
21552157
} catch (error) {
21562158
log.error(`Failed to subscribe '${attributionId}' to Stripe`, error);
21572159
throw new ResponseError(

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3106,7 +3106,7 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
31063106
attributionId: string,
31073107
setupIntentId: string,
31083108
usageLimit: number,
3109-
): Promise<void> {
3109+
): Promise<number | undefined> {
31103110
throw new ResponseError(ErrorCodes.SAAS_FEATURE, `Not implemented in this version`);
31113111
}
31123112
async getStripePortalUrl(ctx: TraceContext, attributionId: string): Promise<string> {

0 commit comments

Comments
 (0)