# Cancel and replace

> How a CFDI is cancelled at SAT, when the customer must accept it and how to correct an invoice with another that replaces it.

A stamped CFDI isn't edited: if it has an error it's cancelled and, if needed, another one is issued that replaces it. Fiscalisto requests the cancellation from SAT with the issuer's CSD.

## Cancel

```bash tab="cURL"
curl https://api.fiscalisto.com/v1/invoices/inv_OufpKqnrvx9p0Nfbydl9jG4UNGeTYcvdrg/cancel \
  -H "Authorization: Bearer $FISCALISTO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "motive": "02" }'
```

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

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

const invoice = await fiscalisto.invoices.cancel("inv_OufpKqnrvx9p0Nfbydl9jG4UNGeTYcvdrg", { motive: "02" });
```

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

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

invoice = fiscalisto.invoices.cancel("inv_OufpKqnrvx9p0Nfbydl9jG4UNGeTYcvdrg", {"motive": "02"})
```

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

use Fiscalisto\Fiscalisto;

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

$invoice = $fiscalisto->invoices->cancel('inv_OufpKqnrvx9p0Nfbydl9jG4UNGeTYcvdrg', ['motive' => '02']);
```

```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()

	invoice, err := client.Invoices.Cancel(ctx, "inv_OufpKqnrvx9p0Nfbydl9jG4UNGeTYcvdrg", &fiscalisto.CancelInvoiceParams{
		Motive: fiscalisto.String("02"),
	})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(invoice.ID)
}
```

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

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

var invoice = fiscalisto.invoices().cancel("inv_OufpKqnrvx9p0Nfbydl9jG4UNGeTYcvdrg", new CancelInvoiceParams().setMotive("02"));
System.out.println(invoice.getId());
```

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

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

var invoice = await fiscalisto.Invoices.CancelAsync("inv_OufpKqnrvx9p0Nfbydl9jG4UNGeTYcvdrg", new CancelInvoiceParams { Motive = "02" });
```

Right after stamping, SAT doesn't have the invoice on record yet: it takes a few minutes (up to 5 in test mode). If you cancel before that, the API returns `409` `cancellation_too_early` with `Retry-After: 60`, without cancelling anything or using timbres: repeat the same request a minute later. If you're cancelling to correct it, better [replace it](#replace): Fiscalisto retries on its own.

SAT requires one of four reasons (`motive`):

| Reason | When |
| --- | --- |
| `01` | It has errors and you already issued the one that replaces it: send `substitution` with its id or UUID. Better use [replace](#replace). |
| `02` | It has errors and won't be replaced. It's the one used if you don't send `motive`. |
| `03` | The operation didn't take place. |
| `04` | Only on a global invoice: a sale included in it was later invoiced in the customer's name, so the global is cancelled (and another is issued without that sale). On another invoice it returns `cancellation_failed`. |

## When the customer must accept it

If the invoice is over $1,000 and isn't one of SAT's exceptions, the customer has to accept the cancellation in their buzón tributario (SAT inbox). Meanwhile the invoice stays `status: "pending"`, with `cancellation.status: "pending"`, and remains current. Then one of these events arrives:

- `invoice.canceled`: they accepted it, or didn't answer within 3 business days and SAT took it as accepted.
- `invoice.cancellation_rejected`: they rejected it, or the request expired. You can request it again.

These are cancelled right away, without acceptance: invoices up to $1,000, credit notes, transfers, payroll receipts, invoices to the general public or to a foreigner, and any invoice cancelled no later than the business day after it was issued (rule 2.7.1.35, section IX, of the RMF 2026): one from Friday, until Monday, or Tuesday if Monday is a holiday. Withholding certificates are also cancelled right away. Fiscalisto asks SAT for a few seconds until it sees it cancelled; if SAT takes longer, the response carries `cancellation.status: "pending"` without the customer having to do anything, and `invoice.canceled` arrives within minutes.

Diesel and gasoline are the exception (rule 2.7.1.34, third paragraph, of the RMF 2026): an invoice or credit note for them (keys `15101505`, `15101514` and `15101515`, with the Hidrocarburos y Petrolíferos complement) and an invoice with Carta Porte that carries them always need the customer's express acceptance, whatever the amount or the day. If the customer doesn't answer, the invoice stays current. Only an invoice to the general public or to a foreigner with the generic RFC cancels without acceptance (rule 2.7.1.35, last paragraph).

If you request the cancellation again while waiting for the customer, the API returns the current status without sending another request. With another `motive` it returns `400` with `param: "motive"`: SAT never changes the motive of a cancellation already requested. If you look up the invoice with `?refresh=true`, Fiscalisto asks SAT for its status at that moment.

## When Fiscalisto asks again

Sometimes SAT doesn't accept the request yet: it doesn't have the invoice that replaces this one on record (it takes a few minutes), or it briefly rejected its signature. Fiscalisto asks again on its own, and the invoice says so in `cancellation`, even though it's still current. And if SAT took the request but 3 hours later still doesn't show it (neither «En proceso» nor cancelled), it didn't get there: Fiscalisto asks again with the same reason, up to twice, and the invoice stays `pending`:

| `cancellation.status` | What happens |
| --- | --- |
| `scheduled` | Fiscalisto asks again on its own. `next_attempt_at` says when (`null`: within the next 15 minutes) and `error` why it didn't go through. `invoice.cancellation_pending` arrives, then `invoice.canceled` once SAT cancels it. |
| `failed` | Fiscalisto stopped trying and the invoice is still current; `error` says why. `invoice.cancellation_failed` arrives. Request it again with [`POST /v1/invoices/{id}/cancel`](https://fiscalisto.com/en/docs/api/referencia/facturas/cancel-invoice), and for a replacement, with reason `01` and the new one in `substitution`. |

With `pending`, on the other hand, SAT already has the request. If the authorized PAC doesn't answer the request and SAT doesn't show it yet, the response is `pending` too: the request may have arrived. Fiscalisto asks SAT every 15 minutes; `invoice.canceled` arrives if SAT cancelled it and, if SAT still doesn't show it 3 hours later, it is requested again as above.

## The cancellation receipt

Once SAT cancels the invoice (`status: "canceled"`), [`GET /v1/invoices/{id}/cancellation_receipt`](https://fiscalisto.com/en/docs/api/referencia/facturas/get-invoice-cancellation-receipt) downloads its acuse de cancelación: the XML signed by SAT that proves it cancelled it and when. Keep it with the invoice for a SAT review or a dispute with the customer.

```bash tab="cURL"
curl https://api.fiscalisto.com/v1/invoices/inv_OufpKqnrvx9p0Nfbydl9jG4UNGeTYcvdrg/cancellation_receipt \
  -H "Authorization: Bearer $FISCALISTO_API_KEY" \
  -o acuse-cancelacion.xml
```

```ts tab="TypeScript"
import { writeFile } from "node:fs/promises";
import { Fiscalisto } from "fiscalisto";

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

await writeFile("factura.xml", await fiscalisto.invoices.cancellationReceipt("inv_OufpKqnrvx9p0Nfbydl9jG4UNGeTYcvdrg"));
```

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

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

with open("factura.xml", "w", encoding="utf-8") as f:
    f.write(fiscalisto.invoices.cancellation_receipt("inv_OufpKqnrvx9p0Nfbydl9jG4UNGeTYcvdrg"))
```

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

use Fiscalisto\Fiscalisto;

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

file_put_contents('factura.xml', $fiscalisto->invoices->cancellationReceipt('inv_OufpKqnrvx9p0Nfbydl9jG4UNGeTYcvdrg'));
```

```go tab="Go"
package main

import (
	"context"
	"log"
	"os"

	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()

	xml, err := client.Invoices.CancellationReceipt(ctx, "inv_OufpKqnrvx9p0Nfbydl9jG4UNGeTYcvdrg", nil)
	if err != nil {
		log.Fatal(err)
	}
	if err := os.WriteFile("factura.xml", []byte(xml), 0o644); err != nil {
		log.Fatal(err)
	}
}
```

```java tab="Java"
import com.fiscalisto.FiscalistoClient;
import java.nio.file.Files;
import java.nio.file.Path;

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

Files.writeString(Path.of("factura.xml"), fiscalisto.invoices().cancellationReceipt("inv_OufpKqnrvx9p0Nfbydl9jG4UNGeTYcvdrg"));
```

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

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

await File.WriteAllTextAsync("factura.xml", await fiscalisto.Invoices.CancellationReceiptAsync("inv_OufpKqnrvx9p0Nfbydl9jG4UNGeTYcvdrg"));
```

Before SAT cancels it (current, or waiting for the customer) it answers `409` with `invoice_not_canceled`: listen to `invoice.canceled` and download it then. In the SDKs it's `invoices.cancellationReceipt`.

## Until when it can be cancelled

A CFDI can be cancelled no later than the month in which the annual return for the year it was issued is due (article 29-A of the Código Fiscal): until March 31 of the following year if the issuer is a company (12-character RFC) and until April 30 if it's an individual. After that day, cancelling it returns `cancellation_failed` and [replacing it](#replace), `invoice_invalid`, with the reason and without asking SAT or stamping the new one. If there's an error, correct it with a [credit note](https://fiscalisto.com/en/docs/api/pagos-y-notas-de-credito#credit-notes) or with a new CFDI.

## What it costs

Cancelling a document uses no timbres, neither the first request nor the ones you repeat after a rejection. The timbre used when stamping it doesn't come back.

## Replace

To correct an invoice (another price, another customer regime, another line item), send the full corrected invoice, with the same body as [`POST /v1/invoices`](https://fiscalisto.com/en/docs/api/referencia/facturas/create-invoice):

```bash tab="cURL"
curl https://api.fiscalisto.com/v1/invoices/inv_OufpKqnrvx9p0Nfbydl9jG4UNGeTYcvdrg/substitute \
  -H "Authorization: Bearer $FISCALISTO_API_KEY" \
  -H "Idempotency-Key: pedido-A-1042-corregida" \
  -H "Content-Type: application/json" \
  -d '{
    "customer": { "tax_id": "ICV060329BY0", "legal_name": "INMOBILIARIA CVA", "tax_system": "601", "zip": "33826" },
    "payment_form": "03",
    "items": [{ "description": "Mensualidad", "product_key": "86121700", "quantity": 2, "unit_price": 2400 }]
  }'
```

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

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

const invoice = await fiscalisto.invoices.substitute("inv_OufpKqnrvx9p0Nfbydl9jG4UNGeTYcvdrg", {
  customer: {
    tax_id: "ICV060329BY0",
    legal_name: "INMOBILIARIA CVA",
    tax_system: "601",
    zip: "33826",
  },
  payment_form: "03",
  items: [
    {
      description: "Mensualidad",
      product_key: "86121700",
      quantity: 2,
      unit_price: 2400,
    },
  ],
}, { idempotencyKey: "pedido-A-1042-corregida" });
```

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

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

invoice = fiscalisto.invoices.substitute("inv_OufpKqnrvx9p0Nfbydl9jG4UNGeTYcvdrg", {
    "customer": {
        "tax_id": "ICV060329BY0",
        "legal_name": "INMOBILIARIA CVA",
        "tax_system": "601",
        "zip": "33826",
    },
    "payment_form": "03",
    "items": [
        {
            "description": "Mensualidad",
            "product_key": "86121700",
            "quantity": 2,
            "unit_price": 2400,
        },
    ],
}, idempotency_key="pedido-A-1042-corregida")
```

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

use Fiscalisto\Fiscalisto;

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

$invoice = $fiscalisto->invoices->substitute('inv_OufpKqnrvx9p0Nfbydl9jG4UNGeTYcvdrg', [
    'customer' => [
        'tax_id' => 'ICV060329BY0',
        'legal_name' => 'INMOBILIARIA CVA',
        'tax_system' => '601',
        'zip' => '33826',
    ],
    'payment_form' => '03',
    'items' => [
        [
            'description' => 'Mensualidad',
            'product_key' => '86121700',
            'quantity' => 2,
            'unit_price' => 2400,
        ],
    ],
], ['idempotency_key' => 'pedido-A-1042-corregida']);
```

```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()

	invoice, err := client.Invoices.Substitute(ctx, "inv_OufpKqnrvx9p0Nfbydl9jG4UNGeTYcvdrg", &fiscalisto.InvoiceCreate{
		Customer: fiscalisto.ObjectOf(fiscalisto.InvoiceCreateCustomer{
			TaxID:     "ICV060329BY0",
			LegalName: "INMOBILIARIA CVA",
			TaxSystem: "601",
			Zip:       "33826",
		}),
		PaymentForm: fiscalisto.String("03"),
		Items: []fiscalisto.InvoiceCreateItem{
			{
				Description: fiscalisto.String("Mensualidad"),
				ProductKey:  fiscalisto.String("86121700"),
				Quantity:    fiscalisto.Float64(2),
				UnitPrice:   fiscalisto.Float64(2400),
			},
		},
	}, fiscalisto.WithIdempotencyKey("pedido-A-1042-corregida"))
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(invoice.ID)
}
```

```java tab="Java"
import com.fiscalisto.FiscalistoClient;
import com.fiscalisto.RequestOptions;
import com.fiscalisto.model.InvoiceCreate;
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 invoice = fiscalisto.invoices().substitute("inv_OufpKqnrvx9p0Nfbydl9jG4UNGeTYcvdrg", new InvoiceCreate()
        .setCustomer(new InvoiceCreateCustomer()
                .setTaxId("ICV060329BY0")
                .setLegalName("INMOBILIARIA CVA")
                .setTaxSystem("601")
                .setZip("33826"))
        .setPaymentForm("03")
        .setItems(List.of(
                new InvoiceCreateItem()
                        .setDescription("Mensualidad")
                        .setProductKey("86121700")
                        .setQuantity(2)
                        .setUnitPrice(2400)
        )), RequestOptions.idempotencyKey("pedido-A-1042-corregida"));
System.out.println(invoice.getId());
```

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

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

var invoice = await fiscalisto.Invoices.SubstituteAsync("inv_OufpKqnrvx9p0Nfbydl9jG4UNGeTYcvdrg", new InvoiceCreate
{
    Customer = new InvoiceCreateCustomer
    {
        TaxId = "ICV060329BY0",
        LegalName = "INMOBILIARIA CVA",
        TaxSystem = "601",
        Zip = "33826",
    },
    PaymentForm = "03",
    Items = new()
    {
        new()
        {
            Description = "Mensualidad",
            ProductKey = "86121700",
            Quantity = 2,
            UnitPrice = 2400,
        },
    },
}, new RequestOptions { IdempotencyKey = "pedido-A-1042-corregida" });
```

Fiscalisto stamps the new one related to the previous one (relationship `04`) and cancels the previous one with reason `01`, in a single call. The response is the new invoice; its `substitutes` says which one it replaced and whether it's already cancelled, and `substitutes.cancellation` is the previous one's cancellation as its `GET` returns it (see [when Fiscalisto asks again](#when-fiscalisto-asks-again)). If it couldn't be cancelled, `substitutes.cancel_error` says why. The previous one is cancelled 15 minutes after the new one is stamped: SAT's status service shows it within seconds, but the one that cancels may not have it yet, and SAT then drops the request without a word. Meanwhile `substitutes.canceled` is `false` and `substitutes.cancellation.status` is `scheduled`. When it's only that SAT doesn't have the new one on record yet (it takes a few minutes), Fiscalisto cancels the previous one again every 15 minutes for 72 hours and the `invoice.canceled` webhook arrives when it's cancelled. If it's something else, correct it and cancel it with [`POST /v1/invoices/{id}/cancel`](https://fiscalisto.com/en/docs/api/referencia/facturas/cancel-invoice) with reason `01` and the new one in `substitution`. If the previous one needs the customer's acceptance, the new one is already stamped and the previous one stays `pending` until they answer.

Payment complements and credit notes aren't replaced: they're cancelled and another is issued.
