Skip to main content
Follow these steps in order. You finish with an Express endpoint that refuses an unpaid customer with 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:
Copy 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

Create server.mjs and replace prd_1A2B3C4D with your product reference:
server.mjs
Start it:

4. Call it as an unpaid customer

The SDK identifies the customer by the 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

Open checkoutUrl 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 same curl 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