Sell Access to Videos
Overview
Transcodely plays a private video for one viewer when the player URL carries a valid playback token. Selling access is connecting two facts: your payment tool knows who paid, and your server signs tokens. This guide shows that connection for Stripe and Polar on your own server: a checkout, a signed webhook that records the purchase, and a watch page that signs a token for the buyer. The same three steps apply to any payment tool that can tell your server, in a way you can verify, that a buyer paid.
Two runnable examples of this flow, one with Stripe Checkout and one with Polar, are in transcodely/examples on GitHub (MIT). They are beta: covered by offline tests only, and not yet run against a real Stripe or Polar account or the live Transcodely player.
On WordPress, the beta Transcodely Video for WordPress plugin signs playback tokens on your server and has access rules per embed, WooCommerce buyers and MemberPress members among them. It is not in the wordpress.org directory: install the zip from its GitHub releases page. It is beta: version 0.1.0 has not been used on a production site or run against the live Transcodely API, and its MemberPress integration has been tested only against stand-ins, never the real plugin.
Transcodely takes no part in the sale. Your payment tool takes the money and keeps the buyer list; your server decides, on every page view, whether this signed-in user may watch. Transcodely only checks that the token is valid and plays the video.
How it fits together
Buyer pays
|
v
Payment tool Stripe or Polar
records it (a signed webhook your server stores)
|
v
Your server on each page view: has this signed-in user paid?
| no --> "buy it first" page, no token
| yes
v
Sign a playback token ptk_..., one video, your opaque user id, 4 hours by default
|
v
Transcodely player https://play.transcodely.com/v/vid_...?token=ptk_...
plays the video until the token expires- The buyer pays in your payment tool. Stripe and Polar record the purchase by sending your server a signed webhook that you store.
- When a signed-in user opens the page with the video, your server asks that record whether this user has paid for it.
- If yes, it signs a playback token for this user and this video and embeds the player with it. If no, it shows a message and no player.
- The player page checks the token’s signature and expiry and plays the video.
The check runs on every page view, so a refund takes effect at the next page load once your server has stored the refund webhook. A token already issued keeps working until it expires: see Limits.
The token every recipe signs
Every recipe signs the same token, described in full in Protected Playback:
| Claim | What the recipes put in it |
|---|---|
vid | The video being sold, vid_…. |
sub | The viewer id: your own opaque user id, 1 to 128 characters and at most 512 bytes once JSON-encoded (a longer one makes the token invalid). Never an email address or a name. The claims are signed, not encrypted, so anyone with the URL can read them. |
exp | Now plus the token lifetime: 4 hours (14400 seconds) by default, 24 hours at most. A later expiry is refused, not shortened. |
ovl | Optional overlay text, up to 80 characters, off by default. Turn it on to draw something that identifies the buyer over the video. |
Sign the token on your server with the app’s playback signing key (psk_… id and its whole pss_… secret). The official SDKs have a helper that does it locally, with no network call (signPlaybackToken in @transcodely/sdk 0.3.27 and later, shown here; Python and Go are in On your server, next to standard-library functions for stacks without the SDK):
import { signPlaybackToken } from '@transcodely/sdk';
const token = signPlaybackToken({
keyId: process.env.TRANSCODELY_PLAYBACK_KEY_ID, // psk_…
secret: process.env.TRANSCODELY_PLAYBACK_SECRET, // the whole pss_… string
videoId: 'vid_a1b2c3d4e5f6g7',
viewerId: user.id, // your opaque user id, never an email
expiresIn: 14400, // 4 hours, the default; 86400 at most
});
const src = `https://play.transcodely.com/v/vid_a1b2c3d4e5f6g7?token=${encodeURIComponent(token)}`;You can also let the API sign it with one server-side call to VideoService.CreatePlaybackToken (Or let the API sign it). Either way, make the video private so it never plays without a token, and send the watch page with Cache-Control: private, no-store: the page belongs to one viewer.
Stripe
For a site of your own, the shape is a checkout, a webhook and a watch page. The snippets below are Node.js with the standard library only; they are the parts that decide access, not a complete application.
1. Checkout. When a signed-in user clicks Buy, your server creates a Checkout Session (POST https://api.stripe.com/v1/checkout/sessions with mode=payment, the product’s price and a success_url) and redirects to the URL Stripe returns. On the server, set client_reference_id, which Stripe describes as a way to reconcile the session with your own systems, to your user id, and put the user id and product in metadata (Create a Checkout Session, accessed 2026-11-28). The browser never chooses who the purchase is for. Do not grant access when the buyer lands on success_url: anyone can open that URL. Only the verified webhook grants.
2. Webhook. Verify the Stripe-Signature header over the raw request body before trusting anything in it (Verify signatures manually, accessed 2026-11-28). Stripe also warns not to parse or re-serialise the body before verifying it (Webhooks, accessed 2026-11-28):
import { createHmac, timingSafeEqual } from 'node:crypto';
// Stripe-Signature: t=<timestamp>,v1=<hex signature>[,v1=…][,v0=…]. Keep t and every v1,
// ignore any other entry. Expected = HMAC-SHA256(endpoint secret, t + "." + raw body).
// rawBody is the request body as raw bytes (for example from express.raw({ type: 'application/json' })),
// never JSON your framework has already parsed.
export function verifyStripeSignature(rawBody, header, secret, now = Math.floor(Date.now() / 1000)) {
let t = '';
const v1 = [];
for (const part of String(header ?? '').split(',')) {
const i = part.indexOf('=');
if (i < 0) continue;
const key = part.slice(0, i).trim();
if (key === 't') t = part.slice(i + 1).trim();
if (key === 'v1') v1.push(part.slice(i + 1).trim());
}
if (!/^d+$/.test(t) || v1.length === 0) return false;
const expected = createHmac('sha256', secret).update(`${t}.`).update(rawBody).digest();
const valid = v1.some((sig) => /^[0-9a-f]{64}$/i.test(sig)
&& timingSafeEqual(Buffer.from(sig, 'hex'), expected));
return valid && Math.abs(now - Number(t)) <= 300; // Stripe's libraries default to 5 minutes
}Then act on three events (event types, fulfilment, the Checkout Session object, the Charge object, accessed 2026-11-28):
| Event | What your server does |
|---|---|
checkout.session.completed | Grant access if the session’s payment_status is paid (“the payment funds are available”). unpaid means a delayed method such as a bank debit is still pending: wait. |
checkout.session.async_payment_succeeded | The delayed payment succeeded: grant access. |
charge.refunded | Sent for full and partial refunds. Stop new tokens only when the charge’s refunded is true, which Stripe sets only for a full refund. |
switch (event.type) {
case 'checkout.session.completed':
case 'checkout.session.async_payment_succeeded': {
const session = event.data.object;
if (session.payment_status !== 'paid') break; // a bank debit may still be pending
// Your server set these when it created the session, and the event body is signed.
if (!PRODUCTS.has(session.metadata?.product_key)) break; // PRODUCTS: a Map of your own catalog
grant(session.payment_intent, session.client_reference_id, session.metadata.product_key);
break;
}
case 'charge.refunded': {
const charge = event.data.object;
if (charge.refunded) refund(charge.payment_intent); // true only for a full refund
break;
}
}Stripe can deliver an event more than once and does not promise their order (Webhooks, accessed 2026-11-28). Record each event.id and skip one you have seen, key purchases by the PaymentIntent id, and let a stored refund win over any later “paid” event for the same payment. The handler reads data.object, so the webhook destination must send snapshot payloads (for local testing, stripe listen --all-snapshot --forward-to localhost:4242/webhooks/stripe) (Set up events, accessed 2026-11-28).
3. Watch page. Look up a paid, unrefunded purchase for this signed-in user and this product; only then sign the token as in The token every recipe signs.
Not covered here: disputes (charge.dispute.created; handle them like refunds if a chargeback should stop access). The handler above grants only on payment_status paid; whether a session paid in full with a 100% discount reports paid or no_payment_required has not been checked, so test it in test mode if you give past buyers free access with coupons.
Polar
The same shape with Polar.
1. Checkout. Your server creates a checkout with POST /v1/checkouts/ and a Polar-Version: 2026-10 header, authenticated with an organization access token that has the checkouts:write scope, sent as a bearer token. Never send the token to the browser. Pass products, success_url, your user id as external_customer_id, and metadata with your user id and product. Polar copies checkout metadata to the order it creates (Checkout sessions, accessed 2026-11-28). Redirect the buyer to the checkout’s url. As with Stripe, do not grant access when the buyer lands on success_url; only the verified webhook grants.
2. Webhook. Polar signs webhooks with the Standard Webhooks scheme (Webhook delivery, Standard Webhooks specification, accessed 2026-11-28): the webhook-signature header carries v1,<base64 HMAC-SHA256> of {webhook-id}.{webhook-timestamp}.{raw body}. The HMAC key depends on when the endpoint secret was created: on or after 2026-09-08 it is the base64-decoded part after whsec_; before that, the UTF-8 bytes of the whole whsec_… string. Polar’s own SDKs try both, and so can you:
import { createHmac, timingSafeEqual } from 'node:crypto';
export function verifyPolarSignature(rawBody, headers, secret, now = Math.floor(Date.now() / 1000)) {
const id = headers['webhook-id'];
const ts = headers['webhook-timestamp'];
const signatures = headers['webhook-signature'];
if (!secret || !id || typeof signatures !== 'string' || !/^d+$/.test(ts ?? '')) return false;
if (Math.abs(now - Number(ts)) > 300) return false; // Polar's SDKs allow 5 minutes
const keys = [Buffer.from(secret, 'utf8')]; // secrets created before 2026-09-08
if (secret.startsWith('whsec_')) keys.push(Buffer.from(secret.slice(6), 'base64'));
const expected = keys.filter((key) => key.length > 0)
.map((key) => createHmac('sha256', key).update(`${id}.${ts}.`).update(rawBody).digest());
return signatures.split(' ').some((entry) => {
const [version, value] = entry.split(',');
const got = version === 'v1' && value ? Buffer.from(value, 'base64') : Buffer.alloc(0);
return got.length === 32 && expected.some((e) => timingSafeEqual(got, e));
});
}Answer a bad signature with 403, and an event you do not handle with 202 so Polar does not retry it. Polar retries failed deliveries and keeps webhook-id the same on every retry and redelivery: record it and skip one you have seen.
Then act on two events (Webhook events, accessed 2026-11-28; order fields from Polar’s OpenAPI schema, accessed 2026-11-28):
| Event | What your server does |
|---|---|
order.paid | Grant access if the order’s paid is true, its product_id is the product you sell, and its metadata names your user. Polar recommends this event for fulfilling one-time purchases. |
order.refunded | Sent for full and partial refunds. Stop new tokens when the order’s status is refunded; partially_refunded keeps access unless you decide otherwise. |
Take the user from the order’s metadata, which your server set, and key purchases by the order id. For subscriptions, Polar recommends customer.state_changed for access control instead.
3. Watch page. As for Stripe: sign a token only when your database has a paid, unrefunded purchase for this user and this product.
Sold on Vimeo On Demand?
Vimeo On Demand shut down on 20 November 2026, and buyers’ access ended with it (Vimeo, accessed 2026-11-30). If you sold videos there, the set-up on this page replaces it: your payment tool sells, Transcodely hosts and plays.
- The videos can come across if you still have them: upload them to Transcodely and make them
private. - Purchases and buyers cannot be moved by us. Who bought what lived with Vimeo’s store, not with the video files.
- Re-issue access yourself, with whatever buyer details you kept: for example, send past buyers a coupon code that makes the product free, or record their purchases in your own database by hand. From then on they are ordinary buyers, and the recipes above apply to them.
Limits
- We do not process payments, hold buyer lists, or decide who has paid. Your payment tool and your server do. Transcodely plays a video for a valid token and nothing else: no checkout, tax, coupons, receipts or payouts.
- A token cannot be revoked on its own; it expires. A refund stops new tokens from the next page load after your server has stored the refund webhook. The token the buyer already has keeps working until its
exp, so at most for the token lifetime: 4 hours by default, 24 hours at most. For a faster cut-off, shortenexpiresIn; playback stops when a token expires, so leave room for the lesson plus a pause or two. - Cutting tokens early cuts every token of a key. Rotating a playback signing key with
expire_previous_in: 0refuses every token that key signed, for every viewer, at the next page load (tokens signed by the app’s other active keys keep working). Put the new key id and secret on your server straight away, or no new token plays. A player already open keeps playing until its stream URLs expire, at the token’sexpor 6 hours after it loaded, whichever is first. See Rotation is how you revoke. - The overlay is a visible deterrent, not copy protection. A determined viewer can remove it, record the screen, or share a valid token until it expires, and it is not visible in the iPhone’s native video fullscreen. Protected playback is not DRM. See what it does not protect against.
- The viewer id is opaque, never an email. Put your own user id in
sub. Transcodely receives the viewer id in each token and keeps viewing progress under it, so it should mean nothing outside your own database. Token claims are readable by anyone who sees the URL; put an email in the overlay only if you accept that.
Next steps
- Protected Playback: the token format, signing keys and rotation, allowed embed domains.
- Course Progress: mark lessons complete from what the buyer actually played.
- Webhook Integration: receive Transcodely’s own signed events on your server.