Integration Guide
This guide provides a detailed, step-by-step process for integrating Smart Fields into your payment checkout. By the end, you will be able to securely collect payment details directly within your website while Localpayment handles the sensitive data.
Prerequisites
Before you begin the integration, ensure you have the following:
API Keys: A valid API key for authenticating requests. You can use a key from either the Stage or Production environment, depending on your development phase.
Client Code: Your unique client identifier, found in your Localpayment dashboard.
Backend Endpoint: Your server must be prepared to receive a payment token from your frontend and use it to execute a transaction via the Localpayment Payins API.
Step 1: Include the Smart Fields SDK
Add the Localpayment SDK to your website by including the appropriate script tag for your environment. We provide two different environments to support your development workflow:
Use this for testing and development before going live. This environment allows you to test with simulated payments and validate your integration.
<script src="https://sdk.stage.localpayment.com/localpayment-sdk.min.js"></script>Use this for your live website when you're ready to process real payments.
<script src="https://sdk.localpayment.com/localpayment-sdk.min.js"></script>Step 2: Initialize the SDK
After successfully including the SDK, initialize it with your unique credentials. The LP constructor requires both your client code and API key to authenticate requests and configure the SDK properly.
Basic Initialization
const localpayment = LP({
clientCode: 'your_client_code', // Your client code here
apiKey: 'your_api_key' // Your secret API key for authentication
});Configuration Options
clientCode
string
Yes
Your unique merchant identifier provided by Localpayment
apiKey
string
Yes
Your secret API key for authentication requests
Step 3: Create a Session
Before creating payment fields, you must create a session. This step establishes a secure connection with Localpayment's servers and prepares the environment for card tokenization.
Step 4: Create and Mount the Payment Fields
After initializing your session, the next step is to create and mount the payment fields.
Creating Payment Fields
Use the create() method to instantiate each payment field. The method accepts a single parameter fieldType which must be one of three values: 'pan', 'cvv', or 'expiration'.
Field Types Overview
pan
Primary Account Number (card number)
Luhn algorithm, brand detection, format validation
cvv
Card Verification Value
Length validation (3-4 digits), numeric only
expiration
Expiration date
MM/YY format, future date validation
Mounting Fields to DOM
The mount() method attaches the secure iframe to your specified DOM container. The method accepts a selector string that should match the id of your container div.
HTML Container Setup
First, create container elements in your HTML:
Mounting the Fields
Step 5: Handle Field Events and Validation
Listen to events from each field to update your UI and track their validation status.
Step 6: Get Session Data
Retrieve the session data and sessionId.
Step 7: Consolidate Session
Make a POST request to the Consolidate endpoint, sending the sessionId and cardholder details.
Stage:
https://tokenization.api.stage.localpayment.com/api/tokenization/consolidateProduction:
https://tokenization.api.localpayment.com/api/tokenization/consolidate
Step 8. Use the Token
The consolidate response includes the token and card metadata (bin, brand, last4, expiration).
Your frontend should send this token to your backend, which will use it to call the Payins API and process the payment.
Example response:
Last updated
Was this helpful?