Skip to content

Commit 47e4887

Browse files
committed
[server] Make Stripe usage-based product price IDs configurable
1 parent d1e04b7 commit 47e4887

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

components/server/ee/src/user/stripe-service.ts

+5-6
Original file line numberDiff line numberDiff line change
@@ -116,16 +116,15 @@ export class StripeService {
116116
}
117117

118118
async createSubscriptionForCustomer(customerId: string, currency: Currency): Promise<void> {
119-
// FIXME(janx): Use configmap.
120-
const prices = {
121-
EUR: "price_1LAE0AGadRXm50o3xjegX0Kd",
122-
USD: "price_1LAE0AGadRXm50o3rKoktPiJ",
123-
};
119+
const priceId = this.config?.stripeConfig?.usageProductPriceIds[currency];
120+
if (!priceId) {
121+
throw new Error(`No Stripe Price ID configured for currency '${currency}'`);
122+
}
124123
const startOfNextMonth = new Date(new Date().toISOString().slice(0, 7) + "-01"); // First day of this month (YYYY-MM-01)
125124
startOfNextMonth.setMonth(startOfNextMonth.getMonth() + 1); // Add one month
126125
await this.getStripe().subscriptions.create({
127126
customer: customerId,
128-
items: [{ price: prices[currency] }],
127+
items: [{ price: priceId }],
129128
billing_cycle_anchor: Math.round(startOfNextMonth.getTime() / 1000),
130129
});
131130
}

components/server/src/config.ts

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export type Config = Omit<
2626
workspaceDefaults: WorkspaceDefaults;
2727
chargebeeProviderOptions?: ChargebeeProviderOptions;
2828
stripeSecrets?: { publishableKey: string; secretKey: string };
29+
stripeConfig?: { usageProductPriceIds: { EUR: string; USD: string } };
2930
builtinAuthProvidersConfigured: boolean;
3031
blockedRepositories: { urlRegExp: RegExp; blockUser: boolean }[];
3132
inactivityPeriodForRepos?: number;

0 commit comments

Comments
 (0)