Giter Site home page Giter Site logo

yuttasakcom / react-stripe-checkout Goto Github PK

View Code? Open in Web Editor NEW

This project forked from azmenak/react-stripe-checkout

0.0 2.0 0.0 89 KB

Load stripe's checkout.js as a react component. Easiest way to use checkout with React.

License: MIT License

JavaScript 100.00%

react-stripe-checkout's Introduction

npm version Dependencies Status Gitter

React Stripe Checkout Component

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.

Installation

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.

Changes in version 2.0

There used to be a separate .styl file and respective .css output. These have been removed and are now written directly in js.

Requirements

token and stripeKey are the only required props, everything else is optional 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(response => {
      response.json().then(data => {
        alert(`We are in business, ${data.email}`);
      });
    });
  }

  // ...

  render() {
    return (
      // ...
      <StripeCheckout
        token={this.onToken}
        stripeKey="my_PUBLISHABLE_stripekey"
      />
    )
  }
}

This will give you a default Stripe-style button which looks like this:

stripe checkout button

Send all the props!

<StripeCheckout
  name="Three Comma Co." // the pop-in header title
  description="Big Data Stuff" // the pop-in header subtitle
  image="https://www.vidhub.co/assets/logos/vidhub-icon-2e5c629f64ced5598a56387d4e3d0c7c.png" // the pop-in header image (default none)
  ComponentClass="div"
  panelLabel="Give Money" // prepended to the amount in the bottom pay button
  amount={1000000} // cents
  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 // accept Alipay (default false)
  bitcoin // accept Bitcoins (default false)
  allowRememberMe // "Remember Me" option (default true)
  token={this.onToken} // submit callback
  opened={this.onOpened} // called when the checkout popin is opened (no IE6/7)
  closed={this.onClosed} // called when the checkout popin is closed (no IE6/7)
  // 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>

Other info

This was probably terribly written, I'll look at any PR coming my way.

Resources

Contributors

  • @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
  • @samcorcos added testing

react-stripe-checkout's People

Contributors

antoinerousseau avatar azmenak avatar bikegriffith avatar byte255 avatar chabou avatar dav-ell avatar gabestein avatar ihsane avatar jstaffans avatar mavarazy avatar michaellyons avatar minheq avatar mscoutermarsh avatar orhan-swe avatar pdeva avatar piuccio avatar rwieruch avatar samcorcos avatar tmoc avatar tpredale avatar warlo avatar waynebrantley avatar wcandillon avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.