Novis\Image\QrCode::giroCode
Novis\Image\QrCode::giroCode({…} $payment): stringNovis\Image\QrCode::giroCode( {…} $payment, ): string
Makes the text of a GiroCode: a QR code on an invoice that a banking app reads to fill in a bank transfer.
QrCode::giroCode takes the details of one SEPA transfer in euros and returns them as text. Give the text to QrCode::render or QrCode::svg to draw the QR code. Many banking apps in Europe read it.
The details are fields of one object. name is who receives the money, and iban is their IBAN. These two are needed, and spaces in the IBAN are removed. amount is a decimal in euros. bic is the BIC of the bank. reference is a creditor reference, such as RF18539007547034. text is a free text.
These throw a LogicError: a wrong IBAN, a field that is too long or has a line break, an amount with more than 2 decimals, and both a reference and a text.
Good to know: the IBAN check finds most typing mistakes. It does not check that the account exists.
The examples below show the text of a payment, a GiroCode on an invoice, and the errors.
Parameters
$payment{ name: string, iban: string, amount?: decimal, bic?: string, reference?: string, text?: string }
Return value
Returns string.
Examples
The text of a payment
<?nvs// Shows the text that `giroCode` returns for one bank transfer.use Novis\Image\QrCode;
// The spaces in the IBAN are removed, and the amount gets 2 decimals.string $payment = QrCode::giroCode({ name: 'Shop GmbH', iban: 'DE89 3704 0044 0532 0130 00', amount: 49.9, text: 'Invoice 2024-0042',});
// Each field is on its own line. Empty fields are empty lines.foreach (Core\Str::split($payment, "\n") as string $line) { echo '[', $line, "]\n";}[BCD][002][1][SCT][][Shop GmbH][DE89370400440532013000][EUR49.90][][][Invoice 2024-0042]A qr code on an invoice
<?nvs// Shows how to draw a GiroCode for an invoice, so the customer can pay with a banking app.use Novis\Image\Image;use Novis\Image\QrCode;
string $payment = QrCode::giroCode({ name: 'Shop GmbH', iban: 'DE89370400440532013000', bic: 'COBADEFFXXX', amount: 129.0, reference: 'RF18539007547034',});
// `QrCode::render` draws the text as a QR code. The result is a PNG for the invoice.bytes $image = QrCode::render($payment, { size: 200 });var $info = Image::info($image);echo $info->width, ' by ', $info->height, " pixels\n";echo Image::mime($info->format), "\n";
// `QrCode::svg` draws the same code for an invoice page in HTML.string $html = '<p>Scan to pay:</p>' . QrCode::svg($payment);echo Core\Str::slice($html, 0, 23), "\n";200 by 200 pixelsimage/png<p>Scan to pay:</p><svgA wrong iban
<?nvs// Shows the errors `giroCode` throws for details that a bank would not accept.use Novis\Image\QrCode;
// The last digit of this IBAN is wrong, so its check digits do not match.try { QrCode::giroCode({ name: 'Shop GmbH', iban: 'DE89 3704 0044 0532 0130 01' }); echo "made a payment\n";} catch (LogicError $e) { echo $e->message, "\n";}
// An amount in euros has at most 2 decimals.try { QrCode::giroCode({ name: 'Shop GmbH', iban: 'DE89370400440532013000', amount: 9.999 }); echo "made a payment\n";} catch (LogicError $e) { echo $e->message, "\n";}
// A name with a line break throws an error. The line break could move the IBAN to a different line.try { QrCode::giroCode({ name: "Shop\nGmbH", iban: 'DE89370400440532013000' }); echo "made a payment\n";} catch (LogicError $e) { echo $e->message, "\n";}`DE89 3704 0044 0532 0130 01` is not a valid IBANan amount is from 0.01 to 999999999.99 euros, with at most 2 decimalsa field of a payment cannot contain a line break