Events

Update your UI from terminal, reader and payment events.

The SDK emits events so your UI can follow the terminal, the reader and the current payment. They are for the UI only: confirm payments from the webhook.

Subscribe

const unsubscribe = LemonwayTerminal.on('payment.success', (payment) => {
  showSuccess(payment.amount, payment.currency);
});

// Later, for example when the screen unmounts
unsubscribe();
FunctionDescription
on(event, callback)Subscribes. Returns a function that unsubscribes.
once(event, callback)Subscribes for the next event only. Returns a function that unsubscribes.
off(event, callback)Unsubscribes a callback passed to on(). For once(), use the returned function.

An error thrown inside a callback is ignored and never changes the SDK's result.


Event list

EventPayloadWhen
terminal.ready—The terminal is initialized. You can connect.
terminal.errorLemonwayTerminalError (INITIALIZATION_FAILED)Initialization failed, for example a refused permission.
reader.discoveredReader[]The phone was found as a reader.
reader.connected—The phone is connected, including after an automatic reconnection.
reader.disconnected—A connected phone was disconnected.
payment.processing—collectPayment() started. Show the tap screen.
payment.successPaymentResultThe payment is confirmed.
payment.canceled—The payment was canceled.
payment.errorLemonwayTerminalErrorThe payment failed. See Error handling.

terminal.ready fires when initialization completes. If your screen subscribes later, check LemonwayTerminal.isReady() too.


Payment events in order

flowchart LR
    A[collectPayment] --> B[payment.processing]
    B --> C{Customer taps}
    C -->|accepted| D[payment.success]
    C -->|declined or failed| E[payment.error]
    C -->|cancelCollectPayment| F[payment.canceled]

Once collectPayment() has started, it emits payment.processing, then exactly one of payment.success, payment.error or payment.canceled. Its promise settles the same way, so you can use either the events or the promise. A call refused upfront (INVALID_PARAMS, PAYMENT_IN_PROGRESS) emits nothing.


Did this page help you?