Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
Signed-off-by: Salah Alkhwlani <[email protected]>
  • Loading branch information
salkhwlani committed Jul 20, 2024
1 parent d8ab748 commit 209d211
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@

## Requirements

* PHP >= 7.2
* An mbstring extension
* PHP >= 8.0
* A mbstring extension
* An ext-dom extension

## Installation

Expand Down Expand Up @@ -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==
```
Expand Down
7 changes: 5 additions & 2 deletions src/Helpers/UXML.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/Models/InvoiceSign.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down

0 comments on commit 209d211

Please sign in to comment.