Install Secure Fields
You can install Secure Fields as the JavaScript SDK (@gr4vy/secure-fields, from npm
or the CDN script) or the React SDK (@gr4vy/secure-fields-react, from npm), which wraps
the JavaScript SDK. Both run in the buyer’s browser. Install from npm when you want to pin
a version.
When using the CDN the latest version of the SDK is always pulled straight
from the server for every request. You can’t pin a version of the CDN script.
Content Security Policy
If your checkout page sets a Content Security Policy (CSP), allow the Gr4vy hosts that Secure Fields uses. Each host is built from your Gr4vy ID, for examplesecure-fields.{gr4vyId}.gr4vy.app in production and
secure-fields.sandbox.{gr4vyId}.gr4vy.app in sandbox.
The wildcard
https://*.gr4vy.app covers all of these hosts in both environments. If you only set
default-src, add the hosts there instead.
Initializing secure fields
With Secure Fields installed it’s now possible to initialize the connection to your instance. Secure Fields expects your Gr4vy ID (gr4vyId), the
environment, and a checkout session ID.
The instance ID is the unique identifier for the deployment of the system and is included in every API call.
Together with the environment (sandbox or production) it is used to connect to the right APIs, as well as dashboard.The possible values for your ID are one of
wpay, wpay1, wpay2, or wpay3. You are informed
in which instance your account has been set up.Adding each of the individual fields
Next, add any of the 3 individual fields to the form. Mix and match these with custom forms, and add custom labels.When not using the React SDK, every field Embed needs to be attached to an HTML element.
In this case, the fields were attached to
<input> fields. The fields can be attached to
any element using a querySelector-compatible query.Vaulting the card data
Secure Fields handles the PCI-compliant submission of all the card data to the servers. Once the form is ready, use the submit feature of Secure Fields to vault the data. Thecard-vault-success event
notifies you when the data has been submitted successfully, and
card-vault-failure when it hasn’t.
Summary
In this step you:- Installed and initialized Secure Fields.
- Rendered each of the individual fields in a custom UI
- Submitted the data to the vault and listened for events