# Favourites, routines and payment runs

The places a person likes and the things they do on a schedule: remind me, suggest and ask, or order it. Personal first; a business can use it for office coffee or lunches.

Migration: `db/052_payment_runs_routines.sql`. Code: `lib/routines.ts`; schedule and limit logic is pure code in `lib/pure/routine.ts`.

## Favourites

A favourite is a merchant, restaurant, cafe, supplier or shop, with `usual_orders` (name, items, size, options, amount, address, time). `place` holds the details the person confirmed when they saved it (a Google Places `place_id`, address, phone, website, hours): capture is Google Places, and nothing here draws Google content on a Mapbox map (see the places note in the app docs). With `payee_id` it can be ordered from; with `deep_link` a routine opens the usual order in the merchant's own app.

## Routines

`mode`: `remind`, `suggest` (ready to order, asks first) or `order`. `schedule`: `{ days, time, utc_offset_minutes }`. `limits`: `per_order_max_minor`, `per_week_max_minor`, `quiet_days`, `away_until`. Limits only lower what happens: order becomes suggest when the amount is over the limit, the week's total would pass, the place cannot be ordered from, or the key's policy asks for approval; a quiet day or a time away skips the run; `POST /routines/{id}/skip` skips the next run once (again to undo). Each run is kept (`GET /routines/runs`) with a plain receipt and sent as `routine.ran`.

## Ordering: official routes only

An order routine pays the favourite's payee through a payout, as the key that made the routine, so the key's spend policy, the new-payee hold and approvals apply. A merchant reached by an agent-ready channel (UCP or agentic checkout, a food platform's partner API) is added as a channel the day its access is granted; until then a favourite with a `deep_link` reminds and the person finishes in the merchant's app. There is no scraping, no browser automation and no stored password anywhere.

## Payment runs

`POST /payment-runs` pays several bills together (up to 100). Each bill is paid as `POST /bills/{id}/pay` pays it; one that fails, is held or waits for approval does not stop the others. `dry_run: true` totals what would be paid, the discount saved, and the bills that cannot be paid and why.

Scopes: `routines:read`, `routines:write` (payment runs use `bills:read` and `payouts:write`). Event: `routine.ran`.
