Kamlesh
Kamlesh

Reputation: 105

PHP Paypal pass multiple items dynamically

I am trying to add multiple products for processing on paypal. The order summery is not showing any item. I am trying it on paypal sandbox.

Here is the complete code :

    <form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" id="paypal">

 <input type="hidden" name="cmd" value="_xclick" />
 <input type="hidden" name="upload" value="1">
 <input type="hidden" name="cbt" value="Return to max shop" />
 <input type="hidden" name="business" value="[email protected]">

<?php
if(isset($_SESSION['products']))
{
    $obj=new project;
    $i=1;
    foreach($_SESSION['products'] as $product)
    {
        $sql=$obj->get_products($product['id']);
        $row=mysql_fetch_array($sql);
        ?>
        <input type="hidden" name="item_number_<?php echo $i ?>" value="<?php echo $i ?>">
        <input type="hidden" name="item_name_<?php echo $i ?>" value="<?php echo $row['title'] ?>" />

        <input type="hidden" name="amount_<?php echo $i ?>" value="<?php echo $row['cost'] ?>">
        <input type="hidden" name="item_quantity_<?php echo $i ?>" value="<?php echo $product['qty'] ?>">

        <?php
        $i++;
    }
}
?>


 <input type="hidden" name="button_subtype" value="services" />
 <input type="hidden" name="no_shipping" value="1" />
 <input type="hidden" name="return" value="http://localhost/oops" />

<input type="hidden" name="currency_code" value="USD"/>

<input type="hidden" id="custom" name="custom" value="invoice_id to track"/>
 <input type="hidden" class="btn btn-primary" style="width:100%" alt="PayPal - The safer, easier way to pay online!"/>
<input type="image" src="http://www.paypalobjects.com/en_US/i/btn/x-click-but23.gif" border="0" name="submit" width="68" height="23" alt="Make payments with PayPal - it's fast, free and secure!">
</form>

I also tried the array format like below but did not recieved any result;

    <input type="hidden" name="item_number[<?php echo $i ?>]" value="<?php echo $i ?>">
<input type="hidden" name="item_name[<?php echo $i ?>]" value="<?php echo $row['title'] ?>" />
    <input type="hidden" name="amount[<?php echo $i ?>]" value="<?php echo $row['cost'] ?>">
    <input type="hidden" name="item_quantity[<?php echo $i ?>]" value="<?php echo $product['qty'] ?>">

Upvotes: 1

Views: 1276

Answers (1)

Vimalnath
Vimalnath

Reputation: 6463

Upload command works only for _cart and not _xclick.

Change this line to :

 <input type="hidden" name="cmd" value="_cart" />

<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" id="paypal">

 <input type="hidden" name="cmd" value="_cart" />
 <input type="hidden" name="upload" value="1">
 <input type="hidden" name="cbt" value="Return to max shop" />
 <input type="hidden" name="business" value="[email protected]">

<?php
$_SESSION['products'] =2;
$product ='';
$pro =array("red","green"); 
if(isset($_SESSION['products']))
{
    // $obj=new project;
    $i=1;
    foreach($pro as $key)
    {
        //$sql=$obj->get_products($product['id']);
        $row='row';
        ?>
        <input type="hidden" name="item_number_<?php echo $i ?>" value="<?php echo $i ?>">
        <input type="hidden" name="item_name_<?php echo $i ?>" value="title" />

        <input type="hidden" name="amount_<?php echo $i ?>" value="10.00">
        <input type="hidden" name="item_quantity_<?php echo $i ?>" value="product">

        <?php
        $i++;
    }
}
?>


 <input type="hidden" name="button_subtype" value="services" />
 <input type="hidden" name="no_shipping" value="1" />
 <input type="hidden" name="return" value="http://localhost/oops" />

<input type="hidden" name="currency_code" value="USD"/>

<input type="hidden" id="custom" name="custom" value="invoice_id to track"/>
 <input type="hidden" class="btn btn-primary" style="width:100%" alt="PayPal - The safer, easier way to pay online!"/>
<input type="image" src="http://www.paypalobjects.com/en_US/i/btn/x-click-but23.gif" border="0" name="submit" width="68" height="23" alt="Make payments with PayPal - it's fast, free and secure!">
</form>

Upvotes: 1

Related Questions