How to send multiple items to PayPal - paypal

I want to send multiple item names and item prices to PayPal but I am unable to post my item name and price with below code can you please help me?
<form method="post" name="cart" action="https://www.sandbox.paypal.com/cgi-bin/webscr">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="navive_1295939206_biz#gmail.com">
<input type="hidden" name="lc" value="US">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="button_subtype" value="services">
<input type="hidden" name="notify_url" value="http://newzonemedia.com/henry/ipn.php" />
<input type="hidden" name="bn" value="PP-BuyNowBF:btn_buynowCC_LG.gif:NonHosted">
<input type="hidden" name="return" value="http://www.example.com/thank_you_kindly.html" />
<?php
//select items for table
$srowcart_dtl = mysql_num_rows($srscart_dtl);
if($srowcart_dtl > 0) {
$cnt=1;
while($srscart_dtl1 = mysql_fetch_assoc($srscart_dtl)) {
?>
<input type="hidden" name="item_name[<?php echo $cnt ?>]" value="<?php echo $srscart_dtl1['cart_iname']; ?>">
<input type="hidden" name="amount[<?php echo $cnt ?>]" value="<?php echo $srscart_dtl1['cart_iprc']; ?>">
<?php
$cnt++;
}
}
?>
<input type="image" src="https://www.paypal.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>

Create your code like this:
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_cart"> <!-- change _xclick to _cart -->
<input type="hidden" name="upload" value="1"> <!-- add this line in your code -->
<input type="hidden" name="business" value="your_seller_account">
<input type="hidden" name="item_name_1" value="Item Name 1">
<input type="hidden" name="amount_1" value="1.00">
<input type="hidden" name="item_name_2" value="Item Name 2">
<input type="hidden" name="amount_2" value="2.00">
<input type="submit" value="PayPal">
</form>

In addition to the changes suggested by devilprince, the underscores are missing from the line item input tags' name attributes, and also the tags are not proper self-closing tags because the closing / is missing. Correct like so:
<form method="post" name="cart" action="https://www.sandbox.paypal.com/cgi-bin/webscr">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="upload" value="1">
<input type="hidden" name="business" value="navive_1295939206_biz#gmail.com">
<input type="hidden" name="lc" value="US">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="button_subtype" value="services">
<input type="hidden" name="notify_url" value="http://newzonemedia.com/henry/ipn.php" />
<input type="hidden" name="bn" value="PP-BuyNowBF:btn_buynowCC_LG.gif:NonHosted">
<input type="hidden" name="return" value="http://www.mysite.org/thank_you_kindly.html" />
<?php
// select items for table
$srowcart_dtl = mysql_num_rows($srscart_dtl);
if($srowcart_dtl > 0)
{
$cnt=1;
while($srscart_dtl1 = mysql_fetch_assoc($srscart_dtl))
{
?>
<input type="hidden" name="item_name_[<?php echo $cnt ?>]" value="<?php echo $srscart_dtl1['cart_iname']; ?>"/>
<input type="hidden" name="amount_[<?php echo $cnt ?>]" value="<?php echo $srscart_dtl1['cart_iprc']; ?>"/>
<?php
$cnt++;
}
}
?>
<input type="image" src="https://www.paypal.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
(You may also want to escape special characters in the value attribute, at least for the " character in case it shows up in your item name data.)
Just had to figure this out today for a client. Besides item_name_N and amount_N I also used quantity_N, tax_N, and shipping_N (where N is the line item number, starting with 1).
This page has a list of all parameters: PayPal HTML Form Variables, but the question & answers given here are a better real-world example than the trivial examples on the PayPal site.

Related

Paypal BuyNow - GET instead of POST with params for returnUrl

I´m running into an issue that I detected today. I have the following paypal button config :
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" i d="paypalFormId">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="mybusinessID">
<input type="hidden" name="lc" value="DE">
<input type="hidden" name="button_subtype" value="services">
<input type="hidden" name="no_note" value="1">
<input type="hidden" name="no_shipping" value="2">
<input type="hidden" name="item_name" value="MyProductName">
<input type="hidden" name="amount" value="1.00">
<input type="hidden" name="custom" value="somecustom infos needed in the redirection">
<input type="hidden" name="rm" value="2">
<input type="hidden" name="return" value="https://myreturnurl.com">
<input type="hidden" name="cancel_return" value="https://mycancelurl.com">
<input type="hidden" name="currency_code" value="EUR">
<input type="hidden" name="notify_url" value="myIPNUrl">
<input type="hidden" name="bn" value="PP-BuyNowBF:btn_buynowCC_LG.gif:NonHosted">
<div class="row">
<button type="submit" class="btn btn-submit-next pull-right">Bestellung abschließen</button>
</div>
I didn´t change anything that could impact this code in the last days, nevertheless, redirection POST parameters are missing and redirection is a GET now and not a POST method anymore, even with the rm=2 !
Any idea, what´s going on ?
Best regards,
Antoine
Edited :
I was able to isolate the issue on JSFiddle : if I remove the item_name input then it works. I have no clue why but maybe it helps you guy telling me what I do wrong !
We had the same problem.
You need to enable "PDT", then the custom field will be returned in the "cm" variable of the return url post.
"Auto Return" also needs to be enabled to use "PDT", but you can still set the return URL in the button form post instead of in the "Auto Return" config if you need it to be dynamic.
https://developer.paypal.com/docs/classic/products/payment-data-transfer/
Try out this sandbox pay button and see what the response looks like when it is recorded on our return URL.
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick"><input type="hidden" name="amount" value="0.67">
<input type="hidden" name="cancel_return" value="http://test.smsportal.co.za/onlinePaymentv2/Testing3rdPartyResponse.aspx">
<input type="hidden" name="custom" value="this is the custom variable. it is named 'cm' in the returned Url.">
<input type="hidden" name="return" value="http://test.smsportal.co.za/onlinePaymentv2/Testing3rdPartyResponse.aspx">
<input type="hidden" name="rm" value="2">
<input type="hidden" name="cbt" value="Return to Merchant"> <input type="hidden" name="business" value="paypalmerchant#smsportal.com">
<input type="hidden" name="item_name" value="Credit Purchase">
<input type="hidden" name="currency_code" value="EUR">
<input type="hidden" name="button_subtype" value="services"><input type="hidden" name="bn" value="PP-BuyNowBF:btn_buynowCC_LG.gif:NonHostedGuest">
<input type="image" src="https://www.paypal.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="Pay now"><img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1"></form>

Change the default quantity added by "Add to cart" in PayPal checkout page

I have this "Add to cart" PayPal button:
<form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<div align="center">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="business" value="email#host.com">
<input type="hidden" name="item_name" value="An item to buy">
<input type="hidden" name="item_number" value="per dozen">
<input type="hidden" name="amount_1" value="48.00">
<input type="hidden" name="currency_code" value="USD">
<input type="image" src="https://www.paypal.com/images/x-click-but22.gif" border="0" name="submit7" alt="Make payments with PayPal - it's fast, free and secure!">
<img alt="" border="0" width="1" height="1" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif">
<input type="hidden" name="add" value="1">
</div>
It works fine if quantity added is 1:
<input type="hidden" name="add" value="1">
But it doesn't work if I try to change the default quantity added to 12:
<input type="hidden" name="add" value="12">
How can I fix this? Thanks.
Try will below code, It will change default quantity to 12:
<form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<div align="center">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="business" value="email#host.com">
<input type="hidden" name="item_name" value="An item to buy">
<input type="hidden" name="item_number" value="per dozen">
<input type="hidden" name="amount" value="48.00">
<input type="hidden" name="currency_code" value="USD">
<input type="image" src="https://www.paypal.com/images/x-click-but22.gif" border="0" name="submit7" alt="Make payments with PayPal - it's fast, free and secure!">
<img alt="" border="0" width="1" height="1" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif">
<input type="hidden" name="add" value="1">
<input type="hidden" name="quantity" value="11">
</div>
To know more about PayPal button parameters, check PayPal documentation

Paypal Sandbox Form - Empty Cart

I have been on this for a long time now but am unable to figure out the error no matter what I try.
<form action="https://www.sandbox.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="business" value="sales#mysite.co.uk">
<?php
$result = mysqli_query($DB, "SELECT * FROM salestemp WHERE id = '".$_REQUEST['sid'].
"' ") or die("Error: ".mysqli_error($DB));
$counter = 0;
while($row = mysqli_fetch_array($result))
{
$counter++;
?>
<input type="hidden" name="item_name_<?php echo $counter; ?>"
value="<?php echo urlencode($row['name']); ?>">
<input type="hidden" name="ammount_<?php echo $counter; ?>"
value="<?php echo urlencode($row['price']); ?>">
<input type="hidden" name="item_number_<?php echo $counter; ?>"
value="MD<?php echo urlencode($row['pid']); ?>">
<input type="hidden" name="quantity" value="1">
<?php
}
?>
<input type="hidden" name="currency_code" value="GBP">
<!-- Enable override of buyers's address stored with PayPal . -->
<input type="hidden" name="address_override" value="1">
<!-- Set variables that override the address stored with PayPal. -->
<input type="hidden" name="first_name" value="John">
<input type="hidden" name="last_name" value="Doe">
<input type="hidden" name="address1" value="345 Lark Ave">
<input type="hidden" name="city" value="San Jose">
<input type="hidden" name="state" value="CA">
<input type="hidden" name="zip" value="95121">
<input type="hidden" name="country" value="US">
<input type="image" name="submit" border="0"
src="https://www.paypalobjects.com/en_US/i/btn/btn_buynow_LG.gif"
alt="PayPal - The safer, easier way to pay online">
</form>
When submitting the form I am met with the "Error Detected: Your Cart Is Empty".
Can anyone help me at all please. Thank you very much in advance.
You have 'ammount' instead of 'amount'.

PayPal HTML form with select drop menu

I am trying to figure this one out, but I need some help.
I want to offer multiple products in the select list for a customer to choose and buy one.
<FORM action="https://www.paypal.com/cgi-bin/webscr" method="post">
<INPUT TYPE="hidden" name="cmd" value="_xclick"/>
<INPUT TYPE="hidden" name="charset" value="utf-8"/>
<INPUT TYPE="hidden" NAME="return" value="http://www.albertamomentummassage.com/gift-certificate-thank-you/"/>
<INPUT TYPE="hidden" NAME="rm" value="2"/>
<INPUT TYPE="hidden" NAME="currency_code" value="CAD"/>
<INPUT TYPE="hidden" NAME="business" value="daniel_1329709715_biz#gmail.com"/>
<select name="os_0" value="Therapeutic Massage">
<option value="2 Hour Masssage">2 Hour Massage $160.00 CAD</option>
<option value="90 Minute Massage">90 Minute Massage $120.00 CAD</option>
</select>
<input type="hidden" name="option_amount0" value="160"/>
<input type="hidden" name="option_amount1" value="120"/>
<input type="submit" src="http://www.paypal.com/en_US/i/btn/btn_buynow_LG.gif" />
</FORM>
Once I got redirected to PayPal I am missing, both, item description and item price.
You'll still need to send along an item_name field. The drop down list acts as a modifier for an item to add to the cart. In addition to the drop down list itself, you'll also need to send option_select(n) and option_amount(n) in your form. Check out the example below, it's from the Paypal button generator and should get you rolling.
<form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="business" value="Yourbiz#gmail.com">
<input type="hidden" name="lc" value="US">
<input type="hidden" name="item_name" value="Massage service">
<input type="hidden" name="button_subtype" value="products">
<input type="hidden" name="no_note" value="0">
<input type="hidden" name="currency_code" value="CAD">
<input type="hidden" name="add" value="1">
<input type="hidden" name="bn" value="PP-ShopCartBF:btn_cart_LG.gif:NonHostedGuest">
<table>
<tr><td><input type="hidden" name="on0" value="Duration">Duration</td></tr>
<tr><td>
<select name="os0">
<option value="90 minutes">90 minutes $120.00 CAD</option>
<option value="2 hours">2 hours $160.00 CAD</option>
</select>
</td></tr>
</table>
<input type="hidden" name="currency_code" value="CAD">
<input type="hidden" name="option_select0" value="90 minutes">
<input type="hidden" name="option_amount0" value="120.00">
<input type="hidden" name="option_select1" value="2 hours">
<input type="hidden" name="option_amount1" value="160.00">
<input type="hidden" name="option_index" value="0">
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_cart_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>

Paypal PDT return variable not sending

small problem with this old paypal button code..
I am trying to get the os0 and os1 to POST back with this script.. I am getting the amount and name, but that is all .. ?
Thanks!
I have a Simple form:
<form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post" style="float:left; width:49.9%">
<input type="image" src="https://www.paypal.com/en_US/i/btn/btn_cart_SM.gif" border="0" name="submit" alt="description">
<img alt="description" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
<input type="hidden" name="add" value="1">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="business" value="mm#mm.com">
<input type="hidden" name="item_name" value="Digital Image (Download ONLY)">
<input type="hidden" name="amount" value="6.00">
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" name="cancel_return" value="http://www.website.com/store/sorry.php">
<input type="hidden" name="return" value="http://www.website.com/store/thank_you.php">
<input type="hidden" name="no_note" value="0">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="lc" value="US">
<input type="hidden" name="rm" value="2">
<input type="hidden" name="bn" value="PP-ShopCartBF"><!--<br />
Phone Number:<input type="text" name="on1" maxlength="60">-->
<table><tr><td><input type="hidden" name="on0" value="Photo ID"></td>
<td><input name="os0" type="hidden" value="{name}" size="40" maxlength="200"></td></tr><tr><td>
<input type="hidden" name="on1" value="Thumbnail preview"></td>
<td><input name="os1" type="hidden" value="{image_url}/{name}" size="40" maxlength="200"></td></tr></table>
</form> <form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post" style="float:left; width:49.9%">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="business" value="mm#mm.com">
<input type="image" src="https://www.paypal.com/en_US/i/btn/btn_viewcart_SM.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<input type="hidden" name="display" value="1">
</form>
Once the user buys the product, they auto return w/ PDT enabled and I am trying to get back the variables os0 and os1 -- but nothing is coming back.
I get the amount and the first and last name, but not the option_selection1 or 2 ??
Here is my return script: ( I was trying different variables to see.. but nothing ? )
$firstname = $keyarray['first_name'];
$lastname = $keyarray['last_name'];
$option_name1 = $keyarray['option_name1'];
$option_name2 = $keyarray['option_name2'];
$custom = $keyarray['option_selection1'];
$os1 = $keyarray['os1'];
$option_selection2 = $keyarray['os2'];
$on1 = $keyarray['on1'];
$on2 = $keyarray['on2'];
$os1 = $keyarray['os1'];
$os2 = $keyarray['os2'];
$amount = $keyarray['payment_gross'];
echo ("<p><h3>Thank you for your purchase!</h3></p>");
echo ("<b>Payment Details</b><br>\n");
echo ("<ul><li>Name: $firstname $lastname</li>\n");
echo ("<li>Item: $option_name1</li>\n");
echo ("<li>Item Name: $option_name2</li>\n");
echo ("<li>Item Name 2: $option_selection1</li>\n");
echo ("<li>Item Name 2: $option_selection2</li>\n");
echo ("<li>Item: $custom</li>\n");
echo ("<li>Item: $on1</li>\n");
echo ("<li>Item Name: $on2</li>\n");
echo ("<li>Item Name 2: $os1</li>\n");
echo ("<li>Item Name 2: $os2</li>\n");
echo ("<li>Amount: $amount</li></ul>\n");
echo ("");
}
else if (strcmp ($lines[0], "FAIL") == 0) {
// log for manual investigation
}
Hi did you ever resolve this issue? I have just begun to create a pdt for my website and based on what I have learnt: 'option_name1' will pull the 'on0' label from your form, 'option_name2' will pull the 'on1' label, etc. same with 'option_selection1' (pulls the information entered in the 'os0' text field box) and 'option_selection2'.
So far I've only tried it in the sandbox environment, but I've found https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_html_IPNandPDTVariables to be useful.