Stripe's Checkout makes it almost too easy to take people's money. This should make it even easier if you're building a react application.
Get started by installing with npm
npm install react-stripe-checkout
Requires babel for compiling. If anyone is having issues with that, open an issue and I'll do my best to better document the build process.
There used to be a seperate .styl
file and respective .css
output. These have been removed and are now written directly in js.
token
and stripeKey
are the only required props,
everything else is options as per the stripe docs. See Checkout
Docs. All props
go through simple validation and are passed to stripe checkout, they're
also documented in StripeCheckout.js
.
import React from 'react'
import StripeCheckout from 'react-stripe-checkout';
export default class TakeMoney extends React.Component {
onToken = (token) => {
fetch('/save-stripe-token', {
method: 'POST',
body: JSON.stringify(token),
}).then(token => {
alert(`We are in business, ${token.email}`);
});
}
// ...
render() {
return (
// ...
<StripeCheckout
token={this.onToken}
stripeKey="my_PUBLISHABLE_stripekey"
/>
)
}
}
This will give you a default Stripe-style button which looks like this:
<StripeCheckout
name="Three Comma Co."
description="Big Data Stuff"
image="https://www.vidhub.co/assets/logos/vidhub-icon-2e5c629f64ced5598a56387d4e3d0c7c.png"
ComponentClass="div"
panelLabel="Give Money"
amount={1000000}
currency="USD"
stripeKey="..."
locale="zh"
email="[email protected]"
// Note: Enabling either address option will give the user the ability to
// fill out both. Addresses are sent as a second parameter in the token callback.
shippingAddress
billingAddress={false}
// Note: enabling both zipCode checks and billing or shipping address will
// cause zipCheck to be pulled from billing address (set to shipping if none provided).
zipCode={false}
alipay
bitcoin
allowRememberMe
token={this.onToken}
// Note: `reconfigureOnUpdate` should be set to true IFF, for some reason
// you are using multiple stripe keys
reconfigureOnUpdate={false}
// Note: you can change the event to `onTouchTap`, `onClick`, `onTouchStart`
// useful if you're using React-Tap-Event-Plugin
triggerEvent="onTouchTap"
>
<button className="btn btn-primary">
Use your own child component, which gets wrapped in whatever
component you pass into as "ComponentClass" (defaults to span)
</button>
</StripeCheckout>
This was probably terribly written, I'll look at any PR coming my way.
- @orhan-swe added updates to checkout after instantiation and fixed a loading error
- @ekalvi added multiple checkout buttons per page
- @jstaffans adding support for locale
- @gabestein added billing and shipping options