Created
November 19, 2020 02:25
-
-
Save OmarKhattab/5f30b8f07795b144adbe271a312a976d to your computer and use it in GitHub Desktop.
stripe and redirecToCheckout
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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