user1227124 user1227124 - 1 year ago 36
SQL Question

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

Answer Source

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.

$amt = amt from db;
$name = product name from db;
$userid = user's id;

<form name=subs action='' 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="">
<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=""> //return to this url after payment completed
<input type="hidden" name="cancel_return" value=""> //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=""> //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