Skip to content

Instantly share code, notes, and snippets.

@johnb8005
Created May 21, 2021 11:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnb8005/3b1aec1546afad3185854b22b55586d4 to your computer and use it in GitHub Desktop.
Save johnb8005/3b1aec1546afad3185854b22b55586d4 to your computer and use it in GitHub Desktop.
Stripe js
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