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

# Invoices

Create, manage, and collect payment on invoices.

## Create Invoice

```bash theme={null}
curl -X POST https://api.atlas.co/functions/v1/invoices \
  -H "Authorization: Bearer sk_test_xxx" \
  -H "Content-Type: application/json" \
  -d '{
    "customer": "cus_xxx",
    "collection_method": "send_invoice",
    "days_until_due": 30
  }'
```

**Parameters:**

| Parameter           | Type    | Required | Description                                |
| ------------------- | ------- | -------- | ------------------------------------------ |
| `customer`          | string  | Yes      | Customer ID to bill                        |
| `auto_advance`      | boolean | No       | Auto-finalize after 1 hour (default: true) |
| `collection_method` | string  | No       | charge\_automatically or send\_invoice     |
| `days_until_due`    | integer | No       | Days until payment is due                  |
| `description`       | string  | No       | Invoice description                        |

## List Invoices

```bash theme={null}
curl "https://api.atlas.co/functions/v1/invoices?status=open" \
  -H "Authorization: Bearer sk_test_xxx"
```

**Query Parameters:**

| Parameter      | Type   | Description                                |
| -------------- | ------ | ------------------------------------------ |
| `customer`     | string | Filter by customer ID                      |
| `status`       | string | Filter by status (draft, open, paid, void) |
| `subscription` | string | Filter by subscription ID                  |

## Finalize Invoice

Transitions invoice from draft to open, making it ready for payment.

```bash theme={null}
curl -X POST https://api.atlas.co/functions/v1/invoices/inv_xxx/finalize \
  -H "Authorization: Bearer sk_test_xxx"
```

## Pay Invoice

Attempt to collect payment on an open invoice.

```bash theme={null}
curl -X POST https://api.atlas.co/functions/v1/invoices/inv_xxx/pay \
  -H "Authorization: Bearer sk_test_xxx"
```

## Void Invoice

Permanently void an invoice. Cannot be undone.

```bash theme={null}
curl -X POST https://api.atlas.co/functions/v1/invoices/inv_xxx/void \
  -H "Authorization: Bearer sk_test_xxx"
```

## Invoice Statuses

| Status          | Description                             |
| --------------- | --------------------------------------- |
| `draft`         | Invoice is being prepared, not yet sent |
| `open`          | Invoice has been finalized and sent     |
| `paid`          | Invoice has been paid in full           |
| `void`          | Invoice was canceled and is invalid     |
| `uncollectible` | Payment attempts exhausted              |

## Invoice Lifecycle

```
1. Create (draft) → 2. Finalize (open) → 3. Pay (paid)
                                       ↘ Void (void)
```

## Node.js SDK

```typescript theme={null}
import { Atlas } from '@atlas/node';

const atlas = new Atlas('sk_test_xxx');

// Create invoice
const invoice = await atlas.invoices.create({
  customer: 'cus_xxx',
  collection_method: 'send_invoice',
  days_until_due: 30,
});

// Add line items
await atlas.invoices.addLines(invoice.id, [
  { description: 'Consulting (10 hours)', amount: 150000 },
  { description: 'Software license', amount: 29900 },
]);

// Finalize and send
await atlas.invoices.finalize(invoice.id);

// Collect payment
await atlas.invoices.pay(invoice.id);
```

## Webhooks

Listen for invoice events:

* `invoice.created` - New invoice created
* `invoice.finalized` - Invoice finalized and ready for payment
* `invoice.paid` - Invoice paid successfully
* `invoice.payment_failed` - Payment attempt failed
* `invoice.voided` - Invoice was voided
