Skip to main content
Let a coding agent (Claude Code, Cursor, Codex, Copilot, or any other) wire SleetPay into your app as its payment method: checkout, webhooks, entitlements and the billing portal. The agent does the code; you do the few dashboard-only steps it will ask for.

Fastest way

These files are served from this docs site, so no GitHub access is needed. If your agent cannot fetch URLs, paste the playbook below instead.
For an agent that can call tools, also add the MCP server in read-only mode: its list_products tool lets the agent discover product and price ids itself.

What the agent can and cannot do

Keep secrets out of the chat: the agent should reference SLEETPAY_API_KEY and SLEETPAY_WEBHOOK_SECRET by name, and you set the values in your own .env or secret manager.

Machine-readable docs

The playbook

The text below is exactly what the agent follows. Read it if you want to know what it will do.

How to use this playbook

You are an AI coding agent asked to make SleetPay the payment method of an application. SleetPay is a Merchant of Record: it charges the buyer, handles tax, refunds and chargebacks, and pays the seller out. Your job is to wire the app to it, end to end, and prove it works. Work in this order: discover, hand off to the human, verify access, implement, test, report. Do not skip the hand-off: some steps exist only in the dashboard and you cannot do them.

Ground rules

  1. You cannot create the account, products, API keys or webhook endpoints. They are dashboard-only (they need a signed-in session; the public API cannot create them). Ask the human at the hand-off in step 2, say exactly what to do and what to give back, then wait.
  2. Secrets never go in chat, git, logs, client bundles or tests. Reference environment variable names (SLEETPAY_API_KEY, SLEETPAY_WEBHOOK_SECRET); put placeholders in .env.example; make sure .env* files are git-ignored; ask the human to set the real values in their secret manager or local .env.
  3. Grant access only from a verified webhook or a server-side state read. Never from the success_url redirect, which anyone can open.
  4. Verify webhooks on the raw request body. Parsing JSON first breaks the signature.
  5. Do not invent ids. Discover product and price ids from the API (step 3).
  6. Amounts are integers in the currency’s minor unit (cents). Never use floats for money.
  7. Do not charge a real card, and do not remove existing payment code (Stripe, Paddle, etc.), without the human’s explicit go-ahead. Propose it, then wait.
  8. Stop and ask about anything outside this playbook: pricing, tax, refund policy, which plans exist.

Step 1. Discover the project

Read the repo and write down, in five lines, before editing anything:
  • Language and framework (Next.js App Router, Express, FastAPI, Django, Rails, …).
  • The auth system and where the stable user id comes from (Better Auth, Auth.js, Clerk, Supabase, custom). That id becomes SleetPay’s external_customer_id, so no mapping table is needed.
  • Where plans or “is this user paid” are checked today, if anywhere.
  • Existing payment code to replace or leave alone.
  • The production URL (needed for the webhook endpoint) and how env vars are managed.
Tell the human your plan in a short message: which recipe in step 4 you will use, which files you will add, and which features (checkout, entitlements, portal; optionally usage, seats, license keys).

Step 2. Hand-off to the human

Ask for these, in one message. Tell them which webhook URL to use (it depends on your recipe). Scopes for the API key (least privilege; add only what the chosen features need): Webhook events to subscribe to (minimum): order.paid, order.refunded, subscription.created, subscription.active, subscription.cycled, subscription.past_due, subscription.paused, subscription.resumed, subscription.canceled, subscription.uncanceled, subscription.revoked, customer.state_changed. Add customer_seat.assigned / customer_seat.revoked for seats and benefit_grant.created / benefit_grant.revoked for benefits. Keys starting sk_live_ move real money. Keys starting sk_test_ belong to a test deployment (Stripe test cards).

Step 3. Verify access and map products

If you have the SleetPay MCP server (@sleetpay/mcp), call list_products instead. Put the mapping in one config file in the app, for example:
If a plan the app needs has no product, ask the human to create it. Do not guess.

Step 4. Implement

Pick the recipe that matches the stack. All of them use the same three server routes plus a webhook: Identity always comes from the server-side session, never from the query string or body.

Recipe A: Next.js (App Router), any auth

The handler reads ?productId=. Link to it as /api/checkout?productId=${PLANS.pro.productId}.
Webhook URL for the human: https://<production-domain>/api/sleetpay/webhook.

Recipe B: Better Auth

Webhook URL for the human: https://<production-domain>/api/auth/sleetpay/webhooks. Better Auth’s base path may differ; confirm it.

Recipe C: Node (Express, Fastify, Hono, …)

Recipe D: Python (FastAPI, Flask, Django)

Flask: request.get_data(). Django: request.body. These SDK calls are synchronous; in an async app run them in a thread pool.

Recipe E: any other language (plain HTTP)

Create a checkout, then redirect the buyer to the returned url:
Verify each webhook (Standard Webhooks):
  1. Read headers webhook-id, webhook-timestamp (unix seconds), webhook-signature.
  2. Reject if the timestamp is more than 300 seconds from now.
  3. Compute "v1," + base64(HMAC_SHA256(key = secret as UTF-8 bytes, message = id + "." + timestamp + "." + rawBody)).
  4. Accept if it equals any space-separated value in webhook-signature (constant-time comparison).
Entitlement read: GET /api/v1/customers/external/{user_id}/state (scope customers:read). Full contract: /api/v1/openapi.json.

Step 4b. Entitlements and webhook handling (all recipes)

Decide what “paid” means in this app, then implement one function the rest of the code calls:
status: "past_due" means a renewal failed and the customer is in the grace period. Treat it as access-with-a-warning unless the human wants it strict. Cache the result per user and refresh it when customer.state_changed arrives (its data is the same document the state endpoint returns). Fall back to a direct read when the cache is empty. Treat events as triggers and the state read as the source of truth. Event meanings overlap: subscription.canceled fires for a cancellation that is scheduled or immediate, and subscription.revoked for one that takes effect now or at period end. So do not delete access because a single event arrived. Re-read the user’s state (or use the customer.state_changed payload, which is that same document) and apply it. Make handlers idempotent. Events are retried (after 15 s, 60 s, then 5 min) and can be replayed, always with the same webhook-id. Store processed webhook-ids (a table with a unique index is enough) and skip repeats. Events can arrive out of order, so when it matters re-read the state instead of trusting the event order. Return 2xx fast; push slow work to a queue. Return 5xx only when you want a retry. UI that is easy to get wrong:
  • Pricing buttons link to your checkout route; the route redirects to SleetPay.
  • The success page may load before the webhook lands. Poll your entitlement endpoint for a few seconds and show “Activating your plan…” rather than “Payment failed”.
  • Add a “Manage billing” link to the portal route wherever users see their plan.

Optional modules

  • Usage-based billing: sleetpay.events.ingest({ name, externalCustomerId, properties, idempotencyKey }). The idempotency key is required; use a stable id such as the request id. The human creates the meter in the dashboard first. Credits: sleetpay.credits.balance(userId).
  • Seats: sleetpay.seats.assign({ subscriptionId, email }), seats.revoke, seats.list({ email }) (an access check). Change quantity with subscriptions.changeSeats.
  • License keys: in the customer’s desktop app or CLI, new SleetPay() (no key) then licenses.activate, licenses.validate. These are public endpoints.
  • Subscriptions from your backend: subscriptions.pause, resume, cancelAtPeriodEnd.

Step 5. Test

Do all of these and show the output to the human:
  1. Typecheck, lint and the existing test suite pass.
  2. Webhook unit tests using signed fixtures. Build the signature with the SDK (signWebhook in TypeScript, sign_webhook in Python) and assert: a good delivery is accepted and grants access; a tampered body, wrong secret and a timestamp older than 5 minutes are rejected with 403; the same webhook-id twice is applied once; a handler error returns 5xx.
  3. Identity test: the checkout route ignores a spoofed externalCustomerId / customerEmail in the query and uses the session user; a signed-out request gets 401 and never calls the API.
  4. Secrets check: git grep -nE "sk_(live|test)_|whsec_" finds only placeholders; .env is ignored; the API key is not referenced from any client-side file.
  5. Live round trip (ask first, it uses real money with sk_live_ keys): with the human’s go-ahead, buy the cheapest product, confirm the webhook arrives (Dashboard > Webhooks > Deliveries shows the status; Replay resends one), the user gains access, “Manage billing” opens the portal, then refund the order from the dashboard and confirm access is removed.

Step 6. Report to the human

End with a short report:
  • Files added or changed.
  • Environment variables the production host needs (SLEETPAY_API_KEY, SLEETPAY_WEBHOOK_SECRET, APP_URL; SLEETPAY_BASE_URL only for self-hosted).
  • The exact webhook URL and events to configure, if not done already.
  • What is verified (list the tests) and what is not (for example: “live purchase not run”).
  • Remaining manual steps (Stripe verification for payouts, removing old payment code once they approve).
  • How to roll back (revert the commit; the dashboard objects are untouched).

Troubleshooting

Reference

  • Guides and API reference: the pages of this site. The machine-readable index is /llms.txt; the whole site as one file is /llms-full.txt.
  • OpenAPI 3.1: https://app.sleetpay.com/api/v1/openapi.json.
  • SDKs: @sleetpay/sdk, @sleetpay/nextjs, @sleetpay/better-auth, @sleetpay/mcp (npm) and sleetpay (PyPI).