> ## Documentation Index
> Fetch the complete documentation index at: https://docs.resurs.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Events

> Handle payment method selection and deselection events.

## `resursPaymentMethodSelected`

Fires when a payment method is selected. The `detail` property contains:

```ts theme={"theme":{"light":"catppuccin-latte","dark":"one-dark-pro"}}
{
  id: string  // Unique identifier, pass this to the Merchant API when creating a payment
}
```

**JavaScript example:**

```js theme={"theme":{"light":"catppuccin-latte","dark":"one-dark-pro"}}
window.addEventListener("resursPaymentMethodSelected", (event) => {
  const { id } = event.detail;
  // Use id with Resurs' Merchant API
});
```

**TypeScript example:**

```ts theme={"theme":{"light":"catppuccin-latte","dark":"one-dark-pro"}}
interface PaymentMethodSelectedDetail {
  id: string;
}

window.addEventListener(
  "resursPaymentMethodSelected",
  ((event: CustomEvent<PaymentMethodSelectedDetail>) => {
    const { id } = event.detail;
    // Use id with Resurs' Merchant API
  }) as EventListener
);
```

## `resursPaymentMethodDeselected`

Fires when a payment method is deselected. The `detail` property contains `{ id }` for a specific deselection, or `null` when all methods are deselected.

```js theme={"theme":{"light":"catppuccin-latte","dark":"one-dark-pro"}}
window.addEventListener("resursPaymentMethodDeselected", (event) => {
  if (event.detail) {
    const { id } = event.detail;
    // Specific method deselected
  } else {
    // All methods deselected
  }
});
```

***

## JavaScript API reference

The script exposes `window.resurs` with utility functions for programmatic control.

### `resurs.dispatchSelected(id)`

Programmatically select a payment method. Fires the global `resursPaymentMethodSelected` event.

```js theme={"theme":{"light":"catppuccin-latte","dark":"one-dark-pro"}}
resurs.dispatchSelected('some-payment-method-id');
```

### `resurs.dispatchDeselected()`

Programmatically deselect all payment methods. Fires the global `resursPaymentMethodDeselected` event.

```js theme={"theme":{"light":"catppuccin-latte","dark":"one-dark-pro"}}
resurs.dispatchDeselected();
```
