> Index of every page: https://docs.merchantservicedepot.com/llms.txt

# Invoices

> Bill once or on a schedule, and hear when an invoice is paid, fails, or goes overdue.

An invoice bills a saved customer for a total or a set of lines. Through the API you create the invoice and collect it from the customer's saved card on a date you choose. A recurring invoice generates a new invoice every period from a template, so the amount can change between cycles.

## Create an invoice

`POST /v1/invoices` creates the invoice as `draft`. Send a top-level `amount`, or send `items` and let the invoice total itself. For the due date, send `dueAt` or `paymentTerms`, never both.

**Node**

```ts title="server.ts"
// Either a top-level amount…
const invoice = await myela.gateway.invoices.create({
  customerId: customer.id,
  amount: 120000,
  currency: 'USD',
  paymentTerms: 'net_30', // or dueAt — never both
});

// …or items, and the invoice totals itself.
const itemised = await myela.gateway.invoices.create({
  customerId: customer.id,
  currency: 'USD',
  items: [{ description: 'Retainer', quantity: 1, unitAmount: 120000 }],
});
```

**cURL**

```bash title="terminal"
# A top-level amount
curl -X POST https://payments-api-sandbox.merchantservicedepot.com/v1/invoices \
  -H "Authorization: Bearer myela_sk_test_…" \
  -H "Content-Type: application/json" \
  -d '{
    "customerId": "{customerId}",
    "amount": 120000,
    "currency": "USD",
    "paymentTerms": "net_30"
  }'

# Or items, and the invoice totals itself
curl -X POST https://payments-api-sandbox.merchantservicedepot.com/v1/invoices \
  -H "Authorization: Bearer myela_sk_test_…" \
  -H "Content-Type: application/json" \
  -d '{
    "customerId": "{customerId}",
    "currency": "USD",
    "items": [{ "description": "Retainer", "quantity": 1, "unitAmount": 120000 }]
  }'
```

| Field | Type | Meaning |
| --- | --- | --- |
| `customerId` | string | Required. An existing customer. |
| `currency` | string | Required. Three letters. Only two-decimal currencies are accepted. |
| `amount` | integer | The total in minor units. Required unless you send items. With items, it must equal the lines plus tax minus discount. |
| `items` | array | 1 to 100 lines, each \{ description, quantity, unitAmount \}. Description up to 500 characters, quantity 1 to 99,999, unitAmount greater than 0. |
| `amountTax` | integer | Tax in minor units. Only with items. |
| `amountDiscount` | integer | Discount in minor units. Only with items, and less than the total before discount. |
| `dueAt` | ISO 8601 | The due date, as a timestamp. |
| `paymentTerms` | string | due_on_receipt, net_7, net_15, net_30, net_60, or custom. Counted in calendar days from when the invoice is sent, not created. |
| `description` | string | A memo, returned as description. |

Each invoice gets an `invoiceNumber` such as `INV-000123` from a sequence on your account. Gaps in the sequence are normal. An unknown customer is a `404`. These rule breaks come back as `422` with a `details.code`:

| details.code | When |
| --- | --- |
| `INVOICE_TOTAL_MISMATCH` | amount doesn't equal the lines plus tax minus discount. |
| `INVOICE_DISCOUNT_EXCEEDS_TOTAL` | The discount is not less than the total before discount. |
| `INVOICE_TERMS_CONFLICT` | You sent dueAt and a term other than custom. |

## Sending an invoice

`POST /v1/invoices/{id}/deliveries` sends an invoice: `{ "channel": "email", "to": "payer@example.com" }`, or `sms` with a phone number, or `qr` or `copied` with no `to` to mint a link to print or paste. It answers `201` with a `link_delivery`, and its `url` is the invoice's own `url` plus `?d=…` so opens and payments through it are counted. It needs `invoices.create`, and `GET /v1/invoices/{id}/deliveries` needs `invoices.retrieve`.

Sending a `draft` issues it first: the invoice becomes `sent` and gets its `url`, `issuedAt` and `billTo`. A `scheduled` invoice that was never issued a link is refused, because sending would cancel its collection. A paid invoice is `409` `INVOICE_ALREADY_PAID`; a void one, or one that cannot take a payment, is `409` `INVOICE_NOT_PAYABLE`. A draft whose customer was deleted is `404` `SHOPPER_NOT_FOUND`.

Payment terms count from the day an invoice is sent, so a `paymentTerms` invoice has no `dueAt` until then, and scheduling it needs `collectAt`. To get paid through the API alone you can still schedule collection from a saved card, straight from `draft`.

## Collect from a saved card

`POST /v1/invoices/{id}/schedule` tells Myela to charge a saved card on `collectAt`. The invoice moves to `scheduled`. Failed attempts that can be retried are retried on a backoff, and every attempt is listed at `GET /v1/invoices/{id}/attempts`. That list is never paginated; read `data`.

**Node**

```ts title="server.ts"
// Collect it from a saved card. Both arguments are optional: no `collectAt`
// means the invoice's own due date.
const scheduled = await myela.gateway.invoices.schedule(invoice.id, {
  collectAt: '2026-10-01T00:00:00.000Z',
});

if (scheduled.warning) {
  // The schedule is real, and nothing on this environment will act on it.
  // Do not wait for a charge that is not coming.
}

// Why hasn't it been paid?
const { data } = await myela.gateway.invoices.attempts(invoice.id);
```

**cURL**

```bash title="terminal"
# Arm collection (omit paymentMethodId to use the customer's default card)
curl -X POST https://payments-api-sandbox.merchantservicedepot.com/v1/invoices/{id}/schedule \
  -H "Authorization: Bearer myela_sk_test_…" \
  -H "Content-Type: application/json" \
  -d '{ "collectAt": "2026-10-01T00:00:00.000Z" }'

# Every attempt so far
curl https://payments-api-sandbox.merchantservicedepot.com/v1/invoices/{id}/attempts \
  -H "Authorization: Bearer myela_sk_test_…"
```

| Field | Type | Meaning |
| --- | --- | --- |
| `collectAt` | ISO 8601 | When to collect. Defaults to the invoice's dueAt. A date in the past collects on the next pass. |
| `paymentMethodId` | string | Pin a saved card of this customer. Leave it out and any pinned card is cleared; the customer's default card is used when collection runs. |

If you pin a card and it's deleted later, collection doesn't fall back to the default card. The attempt fails with `NO_PAYMENT_METHOD`.

The response is the invoice. It may also carry a `warning` with `code: "INVOICE_SCHEDULER_DISABLED"`. That means the schedule is saved but nothing on that environment will act on it, so don't wait for a charge. Branch on the code; the message varies by environment.

| details.code | Status | When |
| --- | --- | --- |
| `INVOICE_NO_COLLECTION_DATE` | 422 | No collectAt, and the invoice has no dueAt. |
| `STORED_CARD_NOT_FOR_SHOPPER` | 422 | The card belongs to a different customer. |
| `INVOICE_PARTIALLY_PAID` | 409 | Part of the invoice was already paid. It can't be scheduled again; void it. |

Each attempt has an `outcome`:

| outcome | What happens |
| --- | --- |
| `succeeded` | The invoice is paid. |
| `declined` | Retried later. If retries run out, the invoice goes overdue. |
| `failed` | Retried later. If retries run out, the invoice goes overdue. |
| `unpayable` | Not retried. The invoice goes overdue. |
| `underpaid` | Not retried. The invoice goes overdue and can't be scheduled again. |
| `unresolved` | Not retried. Collection freezes until the payment is reconciled. |

While collection is armed, the invoice carries a `collection` object: `collectAt`, the pinned `paymentMethodId` if any, `attemptCount`, `nextAttemptAt` while a retry is due, and `lastFailureCode`, the code from the last failed attempt. Any failure that can't be retried sends the invoice to `overdue` with no retry. For example:

| collection.lastFailureCode | Means |
| --- | --- |
| `NO_PAYMENT_METHOD` | There was no card to charge: the customer has no saved card, or the card you pinned was deleted. Save or pin a card, then schedule the invoice again. |
| `PARTIAL_PAYMENT` | The payment came up short. `amountPaid` shows what was taken. The invoice can't be scheduled again; void it and bill the rest. |
| `STORED_CARD_NOT_FOR_SHOPPER` | The pinned card belongs to a different customer. Pin one of this customer's cards, then schedule again. |

Other codes can appear. Branch on the ones you handle and treat the rest as needing a look.

An `unresolved` charge stops everything. The invoice stays `scheduled`, its `collection.nextAttemptAt` clears, `lastFailureCode` is `UNRESOLVED` or a more specific code, and `pendingConfirmation` appears with the payment's id and when it started. Nothing retries until that payment is reconciled, and there's no automatic sweep to do it for you. Contact Myela with the `paymentId` to have it reconciled.

To stop automatic collection, call `POST /v1/invoices/{id}/cancel_schedule`. A scheduled invoice goes back to `open`; on any other status nothing changes, and the call always succeeds. To end an invoice for good, call `POST /v1/invoices/{id}/void`. Voiding is refused with `409` and `details.code: "PAYMENT_PENDING_CONFIRMATION"` while a charge on the invoice is still being confirmed, because a void invoice can't take the money if that charge went through. It's also refused when that payment came back authorized but was never captured. Void it once the payment is reconciled and nothing is left authorized.

## Invoice PDF

Every invoice carries a `pdfUrl`, which is `GET /v1/invoices/{id}/pdf`. It returns the invoice as a PDF (`application/pdf`), fronted by your business name. Fetch it with the same API key and `invoices.retrieve`; it isn't a public link, so to put an invoice in front of a customer, send it instead.

```bash title="terminal"
curl https://payments-api-sandbox.merchantservicedepot.com/v1/invoices/{id}/pdf \
  -H "Authorization: Bearer myela_sk_test_…" \
  -o invoice.pdf
```

## Statuses and webhooks

| status | Means |
| --- | --- |
| `draft` | Created, not sent. Every invoice created through the API starts here. |
| `open` | Sent, from the dashboard or by a recurring schedule in auto_send mode. A scheduled invoice also comes back here when you cancel its collection. |
| `scheduled` | Collection from a saved card is armed. |
| `paid` | Paid in full. Final. |
| `void` | Ended. Final. |
| `overdue` | Collection stopped without full payment: retries ran out, the failure can't be retried, or the payment came up short. |

A move the invoice can't make, such as scheduling a `paid` invoice, is a `409 conflict`. Collection results arrive as webhooks. Each payload is the invoice, and each event's `id` is stable, so you can drop duplicates.

| Event | When |
| --- | --- |
| `invoice.created` | The invoice was created. |
| `invoice.scheduled` | Automatic collection was scheduled. |
| `invoice.paid` | A collection attempt succeeded. |
| `invoice.payment_failed` | An attempt failed and a retry is scheduled, or a charge went unresolved and collection froze. In the second case there's no nextAttemptAt. |
| `invoice.overdue` | Retries ran out, the failure can't be retried, or the payment came up short. |

Verifying and handling these is covered in [Webhooks](https://docs.merchantservicedepot.com/docs/payments/webhooks/). List invoices with `GET /v1/invoices`. It filters by `status`, `customerId`, `createdAfter` (inclusive) and `createdBefore` (exclusive), and pages are covered in [Pagination](https://docs.merchantservicedepot.com/docs/platform/pagination/).

## Testing collection in the sandbox

Automatic collection is off in the sandbox, so a schedule there can come back with the `INVOICE_SCHEDULER_DISABLED` warning. Instead, call `POST /v1/invoices/scheduler/run`. It collects your account's due invoices now and returns `claimed`, `collected`, and `released` counts. Runs are batched: if `claimed` comes back at the batch limit, call it again.

```bash title="terminal"
# 1. Schedule with a collectAt in the past, so the next pass picks it up
curl -X POST https://payments-api-sandbox.merchantservicedepot.com/v1/invoices/{id}/schedule \
  -H "Authorization: Bearer myela_sk_test_…" \
  -H "Content-Type: application/json" \
  -d '{ "collectAt": "2026-01-01T00:00:00.000Z" }'

# 2. Sandbox only: collect your due invoices now
curl -X POST https://payments-api-sandbox.merchantservicedepot.com/v1/invoices/scheduler/run \
  -H "Authorization: Bearer myela_sk_test_…"
# → { "claimed": …, "collected": …, "released": … }

# 3. See what happened
curl https://payments-api-sandbox.merchantservicedepot.com/v1/invoices/{id}/attempts \
  -H "Authorization: Bearer myela_sk_test_…"
```

Running it twice is safe: each charge is tied to its attempt, so the same attempt isn't charged twice. The route exists only in the sandbox. Anywhere else it answers `403 permission_denied` with `details.code: "SANDBOX_ONLY"`.

## Recurring invoices

`POST /v1/recurring_invoices` creates a schedule that generates a real, itemized invoice each period from its template. Because you can edit the template between cycles, the amount can change. That's the difference from a [subscription](https://docs.merchantservicedepot.com/docs/payments/subscriptions/), whose amount is fixed by its plan.

**Node**

```ts title="server.ts"
const schedule = await myela.gateway.recurringInvoices.create({
  customerId: customer.id,
  name: 'Monthly retainer',
  startDate: '2026-09-01', // a calendar date, not a timestamp
  cadence: { unit: 'monthly', interval: 1, dayOfMonth: 1 },
  template: {
    currency: 'USD',
    items: [{ description: 'Retainer', quantity: 1, unitAmount: 120000 }],
  },
});
```

**cURL**

```bash title="terminal"
curl -X POST https://payments-api-sandbox.merchantservicedepot.com/v1/recurring_invoices \
  -H "Authorization: Bearer myela_sk_test_…" \
  -H "Content-Type: application/json" \
  -d '{
    "customerId": "{customerId}",
    "name": "Monthly retainer",
    "startDate": "2026-09-01",
    "cadence": { "unit": "monthly", "interval": 1, "dayOfMonth": 1 },
    "template": {
      "currency": "USD",
      "items": [{ "description": "Retainer", "quantity": 1, "unitAmount": 120000 }]
    }
  }'
```

| Field | Meaning |
| --- | --- |
| `customerId` | Required. An existing customer. |
| `name` | Required. Your label for the schedule. |
| `mode` | auto_send (default) sends each generated invoice. draft_for_review leaves it as a draft. |
| `cadence.unit` | Required. weekly or monthly. |
| `cadence.interval` | How many units between invoices. Defaults to 1. 3 with monthly is quarterly. |
| `cadence.weekday` | Required for weekly. 0 to 6, where 0 is Sunday. |
| `cadence.dayOfMonth` | Required for monthly unless lastDayOfMonth is set. 1 to 31. In a shorter month, 29 to 31 fall on its last day. |
| `cadence.lastDayOfMonth` | true to bill on the last day. Not with dayOfMonth. |
| `startDate` | Required. YYYY-MM-DD, a calendar date. |
| `endDate` | YYYY-MM-DD or null. Not before startDate. |
| `maxOccurrences` | Stop after this many invoices. |
| `template.amount` | The total in minor units. Required unless you send template.items. |
| `template.items` | Lines as \{ description, quantity, unitAmount \}. Quantity defaults to 1. The total is worked out from the lines. |
| `template.currency` | Defaults to USD. |
| `template.amountTax` | Tax in minor units. |
| `template.amountDiscount` | Discount in minor units. Must be less than the total. |
| `template.description` | A memo on each invoice. |
| `template.paymentTerms` | due_on_receipt, net_7, net_15, net_30, or net_60. custom isn't allowed here. |
| `template.autoCharge` | true charges a saved card through the same collection as schedule. false (default) leaves the invoice for the customer to pay. |
| `template.paymentMethodId` | Pin a saved card. It must belong to the customer. |

There's no daily or yearly cadence. For yearly, use monthly with an interval of 12. A cadence that doesn't fit together is `422` with `RECURRING_INVOICE_CADENCE_INVALID`. Dates are calendar days in your account's timezone, which you set in the Myela dashboard under Settings → Invoicing. No API field sets it.

Each generated invoice carries `recurringInvoiceId` and `billingPeriod`, the period's start date. A schedule makes at most one invoice per period. `template.autoCharge` decides how that invoice is paid, not when it's made.

Generation may not run in the sandbox, and the API has no way to start it: `scheduler/run` only collects invoices that already exist. You may not see generated invoices there.

### Change, pause, or stop a schedule

`POST /v1/recurring_invoices/{id}` takes the same fields, all optional. Template changes apply from the next cycle. Changing the cadence works the next date out again from today, so a month can end up with two invoices with different `billingPeriod` values.

`/pause`, `/resume`, and `/cancel` do what they say. Resume works the next date out from today, so periods missed while paused aren't billed. Schedules can't be deleted; cancel them. On a canceled or completed schedule, pause and resume answer `409 RECURRING_INVOICE_TERMINAL`, and an update answers `409 RECURRING_INVOICE_NOT_EDITABLE`. Cancel is safe to retry: on a schedule that's already canceled it returns the schedule. Canceling a completed schedule answers `409 RECURRING_INVOICE_TERMINAL`.

### Schedule statuses

| status | Means |
| --- | --- |
| `active` | Generating invoices. |
| `paused` | You paused it. Resume to continue. |
| `completed` | endDate or maxOccurrences was reached. Final. |
| `cancelled` | You canceled it. Final. |
| `failed` | Several periods in a row failed to generate, so the schedule parked itself. Resume restarts it. |

When a schedule carries `lastFailureCode`, it's a code, not a message. Once a schedule is canceled or has run out, it has no `nextInvoiceDate`.

Source: https://docs.merchantservicedepot.com/docs/payments/invoices/
