Verifactu on Shopify: how to connect your store with the Verifactu API
Verifacti has no official Shopify app: your store connects to the Verifactu API from your own service, which receives the orders/paid webhook, sends the invoice as JSON and stores the QR the API returns. No XML to generate, no hash to compute and no digital certificate: Verifacti sends the invoicing record to the AEAT as a colaborador social. In Álava, Bizkaia and Gipuzkoa, the same pattern works with the TicketBAI API.
Which APIs you need for Shopify
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 Shopify with the API
Flow: paid order in Shopify (orders/paid webhook) → your service → 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 an
orders/paidwebhook in Shopify (in a custom app or in Settings › Notifications) pointing to your service. - Verify the webhook's HMAC signature and answer 200 straight away.
- Turn the order into the invoice and call
POST /verifactu/create. - Store
uuid,qrandhuellawith the order (for example, in a metafield) and put the QR on the invoice you send the customer.
Do you build software and want to offer Verifactu to your customers? See SaaS.
Example: from the paid order to the record
A Node.js service with Express. It verifies Shopify's signature (X-Shopify-Hmac-Sha256), removes VAT when prices include it (taxes_included), leaves tips and gift cards out and sends the order as a simplified invoice. The invoice number is its own sequential one (series WEB-): Shopify order numbers can have gaps.
// Webhook orders/paid de Shopify → API Verifactu (Node.js 18+, Express).
// Variables de entorno: SHOPIFY_WEBHOOK_SECRET, VERIFACTI_API_KEY.
const crypto = require('node:crypto');
const fs = require('node:fs');
const express = require('express');
const app = express();
const hoy = ()=>new Intl.DateTimeFormat('es-ES', {
timeZone: 'Europe/Madrid',
day: '2-digit',
month: '2-digit',
year: 'numeric'
}).format(new Date()).replaceAll('/', '-');
// Numeración propia: la factura necesita una serie correlativa y sin huecos, y los números de
// pedido de Shopify pueden tenerlos. Cada pedido recibe un número una sola vez (también en los
// reintentos). Este ejemplo lo guarda en un fichero; en producción, usa tu base de datos con un
// incremento atómico.
const CONTADOR = 'numeracion.json';
function numeroDeFactura(orderId) {
const c = fs.existsSync(CONTADOR) ? JSON.parse(fs.readFileSync(CONTADOR, 'utf8')) : {
ultimo: 0,
pedidos: {}
};
if (!c.pedidos[orderId]) {
c.ultimo += 1;
c.pedidos[orderId] = String(c.ultimo);
fs.writeFileSync(CONTADOR, JSON.stringify(c));
}
return c.pedidos[orderId];
}
function factura(order) {
const porTipo = {};
const sumar = (item, bruto)=>{
const cuota = item.tax_lines.reduce((s, t)=>s + Number(t.price), 0);
// Línea sin IVA: revisa si es exenta (operacion_exenta) o no sujeta (calificacion_operacion).
const tipo = item.tax_lines.length ? Math.round(item.tax_lines[0].rate * 10000) / 100 : 0;
const descuento = (item.discount_allocations || []).reduce((s, d)=>s + Number(d.amount), 0);
const base = bruto - descuento - (order.taxes_included ? cuota : 0);
porTipo[tipo] ??= {
base: 0,
cuota: 0
};
porTipo[tipo].base += base;
porTipo[tipo].cuota += cuota;
};
// Las tarjetas regalo y las propinas no van en la factura.
order.line_items.filter((l)=>!l.gift_card).forEach((l)=>sumar(l, Number(l.price) * l.quantity));
order.shipping_lines.forEach((s)=>sumar(s, Number(s.price)));
const regalo = order.line_items.filter((l)=>l.gift_card).reduce((s, l)=>s + Number(l.price) * l.quantity, 0);
const total = Number(order.total_price) - Number(order.total_tip_received || 0) - regalo;
return {
serie: 'WEB-',
numero: numeroDeFactura(order.id),
fecha_expedicion: hoy(),
tipo_factura: 'F2',
descripcion: `Pedido ${order.name}`,
lineas: Object.entries(porTipo).map(([tipo, l])=>({
base_imponible: l.base.toFixed(2),
tipo_impositivo: tipo,
cuota_repercutida: l.cuota.toFixed(2)
})),
importe_total: total.toFixed(2)
};
}
app.post('/webhooks/shopify/orders-paid', express.raw({
type: 'application/json'
}), async (req, res)=>{
const firma = crypto.createHmac('sha256', process.env.SHOPIFY_WEBHOOK_SECRET).update(req.body).digest('base64');
const recibida = req.get('X-Shopify-Hmac-Sha256') || '';
if (firma.length !== recibida.length || !crypto.timingSafeEqual(Buffer.from(firma), Buffer.from(recibida))) {
return res.sendStatus(401);
}
const order = JSON.parse(req.body);
// Shopify espera la respuesta en menos de 5 segundos y no reenviará el webhook:
// en producción, encola el pedido y reintenta la llamada si falla.
res.sendStatus(200);
const cuerpo = JSON.stringify(factura(order));
const r = await fetch('https://api.verifacti.com/verifactu/create', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.VERIFACTI_API_KEY}`,
'Content-Type': 'application/json',
'Idempotency-Key': `shopify-${order.id}-${crypto.createHash('sha256').update(cuerpo).digest('hex').slice(0, 12)}`
},
body: cuerpo
});
const registro = await r.json();
if (r.status !== 200) return console.error('Verifacti', r.status, registro);
// Guarda registro.uuid, registro.qr y registro.huella con el pedido (por ejemplo, en un metafield)
console.log(order.name, registro.uuid, registro.estado);
});
app.listen(3000);The code groups the lines by VAT rate and always sends a simplified invoice (F2); if the customer asks for a full invoice, issue an exchange invoice (F3). It sends the Idempotency-Key header with the order 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 tutorials. 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 Shopify
| Case | What to do | Read more |
|---|---|---|
| Numbering | The code gives each order its own sequential number (series WEB-), once: order numbers can have gaps | 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 |
| 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 Shopify
More questions about VerifactuIs there a module or app from Verifacti for Shopify?
Does Shopify 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 Shopify in the test environment
Create your free account and try the API with a test NIF before going to production.