The Localpayment Object

The Localpayment object is your entry point to the Smart Fields SDK. It provides methods to create payment fields, handle tokens, and manage the payment flow. This object is created by calling the LP constructor with your public key.

Initialization

To start using Localpayment Smart Fields, you must first initialize the LP object with your public API key. This creates the main interface for all Smart Fields operations.

const localpayment = LP({
    clientCode: 'your_client_code', // Your client code here 
    apiKey: 'your_api_key' // Your secret API key for authentication
});

Configuration Options

ParameterTypeRequiredDescription
clientCodestringYesYour unique merchant identifier provided by Localpayment.
apiKeystringYesYour secret API key for authentication requests.

Methods

createSession()

Creates a new session with the Localpayment backend. This session is valid for a limited time (10 minutes) and must be created before mounting any payment fields.

  • Returns: Promise<void>
  • Throws: An error if the network request fails or the credentials are invalid.

Example

create(fieldType)

Creates an instance of a secure payment field. The field is not visible until it is mounted.

  • Returns: LPField instance.

Parameters

ParameterTypeRequiredDescription
fieldTypeStringYesThe type of field to create. Accepted values: pan, cvv, expiration.

Example

// Create field instances
const panField = localpayment.create('pan');
const cvvField = localpayment.create('cvv');
const expirationField = localpayment.create('expiration');

getSessionData()

Retrieves the data for the current active session, including the session ID and access token. This is essential for the token consolidation step on your backend.

  • Returns: Object containing session data.
    • sessionId (String): The unique identifier for the current session.
    • accessToken (String): The short-lived token used for authenticating the consolidation request.
    • clientCode (String): The client code used to initialize the SDK.
    • apiKey (String): The API key used to initialize the SDK.

Example

const sessionData = localpayment.getSessionData();
// Example response: { sessionId: 'd069f375-c07c-4ac8-9f8a-6abbeb31f459', accessToken: 'eyJhbGci...', clientCode: '0001', apiKey: 'IIBCgKCAQEAtI...' }