mirror of
https://github.com/Frooodle/Stirling-PDF.git
synced 2026-03-04 02:20:19 +01:00
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:
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user