# Complementos

> Carta Porte, comercio exterior, impuestos locales, instituciones educativas y los demás complementos del CFDI, como un campo más de la factura.

Un complemento agrega al CFDI la información que el SAT pide para ciertas operaciones. En la API cada uno es un campo de [`POST /v1/invoices`](https://fiscalisto.com/docs/api/referencia/facturas/create-invoice), de la factura o de cada concepto, y Fiscalisto lo revisa con las mismas reglas que la app antes de timbrar.

| Complemento | Campo | Para qué |
| --- | --- | --- |
| Carta Porte 3.1 | `carta_porte` | Traslado de mercancías por carretera, mar, aire o tren: origen, destinos, mercancías, vehículo y operadores. Va en un traslado (`"type": "T"`) o en una factura de flete. |
| Comercio exterior 2.0 | `comercio_exterior` | Exportación definitiva de mercancías, con `"export": "02"`. |
| Impuestos locales | `local_taxes` | Impuestos estatales trasladados o retenidos, como el ISH de hospedaje. |
| Instituciones educativas | `items[].iedu` | Colegiaturas: alumno, CURP, nivel y RVOE, para que los padres las deduzcan. |
| A cuenta de terceros | `items[].third_party` | Un concepto que se cobra por cuenta de otro contribuyente. |
| Vehículo usado | `items[].used_vehicle` | Venta de un auto usado por una persona física. |
| Donatarias | `donation` | Recibos de donativos de una donataria autorizada. |
| INE | `ine` | Operaciones con partidos políticos y candidatos. |
| Leyendas fiscales | `leyendas` | Textos que una disposición fiscal pide incluir. |
| Addenda | `addenda` (y `items[].addenda`) | Lo que piden algunos receptores, como Walmart o Soriana. |

Las facturas también llevan sin complemento la cuenta predial (`items[].predial`) en un arrendamiento y los pedimentos (`items[].pedimentos`) de la mercancía importada.

La referencia de `POST /v1/invoices` describe cada campo de cada complemento, con su nombre en el XML del SAT.

## Ejemplo: hospedaje con ISH

```bash tab="cURL"
curl https://api.fiscalisto.com/v1/invoices \
  -H "Authorization: Bearer $FISCALISTO_API_KEY" \
  -H "Idempotency-Key: reserva-77812" \
  -H "Content-Type: application/json" \
  -d '{
    "customer": { "tax_id": "ICV060329BY0", "legal_name": "INMOBILIARIA CVA", "tax_system": "601", "zip": "33826" },
    "payment_form": "04",
    "items": [{ "description": "Hospedaje, 2 noches", "product_key": "90111800", "unit_name": "Noche", "quantity": 2, "unit_price": 1500 }],
    "local_taxes": [{ "retention": false, "name": "ISH", "rate": 3, "amount": 90 }]
  }'
```

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

// La llave viene de FISCALISTO_API_KEY.
const fiscalisto = new Fiscalisto();

const invoice = await fiscalisto.invoices.create({
  customer: {
    tax_id: "ICV060329BY0",
    legal_name: "INMOBILIARIA CVA",
    tax_system: "601",
    zip: "33826",
  },
  payment_form: "04",
  items: [
    {
      description: "Hospedaje, 2 noches",
      product_key: "90111800",
      unit_name: "Noche",
      quantity: 2,
      unit_price: 1500,
    },
  ],
  local_taxes: [
    {
      retention: false,
      name: "ISH",
      rate: 3,
      amount: 90,
    },
  ],
}, { idempotencyKey: "reserva-77812" });
```

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

# La llave viene de FISCALISTO_API_KEY.
fiscalisto = Fiscalisto()

invoice = fiscalisto.invoices.create({
    "customer": {
        "tax_id": "ICV060329BY0",
        "legal_name": "INMOBILIARIA CVA",
        "tax_system": "601",
        "zip": "33826",
    },
    "payment_form": "04",
    "items": [
        {
            "description": "Hospedaje, 2 noches",
            "product_key": "90111800",
            "unit_name": "Noche",
            "quantity": 2,
            "unit_price": 1500,
        },
    ],
    "local_taxes": [
        {
            "retention": False,
            "name": "ISH",
            "rate": 3,
            "amount": 90,
        },
    ],
}, idempotency_key="reserva-77812")
```

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

use Fiscalisto\Fiscalisto;

// La llave viene de FISCALISTO_API_KEY.
$fiscalisto = new Fiscalisto();

$invoice = $fiscalisto->invoices->create([
    'customer' => [
        'tax_id' => 'ICV060329BY0',
        'legal_name' => 'INMOBILIARIA CVA',
        'tax_system' => '601',
        'zip' => '33826',
    ],
    'payment_form' => '04',
    'items' => [
        [
            'description' => 'Hospedaje, 2 noches',
            'product_key' => '90111800',
            'unit_name' => 'Noche',
            'quantity' => 2,
            'unit_price' => 1500,
        ],
    ],
    'local_taxes' => [
        [
            'retention' => false,
            'name' => 'ISH',
            'rate' => 3,
            'amount' => 90,
        ],
    ],
], ['idempotency_key' => 'reserva-77812']);
```

```go tab="Go"
package main

import (
	"context"
	"fmt"
	"log"

	fiscalisto "fiscalisto.com/go"
)

func main() {
	// La llave viene de FISCALISTO_API_KEY.
	client, err := fiscalisto.NewClient("")
	if err != nil {
		log.Fatal(err)
	}
	ctx := context.Background()

	invoice, err := client.Invoices.Create(ctx, &fiscalisto.InvoiceCreate{
		Customer: fiscalisto.ObjectOf(fiscalisto.InvoiceCreateCustomer{
			TaxID:     "ICV060329BY0",
			LegalName: "INMOBILIARIA CVA",
			TaxSystem: "601",
			Zip:       "33826",
		}),
		PaymentForm: fiscalisto.String("04"),
		Items: []fiscalisto.InvoiceCreateItem{
			{
				Description: fiscalisto.String("Hospedaje, 2 noches"),
				ProductKey:  fiscalisto.String("90111800"),
				UnitName:    fiscalisto.String("Noche"),
				Quantity:    fiscalisto.Float64(2),
				UnitPrice:   fiscalisto.Float64(1500),
			},
		},
		LocalTaxes: []fiscalisto.InvoiceCreateLocalTax{
			{Retention: false, Name: "ISH", Rate: 3, Amount: 90},
		},
	}, fiscalisto.WithIdempotencyKey("reserva-77812"))
	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 com.fiscalisto.model.InvoiceCreateLocalTax;
import java.util.List;

// La llave viene de FISCALISTO_API_KEY.
var fiscalisto = new FiscalistoClient();

var invoice = fiscalisto.invoices().create(new InvoiceCreate()
        .setCustomer(new InvoiceCreateCustomer()
                .setTaxId("ICV060329BY0")
                .setLegalName("INMOBILIARIA CVA")
                .setTaxSystem("601")
                .setZip("33826"))
        .setPaymentForm("04")
        .setItems(List.of(
                new InvoiceCreateItem()
                        .setDescription("Hospedaje, 2 noches")
                        .setProductKey("90111800")
                        .setUnitName("Noche")
                        .setQuantity(2)
                        .setUnitPrice(1500)
        ))
        .setLocalTaxes(List.of(
                new InvoiceCreateLocalTax()
                        .setRetention(false)
                        .setName("ISH")
                        .setRate(3)
                        .setAmount(90)
        )), RequestOptions.idempotencyKey("reserva-77812"));
System.out.println(invoice.getId());
```

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

// La llave viene de FISCALISTO_API_KEY.
var fiscalisto = new FiscalistoClient();

var invoice = await fiscalisto.Invoices.CreateAsync(new InvoiceCreate
{
    Customer = new InvoiceCreateCustomer
    {
        TaxId = "ICV060329BY0",
        LegalName = "INMOBILIARIA CVA",
        TaxSystem = "601",
        Zip = "33826",
    },
    PaymentForm = "04",
    Items = new()
    {
        new()
        {
            Description = "Hospedaje, 2 noches",
            ProductKey = "90111800",
            UnitName = "Noche",
            Quantity = 2,
            UnitPrice = 1500,
        },
    },
    LocalTaxes = new()
    {
        new()
        {
            Retention = false,
            Name = "ISH",
            Rate = 3,
            Amount = 90,
        },
    },
}, new RequestOptions { IdempotencyKey = "reserva-77812" });
```

`rate` va en por ciento y `amount` es el importe del impuesto local; Fiscalisto lo suma (o, si es una retención, lo resta) al total.

Si el producto del catálogo ya lleva el impuesto (`local_taxes` en [`POST /v1/products`](https://fiscalisto.com/docs/api/referencia/productos/create-product)) y la factura no manda `local_taxes`, Fiscalisto lo agrega solo, calculado sobre los conceptos de ese producto: en una factura con hospedaje y cena, el ISH va sobre el hospedaje. Si la factura manda `local_taxes`, se usan los suyos tal cual. Al público en general solo se le trasladan.

## Ejemplo: a cuenta de terceros

```bash tab="cURL"
curl https://api.fiscalisto.com/v1/invoices \
  -H "Authorization: Bearer $FISCALISTO_API_KEY" \
  -H "Idempotency-Key: comision-3391" \
  -H "Content-Type: application/json" \
  -d '{
    "customer": { "tax_id": "ICV060329BY0", "legal_name": "INMOBILIARIA CVA", "tax_system": "601", "zip": "33826" },
    "payment_form": "03",
    "items": [{
      "description": "Consultoría",
      "product_key": "80101500",
      "unit_price": 1000,
      "third_party": { "tax_id": "CACX7605101P8", "name": "XOCHILT CASAS CHAVEZ", "tax_system": "612", "zip": "36257" }
    }]
  }'
```

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

// La llave viene de FISCALISTO_API_KEY.
const fiscalisto = new Fiscalisto();

const invoice = await fiscalisto.invoices.create({
  customer: {
    tax_id: "ICV060329BY0",
    legal_name: "INMOBILIARIA CVA",
    tax_system: "601",
    zip: "33826",
  },
  payment_form: "03",
  items: [
    {
      description: "Consultoría",
      product_key: "80101500",
      unit_price: 1000,
      third_party: {
        tax_id: "CACX7605101P8",
        name: "XOCHILT CASAS CHAVEZ",
        tax_system: "612",
        zip: "36257",
      },
    },
  ],
}, { idempotencyKey: "comision-3391" });
```

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

# La llave viene de FISCALISTO_API_KEY.
fiscalisto = Fiscalisto()

invoice = fiscalisto.invoices.create({
    "customer": {
        "tax_id": "ICV060329BY0",
        "legal_name": "INMOBILIARIA CVA",
        "tax_system": "601",
        "zip": "33826",
    },
    "payment_form": "03",
    "items": [
        {
            "description": "Consultoría",
            "product_key": "80101500",
            "unit_price": 1000,
            "third_party": {
                "tax_id": "CACX7605101P8",
                "name": "XOCHILT CASAS CHAVEZ",
                "tax_system": "612",
                "zip": "36257",
            },
        },
    ],
}, idempotency_key="comision-3391")
```

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

use Fiscalisto\Fiscalisto;

// La llave viene de FISCALISTO_API_KEY.
$fiscalisto = new Fiscalisto();

$invoice = $fiscalisto->invoices->create([
    'customer' => [
        'tax_id' => 'ICV060329BY0',
        'legal_name' => 'INMOBILIARIA CVA',
        'tax_system' => '601',
        'zip' => '33826',
    ],
    'payment_form' => '03',
    'items' => [
        [
            'description' => 'Consultoría',
            'product_key' => '80101500',
            'unit_price' => 1000,
            'third_party' => [
                'tax_id' => 'CACX7605101P8',
                'name' => 'XOCHILT CASAS CHAVEZ',
                'tax_system' => '612',
                'zip' => '36257',
            ],
        ],
    ],
], ['idempotency_key' => 'comision-3391']);
```

```go tab="Go"
package main

import (
	"context"
	"fmt"
	"log"

	fiscalisto "fiscalisto.com/go"
)

func main() {
	// La llave viene de FISCALISTO_API_KEY.
	client, err := fiscalisto.NewClient("")
	if err != nil {
		log.Fatal(err)
	}
	ctx := context.Background()

	invoice, err := client.Invoices.Create(ctx, &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("Consultoría"),
				ProductKey:  fiscalisto.String("80101500"),
				UnitPrice:   fiscalisto.Float64(1000),
				ThirdParty: &fiscalisto.InvoiceCreateItemThirdParty{
					TaxID:     "CACX7605101P8",
					Name:      "XOCHILT CASAS CHAVEZ",
					TaxSystem: "612",
					Zip:       "36257",
				},
			},
		},
	}, fiscalisto.WithIdempotencyKey("comision-3391"))
	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 com.fiscalisto.model.InvoiceCreateItemThirdParty;
import java.util.List;

// La llave viene de FISCALISTO_API_KEY.
var fiscalisto = new FiscalistoClient();

var invoice = fiscalisto.invoices().create(new InvoiceCreate()
        .setCustomer(new InvoiceCreateCustomer()
                .setTaxId("ICV060329BY0")
                .setLegalName("INMOBILIARIA CVA")
                .setTaxSystem("601")
                .setZip("33826"))
        .setPaymentForm("03")
        .setItems(List.of(
                new InvoiceCreateItem()
                        .setDescription("Consultoría")
                        .setProductKey("80101500")
                        .setUnitPrice(1000)
                        .setThirdParty(new InvoiceCreateItemThirdParty()
                                .setTaxId("CACX7605101P8")
                                .setName("XOCHILT CASAS CHAVEZ")
                                .setTaxSystem("612")
                                .setZip("36257"))
        )), RequestOptions.idempotencyKey("comision-3391"));
System.out.println(invoice.getId());
```

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

// La llave viene de FISCALISTO_API_KEY.
var fiscalisto = new FiscalistoClient();

var invoice = await fiscalisto.Invoices.CreateAsync(new InvoiceCreate
{
    Customer = new InvoiceCreateCustomer
    {
        TaxId = "ICV060329BY0",
        LegalName = "INMOBILIARIA CVA",
        TaxSystem = "601",
        Zip = "33826",
    },
    PaymentForm = "03",
    Items = new()
    {
        new()
        {
            Description = "Consultoría",
            ProductKey = "80101500",
            UnitPrice = 1000,
            ThirdParty = new()
            {
                TaxId = "CACX7605101P8",
                Name = "XOCHILT CASAS CHAVEZ",
                TaxSystem = "612",
                Zip = "36257",
            },
        },
    },
}, new RequestOptions { IdempotencyKey = "comision-3391" });
```
