[solved] Rate refund, posible bug?

Hi,

I’m trying to make a refund under some circumstances and I found “rate_refund” and “simplerate_hook_rate_refund” that seems to be what I need.
The problem is that “simplerate_hook_rate_refund” seems that doesn’t work.

I tried to find the problem and I think that it is in the call to “$db_row = dba_fetch_row($db_result)”

First I get the query and executed directly from my db:
SELECT p_dst,p_msg,uid FROM playsms_tblSMSOutgoing WHERE p_status='2' AND smslog_id='1619'

This give me a row:
p_dst p_msg uid
XXXX Test07 13

Then I looked into “$db_result” with “print_r($db_result, true)”:
DB_result Object ( [autofree] => [dbh] => DB_mysql Object ( [phptype] => mysql [dbsyntax] => mysql [features] => Array ( [limit] => alter [new_link] => 4.2.0 [numrows] => 1 [pconnect] => 1 [prepare] => [ssl] => [transactions] => 1 ) [errorcode_map] => Array ( [1004] => -15 [1005] => -15 [1006] => -15 [1007] => -5 [1008] => -17 [1022] => -5 [1044] => -26 [1046] => -14 [1048] => -3 [1049] => -27 [1050] => -5 [1051] => -18 [1054] => -19 [1061] => -5

I assume that “[numrows] => 1” is the correct thing.
But when “$db_row = dba_fetch_row($db_result)” is executed, nothing is returned.

Also, I see that in this function, it read $p_footer and $unicode, but this fields are not readed from the db

Any hint on that?

I don’t understand your post, yet, sorry :smile:

how was it “doesn’t work”, how do you use rate_refund, how do you know it doesn’t work ?

I rarely use dba_fetch_row, why use that ? I use dba_fetch_array alot, how do you use the dba_fetch_row

can you show me your code ?

anton

Hi Anton,

The code is the function “simplerate_hook_rate_refund”.

Following the example in my previous post, I only call to “rate_refund” with the “smslog_id”:
$smslog_id = 1619;
rate_refund($smslog_id);

I only added to “simplerate_hook_rate_refund” a pair of lines with “print_r($db_result, true)” to see what is happening:

function simplerate_hook_rate_refund($smslog_id) {
    global $core_config;

    logger_print("start smslog_id:" . $smslog_id, 2, "simplerate refund");
    $db_query = "SELECT p_dst,p_msg,uid FROM " . _DB_PREF_ . "_tblSMSOutgoing WHERE p_status='2' AND smslog_id='$smslog_id'";
    $db_result = dba_query($db_query);
    logger_print("result: ".print_r($db_result, true), 2, "simplerate refund");
    if ($db_row = dba_fetch_row($db_result)) {
        // This is never reached!!
        logger_print("row: ".print_r($db_row, true), 2, "simplerate refund");
        $p_dst = $db_row['p_dst'];
        $p_msg = $db_row['p_msg'];
        $p_footer = $db_row['p_footer']; // This is not needed
        $uid = $db_row['uid'];
        $unicode = $db_row['unicode']; // This is not needed
        if ($p_dst && $p_msg && $uid) {
            if (billing_rollback($smslog_id)) {
                $bill = billing_getdata($smslog_id);
                $credit = $bill['credit'];
                $charge = $bill['charge'];
                $status = $bill['status'];
                ........

ok, first, see this:

its using dba_fetch_array()

secondly, to successfully refund the message needs to be failed, p_status=2, so you cannot just refund any smslog_id

anton

Hi Anton, thank you for your fast support.

Yes, I know that that the message need to be failed.
I have a message with this condition to test. If you look to the first post, you can see that “dba_query($db_query)” gives me a row, but “dba_fetch_row($db_result)” return nothing.

I executed the same query directly in my mysql db, and it returns the message I tell you:
"SELECT p_dst,p_msg,uid FROM playsms_tblSMSOutgoing WHERE p_status=‘2’ AND smslog_id=‘1619’"
return:
p_dst p_msg uid
XXXX Test07 13

Greetings.

ok, sorry for my slowness, so the bug is in the dba_fetch_row() ?

anyway, why forcing to use dba_fetch_row() ? while the code is currently in dba_fetch_array()

I tested dba_fetch_array and row, looks ok on my laptop.

to conclude:

I still don’t know why it never reached that print_r you mentioned, but I also don’t know why you keep using dba_fetch_row while the current code is using dba_fetch_array

and I have tested both dba_fetch_array and dba_fetch_row, both are working as expected, no bugs

anton

I’m sorry, I mean “dba_fetch_array”, I changed to “dba_fetch_row” to see if this return something, but nothing.
Ok, I will test it again.
Currently I’m on 1.3.1.

This is very strange for me because the data seems to be ok, but “dba_fetch_array” doesn’t returns nothing.

Greetings.

btw, some action is done by playsmsd, so you need to restart it to see it on log

anton

Finally I solved my problem.
Thank you for your attention Anton.

Greetings.