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
In your JavaScript application, create an instance of theYuno class by providing a valid PUBLIC_API_KEY:
Step 3: Start the checkout process
Use thesecureFields function and provide the necessary configuration parameters:
The essential parameters are the countryCode, which determines the country for which the payment process is configured, and checkoutSession, which refers to the current payment’s checkout session.
Parameters
Configure the secure fields with the following options:Step 4: 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:
Validation behaviour (
validationType): Use options.validationType to control when the field is validated: 'on_change' validates as the user types; 'on_blur' validates when the field loses focus; 'on_blur_full' runs full validation on blur. Default: in checkout flows, 'on_blur_full'. Outside checkout flows there is no default — specify validationType if you want validation. If you previously used validateOnBlur: true, migrate to validationType: 'on_blur' or, for full validation on blur, validationType: 'on_blur_full'.
Once you have set the parameter, you will render the created Secure Field with the render function by selecting an HTML element using a valid CSS selector (#, ., [data-*]).
Example (three secure-fields):
Data available in onChange callback
When theonChange callback is triggered, the data parameter contains:
- Card IIN Information: Card issuer details including scheme, brand, type, and issuer information
- Installment Plans: Available installment options for the account if configured
- Loading States:
isCardIINLoadingandisInstallmentLoadingboolean flags
Step 5: Generate an OTT (one-time token)
With all user information in hand, start the payment by creating a One-Time Token (OTT) using the functionsecureFields.generateToken. As it is an asynchronous function, use try/catch to handle triggered errors. When you use a vaulted token with the SDK, all the fraud information from the providers you configured in your card routing is collected and attached to the one-time token; you can add installment information and a security code if the provider requires it.
Generate token parameters
secureFields.generateTokenWithInformation to receive any additional info the customer gives at checkout, such as installments or document type/number. Create a one-time token with error handling:
Step 6: Create the Payment
After receiving the one-time token, you can create the payment using one of the following options:- Create the payment using the Create Payment endpoint.
- Use the
createPaymentfunction.
oneTimeToken and the checkoutSession. As creating the payment may raise errors, Yuno recommends you use a try/catch function here.
Check payment status with yuno.mountStatusPayment. Example (createPayment and mountStatusPayment):
Payment creation flow
- Create Payment: Use the
createPaymentfunction with the one-time token and checkout session - Check SDK Action: If
sdk_action_requiredis true, callyuno.continuePayment()for additional customer actions - Mount Status: If no SDK action is required, use
yuno.mountStatusPayment()to display payment status