# Agent Integration — A Star Named

> Last updated: 2026-10-28
> Pricing: https://astarnamed.com/pricing.md
> Site summary: https://astarnamed.com/llms.txt

A Star Named sells one digital memorial product: a real star from the HYG catalog, named in memory of a person or pet, with a certificate and a private memorial space.

**Hard boundary: an agent can prepare an order, but a human must pay.** Payment runs on Waffo's hosted checkout page and requires the buyer's card and any 3-D Secure challenge. This site has no agent payment credential, wallet, x402, ACP or UCP endpoint. Never ask for, collect, or store card data.

## Recommended: one-call checkout

`POST https://astarnamed.com/api/agent/checkout`
`Content-Type: application/json`
`Idempotency-Key: <random 8-128 character string>` (recommended — see below)

This call finds the available star nearest the zenith, reserves it, creates a pending order, and returns a hosted checkout URL.

### Request

```json
{
  "date": "2007-11-16",
  "time": "23:40",
  "latDeg": 30.5728,
  "lngDeg": 104.0668,
  "timeZone": "Asia/Shanghai",
  "placeEn": "Chengdu",
  "placeZh": "成都",
  "personal_name": "Grandpa",
  "email": "buyer@example.com",
  "memorial": { "kind": "person" },
  "dedication": "The star that was above you is still there.",
  "locale": "en"
}
```

Required:

- `personal_name` — 1 to 60 characters
- `email` — buyer email; the order confirmation is sent here
- Either `find_token` (from `POST /api/birth-star/find`; valid for 24 hours in the current server process) **or** `date` + `time` + a place:
  - `date` — `YYYY-MM-DD`
  - `time` — `HH:MM`
  - `cityKey` — a supported city key, **or** `latDeg` + `lngDeg` + `timeZone` (IANA name)

Optional:

- `candidate_index` — 0-based index in the candidate list; default is the nearest available star
- `gift_scene` — up to 100 characters
- `dedication` — up to 500 characters
- `memorial` — `{"kind":"person"|"pet","species":"...","life_dates":"..."}`; defaults to `{"kind":"person"}`. **Pass `kind:"pet"` for pets.**
- `birth_info` — a structurally complete moment record; if omitted, the one-call path builds it automatically when place names are known:
  - with `cityKey`, the city's English/Chinese name is used;
  - with `latDeg`/`lngDeg`, pass `placeEn` and `placeZh` so it can be built;
  - with `find_token`, pass `birth_info` explicitly if you need the date/place on the certificate.
- `placeEn`, `placeZh` — optional place labels for coordinate input (used to build `birth_info`)
- `locale` — `en` or `zh`; controls the confirmation email language
- `product_id` — defaults to the current sale product

### Response

```json
{
  "success": true,
  "data": {
    "order_id": 123,
    "order_token": "48-hex-character-capability-token",
    "status": "pending",
    "birth_info_saved": true,
    "memorial_kind": "person",
    "product": { "id": 7, "name": "Digital Star", "price": 19.99, "currency": "USD" },
    "star": {
      "personal_id": "TES-LYRA-HIP-92404",
      "gaia_source_id": "HIP 92404",
      "constellation": "lyra",
      "constellation_name": "Lyra",
      "inventory_code": "LYRA-0000846"
    },
    "payment": {
      "provider": "waffo",
      "required": true,
      "requires_human": true,
      "checkout_url": "https://checkout.example/..."
    },
    "hold_expires_at": "2026-11-04T00:00:00.000Z",
    "poll_url": "https://astarnamed.com/api/orders/123?token=...",
    "next": "Send checkout_url to the human buyer. Poll poll_url until status is paid or completed; the payment webhook is authoritative."
  }
}
```

**Next step for the agent:** give `payment.checkout_url` to the human buyer. Do not attempt to pay it yourself.

## Step-by-step API (if you need control)

1. `GET https://astarnamed.com/api/products` — current sale product and price.
2. `POST https://astarnamed.com/api/birth-star/find` — body: `{date,time,cityKey}` or `{date,time,latDeg,lngDeg,timeZone}`. Returns `data.token` and `data.result.candidates[]`.
3. `POST https://astarnamed.com/api/stars/check` — body: `{constellation, gaia_source_id}`. Confirms the star is still available.
4. `POST https://astarnamed.com/api/orders` — create a pending order:
   - `product_id`, `constellation`, `personal_name`, `personal_id`, `gaia_source_id`, `email`
   - `personal_id` format: `TES-<CONSTELLATION_UPPER>-<gaia_source_id with spaces replaced by ->`
   - optional `gift_scene`, `dedication`, `birth_info`, `memorial`, `locale`
5. `POST https://astarnamed.com/api/orders/{order_id}/pay` — returns `data.checkout_url` in production (Waffo), or `data.provider = "mock"` in development.
6. `GET https://astarnamed.com/api/orders/{order_id}?token={order_token}` — poll status. `paid` or `completed` means fulfilled. The payment webhook is authoritative.
7. After payment, certificate: `GET https://astarnamed.com/api/certificates/{order_id}/download?lang=en&token={order_token}`.

Guest checkout is allowed. If the email already belongs to a registered account, the request must include that account's `Authorization: Bearer <JWT>`; otherwise the API returns `409`.

## Limits and safety

- `POST /api/agent/checkout`: 3 requests per minute per IP.
- `POST /api/orders`: 6 requests per minute per IP.
- An unpaid order holds its star for 7 days; it is released automatically after that.
- `order_token` is a secret capability. Treat it like a password. It is returned once, at order creation.
- Do not create duplicate orders for the same purchase. Each order reserves a different star.
- Do not buy a memorial on behalf of someone without their authorization.

## Idempotency

Send an `Idempotency-Key` header with a random 8–128 character string using only
`A-Z a-z 0-9 . _ : -` on `POST /api/agent/checkout`. For 15 minutes, a repeat from the
same IP with the same key returns the original response with `Idempotency-Replayed: true`
and does not reserve another star. A concurrent duplicate returns `409` with
`Retry-After: 2`. Only successful responses are cached; after a 4xx/5xx you may retry
with the same key.

Use a fresh random key for each distinct purchase. Reusing a key for a different purchase
returns the original order, not a new one.

## Retries

Prefer the `Idempotency-Key` flow above. If you have an `order_id` and `order_token`,
poll `poll_url` instead of re-submitting.

## Error codes

| Status | Meaning |
|---|---|
| 400 | Invalid or missing input, or invalid `Idempotency-Key` |
| 404 | Find token expired, or no star found |
| 409 | Star already named, product not on sale, email belongs to a registered account, or the same `Idempotency-Key` request is still in flight |
| 429 | Rate limited |
| 502 | Payment session creation failed; the local order was cancelled and the star released |
| 503 | Payment is not configured |

## Links

- Pricing: https://astarnamed.com/pricing.md
- Products: https://astarnamed.com/products
- Terms: https://astarnamed.com/terms
- Privacy: https://astarnamed.com/privacy
- Refunds: https://astarnamed.com/refund
- Contact: https://astarnamed.com/contact
