Skip to main content

Overview

SolvaPay bills and meters on the server side. Your product keeps its own client (CLI, web app, mobile) and its own identity provider (Auth0, Cognito, a custom IdP, or a provider CLI like login / init). Your backend holds sk_* and links each signed-in user to a SolvaPay customer via a stable externalRef. This is the canonical integration shape when you own the customer experience. SolvaPay does not need a credential in the CLI, a SolvaPay-hosted approval page, or IdP access tokens on SolvaPay APIs.

Quick start (any Node backend)

ensureCustomer is idempotent: repeated calls with the same externalRef return the same SolvaPay customerRef.

The externalRef contract

REST equivalent

The SDK wraps existing SDK customer endpoints:
  • GET /v1/sdk/customers?externalRef= — find by linkage
  • POST /v1/sdk/customers — create with { externalRef, email, name }
  • PATCH /v1/sdk/customers/:reference — update externalRef on an existing customer
ensureCustomer implements find-or-create-by-externalRef so you do not need to manage that flow yourself.

Provider-owned CLI pattern

A provider that ships its own CLI (for example your-cli login backed by Auth0) already has an authenticated user id after login. The CLI talks to your API; your API calls SolvaPay:
  1. CLI completes your IdP login and stores your session token (not sk_*).
  2. CLI calls your backend with that session.
  3. Backend resolves externalRef from the session (e.g. JWT sub).
  4. Backend calls ensureCustomer(externalRef) then trackUsage / payable / checkLimits.
No SolvaPay device flow or hosted handoff is required. See the runnable reference: express-provider-linkage example.

Web app pattern (Auth0 reference)

For Next.js + Auth0, the SDK ships a ready reference that forwards session.user.sub as billing identity: The Auth0 path is one linkage implementation. The same externalRef contract applies with any IdP.

Protecting routes after linkage

Once you have customerRef, pass it into paywall helpers:
For Next.js, prefer createAuth0AuthMiddleware (or your own adapter) so route handlers receive x-user-id / externalRef automatically. For Express and other frameworks, resolve externalRef in middleware, call ensureCustomer, then set x-customer-ref for payable.http().

What not to do

  • Do not put SOLVAPAY_SECRET_KEY in a customer CLI or browser.
  • Do not send Auth0 (or other IdP) access tokens to SolvaPay APIs.
  • Do not rely on email alone as externalRef — emails can change; subjects and internal ids should not.
  • Do not assume SolvaPay will host your customer login — use customer OAuth only when your OAuth clients need SolvaPay as the authorization server (e.g. MCP / third-party apps), which is separate from provider-owned CLI linkage.