Skip to content

Instantly share code, notes, and snippets.

@ValchanOficial
Created February 18, 2024 21:05
Show Gist options
  • Save ValchanOficial/282666ebba2df49e6be23ccfbffc18a0 to your computer and use it in GitHub Desktop.
Save ValchanOficial/282666ebba2df49e6be23ccfbffc18a0 to your computer and use it in GitHub Desktop.
[React] Stripe
import "./styles.css";
import Stripe from "stripe";
const lineItems = [
{
price: "price_123",
quantity: 1,
},
];
export default function App() {
const handleCheckout = async () => {
const stripe = new Stripe("secret_123", {
apiVersion: "2023-10-16",
});
const checkoutSession = await stripe.checkout.sessions.create({
payment_method_types: ["card"],
line_items: lineItems,
mode: "payment",
success_url: "http://localhost:5173/success",
cancel_url: "http://localhost:5173/cancel",
});
window.location.href = checkoutSession.url;
};
return (
<div className="App">
<button onClick={handleCheckout}>Checkout</button>
</div>
);
}
-----------------------------
https://docs.stripe.com/keys
https://docs.stripe.com/api/products/create
https://docs.stripe.com/api/prices/create
https://docs.stripe.com/api/checkout/sessions/create
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment