# Buy one prepaid month or year with delegated MPP or x402; never renews or approves a post

`POST` `/api/v1/billing/pay`

`payPlan`

The workspace is inferred from a workspace token; owner sessions supply workspace. HTTP 402 supplies challenges, the exact one-time price/period, description and terms_url. MPP uses WWW-Authenticate; Link answers with the person's delegated Shared Payment Token in Payment-Credential or JSON payment_credential. Keep the workspace Bearer token in Authorization. Standard MPP Authorization: Payment clients instead put the workspace token in X-Flaghand-Token (only on this route); never send both workspace-token headers. x402 v2 uses PAYMENT-REQUIRED: base64 JSON with resource URL/description (plan, price, period and Terms) and an exact USDC requirement on Base, eip155:8453 live or eip155:84532 test. Pay only the quoted Stripe deposit payTo, using a wallet the person explicitly delegated and funded or capped for this spend. Standard @x402/fetch and @x402/evm 2.29.0 exact clients generate the EIP-3009 nonce; no custom signer or server-selected authorizationNonce is required. The authorization is a delegated bearer credential: it signs payer/payee, exact amount, network/asset domain, client-generated nonce and validity, not the HTTP workspace, payment_id or resource URL. Before facilitator dispatch, the server durably and atomically claims (mode, network, asset, payer, nonce) on first use for the authenticated immutable purchase; later use may only recover or replay that same purchase. This is server-side first-use binding, not cryptographic workspace binding: a stolen preclaim signature is transferable to a same-price eligible purchase in another eligible workspace the holder can access. Disclosure compromises the credential; authenticated TLS protects confidential transport only, not after disclosure. Never put raw signatures or credentials in URLs, command arguments, logs, errors, screenshots or retained evidence. Send the base64 v2 answer in PAYMENT-SIGNATURE or JSON payment_signature (HTTP/MCP/CLI), separately from workspace Bearer access, which is never payment authority. x402 requires US billing country/state and trusted US edge-IP evidence; DE, missing or unknown edge evidence supplies a machine-readable startCheckout fallback with mode=payment and managed_payments=true, in x402_unavailable if MPP is still offered. Client-supplied country headers do not qualify. A facilitator settlement is not payment truth: a matching succeeded Stripe PaymentIntent and paid Charge are required before granting time. A renewing or overdue recurring subscription returns 409 recurring_subscription_active without a challenge or charge; manage_billing and renews_at identify the existing obligation. A person-canceled subscription keeps its remaining time before prepaid begins. Retry the original credential/signature and same payment_id/plan after any lost or pending reply; never double buy to recover. A paid response includes Payment-Receipt, the paid-through date and, for x402, PAYMENT-RESPONSE and x402 transaction/network/payer. Supply billing.country and US billing.state once; the account remembers them and updateBillingLocation changes them. Missing billing fields return billing_location_required without a challenge or charge. Agent rails are US-only; California uses Managed Payments from 2027-01-01 America/Los_Angeles. A different known SPT card country also requires Managed Payments. Quote and pre-charge checks use immutable purchase evidence and reject stale billing location. managed_payments_required supplies executable next_action startCheckout with mode=payment, plan and managed_payments=true. This one-time operation never renews, approves, schedules or posts. Who can call it: An API token with the "billing" scope, or an owner of this workspace, signed in.

**Scopes:** `billing`

**Parameters**

| Name | In | Required | Type and constraints | Description / example |
| --- | --- | --- | --- | --- |
| `Idempotency-Key` | header | No | `string` | Reuses the same quoted purchase for this workspace and plan. Payment retries are also idempotent on the challenge itself. Example: `"example-plan-2026-11-06"` |

**JSON body**

| Field | Required | Type and constraints | Description |
| --- | --- | --- | --- |
| `plan` | Yes | `string`; enum: `["monthly","yearly","founding"]` |  |
| `billing` | No | `object` |  |
| `workspace` | No | `string` | Required for an owner session; a token can only name its own workspace. |
| `payment_id` | No | `string` | Recover this same quoted purchase without creating another. |
| `payment_credential` | No | `string` | MPP Payment credential for transports that cannot set Payment-Credential. Keep it private. |
| `payment_signature` | No | `string` | Optional base64-encoded x402 v2 PAYMENT-SIGNATURE header value for HTTP JSON, MCP or CLI, using the standard exact client's EIP-3009 nonce. This is a delegated bearer credential, not a workspace/resource signature. Submit only for this authenticated purchase and recover the same payment_id/plan; keep private. |

**Request example**

```http
POST https://app.flaghand.com/api/v1/billing/pay
Authorization: Bearer tok_<your workspace token>
Content-Type: application/json

{
  "plan": "monthly"
}
```

**Response example**

```json
{
  "payment_id": "pay_aaaaaaaaaaaaaaaa",
  "status": "paid",
  "plan": "monthly",
  "amount": 1900,
  "currency": "usd",
  "period_start": "2026-11-06T12:00:00.000Z",
  "paid_through": "2026-12-06T12:00:00.000Z",
  "auto_renews": false,
  "invoice_url": "https://invoice.stripe.com/i/example",
  "receipt": {
    "method": "stripe",
    "status": "success",
    "reference": "pi_example"
  },
  "next_step": "No automatic renewal. The person still approves each exact posting plan."
}
```

Success: HTTP 200. Content-Type: application/json.

Response headers: `Payment-Receipt`: Stripe-backed receipt for this settled purchase.; `PAYMENT-RESPONSE`: Base64 x402 v2 settlement response with success, transaction, network and payer; emitted only after Stripe payment verification..

**Errors:** `invalid_request` (400), `internal` (500), `unauthorized` (401), `invalid_token` (401), `session_expired` (401), `bad_origin` (403), `scope_missing` (403), `owner_session_required` (403), `invalid_json` (400). See the [error codes](https://app.flaghand.com/docs/errors.md) for meanings and the shared default error response. Other domain errors from that catalog may apply; the response's code and message are authoritative.

**CLI:** `flaghand billing pay`

```sh
flaghand billing pay -d '{"plan":"monthly"}' --json
```

**MCP tool:** `payPlan` (also reachable through `callWriteOperation`; use `getOperation` to load its full schema).

```json
{
  "name": "callWriteOperation",
  "arguments": {
    "operation_id": "payPlan",
    "arguments": {
      "plan": "monthly"
    }
  }
}
```

Base URL: `https://app.flaghand.com/api/v1`. Part of the [API reference](https://app.flaghand.com/docs/api.md); every error code is in [errors](https://app.flaghand.com/docs/errors.md).
