Path: blob/master/src/packages/frontend/billing/stripe.ts
1503 views
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45import { getStripePublishableKey } from "@cocalc/frontend/purchases/api";6//import { loadStripe as loadStripe0, type Stripe } from "@stripe/stripe-js";7import { type Stripe } from "@stripe/stripe-js";8import { reuseInFlight } from "@cocalc/util/reuse-in-flight";910export interface StripeCard {11mount: Function;12}1314let stripe: Stripe | null = null;15export const loadStripe = reuseInFlight(async (): Promise<Stripe> => {16if (stripe != null) {17return stripe;18}19// load only when actually used, since this involves dynamic load over the internet to stripe.com,20// and we don't want loading cocalc in an airgapped network to have hung network requests.21const { loadStripe: loadStripe0 } = await import("@stripe/stripe-js");22const key = await getStripePublishableKey();23stripe = await loadStripe0(key);24if (stripe == null) {25throw Error("failed to initialized Stripe");26}27return stripe;28});293031