---
title: "Show orders, invoices and usage"
description: "List an entity's past charges with invoice links, show its metered consumption, and refund an order from the admin tier."
canonical_url: "https://nuxt-backend.dev/docs/build/billing/subscriptions/orders"
---
# Show orders, invoices and usage

> List an entity's past charges with invoice links, show its metered consumption, and refund an order from the admin tier.

Version: nuxt-backend 0.6.x · Tab: Build · Kind: how-to · 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.

- [Try it live in the playground](https://nuxt-backend.dev/playground/settings)
- [API reference](https://nuxt-backend.dev/docs/reference/api/use-orders)
- [Source](https://github.com/qruto/nuxt-backend/blob/main/src/runtime/vue/composables/use-orders.ts)

You show a billing entity its past charges with invoice links and its metered consumption, and an administrator refunds an order.

- **Polar does natively:** orders, invoice PDFs, usage events per meter, refunds, and the same history in its customer portal (checked on 2026-10-25).
- **The package adds:** paged composables and components that read it live, a history that leaves out $0 cycles, and a refund held to the admin tier with a recent sign-in.

The package keeps no order or usage table of its own, because Polar already is the ledger. Every read returns nothing, rather than an error, when no access token is configured.

## Orders and invoices

`useOrders()` pages the entity's past charges from the provider, and `<BillingHistory>` renders them with invoice links:

```vue [app/pages/billing.vue]
<script setup lang="ts">
const { orders, invoice, next, previous, hasMore } = useOrders({ limit: 10 })
// invoice(orderId) opens the invoice in a new tab and resolves with its URL,
// or null while the provider is still generating the PDF, so offer a retry.
// `{ open: false }` hands the URL back without opening it (a download link);
// `{ redirect: true }` opens it in the same tab.
</script>

<template>
  <BillingHistory :limit="10" />
</template>
```

`useOrders({ limit?, immediate?, api? })` returns:

- **The page**: `orders` (`undefined` until the first load), `page`, `total` and `pageCount` (when the provider reports them), `hasMore` and `hasPrevious`.
- **Paging**: `refresh()`, `next()`, `previous()` and `goTo(page)`.
- **State**: `isLoading`, `isPending` (while `invoice` runs), and `error` (`{ code, data, message }`: the last failed `invoice`, else the last failed load). Loads never reject; `invoice` does.
- **invoice(orderId, options?)**: the invoice's URL, opened as above.

Signed-out visitors, and backends that have not deployed `getOrders`, get an empty list rather than an error.

The history lists charges. A subscription's order that charged nothing is left out: a [free plan](https://nuxt-backend.dev/docs/build/billing/catalog#the-free-plan)'s cycle, a trial's start, a cycle a full discount brought to nothing. The provider has no filter for those, so `total` and `pageCount` still count them, and a page may list fewer than `limit`.

## Usage

`useUsage()` pages one credit meter's consumption, the events your server ingested when it spent credits, and `<UsageHistory>` renders it:

```vue [app/pages/usage.vue]
<script setup lang="ts">
const { events, units, next, previous, hasMore } = useUsage({ meter: 'credits', limit: 20 })
</script>

<template>
  <UsageHistory meter="credits" />
</template>
```

`useUsage({ meter?, limit?, immediate?, api? })` returns `events`, `units` (the page's total, once the server reports units per event), the same paging fields as `useOrders`, `isLoading` and `error` (the last failed load). Without `meter` it reads every metered event.

## Refunds

`refundOrder` moves real money, so it is admin-tier. By default only an account with the `admin` role passes, read fresh from the user table; `setupBilling({ requireAdmin })` replaces that check with your own. Either way it refuses an impersonated session, and asks for a sign-in from the last ten minutes ([Require a recent sign-in](https://nuxt-backend.dev/docs/build/auth/access/step-up)). Orders and invoices are for the workspace's billing managers, its owner and admins: see [Decide who manages billing](https://nuxt-backend.dev/docs/build/billing/setup#who-may-buy-for-a-workspace).

`refundOrder` takes:

- `orderId`;
- `amount`, in the currency's minor unit (everything still refundable when omitted);
- `reason`;
- `revokeBenefits`, for a one-time purchase whose benefits should go too.

A refund is recorded on the [activity trail](https://nuxt-backend.dev/docs/build/billing/events#on-the-activity-trail) as `billing.refund_issued`, with the administrator as the actor, and the provider's `order.refunded` that follows as `billing.order_refunded`. A refunded gift that was not claimed yet can no longer be claimed ([Send and receive gifts](https://nuxt-backend.dev/docs/build/growth/offers/gifts#how-a-gift-works)).

## What happens when…

- **The invoice isn't ready.** `invoice(orderId)` resolves `null` while Polar generates the PDF: offer a retry.
- **The caller is a member who doesn't manage billing.** `getOrders` and `getInvoiceUrl` refuse as `forbidden` (reason `not_billing_manager`), and `<BillingHistory>` shows nothing to them.
- **A refund comes from someone who isn't an admin.** `forbidden` (reason `admin_only`). An admin signed in more than ten minutes ago gets `reauthentication_required` ([Require a recent sign-in](https://nuxt-backend.dev/docs/build/auth/access/step-up)).
- **No token is configured.** Every read answers an empty list.

## Limits

- **Live reads.** Each page is a call to Polar, throttled by the `billingSync` limit when you pass a `rateLimiter`.
- **Counts include $0 orders.** Polar has no filter for them, so `total` and `pageCount` count what the list leaves out.
- **No ledger export.** Polar's dashboard exports orders; the package adds none.

## Test it

```ts [test/app/history.test.ts]
import { mountSuspended } from '@nuxt/test-utils/runtime'
import { createBackendMock, resetBackendMock } from 'nuxt-backend/test-utils'
import { afterEach, expect, test } from 'vitest'
import { BillingHistory } from '#components'

afterEach(() => resetBackendMock())

test('the history lists a paid order', async () => {
  const backend = createBackendMock({ user: { name: 'Ada' } })
  backend.stub('billing:getOrders', () => ({
    items: [{ id: 'order_1', createdAt: '2026-10-01T10:00:00Z', status: 'paid', totalAmount: 1200, currency: 'usd', product: { id: 'prod_creator', name: 'Creator' } }],
  }))
  const history = await mountSuspended(BillingHistory)
  expect(history.text()).toContain('Creator')
})
```

## Related

- [Polar](https://nuxt-backend.dev/docs/services/polar): orders, invoices and refunds at the provider.
- [Manage subscriptions](https://nuxt-backend.dev/docs/build/billing/subscriptions): the billing section of `/settings`, which shows both histories.
- [Spend credits in your functions](https://nuxt-backend.dev/docs/build/billing/credits/spending): the spends whose usage events `useUsage()` lists.
- [Decide who manages billing](https://nuxt-backend.dev/docs/build/billing/setup#who-may-buy-for-a-workspace): who reads orders and invoices, and who refunds.
- [`useOrders` reference](https://nuxt-backend.dev/docs/reference/api/use-orders) and [`<BillingHistory>`](https://nuxt-backend.dev/docs/reference/components/billing#billinghistory): every field, prop and slot.


## Sitemap

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