Skip to content

Minor Stripe API clean-up #10554

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions components/dashboard/src/teams/TeamUsageBasedBilling.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default function TeamUsageBasedBilling() {
setStripeCustomerId(undefined);
setIsLoading(true);
try {
const customerId = await getGitpodService().server.getTeamStripeCustomerId(team.id);
const customerId = await getGitpodService().server.findStripeCustomerIdForTeam(team.id);
setStripeCustomerId(customerId);
} catch (error) {
console.error(error);
Expand Down Expand Up @@ -102,7 +102,7 @@ export default function TeamUsageBasedBilling() {
if (!pollStripeCustomerTimeout) {
// Refresh Stripe customer in 5 seconds in order to poll for upgrade confirmation
const timeout = setTimeout(async () => {
const customerId = await getGitpodService().server.getTeamStripeCustomerId(team.id);
const customerId = await getGitpodService().server.findStripeCustomerIdForTeam(team.id);
setStripeCustomerId(customerId);
setPollStripeCustomerTimeout(undefined);
}, 5000);
Expand Down Expand Up @@ -164,7 +164,7 @@ function BillingSetupModal(props: { onClose: () => void }) {
useEffect(() => {
const { server } = getGitpodService();
Promise.all([
server.getStripePublishableKey().then((v) => () => setStripePromise(loadStripe(v || ""))),
server.getStripePublishableKey().then((v) => () => setStripePromise(loadStripe(v))),
server.getStripeSetupIntentClientSecret().then((v) => () => setStripeSetupIntentClientSecret(v)),
]).then((setters) => setters.forEach((s) => s()));
}, []);
Expand Down
6 changes: 3 additions & 3 deletions components/gitpod-protocol/src/gitpod-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,9 @@ export interface GitpodServer extends JsonRpcServer<GitpodClient>, AdminServer,

getGithubUpgradeUrls(): Promise<GithubUpgradeURL[]>;

getStripePublishableKey(): Promise<string | undefined>;
getStripeSetupIntentClientSecret(): Promise<string | undefined>;
getTeamStripeCustomerId(teamId: string): Promise<string | undefined>;
getStripePublishableKey(): Promise<string>;
getStripeSetupIntentClientSecret(): Promise<string>;
findStripeCustomerIdForTeam(teamId: string): Promise<string | undefined>;
subscribeTeamToStripe(teamId: string, setupIntentId: string): Promise<void>;

/**
Expand Down
22 changes: 16 additions & 6 deletions components/server/ee/src/workspace/gitpod-server-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1848,26 +1848,36 @@ export class GitpodServerEEImpl extends GitpodServerImpl {
}
}

async getStripePublishableKey(ctx: TraceContext): Promise<string | undefined> {
async getStripePublishableKey(ctx: TraceContext): Promise<string> {
const user = this.checkAndBlockUser("getStripePublishableKey");
await this.ensureIsUsageBasedFeatureFlagEnabled(user);
return this.config.stripeSettings?.publishableKey;
const publishableKey = this.config.stripeSettings?.publishableKey;
if (!publishableKey) {
throw new ResponseError(
ErrorCodes.INTERNAL_SERVER_ERROR,
"Stripe is not properly configured (no publishable key)",
);
}
return publishableKey;
}

async getStripeSetupIntentClientSecret(ctx: TraceContext): Promise<string | undefined> {
async getStripeSetupIntentClientSecret(ctx: TraceContext): Promise<string> {
const user = this.checkAndBlockUser("getStripeSetupIntentClientSecret");
await this.ensureIsUsageBasedFeatureFlagEnabled(user);
try {
const setupIntent = await this.stripeService.createSetupIntent();
return setupIntent.client_secret || undefined;
if (!setupIntent.client_secret) {
throw new Error("No client secret in the SetupIntent");
}
return setupIntent.client_secret;
} catch (error) {
log.error("Failed to create Stripe SetupIntent", error);
throw new ResponseError(ErrorCodes.INTERNAL_SERVER_ERROR, "Failed to create Stripe SetupIntent");
}
}

async getTeamStripeCustomerId(ctx: TraceContext, teamId: string): Promise<string | undefined> {
const user = this.checkAndBlockUser("getTeamStripeCustomerId");
async findStripeCustomerIdForTeam(ctx: TraceContext, teamId: string): Promise<string | undefined> {
const user = this.checkAndBlockUser("findStripeCustomerIdForTeam");
await this.ensureIsUsageBasedFeatureFlagEnabled(user);
await this.guardTeamOperation(teamId, "update");
try {
Expand Down
2 changes: 1 addition & 1 deletion components/server/src/auth/rate-limiter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ function getConfig(config: RateLimiterConfig): RateLimiterConfig {
tsReassignSlot: { group: "default", points: 1 },
getStripePublishableKey: { group: "default", points: 1 },
getStripeSetupIntentClientSecret: { group: "default", points: 1 },
getTeamStripeCustomerId: { group: "default", points: 1 },
findStripeCustomerIdForTeam: { group: "default", points: 1 },
subscribeTeamToStripe: { group: "default", points: 1 },
trackEvent: { group: "default", points: 1 },
trackLocation: { group: "default", points: 1 },
Expand Down
6 changes: 3 additions & 3 deletions components/server/src/workspace/gitpod-server-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3033,13 +3033,13 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
async getGithubUpgradeUrls(ctx: TraceContext): Promise<GithubUpgradeURL[]> {
throw new ResponseError(ErrorCodes.SAAS_FEATURE, `Not implemented in this version`);
}
async getStripePublishableKey(ctx: TraceContext): Promise<string | undefined> {
async getStripePublishableKey(ctx: TraceContext): Promise<string> {
throw new ResponseError(ErrorCodes.SAAS_FEATURE, `Not implemented in this version`);
}
async getStripeSetupIntentClientSecret(ctx: TraceContext): Promise<string | undefined> {
async getStripeSetupIntentClientSecret(ctx: TraceContext): Promise<string> {
throw new ResponseError(ErrorCodes.SAAS_FEATURE, `Not implemented in this version`);
}
async getTeamStripeCustomerId(ctx: TraceContext, teamId: string): Promise<string | undefined> {
async findStripeCustomerIdForTeam(ctx: TraceContext, teamId: string): Promise<string | undefined> {
throw new ResponseError(ErrorCodes.SAAS_FEATURE, `Not implemented in this version`);
}
async subscribeTeamToStripe(ctx: TraceContext, teamId: string, setupIntentId: string): Promise<void> {
Expand Down