-
Notifications
You must be signed in to change notification settings - Fork 617
Add Stripe checkout for Growth plan subscription #8068
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -91,3 +91,24 @@ if (REDIS_URL) { | |
| REDIS_URL, | ||
| ); | ||
| } | ||
|
|
||
| export const GROWTH_PLAN_SKU = process.env.GROWTH_PLAN_SKU || ""; | ||
|
|
||
| if (GROWTH_PLAN_SKU) { | ||
| experimental_taintUniqueValue( | ||
| "Do not pass GROWTH_PLAN_SKU to the client", | ||
| process, | ||
| GROWTH_PLAN_SKU, | ||
| ); | ||
| } | ||
|
|
||
| export const PAYMENT_METHOD_CONFIGURATION = | ||
| process.env.PAYMENT_METHOD_CONFIGURATION || ""; | ||
|
|
||
| if (PAYMENT_METHOD_CONFIGURATION) { | ||
| experimental_taintUniqueValue( | ||
| "Do not pass PAYMENT_METHOD_CONFIGURATION to the client", | ||
| process, | ||
| PAYMENT_METHOD_CONFIGURATION, | ||
| ); | ||
| } | ||
|
Comment on lines
+95
to
+114
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fail fast in prod when required billing envs are missing.
export const GROWTH_PLAN_SKU = process.env.GROWTH_PLAN_SKU || "";
if (GROWTH_PLAN_SKU) {
experimental_taintUniqueValue(
"Do not pass GROWTH_PLAN_SKU to the client",
process,
GROWTH_PLAN_SKU,
);
}
export const PAYMENT_METHOD_CONFIGURATION =
process.env.PAYMENT_METHOD_CONFIGURATION || "";
if (PAYMENT_METHOD_CONFIGURATION) {
experimental_taintUniqueValue(
"Do not pass PAYMENT_METHOD_CONFIGURATION to the client",
process,
PAYMENT_METHOD_CONFIGURATION,
);
}
+
+// Guard required billing envs in production to avoid runtime failures
+if (isProd && !GROWTH_PLAN_SKU) {
+ throw new Error("GROWTH_PLAN_SKU must be set in production");
+}
🤖 Prompt for AI Agents |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug:
headers()is synchronous andorigincan be null; invalid return_url breaks Embedded Checkout. Add robust base URL derivation and env guards.await headers().x-forwarded-proto+x-forwarded-host(fallback tohost), and error if unavailable.GROWTH_PLAN_SKU; don’t send emptypayment_method_configuration.metadatafor traceability.export async function fetchClientSecret(team: Team) { "use server"; - const origin = (await headers()).get("origin"); const stripe = getStripe(); const customerId = team.stripeCustomerId; if (!customerId) { throw new Error("No customer ID found"); } + if (!GROWTH_PLAN_SKU) { + throw new Error("GROWTH_PLAN_SKU is not configured"); + } + + const hdrs = headers(); + const proto = hdrs.get("x-forwarded-proto") ?? "https"; + const host = hdrs.get("x-forwarded-host") ?? hdrs.get("host"); + const baseUrl = host ? `${proto}://${host}` : undefined; + if (!baseUrl) { + throw new Error("Unable to determine base URL from headers"); + } // Create Checkout Sessions from body params. const session = await stripe.checkout.sessions.create({ ui_mode: "embedded", line_items: [ { // Provide the exact Price ID (for example, price_1234) of // the product you want to sell price: GROWTH_PLAN_SKU, quantity: 1, }, ], mode: "subscription", - - return_url: `${origin}/get-started/team/${team.slug}/select-plan?session_id={CHECKOUT_SESSION_ID}`, + return_url: `${baseUrl}/get-started/team/${team.slug}/select-plan?session_id={CHECKOUT_SESSION_ID}`, automatic_tax: { enabled: true }, allow_promotion_codes: true, customer: customerId, customer_update: { address: "auto", }, payment_method_collection: "always", - payment_method_configuration: PAYMENT_METHOD_CONFIGURATION, + payment_method_configuration: PAYMENT_METHOD_CONFIGURATION || undefined, subscription_data: { trial_period_days: 14, trial_settings: { end_behavior: { missing_payment_method: "cancel", }, }, }, + metadata: { + teamId: team.id, + teamSlug: team.slug, + source: "onboarding", + }, }); if (!session.client_secret) { throw new Error("No client secret found"); } return session.client_secret; }📝 Committable suggestion