Verifactu in FacturaScripts: how to connect FacturaScripts with the Verifactu API
Verifacti has no official FacturaScripts plugin: FacturaScripts connects to the Verifactu API with your own plugin that extends the customer invoice model, sends it as JSON when it is issued and gets the QR back. No XML to generate, no hash to compute and no digital certificate: Verifacti sends the invoicing record to the AEAT as a colaborador social. The same pattern works for TicketBAI with the TicketBAI API.
Which APIs you need for FacturaScripts
Your connector uses two pieces: the submission API that matches the NIF (Verifactu API in common territory; TicketBAI API in Álava, Bizkaia and Gipuzkoa) and the NIF management API, integrated once to register the NIF, manage the representation form and receive webhooks. Each NIF uses one API or the other depending on where it is taxed.
How to connect FacturaScripts with the API
Flow: customer invoice moved to a non-editable status in FacturaScripts (FacturaCliente model extension) → your plugin → Verifactu API or TicketBAI API → AEAT or foral treasury.
- Register the NIF with the NIF management API and sign the representation form. Each NIF has its own API key.
- Create a plugin with an extension of the
FacturaClientemodel and register it inInit.php. - In
saveBefore, when the invoice moves to a non-editable status (for example, Issued), build the invoice from its lines and callPOST /verifactu/create. If the API answers with an error, the status change is not saved. - Store
uuidandqrand add the QR to the print format.
Do you build software and want to offer Verifactu to your customers? See ERP vendors.
Example: from the issued invoice to the record
The extension sends the invoice when it stops being editable: by then it has its lines and totals, and it can't change afterwards. It uses the FacturaScripts series, fiscal year and number, which are already sequential, applies global discounts to the bases and computes the total as base + VAT (without surcharge, disbursements or withholding). Credit notes are skipped: they need their own mapping as corrective invoices.
<?php
// Plugins/Verifacti/Extension/Model/FacturaCliente.php · FacturaScripts 2024+.
// Se registra en Plugins/Verifacti/Init.php con $this->loadExtension(new Extension\Model\FacturaCliente());
// La API key va en la configuración del plugin (Tools::settings('verifacti', 'apikey')).
// Envía la factura cuando pasa a un estado no editable (por ejemplo, «Emitida»): entonces ya tiene
// sus líneas y sus totales, y no se puede cambiar después. Si la API responde con un error, el
// cambio de estado no se guarda.
namespace FacturaScripts\Plugins\Verifacti\Extension\Model;
use Closure;
use FacturaScripts\Core\Model\FacturaCliente as Factura;
use FacturaScripts\Core\Tools;
class FacturaCliente
{
public function saveBefore(): Closure
{
return function () {
if (!$this->exists() || $this->editable || $this->idfacturarect) {
return true; // nueva, todavía editable o abono (rectificativa: mapeo propio)
}
$antes = new Factura();
if (!$antes->loadFromCode($this->idfactura) || !$antes->editable) {
return true; // ya estaba cerrada: ya se envió
}
$descuento = (1 - $this->dtopor1 / 100) * (1 - $this->dtopor2 / 100); // descuentos globales
$porTipo = [];
foreach ($this->getLines() as $linea) {
$tipo = (string) (float) $linea->iva;
$base = $linea->pvptotal * $descuento;
$porTipo[$tipo]['base'] = ($porTipo[$tipo]['base'] ?? 0) + $base;
$porTipo[$tipo]['cuota'] = ($porTipo[$tipo]['cuota'] ?? 0) + $base * $linea->iva / 100;
}
$factura = [
'serie' => $this->codserie . $this->codejercicio . '-',
'numero' => (string) $this->numero,
'fecha_expedicion' => $this->fecha,
'tipo_factura' => $this->cifnif ? 'F1' : 'F2',
'descripcion' => $this->observaciones ?: 'Factura ' . $this->codigo,
'lineas' => [],
// total incluye recargo y suplidos y resta la retención de IRPF: el registro lleva base + IVA
'importe_total' => number_format($this->neto + $this->totaliva, 2, '.', ''),
];
if ($this->cifnif) {
$factura['nif'] = $this->cifnif;
$factura['nombre'] = $this->nombrecliente;
}
foreach ($porTipo as $tipo => $l) {
$factura['lineas'][] = [
'base_imponible' => number_format($l['base'], 2, '.', ''),
'tipo_impositivo' => $tipo,
'cuota_repercutida' => number_format($l['cuota'], 2, '.', ''),
];
}
$cuerpo = json_encode($factura);
$ch = curl_init('https://api.verifacti.com/verifactu/create');
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . Tools::settings('verifacti', 'apikey'),
'Content-Type: application/json',
'Idempotency-Key: facturascripts-' . $this->idfactura . '-' . substr(hash('sha256', $cuerpo), 0, 12),
],
CURLOPT_POSTFIELDS => $cuerpo,
]);
$registro = json_decode((string) curl_exec($ch), true);
if (curl_getinfo($ch, CURLINFO_HTTP_CODE) !== 200) {
Tools::log()->error('Verifactu: ' . ($registro['error'] ?? 'sin respuesta'));
return false; // el cambio de estado no se guarda
}
Tools::log()->notice('Verifactu: registro ' . $registro['uuid']);
// Guarda $registro['uuid'] y $registro['qr'] en tu tabla para imprimir el QR
return true;
};
}
}The code groups the lines by VAT rate and uses F1 if the customer has a NIF and F2 otherwise. It sends the Idempotency-Key header with the invoice identifier plus a digest of the body: an identical retry never duplicates the invoice and, if you fix the data after an error, the key changes. The response carries the uuid, the state (Pendiente: the submission to the AEAT is queued), the verification URL, the QR in Base64 and the hash: store them with the invoice.
More code in the Verifactu tutorial in PHP. For TicketBAI, the call goes to POST /ticketbai/create with the foral NIF's API key: the fields, in the TicketBAI API documentation.
Special cases in FacturaScripts
| Case | What to do | Read more |
|---|---|---|
| Numbering | Every invoice needs a series with sequential numbering. If invoice numbers can have gaps, give the invoice its own number | Verifactu requirements |
| Customer without a NIF | Simplified invoice (F2), without nif or nombre. The API rejects an F2 above €3,000 (vf-verifactu-f2_limite_3000) | Simplified invoice |
| Return or refund | Corrective invoice: R5 if the original was simplified; R1–R4 if it was a full invoice | Corrective invoices |
| Customer asks for a full invoice later | Exchange invoice (F3) replacing the simplified one | Exchange invoice |
| Canary Islands, Ceuta and Melilla | IGIC or IPSI in the lines (impuesto field), not VAT | IGIC · IPSI |
| Products without VAT | Check whether they are exempt (operacion_exenta) or not subject (calificacion_operacion): they are not sent at rate 0 | Exempt invoice |
| Cancellation | Only for invoices that should never have been issued: POST /verifactu/cancel | Cancellation |
| Sale to another EU country | It depends on whether the customer is a business and on the distance-selling threshold | Intra-EU examples |
| Equivalence surcharge | tipo_recargo_equivalencia and cuota_recargo_equivalencia on the VAT line, not as another line | Equivalence surcharge |
| IRPF withholding | Not sent: importe_total is base + tax (+ surcharge), without subtracting the withholding | Disbursements and withholding |
| Several companies or shops | One NIF per company, each with its own API key | NIF management API |
Dates
The first row only applies if you build the connector to sell it: then you sell invoicing software. For those who invoice, the Verifactu dates are published in the BOE and the postponement to October 2028 is announced with no rule published. In Álava, Bizkaia and Gipuzkoa, TicketBAI is in force.
| Who | Date | Status | Rule |
|---|---|---|---|
| Producers and resellers of invoicing software RDL 15/2025 did not change this date. | Since 29 Jul 2025 | In force | RD 1007/2023 · Orden HAC/1177/2024 |
| Corporate Income Tax payers | 1 Jan 2027 | Published in the BOE, future date | RDL 15/2025 |
| Everyone else, including the self-employed | 1 Jul 2027 | Published in the BOE, future date | RDL 15/2025 |
| Postponement of the pending obligations The note does not specify the scope for businesses invoicing over €8M. | Oct 2028 | Announced, no rule published | Nota de Hacienda, 5 oct 2026 |
| TicketBAI in Álava: foral taxpayers Phased from 1 April 2022; all other taxpayers since 1 December 2022. | Since 1 Dec 2022 | In force | NF 13/2021 y DF 48/2021 · FAQ 1.9 · calendario |
| Batuz in Bizkaia (TicketBAI and LROE): all taxpayers Companies that are not SMEs since 1 January 2024; everyone else in windows on 1 July 2024, 1 January 2025, 1 July 2025 and 1 January 2026. | Since 1 Jan 2026 | In force | NF 8/2023 · Batuz |
| TicketBAI in Gipuzkoa: foral taxpayers Phased by activity from 1 July 2022. | Since 1 Jun 2023 | In force | NF 3/2020 · DF 32/2020 |
This is not advice: each taxpayer determines what applies to them with their adviser.
More detail in Verifactu dates and TicketBAI.
Pricing
Public tariff of the Verifactu API and the TicketBAI API: you pay per NIF active in production, VAT excluded. Custom per-NIF pricing is available for volume.
From
€14.99
per month for the first NIF active in production, VAT excluded
See all pricing- The price per NIF goes down with every tier.
- Free test environment and test NIF.
- Annual plan with a 10% discount, no setup fees.
- Up to 3,000 invoicing records per month per NIF.
- Startup plan for companies under 12 months old, with under €100,000 in revenue and under €200,000 in funding.
- Same price with the Verifactu API and the TicketBAI API: each NIF uses one or the other depending on where it is taxed.
- Online signing of the representation form: €2.90 + VAT per signature.
Developer resources
For your AI: llms.txt and the OpenAPI specification.
Questions about Verifactu and FacturaScripts
More questions about VerifactuIs there a plugin from Verifacti for FacturaScripts?
Does FacturaScripts comply with Verifactu on its own?
Does it work for TicketBAI too?
/ticketbai/create), the invoice fields and the API key change.Do I need a digital certificate?
How much does it cost?
Other integrations
Connect FacturaScripts in the test environment
Create your free account and try the API with a test NIF before going to production.