# loyalty (https://docs.salla.dev/twilight/react/sdk/loyalty)



Use `Salla.loyalty` when the store runs a loyalty program: customers collect points and spend them on prizes in the cart.
The [`loyalty` API module](https://docs.salla.dev/twilight/react/api/modules/loyalty) reads the same data for a page, and the `salla-loyalty` web component shows the whole program: see [`salla-loyalty`](https://docs.salla.dev/twilight/react/web-components/salla-loyalty).

```ts
const { data: program } = await Salla.loyalty.getProgram();

await Salla.loyalty.exchange(978);  // spend points on prize 978 in the current cart
await Salla.loyalty.reset();        // take the prize back out
```

## Methods [#methods]

| Method             | Parameters                             | Does                                                                                                              |
| ------------------ | -------------------------------------- | ----------------------------------------------------------------------------------------------------------------- |
| `getProgram`       | none                                   | The program: how points are earned and the prizes                                                                 |
| `getPoints`        | none                                   | The logged-in customer's points                                                                                   |
| `exchange`         | `prizeId, cartId?, selectedProductId?` | Spends points on a prize in the cart. Pass `selectedProductId` when the prize lets the customer choose a product. |
| `reset`            | `cartId?`                              | Removes the prize from the cart and returns the points                                                            |
| `isFeatureEnabled` | none                                   | `true` when the store has the loyalty program on. No request.                                                     |

Without a `cartId`, `exchange` and `reset` use the current cart.

## Events [#events]

| Event                                                                  | Fires when   | Arguments                   |
| ---------------------------------------------------------------------- | ------------ | --------------------------- |
| `loyalty::program.fetched` / `loyalty::program.not.fetched`            | `getProgram` | response or error           |
| `loyalty::points.fetched` / `loyalty::points.not.fetched`              | `getPoints`  | response or error           |
| `loyalty::exchange.succeeded` / `loyalty::exchange.failed`             | `exchange`   | response or error, prize id |
| `loyalty::exchange-reset.succeeded` / `loyalty::exchange-reset.failed` | `reset`      | response or error           |

A successful `exchange` or `reset` also fires `cart::updated`, so your cart summary updates by itself.

## Gotchas [#gotchas]

* On a store without the loyalty program, `getProgram` and `getPoints` reject at once. Check `isFeatureEnabled()` first.
* `getPoints` rejects for a guest.
* Old Twig examples listen to these events on `Salla.event.rating`. They are on `Salla.event.loyalty`.

## See also [#see-also]

* [`loyalty` API module](https://docs.salla.dev/twilight/react/api/modules/loyalty)
* [Loyalty route](https://docs.salla.dev/twilight/react/routes/loyalty)
* [Cart](https://docs.salla.dev/twilight/react/sdk/cart)
