Skip to content

Lightweight, easy to integrate and use React native library for Stripe payments (using Payment Intents) compliant with SCA (strong customer authentication)

License

Notifications You must be signed in to change notification settings

0xamogh/react-native-stripe-payments

 
 

Repository files navigation

React Native Stripe payments

A well typed React Native library providing support for Stripe payments on both iOS and Android.

React Native Stripe payments

Getting started

Starting September 14, 2019 new payments regulation is being rolled out in Europe, which mandates Strong Customer Authentication (SCA) for many online payments in the European Economic Area (EEA). SCA is part of the second Payment Services Directive (PSD2).

This library provides simple way to integrate SCA compliant Stripe payments into your react native app with a first class Typescript support.

Installation

$ yarn add react-native-stripe-payments

$ npx react-native link react-native-stripe-payments

The library ships with platform native code that needs to be compiled together with React Native. This requires you to configure your build tools which can be done with autolinking.

Usage

To use the module, import it first.

import stripe from 'react-native-stripe-payments';

Setup

First of all you have to obtain a Stripe account publishable key, which you need to set it for the module.

stripe.setOptions({ publishingKey: 'STRIPE_PUBLISHING_KEY' });

Validate the given card details

const isCardValid = stripe.isCardValid({
  number: '4242424242424242',
  expMonth: 10,
  expYear: 21,
  cvc: '888',
});

The argument for isCardValid is of type CardParams, which is used across the other APIs.

Set up a payment method for future payments (Setup Intent)

stripe.confirmSetup('client_secret_from_backend', cardParams)
  .then(result => {
    // result of type SetupIntentResult
    // {
    //    paymentMethodId,
    //    liveMode,
    //    last4,
    //    created,
    //    brand
    // }
  })
  .catch(err =>
    // error performing payment
  )

The brand is the provider of the card, and we use the module credit-card-type to achieve that.

One-time payment using the id of a PaymentMethod

stripe.confirmPaymentWithPaymentMethodId('client_secret_from_backend', paymentMethodId)
  .then(result => {
    // result of type PaymentResult
    // {
    //    id,
    //    paymentMethodId
    // }
  })
  .catch(err =>
    // error performing payment
  )

One-time payment using cardParams

const cardDetails = {
  number: '4242424242424242',
  expMonth: 10,
  expYear: 21,
  cvc: '888',
}
stripe.confirmPaymentWithCardParams('client_secret_from_backend', cardParams)
  .then(result => {
    // result of type PaymentResult
    // {
    //    id,
    //    paymentMethodId
    // }
  })
  .catch(err =>
    // error performing payment
  )

About

Lightweight, easy to integrate and use React native library for Stripe payments (using Payment Intents) compliant with SCA (strong customer authentication)

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 49.3%
  • Objective-C 36.3%
  • TypeScript 9.5%
  • Ruby 4.9%