capacitorcapacitor-community/stripe

Logo Github GitHub

IdentityVerificationSheet

IdentityVerificationSheet can use Stripe Identity. Stripe Identity lets you programmatically confirm the identity of global users so you can prevent attacks from fraudsters while minimizing friction for legitimate customers. This is a simple way.

Initialize Android

Add the following to your AndroidManifest.xml and res/values/strings.xml:

AndroidManifest.xml
+ <meta-data
+   android:name="com.getcapacitor.community.stripe.enableIdentifier"
+   android:value="@bool/enableIdentifier"/>
strings.xml
+ <bool name="enableIdentifier">true</bool>

And change base application theme to Theme.MaterialComponents.DayNight at res/values/styles.xml :

res/values/styles.xml
- <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
+ <style name="AppTheme" parent="Theme.MaterialComponents.DayNight">

parent can be any MaterialComponents. See here for other options.
All process is here: https://github.com/capacitor-community/stripe/commit/f514d893e9193bed2edbaf52c0d3ed1d534c7890

Usage

import { Stripe } from '@capacitor-community/stripe';

await Stripe.createIdentityVerificationSheet({
  ephemeralKeySecret,
  verificationId,
});
const result = await Stripe.presentIdentityVerificationSheet();

🐾 Implements Guide

1. createIdentityVerificationSheet

Props ephemeralKeySecret and verificationId is required. This requires to generate at server side. See Stripe Identity for more details.
https://stripe.com/docs/identity/verify-identity-documents?platform=ios&type=new-integration#create-a-verificationsessionhttps://stripe.com/docs/identity/verify-identity-documents?platform=ios&type=new-integration#create-a-verificationsession

import { Stripe } from '@capacitor-community/stripe';

(async () => {
  // Connect to your backend endpoint, and get every key.
  const { verficationSessionId, ephemeralKeySecret } = await this.http.post<{
    verficationSessionId: string;
    ephemeralKeySecret: string;
  }>(environment.api + 'identify', {}).pipe(first()).toPromise(Promise);

  // prepare IdentityVerificationSheet with createIdentityVerificationSheet.
  await Stripe.createIdentityVerificationSheet({
    ephemeralKeySecret,
    verificationId: verficationSessionId,
  })
})();

You can use options of CreateIdentityVerificationSheetOption on createIdentityVerificationSheet.

method createIdentityVerificationSheet(...)

createIdentityVerificationSheet(options: CreateIdentityVerificationSheetOption) => Promise<void>

Props ephemeralKeySecret and verificationId is required.

interface CreateIdentityVerificationSheetOption

Prop Type
verificationId string
ephemeralKeySecret string

2. presentIdentityVerificationSheet

When you do presentIdentityVerificationSheet method, plugin present PaymentSheet and get result. This method must do after createIdentityVerificationSheet.

(async () => {
  // present IdentityVerificationSheet and get result.
  const result = await Stripe.presentIdentityVerificationSheet()
  if (result.identityVerificationResult === IdentityVerificationSheetEventsEnum.Completed) {
    // Happy path
  }
})();

You can get IdentityVerificationSheetResultInterface from presentIdentityVerificationSheet.

method presentIdentityVerificationSheet()

presentIdentityVerificationSheet() => Promise<{ identityVerificationResult: IdentityVerificationSheetResultInterface; }>

IdentityVerificationSheetResultInterface is created from Enum of IdentityVerificationSheetEventsEnum. So you should import and check result.

type alias IdentityVerificationSheetResultInterface

IdentityVerificationSheetEventsEnum.Completed | IdentityVerificationSheetEventsEnum.Canceled | IdentityVerificationSheetEventsEnum.Failed

enum IdentityVerificationSheetEventsEnum

Members Value
Loaded "identityVerificationSheetLoaded"
FailedToLoad "identityVerificationSheetFailedToLoad"
Completed "identityVerificationSheetCompleted"
Canceled "identityVerificationSheetCanceled"
Failed "identityVerificationSheetFailed"

3. addListener

Method of IdentityVerificationSheet notify any listeners. If you want to get event of IdentityVerificationSheet process is 'Completed', you should add IdentityVerificationSheetEventsEnum.Completed listener to Stripe object:

// be able to get event of IdentityVerificationSheet
Stripe.addListener(IdentityVerificationSheetEventsEnum.Completed, () => {
  console.log('IdentityVerificationSheetEventsEnum.Completed');
});

The event name you can use is IdentityVerificationSheetEventsEnum.

enum IdentityVerificationSheetEventsEnum

Members Value
Loaded "identityVerificationSheetLoaded"
FailedToLoad "identityVerificationSheetFailedToLoad"
Completed "identityVerificationSheetCompleted"
Canceled "identityVerificationSheetCanceled"
Failed "identityVerificationSheetFailed"