MinuteGate wire protocol
Summary of SPEC.md (version 0.1). Payments run against the PayPal sandbox only; no real money moves.
Roles
- Server — hosts a resource and charges for access to it.
- Client — requests the resource and pays through PayPal (sandbox).
- PayPal — the PayPal Orders v2 API at the sandbox endpoint.
1. Payment required
A client requests a resource with no proof header. The server answers
402 Payment Required with a JSON body. The body includes protocol version
(minutegate, currently 0.1), total amount and
currency, a rate object (unit is
session or minute, price per unit,
quantity of units; amount equals price ×
quantity), a single-use reference, expiresAt,
accepted methods (spec 0.1 defines only paypal-sandbox),
and the proofHeader name for the retry. Optional
description text may appear. The server stores each reference with amount,
currency, rate, expiry, and whether it has been used.
A tick on the meter marks each elapsed minute. In version 0.1 each session is paid up front; settling totals when the session ends is planned for a later version. No flat monthly gate for short agent jobs.
2. Client pays through PayPal (sandbox)
-
Create order —
POST /v2/checkout/orderswithintent: "CAPTURE"and one purchase unit whose amount matches the 402 body and whosecustom_id(andreference_id) is the MinuteGatereference. - Buyer step — the buyer opens the order's approve link and completes the payment step as a PayPal sandbox buyer.
-
Capture —
POST /v2/checkout/orders/{id}/capture.
In this sandbox demo the client and the example server use the same PayPal sandbox app credentials, so the order is created on the server's own merchant account. Separating the payer side from the merchant side is planned for a later version.
PayPal and Venmo are trademarks of PayPal, Inc. Not affiliated with or endorsed by PayPal.
3. Retry with proof
The client repeats the original request with the proof header (default name
minutegate-payment):
minutegate-payment: reference=mg_EXAMPLE123456789; order=EXAMPLE-ORDER-001
4. Server-side check
The order id in the header is a lookup key only. The server does not grant access because a client asserts an order exists or was captured. For each retry the server:
- Parses the header; rejects malformed values (
malformed_proof). -
Looks up the reference in its own records; rejects unknown
(
unknown_reference), already used (reference_used), or expired (reference_expired) references. - Rejects an order id that already unlocked a resource (
order_reused). -
Fetches the order from PayPal with its own credentials. An order PayPal does not
return is rejected (
order_not_found); a PayPal outage givespaypal_unavailable. -
Requires exactly one purchase unit whose
custom_idequals the reference (reference_mismatch). -
Requires order status
COMPLETEDwith a capture in statusCOMPLETED(not_captured). -
Requires purchase unit and capture amounts to match the issued currency
(
currency_mismatch) and amount (amount_mismatch). -
On success, marks the reference and order id as used and answers
200with the resource. The PayPal capture id is returned in theminutegate-receiptheader.
A rejected retry gets a new 402 body with a fresh reference and an
error code from the list above.
Proof header grammar (as implemented)
The client emits reference=<reference>; order=<orderId>.
References match mg_ plus 8–64 ASCII letters, digits, underscores, or
hyphens. Order ids are 1–64 uppercase ASCII letters, digits, or hyphens. Extra fields
with = are ignored; the last duplicate key wins. These are current parser
behaviors. Strict duplicate or unknown-field rejection is not implemented.
Scope of version 0.1
In this repository: the flow above, a TypeScript PayPal sandbox client, an example server, an in-process PayPal mock for running without credentials, and tests.
Not in 0.1:
- Non-sandbox PayPal endpoints.
- Webhooks.
- Refunds.
- Persistent storage of references.
- Any other payment method.
- Charging once when the session ends instead of up front — planned for a later version.
The example server keeps references in memory, so they reset when it restarts.
Reference lifetime defaults to 900 seconds; each 402 issues a new
reference.