---
title: "Candidate paywalls"
label: "Paywalls"
description: "Build candidate offer selection, embedded checkout, entitlement checks, and billing management."
publishedAt: 2026-07-10
updatedAt: 2026-10-20
order: 10
status: "published"
---

Build the candidate job-access purchase flow. Offers are public, but checkout, checkout state, grants, and billing-portal access all belong to the signed-in candidate.

## Prerequisites

- `board.context().features.candidatePaywall` is `true`.
- Candidate authentication and a completed candidate profile.
- `@stripe/stripe-js` in the browser that mounts embedded checkout.
- A server-owned session for every `board.me.access` request.

## Load offers and the current grant

```ts
// src/data/access.ts
import type { FetchOptions } from '@cavuno/board';

import { board } from '../lib/board';

function session(accessToken: string): FetchOptions {
  return {
    cache: 'no-store',
    headers: { authorization: `Bearer ${accessToken}` },
  };
}

export async function loadAccessPage(accessToken: string) {
  const [context, offers, grant] = await Promise.all([
    board.context(),
    board.paywall.offers(),
    board.me.access.grant(session(accessToken)),
  ]);

  if (!context.features.candidatePaywall) return null;
  return { offers: offers.data, grant };
}
```

`grant` always resolves. No access is `{ hasAccess: false, … }`, not an error. Use it for the rendering decision instead of inferring access from `gatedCount` or a previous checkout redirect.

## Start embedded checkout

```ts
export async function startAccessCheckout(
  accessToken: string,
  offerKey: string, // Use the selected offer.offerKey unchanged.
) {
  return board.me.access.checkout(
    {
      offerKey,
      returnPath: '/account/access',
      colorMode: 'light',
    },
    session(accessToken),
  );
}
```

The response is a mount kit containing `sessionId`, `clientSecret`, `stripeAccountId`, and `publishableKey`. In the browser, initialize Stripe.js with both the publishable key and connected account, then mount embedded checkout with the returned client secret.

```ts
// src/browser/mount-access-checkout.ts
import type { AccessCheckoutSession } from '@cavuno/board';
import { loadStripe } from '@stripe/stripe-js';

export async function mountAccessCheckout(
  kit: AccessCheckoutSession,
  selector: string,
) {
  const stripe = await loadStripe(kit.publishableKey, {
    stripeAccount: kit.stripeAccountId,
  });

  if (!stripe) throw new Error('Stripe.js failed to load');

  const checkout = await stripe.initEmbeddedCheckout({
    clientSecret: kit.clientSecret,
  });

  checkout.mount(selector);
  return () => checkout.destroy();
}
```

Call the returned cleanup function when the checkout view unmounts.

## Confirm access after checkout

```ts
export async function confirmAccess(
  accessToken: string,
  sessionId: string,
) {
  const options = session(accessToken);
  const checkout = await board.me.access.retrieveCheckout(
    sessionId,
    options,
  );

  if (checkout.status !== 'complete') return { checkout, grant: null };
  // A bank debit or transfer that has not cleared: nothing is granted yet.
  if (checkout.paymentStatus === 'processing') return { checkout, grant: null };
  // The bank payment did not go through: nothing was granted.
  if (checkout.paymentStatus === 'failed') return { checkout, grant: null };

  const grant = await board.me.access.grant(options);
  return { checkout, grant };
}
```

An `open` checkout can be remounted with its returned `clientSecret`. An `expired` checkout needs a new session. Even after `complete`, unlock content only when a fresh grant returns `hasAccess: true`.

A `complete` checkout also carries `paymentStatus`. `paid` means the money has arrived, so the grant follows shortly. `processing` means the buyer paid by bank debit or transfer (SEPA, Bacs, ACH) and the money has not cleared. Access is granted only once it does, usually within a few business days, so show a payment-processing message instead of polling the grant, and read the checkout again on the buyer's next visit to see whether it cleared or failed. `failed` means the bank payment did not go through: nothing was granted, and the buyer can start a new checkout.

## Open subscription management

```ts
const portal = await board.me.access.portal(
  { returnPath: '/account/access' },
  session(accessToken),
);

// Redirect to portal.url with your framework.
```

Only recurring grants have a billing portal. Lifetime access does not.

## Expected result

The page shows current public offers and the viewer’s grant. Checkout returns an embedded-checkout mount kit; a completed checkout followed by `grant()` returns the authoritative access decision.

## Verify the result

- Disabled paywalls do not render purchase routes or controls.
- Offer labels and prices come from `board.paywall.offers`.
- Checkout is unavailable without a signed-in candidate profile.
- A browser return does not unlock content until `grant.hasAccess` is true.
- A `complete` checkout with `paymentStatus: 'processing'` shows a payment-processing message, not a spinner that times out.
- A `complete` checkout with `paymentStatus: 'failed'` says the payment did not go through and offers a new checkout.
- Lifetime users never see a recurring-subscription management action.

## Errors and edge cases

- `offers()` returns an empty list when the paywall is disabled.
- Past-due, unpaid, incomplete, canceled, and pending grants can all return `hasAccess: false`; render from both fields without inventing a local status.
- `returnPath` must remain a safe relative path.
- The SDK does not mount Stripe UI or process card details.

## Production cautions

- Never cache grants, checkout state, or portal URLs publicly.
- Keep card handling inside Stripe’s embedded checkout.
- Re-read the grant on every protected server render, not only in the browser.
- Log API request IDs, not checkout secrets or session credentials.

Continue with [Frontend infrastructure](/docs/sdk/frontend-infrastructure) to make these routes canonical, indexable, and visually consistent.
