---
title: "Offers"
description: "Perks a hotel gives guests, the code and QR a guest shows, and how they are scoped and tested."
url: https://pr-417-docs.preview-ritorno.findmalek.engineer/docs/offers
markdown: https://pr-417-docs.preview-ritorno.findmalek.engineer/docs/offers.md
---

# Offers

An offer is a simple perk, not points: a welcome drink, a birthday dessert, a spa credit. Every offer belongs to one hotel.

## What an offer has

`offers`: title, text, `translations`, validity window (`valid_from`, optional `valid_until`), a promo code that is unique inside the hotel, an optional audience (`welcome`, `birthday`, or none for handed out by staff), an optional `max_redemptions` and an `active` flag.

## Languages

`title` and `text` are the offer's default words. `translations` holds a title and text for any of `en`, `fr`, `ar`, written in **Other languages** on the offer form. `localizedOffer` (`@ritorno/common/offers`) picks the words field by field: a title or a text left empty for a language falls back to the default one. Offers made before translations existed have none and read as before.

| Where | Language used |
|---|---|
| capture page and thank-you code | the page's language |
| `/o` page | `?lang`, else the guest's (or the sign-up's) |
| welcome, birthday, reminder, campaign and **Send** messages, email and WhatsApp | the guest's |
| WhatsApp scan reply | the scanned code's |
| offer and campaign previews | the one shown |
| QR kit | the card's, or all three |

The dashboard lists, the redeem screen and the guest history show the default words: they are for staff.

Owners and managers create, change and delete offers in the dashboard (**Offers**, `/offers`, `offers.*`). Staff can read them. The form shows a preview of the page as the guest sees it, in the hotel's colors. Deleting an offer deletes its redemptions, so pausing (`active` off) is the way to stop one and keep the numbers.

## The guest's code and QR

A guest holds one code per offer, made the first time they open their link (`offer_codes`, unique per offer and guest, unique across hotels). It looks like `AB3D-EF7H` (no `0`, `O`, `1`, `I`, `L`) so it can be typed at a desk. The QR holds that code and is rendered by the api (`lib/qr.ts`, the same helper as the hotel QR codes).

The guest link is `/o/<token>` on the web app (`offerPageUrl` in `@ritorno/common/offer-tokens`). The token is signed with the server secret, like unsubscribe links, and carries the hotel, offer and guest. The page is `noindex` and shows the branded offer, its state (ready, paused, not started, expired, all taken, already used) and the QR. It never shows the guest's name or contact. Messages that carry an offer build the link with `signOfferToken`.

## Welcome offer on the capture page

`public.hotel` returns `welcomeOffer` (title, text and translations only): the newest active `welcome` offer that can be redeemed now (inside its window and not used up). The capture page shows it as the perk instead of the generic one.

### The code on the thank-you screen

`public.capture` answers with `perk`: the offer, a code, its QR and a link to reopen it. The thank-you screen shows the same card as `/o`. It needs no consent, because showing a code on the guest's own screen is not a message: nothing is sent and the consent log is untouched. `perk` is null when the hotel has no open welcome offer, and the screen then shows the plain thank-you.

The public form takes any phone, so the answer is built the same way for a new and a known one (`signUpPerk` in `lib/offers.ts`):

- The code is derived (HMAC with the server secret) from the hotel, the offer, the phone and `claim`, a random value the browser makes for this visit of the form.
- It is stored as the guest's code only when they hold none for the offer: a new guest, or one added by staff or CSV. A welcome message sent afterwards carries the same code.
- A guest who already holds a code keeps it. The screen shows a code that redeems nothing (the desk reads "code not found"), so someone typing another person's number never gets or learns anything about their code. The thank-you tells everyone who signed up before to use their first code or ask the desk.
- A retry of a lost answer sends the same `claim`, so it shows the stored code.
- The link is a signed `/o/<token>` that names the code, never the guest, and a code nobody holds reads like a fresh one.

Limits against farming: one code per phone and offer, one redemption per code, the capture rate limits ([data rules](https://pr-417-docs.preview-ritorno.findmalek.engineer/docs/data-rules.md#the-qr-capture-page)) and the offer's `max_redemptions`. Phones are not verified, so a determined person at the desk can sign up a made-up number for a second drink: set `max_redemptions` on an offer where that matters. Someone who signs up another person's number before that person ever has a code gets the code for it; the owner of the number then needs the desk.

The WhatsApp welcome template still has no offer link: adding it needs Meta approval again.

## Redemptions

`offer_redemptions` has one row per redemption: offer, guest (optional), time and the staff user. With a guest the unique `(offer_id, guest_id)` makes a double redemption impossible even when two phones scan at the same moment. Deleting a guest keeps the row without the guest, so counts stay and no personal data does.

## The staff redemption screen

**Redeem** (`/redeem`) is built for a phone at the desk. Staff scan the guest's QR with the phone camera (the browser's `BarcodeDetector`, read in `qr-scanner.tsx`) or type the code, then see the offer, the guest's first name only and the validity. One tap marks it redeemed with who and when. The answer fills the screen: green when the code can be or just was redeemed, amber when it is real but not usable now (already used, expired, not started, paused, used up), red for another hotel's code or an unknown one, each with one line saying what to tell the guest. Safari and Firefox have no `BarcodeDetector` yet, so there the screen only offers the typed code.

A code can be a guest's code (`AB3D-EF7H`) or the offer's promo code. A promo code is not bound to a guest, so it can be redeemed many times, up to `max_redemptions`. `offers.lookup` and `offers.redeem` answer with a status, never an error:

| Status | Meaning |
|---|---|
| `ready` | can be redeemed now |
| `redeemed` | already redeemed (with who and when) |
| `expired`, `notStarted` | outside the validity window |
| `inactive` | the offer is paused |
| `exhausted` | `max_redemptions` reached |
| `wrongHotel` | the guest code belongs to another hotel, nothing about it is shown |
| `unknown` | no such code |

`offers.redeem` locks the offer row while it counts, then inserts, so two phones scanning the same code at once give one redemption and one "already redeemed". The unique `(offer_id, guest_id)` is the backstop. Each redemption writes an `offer.redeem` audit row (offer id, no guest data). A guest's code also counts their visit for the day and the result links to the guest. A wrong tap can be taken back for 10 minutes with `offers.undoRedeem`: the redemption and the visit it counted are removed and `offer.unredeem` is audited. Owners, managers and staff can redeem. `offers.redemptionStats` gives the counts (today in the hotel's timezone, last 7 days, total) and `offers.redemptions` lists every redemption of the hotel, newest first, which the screen loads as you scroll.

## Staff hand out an offer

**Give offer** on the guest page and on an unhappy guest's case lists the offers that can be redeemed now, whatever their audience. Picking one makes the guest's code (`offers.give`) or shows the one they already hold, with its QR. It redeems like any other code, once per guest. A used, expired or paused offer is not given again: a guest who holds a code sees why instead. Showing the code needs no consent.

**Send** buttons appear only for channels the guest agreed to and can be reached on. `offers.send` goes through `sendToGuest`, so consent is checked again and the message is logged, with the unsubscribe link or STOP line. It uses the `message` template: email carries the offer card and a link to `/o`, WhatsApp the approved `guest_message` with the offer, code and link in its text. The same offer is sent to a guest at most once per 5 minutes and channel.

Owners, managers and staff can give and send, the demo viewer cannot. A new code writes `offer.give` and each send `offer.send` in the audit log.

## Demo data

The seed adds three offers per demo hotel (open, open, and one past its end date) with codes and redemptions spread over the last weeks (`packages/db/src/seed/offers.ts`).
