MinuteGate quickstart

Mirrors QUICKSTART.md at commit 48a6752.

Two ways to run MinuteGate:

  • Mock mode (start here; it is also the QA path): the full 402 flow end to end against an in-process payment mock. No provider account, no credentials, no outbound network calls to the payment provider.
  • Sandbox mode (payment provider): the same code against the payment provider's sandbox API host, using your own sandbox app credentials from the payment provider.

Payments shown use the payment provider's sandbox only; no real money moves.

Requirements

  • Node.js 20 or newer (node --version)
  • git

1. Install

git clone https://github.com/gilrobertsiii/MinuteGate.git
cd MinuteGate
npm install

npm install adds two development-only packages (typescript, @types/node). The code has no runtime dependencies.

2. Mock mode (no credentials)

npm run quickstart:mock

Expected output (paraphrased; IDs and times will differ):

MinuteGate quickstart (MOCK mode, no credentials)
1. GET http://127.0.0.1:<port>/resource
   -> 402 Payment Required: 1.00 USD per session, reference mg_..., expires ...
2. Create PayPal order
   -> order <id> (CREATED)
3. Buyer step (simulated by the mock)
4. Capture and retry with proof header
   -> 200, receipt (capture id) CAP-...
5. Tamper check: pay 0.01 against a fresh reference and retry
   -> 402, error amount_mismatch
Mock quickstart finished: 1 accepted payment, 1 rejected tamper attempt.

Run the tests (also mock mode):

npm test

The tests cover the accepted path and the rejections: wrong amount, wrong currency, wrong reference, order reuse, buyer step with no capture, a made-up order ID, an unknown or expired reference, and a malformed proof header.

3. Payment provider sandbox mode

You need your own sandbox app on the payment provider's developer portal (Apps & Credentials, Sandbox) and, for the capture step, a sandbox buyer account. Credentials are read from your environment only; never commit them.

cp .env.example .env

Open .env in your editor and fill in your sandbox values there, not at the shell prompt.

Edit .env

# https://api-m.sandbox.paypal.com
PAYPAL_CLIENT_ID=your-sandbox-client-id
PAYPAL_CLIENT_SECRET=your-sandbox-client-secret
set -a; . ./.env; set +a

.env and every other .env* file except .env.example are gitignored.

Sandbox: through order creation

npm run quickstart:sandbox

This requests the resource, gets the 402, creates a sandbox order with the payment provider, prints the buyer link, and stops. It does not capture: capture needs a sandbox buyer to complete the order step first, using your own sandbox credentials.

Sandbox: full flow (two terminals)

Terminal 1, the example server (keeps its references in memory while it runs):

npm run sandbox:server

Terminal 2, the client:

npm run sandbox:client

It prints the buyer link and a follow-up command. Open the link, log in as your sandbox buyer, and complete the order step. Then run the printed command:

npm run sandbox:client -- --reference mg_... --order <order id>

The client captures the order and retries with the proof header. The server looks the order up with the payment provider and answers 200 with the capture ID in minutegate-receipt, or 402 with an error code (see SPEC.md).

Troubleshooting

  • PAYPAL_CLIENT_ID and PAYPAL_CLIENT_SECRET must be set: load your .env (step 3) or use mock mode.
  • PayPal token request failed (401): the credentials are not sandbox app credentials or contain a typo.
  • PayPal POST .../capture failed (422): no sandbox buyer has completed the order step for the order yet.
  • reference_expired: references last 15 minutes; start again from npm run sandbox:client.