Functions
Reference for the SDK methods, types and test cards.
Call SDK methods on LemonwayTerminal. The package also exports the root component, error class and simulated cards.
import { LemonwayTerminal, LemonwayTerminalRoot, LemonwayTerminalError, SimulatedCard } from '@lemonway/terminal';SDK errors use LemonwayTerminalError.
Setup
| Function | Returns | Description |
|---|---|---|
init(config) | void | Initializes the SDK. Call it before mounting <LemonwayTerminalRoot>. See Init and connect. |
isReady() | boolean | true once the terminal is initialized. |
setLocationId(locationId) | void | Sets the location when tokenProvider does not return it. |
getLocationId() | string | undefined | The location set in init() or setLocationId(). |
Reader
| Function | Returns | Description |
|---|---|---|
connectTapToPay(options?) | Promise<Reader.Type> | Waits for the terminal to initialize, then discovers and connects the phone. |
disconnectReader() | Promise<void> | Disconnects the phone. |
status() | Promise<{ connectionStatus, connectedReader }> | Current connection status (notConnected, connecting, connected, discovering or reconnecting) and reader. notConnected and null if the terminal is not ready yet. |
discoverReaders() | Promise<void> | Advanced: discovers the phone. |
getDiscoveredReaders() | Reader.Type[] | Readers reported by discovery. The list can lag behind the discovery promise. |
connectReader(reader, options?) | Promise<Reader.Type> | Connects a discovered reader. Wait for initialization before using the two-step discovery flow. |
Payment
| Function | Returns | Description |
|---|---|---|
authorizePaymentOrder({ id, objectSecret }) | Promise<AuthorizedPayment> | Authorizes an existing Payment Order. |
getPaymentOrder({ id, objectSecret }) | Promise<PaymentOrderResult> | Reads the existing order with the public key and order secret. |
collectPayment(authorized) | Promise<PaymentResult> | Asks the customer to tap and confirms the payment. |
cancelCollectPayment() | Promise<void> | Cancels card reading. Rejects with PAYMENT_IN_PROGRESS during confirmation. |
setSimulatedCard(cardNumber) | Promise<void> | Selects a sandbox test card. Use SimulatedCard.success or SimulatedCard.declined. |
Events
| Function | Returns | Description |
|---|---|---|
on(event, callback) | () => void | Subscribes. Call the returned function to unsubscribe. |
once(event, callback) | () => void | Subscribes for the next event only. |
off(event, callback) | void | Unsubscribes 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';
simulated?: boolean; // sandbox only
};
type ConnectionTokenSession = {
secret: string;
locationId?: string;
onBehalfOf?: string;
};
type ConnectOptions = {
allowTermsAcceptance?: boolean; // iOS only, defaults to true
};
type AuthorizePaymentOrderParams = {
id: string;
objectSecret: string;
};
type AuthorizedPayment = {
paymentOrderId: string;
paymentIntentId?: string;
clientSecret: string;
objectSecret: string;
};
type CollectPaymentParams = {
clientSecret: string;
paymentOrderId: string;
objectSecret?: string;
};
type PaymentOrderResult = {
id: string;
status: string; // without the payment_order. prefix
};
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
hint?: string;
cause?: unknown;
}Reader describes the phone. deviceType and status are always set. id, serialNumber, label, batteryLevel, locationId and simulated are optional, and so is the iOS-only isCharging (a boolean).
See Error handling for the LemonwayTerminalErrorCode values and recovery actions.
TerminalEventMap maps each event name to its payload type. See Events.
Updated 8 days ago
Did this page help you?