Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.

Verify repeatable purchases server-side

Verifying a repeatable purchase on the backend is identity verification plus a per-reference access check. If your server returns content that should only go to customers who bought a specific item — an article, a booking, a report — this guide is what you want.

Steps 1 and 2 are the same as server-side authentication verification. The difference is step 3: instead of looking at productAccess, you ask tiun about the product and reference ID together.

This page is for repeatable one-time products. For regular one-time products and subscriptions, a productAccess check is enough — see server-side subscription verification.


How it works

  1. Your frontend asks tiun for a signed verification token and sends it to your backend with the request for an item.

  2. Your backend exchanges the token with the tiun UserVerification API and gets the userId.

  3. Your backend asks the product access API whether that user has access to the product for that reference ID.

  4. If hasAccess is true, you serve the item.


Setup: API key

Create an API key in the dashboard under API & Webhook → API Keys, then store it in your backend environment variables. Same key as the one used for server-side authentication verification.


1. Get the verification token

Identical to the auth verification flow — call tiun.getUserVerificationToken() on the frontend and send the result to your backend as a Bearer token. Get a fresh token for every request; parallel requests can each fetch their own. See getting the verification token for the snippet.


2. Verify the token on your server

Identical to the auth verification flow — POST the token to the UserVerification API and check isAuthenticated. See verifying the token on your server. Keep user.userId from the response for the next step.


3. Check access for the reference ID

Endpoint:

GET /live_api/s2s/v1/users/{userId}/product_access/{productId}?referenceId={referenceId}

Base URLs:

Environment
URL

Live

https://api.tiun.live

Sandbox

https://api-sandbox.tiun.live

Use the base URL and API key from the same environment as your frontend.

Header: X-TIUN-API-KEY: <your-api-key>

Parameter
In
Description

userId

path

The tiun user ID from the verified response.

productId

path

The repeatable product's ID.

referenceId

query

The reference ID the purchase was made with.

Response codes:

Status
Meaning

200

Access result returned — read the body

400

The request is invalid

401

API key is invalid

404

The user or product does not exist

A 200 response tells you whether the user has access for that reference, and if so, since when and until when:

expiresAt is null unless the product has limited access. Without access, hasAccess is false and there's no access object.


Full round-trip

Frontend — request the item with a verification token. See the repeatable purchases guide for the full frontend side.

Backend — verify the user, then check the purchase for the requested article:


All purchases of a user

To list everything a user has access to — every product and reference ID pair — call the same API without a product:

GET /live_api/s2s/v1/users/{userId}/product_access

It takes the same header and returns the same access objects in a data array:

Use it for a "My purchases" page, or to sync a user's purchases into your own database.

Last updated

Was this helpful?