> ## Documentation Index
> Fetch the complete documentation index at: https://docs.useroutr.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Invoices

> Bill clients in USDC and let them pay with whatever their treasury holds. The invoice marks itself paid.

![A client pays a 1,200 USDC invoice with USDT on Ethereum, DAI on Arbitrum or USDC on Stellar, and it is stamped paid.](https://mintcdn.com/thirtn/tEtIKPxuXx_PTNHq/images/illustrations/use-case-invoices-light.svg?fit=max\&auto=format\&n=tEtIKPxuXx_PTNHq\&q=85\&s=9089f002d775cff4b288d0b3f8c03616)

Hosted checkoutFunding intentsWebhooks

## The idea

You bill 1,200 USDC. Your client's treasury holds USDT on Ethereum. Instead of a thread of emails
about which network, which address and whether the memo matters, your invoice has a **Pay** button.
The client pays with what they hold, and you get exactly 1,200 USDC and a webhook.

## How it plays out

**1. You send the invoice**

Your invoice page shows the amount and a **Pay** button. Nothing is created yet.

**2. The client clicks Pay**

Only now does your server create the funding intent, with the invoice number as its
reference, and send the client to the hosted checkout.

**3. The invoice stamps itself**

`funding.credited` marks the invoice paid. Your accounting can read the same credit from your
[ledger](https://docs.useroutr.com/concepts/balances-and-ledger.md).

## The code

```ts When the client clicks Pay theme={null}
export async function payInvoice(invoice: Invoice) {
  if (invoice.openIntentId) {
    const open = await useroutr.fundingIntents.retrieve(invoice.openIntentId);
    const stillPayable =
      ["CREATED", "AWAITING_PAYMENT", "PARTIALLY_FUNDED"].includes(open.status) &&
      new Date(open.expires_at) > new Date();
    if (stillPayable && open.hosted_funding_url) return open.hosted_funding_url;
  }

  const attempt = invoice.paymentAttempts + 1;
  const intent = await useroutr.fundingIntents.create(
    { amount: invoice.total, asset: "asset_usdc_stellar", reference: invoice.number },
    { idempotencyKey: `${invoice.number}-${attempt}` },
  );
  await saveOpenIntent(invoice.id, intent.id, attempt);
  return intent.hosted_funding_url!;
}
```

```ts Stamp it paid theme={null}
// Inside your webhook handler, after verifying the event
if (event.type === "funding.credited") {
  await markInvoicePaid(event.data.object.reference); // once per invoice: deliveries can repeat
}
```

## Make it your own

* **Partial payments are fine.** A client who sends part of the total moves the intent to
  `PARTIALLY_FUNDED`, and it waits for the rest before it expires.
* **Long invoices, many lines.** Put line items in `metadata` (up to 50 keys) or keep them in your
  own system and use the reference to join.
* **Show it in your books.** Every credit in your ledger links back to its funding intent, and so
  to the invoice.

## Good to know

* An intent takes payment for 24 hours at most, which is why it is created when the client clicks
  **Pay**, not when the invoice is sent.
* A client paying from an exchange may need help if a refund is ever due, because exchanges credit
  their customers by memo. See [Refunds](https://docs.useroutr.com/guides/refunds.md).
* [Payment links](https://docs.useroutr.com/use-cases/coming-soon.md#payment-links), on the roadmap, will make sharing a pay
  link simpler still.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.