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. Use events for UI feedback and verify the captured Payment Order before closing the sale.
Subscribe
const unsubscribe = LemonwayTerminal.on('payment.success', (payment) => {
showSuccess(payment.amount, payment.currency);
});
// Later, for example when the screen unmounts
unsubscribe();| Function | Description |
|---|---|
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
| Event | Payload | When |
|---|---|---|
terminal.ready | — | The terminal is initialized. You can connect. |
terminal.error | LemonwayTerminalError | Initialization failed. Use the specific error code to guide recovery. |
reader.discovered | Reader[] | The phone was found as a reader. |
reader.connected | — | The phone is connected, including after an automatic reconnection. |
reader.disconnected | — | The phone was disconnected, or its connection attempt or automatic reconnection ended without a connection. |
reader.configuring | { progress: number } | Tap to Pay is being set up on the phone. progress goes from 0 to 1. |
reader.configured | — | The setup is finished. |
payment.processing | — | collectPayment() started. Show the tap screen. |
payment.success | PaymentResult | The payment is confirmed. |
payment.canceled | — | Card reading was canceled before confirmation. |
payment.error | LemonwayTerminalError | Collection failed, for example because the card was declined or sandbox mode detection failed. |
payment.unknown | LemonwayTerminalError | The payment outcome is uncertain. Check the same Payment Order before retrying. |
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 -->|confirmed| C[payment.success]
B -->|decline or other failure| D[payment.error]
B -->|card reading canceled| E[payment.canceled]
B -->|outcome uncertain| F[payment.unknown]
After payment.processing, the SDK emits one outcome event. The promise resolves with the payment on success and rejects with LemonwayTerminalError otherwise. Calls rejected before collection starts emit no payment events. On payment.unknown, check the same Payment Order.
Updated 8 days ago
Did this page help you?