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