Reputation: 3209
Hey ya'll I have a question. I have a shopping cart on my page and that works fine and it stores the information in a session and passes it to paypal using this form....
<?php $items = unserialize($_SESSION['items']); ?>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="no_note" value="1">
<input type="hidden" name="business" value="[email protected]">
<input type="hidden" name="currency_code" value="CAD">
<input type="hidden" name="return" value="http://www.mysite.com/">
<input type="hidden" name="item_name" value="<?php echo $items['1_']['name']; ?>">
<input type="hidden" name="amount" value="<?php echo $items['1_']['price']; ?>">
<input type="submit" name="paypal" id="paypal" value="Checkout" />
</form>
But when my session has more than one item paypal only take both items only one.
So my question is how to do pass multiple items to paypal using this form?
If someone can point me in the right direction that would be terrific!
Thanks in advanced,
Upvotes: 2
Views: 3997
Reputation: 91
In case anyone else stumbles on this in the future, make sure you follow @strkol's post.
I struggled with this until I changed _xclick to _cart and added
<input type="hidden" name="upload" value="1">
Upvotes: 0
Reputation: 64526
Use a cmd
value of _cart instead of _xclick, also include an upload=1 value:
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="upload" value="1">
You need to repeat the item_name
and amount
inputs for every item in the cart, but use a counter as a suffix e.g. item_name_x
and amount_x
. x
should be 1 for the first item, and increment for each other item in the cart. So the first item would be item_name_1
and item_amount_1
.
Full documentation - scroll down to Method 2. Passing Individual Items to PayPal
:
https://www.paypal.com/cgi-bin/webscr?cmd=p/pdn/howto_checkout-outside
So your code could look something like:
<?php $items = unserialize($_SESSION['items']); ?>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="upload" value="1">
<input type="hidden" name="no_note" value="1">
<input type="hidden" name="business" value="[email protected]">
<input type="hidden" name="currency_code" value="CAD">
<input type="hidden" name="return" value="http://www.mysite.com/">
<?php
$suffix = 1;
foreach($items as $item):
?>
<input type="hidden" name="item_name_<?php echo $suffix; ?>" value="<?php echo $item['name']; ?>">
<input type="hidden" name="amount_<?php echo $suffix; ?>" value="<?php echo $item['price']; ?>">
<?php
$suffix++;
endforeach;
?>
<input type="submit" name="paypal" id="paypal" value="Checkout" />
</form>
Upvotes: 4
Reputation: 2029
First change _xclick to _cart, then add a new hidden field:
<input type="hidden" name="upload" value="1">
And then use item_name_1, item_amount_1, item_name_2, item_amount_2 ... item_name_N, item_amount_N to pass your multiple items to PayPal.
Upvotes: 2