# Exchanges

> Upgrade a ticket, swap its day or add an add-on without a refund and a rebuy

Source: https://rcms-tickets-test.web.app/docs/exchanges

An exchange changes tickets that were already sold: an upgrade from GA to VIP, a swap from Friday's ticket to Saturday's, or an add-on added to an order. It is a **quote** first, then a **confirm**. The old ticket is replaced by a reissued one, with a new QR code, and the buyer pays only the difference or is given it back.

## Quote

The quote holds the new items for a short time and prices the change. Nothing is paid or changed until you confirm.

```ts
const vip = setup.ticket_types.find((t) => t.ref === 'vip')!.id!;
const current = await tickets.orders.retrieve(order.id);
const first = current.tickets[0]!;

const quote = await tickets.exchanges.create({
  order: order.id,
  changes: [{ kind: 'change_ticket_type', ticket: first.id, ticket_type: vip }],
});

console.log(quote.status, quote.price.credit.amount, quote.price.due.amount, quote.price.refund.amount); // quoted 4500 7500 0
```

Read `price`:

| Field | Meaning |
| --- | --- |
| `credit` | What the replaced items were paid, after discounts and refunds. |
| `charge` | The new items priced now, as a full price breakdown. |
| `due` | What to pay: `charge.total − credit`, if more than zero. |
| `refund` | What comes back: `credit − charge.total`, if more than zero. |

One ticket moving to a type of the same price keeps what it was paid: nothing is due or refunded, and no use of a code is spent (`price.same_price`). That needs the same base price, fee rules and tax, a discount that covers the new type, and no refund on the ticket yet.

Any other change is priced now, without the order's discount unless you send `code` again. A code with a limited number of uses can't be sent in an exchange.

A quote expires (`quote_expires_at`). Confirming an expired one answers `exchange_quote_expired`: quote again.

## Confirm

Pay the difference and make the change. The payment is the same kind as an order's: `external` with the amount you took, or the `test` provider in test mode.

```ts
const done = await tickets.exchanges.confirm(quote.id, { payment: { provider: 'test', token: 'tok_success' } });
console.log(done.status); // completed

const changed = await tickets.orders.retrieve(order.id);
console.log(changed.exchanges.length, changed.tickets.filter((t) => t.status === 'valid').length); // 1 2
```

- When the new items cost **less**, confirm with `refund_difference: true`, or it answers `exchange_refund_required`. The difference goes back as a refund line.
- Day swaps and upgrades are priced like any change: the quote says what is owed. A swap at the same price has `due` and `refund` of zero.
- Add an add-on with `{ kind: 'add_add_on', add_on, quantity }`, and name the `ticket` for a per-ticket add-on.
- Refused: a disputed order, a void or frozen ticket, a ticket already scanned in today (`ticket_checked_in`), a new item that is sold out.
- Drop a quote you will not use with `tickets.exchanges.cancel(id)`: it gives the held items back at once.

## Let holders swap their own day

For a swap at the same price, the holder's own ticket page has a day-swap button when the event allows it (`swap_not_allowed`, `swap_cutoff_passed`, `swap_limit_reached` explain a refusal). Anything that costs money goes through an exchange like this one.

## Webhooks

`exchange.created`, `exchange.completed`, `exchange.cancelled` and `exchange.expired` report the quote's life, and `order.exchanged` and `ticket.exchanged` report the change itself. A confirmed exchange reissues the tickets it replaced.
