# MicroSaaS Directory — Machine Payments Protocol (MPP HTTP 402 & x402)

AI agents and scripts can autonomously purchase one-time MicroSaaS Directory SKUs without an interactive browser checkout using HTTP `402 Payment Required` (**MPP** / **x402**).

- **Validate / Quote (dry-run):** `POST /api/v1/machine/orders/validate`
- **Order & Fulfill (HTTP 402):** `POST /api/v1/machine/orders`
- **Status Polling:** `GET /api/v1/machine/orders/{requestId}?statusToken=...`
- **x402 Discovery Manifest:** `GET /.well-known/x402`
- **OpenAPI Spec:** `GET /openapi.json`

---

## Machine-Payable SKUs

| SKU | Price | Requires `saas_slug` | What it does |
| --- | --- | --- | --- |
| `instant_recrawl` | $2.00 | Yes | Immediately triggers a fresh crawl + 10-dimension re-audit (bypasses the free 1x/7-day cooldown). |
| `beat_queue` | $9.00 | Yes | Fast-tracks a submitted listing to the top of the review queue and dispatches an immediate crawl. |
| `agency_submit` | $15.00 | Yes | Agency pay-per-submission bundle: fast-tracks review, dispatches immediate crawl + audit, and unlocks permanent badge-free `dofollow` upon approval. |
| `badge_free_dofollow` | $29.00 | Yes | Permanently unlocks a dofollow outbound link without embedding the footer badge. |
| `radar_snapshot` | $2.00 | No | Returns a live JSON export of top indie apps with verified traffic, verified MRR, RPV, 10-dim health scores, and acquisition flags. |
| `pixel_wall_slot` | $49.00 | Yes | Permanently claims a tile (optional `slot_index` `0..99`) on the 10x10 Founding Pixel Wall. |

> **Subscriptions (`buyer_pass` $49/mo, `agency_pass` $79/mo for 25 fast-track nofollow submissions/mo)** use human-approved Stripe Checkout URLs via the MCP `create_checkout` tool. Priority review never guarantees approval for spam or blocked domains.

---

## Step 1: Dry-Run Quote (Zero Side Effects)

```bash
curl -sS -X POST https://microsaas.directory/api/v1/machine/orders/validate \
  -H "Content-Type: application/json" \
  -d '{
    "sku": "instant_recrawl",
    "saas_slug": "your-app-slug",
    "request_id": "recrawl-2026-11-27-001"
  }'
```

---

## Step 2: Request HTTP 402 Payment Challenge

```bash
curl -i -X POST https://microsaas.directory/api/v1/machine/orders \
  -H "Content-Type: application/json" \
  -d '{
    "sku": "instant_recrawl",
    "saas_slug": "your-app-slug",
    "request_id": "recrawl-2026-11-27-001"
  }'
```

The server responds with **`402 Payment Required`**, `WWW-Authenticate: Payment ...`, `PAYMENT-REQUIRED`, and JSON containing:
- `challenge` and `digest` (HMAC-SHA256 bound to your exact `request_id`, SKU, and payload hash)
- `status_token` and `status_url` (store `status_token` to poll the order later)
- `payment_methods` (Stripe SPT, Tempo USDC.e, or `local_mock` in development)

---

## Step 3: Retry with Payment Credential

Attach `Authorization: Payment <base64url-json>` (or `PAYMENT-SIGNATURE` for x402) using the **exact same request body and `request_id`**.

```bash
# Credential JSON before base64url encoding:
# {
#   "challenge": "<challenge from 402>",
#   "digest": "<digest from 402>",
#   "method": "stripe",
#   "token": "<Stripe SPT / payment receipt>"
# }

curl -sS -X POST https://microsaas.directory/api/v1/machine/orders \
  -H "Content-Type: application/json" \
  -H "Authorization: Payment <base64url_credential>" \
  -d '{
    "sku": "instant_recrawl",
    "saas_slug": "your-app-slug",
    "request_id": "recrawl-2026-11-27-001"
  }'
```

### Idempotency & Replay Protection
- Repeating the same `request_id` with the **same body** after fulfillment returns `200 OK` with `idempotent_replay: true` and the stored result (never double-charged).
- Repeating the same `request_id` with a **different body** returns `409 Conflict`.
- Reusing a spent payment token for a different `request_id` is atomically blocked via PostgreSQL advisory locks (`409 Conflict`).
