Feature/v2/stripeorsupabaseNotEnabled (#5006)

Removed current plan section from static plan to match connected version

stripe publishable key not required to show plans or checkout in hosted
version

lazy load plans when needed not on load
This commit is contained in:
ConnorYoh
2025-11-25 17:09:41 +00:00
committed by GitHub
parent 7253b9fa6d
commit 3b8b539efc
7 changed files with 81 additions and 79 deletions

View File

@@ -3,6 +3,16 @@
* Used to decide between Embedded Checkout (HTTPS) and Hosted Checkout (HTTP)
*/
/**
* Check if Stripe publishable key is configured
* Similar to isSupabaseConfigured pattern - checks availability at decision points
* @returns true if key exists and has valid format
*/
export function isStripeConfigured(): boolean {
const stripeKey = import.meta.env.VITE_STRIPE_PUBLISHABLE_KEY;
return !!stripeKey && stripeKey.startsWith('pk_');
}
/**
* Check if the current context is secure (HTTPS or localhost)
* @returns true if HTTPS or localhost, false if HTTP
@@ -28,16 +38,24 @@ export function isSecureContext(): boolean {
/**
* Get the appropriate Stripe checkout UI mode based on current context
* @returns 'embedded' for HTTPS/localhost, 'hosted' for HTTP
* @returns 'embedded' for HTTPS with key, 'hosted' for HTTP or missing key
*/
export function getCheckoutMode(): 'embedded' | 'hosted' {
// Force hosted checkout if no publishable key (regardless of protocol)
// Hosted checkout works without the key - it just redirects to Stripe
if (!isStripeConfigured()) {
return 'hosted';
}
// Normal protocol-based detection if key is available
return isSecureContext() ? 'embedded' : 'hosted';
}
/**
* Check if Embedded Checkout can be used in current context
* @returns true if secure context (HTTPS/localhost)
* Requires both HTTPS and Stripe publishable key
* @returns true if secure context AND key is configured
*/
export function canUseEmbeddedCheckout(): boolean {
return isSecureContext();
return isSecureContext() && isStripeConfigured();
}