{"record":{"id":"99c92230fae25ec6","repo":"Stirling-Tools/Stirling-PDF","slug":"failed-to-create-checkout-session-error-message","errorCode":null,"errorMessage":"Failed to create checkout session: ${error.message}","messagePattern":"Failed to create checkout session: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"frontend/editor/src/proprietary/services/licenseService.ts","lineNumber":371,"sourceCode":"        requires_seats: request.requires_seats,\n        seat_count: request.seat_count || 1,\n        email: request.email,\n        callback_base_url: baseUrl,\n        ui_mode: checkoutMode,\n        // For hosted checkout, provide success/cancel URLs\n        success_url:\n          checkoutMode === \"hosted\"\n            ? `${settingsUrl}?session_id={CHECKOUT_SESSION_ID}&payment_status=success`\n            : undefined,\n        cancel_url:\n          checkoutMode === \"hosted\"\n            ? `${settingsUrl}?payment_status=canceled`\n            : undefined,\n      },\n    });\n\n    if (error) {\n      throw new Error(`Failed to create checkout session: ${error.message}`);\n    }\n\n    return data as CheckoutSessionResponse;\n  },\n\n  /**\n   * Create a Stripe billing portal session for managing subscription\n   * Uses license key for self-hosted authentication\n   */\n  async createBillingPortalSession(\n    returnUrl: string,\n    licenseKey: string,\n  ): Promise<BillingPortalResponse> {\n    // Check if Supabase is configured\n    if (!isSupabaseConfigured || !supabase) {\n      throw new Error(\n        \"Supabase is not configured. Billing portal is not available.\",\n      );","sourceCodeStart":353,"sourceCodeEnd":389,"githubUrl":"https://github.com/Stirling-Tools/Stirling-PDF/blob/9ef20dcab80b85041912f045e17a6aea1d08f969/frontend/editor/src/proprietary/services/licenseService.ts#L353-L389","documentation":"Thrown by createCheckoutSession when supabase.functions.invoke('create-checkout', ...) returns a non-null error. Like other Supabase edge-function calls, invoke resolves with {data, error}; a non-null error means the create-checkout function failed — bad Stripe keys, invalid lookup_key, missing installation_id, or a function-level exception. The thrown Error wraps error.message for the caller.","triggerScenarios":"create-checkout edge function lacks STRIPE_SECRET_KEY; the lookup_key in the request doesn't match a Stripe price; installation_id missing or malformed; Stripe rejects the session (blocked currency, inactive product); function throws on an unhandled code path.","commonSituations":"Stripe product for the lookup key is archived; currency/region mismatch; edge function deployed without secrets; Supabase project outage; malformed CheckoutSessionRequest from the UI.","solutions":["Read error.message — Stripe errors include the Stripe code (e.g. resource_missing, invalid_request).","Confirm the create-checkout function is deployed with STRIPE_SECRET_KEY set.","Validate the request.lookup_key against SELF_HOSTED_LOOKUP_KEYS and ensure the price is active in Stripe.","Ensure installation_id was fetched (getInstallationId) and passed for self-hosted checkout."],"exampleFix":"// before\nconst data = await licenseService.createCheckoutSession(req);\n\n// after\ntry {\n  const data = await licenseService.createCheckoutSession(req);\n  redirectToCheckout(data);\n} catch (e) {\n  showToast(e instanceof Error ? e.message : 'Checkout failed');\n}","handlingStrategy":"try-catch","validationCode":"if (!req.lookup_key || !SELF_HOSTED_LOOKUP_KEYS.includes(req.lookup_key)) {\n  setError('Invalid plan selection');\n  return;\n}\nif (req.installation_id == null) req.installation_id = await licenseService.getInstallationId();","typeGuard":"export function isValidCheckoutRequest(r: CheckoutSessionRequest): boolean {\n  return Boolean(r.lookup_key) && SELF_HOSTED_LOOKUP_KEYS.includes(r.lookup_key);\n}","tryCatchPattern":"try {\n  const data = await licenseService.createCheckoutSession(req);\n  redirectToCheckout(data);\n} catch (e) {\n  showToast(e instanceof Error ? e.message : 'Checkout failed');\n}","preventionTips":["Validate lookup_key against SELF_HOSTED_LOOKUP_KEYS before calling.","Ensure installation_id is fetched and passed for self-hosted checkout.","Confirm create-checkout is deployed with STRIPE_SECRET_KEY and the Stripe price is active."],"tags":["supabase","edge-function","stripe","checkout","license","proprietary","typescript"],"backgroundTag":null,"analyzedSha":"9ef20dcab80b85041912f045e17a6aea1d08f969","analyzedAt":"2026-08-13T22:11:39.827Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}