# Wallet buttons

> Add to Apple Wallet and Google Wallet from a ticket, and what a pass does after it is added

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

> **Not every host has them on yet.** A pass needs its platform's account connected, Apple's or Google's, and a link is `null` until it is. On the test host Apple passes are on and Google's are not. Write your page to cope with `null`, as the sample below does, and the buttons appear on their own the day passes are turned on.

## The links

A ticket you read yourself carries two links (`GET /v1/tickets/{id}`, or `GET /v1/tickets?order=ord_...` for all of an order's). A ticket inside an order does not: `wallet` is `{ apple_url: null, google_url: null }` on `/v1/orders` answers, on webhooks and in the event log, because those are kept and passed around and these links open a ticket.

- `ticket.wallet.apple_url`: an https link that downloads the ticket's `.pkpass` file.
- `ticket.wallet.google_url`: an https link that redirects to Google's "Save to Google Wallet" page for the ticket.

```ts
const page = await tickets.tickets.list({ order: order.id });

for (const ticket of page.data) {
  const { apple_url, google_url } = ticket.wallet;
  console.log(ticket.id, apple_url ?? 'no Apple link yet', google_url ?? 'no Google link yet');
}
```

Each link authorizes itself: it carries a signed token for this ticket at this version, good for 7 days. That has three consequences.

1. **They are secrets.** Anyone with the link can add the ticket. Show them only to the ticket's holder, and never put one in a log.
2. **They are made fresh on every read.** Do not store one. Read the ticket again when you need to show a button.
3. **An old link stops working.** After 7 days, a transfer, a reissue or a change the link answers `wallet_link_expired` (410). The holder opens their ticket page and adds the pass from there, and the page always has the current links. A read key, and a reader who no longer holds the ticket, get `null`.

The 410 is JSON for a program. A browser that opens the link (`Accept: text/html`) gets a short page with the same status, saying what happened and leading to My tickets.

**In an email or a text, link the ticket page, not these.** A message stays in an inbox for months and these last 7 days. Add `?wallet=apple` or `?wallet=google` to `ticket.url`: the page makes a fresh link and starts it, for as long as the ticket lasts. It is what our own emails do.

## Showing the buttons

Link to the URL with a normal anchor. Use Apple's and Google's own button artwork and follow their guidelines for it: the badges are theirs, not ours. Show a button only for the platform that can use it, and only when the link is not `null`. On a phone, tapping the link adds the pass without the holder leaving the page.

The holder's ticket page (`ticket.url`) already shows both buttons, so an email or a text that links to it needs nothing more. For a holder who lost the link, see [My tickets](https://rcms-tickets-test.web.app/docs/my-tickets.md).

## After the pass is added

A pass follows its ticket. A change that keeps the holder's links (a reissue, an exchange, a corrected name, a void, a freeze) updates the pass in place, with the new QR code, or none while the ticket is void or frozen. A transfer replaces it: the old holder's pass is updated one last time to say the ticket moved, with no QR code, and the new holder gets a pass of their own.

You can also put a message on every holder's lock screen for an event, for example "Doors move to 6 PM". An event sends at most three a day (`wallet_message_limit`), and the reach says how many passes a message would arrive on and how many messages are left today.

```ts
const reach = await tickets.events.walletReach(event);
console.log(reach.object); // wallet_reach
```

`POST /v1/events/{id}/wallet_messages` sends one. Anything that goes to many people asks first when an agent does it: see [the MCP server](https://rcms-tickets-test.web.app/docs/mcp.md).
