Skip to content

Commit e247d6e

Browse files
committed
[server][dashboard] Minor Stripe API clean-up
1 parent dbd8d6b commit e247d6e

File tree

5 files changed

+26
-16
lines changed

5 files changed

+26
-16
lines changed

components/dashboard/src/teams/TeamUsageBasedBilling.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export default function TeamUsageBasedBilling() {
3636
setStripeCustomerId(undefined);
3737
setIsLoading(true);
3838
try {
39-
const customerId = await getGitpodService().server.getTeamStripeCustomerId(team.id);
39+
const customerId = await getGitpodService().server.findStripeCustomerIdForTeam(team.id);
4040
setStripeCustomerId(customerId);
4141
} catch (error) {
4242
console.error(error);
@@ -102,7 +102,7 @@ export default function TeamUsageBasedBilling() {
102102
if (!pollStripeCustomerTimeout) {
103103
// Refresh Stripe customer in 5 seconds in order to poll for upgrade confirmation
104104
const timeout = setTimeout(async () => {
105-
const customerId = await getGitpodService().server.getTeamStripeCustomerId(team.id);
105+
const customerId = await getGitpodService().server.findStripeCustomerIdForTeam(team.id);
106106
setStripeCustomerId(customerId);
107107
setPollStripeCustomerTimeout(undefined);
108108
}, 5000);
@@ -164,7 +164,7 @@ function BillingSetupModal(props: { onClose: () => void }) {
164164
useEffect(() => {
165165
const { server } = getGitpodService();
166166
Promise.all([
167-
server.getStripePublishableKey().then((v) => () => setStripePromise(loadStripe(v || ""))),
167+
server.getStripePublishableKey().then((v) => () => setStripePromise(loadStripe(v))),
168168
server.getStripeSetupIntentClientSecret().then((v) => () => setStripeSetupIntentClientSecret(v)),
169169
]).then((setters) => setters.forEach((s) => s()));
170170
}, []);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,9 +270,9 @@ export interface GitpodServer extends JsonRpcServer<GitpodClient>, AdminServer,
270270

271271
getGithubUpgradeUrls(): Promise<GithubUpgradeURL[]>;
272272

273-
getStripePublishableKey(): Promise<string | undefined>;
274-
getStripeSetupIntentClientSecret(): Promise<string | undefined>;
275-
getTeamStripeCustomerId(teamId: string): Promise<string | undefined>;
273+
getStripePublishableKey(): Promise<string>;
274+
getStripeSetupIntentClientSecret(): Promise<string>;
275+
findStripeCustomerIdForTeam(teamId: string): Promise<string | undefined>;
276276
subscribeTeamToStripe(teamId: string, setupIntentId: string): Promise<void>;
277277

278278
/**

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

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1848,26 +1848,36 @@ export class GitpodServerEEImpl extends GitpodServerImpl {
18481848
}
18491849
}
18501850

1851-
async getStripePublishableKey(ctx: TraceContext): Promise<string | undefined> {
1851+
async getStripePublishableKey(ctx: TraceContext): Promise<string> {
18521852
const user = this.checkAndBlockUser("getStripePublishableKey");
18531853
await this.ensureIsUsageBasedFeatureFlagEnabled(user);
1854-
return this.config.stripeSettings?.publishableKey;
1854+
const publishableKey = this.config.stripeSettings?.publishableKey;
1855+
if (!publishableKey) {
1856+
throw new ResponseError(
1857+
ErrorCodes.INTERNAL_SERVER_ERROR,
1858+
"Stripe is not properly configured (no publishable key)",
1859+
);
1860+
}
1861+
return publishableKey;
18551862
}
18561863

1857-
async getStripeSetupIntentClientSecret(ctx: TraceContext): Promise<string | undefined> {
1864+
async getStripeSetupIntentClientSecret(ctx: TraceContext): Promise<string> {
18581865
const user = this.checkAndBlockUser("getStripeSetupIntentClientSecret");
18591866
await this.ensureIsUsageBasedFeatureFlagEnabled(user);
18601867
try {
18611868
const setupIntent = await this.stripeService.createSetupIntent();
1862-
return setupIntent.client_secret || undefined;
1869+
if (!setupIntent.client_secret) {
1870+
throw new Error("No client secret in the SetupIntent");
1871+
}
1872+
return setupIntent.client_secret;
18631873
} catch (error) {
18641874
log.error("Failed to create Stripe SetupIntent", error);
18651875
throw new ResponseError(ErrorCodes.INTERNAL_SERVER_ERROR, "Failed to create Stripe SetupIntent");
18661876
}
18671877
}
18681878

1869-
async getTeamStripeCustomerId(ctx: TraceContext, teamId: string): Promise<string | undefined> {
1870-
const user = this.checkAndBlockUser("getTeamStripeCustomerId");
1879+
async findStripeCustomerIdForTeam(ctx: TraceContext, teamId: string): Promise<string | undefined> {
1880+
const user = this.checkAndBlockUser("findStripeCustomerIdForTeam");
18711881
await this.ensureIsUsageBasedFeatureFlagEnabled(user);
18721882
await this.guardTeamOperation(teamId, "update");
18731883
try {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ function getConfig(config: RateLimiterConfig): RateLimiterConfig {
198198
tsReassignSlot: { group: "default", points: 1 },
199199
getStripePublishableKey: { group: "default", points: 1 },
200200
getStripeSetupIntentClientSecret: { group: "default", points: 1 },
201-
getTeamStripeCustomerId: { group: "default", points: 1 },
201+
findStripeCustomerIdForTeam: { group: "default", points: 1 },
202202
subscribeTeamToStripe: { group: "default", points: 1 },
203203
trackEvent: { group: "default", points: 1 },
204204
trackLocation: { group: "default", points: 1 },

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3033,13 +3033,13 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
30333033
async getGithubUpgradeUrls(ctx: TraceContext): Promise<GithubUpgradeURL[]> {
30343034
throw new ResponseError(ErrorCodes.SAAS_FEATURE, `Not implemented in this version`);
30353035
}
3036-
async getStripePublishableKey(ctx: TraceContext): Promise<string | undefined> {
3036+
async getStripePublishableKey(ctx: TraceContext): Promise<string> {
30373037
throw new ResponseError(ErrorCodes.SAAS_FEATURE, `Not implemented in this version`);
30383038
}
3039-
async getStripeSetupIntentClientSecret(ctx: TraceContext): Promise<string | undefined> {
3039+
async getStripeSetupIntentClientSecret(ctx: TraceContext): Promise<string> {
30403040
throw new ResponseError(ErrorCodes.SAAS_FEATURE, `Not implemented in this version`);
30413041
}
3042-
async getTeamStripeCustomerId(ctx: TraceContext, teamId: string): Promise<string | undefined> {
3042+
async findStripeCustomerIdForTeam(ctx: TraceContext, teamId: string): Promise<string | undefined> {
30433043
throw new ResponseError(ErrorCodes.SAAS_FEATURE, `Not implemented in this version`);
30443044
}
30453045
async subscribeTeamToStripe(ctx: TraceContext, teamId: string, setupIntentId: string): Promise<void> {

0 commit comments

Comments
 (0)