sprain / php-swiss-qr-bill

A PHP library to create Swiss QR bills | QR-Rechnung in PHP erstellen
MIT License
274 stars 79 forks source link

Character set windows-1252 should be CP1252 under Unix #245

Closed supercosh closed 1 week ago

supercosh commented 8 months ago

In /src/PaymentPart/Output/FpdfOutput/FpdfOutput.php, the following code is found:

return iconv('UTF-8', 'windows-1252', $text) ?: '';

Under unix, the character set should be called "CP1252", since "windows-1252" is unknown on most systems. Also I'm not sure if the code is correct, since the funktion name is "toUtf8", but what the code does, is to convert "from" UTF8.

The occurence of "windows-1252" is in several files.

sprain commented 8 months ago

Thanks for reporting.

Do you experience any problems because of this or is it just "cosmetics"?

supercosh commented 8 months ago

It just throws a PHP warnings every time a QR bill is created; the generated qr bill however seems to be valid. So it's not a severe problem, it just got me curious because of the growing logs. A solution could perhaps be to get a list of the character sets on the system and chose one of them?

sprain commented 8 months ago

Could you post the exacting warning that you get? This might help to improve this.

supercosh commented 7 months ago

Here's the warning

2024-01-26 15:54:25 warning: iconv(): Wrong encoding, conversion from "UTF-8" to "windows-1252" is not allowed
Trace:
iconv [internal], line ??
Sprain\SwissQrBill\PaymentPart\Output\TcPdfOutput\TcPdfOutput::toUtf8() /httpdocs/vendor/sprain/swiss-qr-bill/src/PaymentPart/Output/TcPdfOutput/TcPdfOutput.php, line 358
Sprain\SwissQrBill\PaymentPart\Output\TcPdfOutput\TcPdfOutput::setFurtherInformationElement() /httpdocs/vendor/sprain/swiss-qr-bill/src/PaymentPart/Output/TcPdfOutput/TcPdfOutput.php, line 286
Sprain\SwissQrBill\PaymentPart\Output\TcPdfOutput\TcPdfOutput::setContentElement() /httpdocs/vendor/sprain/swiss-qr-bill/src/PaymentPart/Output/TcPdfOutput/TcPdfOutput.php, line 233
Sprain\SwissQrBill\PaymentPart\Output\TcPdfOutput\TcPdfOutput::addFurtherInformationContent() /httpdocs/vendor/sprain/swiss-qr-bill/src/PaymentPart/Output/TcPdfOutput/TcPdfOutput.php, line 213
Sprain\SwissQrBill\PaymentPart\Output\TcPdfOutput\TcPdfOutput::getPaymentPart() /httpdocs/vendor/sprain/swiss-qr-bill/src/PaymentPart/Output/TcPdfOutput/TcPdfOutput.php, line 89

And here is the code:

$qr = QrBill::create();
$qr->setCreditor(CombinedAddress::create(...));
$qr->setCreditorInformation(CreditorInformation::create(...));
$qr->setUltimateDebtor(StructuredAddress::createWithoutStreet(...));
$qr->setPaymentAmountInformation(PaymentAmountInformation::create('CHF', $total));
$qr->setPaymentReference(PaymentReference::create(PaymentReference::TYPE_QR, $qr_nummer));

$output = new TcPdfOutput($qr, 'de', $pdf);
$output->getPaymentPart();
merlincom commented 1 week ago

Do you experience any problems because of this or is it just "cosmetics"? The problem: With the self-generated reference number, there is no output of the payment slip

supercosh commented 1 week ago

The problem: With the self-generated reference number, there is no output of the payment slip

This, on the other hand, works for me. But there is an exception every time I generate a payment slip. The PDF is fine, but it just fills the php error log and I can't catch-try it, since it is a php warning and not an exception.

kohlerdominik commented 1 week ago

Hi @merlincom @supercosh

I suggested a change in #260, but I'm not sure yet if this will be 100% compatible, we need to wait for sprain.

In the meanwwhile, I would appreciate if you could test my fix in your environment? To do that, you need to redirect composer to my fork, and then require the branch with the fix:

In composer.json add this: (at the top as first item, but inside the root-{}, is fine)

    "repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/kohlerdominik/php-swiss-qr-bill"
        }
    ],

like this grafik

Then update the package

composer require sprain/swiss-qr-bill:dev-pdf-unsupported-characters
merlincom commented 1 week ago

Today I get a Error-Message with my own generated RF-Number : $referenceNumber = 'RF2953900754240831094548' ; // Results in an error Fatal error: Uncaught Sprain\SwissQrBill\Exception\InvalidQrBillDataException: The provided data is not valid to generate a qr code. Use getViolations() to find details. in /vendor/sprain/swiss-qr-bill/src/QrBill.php:182 Stack trace: #0 /vendor/sprain/swiss-qr-bill/src/PaymentPart/Output/AbstractOutput.php(187): Sprain\SwissQrBill\QrBill->getQrCode('png') #1 /vendor/sprain/swiss-qr-bill/src/PaymentPart/Output/FpdfOutput/FpdfOutput.php(100): Sprain\SwissQrBill\PaymentPart\Output\AbstractOutput->getQrCode() #2 /vendor/sprain/swiss-qr-bill/src/PaymentPart/Output/FpdfOutput/FpdfOutput.php(78): Sprain\SwissQrBill\PaymentPart\Output\FpdfOutput\FpdfOutput->addSwissQrCodeImage() #3 ... .php(917): Sprain\SwissQrBill\PaymentPart\Output\FpdfOutput\FpdfOutput->getPaymentPart()

sprain commented 1 week ago

@merlincom

The reference number you are using is invalid. You can also use this validator to check this.

See this example on how to create a reference number with the tools provided by this library. For your own implementation that you mentioned yesterday, we cannot provide support here.

Please also note how you can find what part of the qr invoice is wrong, as shown here.

merlincom commented 1 week ago

Vielen Dank für den Hinweis auf https://kahur.ee/rfcalculator/ und die eigene Funktion von Swiss-QR-Bill. Mit der Anleitung hat es auch Anhieb geklappt.

Thank you for pointing out Swiss-QR-Bill's own function. The instructions worked straight away.

Greetings from Marcel aus Basel

Am 04.09.2024 um 07:52 schrieb Manuel Reinhard:

@merlincom https://github.com/merlincom

The reference number you are using is invalid. You can also use this validator to check this. https://kahur.ee/rfcalculator/. So this is unrelated to this current issue.

See this example <https://github.com/sprain/php-swiss-qr-bill/ blob/5490e9139c4050d18533440cd9ff51a64955c035/example/ example_scor.php#L59> on how to create a reference number with the tools provided by this library. For your own implementation that you mentioned yesterday <https://github.com/sprain/php-swiss-qr-bill/ issues/259#issue-2502201214>, we cannot provide support here.

Please also note how you can find what part of the qr invoice is wrong, as shown here <https://github.com/sprain/php-swiss-qr-bill/ issues/259#issuecomment-2325935567>.