Created
June 16, 2019 20:05
-
-
Save reichert621/66a3f0414064513ec899d02d7f31fc17 to your computer and use it in GitHub Desktop.
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 { 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