Skip to content

stripe/stripe-identity-react-native

Repository files navigation

Stripe Identity React Native SDK

Stripe Identity enables online businesses to securely verify the identities of users around the world. Robust identity verification helps prevent fraud, simplify compliance, and increase trust. Stripe will use biometric technology (on images of you and your IDs) and other data sources. With the Stripe Identity React Native SDK, you can confidently verify the authenticity of ID documents from over 33 countries in your React Native application.

To get access to the Identity React Native SDK, visit the Identity Settings page and click Enable.

Getting started

Get started with our 📚 integration guides and example project.

Updating to a newer version of the SDK? See our changelog.

Features

Simplified security: We've made it simple for you to securely collect your user's personally identifiable information (PII) such as identity document images. Sensitive PII data is sent directly to Stripe Identity instead of passing through your server. For more information, see our integration security guide.

Automatic document capture: We automatically capture images of the front and back of government-issued photo ID to ensure a clear and readable image.

Prebuilt UI: We provide IdentityVerificationSheet, a prebuilt UI that combines all the steps required to collect ID documents, selfies, and ID numbers into a single sheet that displays on top of your app.

Automated verification: Stripe Identity's automated verification technology looks for patterns to help determine if an ID document is real or fake and uses distinctive physiological characteristics of faces to match your users' selfies to photos on their ID document. Collected identity information is checked against a global set of databases to confirm that it exists. Learn more about the verification checks supported by Stripe Identity, accessing verification results, or our integration guide on handling verification outcomes.

Requirements

The SDK uses TypeScript features available in Babel version 7.9.0 and above. Alternatively use the plugin-transform-typescript plugin in your project.

Android

  • Compatible with Android 5.0 (API level 21) and above.
  • Stripe Identity requires the hosting activity to use material theme. To enable material theme:
    • Open your project's app/src/main/AndroidManifest.xml.
    • Make sure the android:theme applied to the application is a child of one of the material themes(e.g Theme.MaterialComponents.DayNight).

      See more details about material theme here.

iOS

Note: Xcode 13 is no longer supported by Apple. Please upgrade to Xcode 14.1 or later.

  • Compatible with apps targeting iOS 13.0 or above.
  • Run pod install in your ios directory to ensure that you also install the required native dependencies.
  • Stripe Identity requires access to the device’s camera to capture identity documents. To enable your app to request camera permissions:
    • Open your project’s Info.plist.
    • Add the NSCameraUsageDescription key.
    • Add a string value that explains to your users why your app requires camera permissions(e.g This app uses the camera to take a picture of your identity documents.).

Usage example

Get started with our 📚 integration guides and example project, or 📘 browse the SDK reference.

To initialize Stripe Identity SDK in your React Native app, use the useStripeIdentity hook in the screen where you want to use it.

First you need a server-side endpoint to create the VerificationSession and ephemeral key secret, then you can send a POST request to create verification session:

const fetchVerificationSessionParams = async () => {
  try {
    const data = await fetch(
      `${YOUR_SERVER_BASE_URL}/create-verification-session`,
      {
        method: 'POST',
        headers: {
          'Content-Type': 'application/json',
        },
        body: {},
      }
    );
    const json = await data.json();
    return json;
  } catch (e) {
    return {};
  }
};

Once you get options you can use useStripeIdentity passing fetchOptions to it.

// HomeScreen.tsx
import { useStripeIdentity } from '@stripe/stripe-identity-react-native';
import logo from './assets/logo.png';

function HomeScreen() {
  const fetchOptions = async () => {
    const response = await fetchVerificationSessionParams();

    return {
      sessionId: response.id,
      ephemeralKeySecret: response.ephemeral_key_secret,
      brandLogo: Image.resolveAssetSource(logo),
    };
  };

  const { status, present, loading } = useStripeIdentity(fetchOptions);

  const handlePress = useCallback(() => {
    present();
  }, [present]);

  const renderButton = useCallback(() => {
    if (loading) {
      return <ActivityIndicator />;
    }
    return <Button title="Verify Identity" onPress={handlePress} />;
  }, [loading, handlePress]);

  return (
    <View>
      <View>{renderButton()}</View>
      <Text>Status: {status}</Text>
    </View>
  );
}

Or if you don't want to use useStripeIdentity hook, you can also use this method to create your own implementation:

// HomeScreen.tsx
import { useState } from 'react';
import { presentIdentityVerificationSheet } from '@stripe/stripe-identity-react-native';
import logo from './assets/logo.png';

function HomeScreen() {
  const [loading, setLoading] = useState(false);
  const [status, setStatus] = useState<
    IdentityVerificationSheetStatus | undefined
  >();
  const [error, setError] = useState<StripeError | undefined>();

  const fetchOptions = async () => {
    const response = await fetchVerificationSessionParams();

    return {
      sessionId: response.id,
      ephemeralKeySecret: response.ephemeral_key_secret,
      brandLogo: Image.resolveAssetSource(logo),
    };
  };

  const present = async () => {
    setLoading(true);
    const options = await fetchOptions();
    setLoading(false);
    const { status, error } = await presentIdentityVerificationSheet(options);
    setStatus(status);
    setError(error);
  };

  const handlePress = useCallback(() => {
    present();
  }, [present]);

  const renderButton = useCallback(() => {
    if (loading) {
      return <ActivityIndicator />;
    }
    return <Button title="Verify Identity" onPress={handlePress} />;
  }, [loading, handlePress]);

  return (
    <View>
      <View>{renderButton()}</View>
      <Text>Status: {status}</Text>
    </View>
  );
}

There are two types available: StripeError and IdentityVerificationSheetStatus, you can import these in your TypeScript project directly from Stripe Identity React Native SDK:

import type {
  StripeError,
  IdentityVerificationSheetStatus,
} from '@stripe/stripe-identity-react-native';

Run the example app

  • Run this command from root folder
    • cd example && yarn
  • Install pods for iOS and update StripeIdentity
    • cd ios && pod install && pod update StripeIdentity
  • Run example app on a specific simulator/emulator from root folder
    • yarn example ios
    • or
    • yarn example android
  • Or from example folder
    • yarn ios
    • or
    • yarn android

Contributing

See the contributor guidelines to learn how to contribute to the repository.