PHP code example of josemmo / facturae-php
1. Go to this page and download the library: Download josemmo/facturae-php library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
josemmo / facturae-php example snippets
$fac = new Facturae();
$fac->setNumber('FAC201804', '123');
$fac->setIssueDate('2018-04-01');
$fac->setSeller(new FacturaeParty([
"taxNumber" => "A00000000",
"name" => "Perico de los Palotes S.A.",
"address" => "C/ Falsa, 123",
"postCode" => "12345",
"town" => "Madrid",
"province" => "Madrid"
]));
$fac->setBuyer(new FacturaeParty([
"isLegalEntity" => false,
"taxNumber" => "00000000A",
"name" => "Antonio",
"firstSurname" => "García",
"lastSurname" => "Pérez",
"address" => "Avda. Mayor, 7",
"postCode" => "54321",
"town" => "Madrid",
"province" => "Madrid"
]));
$fac->addItem("Lámpara de pie", 20.14, 3, Facturae::TAX_IVA, 21);
$fac->sign("certificado.pfx", null, "passphrase");
$fac->export("mi-factura.xsig");
$signer = new FacturaeSigner();
$signer->loadPkcs12("certificado.pfx", "passphrase");
$xml = file_get_contents(__DIR__ . "/factura.xml");
$signedXml = $signer->sign($xml);
file_put_contents(__DIR__ . "/factura.xsig", $signedXml);