From 53697ae05158c3dd033d90873f1f58d9efc8bad8 Mon Sep 17 00:00:00 2001 From: Nenad Ticaric Date: Mon, 9 Oct 2023 15:42:42 +0200 Subject: [PATCH] qr generator --- composer.json | 3 ++- src/QRGenerator.php | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 src/QRGenerator.php 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()); + } +}