Created
May 21, 2021 11:21
-
-
Save johnb8005/3b1aec1546afad3185854b22b55586d4 to your computer and use it in GitHub Desktop.
Stripe js
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 from "react"; | |
import { loadStripe, Stripe } from "@stripe/stripe-js"; | |
const stripePublicKey = 'mypublic key' | |
/** | |
* @param sessionId: session id returned ny the backend, see https://github.com/nexys-system/stripe | |
*/ | |
const Stripe = ({ stripe, seesionId }: { stripe: Stripe, sessionId: string }) => { | |
const sessionId = | |
"cs_test_a1qVEVYCpVTpren53NbTIodcmQXETGj7RJ9esAK26ETkOMHe1pbnWdPJhz"; | |
stripe.redirectToCheckout({ sessionId }); | |
return <p>fd {JSON.stringify(stripe)}</p>; | |
}; | |
export default () => { | |
const [stripe, setStripe] = React.useState<Stripe | undefined>(undefined); | |
if (stripe === undefined) { | |
loadStripe(stripePublicKey).then((x) => setStripe(x)); | |
return ( | |
<p> | |
<i>Loading</i> | |
</p> | |
); | |
} | |
return <Stripe stripe={stripe} />; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment