Results 1 to 7 of 7
  1. #1
    Join Date
    Aug 2007
    Location
    Gijón, Asturias, Spain
    Posts
    2,589
    Plugin Contributions
    30

    Default trying to pass a variable from one function to another in same payment class instance

    After a great deal of time and trial and error I am stumped with this basic php variable handling and I would be grateful for some help.

    To cut a long story short I am playing with the cod module (although I want to implement the hacks in another module that I can only test live).

    I have declared the new variable ($Qb_order_no) I want to use:
    PHP Code:
      class cod {
        var 
    $code$title$description$enabled$Qb_order_no
    and have set it here:

    PHP Code:
        function process_button() {
        global 
    $order$db;
        
    $gv_query"insert into qb_zhenit (pedido) values ('".urlencode(serialize($order))."')";//creates new record for this order in table qb_zhenit
        
    $gv $db->Execute($gv_query);
        
    $this->Qb_order_no $db->Insert_ID();
        echo 
    'fn Process Button: $this->Qb_order_no='.$this->Qb_order_no.'<br />';
    //    return false;
        

    I see the $this->Qb_order_no as being set correctly (an integer) at the bottom of the order confirmation page.

    Then I want to use this variable again here:

    PHP Code:
    function after_process() {
            global 
    $order$db$insert_id;
            echo 
    'fn After Process: $this->Qb_order_no='.$this->Qb_order_no.'<br />';
            
    $query_add_order_id "UPDATE qb_zhenit SET orders_id=$insert_id WHERE id = $this->Qb_order_no";  
            echo 
    '$query_add_order_id ='.$query_add_order_id.'<br />';  
            
    $db->Execute($query_add_order_id);
          
    //return false;
        

    Here $this->Qb_order_no is empty.

    If I set
    $this->Qb_order_no ='999'; in the constructor,

    then I find that:

    in process_button it has the correct value,
    but in after_process it has '999'

    which looks like after_process is evaluated before process_button.

    No doubt this is trivial, but I am stuck...

  2. #2
    Join Date
    Aug 2007
    Location
    Gijón, Asturias, Spain
    Posts
    2,589
    Plugin Contributions
    30

    Default Re: trying to pass a variable from one function to another in same payment class inst

    Bump!

    I only come here as a last resort, surely someone is qualified to say this should work/will never work?

    This is the last bit of fixing up a flaky payment module which will be a contribution.
    Steve
    github.com/torvista: Spanish Language Pack, Google reCaptcha, Structured Data, Multiple Copy-Move-Delete, Image Checker, BackupMySQL Admin/Auto...

  3. #3
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: trying to pass a variable from one function to another in same payment class inst

    ->process_button() is executed when preparing the "confirm" button on the checkout_confirmation screen.

    And then the customer is redirected to the next page, whether an offsite service, or the store's own checkout_process screen.

    And then the ->before_process() and ->after_process() methods are triggered, but the classes are re-instantiated afresh, with no knowledge of prior instantiations.
    If you want information to survive between process_button and after_process, you'll need to rethink how you do it. One way, although not necessarily the only or best way, might be to create a session variable to hold the information, along with checks and balances to ensure the value is good before accepting it for use.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  4. #4
    Join Date
    Aug 2007
    Location
    Gijón, Asturias, Spain
    Posts
    2,589
    Plugin Contributions
    30

    Default Re: trying to pass a variable from one function to another in same payment class inst

    great, thanks. I would not have expected the class to be re-instantiated.
    Steve
    github.com/torvista: Spanish Language Pack, Google reCaptcha, Structured Data, Multiple Copy-Move-Delete, Image Checker, BackupMySQL Admin/Auto...

  5. #5
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: trying to pass a variable from one function to another in same payment class inst

    You might also pass another variable in your process_button output, and then read that value in your after_process processing. Again, some validation needs to be done to ensure it's not been tampered with.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  6. #6
    Join Date
    Aug 2007
    Location
    Gijón, Asturias, Spain
    Posts
    2,589
    Plugin Contributions
    30

    Default Re: trying to pass a variable from one function to another in same payment class inst

    that's enough for me to go on, thanks again
    Steve
    github.com/torvista: Spanish Language Pack, Google reCaptcha, Structured Data, Multiple Copy-Move-Delete, Image Checker, BackupMySQL Admin/Auto...

  7. #7
    Join Date
    Aug 2007
    Location
    Gijón, Asturias, Spain
    Posts
    2,589
    Plugin Contributions
    30

    Default sanitizing variables

    It turns out the variable (a transaction number) was there all the time and being returned back by the gateway.

    It is stored by this method which is called by the page the gateway returns to.

    function save_result(){//steve added orders_id to query
    global $db, $insert_id;
    $this->trace("Desde: ".$_SERVER['REMOTE_ADDR']." pide:".$_SERVER['REQUEST_URI'].":\n" .
    $_REQUEST['result'] . "\n" .
    $_REQUEST['pszPurchorderNum'] . "\n" .
    $_REQUEST['pszTxnId'] . "\n" .
    $_REQUEST['pszTxnDate'] . "\n" .
    $_REQUEST['tipotrans'] . "\n" .
    $_REQUEST['store'] . "\n" .
    $_REQUEST['coderror'] . "\n" .
    $_REQUEST['deserror']);
    $sql = "update qb_zhenit set
    orders_id = $insert_id,
    resultado = '".$_REQUEST['result']."',
    pszTxnID='".$_REQUEST['pszTxnDate']."',
    deserror='".$_REQUEST['deserror']."' where id='".$_REQUEST['pszPurchorderNum']."'";
    echo '$sql='.$sql;
    $db->Execute($sql);
    }
    My first question is regarding posting these $_REQUEST variables directly into the database "as is".
    Should there not be some sort of sanitizing going on?
    If so, where can I find an example.

    Secondly I have added the global $insert_id, I assume its available at this point as its available to function after_process()?
    Steve
    github.com/torvista: Spanish Language Pack, Google reCaptcha, Structured Data, Multiple Copy-Move-Delete, Image Checker, BackupMySQL Admin/Auto...

 

 

Similar Threads

  1. Trying to clone from one website to another
    By flyspidert in forum General Questions
    Replies: 4
    Last Post: 27 Mar 2013, 07:08 PM
  2. Moving DB from one domain to another on same server
    By donzi in forum General Questions
    Replies: 10
    Last Post: 23 Mar 2013, 01:31 AM
  3. Trying to transfer SQL dump from one database to another
    By datatv in forum General Questions
    Replies: 3
    Last Post: 3 Jul 2012, 10:13 PM
  4. Transfering one site from one Domain to another on the same server?
    By gmartakis in forum Installing on a Linux/Unix Server
    Replies: 21
    Last Post: 13 Feb 2012, 08:56 AM
  5. Pass variable from link to Discount Coupon Code
    By MrForce in forum General Questions
    Replies: 0
    Last Post: 17 Apr 2008, 06:07 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR