402, sends them to checkout, and serves them after they pay in sandbox.
Prerequisites
- A SolvaPay account. Create one if you don’t have one.
- Node.js 20.6 or later (for
node --env-file). - A project directory. An empty one works.
1. Connect the project
From your project root:init signs you in through the browser, writes SOLVAPAY_SECRET_KEY to .env, adds .env to .gitignore, and installs the SolvaPay server packages. See CLI setup for details.
Check that the key in .env starts with sk_sandbox_. If it doesn’t, get a sandbox key from Console > Developers > API Keys and put it in .env yourself.
2. Create a product and a paid plan
Load the key into your shell, then create a product:reference from the response, for example prd_1A2B3C4D. Then add a $20-per-month plan to it:
amountMinor is in cents. Plans covers usage-based, credit, and hybrid plans. You can also create the product in the Console.
3. Protect an endpoint
Createserver.mjs and replace prd_1A2B3C4D with your product reference:
server.mjs
4. Call it as an unpaid customer
x-customer-ref header and creates them in SolvaPay on first use. They have no purchase, so the endpoint answers 402 Payment Required with a JSON body that includes checkoutUrl.
5. Pay in sandbox
OpencheckoutUrl in a browser and pay with the Stripe test card 4242 4242 4242 4242, any future expiry date, and any CVC. Sandbox never charges a real card.
6. Make the first paid call
Run the samecurl again. The customer now has a Pro purchase, so the endpoint returns 200 with the task. This is your first paid call.
In the Console, the customer user_123 and their purchase show up in sandbox.
Next steps
- Identify customers from your own auth instead of a header: Custom auth.
- Framework guides: Express, Next.js, MCP.
- Bill per request: Usage events.
- Go live when you’re ready to take real payments with an
sk_live_key.