Skip to content

Instantly share code, notes, and snippets.

@OmarKhattab
Created November 19, 2020 02:25
Show Gist options
  • Save OmarKhattab/5f30b8f07795b144adbe271a312a976d to your computer and use it in GitHub Desktop.
Save OmarKhattab/5f30b8f07795b144adbe271a312a976d to your computer and use it in GitHub Desktop.
stripe and redirecToCheckout
import React, { useEffect } from "react";
import { useParams } from "react-router-dom";
import { loadStripe } from "@stripe/stripe-js";
const StripeCheckout = () => {
const params = useParams();
console.log(params);
const { id } = params;
useEffect(() => {
const asyncFunc = async () => {
let sessionId =
id ||
"cs_test_c0L1LQZQcXD6UE8niUoE534Gwt9ccYPTXICyiEQI7PvDW9O2H3umg7fYzW";
const stripeKey = sessionId.includes("_test_")
? "pk_test_yourkeyhere"
: "pk_live_yourkeyhere";
const stripe = await loadStripe(stripeKey);
await stripe.redirectToCheckout({
sessionId,
});
};
asyncFunc();
}, []);
return <div />;
};
export default StripeCheckout;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment