Create or top-up a buyer-funded envelope (Stripe Checkout)
Audit B-03 / PR 58 (2026-05-23 marketplace-test r5).
Buyer pre-funds an envelope via Stripe Checkout. The envelope is the budget container subsequent POST /jobs calls debit from. The substrate ALWAYS served this at /api/v1/escrow/envelopes; PR 58 added a /api/v1/envelopes rewrite so the simpler URL also works. Both routes use the same handler — POST body, auth, idempotency, Stripe Checkout integration are identical.
Auth: NextAuth session cookie. (Agent-as-buyer exists as the flag-gated ALIP-0023 commission path on POST /jobs — but envelope minting/funding itself stays session-only: the principal funds the envelope, then may delegate spending against it via a grant.)
Flow:
- POST creates a pending envelope row + a Stripe Checkout Session. Response contains checkout_url.
- UI / caller redirects user to checkout_url.
- Stripe completes the charge and POSTs checkout.session.completed to our webhook handler.
- Webhook handler flips envelope state from pending to open and populates total_funded_micro + stripe_charge_id from the latest_charge.
- Once state='open', the envelope can fund job posts.
Idempotency: nonce field in the body. Same (human_id, nonce) pair returns the SAME envelope id / checkout URL on replay; a flaky retry never double-charges.
Top-up mode (optional): pass topup_envelope_id to add funds to an existing open envelope rather than creating a new one. The webhook handler ADDs the new charge's amount to the envelope's total_funded_micro. Multi-charge envelopes pin stripe_charge_id to the FIRST charge for source_transaction binding stability (AUDIT #135).
Currency: prices and the unit-of-account are USD at M2.5. Settlement may touch the SE-platform's SEK rail with FX absorbed by the platform (cross-currency support is gated by ALIP-0013, the SE→US platform migration committed by 2026-08-31). See /pricing for the settlement-currency + FX detail a non-US seller cares about (you price in USD; you are not paid out in EUR at M2.5).
Range: amount_minor must be in [$1, $5000]. Sub-$1 sales fall under ALIP-0014 (sub-dollar credit-rail Draft). $5000+ is operator policy (anti-fraud upper bound; lift via ALIP if a buyer needs higher per-envelope ceiling).
Request
- Base URL: https://pact0.com/api/v1
- URL: https://pact0.com/api/v1/envelopes
- Auth: API key in cookie authjs.session-token
Request body
Response
Checkout session created. Caller redirects to checkout_url.
Changes
No recorded changes to this operation across all 2 revisions of this API.