Help for developers to integrate Verifactu with Python: learn to make REST requests, generate invoices with QR, sign with digital certificate and create XML efficiently.

In Python, the most widely used library for making HTTP requests is requests. To call a REST API like Verifacti's using the requests library, you can use the following code:
import requests
url = "https://api.verifacti.com/verifactu/create"
headers = {
"Authorization": "Bearer <API_KEY>",
"Content-Type": "application/json"
}
payload = {
"serie": "A",
"numero": "234634",
"fecha_expedicion": "02-12-2024",
"tipo_factura": "F1",
"descripcion": "Descripcion de la operacion",
"nif": "A15022510",
"nombre": "Nombre cliente",
"lineas": [{
"base_imponible": "200",
"tipo_impositivo": "21",
"cuota_repercutida": "42"
}],
"importe_total": "242"
}
response = requests.post(url, headers=headers, json=payload)
print(response.text)
To embed a QR code in a PDF, you can use the following libraries:
Example with reportlab:
from reportlab.pdfgen import canvas
from reportlab.lib.utils import ImageReader
def agregar_qr_a_pdf():
c = canvas.Canvas("FacturaConQR.pdf")
qr_image = ImageReader("QRFactura.png")
c.drawImage(qr_image, 100, 100, 100, 100)
c.save()
agregar_qr_a_pdf()To generate QR codes in Python, you can use:
Example with qrcode:
import qrcode
def generar_qr():
qr = qrcode.make("https://verifacti.com")
qr.save("QRFactura.png")
generar_qr()Help for developers to integrate Verifactu with PHP: learn to make REST requests, generate invoices with QR, sign with digital certificate and create XML efficiently.
Complete collection of Verifactu invoice examples: simplified, standard, corrective, intra-Community, export, IGIC, IPSI, cancellation, and more. Ready-to-copy JSON.
Verifactu mandatory compliance. Who is required to comply with VeriFactu. Mandatory compliance for computerized invoicing systems, legal entities and self-employed workers.