MCPcopy Create free account
hub / github.com/sqlchat/sqlchat / checkout

Function checkout

src/components/PricingView.tsx:7–30  ·  view source on GitHub ↗
(priceId: string)

Source from the content-addressed store, hash-verified

5import { fetchPostJSON } from "../utils/api-helpers";
6
7const checkout = async (priceId: string) => {
8 // Create a Checkout Session.
9 const response = await fetchPostJSON("/api/checkout_sessions", {
10 price: priceId,
11 });
12
13 if (response.statusCode === 500) {
14 console.error(response.message);
15 return;
16 }
17
18 // Redirect to Checkout.
19 const stripe = await getStripe();
20 const { error } = await stripe!.redirectToCheckout({
21 // Make the id field from the Checkout Session creation API response
22 // available to this file, so you can provide it as parameter here
23 // instead of the {{CHECKOUT_SESSION_ID}} placeholder.
24 sessionId: response.id,
25 });
26 // If `redirectToCheckout` fails due to a browser or network
27 // error, display the localized error message to your customer
28 // using `error.message`.
29 console.warn(error.message);
30};
31
32const PricingView = () => {
33 const { t } = useTranslation();

Callers 1

PricingViewFunction · 0.85

Calls 2

fetchPostJSONFunction · 0.90
getStripeFunction · 0.85

Tested by

no test coverage detected