Paypal "add to cart" without leaving page - php

I am trying to integrate a paypal add to cart button on my page. When added per paypal the form included seems to work fine .. but when I use ajax to serialize and submit the form it gives me a 302 error and never populates the Div.
Technically I am trying ot avoid reloading the page, or redirecting/opening a new page when someone clicks the "add to cart" button, and figured i could work around this with Ajax. Apparently a redirect kills that possiblity as the ajax call can't post or load the redirected page?
Any pointers would be apprecaited.
Here is my code:
Javascript:
$(document).ready(function(){
$(".addToCart").click(function(){
var ev = arguments[0] || window.event,
origEl = ev.target || ev.srcElement;
var cartForm = origEl.name;
var formData = $(cartForm).serialize();
$.ajax({
type: "POST",
url: "https://www.paypal.com/cgi-bin/webscr",
cache: false,
data: formData,
success: onSuccess,
error: onError
});
return false;
});
});
HTML:
<a class="addToCart" cartNumber="#paypal<?PHP echo $counter; ?>">
<img name="#paypal<?PHP echo $counter; ?>" src="images/butNowButton.jpg" cartNumber="#paypal<?PHP echo $counter; ?>" border="0" style="text-decoration:none;" />
</a>
<form name="paypal<?PHP echo $counter; ?>" id="paypal<?PHP echo $counter; ?>" 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="removed for security">
<input type="hidden" name="lc" value="US">
<input type="hidden" name="item_name" value="<?PHP echo $itemName; ?>">
<input type="hidden" name="item_number" value="<?PHP echo $Row['id']; ?>">
<input type="hidden" name="amount" value="<?PHP echo $amount; ?>">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="button_subtype" value="products">
<input type="hidden" name="no_note" value="0">
<input type="hidden" name="tax_rate" value="0.000">
<input type="hidden" name="shipping" value="0.00">
<input type="hidden" name="add" value="1">
<input type="hidden" name="bn" value="PP-hopCartBF:btn_cart_LG.gif:NonHostedGuest">
</form>
thanks,
Silver Tiger

You can use the add="1" method of the Shopping Cart API to submit multiple items. All you need to do is to include the item_name, item_number and/or amount variables for each product you want to submit, like this.
<!-- item 1 -->
<input type="hidden" name="item_name_1" value="....">
<input type="hidden" name="item_number_1" value="....">
<input type="hidden" name="amount_1" value="....">
<!-- item 2 -->
<input type="hidden" name="item_name_2" value="....">
<input type="hidden" name="item_number_2" value="....">
<input type="hidden" name="amount_2" value="....">
<!-- item x -->
<input type="hidden" name="item_name_x" value="....">
<input type="hidden" name="item_number_x" value="....">
<input type="hidden" name="amount_x" value="....">
Please check HTML Variables for PayPal Payments Standard for more information regarding this API method and the variables you can use.

I have individual buttons for add to cart, and need this process to add multiple items as additionally well.
I did find that you can use a form to submit multiple items using the "upload='1'" method, but when submitted it "overwrites" the current cart items with the newlist ... which won't work as the other items i input with the single "add to cart" button will be lost.
Has anyone had any experience with this? I was hoping that paypal hd an API i could add items with .. but have been unable to find anything like that.

Related

paypal order summary missing

For checking out process while redirecting the user https://www.sandbox.paypal.com the paypal does not show more than one type item and only the last (with its quantity) i.e, if user add two types product in his cart and click for checking out process the paypal show only the second type with its quantity but not the first type in billing process. how can i solve the problem?
here is my api code in view file
<form style=" padding:0px;margin:0px;" name="frmOrderAutoSubmit" method="post" >
<input type="hidden" name="upload" value="1">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="sunymegh#gmail.com">
<?php $cdata = $this->cart->contents() ?>
<?php foreach ($cdata as $items) { ?>
<input type="hidden" name="quantity" value="<?php echo $items['qty']; ?>" />
<input type="hidden" name="item_name" value=" <?php echo $items['name']; ?>"/>
<input type="hidden" name="amount" value="<?php echo $items['price']; ?>"/>
<input type="hidden" name="rm" value="2" />
<input TYPE="hidden" name="address_override" value="0">
<?php } ?>
</form>
You only have one name attribute submitted name="quantity" for example. PayPal uses a format of name="quantity_1".

Passing values or variables over to paypal cart

I am developing a website so that a customer can buy gardening products. Currently, a customer can browse products on the website. When they select an individual product, I want them to be able to add to cart using Paypal's custom button. My website is set up so that when a user selects a product, it grabs the information from the database. What do I need to do in order for the product they have added to cart to appear in the Paypal cart? (with its name, and price).
From what I understand, you have to create each individual button for each item on your website. But I do not know what product the customer has selected from the database and my website is set up so that it retrieves the product info from the db.
Hope somebody could help me
A single button can use different products , you must be in a loop. But hidden params would be different.
<input type="hidden" value="Scicssors" name="item_name">
<input type="hidden" value="return.php" name="notify_url">
<input type="hidden" value="10.00" name="amount">
...........................................
There are more than fields required to pass as hidden. You can send these along with form submission button
Refer this link https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_html_Appx_websitestandard_htmlvariables
You can use a single button for all products. You can change the item_name and amount depending upon the product selected. You can pass userid in item_number field.
When a customer selects the product, query to the database and fetch the product name and amount and update it to the hidden fields.
<?php
$amt = amt from db;
$name = product name from db;
$userid = user's id;
?>
<form name=subs action='https://www.paypal.com/cgi-bin/webscr' method='post'>
<table cellspacing=0 cellpadding=0><tr><td>
<input type="hidden" name="on0" value="user">
<input type="hidden" name="os0" value="<?php echo $user_email; ?>">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="sales#yoursite.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="no_note" value="0">
<input type="hidden" name="cn" value="add">
<input type="hidden" name="no_shipping" value="2">
<input type="hidden" name="rm" value="1">
<input type="hidden" name="return" value="http://yoursite.com/payment-success.php"> //return to this url after payment completed
<input type="hidden" name="cancel_return" value="http://yoursite.com/payment-cancel.php"> //return to this url when payment cancelled
<input type="hidden" name="bn" value="PP-BuyNowBF:btn_buynowCC_LG.gif:NonHosted">
<input type="hidden" name="custom" value="CustomValue">
<input type="hidden" name="notify_url" value="http://yoursite.com/payment-confirm.php"> //return instant payment notification to this url where you can get the response from paypal and process it
<input type="hidden" name="event" value="add">
<input type="hidden" name="mnt" value="0">
<input type="hidden" name="amount" value="<?php echo $amt; ?>" id="paypalamt"> //the product's amount
<input type="hidden" name="item_number" id="paypalno" value="<?php echo $userid; ?>"> //you can send the customer/user id with this, so that you can retrieve it after payment completion
<input type="hidden" name="item_name" id="itemname" value="<?php echo $name; ?>"> //here you can set your product name
</td></tr>
</form>

Send values of item to paypal cart [duplicate]

I am developing a website so that a customer can buy gardening products. Currently, a customer can browse products on the website. When they select an individual product, I want them to be able to add to cart using Paypal's custom button. My website is set up so that when a user selects a product, it grabs the information from the database. What do I need to do in order for the product they have added to cart to appear in the Paypal cart? (with its name, and price).
From what I understand, you have to create each individual button for each item on your website. But I do not know what product the customer has selected from the database and my website is set up so that it retrieves the product info from the db.
Hope somebody could help me
A single button can use different products , you must be in a loop. But hidden params would be different.
<input type="hidden" value="Scicssors" name="item_name">
<input type="hidden" value="return.php" name="notify_url">
<input type="hidden" value="10.00" name="amount">
...........................................
There are more than fields required to pass as hidden. You can send these along with form submission button
Refer this link https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_html_Appx_websitestandard_htmlvariables
You can use a single button for all products. You can change the item_name and amount depending upon the product selected. You can pass userid in item_number field.
When a customer selects the product, query to the database and fetch the product name and amount and update it to the hidden fields.
<?php
$amt = amt from db;
$name = product name from db;
$userid = user's id;
?>
<form name=subs action='https://www.paypal.com/cgi-bin/webscr' method='post'>
<table cellspacing=0 cellpadding=0><tr><td>
<input type="hidden" name="on0" value="user">
<input type="hidden" name="os0" value="<?php echo $user_email; ?>">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="sales#yoursite.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="no_note" value="0">
<input type="hidden" name="cn" value="add">
<input type="hidden" name="no_shipping" value="2">
<input type="hidden" name="rm" value="1">
<input type="hidden" name="return" value="http://yoursite.com/payment-success.php"> //return to this url after payment completed
<input type="hidden" name="cancel_return" value="http://yoursite.com/payment-cancel.php"> //return to this url when payment cancelled
<input type="hidden" name="bn" value="PP-BuyNowBF:btn_buynowCC_LG.gif:NonHosted">
<input type="hidden" name="custom" value="CustomValue">
<input type="hidden" name="notify_url" value="http://yoursite.com/payment-confirm.php"> //return instant payment notification to this url where you can get the response from paypal and process it
<input type="hidden" name="event" value="add">
<input type="hidden" name="mnt" value="0">
<input type="hidden" name="amount" value="<?php echo $amt; ?>" id="paypalamt"> //the product's amount
<input type="hidden" name="item_number" id="paypalno" value="<?php echo $userid; ?>"> //you can send the customer/user id with this, so that you can retrieve it after payment completion
<input type="hidden" name="item_name" id="itemname" value="<?php echo $name; ?>"> //here you can set your product name
</td></tr>
</form>

Using paypal buy now form in php gallery please help

Basically I just want to turn off the button after people purchase the art and send them a receipt. I would also like to have a copy of their information. This is what I am passing through my array:
<form method="post" action="https://www.paypal.com/cgi-bin/webscr">
<input type="hidden" name="cmd" value="_xclick" />
<input type="hidden" name="business" value="email#mydomain.com" />
<input type="hidden" name="item_name" value="<?php echo $title; ?> (ID:#<?php echo " {$p['id']}" ?>)" />
<input type="hidden" name="item_number" value="<?php echo "{$p['id']}" ?>" />
<input type="hidden" name="amount" value="<?php echo "{$p['price']}" ?>" />
<input type="hidden" name="shipping" value="39.99" />
<input type="hidden" name="return" value="http://mydomain.com/thankyou.php" />
<input type="submit" value=" " class="button" />
</form>
How do I setup a sold field in my database and show/hide my button in php?
IPN, API which do I need to use to make it happen?
Cheers!
I would setup the IPN listener to mark the item's status as sold in it's database table (you are generating that form based on a database?) when the IPN comes back "VERFIFIED" and payment_status = 'Complete'. Then, only generate that form when the item is not sold.
If you don't know how to implement an IPN listener, here is a tutorial: PayPal IPN with PHP

Include results of a Paypal button generator in post without copy/paste

I own a locally exclusive trade form for people to sell items to others locally. I want to have an option to include a Paypal "Buy Now" button in new posts but I'm stuck at how to include the button in a new post without having the user manually copy/past the HTML. I have made a simple Paypal button generator with a checkbox and jQuery to display form fields if checkbox is checked. Here it is on jsfiddle
HTML
<form>
<input type="checkbox" id="checkme" /> Add a "Buy Now" Paypal button
</form>
<div id="extra">
<form action="includes/paypal_button.php" method="post">
Paypal account email: <input type="text" name="email" /><br />
Short item description: <input type="text" name="item" /><br />
Price for item (all amounts are in USD): <input type="text" name="amount" /><br />
Tax amout: <input type="text" name="tax" /><br />
Shipping and handling: <input type="text" name="shipping" />
<input type=submit value="Create Paypal button!">
</form>
</div>
jQuery
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.3/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
//Hide div w/id extra
$("#extra").css("display","none");
// Add onclick handler to checkbox w/id checkme
$("#checkme").click(function(){
// If checked
if ($("#checkme").is(":checked"))
{
//show the hidden div
$("#extra").show("fast");
}
else
{
//otherwise, hide it
$("#extra").hide("fast");
}
});
});
</script>
The controller form is in a separate php script, paypal_button.php
HTML
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="<?php echo htmlspecialchars(($_POST["email"]))?>" >
<input type="hidden" name="lc" value="US">
<input type="hidden" name="item_name" value="<?php echo htmlspecialchars(($_POST["item"]))?>">
<input type="hidden" name="amount" value="<?php echo htmlspecialchars(($_POST["amount"]))?>">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="button_subtype" value="services">
<input type="hidden" name="tax_rate" value="<?php echo htmlspecialchars(($_POST["tax"]))?>">
<input type="hidden" name="shipping" value="<?php echo htmlspecialchars(($_POST["shipping"]))?>">
<input type="hidden" name="bn" value="PP-BuyNowBF:btn_buynowCC_LG.gif:NonHosted">
<input type="image" src="https://www.paypalobjects.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.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
So should I include the controller(the button to print) in a php if statement that will print the button in new form posts? It would be highly appreciative if someone could point me in the right direction.
Thanks in advance

Categories