# Events

Events are fired by `Tebex.checkout` upon specific actions to alert your frontend and enable you to take action when required. These events should **not** be used to confirm actual receipt of payment - you should use [Webhooks](/developers/webhooks/overview.md) instead.

To add a checkout event callback, use `Tebex.checkout.on()` . The first argument to this function should be the name of the event to listen to, and the second argument should be a function to call when that event is fired:

```javascript
Tebex.checkout.on("payment:complete", (event) => {
    console.log("Payment completed!", event);
});
```

Available events are as follows:

<table><thead><tr><th width="189.74609375">Name</th><th>Fired Upon</th></tr></thead><tbody><tr><td><code>"open"</code></td><td>The portal popup opening after calling <code>Tebex.checkout.launch().</code></td></tr><tr><td><code>"close"</code></td><td>The portal popup closing after being dismissed by the user.</td></tr><tr><td><code>"payment:complete"</code></td><td>The customer has successfully completed their payment.</td></tr><tr><td><code>"payment:error"</code></td><td>The customer experienced an error, such as incorrect card details or insufficient funds, when making a payment.</td></tr></tbody></table>

All events that can be listened to with [`Tebex.checkout.on()`](#events) are exposed on the element as custom DOM events, which means you can use addEventListener to subscribe to them:

```html
<html>
    <body>
        <tebex-checkout id="checkout"></tebex-checkout>
    </body>
    <script>
        const checkout = document.getElementById("checkout);
        
        checkout.addEventListener("open", () => {
            console.log("checkout opened");
        });

        checkout.addEventListener("close", () => {
            console.log("checkout closed");
        });

        checkout.addEventListener("payment:complete", (event) => {
            console.log("payment completed", event);
        });

        checkout.addEventListener("payment:error", (event) => {
            console.log("payment errored", event);
        });
    </script>
</html>
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.tebex.io/developers/tebex.js/checkout/events.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
