---
title: "Send, receive and manage gifts"
description: "Buy a credit pack for someone else by email with useGifts().send. The purchaser pays on their own billing account and keeps the receipt; the recipient signs in and claims the credits at no cost."
canonical_url: "https://nuxt-backend.dev/docs/build/growth/offers/gifts"
---
# Send, receive and manage gifts

> Buy a credit pack for someone else by email with useGifts().send. The purchaser pays on their own billing account and keeps the receipt; the recipient signs in and claims the credits at no cost.

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/gifts)
- [API reference](https://nuxt-backend.dev/docs/reference/api/use-gifts)
- [Source](https://github.com/qruto/nuxt-backend/blob/main/src/convex/integrations/billing/gifts.ts)

A gift lets someone buy credits for a friend or a teammate who may not use your app yet: the recipient is known only by email. The purchaser pays on their own billing account and gets the provider's receipt and invoice. The recipient signs in with that address and claims the pack into their own account at no cost, and the provider grants them the credits.

- **Natively:** Polar has no gifts. It sells a product at checkout, sends the receipt, grants a pack's credits on a paid or $0 order, and applies a single-use 100% discount (checked on 2026-10-25).
- **The package adds:** a private gift product per pack, the gift record in the `backend` component, the claim by the recipient's proven address, the notice email, refunds before the claim, and the limits that keep gifts from becoming a cash-out route. Your schema needs nothing.

Gifts are credit packs, counted in units of service, never money: no balance and no gift card. A plan can be gifted too, as a [plan pass](https://nuxt-backend.dev/docs/build/growth/offers/plan-passes), and the [gifts page](https://nuxt-backend.dev/docs/build/growth/offers/gifts#manage-gifts) lists what each person sent and received.

## How a gift works

1. **Purchase.** The purchaser buys the pack's gift product on their own billing account: their personal workspace (or the active workspace, when they own it), or their account with `billTo: 'user'`. The gift product is a private twin of the pack that `billing sync` creates beside it, with the same prices and none of its benefits, so the purchase grants the purchaser nothing. Discount codes are off. The checkout carries nothing about the recipient: no customer, name, address or email of theirs.
2. **Fulfilment.** When the provider says the order is paid, by its `order.paid` webhook or as the purchaser comes back from the checkout ([Back from checkout](https://nuxt-backend.dev/docs/build/billing/subscriptions/checkout#back-from-checkout): what settles a gift on a local deployment, which gets no webhooks), the package checks it is the gift's own: the gift product, on the purchaser's account, charged above zero with no discount. It then mints the gift's claim discount (code-free, 100%, once, one redemption, on the pack only, named `gift-<id>`) and emails the recipient.
3. **Claim.** The recipient signs in with the address, which proves it by code, and claims the gift. A claim and the list of received gifts both need the session's email to be verified. The server opens a checkout of the pack on the recipient's own account with the discount locked on, and confirms it itself. The $0 order makes the provider grant the pack's credits to the recipient, with the pack's rollover. A pack that asks for checkout fields opens the provider's $0 checkout to finish instead. The gift counts as received once an order that redeemed its discount is paid, on whichever of the recipient's accounts it landed.
4. **Refund.** Any refund of the purchase before the claim, a partial one too, ends the discount and deletes it: the gift is `refunded` and can't be claimed. A gift is one pack, so a refunded share would otherwise still deliver all of it. A refund the provider reports before the order's `order.paid` voids the pending gift, so it is never delivered.

A refund after the claim can't take back what the $0 order granted. The gift is left to its claim, and the deployment logs `billing.gift_refunded_after_claim`, as `refundOrder` does before it refunds a claimed one. A claim paid after the gift was voided logs `billing.gift_claimed_after_refund`.

## Send a gift

`useGifts().send()` buys a pack for someone else, by the pack's key in `backend/billing.catalog.ts`, and opens the purchaser's checkout:

```vue [app/components/GiftCredits.vue]
<script setup lang="ts">
const gifts = useGifts()
const recipientEmail = ref('')

async function sendGift() {
  await gifts.send('credits500', {
    recipientEmail: recipientEmail.value,
    message: 'For your next strip. Enjoy!',
  })
}
</script>

<template>
  <form @submit.prevent="sendGift">
    <input v-model="recipientEmail" type="email" placeholder="friend@example.com" required>
    <button type="submit" :aria-disabled="gifts.isPending.value || undefined">Send 500 credits</button>
  </form>
</template>
```

`send(item, { recipientEmail, message?, months?, deliverAt?, metadata?, currency?, successUrl?, redirect? })` calls the scaffold's `giftCheckout` action. `item` is a pack's key, or a plan's key with its `months` for a [plan pass](https://nuxt-backend.dev/docs/build/growth/offers/plan-passes#send-a-pass). It is the one way to buy a gift: it replaces `useCredits().gift` and `useBilling().gift`. `currency` pays in one of the currencies the pack is priced in ([Currencies](https://nuxt-backend.dev/docs/build/billing/catalog#currencies)).

A plan's lengths and their live prices come with the pricing: `usePricing().plans` carries `gift` on a giftable plan, `{ lengths: [{ months, amount, currency, monthly, savings? }] }`, shortest first, each from the length's private purchase product in the visitor's currency. `savings` is what a length saves against as many months at the plan's monthly price. While billing is [not launched](https://nuxt-backend.dev/docs/build/billing/setup#before-billing-launches), `send` is refused as `unavailable` (reason `not_launched`) and the gifts page says gifts open with the plans.

### The gift form

`<GiftForm>`, on the `/gifts` page, is that call with its fields: a credit pack or a plan pass, the pass's length (the plan's gift lengths, each at its live price), the recipient's email, a note and a delivery day. Its button says the price ("Pay $27 and send") and opens the purchaser's checkout in the pricing's currency. The `/gifts` page needs a sign-in: a visitor who opens it is sent to sign in and back to the same address, so a link of yours opens the form on one gift with the choice in it (`?pack=credits500`, or `?plan=pro&months=3`). Placed on a page anyone can open, the form's button signs a visitor in first and brings them back with their choice in the address the same way. The purchaser comes back from paying with `?sent=1`, which the form reads as a polite "Paid" and takes off the address. A refusal is an alert, and the field it names is marked invalid.

```vue [app/pages/give.vue]
<template>
  <GiftForm success-url="/give?sent=1" />
</template>
```

`useGiftForm()` is the same form without its markup:

```vue [app/components/GiveCredits.vue]
<script setup lang="ts">
const gift = useGiftForm()
</script>

<template>
  <p v-if="gift.sent.value">Paid. It goes out on the day you picked.</p>
  <form @submit.prevent="gift.send()">
    <label v-for="pack in gift.packs.value" :key="pack.key">
      <input v-model="gift.pack.value" type="radio" :value="pack.key"> {{ pack.name }}
    </label>
    <label>Their email <input v-model="gift.recipientEmail.value" type="email" required></label>
    <button type="submit" :aria-disabled="gift.isPending.value || undefined">
      {{ gift.isSignedIn.value ? `Pay ${gift.choice.value?.price} and send` : 'Sign in to send' }}
    </button>
  </form>
</template>
```

<table>
<thead>
  <tr>
    <th>
      Member
    </th>
    
    <th>
      What it holds
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        kind
      </code>
      
      , <code>
        kinds
      </code>
    </td>
    
    <td>
      <code>
        'pack'
      </code>
      
       or <code>
        'pass'
      </code>
      
      , and the kinds on sale. A <code>
        ?plan=
      </code>
      
       in the address starts on a pass.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        packs
      </code>
      
      , <code>
        pack
      </code>
    </td>
    
    <td>
      The packs on sale, and the one chosen by key (<code>
        ?pack=
      </code>
      
      , else the first).
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        plans
      </code>
      
      , <code>
        plan
      </code>
      
      , <code>
        months
      </code>
      
      , <code>
        lengths
      </code>
    </td>
    
    <td>
      The plans a pass can be bought for (paid, on sale, with <code>
        gift.lengths
      </code>
      
      ), the one chosen, its length, and the lengths it is gifted for with their prices. A length the plan is not gifted for moves to its first.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        recipientEmail
      </code>
      
      , <code>
        message
      </code>
      
      , <code>
        deliverOn
      </code>
    </td>
    
    <td>
      The fields: <code>
        deliverOn
      </code>
      
       is a <code>
        YYYY-MM-DD
      </code>
      
       day in the purchaser's own calendar, sent as 09:00 their time that day, between <code>
        firstDay
      </code>
      
       and <code>
        lastDay
      </code>
      
       (a year after it); empty sends it once paid. <code>
        firstDay
      </code>
      
       is the purchaser's today once the page is on screen, so it is never a day already over for them; while the page hydrates it is today in UTC by the server's clock, as the server rendered it. A day whose 09:00 has passed sends it at once.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        choice
      </code>
    </td>
    
    <td>
      The gift as chosen, with its <code>
        price
      </code>
      
       in words; <code>
        null
      </code>
      
       until something on sale is chosen.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        send()
      </code>
    </td>
    
    <td>
      Signs a visitor in first and resolves <code>
        false
      </code>
      
      ; otherwise opens the checkout and resolves <code>
        true
      </code>
      
      . Never rejects: a refusal is <code>
        error
      </code>
      
      , and <code>
        invalidField
      </code>
      
       names the field it is about (<code>
        recipientEmail
      </code>
      
      , <code>
        message
      </code>
      
      , <code>
        deliverAt
      </code>
      
      ).
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        sent
      </code>
    </td>
    
    <td>
      <code>
        true
      </code>
      
       after the purchaser came back paid.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        isSignedIn
      </code>
      
      , <code>
        isLoading
      </code>
      
      , <code>
        isPending
      </code>
    </td>
    
    <td>
      Who is sending, the pricing's read, and the checkout opening.
    </td>
  </tr>
</tbody>
</table>

`useGiftForm({ successUrl, redirect })` and `<GiftForm>`'s props of the same names choose where the purchaser returns and whether the checkout opens in the same tab (the default).

The server checks, in this order:

1. **The recipient**: a valid address, never the purchaser's own (`forbidden`, reason `gift_refused`).
2. **The message and the date**: the message is plain text of at most 500 characters with no links (`invalid_input`, field `message`). The app shows it only inside the app, never in the email. A `deliverAt` is at most a year ahead (`invalid_input`, field `deliverAt`); a date within the next minute is no date, and the gift is delivered at once.
3. **The return URLs and the metadata**: [the same rules as a checkout](https://nuxt-backend.dev/docs/build/billing/subscriptions/checkout#what-the-server-decides).
4. **The pack**: a catalog pack by its key, never a plan's key, a product id or a key outside the packs (`invalid_input`, field `pack`). Its gift product must exist: an app that has not run `billing sync` since gifts changed is `not_ready` (reason `no_catalog`).
5. **The purchaser's limit**: at most 10 gifts in 30 days by default (`rate_limited`, limit `gifts`). Set it with `setupBilling({ giftLimit: { max, days } })`; a field you leave out keeps its default. Checkouts the purchaser still has open count too. The limit holds again when the order is paid: a gift paid past it, from several checkouts opened at once, is refunded in full instead of delivered (`billing.gift_over_limit`). With a `rateLimiter` configured, each checkout also counts against the `billingSync` limit, keyed by the purchaser.
6. **canGift**, when you pass one ([below](#who-can-receive-a-gift)).
7. **The recipient's email**: outside production, email runs in test mode, and so does a deployment without `EMAIL_API_KEY` or `EMAIL_FROM`. There a real address is refused as `unavailable`, service `email` ([Get email into inboxes](https://nuxt-backend.dev/docs/build/email/delivery/deliverability)). This check comes after your `canGift`, so your refusal is the one the purchaser reads.
8. **An earlier paid order**: the purchaser must have paid for something before, on any workspace they own (`forbidden`, reason `gift_refused`). Otherwise a stolen card could buy gifts for strangers at once and cash itself out.
9. **The address's limit**: one address is sent at most 5 gifts a day (`forbidden`, reason `gift_refused`), so nobody floods an inbox. Like the purchaser's limit, it holds again when the order is paid: a fifth-plus gift paid past it is refunded in full (`billing.gift_over_address_limit`).

## Who can receive a gift

Every address but the purchaser's own is accepted by default. To limit recipients further, to your own domain or to test addresses on a public demo, pass `canGift` to `setupBilling`. `giftCheckout` asks it before it opens the checkout:

```ts [backend/billing.ts]
export const billing = setupBilling(components, {
  catalog,
  email,
  audit,
  canGift: (ctx, { recipientEmail, purchaserUserId, purchaserEntityId }) =>
    recipientEmail.endsWith('@example.com') || { allowed: false, message: 'Gifts go to teammates only.' },
})
```

`recipientEmail` arrives lower-cased, `purchaserEntityId` is the billing entity that pays, and `ctx` is the action's, so the check can read your own tables. A refusal is `forbidden` with reason `gift_refused` and carries your message (default: "This address can't receive gifts."), so it reaches the purchaser even where production hides other errors. `canGift` adds to the package's own rules; it never lifts them.

## Receive gifts

Nothing is claimed until the recipient asks. The gift notice of `<BackendNotices>`, the app-wide notices region, tells a signed-in recipient a gift is waiting and offers to receive it. Override that notice through its named slot, or build your own over `useGifts()`:

```vue [app/pages/gifts.vue]
<script setup lang="ts">
const gifts = useGifts()
</script>

<template>
  <div v-for="gift in gifts.unclaimed.value" :key="gift.id">
    A gift from {{ gift.purchaserName ?? 'someone' }}: {{ gift.message }}
    <button
      :aria-disabled="gifts.isPending.value || undefined"
      @click="gifts.isPending.value || gifts.claim(gift.id)"
    >
      Receive
    </button>
  </div>
</template>
```

`useGifts()` returns:

<field-group>
<field name="received" type="ComputedRef<ReceivedGift[] | undefined>">

The delivered and claimed gifts addressed to the signed-in user's verified email: `id`, `purchaserName` (at most 40 characters, no links), `pack` (or `plan` and `months` for a plan pass), `productIds`, `message`, `status` (`'paid'`, then `'claimed'`), `createdAt`, `paidAt`, `deliveredAt` and `claimedAt`. Never the purchaser's email or a billing id. A gift still at checkout, dated for later, or refunded is not listed.

</field>

<field name="unclaimed" type="ComputedRef<ReceivedGift[]>">

The `paid` ones, claimable now.

</field>

<field name="isLoading / isPending" type="ComputedRef<boolean>">

`isLoading` is `true` until the gift list has loaded (always `false` when signed out, and once the read failed). `isPending` is `true` while a send or a claim runs.

</field>

<field name="error" type="ComputedRef<BackendError | null>">

Why the last send or claim failed, else why the gift list could not be read, else `null`: `{ code, data, message }`, as [Composable conventions](https://nuxt-backend.dev/docs/reference/nuxt/conventions) describes. The list never throws.

</field>

<field name="sent" type="ComputedRef<SentGift[] | undefined>">

The gifts the signed-in user sent, newest first. See [Build on useGifts](#build-on-usegifts).

</field>

<field name="send(item, options)" type="Promise<string>">

Buy a pack, or a plan as a pass, as a gift and open the purchaser's checkout, resolving with its URL. See [Send a gift](#send-a-gift).

</field>

<field name="claim(giftId, { workspaceId?, successUrl?, redirect? })" type="Promise<boolean>">

Claim one gift into a workspace the signed-in user manages, their personal one by default. The session's email must be verified (`forbidden`, reason `no_email`, otherwise). Resolves `true` when the server confirmed the claim: the credits arrive a moment later, once the provider says the $0 order is paid. Resolves `false` after opening the provider's $0 checkout, for a pack that asks for checkout fields. Rejects with the refusal on failure, which `error` also holds.

</field>
</field-group>

`claim` refuses a gift addressed to another email and one that does not exist alike (`forbidden`, reason `not_recipient`), a refunded one (`gift_refunded`), one whose purchase is not paid yet (`not_ready`, reason `not_paid`), and one dated for later (`not_ready`, reason `not_delivered`). In workspace mode a gift is claimed into the recipient's personal workspace unless `workspaceId` names another the recipient manages (`forbidden`, reason `not_member` or `not_billing_manager`).

A gift paid before 0.2 was billed to a customer keyed by the recipient's email. Its claim makes that customer the recipient's own when their personal workspace has none yet, and the credits are already there. Otherwise the gift gets its claim discount then and is claimed like any other.

## The notification email

The notice goes out through `email`, the `setupEmail` instance `setupBilling` takes, once per gift, after the purchase is paid. It names the sender (at most 40 characters, with links and domains taken out) and the pack, and links to `SITE_URL` with no token: the recipient signs in to claim. The purchaser's email and message stay out of it.

The package sends first and stamps the gift after, with the key `nuxt-backend:gift:<id>`. An address the purchaser changed to gets keys of its own (`nuxt-backend:gift:<id>:to<n>`), so the old address's notice never stands in for the new one's:

- **A send that throws**, from a template override or a transient failure, leaves no stamp, so the provider's redelivery of `order.paid` sends it again.
- **An email the deployment cannot deliver at all** is skipped, not thrown: test mode, or no `EMAIL_API_KEY` or `EMAIL_FROM`, after a setting changed since the checkout. The delivery succeeds, your own `order.paid` handler runs, and the log has `email.undeliverable`. Once the setting is fixed, redeliver that `order.paid` event from the provider's webhook dashboard, or [replay it](https://nuxt-backend.dev/docs/ship/operate/replay) from the admin console, and the gift, still unstamped, gets its email. The recipient can claim it in the app meanwhile.
- **A run that sent but failed before stamping** is absorbed by the key while the first email's record exists.
- **Once stamped**, a replay emails nobody, however late it comes.

The default is a minimal, dependency-free template. Restyle it as the `gift` [template](https://nuxt-backend.dev/docs/build/email/templates), with the rest of the package's email:

```ts [backend/email.ts]
import { escapeHtml, setupEmail } from 'nuxt-backend/email'
import { components } from './_generated/api'

export const email = setupEmail(components, {
  templates: {
    gift: ({ recipientEmail, purchaserName, item, claimUrl }) => ({
      to: recipientEmail,
      subject: `${purchaserName ?? 'Someone'} sent you a gift`,
      html: `<p>${escapeHtml(item)} are waiting for you.</p><a href="${claimUrl}">Receive it</a>`,
    }),
  },
})
```

Keep it transactional: a gift notice carries no promotion.

<note>

`npx nuxt-backend billing sync` creates each pack's gift product, private and out of the price list and the checkout allow-list. `billing.generated.ts` lists it under `gifts`, by pack key.

</note>

## On the activity trail

The purchase, the claim and a refund before the claim are recorded as `gift.purchased`, `gift.claimed` and `gift.refunded`, for the purchaser's and the recipient's billing entities. The [events reference](https://nuxt-backend.dev/docs/reference/backend/events#backend-events) has their data. The recipient's address is never on the trail. When an account is erased, a gift stays as a record of a payment, with its purchaser's or recipient's id and address replaced ([What an erasure removes](https://nuxt-backend.dev/docs/build/auth/accounts/data#what-an-erasure-removes)).

## Manage gifts

A gift someone bought for a birthday shouldn't arrive a week early, and a mistyped address shouldn't cost the purchaser their money. The gifts page gives both sides of a gift one place: the purchaser sees what they sent and can fix it until the claim, and the recipient sees what is waiting. The module adds a `/gifts` page, and `useGifts()` carries every action on either side. The purchase, the claim and the guards stay as [Send and receive gifts](https://nuxt-backend.dev/docs/build/growth/offers/gifts) describes: the purchaser pays on their own account and keeps the receipt, the recipient proves the address by signing in, and gifts are units of service, never money.

### Before you start

- A catalog with at least one pack, synced: every pack gets its private gift product ([Define and sync your catalog](https://nuxt-backend.dev/docs/build/billing/catalog#sync)).
- Email that reaches real addresses, for the notice: [Get email into inboxes](https://nuxt-backend.dev/docs/build/email/delivery/deliverability).

### What the page shows

The page opens with [the gift form](#the-gift-form), while billing sells, then has two lists, each for the signed-in person:

- **Received**: gifts for the person's verified address, with who sent them (a name, never an address), the message, what the gift is and its state. A waiting gift offers **Receive it**, with a choice among the workspaces the person manages to claim it into.
- **Sent**: gifts the person bought, each with its recipient and its state: `scheduled`, `delivered`, `claimed` or `refunded`.

Until a sent gift is claimed, the purchaser can:

- **send the notice again**, for a recipient who lost it;
- **change the recipient**, for a mistyped address: the old address can no longer claim it, and the new one gets the notice;
- **change the delivery date** of a gift not delivered yet;
- **cancel**, which refunds the purchase in full through the provider. A cancel asks for a [recent sign-in](https://nuxt-backend.dev/docs/build/auth/access/step-up) first, since it moves money.

A claimed gift can't be cancelled: the provider can't take back what the claim granted. Once the recipient starts a claim, the gift is theirs: it can be neither cancelled nor sent to another address. A cancel holds the gift while the refund goes through, so no claim starts in between.

### Build on useGifts

The page is built on `useGifts()`, so a page of your own gets the same lists and actions:

```vue [app/pages/account/gifts.vue]
<script setup lang="ts">
const gifts = useGifts()
const { withReauthentication } = useReauthentication()

// A cancel moves money: the person confirms a recent sign-in first.
const cancelGift = (giftId: string) => withReauthentication(() => gifts.cancel(giftId))
</script>

<template>
  <section>
    <h2>Sent</h2>
    <article v-for="gift in gifts.sent.value" :key="gift.id">
      {{ gift.item }} to {{ gift.recipientEmail }}: {{ gift.status }}
      <template v-if="gift.status === 'scheduled' || gift.status === 'delivered'">
        <button v-if="gift.status === 'delivered'" type="button" @click="gifts.resend(gift.id)">Send the notice again</button>
        <button type="button" @click="cancelGift(gift.id)">Cancel and refund</button>
      </template>
    </article>
  </section>
</template>
```

`useGifts()` keeps `received`, `unclaimed`, `send`, `claim`, `isLoading`, `isPending` and `error`, and adds:

<table>
<thead>
  <tr>
    <th>
      Member
    </th>
    
    <th>
      What it does
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        sent
      </code>
    </td>
    
    <td>
      The gifts the signed-in person bought: <code>
        id
      </code>
      
      , <code>
        item
      </code>
      
       (the pack's or the plan's catalog key; a plan pass also carries <code>
        plan
      </code>
      
       and <code>
        months
      </code>
      
      ), <code>
        recipientEmail
      </code>
      
      , <code>
        message
      </code>
      
      , <code>
        status
      </code>
      
      , <code>
        deliverAt
      </code>
      
      , <code>
        paidAt
      </code>
      
      , <code>
        deliveredAt
      </code>
      
       and <code>
        claimedAt
      </code>
      
      . <code>
        undefined
      </code>
      
       while loading.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        resend(giftId)
      </code>
    </td>
    
    <td>
      Send the notice again, of a delivered gift: at most one an hour and six in all (<code>
        rate_limited
      </code>
      
      , limit <code>
        giftNotice
      </code>
      
      ). Refused once the gift is claimed (<code>
        forbidden
      </code>
      
      , reason <code>
        gift_claimed
      </code>
      
      ) or refunded, and before it is delivered (<code>
        not_ready
      </code>
      
      , reason <code>
        not_delivered
      </code>
      
      ).
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        changeRecipient(giftId, recipientEmail)
      </code>
    </td>
    
    <td>
      Address an unclaimed gift to someone else, under the same checks as a new gift. Refused once the recipient started a claim (<code>
        forbidden
      </code>
      
      , reason <code>
        gift_claimed
      </code>
      
      ).
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        reschedule(giftId, deliverAt)
      </code>
    </td>
    
    <td>
      Move the delivery date of a gift not delivered yet, up to a year ahead; a date that is now delivers it at once. Refused once it is delivered (<code>
        forbidden
      </code>
      
      , reason <code>
        gift_delivered
      </code>
      
      ), and held to the same rate limit as the other changes.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        cancel(giftId)
      </code>
    </td>
    
    <td>
      Refund the purchase in full and end the gift. Needs a recent sign-in (<code>
        reauthentication_required
      </code>
      
       otherwise). Refused once the recipient has claimed it, or started to (<code>
        forbidden
      </code>
      
      , reason <code>
        gift_claimed
      </code>
      
      ).
    </td>
  </tr>
</tbody>
</table>

The lists themselves, with names, dates and states in the reader's language, are `<GiftList>`, and `useGiftList()` is that without its markup: `received` and `sent` as rows ready to show (`what`, `sender` or `recipient`, `statusText`, `dateText`, and what each still allows: `claimable`, `canResend`, `canChange`, `canReschedule`, `canCancel`), the workspaces a gift can go into, and the actions, whose outcome is `announcement` and refusal `error`, both in words. A cancel asks for a recent sign-in first. A reschedule is dated the way a new gift is: `reschedule(giftId, day)` with a `YYYY-MM-DD` day sends it at 09:00 the purchaser's time that day, as `useGiftForm` sends one, and `firstDay` and `lastDay` are the same bounds, today in the purchaser's calendar to a year after it, for a date input's `min` and `max`. A `datetime-local` value or a `Date` goes out at that moment.

`send` takes `deliverAt`, and `claim` takes the `workspaceId` to claim into, one the recipient manages; without it, the gift goes to their personal workspace. Each action rejects with its refusal, which `error` also holds. Mount `<ReauthenticateDialog>` once in your layout so `withReauthentication` can ask for the sign-in ([Require a recent sign-in](https://nuxt-backend.dev/docs/build/auth/access/step-up#ask-in-the-ui)).

### Send a gift on a date

A gift can arrive later: on a birthday, on a launch day. Pass `deliverAt` to `send`, up to a year ahead:

```ts
await gifts.send('credits500', {
  recipientEmail: 'friend@example.com',
  deliverAt: new Date('2027-03-14T09:00:00Z'),
})
```

The purchase is paid at once, and the notice goes out on the date. The email provider schedules sends only 30 days ahead, so the package keeps the date itself: a scheduled function delivers the notice, and a sweep on the package's own crons, every hour, catches a delivery a restart missed. A recipient can't claim a gift before its delivery date (`not_ready`, reason `not_delivered`), and the gift is listed for them only from then. The scaffold's `billing.ts` exports `runGiftSweep` for both (`npx nuxt-backend upgrade` restores it).

### The message and the notice

A message is plain text of at most 500 characters with no links, shown only inside the app, and never shown before the purchase is paid. The notice email names the sender and the gift and links to the app. It is written in the recipient's language when the app knows it, else the sender's. One reminder goes out when a gift is still unclaimed seven days after it was delivered, from the same `gift` template with `reminder` set. Paid gifts never expire. The notice and the reminder are the only emails: a gift's message, its purchaser's address and any promotion stay out of both.

### Notices in the app

The recipient sees a gift arrive in the gift notice of `<BackendNotices>`, and the purchaser sees it claimed (the `gift.claimed` event, recorded for the purchaser's billing entity beside the recipient's), in the [in-app inbox](https://nuxt-backend.dev/docs/build/email/notifications) once it lands. Both are in-app only, like every billing notice ([Customer emails and notifications](https://nuxt-backend.dev/docs/build/billing/events/customer-emails)).

### Where it lives

The page is a module page like `/settings`. Replace it with a page of your own at `/gifts`, with `<GiftForm>` and `<GiftList>` in it or built on `useGiftForm()`, `useGiftList()` and `useGifts()` ([Replace a page](https://nuxt-backend.dev/docs/build/ui/customize/parts#replace-a-page)).

## What happens when…

<table>
<thead>
  <tr>
    <th>
      Refusal
    </th>
    
    <th>
      When
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <a href="https://nuxt-backend.dev/docs/reference/backend/errors#forbidden">
        <code>
          forbidden
        </code>
      </a>
      
      , reason <code>
        gift_refused
      </code>
    </td>
    
    <td>
      The recipient is the purchaser, the purchaser has never paid before, the address was sent 5 gifts today, or <code>
        canGift
      </code>
      
       said no (with its message).
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        forbidden
      </code>
      
      , reason <code>
        not_owner
      </code>
    </td>
    
    <td>
      A change to a gift its caller did not send.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        forbidden
      </code>
      
      , reason <code>
        gift_claimed
      </code>
      
      , <code>
        gift_delivered
      </code>
    </td>
    
    <td>
      A change after the claim (or while it is under way), or a new date after the delivery.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        forbidden
      </code>
      
      , reason <code>
        not_recipient
      </code>
    </td>
    
    <td>
      The gift is addressed to another email, or does not exist. Both answer alike.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        forbidden
      </code>
      
      , reason <code>
        no_email
      </code>
    </td>
    
    <td>
      The session's email is not verified.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        forbidden
      </code>
      
      , reason <code>
        gift_refunded
      </code>
    </td>
    
    <td>
      The purchase was refunded before the claim.
    </td>
  </tr>
  
  <tr>
    <td>
      <a href="https://nuxt-backend.dev/docs/reference/backend/errors#invalid_input">
        <code>
          invalid_input
        </code>
      </a>
    </td>
    
    <td>
      The message is over 500 characters or holds a link (<code>
        message
      </code>
      
      ), or the pack is no catalog pack (<code>
        pack
      </code>
      
      ).
    </td>
  </tr>
  
  <tr>
    <td>
      <a href="https://nuxt-backend.dev/docs/reference/backend/errors#not_ready">
        <code>
          not_ready
        </code>
      </a>
    </td>
    
    <td>
      The purchase is not paid yet (<code>
        not_paid
      </code>
      
      ), the gift is dated for later (<code>
        not_delivered
      </code>
      
      ), or <code>
        billing sync
      </code>
      
       has not made the gift product (<code>
        no_catalog
      </code>
      
      ).
    </td>
  </tr>
  
  <tr>
    <td>
      <a href="https://nuxt-backend.dev/docs/reference/backend/errors#rate_limited">
        <code>
          rate_limited
        </code>
      </a>
      
      , limit <code>
        gifts
      </code>
    </td>
    
    <td>
      The purchaser reached <code>
        giftLimit
      </code>
      
      . A gift paid past it is refunded in full.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        rate_limited
      </code>
      
      , limit <code>
        giftNotice
      </code>
    </td>
    
    <td>
      A notice was sent again within the hour, or six were sent already.
    </td>
  </tr>
  
  <tr>
    <td>
      <a href="https://nuxt-backend.dev/docs/reference/backend/errors#unavailable">
        <code>
          unavailable
        </code>
      </a>
      
      , service <code>
        email
      </code>
    </td>
    
    <td>
      Email runs in test mode and the recipient is a real address.
    </td>
  </tr>
  
  <tr>
    <td>
      <a href="https://nuxt-backend.dev/docs/reference/backend/errors#reauthentication_required">
        <code>
          reauthentication_required
        </code>
      </a>
    </td>
    
    <td>
      A cancel without a recent sign-in.
    </td>
  </tr>
</tbody>
</table>

## Limits

The package's own rules hold on every gift, whatever your `canGift` adds:

- the purchaser has paid for something before, on any workspace they own;
- a purchaser buys a limited number of gifts in a window (`giftLimit`), and an address receives at most 5 gifts a day, so nobody floods one inbox;
- a notice is resent at most once an hour, and six times in all;
- a gift never goes to the purchaser's own address;
- a gift is a pack or a [plan pass](https://nuxt-backend.dev/docs/build/growth/offers/plan-passes), never money or a balance;
- a refund after the claim can't take back what the $0 order granted.

## Test it

On Polar's sandbox, send a pack to `delivered+gift@resend.dev`, pay with the test card `4242 4242 4242 4242`, and read the notice in the dev inbox. In a backend test, a gift to your own address is refused:

```ts [backend/gifts.test.ts]
import { asUser, defineBackendTestApp } from 'nuxt-backend/test'
import { expect, test } from 'vitest'
import { api } from './_generated/api'
import schema from './schema'

const testApp = defineBackendTestApp(schema, import.meta.glob('./**/*.ts'))

test('nobody gifts to themselves', async () => {
  const ada = await asUser(testApp(), { email: 'ada@panels.example' })
  await expect(ada.action(api.billing.giftCheckout, {
    pack: 'credits500',
    recipientEmail: 'ada@panels.example',
    origin: 'http://localhost:3000',
    successUrl: 'http://localhost:3000/gifts',
  })).rejects.toMatchObject({ data: { code: 'forbidden', reason: 'gift_refused' } })
})
```

## Related

- [Polar](https://nuxt-backend.dev/docs/services/polar): the account, the sandbox and the receipts.
- [Gift a plan as a pass](https://nuxt-backend.dev/docs/build/growth/offers/plan-passes): plan gifts, which the page lists beside packs.
- [Define and sync your catalog](https://nuxt-backend.dev/docs/build/billing/catalog#sync): the private gift product `billing sync` makes for each pack.
- [Customize email templates](https://nuxt-backend.dev/docs/build/email/templates): the `gift` email and its data.
- [`useGifts` reference](https://nuxt-backend.dev/docs/reference/api/use-gifts): every field and action.


## Sitemap

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