Changes
Co-authored-by: wolfoftyreso-debug <250630591+wolfoftyreso-debug@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,31 @@
|
|||||||
|
import { loadStripe, Stripe } from "@stripe/stripe-js";
|
||||||
|
|
||||||
|
export type StripeEnv = "sandbox" | "live";
|
||||||
|
|
||||||
|
const clientToken = import.meta.env.VITE_PAYMENTS_CLIENT_TOKEN as string | undefined;
|
||||||
|
|
||||||
|
function paymentsEnvironment(): StripeEnv {
|
||||||
|
if (clientToken?.startsWith("pk_test_")) return "sandbox";
|
||||||
|
if (clientToken?.startsWith("pk_live_")) return "live";
|
||||||
|
throw new Error(
|
||||||
|
"Betalningar är inte konfigurerade för denna build. Slutför go-live i Payments-fliken för att aktivera skarpa betalningar."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
let stripePromise: Promise<Stripe | null> | null = null;
|
||||||
|
|
||||||
|
export function getStripe(): Promise<Stripe | null> {
|
||||||
|
if (!stripePromise) {
|
||||||
|
paymentsEnvironment();
|
||||||
|
stripePromise = loadStripe(clientToken as string);
|
||||||
|
}
|
||||||
|
return stripePromise;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getStripeEnvironment(): StripeEnv {
|
||||||
|
return paymentsEnvironment();
|
||||||
|
}
|
||||||
|
|
||||||
|
export function hasPaymentsConfigured(): boolean {
|
||||||
|
return !!clientToken && (clientToken.startsWith("pk_test_") || clientToken.startsWith("pk_live_"));
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user