Adding a Tickbox Before PayPal Button - paypal

I use the following code to add a tickbox to agree to T&Cs before taking PayPal payment. The code works well but not if there are more than one tickboxes on the same page, in which case it wants the first tickbox ticked before proceeding.
How do I amend the code so that it functions with more than one tickbox on a page, please?
<script type="text/javascript"> // <![CDATA[
function confSubmit() {
if(!document.getElementById("accept").checked) {
alert("Please read and accept the Terms and Conditions in order to continue.");
return false;
}
} // ]]></script>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" onsubmit="return confSubmit();">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="LAT8US8737YM66">
<p><input id="accept" type="checkbox"> I have read and agree to the Terms and Conditions</p>
<input type="image" src="https://www.paypalobjects.com/en_US/GB/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.paypalobjects.com/en_GB/i/scr/pixel.gif" width="1" height="1">
</form>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" onsubmit="return confSubmit();">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="LAT8US8737YM66">
<p><input id="accept" type="checkbox"> I have read and agree to the Terms and Conditions</p>
<input type="image" src="https://www.paypalobjects.com/en_US/GB/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.paypalobjects.com/en_GB/i/scr/pixel.gif" width="1" height="1">
</form>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" onsubmit="return confSubmit();">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="LAT8US8737YM66">
<p><input id="accept" type="checkbox"> I have read and agree to the Terms and Conditions</p>
<input type="image" src="https://www.paypalobjects.com/en_US/GB/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.paypalobjects.com/en_GB/i/scr/pixel.gif" width="1" height="1">
</form>

HTML id values should be unique, never used on more than one element. Use a class if something is to be shared by more than one.
To make your JS look for the current form's checkbox, pass the event caller to your confSubmit function using this, and use querySelector to search within that for the class you want (identified with a period, .accept), since it's a class.
<script type="text/javascript"> // <![CDATA[
function confSubmit(form) {
if(!form.querySelector(".accept").checked) {
alert("Please read and accept the Terms and Conditions in order to continue.");
return false;
}
} // ]]></script>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" onsubmit="return confSubmit(this);">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="LAT8US8737YM66">
<p><input class="accept" type="checkbox"> I have read and agree to the Terms and Conditions</p>
<input type="image" src="https://www.paypalobjects.com/en_US/GB/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.paypalobjects.com/en_GB/i/scr/pixel.gif" width="1" height="1">
</form>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" onsubmit="return confSubmit(this);">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="LAT8US8737YM66">
<p><input class="accept" type="checkbox"> I have read and agree to the Terms and Conditions</p>
<input type="image" src="https://www.paypalobjects.com/en_US/GB/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.paypalobjects.com/en_GB/i/scr/pixel.gif" width="1" height="1">
</form>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" onsubmit="return confSubmit(this);">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="LAT8US8737YM66">
<p><input class="accept" type="checkbox"> I have read and agree to the Terms and Conditions</p>
<input type="image" src="https://www.paypalobjects.com/en_US/GB/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.paypalobjects.com/en_GB/i/scr/pixel.gif" width="1" height="1">
</form>

Related

Paypal sandbox doesn't return to notify_url

I have a paypal button like
<form action="https://sandbox.paypal.com/cgi-bin/webscr" method="post" target="_top" id="paypalPayment">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="mybuttonid">
<input type="hidden" name="notify_url" value="myipnlistener" />
<input type="image" src="https://www.sandbox.paypal.com/es_ES/ES/i/btn/btn_subscribeCC_LG.gif" border="0" name="submit" alt="PayPal, la forma rápida y segura de pagar en Internet.">
<img alt="" border="0" src="https://www.sandbox.paypal.com/es_ES/i/scr/pixel.gif" width="1" height="1"></form>
where myipnlistener is a route to node controller that have ipn listener code offered by Paypal. The problem is that this controller is never been called. I setted ipn listener to on in account settings.
what am I doing wrong?

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 PDT how to get single item price

My single item price is 2.00, if buyer buy 2 quantity, the value 'mc_gross' will become 4.00. My 'item_number' value is 1. So I try use the 'mc_gross_1' to get the single item value, but return empty value.
What I temporary solve is use 'mc_gross'/'quantity' to get the single item price. I am referring from here
My site only have a 'Buy Now' button and single item only, not shopping cart.
My code as below:
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" target="_top">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="QAZN7GVGZPERC">
<input type="image" src="https://www.paypalobjects.com/webstatic/en_US/btn/btn_buynow_pp_142x27.png" border="0" name="submit"
alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.sandbox.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
Html same code I used:
<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="XXX-facilitator#gmail.com">
<input type="hidden" name="currency_code" value="US">
<input type="hidden" name="item_name_1" value="IT SERVER">
<input type="hidden" name="amount_1" value="15">
<input type="hidden" name="item_name_2" value="convenience fees">
<input type="hidden" name="amount_2" value="5.00">
<input type="hidden" name="return" value="http://localhost/justbuy/pdtreturn.php">
<input type="image" src="http://www.paypal.com/en_US/i/btn/x-click-but01.gif" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
</form>
mc_gross_1 should return the first item price. I have tested in and here is the pdt details returned.
SUCCESS
mc_gross=30.80
protection_eligibility=Eligible
address_status=confirmed
item_number1=
tax=0.80
item_number2=
payer_id=ZK5AUW8MWY9CW
ebay_txn_id1=
address_street=1+Main+St
ebay_txn_id2=
payment_date=01%3A11%3A41+Feb+04%2C+2016+PST
payment_status=Completed
charset=UTF-8
address_zip=95131
mc_shipping=10.00
mc_handling=0.00
first_name=vimalbuyer
mc_fee=1.19
address_country_code=US
address_name=vimalbuyer+ravichandran
custom=
payer_status=verified
business=vimal53-facilitator%40gmail.com
address_country=United+States
num_cart_items=2
mc_handling1=0.00
mc_handling2=0.00
address_city=San+Jose
payer_email=vimalbuyer%40gmail.com
mc_shipping1=0.00
mc_shipping2=0.00
tax1=0.00
tax2=0.00
contact_phone=408-329-3451
txn_id=99E872700B3517715
payment_type=instant
last_name=ravichandran
address_state=CA
item_name1=IT+SERVER
receiver_email=vimal-facilitator%40gmail.com
item_name2=convenience+fees
payment_fee=1.19
shipping_discount=0.00
quantity1=1
insurance_amount=0.00
quantity2=1
receiver_id=S4X5XW328WAYY
txn_type=cart
discount=0.00
mc_gross_1=15.00
mc_currency=USD
mc_gross_2=5.00
residence_country=US
shipping_method=Express
transaction_subject=
payment_gross=30.80

paypal options modify price

Was wondering if there's a way to have an drop-down option field modify a base price of an item? Something like this...
<input type="hidden" name="amount" value="$90" />
<input type="hidden" name="shipping" value="$10" />
<input type="text" name="quantity" value="1" style="width:15px;" />
<input type="hidden" name="on0" value="Options1" />
<select name="os0">
<option value="21 inches $5" >21 inches $5</option>
<option value="22 inches $5" >22 inches $5</option>
<option value="24 inches $10" >24 inches $10</option>
</select>
I'm guessing I'll have to make the amount field be a drop-down?
You can check the updated demo:
I have made a custom code to achieve base price + optional price scenario.
you will need to customise your own logic to build the amount value and pass to the amount variable and send it to paypal
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" target="_top">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="S4X5XW328WAYY">
<input type="hidden" name="lc" value="US">
<input type="hidden" name="item_name" value="test">
<input type="hidden" name="button_subtype" value="services">
<input type="hidden" name="no_note" value="0">
<input type="hidden" name="cn" value="Add special instructions to the seller:">
<input type="hidden" name="no_shipping" value="2">
<input type="hidden" name="currency_code" value="USD">
Base Price:<div id="base_price" value="100.00">100.00</div>
<input id="final_amount" name="amount" type="hidden" value="100">
<input type="hidden" name="weight_unit" value="lbs">
<input type="hidden" name="bn" value="PP-BuyNowBF:btn_buynowCC_LG.gif:NonHosted"><br>
Optional Prices
<table>
<tr><td>
<select name="os0">
<option class="optionVal" value="10.00">Option $10.00 USD</option>
<option class="optionVal" value="20.00">Option $20.00 USD</option>
<option class="optionVal" value="30.00">Option $30.00 USD</option>
</select>
</td></tr>
</table>
<input type="image" src="https://www.sandbox.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.sandbox.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
JavaScript:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js"></script>
<script>
$(document).ready(function(){
var base_price = $('#base_price').text();
$('select').change(function(){
var amt = $(this).val();
final_amt = parseInt(amt)+parseInt(base_price);
$('#final_amount').val(final_amt);
});
});
</script>

How to send multiple items to 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.