# Recurring invoices

> Rent, subscriptions and retainers: an invoice the issuer stamps on its own every month, week or day, at the time you choose, without you scheduling anything.

A **recurring invoice** is stamped on its own on each date, with your account's timbres, and sent to the customer if you ask. You don't need a cron or to keep track of which month it's on: Fiscalisto stamps each period only once, even if your server retries or is down.

## Create one

```bash tab="cURL"
curl https://api.fiscalisto.com/v1/recurring_invoices \
  -H "Authorization: Bearer $FISCALISTO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Renta oficina 3",
    "schedule": { "frequency": "monthly", "day_of_month": 1, "hour": 7 },
    "invoice": {
      "customer": {
        "tax_id": "ICV060329BY0",
        "legal_name": "INMOBILIARIA CVA",
        "tax_system": "601",
        "zip": "33826",
        "email": "pagos@cva.example"
      },
      "payment_form": "03",
      "items": [
        {
          "description": "Renta de oficina de {mes} {año}",
          "product_key": "80131500",
          "unit_price": 15000
        }
      ]
    }
  }'
```

```ts tab="TypeScript"
import { Fiscalisto } from "fiscalisto";

// The key comes from FISCALISTO_API_KEY.
const fiscalisto = new Fiscalisto();

const recurringInvoice = await fiscalisto.recurringInvoices.create({
  name: "Renta oficina 3",
  schedule: {
    frequency: "monthly",
    day_of_month: 1,
    hour: 7,
  },
  invoice: {
    customer: {
      tax_id: "ICV060329BY0",
      legal_name: "INMOBILIARIA CVA",
      tax_system: "601",
      zip: "33826",
      email: "pagos@cva.example",
    },
    payment_form: "03",
    items: [
      {
        description: "Renta de oficina de {mes} {año}",
        product_key: "80131500",
        unit_price: 15000,
      },
    ],
  },
});
```

```python tab="Python"
from fiscalisto import Fiscalisto

# The key comes from FISCALISTO_API_KEY.
fiscalisto = Fiscalisto()

recurring_invoice = fiscalisto.recurring_invoices.create({
    "name": "Renta oficina 3",
    "schedule": {
        "frequency": "monthly",
        "day_of_month": 1,
        "hour": 7,
    },
    "invoice": {
        "customer": {
            "tax_id": "ICV060329BY0",
            "legal_name": "INMOBILIARIA CVA",
            "tax_system": "601",
            "zip": "33826",
            "email": "pagos@cva.example",
        },
        "payment_form": "03",
        "items": [
            {
                "description": "Renta de oficina de {mes} {año}",
                "product_key": "80131500",
                "unit_price": 15000,
            },
        ],
    },
})
```

```php tab="PHP"
<?php

use Fiscalisto\Fiscalisto;

// The key comes from FISCALISTO_API_KEY.
$fiscalisto = new Fiscalisto();

$recurringInvoice = $fiscalisto->recurringInvoices->create([
    'name' => 'Renta oficina 3',
    'schedule' => [
        'frequency' => 'monthly',
        'day_of_month' => 1,
        'hour' => 7,
    ],
    'invoice' => [
        'customer' => [
            'tax_id' => 'ICV060329BY0',
            'legal_name' => 'INMOBILIARIA CVA',
            'tax_system' => '601',
            'zip' => '33826',
            'email' => 'pagos@cva.example',
        ],
        'payment_form' => '03',
        'items' => [
            [
                'description' => 'Renta de oficina de {mes} {año}',
                'product_key' => '80131500',
                'unit_price' => 15000,
            ],
        ],
    ],
]);
```

```go tab="Go"
package main

import (
	"context"
	"encoding/json"
	"fmt"
	"log"

	fiscalisto "fiscalisto.com/go"
)

func main() {
	// The key comes from FISCALISTO_API_KEY.
	client, err := fiscalisto.NewClient("")
	if err != nil {
		log.Fatal(err)
	}
	ctx := context.Background()

	recurringInvoice, err := client.RecurringInvoices.Create(ctx, &fiscalisto.CreateRecurringInvoiceParams{
		Name: "Renta oficina 3",
		Schedule: fiscalisto.CreateRecurringInvoiceParamsSchedule{
			Frequency:  "monthly",
			DayOfMonth: json.RawMessage(`1`),
			Hour:       fiscalisto.Int64(7),
		},
		Invoice: fiscalisto.CreateRecurringInvoiceParamsInvoice{
			Customer: fiscalisto.ObjectOf(fiscalisto.InvoiceCreateCustomer{
				TaxID:     "ICV060329BY0",
				LegalName: "INMOBILIARIA CVA",
				TaxSystem: "601",
				Zip:       "33826",
				Email:     fiscalisto.String("pagos@cva.example"),
			}),
			PaymentForm: fiscalisto.String("03"),
			Items: []fiscalisto.InvoiceCreateItem{
				{
					Description: fiscalisto.String("Renta de oficina de {mes} {año}"),
					ProductKey:  fiscalisto.String("80131500"),
					UnitPrice:   fiscalisto.Float64(15000),
				},
			},
		},
	})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(recurringInvoice.ID)
}
```

```java tab="Java"
import com.fiscalisto.FiscalistoClient;
import com.fiscalisto.model.CreateRecurringInvoiceParams;
import com.fiscalisto.model.CreateRecurringInvoiceParamsInvoice;
import com.fiscalisto.model.CreateRecurringInvoiceParamsSchedule;
import com.fiscalisto.model.InvoiceCreateCustomer;
import com.fiscalisto.model.InvoiceCreateItem;
import java.util.List;

// The key comes from FISCALISTO_API_KEY.
var fiscalisto = new FiscalistoClient();

var recurringInvoice = fiscalisto.recurringInvoices().create(new CreateRecurringInvoiceParams()
        .setName("Renta oficina 3")
        .setSchedule(new CreateRecurringInvoiceParamsSchedule()
                .setFrequency("monthly")
                .setDayOfMonth(1)
                .setHour(7))
        .setInvoice(new CreateRecurringInvoiceParamsInvoice()
                .setCustomer(new InvoiceCreateCustomer()
                        .setTaxId("ICV060329BY0")
                        .setLegalName("INMOBILIARIA CVA")
                        .setTaxSystem("601")
                        .setZip("33826")
                        .setEmail("pagos@cva.example"))
                .setPaymentForm("03")
                .setItems(List.of(
                        new InvoiceCreateItem()
                                .setDescription("Renta de oficina de {mes} {año}")
                                .setProductKey("80131500")
                                .setUnitPrice(15000)
                ))));
System.out.println(recurringInvoice.getId());
```

```csharp tab="C#"
using System.Text.Json;
using Fiscalisto;

// The key comes from FISCALISTO_API_KEY.
var fiscalisto = new FiscalistoClient();

var recurringInvoice = await fiscalisto.RecurringInvoices.CreateAsync(new CreateRecurringInvoiceParams
{
    Name = "Renta oficina 3",
    Schedule = new()
    {
        Frequency = "monthly",
        DayOfMonth = JsonDocument.Parse("1").RootElement,
        Hour = 7,
    },
    Invoice = new()
    {
        Customer = new InvoiceCreateCustomer
        {
            TaxId = "ICV060329BY0",
            LegalName = "INMOBILIARIA CVA",
            TaxSystem = "601",
            Zip = "33826",
            Email = "pagos@cva.example",
        },
        PaymentForm = "03",
        Items = new()
        {
            new()
            {
                Description = "Renta de oficina de {mes} {año}",
                ProductKey = "80131500",
                UnitPrice = 15000,
            },
        },
    },
});
```

`invoice` is the same body as [POST /v1/invoices](https://fiscalisto.com/en/docs/api/facturas), without `issuer`, `folio`, `date`, `global` or `metadata`: each invoice takes the next folio of its series (`series`, the default one if you don't send it) and the date of the day it's stamped. It's checked when created with the same rules, so a misspelled RFC or a key that doesn't exist is refused now and not on the day it's due. You can also use a customer from your catalog (`"customer": "cus_…"`) or products (`"product": "prd_…"`): each invoice takes the data the customer has at that moment.

Returns `201` with the recurring invoice (`rin_…`), its next date in `next_invoice_on` and each invoice's total at today's prices.

### How often

| `schedule` | What it does |
| --- | --- |
| `"frequency": "monthly", "day_of_month": 1` | The 1st of every month |
| `"frequency": "monthly", "day_of_month": "last"` | The last day of every month |
| `"frequency": "monthly", "interval": 12` | Once a year |
| `"frequency": "weekly", "interval": 2` | Every two weeks from `start_date` |
| `"frequency": "daily"` | Every day |

`day_of_month` goes from 1 to 28, or `"last"`. `start_date` (YYYY-MM-DD) is the first invoice; if you don't send it, it's the next `day_of_month` (monthly) or today (weekly and daily). `hour` (0 to 23, default 7) is the time it's stamped, in `time_zone` (default the issuing empresa's time zone; one of `America/Mexico_City`, `America/Cancun`, `America/Matamoros`, `America/Mazatlan`, `America/Hermosillo`, `America/Tijuana` and `America/Ciudad_Juarez`).

### Text that changes every month

In `description` write `{mes}`, `{mes anterior}`, `{mes siguiente}`, `{año}`, `{año anterior}`, `{año siguiente}` or `{periodo}` (month, previous month, next month, year, previous year, next year, period) and each invoice fills them with its date: `Renta de oficina de {mes} {año}` comes out as `Renta de oficina de noviembre 2026`. `{periodo}` follows the frequency: the whole month on a monthly one (`1 al 30 de noviembre`), the week on a weekly one (`2 al 8 de noviembre`) and all its months on a multi-month one (`1 de noviembre al 31 de diciembre`). The way you write the variable is the way it comes out: `{mes}` gives `noviembre`, `{Mes}` gives `Noviembre` and `{MES}` gives `NOVIEMBRE` (the same with `{mes anterior}`, `{mes siguiente}` and `{periodo}`, which with `{Periodo}` capitalizes its months). The values are in Spanish, as the CFDI is. The recurring invoice keeps them as written in `items`.

## What it stamps

Each invoice is a normal invoice: `invoice.stamped` reaches your [webhooks](https://fiscalisto.com/en/docs/api/webhooks), it shows up in `GET /v1/invoices` and carries `recurring_invoice` with the id of the recurring invoice that stamped it. `last_invoice` and `last_invoiced_on` say which was the last one.

If a period can't be stamped (timbres ran out, the customer was deleted from the catalog, SAT rejected it), the recurring invoice keeps the reason in `last_error`, `recurring_invoice.failed` arrives once, and it tries again every day at its time until it goes through. With `catch_up: "all"` (default) it later stamps each period left pending, each with its month; with `"latest"`, only the most recent.

## Change it, pause it or stamp now

```bash tab="cURL"
# Pausar (active: true la reanuda desde hoy, sin timbrar lo que pasó en pausa)
curl https://api.fiscalisto.com/v1/recurring_invoices/rin_OufpKqnrvx9p7Hq2mZr1XyT5uBcW8sKdLx \
  -H "Authorization: Bearer $FISCALISTO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "active": false }'
```

```ts tab="TypeScript"
import { Fiscalisto } from "fiscalisto";

// The key comes from FISCALISTO_API_KEY.
const fiscalisto = new Fiscalisto();

const recurringInvoice = await fiscalisto.recurringInvoices.update("rin_OufpKqnrvx9p7Hq2mZr1XyT5uBcW8sKdLx", { active: false });
```

```python tab="Python"
from fiscalisto import Fiscalisto

# The key comes from FISCALISTO_API_KEY.
fiscalisto = Fiscalisto()

recurring_invoice = fiscalisto.recurring_invoices.update("rin_OufpKqnrvx9p7Hq2mZr1XyT5uBcW8sKdLx", {"active": False})
```

```php tab="PHP"
<?php

use Fiscalisto\Fiscalisto;

// The key comes from FISCALISTO_API_KEY.
$fiscalisto = new Fiscalisto();

$recurringInvoice = $fiscalisto->recurringInvoices->update('rin_OufpKqnrvx9p7Hq2mZr1XyT5uBcW8sKdLx', ['active' => false]);
```

```go tab="Go"
package main

import (
	"context"
	"fmt"
	"log"

	fiscalisto "fiscalisto.com/go"
)

func main() {
	// The key comes from FISCALISTO_API_KEY.
	client, err := fiscalisto.NewClient("")
	if err != nil {
		log.Fatal(err)
	}
	ctx := context.Background()

	recurringInvoice, err := client.RecurringInvoices.Update(ctx, "rin_OufpKqnrvx9p7Hq2mZr1XyT5uBcW8sKdLx", &fiscalisto.UpdateRecurringInvoiceParams{
		Active: fiscalisto.Bool(false),
	})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(recurringInvoice.ID)
}
```

```java tab="Java"
import com.fiscalisto.FiscalistoClient;
import com.fiscalisto.model.UpdateRecurringInvoiceParams;

// The key comes from FISCALISTO_API_KEY.
var fiscalisto = new FiscalistoClient();

var recurringInvoice = fiscalisto.recurringInvoices().update("rin_OufpKqnrvx9p7Hq2mZr1XyT5uBcW8sKdLx", new UpdateRecurringInvoiceParams().setActive(false));
System.out.println(recurringInvoice.getId());
```

```csharp tab="C#"
using Fiscalisto;

// The key comes from FISCALISTO_API_KEY.
var fiscalisto = new FiscalistoClient();

var recurringInvoice = await fiscalisto.RecurringInvoices.UpdateAsync("rin_OufpKqnrvx9p7Hq2mZr1XyT5uBcW8sKdLx", new UpdateRecurringInvoiceParams { Active = false });
```

- `POST /v1/recurring_invoices/{id}` changes only what you send: `name`, `schedule`, `send_email`, `catch_up`, `active` or `invoice` (the whole invoice from the next time). `schedule.start_date` moves the next date.
- `POST /v1/recurring_invoices/{id}/skip` skips the next date without stamping.
- `POST /v1/recurring_invoices/{id}/run` stamps the due period now, without waiting for its time; it returns the invoice. If it isn't due yet, `409 recurring_not_due`. If its time arrives meanwhile it isn't stamped twice: it's the same period.
- `DELETE /v1/recurring_invoices/{id}` deletes it; the invoices it stamped stay.

## Limits

An issuer has up to 5,000 active recurring invoices in production and 25 in test mode (paused ones don't count). In test mode they're stamped with the test PAC, like the rest.
