# Overview

The cart is a purchasing mechanism that enables combining multiple items into a single order. A user can buy items of any type in any quantity for real currency, as well as use [promo codes](https://developers.xsolla.com/api/liveops/promotions-promo-codes).

The cart is stored on the Xsolla side. Saving the cart across sessions depends on whether the user is authorized:
  * For authorized users, the cart is linked to a specific user and is saved across sessions as long as requests are sent on behalf of the same user.

  * For [unauthorized users](/api/catalog/authentication-with-guest-access-support), saving the cart depends on passing the `x-unauthorized-id` header. To save the cart of an unauthorized user across sessions, pass the same  `x-unauthorized-id` in every request. This option is available only for game key sales.

You can identify the cart in two ways: automatically by [user's JWT](https://developers.xsolla.com/api/catalog/authentication-using-users-jwt) or by cart ID (`cart_id`).

Cart management is available both on the client side and on the server side.

On the server side, you can fill the cart with items, e.g., when restoring a user session. The following actions are available on the client side:

* retrieve the current user's cart or a cart by ID
* fill the cart
* update items in the cart
* delete items from the cart

To purchase items from the cart, the client and server calls for order creation are used.

The cart’s time to live (TTL) is 72 hours by default. If its content changes, e.g., when a new item is added, the TTL is extended.

After successful payment, the cart isn’t cleared automatically. To clear the cart, use the following client-side API calls:
  * [Delete all cart items by cart ID](/api/catalog/cart-client-side/cart-clear-by-id).

  * [Delete all cart items from current cart](/api/catalog/cart-client-side/cart-clear).

  * [Delete cart item by cart ID](/api/catalog/cart-client-side/delete-item-by-cart-id) and [Delete cart item from current cart](/api/catalog/cart-client-side/delete-item) — the cart is cleared when you delete the last item from it.

Cart usage scenario:

1. Implement a store UI where the user will select items.

2. When the user selects items in the store, add them to the cart, e.g., using the [Fill cart with items](https://developers.xsolla.com/api/catalog/cart-client-side/cart-fill) call. In the items array, you need to pass the SKUs and the required quantity of items.

3. Implement the cart viewing UI. When the user navigates to the cart, display its contents using the [Get current user's cart](https://developers.xsolla.com/api/catalog/cart-client-side/get-user-cart) call. The response will return information about the final price of the items, including discounts and applied promotions.

4. Implement the opening of the payment UI to pay for the order. For example, you can use the [Create order with all items from particular cart](https://developers.xsolla.com/api/catalog/payment-client-side/create-order-by-cart-id) call. The response returns a token to open the payment UI.

5. Configure order status tracking, e.g., using [webhooks](https://developers.xsolla.com/webhooks/), to promptly receive data about successfully paid items and grant them to the user.

<div class="note">
  <p><b>Note</b></p>
  <p>To implement selling items in-game and online, refer to the <a href="https://developers.xsolla.com/virtual-goods/own-ui/">integration guide</a>.</p>
</div>

![Cart and payment flow](https://cdn.xsolla.net/developers/current/images/api_docs/cart-payment-flow.svg)


