React
Getting Started
Our React SDK is distributed via npm and can be installed using your preferred package manager.
Once installed, Initialize the SDK by wrapping your application with the EvervaultProvider component.
Encrypting Data
Once you've added the <EvervaultProvider>, you can access the useEvervault() hook in its children. The useEvervault() hook returns an initialized instance of the JavaScript SDK, which includes the encrypt() function. The encrypt() function can can be used to encrypt plaintext data in your application.
Components
EvervaultProvider
Sets up a client for interacting with Evervault. You must provide a teamId and appId to the provider.
Props
The unique identifier for your Team.
The unique identifier for your App.
A callback function that is called if the SDK fails to load.
Card
The Card Component allows you to collect and encrypt card data in a completely PCI-compliant environment. See Card Collection for more information.
Props
The theme to use for the Card. See the styling section for more information.
If set to true, the component will display icons for the detected card brand. You can customize icons by passing an object with the brand as the key and src URL as the value.
If set to true, the component will automatically focus the first field when the component is mounted.
Allows you to configure the fields displayed in the component. Possible values are
name,number,expiry, andcvc. By default only number, expiry and cvc will be shown.Sets the
typeattribute of the CVC field topasswordin order to visually redact the CVC field..Triggered whenever the component's state is updated.
Triggered when the component is complete.
Triggered when the component is swiped.
Triggered when the component has loaded and is ready to be used.
Triggered when the component encounters an error and fails to load.
Allows you to customize the translations of the component.
ThreeDSecure
The ThreeDSecure component can be used instead of the useThreeDSecure hook when you want more control over how and where the 3D Secure iframe is displayed. In order to use the component you must first create a 3D Secure session on your backend.
Props
The 3D Secure session ID. A 3D Secure session can be created using the API.
Allows you to customize the appearance of the component. Note: You can't customize the appearance of the iframe content itself. This is controlled by the card issuer.
This size of the 3D Secure iframe. Card issuers are required to support content at 250x400, 390x400, 500x600, 600x400. The default size is 500x600.
If set to true, the component will fail 3DS authentication when a challenge is requested and no challenge will be shown. Alternatively, you can provide a function which will be called when a challenge is requested. If the function returns true 3DS authentication will fail, if it returns false the challenge will be shown.
The 'success' event will be fired once the 3D Secure 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 3D Secure authentication process fails. You should use this event to handle the failure and inform the user and prompt them to try again.
The error event will be fired if the component fails to load.
The ready event will be fired once the component has fully loaded and is ready to be displayed. This is often used to show a loading state while the component loads.
Reveal
The Reveal component allows you to display previously encrypted card data to your users in plaintext in a secure iframe hosted by Evervault. See Card Reveal for more information.
Props
The request to use to fetch the encrypted data.
Triggered when the component has fully loaded and is ready to be shown.
Triggered when the component fails to load.
Reveal.Text
Creates a Reveal Text consumer component. The Reveal Text consumer allows you to render a selected field from the request response. This component must be rendered as a child of the Reveal component.
Props
Allows you to completely customize the appearance of the component.
A JSON path selector for the response field you want to display.
Allows you to use regex matching to format the field value.
Reveal.CopyButton
Creates a Reveal Copy Button consumer component. This renders a button which when clicked will copy a response field to the users clipboard. This component must be rendered as a child of the Reveal component.
Pin
Creates a Pin component which allows you to collect and encrypt pin numbers in a completely PCI-compliant environment.
Props
The theme to use for the Pin.
If set to true, the component will automatically steal focus when it mounts.
Change the length of the pin number.
If set to 'alphanumeric' the pin number will also accept letters as input.
Triggered whenever the component's state is updated.
Triggered when the pin number field has been fully filled out by the user.
Triggered when the component has fully loaded and is ready to be shown.
Triggered when the component fails to load. If you want to respond to validation errors you should use the change event instead.
Hooks
useEvervault
The useEvervault hook is accessible in children of the EvervaultProvider, and returns an initialized instance of the Evervault JavaScript SDK. One of the functions included in the returned object is encrypt(), which can be passed any plaintext data structure.
.encrypt()
Encrypts data using Evervault Encryption. Evervault Strings can be used across all of our products. It is accessible on the returned value from the useEvervault() hook. To encrypt data using the React.js SDK, simply pass a String or an Object into the evervault.encrypt() function.
The encrypted data can be passed to your server and stored in your database as normal. It can also be used with any of Evervault’s other services.
.decrypt()
Allows you to decrypt a previously encrypted piece of data using a client side token. The token is a time bound token for decrypting data. The token can be generated using our backend SDKs or through our REST API.
The payload must be the same payload that was used to create the token and expires in a maximum of 10 minutes depending on the expiry set when creating the token.
The payload can be any String or Object and it will be returned, decrypted, in the same form.
Parameters
A valid client-side token with permissions to decrypt the data.
The encrypted data to decrypt.
useThreeDSecure
The useThreeDSecure hook can be used in combination with the Evervault API to perform 3D Secure authentication. In order to use the hook you must first create a 3D Secure session on your backend and pass it to your frontend. The hook will manage displaying the 3D Secure iframe inside of a modal window and handle the authentication process.
Note: If you want more control over how and where the 3D Secure iframe is displayed you can use the ThreeDSecure component instead.
See 3D Secure for more information.
Options
Allows you to customize the appearance of the component. Note: You can't customize the appearance of the iframe content itself. This is controlled by the card issuer.
This size of the 3D Secure iframe. Card issuers are required to support content at 250x400, 390x400, 500x600, 600x400. The default size is 500x600.
If set to true, the component will fail 3DS authentication when a challenge is requested and no challenge will be shown. Alternatively, you can provide a function which will be called when a challenge is requested. If the function returns true 3DS authentication will fail, if it returns false the challenge will be shown.
threeDSecure.start()
The start function is used to begin the 3D Secure authentication process.
Parameters
The 3D Secure session ID. A 3D Secure session can be created using the API.
The 'success' event will be fired once the 3D Secure 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 3D Secure authentication process fails. You should use this event to handle the failure and inform the user and prompt them to try again.
The error event will be fired if the component fails to load.
The ready event will be fired once the component has fully loaded and is ready to be displayed. This is often used to show a loading state while the component loads.
Content Security Policy (CSP)
If you are using a Content Security Policy (CSP), you will need to add the following directives to allow the Evervault SDK to function correctly.