(priceId: string)
| 5 | import { fetchPostJSON } from "../utils/api-helpers"; |
| 6 | |
| 7 | const 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 | |
| 32 | const PricingView = () => { |
| 33 | const { t } = useTranslation(); |
no test coverage detected