react-stripe-typescript-client
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

React Stripe Typescript Client

A small library for React / React Native which creates Stripe tokens using your Publishable API Key which can then safely be consumed by your backend

Installation

$ npm i install react-stripe-typescript-client

or

$ yarn add react-stripe-typescript-client

Usage

import { createToken } from "react-stripe-typescript-client"

const res: TokenResponse = await createToken(
    'YOUR_PUBLISHABLE_STRIPE_TOKEN',
      {
        cvc: 245,
        exp_month: 12,
        exp_year: 24,
        number: 42424242424242,
      }
    );

The createToken function also accepts all other Stripe card parameters within the card object

The TokenResponse interface has the following format

interface TokenResponse {
  id: string;
  object: string;
  card: Card;
  client_ip: string;
  created: number;
  livemode: boolean;
  type: string;
  used: boolean;
  error: TokenErrorResponse;
}

Error handling

If an error is sent back by Stripe, it's made available in the error key inside of the TokenResponse interface

Package Sidebar

Install

npm i react-stripe-typescript-client

Weekly Downloads

1

Version

1.0.2

License

MIT

Unpacked Size

9.26 kB

Total Files

11

Last publish

Collaborators

  • jeremywashington