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
The Team ID found in the Evervault Dashboard.
The App ID found in the Evervault Dashboard.
<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:
- <Card.Holder />
- <Card.Number />
- <Card.Expiry />
- <Card.ExpiryMonth /> and <Card.ExpiryYear />
- <Card.Cvc />
- <Card.Field />
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
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'.
The validation mode for the card fields. Defaults to
all.Moves focus to the next field after the current one is filled. A field's own
autoProgressprop takes precedence. Defaults tofalse.A callback function that is called whenever the card data changes.
The card holder name.
The encrypted card number. This will only be present if the number is valid.
The brand that issued the card.
The last 4 digits of the card. This will only be present if the number is valid.
The BIN for the card.
The month for the card expiry field.
The year for the card expiry field.
The encrypted card CVC.
Validation errors related to the card details.
Whether or not there are any errors shown in the component.
Whether or not all of the fields have been filled out successfully with valid values.
The payload also includes
fields, the encrypted values of the custom fields by name. A field that's empty or invalid isnull. A Card component without custom fields doesn't reportfields. Errors for custom fields are undererrors.fields, by name.A callback function that is called when a native error occurs.
Ref
The Card component exposes an imperative handle using ref.
Methods
Resets the form to its default values and state. Fields with a
defaultValuestart with it again.
<Card.Holder />
Used as a child of <Card /> to collect the name of a card holder.
Props
The placeholder text to display in the input field.
Text rendered above the field. It's also read out as the field's accessibility label.
The style of the
labeltext.Replaces the text of this field's error in the payload's
errors.A regular expression the whole name must match.
The name the field starts with. A changed
defaultValueonly 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
The placeholder text to display in the input field.
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•).Text rendered above the field. It's also read out as the field's accessibility label.
The style of the
labeltext.Moves focus to the next field after this one is filled. Overrides the Card component's
autoProgressfor this field.Replaces the text of this field's error in the payload's
errors.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
The placeholder text to display in the input field.
Text rendered above the field. It's also read out as the field's accessibility label.
The style of the
labeltext.Moves focus to the next field after this one is filled. Overrides the Card component's
autoProgressfor this field.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
The placeholder text to display in the input field. Defaults to
MMfor the month andYYfor the year.Text rendered above the field. It's also read out as the field's accessibility label.
The style of the
labeltext.Moves focus to the next field after this one is filled. Overrides the Card component's
autoProgressfor this field.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
The placeholder text to display in the input field.
If
true, all of the CVC will be obfuscated. If a string is provided, it will be used as the obfuscation character (defaults to•).Text rendered above the field. It's also read out as the field's accessibility label.
The style of the
labeltext.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
autoProgressfor this field.Replaces the text of this field's error in the payload's
errors.Makes the CVC optional. CVCs are still validated if provided. Defaults to
false.Set it to
falseto require a 4-digit CVC for American Express cards. Defaults totrue.
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
The style of the row.
Card.Rowaccepts 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
The key the field's encrypted value is reported under, in the payload's
fields.The kind of value the field takes. An
email,urlornumbervalue must be valid for its type. Every type excepttextshows a matching keyboard. Defaults totext.The value the field starts with. A changed
defaultValueonly replaces a value the user hasn't changed.Stops the user from changing the value. A read-only field is never invalid.
Rejects an empty value.
A regular expression the whole value must match. Doesn't apply to
numberfields.The minimum length of the value. Doesn't apply to
numberfields.The maximum length of the value. With
autoProgressset, focus moves to the next field after the value reaches this length.The lowest value a
numberfield takes.The highest value a
numberfield takes.The steps a
numbervalue must keep to, counted frommin.Replaces the text of the field's error in the payload's
errors.fields, for both a missing and an invalid value.Text rendered above the field. It's also read out as the field's accessibility label.
The style of the
labeltext.Moves focus to the next field after the value reaches
maxLength. Without amaxLength, the field doesn't auto-progress. Overrides the Card component'sautoProgressfor this field.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
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.
Parameters
The 3D Secure session ID.
The options for the 3DS authentication process.
If set to true (or a function that returns true), the authentication will fail if a challenge is required.
The
requestChallengeevent will be fired if the 3DS authentication process requires a challenge. If you'd like to fail the authentication, you should callpreventDefaulton the passed event.The 'success' event will be fired once the 3DS authentication process has been completed successfully. You should use this event to trigger your backend to finalize the payment. Your backend can use the Retrieve 3DS Session endpoint to retrieve the cryptogram for the session and complete the payment.
The 'failure' event will be fired if the 3DS authentication process fails. You should use this event to handle the failure and inform the user and prompt them to try again. If the user cancels the 3DS authentication process this event will be fired.
The error event will be fired if the component fails to load.
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.
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
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
The 3DS session ID. A 3DS session can be created using the Evervault API.
The options for the 3DS authentication process.
If set to true (or a function that returns true), the authentication will fail if a challenge is required.
The
requestChallengeevent will be fired if the 3DS authentication process requires a challenge. If you'd like to fail the authentication, you should callpreventDefaulton the passed event.The 'success' event will be fired once the 3DS authentication process has been completed successfully. You should use this event to trigger your backend to finalize the payment. Your backend can use the Retrieve 3DS Session endpoint to retrieve the cryptogram for the session and complete the payment.
The 'failure' event will be fired if the 3DS authentication process fails. You should use this event to handle the failure and inform the user and prompt them to try again. If the user cancels the 3DS authentication process this event will be fired.
The error event will be fired if the component fails to load.
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.