Skip to content

Instantly share code, notes, and snippets.

@reichert621
Created June 16, 2019 20:05
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 reichert621/66a3f0414064513ec899d02d7f31fc17 to your computer and use it in GitHub Desktop.
Save reichert621/66a3f0414064513ec899d02d7f31fc17 to your computer and use it in GitHub Desktop.
import React from 'react';
import { StripeProvider, Elements, injectStripe } from 'react-stripe-elements';
// Replace with your public key (https://dashboard.stripe.com/test/apikeys)
const STRIPE_API_KEY = 'pk_test_xxx';
const Checkout = props => {
const handleCheckout = () => {
props.stripe.redirectToCheckout({
items: [{ sku: props.skuId, quantity: 1 }],
// Replace with your redirect URLs
successUrl: 'http://localhost:3000/success',
cancelUrl: 'http://localhost:3000/cancel'
});
};
return <button onClick={handleCheckout}>Checkout</button>;
};
const StripeCheckout = injectStripe(Checkout);
const App = () => {
// Fetch dynamically (see "Create a product")
const skuId = 'sku_xxx';
return (
<StripeProvider apiKey={STRIPE_API_KEY}>
<Elements>
<StripeCheckout skuId={skuId} />
</Elements>
</StripeProvider>
);
};
export default App;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment