Skip to content

Instantly share code, notes, and snippets.

@lfades
Created February 22, 2018 20:34
Show Gist options
  • Save lfades/5e916dcffed22665071b6efbe732f255 to your computer and use it in GitHub Desktop.
Save lfades/5e916dcffed22665071b6efbe732f255 to your computer and use it in GitHub Desktop.
Next with Stripe
function LoadScript(src) {
return new Promise((resolve, reject) => {
const script = document.createElement('script')
script.src = src
script.addEventListener('load', resolve)
script.addEventListener('error', reject)
document.body.appendChild(script)
})
}
export default class ComponentWithStripe extends React.Component {
stripe = this.loadStripeHandler(this)
loadStripeHandler(Component) {
if (!process.browser) return
LoadScript('https://checkout.stripe.com/checkout.js')
.then(() => {
Component.stripe = window.StripeCheckout.configure({
key: 'xxxxxxx',
image:
'https://stripe.com/img/documentation/checkout/marketplace.png',
locale: 'auto',
token: this.payWithStripe
})
})
.catch(error => {
console.log(error)
})
}
payWithStripe(token) {
// payment stuff
}
render () {
// jsx
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment