Skip to content

Commit

Permalink
qr generator
Browse files Browse the repository at this point in the history
  • Loading branch information
nticaric committed Oct 9, 2023
1 parent 6bef241 commit 53697ae
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
}],
"require": {
"php": ">=7.3.0",
"nesbot/carbon": "2.*"
"nesbot/carbon": "2.*",
"endroid/qr-code": "^5.0"
},
"require-dev": {
"mockery/mockery": "^1.0",
Expand Down
38 changes: 38 additions & 0 deletions src/QRGenerator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php namespace Nticaric\Fiskalizacija;

use DateTime;
use Endroid\QrCode\QrCode;

class QRGenerator
{
private $jir;
private $date;
private $amount;

public function __construct($jir, $date, $amount)
{
$this->jir = $jir;
$this->date = $date;
$this->amount = $amount;
}

public function generateUrl()
{
$formattedDate = DateTime::createFromFormat('d.m.Y\TH:i:s', $this->date)->format('Ymd_Hi');
$formattedAmount = number_format($this->amount, 2, ',', '');
$url = sprintf(
'https://porezna.gov.hr/rn?jir=%s&datv=%s&izn=%s',
$this->jir,
$formattedDate,
$formattedAmount
);
return $url;
}

public function getQrCode()
{
$url = $this->generateUrl();
$qrCode = new QrCode($url);
return base64_encode($qrCode->writeString());
}
}

0 comments on commit 53697ae

Please sign in to comment.