---
title: "Part 2: sell credits"
description: "Declare credit packs and a plan in the billing catalog, sync them to the billing sandbox, show the pricing page, and buy credits with the test card."
canonical_url: "https://nuxt-backend.dev/docs/start/tutorial/credits"
---
# Part 2: sell credits

> Declare credit packs and a plan in the billing catalog, sync them to the billing sandbox, show the pricing page, and buy credits with the test card.

Version: nuxt-backend 0.6.x · Tab: Start · Kind: tutorial · Status: stable

Every page: [llms.txt](https://nuxt-backend.dev/llms.txt) · Skill for coding agents: [nuxt-backend](https://nuxt-backend.dev/.well-known/skills/nuxt-backend/SKILL.md)

Commands use npm; use your project's package manager.

Sell the credits a strip costs: a catalog in code, a sync to Polar's sandbox, the pricing page and a test purchase.

<table>
<thead>
  <tr>
    <th>
      Part
    </th>
    
    <th>
      You add
    </th>
    
    <th>
      Accounts
    </th>
    
    <th>
      Time
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      2. Sell credits
    </td>
    
    <td>
      A credit meter, two packs and a plan, the pricing page, and the balance in the header
    </td>
    
    <td>
      A Polar sandbox
    </td>
    
    <td>
      15 min
    </td>
  </tr>
</tbody>
</table>

## Before you start

You need the app from [Part 1](https://nuxt-backend.dev/docs/start/tutorial/sign-in), running with `npx nuxt-backend dev`. This part adds a Polar sandbox account: sign up at [sandbox.polar.sh](https://sandbox.polar.sh/start), create an organization, and create an organization access token in its settings. The sandbox is free and charges no card. [Polar](https://nuxt-backend.dev/docs/services/polar) covers the account, the token's scopes and what the sandbox does differently.

Credits are Polar's meters. Polar keeps every balance, grant and spend, and the package keeps a cache it can rebuild, so there is no ledger of yours to reconcile.

<steps level="3">

### Declare credits in the catalog

The catalog is your pricing as code. Replace the starter's with Panels' own: a `credits` meter, a free plan with a few credits a month, two packs, and a Studio plan whose `priority_queue` feature gives its strips a head start in Part 4.

```ts [backend/billing.catalog.ts]
import { defineBillingCatalog } from 'nuxt-backend/billing'

export default defineBillingCatalog({
  // US dollars and euros, a native price in each on the same product: the
  // pricing page offers both, and a visitor in any other currency pays in US
  // dollars. The organization's default currency needs a price too, since
  // the provider makes no product without one: billing sync refuses a
  // catalog that leaves it out, so add yours if it is neither.
  currency: 'usd',
  meters: { credits: {} },
  plans: {
    free: {
      name: 'Free',
      prices: { month: 0 },
      credits: { meter: 'credits', units: 30 },
    },
    studio: {
      name: 'Studio',
      prices: { usd: { month: 1200, year: 12000 }, eur: { month: 1200, year: 12000 } },
      credits: { meter: 'credits', units: 400 },
      features: ['priority_queue'],
    },
  },
  packs: {
    credits100: { name: '100 credits', price: { usd: 500, eur: 500 }, credits: { meter: 'credits', units: 100 } },
    credits500: { name: '500 credits', price: { usd: 2000, eur: 2000 }, credits: { meter: 'credits', units: 500 } },
  },
  features: {
    priority_queue: { description: 'Your strips start drawing first' },
  },
})
```

A strip will cost 30 credits, so the free plan draws one strip a month. Prices are in cents, one native price per currency on the same product: Studio and the packs sell in US dollars and euros, and `currency` is the one a visitor in any other currency pays in. Every paid plan and pack needs a price in your Polar organization's default currency too, or `billing sync` refuses the catalog before it creates anything: add yours if it is neither.

### Sync the catalog to the sandbox

Put the sandbox token in `.env.local`:

```bash [.env.local]
BILLING_ACCESS_TOKEN=your_sandbox_access_token
```

Push it to the deployment, then create the catalog in the sandbox:

```bash
npx nuxt-backend env push
npx nuxt-backend billing sync
```

`env push` forwards the token. The deployment's `BACKEND_ENVIRONMENT` is `development`, so billing calls Polar's sandbox, never live Polar. `billing sync` creates the meter, the plans and the packs, and writes their ids to `backend/billing.generated.ts`. Commit that file.

**You should see** `billing` turn from `missing` to `test` in `npx nuxt-backend status`.

### Buy credits with the test card

Open [localhost:3000/pricing](http://localhost:3000/pricing). The module mounts it, and `<PricingTable>` on it lists the plans and packs from the catalog. Press **Top up** on the **100 credits** card. Polar's sandbox checkout opens: pay with the card `4242 4242 4242 4242`, any future expiry and any CVC.

Back in the app, show the balance in the header, so people always know what a strip leaves them. Read it in the layout, and put it in the shell's `#actions` slot, for someone signed in: credits belong to a workspace, so a visitor has none.

```vue [app/layouts/default.vue]
<script setup lang="ts">
const pricing = useBackendPagePath('pricing')
const { isSignedIn } = useAuth()
const credits = useCredits({ meter: 'credits' })
</script>
<!-- … -->
    </template>
    <template #actions>
      <NuxtLink
        v-if="pricing && isSignedIn"
        :to="pricing"
      >
        {{ credits.balance.value ?? '…' }} credits
      </NuxtLink>
    </template>
    <slot />
  </AppShell>
</template>
```

`useCredits` reads the active workspace's balance, live: credits belong to the workspace. When it runs low, `<BackendNotices>` inside the shell shows a low-credits notice with a link to buy more. Set the threshold in app config:

```ts [app/app.config.ts]
export default defineAppConfig({
  backend: {
    billing: { lowCreditsThreshold: 30 },
// …
  },
})
```

**You should see** 130 credits in the header: the free plan's 30, plus the pack. Polar's webhooks cannot reach a deployment on your machine, so the return from checkout refreshes the balance.

</steps>

## Check your work

- `npx nuxt-backend status` shows `billing` as `test`.
- The header reads 130 credits, and `/settings` shows the same balance in its billing section.
- Switch to another workspace. Its balance is its own: credits belong to the workspace that bought them.

## What you used

- `defineBillingCatalog` and `npx nuxt-backend billing sync` ([Define and sync your catalog](https://nuxt-backend.dev/docs/build/billing/catalog)).
- `npx nuxt-backend env push` and Polar's sandbox ([Polar](https://nuxt-backend.dev/docs/services/polar)).
- `<PricingTable>` at `/pricing` ([Customize the pricing page](https://nuxt-backend.dev/docs/build/billing/pricing-page)).
- `useCredits` ([Sell credits and top-ups](https://nuxt-backend.dev/docs/build/billing/credits)).
- `<BackendNotices>` and its low-credits notice ([Show app-wide notices](https://nuxt-backend.dev/docs/build/ui/notices)).

## Next

[Part 3: accept photos](https://nuxt-backend.dev/docs/start/tutorial/uploads) lets people add a photo to a strip, and keeps unsafe uploads out.


## Sitemap

See the full [sitemap](https://nuxt-backend.dev/sitemap.md) for all pages.
