Buy widget: events
The buy widget emits events that your application can listen to. Use the native window.addEventListener to handle them:
window.addEventListener('EVENT_NAME', (event) => { // The data sent by the widget is in event.detail});Replace EVENT_NAME with the event names described below.
Order confirmed
Section titled “Order confirmed”Emitted when the user confirms their order and is about to be redirected to the payment page.
Event name: btcdirect-embeddable-fiat-to-coin-order-confirmed
// event.detail:{ currencyCode: 'iso:EUR', exchangeAmount: 100, orderId: '123456789'}| Field | Description |
|---|---|
currencyCode | The fiat currency code |
exchangeAmount | The fiat amount being paid |
orderId | The order ID |
Wallet confirmation requested
Section titled “Wallet confirmation requested”Emitted when walletConfirmationRequired is set to true in the init call. Your application should verify the wallet address (e.g. on a hardware wallet) and then confirm or cancel.
Event name: btcdirect-embeddable-wallet-address-confirmation-requested
// event.detail:{ id: '123456789'}The id matches the wallet ID from Provide wallet addresses.
Confirming the wallet
Section titled “Confirming the wallet”btcdirect('wallet-address-confirmation', { address: 'user-wallet-address' });Canceling the confirmation
Section titled “Canceling the confirmation”Returns the user to the order form:
btcdirect('wallet-address-confirmation-canceled');Callback statuses
Section titled “Callback statuses”If a callbackUrl is configured, the following statuses are sent as query parameters (?orderId=123&status=success):
| Status | Description |
|---|---|
success | The order has been processed successfully. |
expired | The payment window has expired. |
cancelled | The order was canceled by the user. |
denied | The payment was denied (e.g. insufficient funds). |
failed | The order failed for unknown reasons. |