Functions

Reference of every function and type of the SDK.

Every function is on the LemonwayTerminal object:

import { LemonwayTerminal, LemonwayTerminalRoot, LemonwayTerminalError } from '@lemonway/terminal';

All functions throw a LemonwayTerminalError.

Setup

FunctionReturnsDescription
init(config)voidInitializes the SDK. Call it before mounting <LemonwayTerminalRoot>. See Init and connect.
isReady()booleantrue once the terminal is initialized.
setLocationId(locationId)voidSets the location when tokenProvider does not return it.
getLocationId()string | undefinedThe location set in init() or setLocationId().

Reader

FunctionReturnsDescription
connectTapToPay()Promise<Reader>Discovers and connects the phone.
disconnectReader()Promise<void>Disconnects the phone.
status()Promise<{ connectionStatus, connectedReader }>Current connection status and reader.
discoverReaders()Promise<void>Advanced: discovers the phone.
getDiscoveredReaders()Reader[]Advanced: readers found by discoverReaders().
connectReader(reader)Promise<Reader>Advanced: connects a discovered reader.

Payment

FunctionReturnsDescription
authorizePaymentOrder({ id, objectSecret })Promise<AuthorizedPayment>Authorizes a Payment Order created by your backend.
collectPayment(authorized)Promise<PaymentResult>Asks the customer to tap and confirms the payment.
cancelCollectPayment()Promise<void>Cancels the running payment until the card is read.

Events

FunctionReturnsDescription
on(event, callback)() => voidSubscribes. Call the returned function to unsubscribe.
once(event, callback)() => voidSubscribes for the next event only.
off(event, callback)voidUnsubscribes a callback passed to on().

See Events for the event list.


Types

type LemonwayTerminalConfig = {
  env: 'sandbox' | 'production';
  publicKey: string; // pk_…
  tokenProvider: () => Promise<string | ConnectionTokenSession>;
  shopId?: string; // sh_…
  locationId?: string; // tml_…
  onBehalfOf?: string; // acct_…, iPhone only
  logLevel?: 'none' | 'verbose';
};

type ConnectionTokenSession = {
  secret: string;
  locationId?: string;
  onBehalfOf?: string;
};

type AuthorizedPayment = {
  paymentOrderId: string;
  paymentIntentId?: string;
  clientSecret: string;
};

type PaymentResult = {
  paymentOrderId?: string;
  paymentIntentId: string;
  status?: string; // 'succeeded'
  amount: number; // in cents
  currency: string; // 'eur'
};

class LemonwayTerminalError extends Error {
  code: LemonwayTerminalErrorCode;
  status?: number; // HTTP status from the PayGreen API
  cause?: unknown;
}

Reader describes the connected phone (id, serial number, device type).


Did this page help you?