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();| 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) | Initialization failed, for example a refused permission. |
reader.discovered | Reader[] | 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.success | PaymentResult | The payment is confirmed. |
payment.canceled | — | The payment was canceled. |
payment.error | LemonwayTerminalError | The 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.
Updated 11 days ago
Did this page help you?