@lyel/lyel-pay) is designed for browser environments. It orchestrates the full payment flow — intention, OTP, verification, and charge — from your web frontend.
Installation
Initialization
| Parameter | Type | Required | Description |
|---|---|---|---|
apiKey | string | ✅ | Your 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.
| Constant | Value | Description |
|---|---|---|
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 extendsEventEmitter. Listen for errors globally:
TypeScript types
Notes
- The OTP token is stored in memory in the
LyelPayinstance — it is not persisted tolocalStorageor cookies. - Create a new
LyelPayinstance per payment session, or call a customlogout()to clear the stored token between transactions. - For server-initiated payments, use the Node.js SDK instead.