Skip to main content
Time: about 30 minutes · Level: intermediate · You’ll build: a backend route that issues a scoped portal session, and a React page that shows the customer’s plan and balance.

Scenario

Your customers want to check their usage and change plans without emailing you. You’ll give each signed-in customer a short-lived portal session. The browser never sees your API key.

Prerequisites

  • A sandbox workspace with a developer API key, and a customer such as cust_tutorial_1.
  • A backend that can keep a secret (Node.js is used here) and a React app.
1

Create a portal session on your backend

Your server checks that the user is signed in to your app, then creates a session for that user’s customer only.
Never take the customerId from the browser. Read it from the signed-in user on your server, or any user could open another customer’s billing.
2

Read the portal token in the browser

The React SDK uses the portal token, not your API key. Pass it to OrvlinProvider. Use getToken if your token expires, so the SDK can request a new one.
The hooks refresh automatically. Show loading and error states so the page never looks empty by mistake.
3

Let customers preview a plan change

Before a customer changes plans, show what it will cost. The preview doesn’t change anything.
Show the result on screen. When the customer confirms, call POST /v1/portal/plan-change with the same plan.
Confirm the plan change with a second click. Plan changes can change the next invoice.
4

Show invoices

Link each invoice to its hosted page from the invoices API, so the customer can pay or download it.
5

Expire and revoke access

Sessions expire on their own. Keep expiresInSeconds short, and create a new session each time the customer opens the billing page. Tokens are scoped to one customer, so a leaked token can’t read another customer’s data.

Production checklist

  • Create sessions only for users who are signed in to your app.
  • Derive the customer ID on the server, never from the request.
  • Keep sessions short-lived.
  • Enable allowCreditPurchases only if you have credit types configured.
  • Show the plan-change preview before every change.

Next steps

Customer portal guide

Every portal endpoint and option.

Portal API reference

Request and response details.