'BCD', 'version' => 2, 'characterSet' => 1, 'identification' => 'SCT', 'bic' => '', 'purpose' => '', ]; public function __construct(protected Company $company, protected Invoice $invoice, protected float $amount){} public function getQrCode() { $renderer = new ImageRenderer( new RendererStyle(200), new SvgImageBackEnd() ); $writer = new Writer($renderer); $this->validateFields(); $qr = $writer->writeString($this->encodeMessage()); nlog($qr); return " {$qr}"; } public function encodeMessage() { return rtrim(implode("\n", array( $this->sepa['serviceTag'], sprintf('%03d', $this->sepa['version']), $this->sepa['characterSet'], $this->sepa['identification'], isset($this->company?->custom_fields?->company2) ? $this->company->settings->custom_value2 : '', $this->company->present()->name(), isset($this->company?->custom_fields?->company1) ? $this->company->settings->custom_value1 : '', $this->formatMoney($this->amount), $this->sepa['purpose'], substr($this->invoice->number,0,34), substr($this->invoice->public_notes,0,139), '' )), "\n"); } private function validateFields() { if(isset($this->company?->custom_fields?->company2)) nlog('The BIC field is not present and _may_ be a required fields for EPC QR codes'); if(isset($this->company?->custom_fields?->company1)) nlog('The IBAN field is required'); } private function formatMoney($value) { return sprintf('EUR%s', number_format($value, 2, '.', '')); } }