diff --git a/composer.json b/composer.json index 5e5d1b3..ae76538 100644 --- a/composer.json +++ b/composer.json @@ -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", diff --git a/src/QRGenerator.php b/src/QRGenerator.php new file mode 100644 index 0000000..7ac3c04 --- /dev/null +++ b/src/QRGenerator.php @@ -0,0 +1,38 @@ +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()); + } +}