I have created a basket where a customer can add to and update etc. The product itself is grabbed from the database and displayed in a table in the basket. How do I use Paypal from here? I now want a button called 'pay' that the user can click and then it takes them to Paypal to pay. But I want the details of the items to be reciprocated in the Paypal receipt.
I have signed up to paypals web standard payment. I think I just need the buy button but as mentioned, I am not sure how to get products over to Paypal. I have noticed that the steps are similar for third party carts but the code provided is this:
<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="business" value="seller#dezignerfotos.com">
<input type="hidden" name="item_name_1" value="Item Name 1">
<input type="hidden" name="amount_1" value="1.00">
<input type="hidden" name="shipping_1" value="1.75">
<input type="hidden" name="item_name_2" value="Item Name 2">
<input type="hidden" name="amount_2" value="2.00">
<input type="hidden" name="shipping_2" value="2.50">
<input type="submit" value="PayPal">
But I dont see how this can relate to my cart. This shows that the cart has 2 items (item_name_1 & item_name_2) but what if the customer has 3? How am I suppose to know how many items the customer has added?
Same issue with the amount - how do I know that an item is going to cost £1.00 or £2.00?
This does not appear to by dynamic depending on what the customer selects? Can somebody explain
You just connect to your database and loop the values from your database to the form's input types.
SELECT * from customer where customer_id = $customer_id
You say that you've already created their shopping cart? I'm not sure how you've stored this, but loop through it, adding these hidden inputs for each item. If for example, your cart was in a PHP array:
$i = 0;
foreach($cart as $item) {
?>
<input type="hidden" name="item_name_<?php echo $i; ?>" value="<?php echo $item['name']; ?>">
<input type="hidden" name="amount_<?php echo $i; ?>" value="<?php echo $item['cost']; ?>">
<input type="hidden" name="shipping_<?php echo $i; ?>" value="<?php echo $item['shipping']; ?>">
<?php
$i++;
}
unset($i);
Obviously you would need to rename the variables to match how you've stored the values in your cart.
Related
I am using paypal functionality in a sandbox environment.I am implementing very basic functionality of paypal. The problem is that when user buys more than 1 quantity of same product the value of amount in the paypal gets multiplied. I am sure that I am missing some variable to use but can't figure out that. The total amount I am calculating on the server side. e.g if buyer selects 2 quantities of same product, the price get multiplied 2 times and this is the value of amount variable in paypal form. But when form is submitted to paypal, the amount variable's value become the value of item price and final amount in paypal is again multiplied by 2.
I am giving here my paypal form
<form action="<?php echo $paypal_url; ?>" method="post" name="frmPayPal1">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="xyz#exmp.com">
<input type="hidden" name="item_name" value="<?php echo $_SESSION['itemName'];?>">
<input type="hidden" name="quantity" value="<?php echo $quant;?>">
<input type="hidden" name="item_price" value="<?php echo $price;?>">
<input type="hidden" name="amount" value="<?php echo $z?>">
<input type="submit" name="submit" value="pay">
<INPUT TYPE="hidden" NAME="return" value="return website">
<INPUT TYPE="hidden" NAME="cancel_return" value="return website">
</form>
where $quant is the quantity of product, $price is the price of product,
$z is the calculated total amount($quant * $price)
if $quant=2
$price=1000 per unit of product
then $z = 2000
and in paypal website the values become
Item price: 2000.00
Quantity: 2
Amount: 4000
please if any body can help.
According to the Paypal manual there's no variable named item_price.
There's quantity:
Number of items.
And there's amount:
The price or amount of the product, service, or contribution, not
including shipping, handling, or tax
So you should have:
$z = 1000; //price_per_product;
$quant = 2;
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>
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>
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
The thing is that I would like to implement the following functionality to my site:
In the account settings - order details I would like to add a button that would add all the products from that very order to cart.
Now, I pretty much get it how the add to cart functionality is implemented on the flypage and browse page. I can't really get how should I pass multiple items to the add to cart function on order details page and how it'll be processed by ps_cart if an item is out of stock or is unpublished.
Here's the code of the add to cart form from browse page:
<form action="<?php echo $mm_action_url ?>index.php" method="post" name="addtocart" id="addtocart<?php echo $i ?>" class="addtocart_form" <?php if( $this->get_cfg( 'useAjaxCartActions', 1 ) && !$notify ) { echo 'onsubmit="handleAddToCart( this.id );return false;"'; } ?>>
<?php echo $ps_product_attribute->show_quantity_box($product_id,$product_id); ?><br />
<input type="submit" class="<?php echo $button_cls ?>" value="<?php echo $button_lbl ?>" title="<?php echo $button_lbl ?>" />
<input type="hidden" name="category_id" value="<?php echo #$_REQUEST['category_id'] ?>" />
<input type="hidden" name="product_id" value="<?php echo $product_id ?>" />
<input type="hidden" name="prod_id[]" value="<?php echo $product_id ?>" />
<input type="hidden" name="page" value="shop.cart" />
<input type="hidden" name="func" value="cartadd" />
<input type="hidden" name="Itemid" value="<?php echo $sess->getShopItemid() ?>" />
<input type="hidden" name="option" value="com_virtuemart" />
<input type="hidden" name="set_price[]" value="" />
<input type="hidden" name="adjust_price[]" value="" />
<input type="hidden" name="master_product[]" value="" />
</form>
I wonder if I'd need to pass all of these to ps_cart?
I don't expect from any of you a completely ready extension, it would be great if you could point me in the right direction.
Thanks!
EDIT:
I was able to set up the add to cart button, now I have to pass the needed data.
It would be great if it would work with at least one item, then I'd start thinking how to alter the code.
EDIT 2:
I was able to make it work flawlessly for one product. But how can I pass multiple Product Id's and their quantities to the add to cart function?
The current code in ps_cart already has a loop to iterate through multiple product IDs that are sent to the cart. From the look of the code there, I would simple put all of the product IDs you want to add to the cart in to prod_id array. You will notice that prod_id, set_price, adjust_price, and master_product are all arrays in the form. My guess is that you will need to put in those values for each product you want to add and ps_cart will do the rest.