Listeners object
The listeners object allows you to listen to some events in the module and react to them.
The following events are available:
Event | Expected data | Description |
---|---|---|
close | undefined | An event raised by the module when the user closes it. |
error | { name: String message: String } | Information about an error that occurred in the module (not payment related). |
loaded | undefined | The module has the necessary data and is ready to work. In case extra data was used, it's ready to receive it. This event can be duplicated if user was redirected to their bank’s page to enter a 3-D Secure code. |
payment-status | { status: String payment_id: String order_id: String tx_id: String //if available} | Possible statuses: pending, cancelled, failed, success, failover. Event can be not unique for each status. |
position | { step: String } | Informs about the changes in user's position in the flow. |
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 } | Information on when the widget updates the rate. |
You can subscribe to any of the events' data; an example using data in step
for the position
event is displayed below:
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)
},
});
Please note, this will only be triggered when you are actually simulating the purchase, not in intermediary steps.
You can also get the list of all available events by calling the static property eventTypes
on the helper:
import WertWidget from '@wert-io/widget-initializer';
console.log(WertWidget.eventTypes);
/* console output:
[
'close',
'error',
'loaded',
'payment-status',
'position'
'rate-update',
]
*/
Updated 25 days ago
Documentation related to this page