Web SDK

The Lydian Web SDK (@lydianpay/sdk-web) is a drop-in checkout for the browser. It registers a <lydian-checkout> custom element and a global window.Lydian API that walks your customer through paying with a connected wallet or QR code.

This page is the library reference. For a step-by-step walkthrough, see Web Checkout; to decide between hosted and embedded checkout, see Choose Your Integration.

Installation

Install from npm, or load the pinned build from a CDN. Pin a version so an upstream release can't change your checkout unexpectedly.

npm install @lydianpay/sdk-web

With a bundler, import the package once to register the element and the global:

import '@lydianpay/sdk-web'

The SDK ships as ES modules, so a script-tag include must use type="module".

Add the checkout element

Place the <lydian-checkout> element where the checkout should render. It stays hidden until you initialize the SDK.

<lydian-checkout></lydian-checkout>

Initialize the SDK

Call window.Lydian.init(options) to render the checkout and start a payment.

window.Lydian.init({
  sandbox: true,
  dev: false,
  isEmbedded: true,
  publishableKey: '{PUBLISHABLE_KEY}',
  walletConnectProjectId: 'your-walletconnect-project-id',
  transaction: {
    amount: 2.45,
    currency: 'USD',
    descriptor: 'Order #1234',
    referenceNumber: 'your-unique-ref',
  },
  paymentSuccessListener: () => {},
  paymentFailedListener: (message) => {},
  paymentCanceledListener: () => {},
})

init options

OptionTypeRequiredDescription
publishableKeystringyesYour Lydian publishable key (pk_...).
walletConnectProjectIdstringyesYour WalletConnect (Reown) project ID, used to power wallet connections.
transactionTransactionyesThe payment to collect (see below).
devbooleanyesTarget the development environment.
sandboxbooleanyesTarget sandbox. With both dev and sandbox false, the SDK uses production.
paymentSuccessListener() => voidyesCalled when the payment completes.
paymentFailedListener(message: string) => voidyesCalled on failure, with a message.
paymentCanceledListener() => voidyesCalled when the customer cancels.
isEmbeddedbooleannoRender the checkout inline (embedded) instead of as a modal.
flowInitFlowOptionsnoPer-embed flow overrides, e.g. { walletConnect: true } to offer wallet connection alongside the QR code.

Transaction

FieldTypeRequiredDescription
amountnumberyesAmount to charge.
currency'USD' | 'TRY' | 'PHP'yesFiat currency the amount is denominated in.
referenceNumberstringyesYour unique reference for this payment.
descriptorstringnoHuman-readable description shown to the customer.

Environments

EnvironmentFlags
Productiondev: false, sandbox: false
Sandboxsandbox: true
Developmentdev: true

Updating the transaction

Before the customer pays, update the amount or currency. This also resets the checkout UI to its initial state.

window.Lydian.updateTransaction({
  amount: 1.45,
  currency: 'USD',
  descriptor: 'Order #1234',
  referenceNumber: 'your-unique-ref',
})

Listeners

Provide these callbacks in init to react to the payment outcome:

  • paymentSuccessListener() — the payment completed.
  • paymentFailedListener(message) — the payment failed; message describes why.
  • paymentCanceledListener() — the customer cancelled.

Supported assets & networks

Which assets appear at checkout is controlled by your Lydian account configuration; the SDK renders whatever your account has enabled across the supported networks.