Step 1: Include the library in your project
Before proceeding with the secure-fields implementation, see the SDK Integration overview for detailed instructions on how to properly integrate the SDK into your project. The integration guide provides three flexible methods:- Direct HTML script inclusion
- Dynamic JavaScript injection
- NPM module installation
Step 2: Initialize secure fields with the public key
Get aYuno instance class in your JavaScript application with a valid PUBLIC_API_KEY:
Step 3: Create a customer session and an enrollment payment method object
Create a customer session and a payment method object to use in the setup of your secure fields integration for enrollment. While creating the payment method object, define which one will be available for your customer to enroll (in the case of secure fields, only CARD is available). To verify cards through a zero-value authorization before enrolling a customer, include theverify structure when defining the payment method object for the customer session.
Step 4: Start the enrollment process
Next, you have to create a configuration object. The essential parameters are thecountryCode, which determines the country for which the enrollment process is configured, and customerSession, which refers to the current enrollment’s customer session.
Parameters
Configure the secure fields with the following options:| Parameter | Description |
|---|---|
countryCode | This parameter specifies the country for which the payment process is being set up. Use an ENUM value representing the desired country code. You can find the full list of supported countries and their corresponding codes on the Country Coverage page. |
customerSession | Refers to the current enrollment’s customer session. Example: '438413b7-4921-41e4-b8f3-28a5a0141638' |
Step 5: Mount the secure-fields
After defining the parameters, define, configure, and mount the secure-fields. For each field, setname and options in secureFields.create.
Configurations:
| Parameters | Description |
|---|---|
name | The available names for field names are cvv, pan, or expiration. |
options.placeholder | Default placeholder for the field. |
options.styles | Additional CSS styles for the current field. |
options.label | Field visible label. |
options.showError | Defines if errors will be shown. Available options are true and false. |
options.onChange | An auxiliary function that can be configured and will run when the field content changes. Indicates if the fields have errors. |
options.onBlur | An auxiliary function that can be configured and will run when blurring from the input. |
options.validateOnBlur | Change the validation behavior, improving the user experience by providing validation feedback after the field loses focus. It is an optional parameter that is false as default. |
options.onFocus | An auxiliary function that can be configured and will run when focusing on the input. |
options.onRenderedSecureField | An auxiliary function that can be configured and will run when the element finishes rendering |
options.errorMessage | This allows for the definition of the field’s error message. |
render function by selecting an HTML element using a valid CSS selector (#, ., [data-*]).
Example (three secure-fields):
secureNumber object before creating the vaulted_token and ignore the secureExpiration and secureCvv objects.
After they are mounted, the three secure fields will be shown:
Step 6: Create Vaulted Token
To enroll, create a Vaulted Token:secureFields.generateVaultedTokenWithInformation to receive the full enrollment response. Generate a vaulted token with customer information: