Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$payment->getQrString(); broken? #61

Closed
fafayqa opened this issue Jun 11, 2024 · 1 comment
Closed

$payment->getQrString(); broken? #61

fafayqa opened this issue Jun 11, 2024 · 1 comment

Comments

@fafayqa
Copy link

fafayqa commented Jun 11, 2024

<?php

require_once('vendor/autoload.php');

use rikudou\SkQrPayment\QrPayment;
use Rikudou\Iban\Iban\IBAN;

$payment = new QrPayment();
$payment
    ->setXzBinary('xz')
    ->setCurrency('EUR')
    ->setAmount(10)
    ->setComment('financny dar, ')
    ->setIbans([
        new IBAN('SK6807200002891987426353')
    ]);

$qrString = $payment->getQrString();

echo $qrString;
?>

Output string is 0005C00 ???

Likewise, if I use your example from this webpage:

<?php

require_once('vendor/autoload.php');

use rikudou\SkQrPayment\QrPayment;
use Rikudou\Iban\Iban\IBAN;

$payment = new QrPayment(new IBAN('SK6807200002891987426353'));
$payment
    ->setXzBinary('xz')
    ->setAmount(500)
    ->setVariableSymbol('123456')
    ->setDueDate(new DateTime('+1 week'))
;

$qrString = $payment->getQrString();


// $qrString now holds the string to embed inside the QR code, in this example:
// 0004U0001M8GLP3E8KPT058IQ99QISMB02IH36MOD4BCKQQGVDE4641AOA2NURPCOPSALFG0LPG1C6N0E2JMC7RG2F4L2E57OCSHOUROGHOC8VTTPHHRFHU6VFTM8N80


echo $qrString;
?>

Output string is 0004U00 instead of supposed 0004U0001M8GLP3E8KPT058IQ99QISMB02IH36MOD4BCKQQGVDE4641AOA2NURPCOPSALFG0LPG1C6N0E2JMC7RG2F4L2E57OCSHOUROGHOC8VTTPHHRFHU6VFTM8N80

Did I miss to enable something somewhere, like some PHP extension or what?

Using QrPaymentSK v4.2.1

UPDATE
I was investigating some more in your getQrString() function in QrPayment.php file, and I found out that until the line 196 proc_close($xzProcess); variable $hashedData still holds all the correct values that were defined in $payment options (Ô ŔŹ 1 1 10 EUR 20240611 financny dar, 1 SK7783605207004206972399 BREXSKBX 0 0).
BUT as soon as the line $hashedData = bin2hex("\x00\x00" . pack('v', strlen($hashedData)) . $pipeOutput); happens, the new variable $hashedData suddenly becomes 00005600.

Investigating even more: important variable $pipeOutput is (seems to be) EMPTY, which means that stream_get_contents($xzProcessPipes[1]) returns nothing?!

Now as I search for the src of the $pipeOutput I see it is probably made by $xzProcess (cos that is the 1st time in the code it appears, thus my impression) which trying to call proc_open and I see it is the only call to proc_open in the file (so what I write further would have its logic, I guess), but interestingly enough, when I was trying to make Composer work I had to run it on a different PC, where I had to manually install PHP 8.1 from scratch, cos here on my PC where I run my testserver with PHP 8.1 it was Unable to launch a new process, which I was told by one guy (I guess author of the Composer, I'm not sure now) might be caused because my server - for some reason - does not allow proc_open. Which by itself is strange cos it is not disabled in the php.ini at all!

These are just my thoughts - still waiting for your actual answer tho!

UPDATE 2
Well, I tried it on that another PC where I was able successfully running Composer (= no problem with launching new process there), but the result is the same, thus I now think it is not the case of my server possibly not allowing proc_open - IT HAS TO BE SOMETHING ELSE!!! Indeed, I tested on my actual local testserver if proc_open works with this code, and it does work (output is echoed into the webpage in a loop):

<?php
set_time_limit(1800);
ob_implicit_flush(true);

$exe_command = 'C:\\Windows\\System32\\ping.exe -t google.com';

$descriptorspec = array(
    0 => array("pipe", "r"),  // stdin
    1 => array("pipe", "w"),  // stdout -> we use this
    2 => array("pipe", "w")   // stderr 
);

$process = proc_open($exe_command, $descriptorspec, $pipes);

if (is_resource($process))
{
    while( ! feof($pipes[1]))
    {
        $return_message = fgets($pipes[1], 1024);
        if (strlen($return_message) == 0) break;

        echo $return_message.'<br />';
        ob_flush();
        flush();
    }
}
?>

If I save to a text file values with file_put_contents("test.txt", $pipeOutput.'<br>'.$hashedData.'<br>'.$xzProcessPipes[0].'<br>'.$xzProcessPipes[1]); right after the line 200 $hashedData = bin2hex("\x00\x00" . pack('v', strlen($hashedData)) . $pipeOutput);, then the result is: <br>00005600<br>Resource id #25<br>Resource id #26 (in case this info would help you somehow in your investigation at all).

Hmm, maybe the xz binary ($xzProcess) is not producing expected result = no result at all, actually (maybe if you know some 100% functional xz binaries download link that you are using yourself, I could try those instead of those I have now)?

I just deleted everything in the xy folder and...no error was produced, and code works still - how come??? There are literally no files in the xz folder now, yet all seems to working OK (except the broken output string, of course) - WHAT IS GOING ON HERE???

I WOULD SAY THIS REVELATION ALONE BASICALLY SAYING WHERE THE RPOBLEM IS: does your script actually check not only for the xz binaries folder, but also for the actual binary files in there it requires for the actual code/output? Seems not...

Everything here is just my uncompetent thoughts...7+ hrs passed and I still wait for any reaction from you. :-(((

@fafayqa fafayqa changed the title $qrString broken? $payment->getQrString(); broken? Jun 11, 2024
@RikudouSage
Copy link
Owner

RikudouSage commented Jun 13, 2024

Hi there, my guess would be that your xz binaries are wrong and don't produce the required results. You might try this for the xz tools: https://tukaani.org/xz/xz-5.2.9-windows.zip. Inside there's a bin_x86-64 directory which is most likely the one you need. Inside it there's the xz.exe, you might want to set the binary path to it.

Edit: Though I haven't tested it, I don't use Windows myself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants