From da66fa627153a47732046a68cf772d0771203bfe Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 30 Jun 2022 14:37:08 +1000 Subject: [PATCH] Qr Swiss --- app/Helpers/SwissQr/SwissQrGenerator.php | 133 +++++++++++++++++++++++ 1 file changed, 133 insertions(+) create mode 100644 app/Helpers/SwissQr/SwissQrGenerator.php diff --git a/app/Helpers/SwissQr/SwissQrGenerator.php b/app/Helpers/SwissQr/SwissQrGenerator.php new file mode 100644 index 000000000000..bf484fda8b01 --- /dev/null +++ b/app/Helpers/SwissQr/SwissQrGenerator.php @@ -0,0 +1,133 @@ +company = $company; + + $this->invoice = $invoice; + } + + public function run() + { + + // This is an example how to create a typical qr bill: + // - with reference number + // - with known debtor + // - with specified amount + // - with human-readable additional information + // - using your QR-IBAN + // + // Likely the most common use-case in the business world. + + // Create a new instance of QrBill, containing default headers with fixed values + $qrBill = \QrBill\QrBill::create(); + + + // Add creditor information + // Who will receive the payment and to which bank account? + $qrBill->setCreditor( + QrBill\DataGroup\Element\CombinedAddress::create( + $this->company->present()->name(), + $this->company->present()->address1(), + $this->company->present()->getCompanyCityState(), + 'CH' + )); + + $qrBill->setCreditorInformation( + QrBill\DataGroup\Element\CreditorInformation::create( + $this->company->present()->qr_iban() // This is a special QR-IBAN. Classic IBANs will not be valid here. + )); + + // Add debtor information + // Who has to pay the invoice? This part is optional. + // + // Notice how you can use two different styles of addresses: CombinedAddress or StructuredAddress. + // They are interchangeable for creditor as well as debtor. + $qrBill->setUltimateDebtor( + QrBill\DataGroup\Element\StructuredAddress::createWithStreet( + 'Pia-Maria Rutschmann-Schnyder', + 'Grosse Marktgasse', + '28', + '9400', + 'Rorschach', + 'CH' + )); + + // Add payment amount information + // What amount is to be paid? + $qrBill->setPaymentAmountInformation( + QrBill\DataGroup\Element\PaymentAmountInformation::create( + 'CHF', + 2500.25 + )); + + // Add payment reference + // This is what you will need to identify incoming payments. + $referenceNumber = QrBill\Reference\QrPaymentReferenceGenerator::generate( + '210000', // You receive this number from your bank (BESR-ID). Unless your bank is PostFinance, in that case use NULL. + '313947143000901' // A number to match the payment with your internal data, e.g. an invoice number + ); + + $qrBill->setPaymentReference( + QrBill\DataGroup\Element\PaymentReference::create( + QrBill\DataGroup\Element\PaymentReference::TYPE_QR, + $referenceNumber + )); + + // Optionally, add some human-readable information about what the bill is for. + $qrBill->setAdditionalInformation( + QrBill\DataGroup\Element\AdditionalInformation::create( + 'Invoice 123456, Gardening work' + ) + ); + + // Now get the QR code image and save it as a file. + try { + $qrBill->getQrCode()->writeFile(__DIR__ . '/qr.png'); + $qrBill->getQrCode()->writeFile(__DIR__ . '/qr.svg'); + } catch (Exception $e) { + foreach($qrBill->getViolations() as $violation) { + print $violation->getMessage()."\n"; + } + exit; + } + + $output = new QrBill\PaymentPart\Output\HtmlOutput\HtmlOutput($qrBill, 'en'); + + $html = $output + ->setPrintable(false) + ->getPaymentPart(); + + // Next: Output full payment parts, depending on the format you want to use: + // + // - FpdfOutput/fpdf-example.php + // - HtmlOutput/html-example.php + // - TcPdfOutput/tcpdf-example.php + } + +} \ No newline at end of file