Skip to main content
The JavaScript SDK (@lyel/lyel-pay) is designed for browser environments. It orchestrates the full payment flow — intention, OTP, verification, and charge — from your web frontend.

Installation

Supports CommonJS and ESM.

Initialization

ParameterTypeRequiredDescription
apiKeystringYour merchant API key
env'production' | 'sandbox'Defaults to 'production'

Payment flow

All transactions follow the same four steps:

Methods

createIntention(operation, params)

Creates a transaction intention. The intention reserves the operation and returns an ID used in the final charge step.
Operation types:
ConstantValueDescription
OPERATION_TYPE_ENDPOINTS.PAYMENT'payment'Customer pays merchant
OPERATION_TYPE_ENDPOINTS.DEPOSIT'deposit'Cash-in to wallet
OPERATION_TYPE_ENDPOINTS.WITHDRAW'withdraw'Cash-out from wallet
OPERATION_TYPE_ENDPOINTS.TRANSFER'transfer'Wallet to wallet

initOtp(params)

Sends a one-time password to the user via SMS or email. Call this after creating the intention.

verifyOtp(params)

Validates the OTP entered by the user. On success, Lyel Pay stores an authorization token in the SDK instance for use in charge().

charge(params)

Executes the transaction using the stored authorization token.

getToken()

Returns the current OTP authorization token held in memory (or null if not yet verified).

Error handling

The SDK extends EventEmitter. Listen for errors globally:
Or handle them per call using try/catch:
See Error Codes for the full list of typed error codes.

TypeScript types


Notes

  • The OTP token is stored in memory in the LyelPay instance — it is not persisted to localStorage or cookies.
  • Create a new LyelPay instance per payment session, or call a custom logout() to clear the stored token between transactions.
  • For server-initiated payments, use the Node.js SDK instead.