Jump to content

PayPal IPN Return Item Data Dynamically Handled - item_number1, 2, 3 ect [code]


BizLab

Recommended Posts

Here is something i dreamt up, i know there is a way for this to work, but i'm not having any great ideas at this point. I want to be able to auto increment through the $_POST[] array data sent from a PayPal IPN. Sample return data looks like

 

item_number1=val

item_name1=val

 

so on and so forth. The idea is: While there are $_POST item_numbers, do something with it. The loop continues until there are no more item_numbers. I don't want to use the static methods eg: explicitly defining item_number1, item_number2, ect. This is what i thought would work, but keeps failing -> the script doesn't enter the first condition:

$x = 1; // set the initial item number
        while(isset($_POST['item_number$x'])){
            $qty = $_POST['quantity$x'];
            while($qty > 0){                
                // step through each item response result, setting each item to paid
                $package_id = $_POST['item_number$x'];    
                update_paid_status($transaction_id, $package_id);
                $qty--;            
            }
            $x++;
        }

Any Ideas?

Link to comment
Share on other sites

Testing shows that the problem is with the

$_POST['item_number$x']

more specifically the "$x" variable being stuck in there, but i don't know of another way to iterate through Paypal's slick POST variables... That line was intended to be displayed as:

$_POST['item_number1']
$_POST['item_number2']
$_POST['item_number3']

Link to comment
Share on other sites

I am not sure but is the way the dollar-sign with the [] is the way to do it? i have never seen that so i am not sure : )

I am afraid that i know nothing about paypal variables, but if your fetching array results why dont you use the For each loop? If i am correct using the while loop is possible to for running through them but you need list().  Not sure though but it's worth a try.

 

If you could maybe give more code i could come up with something : ) lol

 

May I ask how PayPal give it's "slick" post variables, and what is expected to be in them?

Link to comment
Share on other sites

I just renamed / changed something in your script which maybe is what your looking for, but i am pretty sure this while loop isnt right if your fetching array results. Here goes nothing  :shy:

 

$x = 1; // set the initial item number
        while(isset($_POST['item'].$x)){
            $qty = $_POST['quantity'].$x; // i placed a .$x behind it, 
            while($qty > 0){                
                // step through each item response result, setting each item to paid
                $package_id = $_POST['item'].$x;    // i placed a .$x behind it, 
                update_paid_status($transaction_id, $package_id);
                $qty--;            
            }
            $x++;
        }

 

Lol but i really just don't know what vars your dealing with

Link to comment
Share on other sites

I wrote something for you, maybe this is more as you like it:

 

   

    <?php
    $paypal_item["monkey"] = "3"; // an array with the name paypal_item, with an item name and quantity
    $paypal_item["donkey"] = "4";
    $paypal_item["frog"] = "6";
    $paypal_item["kitty"] = "1";
    $paypal_item["lepricorn"] = "8";
    $paypal_item["cow"] = "300";
   

    function paypal_custom_function($array){ // a custom function to loop through the paypal array.
        foreach($array as $item => $quantity){
            echo "item: {$item} quantity: {$quantity}.<br />\n";
            update_paid_status($transaction_id, $package_id)or die ('error');
            echo 'result = succes!<br />';
        }
    }
    
    echo paypal_custom_function($paypal_item);  //An echo that calls the function and loops through everything gives an error if needed and else succes
?>

Link to comment
Share on other sites

GREAT EYE DAVIDAM!!!! And thanks for the help Fortnox

All that is left is to work out the processes and i will be 100% thanks to the awesome contributors in this forum

 

When you put a variable inside of single quotes it is a literal. When you use double quotes, it is interpreted:

$x = 1;
$key = 'item_number$x'; // $key will be item_number$x

$key = "item_number$x"; // $key will be item_number1

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.