expo / stripe-expo

Use the Stripe HTTP API in Expo without the DOM, node, or native deps
MIT License
159 stars 23 forks source link

Stripe Client

Build Status

React Native Stripe wrapper that makes using Stripe with React Native easy in iOS/Android.

Features

Limitations

Installation

npm install stripe-client --save

Or

yarn add stripe-client

Creating a token

stripe.createToken(...) returns a Promise of a token object (https://stripe.com/docs/api/node#token_object).

If the token object creation fails (ex. the expiration date is invalid, the card number is the wrong format), stripe.createToken(...) returns the corresponding error (https://stripe.com/docs/api/node#errors).

Creating a credit card token

import React from 'react';
var stripe = require('stripe-client')('YOUR_PUBLISHABLE_STRIPE_API_KEY');

var information = {
  card: {
    number: '4242424242424242',
    exp_month: '02',
    exp_year: '21',
    cvc: '999',
    name: 'Billy Joe'
  }
}

export class App extends React.Component {
  async onPayment() {
    var card = await stripe.createToken(information);
    var token = card.id;
    // send token to backend for processing
  }

  render() {
    ...
  }
}

Creating a bank account token

import React from 'react';
var stripe = require('stripe-client')('YOUR_PUBLISHABLE_STRIPE_API_KEY');

var information = {
  bank_account: {
    country: 'US',
    currency: 'usd',
    account_holder_name: 'Noah Martinez',
    account_holder_type: 'individual',
    routing_number: '110000000',
    account_number: '000123456789'
  }
}

export class App extends React.Component {
  async onPayment() {
    var bank = await stripe.createToken(information);
    var token = bank.id;
    // send token to backend for processing
  }

  render() {
    ...
  }
}

Creating a PII token

var stripe = require('stripe-client')('YOUR_PUBLISHABLE_STRIPE_API_KEY');

var information = {
  pii: {
    personal_id_number: '000000000'
  }
}

export class App extends React.Component {
  async onPayment() {
    var pii = await stripe.createToken(information);
    var token = pii.id;
    // send token to backend for processing
  }

  render() {
    ...
  }
}

Questions and Answers

Where can I find more information about creating tokens in Stripe?

Help! I don't know where to find 'YOUR_PUBLISHABLE_STRIPE_API_KEY' ?

Is it okay to publish my Stripe API key in the Expo / React Native application?

I want to charge a customer with this library. How would I do that?