Documentation

Guides and references for the MinuteGate HTTP 402 flow in this repository. Sandbox only; no real money moves.

TypeScript API (src/)

Exported symbols from the package entry (src/). Re-exports are grouped by module.

protocol.ts

Name Kind Description
SPEC_VERSION const Protocol version string (0.1).
PROOF_HEADER const Header the client sends on the retry.
RECEIPT_HEADER const Header the server returns on success with the PayPal capture id.
RateUnit type "session" or "minute".
Rate interface Unit, per-unit price string, and quantity covered.
PaymentRequired interface Body of an HTTP 402 response.
RejectionCode type Error codes on a rejected retry; see SPEC.md.
PaymentProof interface Reference and PayPal order id pair.
formatProof function Formats a proof header value.
parseProof function Parses a proof header value; returns null when malformed.
totalFor function Multiplies a decimal price by quantity, returning N.NN.
toCents function Parses a decimal amount string into integer cents.
fromCents function Formats integer cents as a two-place decimal string.

client.ts

Name Kind Description
PendingPayment interface URL, 402 body, created order, and buyer approval link.
FetchResult interface HTTP status, decoded body, and receipt header value.
requestResource function Requests the resource; returns the 402 body or null if not gated.
startPayment function Creates a PayPal sandbox order for the 402 body.
finishPayment function Captures the order after buyer approval, then retries with proof.
retryWithProof function Retries the resource with the proof header.

server.ts

Name Kind Description
GateOptions interface PayPal client, rate, currency, reference TTL, and optional clock.
CheckResult type Success with capture id or failure with a rejection code.
MinuteGate class Issues references and checks proof headers against PayPal.
createGateServer function HTTP server exposing one gated resource at GET /resource.

paypal.ts

Name Kind Description
PAYPAL_SANDBOX_BASE const Default PayPal sandbox API base URL.
PayPalConfig interface Sandbox client id, secret, and optional base URL.
Money, Capture, PurchaseUnit, Order interface Subset of PayPal order shapes used by MinuteGate.
PayPalError class Error type for failed PayPal HTTP calls.
configFromEnv function Reads PayPal sandbox credentials from the environment.
PayPalSandboxClient class Minimal PayPal Orders v2 client for the sandbox.
approvalLink function Returns the buyer approval link from a created order.

mock-paypal.ts

Name Kind Description
MockPayPal interface Loopback mock base URL, credentials, and approve/close helpers.
MOCK_CREDENTIALS const Placeholder credentials the mock accepts (not PayPal credentials).
startMockPayPal function Starts the in-process PayPal API mock server.

PayPal and Venmo are trademarks of PayPal, Inc. Not affiliated with or endorsed by PayPal.