React Native

Installation


Our React Native SDK is distributed via npm, and can be installed using your preferred package manager. The react-native-webview package is a peer dependency and will need to be installed as well.

Compatibility

Our React Native SDK requires React Native 0.76 or higher. We recommend upgrading if possible.

If you are unable to upgrade, you will need to use our legacy React Native SDK.

Linking


This package supports autolinking.

Expo


This library has native code, so it does not work with Expo Go. However, you can install it using a custom development build.

Proguard Rules


If you are using code shrinking with ProGuard for Android, you will need to specify exclusion rules for several Evervault dependencies. The required ProGuard rules can be found in our Android SDK docs.

Quickstart


Add the EvervaultProvider


Wrap your app with the <EvervaultProvider /> component and pass your Team and App ID as props.

Your Team and App ID can be found in the Evervault Dashboard.

Collect Card Data


You can use the <Card /> component to collect card data securely.

If you don't need to collect all four types of supported Card Data, you can omit the relevant components.

However, the components cannot be used individually outside of the <Card /> component.

Perform 3D Secure Authentication


You can use the <ThreeDSecure /> component in combination with the Evervault API to perform 3DS authentications.

In order to use the 3DS component you must first create a 3DS session on your backend and pass it to your frontend. You can then use the <ThreeDSecure.Frame /> component to display the 3DS webview.

Components


<EvervaultProvider />


Wraps your app in a new Evervault context, scoped to a specific team and app.

Props

<Card />


The Card component is used to securely collect cardholder data from your users.

It is a wrapper component that manages the state of the child input components:

You don't have to render all of the available child input components as children. For example, if you only need to collect a card number and expiry, you can omit the Card.Cvc and Card.Holder components. Use <Card.Row /> to place fields side by side. Each field accepts every TextInput prop except value, onChange, and onChangeText.

With autoProgress set, focus moves to the next field after the current one is filled. Focus follows the order the fields first render in, and a field rendered later is added to the end.

Declare each field once. A second field of the same kind, such as another Card.Number, isn't rendered and logs a warning. You can't combine Card.Expiry with Card.ExpiryMonth and Card.ExpiryYear, and the month and year must be declared together. Otherwise, an error is logged and the new layout isn't rendered.

The onComplete field will be true once all rendered fields are filled out successfully with valid values.

Props

  • acceptedBrandsCardBrandName[]

    An array of card brands that are accepted. If not provided, all brands are accepted. Possible values are 'american-express', 'visa', 'mastercard', 'discover', 'jcb', 'diners-club', 'unionpay', 'maestro', 'mir', 'elo', 'hipercard', 'hiper', 'szep', 'uatp', 'rupay'.

  • defaultValuesCardForm

    Default values for the card fields.

  • validationMode'onChange' | 'onBlur' | 'onTouched' | 'all'

    The validation mode for the card fields. Defaults to all.

  • autoProgressboolean

    Moves focus to the next field after the current one is filled. A field's own autoProgress prop takes precedence. Defaults to false.

  • onChange(payload: CardPayload) => void

    A callback function that is called whenever the card data changes.

    The payload also includes fields, the encrypted values of the custom fields by name. A field that's empty or invalid is null. A Card component without custom fields doesn't report fields. Errors for custom fields are under errors.fields, by name.

  • onError(error: Error) => void

    A callback function that is called when a native error occurs.

Ref


The Card component exposes an imperative handle using ref.

Methods
  • reset()() => void

    Resets the form to its default values and state. Fields with a defaultValue start with it again.

<Card.Holder />


Used as a child of <Card /> to collect the name of a card holder.

Props

  • placeholderstring

    The placeholder text to display in the input field.

  • labelstring

    Text rendered above the field. It's also read out as the field's accessibility label.

  • labelStyleStyleProp<TextStyle>

    The style of the label text.

  • errorMessagestring

    Replaces the text of this field's error in the payload's errors.

  • patternstring

    A regular expression the whole name must match.

  • defaultValuestring

    The name the field starts with. A changed defaultValue only replaces a name the user hasn't changed.

The cardholder name has no fixed length, so it never auto-progresses.

<Card.Number />


Used as a child of <Card /> to collect the card number.

Props

  • placeholderstring

    The placeholder text to display in the input field.

  • obfuscateValueboolean | string

    If true, all but the first 6 characters of the card number will be obfuscated. If a string is provided, it will be used as the obfuscation character (defaults to •).

  • labelstring

    Text rendered above the field. It's also read out as the field's accessibility label.

  • labelStyleStyleProp<TextStyle>

    The style of the label text.

  • autoProgressboolean

    Moves focus to the next field after this one is filled. Overrides the Card component's autoProgress for this field.

  • errorMessagestring

    Replaces the text of this field's error in the payload's errors.

  • unsupportedBrandMessagestring

    Replaces the error text for a card brand that isn't in acceptedBrands.

<Card.Expiry />


Used as a child of <Card /> to collect the expiry date of a card.

Props

  • placeholderstring

    The placeholder text to display in the input field.

  • labelstring

    Text rendered above the field. It's also read out as the field's accessibility label.

  • labelStyleStyleProp<TextStyle>

    The style of the label text.

  • autoProgressboolean

    Moves focus to the next field after this one is filled. Overrides the Card component's autoProgress for this field.

  • errorMessagestring

    Replaces the text of this field's error in the payload's errors.

<Card.ExpiryMonth /> and <Card.ExpiryYear />


Used as children of <Card /> to collect the expiry date as two separate fields. Use them instead of Card.Expiry, not alongside it.

Both fields write the same expiry, but the payload reports a single card.expiry, and an invalid date is reported under errors.expiry. The date is checked when either field loses focus, except when focus moves to the other field while it's still empty.

The month accepts 01 to 12. A four-digit year, such as one filled in by autofill, is shortened to its last two digits.

Props

  • placeholderstring

    The placeholder text to display in the input field. Defaults to MM for the month and YY for the year.

  • labelstring

    Text rendered above the field. It's also read out as the field's accessibility label.

  • labelStyleStyleProp<TextStyle>

    The style of the label text.

  • autoProgressboolean

    Moves focus to the next field after this one is filled. Overrides the Card component's autoProgress for this field.

  • errorMessagestring

    Replaces the text of the expiry's error in the payload's errors. Either field can set it. If both do, the field declared later is used.

<Card.Cvc />


Used as a child of <Card /> to collect the CVC code of a card.

Props

  • placeholderstring

    The placeholder text to display in the input field.

  • obfuscateValueboolean | string

    If true, all of the CVC will be obfuscated. If a string is provided, it will be used as the obfuscation character (defaults to •).

  • labelstring

    Text rendered above the field. It's also read out as the field's accessibility label.

  • labelStyleStyleProp<TextStyle>

    The style of the label text.

  • autoProgressboolean

    Moves focus to the next field after this one is filled. The CVC advances after the max number of digits are entered (the max depends on the card brand). Overrides the Card component's autoProgress for this field.

  • errorMessagestring

    Replaces the text of this field's error in the payload's errors.

  • optionalboolean

    Makes the CVC optional. CVCs are still validated if provided. Defaults to false.

  • allow3DigitAmexboolean

    Set it to false to require a 4-digit CVC for American Express cards. Defaults to true.

The CVC is validated against the card number, so its required length depends on the card brand.

<Card.Row />


Used as a child of <Card /> to place fields side by side. Each child takes an equal share of the row's width.

Props

  • styleStyleProp<ViewStyle>

    The style of the row. Card.Row accepts every View prop.

<Card.Field />


Used as a child of <Card /> to collect your own, non-card data, such as a postcode or an email address. The value is encrypted and reported in the payload's fields, under the field's name.

A field that's empty or invalid is reported as null, and its error is reported under errors.fields, following the Card component's validationMode. The default error messages are This field is required and Please enter a valid value. A second field with the same name isn't rendered and logs a warning. A field without a name isn't rendered and also logs a warning. Changing a field's validation props clears its value and its error.

Props

  • nameRequiredstring

    The key the field's encrypted value is reported under, in the payload's fields.

  • type'text' | 'email' | 'tel' | 'url' | 'number'

    The kind of value the field takes. An email, url or number value must be valid for its type. Every type except text shows a matching keyboard. Defaults to text.

  • defaultValuestring

    The value the field starts with. A changed defaultValue only replaces a value the user hasn't changed.

  • readOnlyboolean

    Stops the user from changing the value. A read-only field is never invalid.

  • requiredboolean

    Rejects an empty value.

  • patternstring

    A regular expression the whole value must match. Doesn't apply to number fields.

  • minLengthnumber

    The minimum length of the value. Doesn't apply to number fields.

  • maxLengthnumber

    The maximum length of the value. With autoProgress set, focus moves to the next field after the value reaches this length.

  • minstring

    The lowest value a number field takes.

  • maxstring

    The highest value a number field takes.

  • stepstring

    The steps a number value must keep to, counted from min.

  • errorMessagestring

    Replaces the text of the field's error in the payload's errors.fields, for both a missing and an invalid value.

  • labelstring

    Text rendered above the field. It's also read out as the field's accessibility label.

  • labelStyleStyleProp<TextStyle>

    The style of the label text.

  • autoProgressboolean

    Moves focus to the next field after the value reaches maxLength. Without a maxLength, the field doesn't auto-progress. Overrides the Card component's autoProgress for this field.

  • placeholderstring

    The placeholder text to display in the input field.

<ThreeDSecure />


The ThreeDSecure component is used to provide access to the 3DS authentication process.

This component allows you to use the <ThreeDSecure.Frame /> component to display the 3DS webview. Any custom components you want to display alongside the 3DS webview should be wrapped in the ThreeDSecure component.

It should be used in combination with the useThreeDSecure hook.

Props

  • stateRequiredThreeDSecureState

    The 3DS state object returned by the useThreeDSecure hook.

<ThreeDSecure.Frame />


The ThreeDSecure.Frame component is used to display the 3DS webview, which will handle the authentication process.

If the user closes the frame before completion, you will need to use the cancel() method (from the useThreeDSecure hook) to properly close the webview and clean up the session.

Props

  • styleStyleProp<ViewStyle>

    Style applied to the WebView container.

Parameters
  • sessionRequiredstring

    The 3D Secure session ID.

  • optionsThreeDSSessionOptions

    The options for the 3DS authentication process.

Hooks


useEvervault


The useEvervault hook is used to access the current Evervault scope in context.

Any component that uses this hook must be wrapped in the <EvervaultProvider /> component.

Returns


encrypt

Encrypts the provided data using native encryption modules and the Evervault API.

Parameters
  • dataRequiredstring | number | boolean | object | array

    The data to encrypt.

useThreeDSecure


The useThreeDSecure hook is used to manage the 3DS authentication process.

The hook returns an object with start() and cancel() methods. The returned object should be used with the <ThreeDSecure /> component.

Options

  • failOnChallengeboolean | () => Promise<boolean>

    If set to true (or a function that returns true), the authentication will fail if any sessions require a challenge. Can be overridden on a per-session basis by the failOnChallenge option passed to the start() method.

Returns


start

The start function is used to kick off the 3DS authentication process.

Parameters
  • sessionIdRequiredstring

    The 3DS session ID. A 3DS session can be created using the Evervault API.

  • optionsThreeDSSessionOptions

    The options for the 3DS authentication process.

cancel

The cancel() function is used to cancel the ongoing 3DS authentication process. This can be particularly useful for canceling a session when a custom cancel button is triggered.

session

The current ThreeDSecureSession object, or null if no session was created.

isVisible

A boolean indicating whether the 3DS webview should currently be rendered. Use this to conditionally display the ThreeDSecure component and its children.

V2 Migration Guide


If your app currently uses the older @evervault/evervault-react-native package, you can follow our migration guide to upgrade to the new package.