diff --git a/README.md b/README.md index a7fe70f..0ad428f 100644 --- a/README.md +++ b/README.md @@ -18,8 +18,9 @@ ## Requirements -* PHP >= 7.2 -* An mbstring extension +* PHP >= 8.0 +* A mbstring extension +* An ext-dom extension ## Installation @@ -109,6 +110,9 @@ $tags = UXML::fromString($xmlInvoice)->toTagsArray($certificate); $QRCodeAsBase64 = GenerateQrCode::fromArray($tags)->toBase64(); +// Invoice Hash: $tags[5]->getValue() +// Digital Signature: $tags[6]->getValue() + //$QRCodeAsBase64 output will be like this //AQ1TYWxsYSAtIFNhbGxhAg8zMTA0NjE0MzU3MDAwMDMDFDIwMjMtMTItMzFUMjE6MDA6MDBaBAY0MDguNjkFBTUzLjMxBiw1TXZmVmZTWGRSZzgyMWU4Q0E3bE1WcDdNS1J4Q2FBWWZHTm90THlHNUg4PQdgTUVRQ0lEOGthSTF1Z29EcWJkN3NEVmFCVE9yOUswWlVwRkZNY2hON2FsNGgyTEhrQWlCYnZxZktkK0xaN0hEc0FMakxmeTA0dTBMNVRhcjhxenowYjBlb0EzMUtIdz09CFgwVjAQBgcqhkjOPQIBBgUrgQQACgNCAATmBleqoCAfxDveLQVAKCvHSjNxoudWhRNQ8zThTxzBtgjAqZQ7vBJWvu2Ut0MxYa8vq7O4tgusgmcLBDhK/xNCCUcwRQIhAIhuJ6o4ETNSosMEf/OLVbp+TZqi2IGSxsgyC54yZgQAAiB3lwym6zpkPspQrT+luMte/ifw4THG+waV+SmXNSukmQ== ``` diff --git a/src/Helpers/UXML.php b/src/Helpers/UXML.php index af6c859..5467e5d 100644 --- a/src/Helpers/UXML.php +++ b/src/Helpers/UXML.php @@ -325,15 +325,18 @@ public function asXML(?string $version = '1.0', string $encoding = 'UTF-8', bool * * @param Certificate $certificate * @param string|null $invoiceHash the base64 encoded string of the binary invoice hash + * @param string|null $digitalSignature the digital signature for the invoice hash * @return array */ - public function toTagsArray(Certificate $certificate, ?string $invoiceHash): array + public function toTagsArray(Certificate $certificate, ?string $invoiceHash, ?string $digitalSignature): array { if (!$invoiceHash) { $invoiceHash = $this->getXmlHash(); } - $digitalSignature = base64_encode($certificate->getPrivateKey()->sign(base64_decode($invoiceHash))); + if (!$digitalSignature) { + $digitalSignature = base64_encode($certificate->getPrivateKey()->sign(base64_decode($invoiceHash))); + } $issueDate = $this->get("cbc:IssueDate")->asText(); $issueTime = $this->get("cbc:IssueTime")->asText(); diff --git a/src/Models/InvoiceSign.php b/src/Models/InvoiceSign.php index a3de50e..2f6622a 100644 --- a/src/Models/InvoiceSign.php +++ b/src/Models/InvoiceSign.php @@ -90,7 +90,7 @@ public function sign(): Invoice private function generateQRCode(): string { return GenerateQrCode::fromArray( - $this->xmlDom->toTagsArray($this->certificate, $this->invoiceHash) + $this->xmlDom->toTagsArray($this->certificate, $this->invoiceHash, $this->digitalSignature) )->toBase64(); }