Reputation: 369
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="[email protected]">
<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
Upvotes: 1
Views: 382
Reputation: 396
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.
Upvotes: 1
Reputation: 26
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
Upvotes: 1