Listeners object

The listeners object helps you keep track of events in the module and respond accordingly.

The following events are available:

Event Expected data Description
closeundefinedIt's triggered when the user closes a widget.
error{
name: String;
message: String;
}
Widget error message (not payment-related), see error codes.
loadedundefinedIt indicates the module is loaded with necessary data and ready to receive extra data if needed.
This event may duplicate if the user is redirected to their bank's 3-D Secure verification page.
payment-status{
status: String
payment_id: String
order_id: String
tx_id: String // if available
}
Possible statuses: 
pendingcanceledfailedsuccessfailover.
Events may not be unique for each status.
tx_id appears in the pending status.
position{
step: String
}
Notifies changes in user flow position.
rate-update{
ticker: String,
fee_percent: String,
currency_amount: String,
fee_amount: String,
commodity_amount: String,
purchase_amount: String,
miner_fee: String,
currency_miner_fee: String
}
Updates when the widget rate changes. We fix the exchange rate for 30 seconds.

Add the listeners object like this: the key is the event type, and the value is your callback function.

const widget = new WertWidget({
  ...options,
  listeners: {
    position: (data) => console.log("step:", data.step),
  },
});

To subscribe to the payment status data, you can do the following:

const widget = new WertWidget({
  ...options,
  listeners: {
    'payment-status': data => console.log('Payment status:', data)
  },
});

This will only be triggered when simulating the purchase, not in intermediary steps.