For sandbox
-create developer central a/c
-creaet multiple Paypal Test a/c for buyer and merchants
make a form in your site which will hidden
this is the default format for paypal
1. <FORM action=”https://www.paypal.com/cgi-bin/webscr” method=”post”>
2. <INPUT TYPE=”hidden” name=”variableName” value=”allowedValue”>
Buy Now buttons – <INPUT TYPE=”hidden” name=”cmd” value=”_xclick”>
Donate buttons – <INPUT TYPE=”hidden” name=”cmd” value=”_donations”>
Subscribe buttons – <INPUT TYPE=”hidden” name=”cmd” value=”_xclick-
subscriptions”>
Shopping cart buttons – <INPUT TYPE=”hidden” name=”cmd” value=”_cart”>
The following are passthrough variables:
custom
item_number or item_number_x
invoice
HTML Code for FORM Prepopulation
<form action=”https://www.paypal.com/cgi-bin/webscr” method=”post”>
for sandbox
https://www.sandbox.paypal.com/cgi-bin/webscr
<input type=”hidden” name=”cmd” value=”_xclick”>
<input type=”hidden” name=”business” value=”seller@designerfotos.com”>
<input type=”hidden” name=”item_name”
value=”Memorex 256MB Memory Stick”>
<input type=”hidden” name=”item_number” value=”MEM32507725″>
<input type=”hidden” name=”amount” value=”3″>
<input type=”hidden” name=”tax” value=”1″>
<input type=”hidden” name=”quantity” value=”1″>
<input type=”hidden” name=”no_note” value=”1″>
<input type=”hidden” name=”currency_code” value=”USD”>
<!– Enable override of payer’s stored PayPal address. –>
<input type=”hidden” name=”address_override” value=”1″>
<!– Set prepopulation variables to override stored address. –>
<input type=”hidden” name=”first_name” value=”John”>
<input type=”hidden” name=”last_name” value=”Doe”>
<input type=”hidden” name=”address1″ value=”345 Lark Ave”>
<input type=”hidden” name=”city” value=”San Jose”>
<input type=”hidden” name=”state” value=”CA”>
<input type=”hidden” name=”zip” value=”95121″>
<input type=”hidden” name=”country” value=”US”>
<input type=”image” name=”submit” border=”0″
src=”https://www.paypal.com/en_US/i/btn/btn_buynow_LG.gif”
alt=”PayPal – The safer, easier way to pay online”>
</form>
<INPUT TYPE=”hidden” name=”charset” value=”utf-8″>
<INPUT TYPE=”hidden” NAME=”return” value=”URLspecificToThisTransaction”> (default paypal own return )
<INPUT TYPE=”hidden” NAME=”currency_code” value=”CurrencyCode”> ( default USD)
<INPUT TYPE=”hidden” name=”address_override” value=”1″>
===IPN ( instant payment notification)=notify_url======
====Allowable Values for the cmd HTML Variable==
Value of cmd Description
_xclick The button that the person clicked was a Buy Now button.
_donations The button that the person clicked was a Donate button.
_xclick-subscriptions The button that the person clicked was a Subscribe button.
_oe-gift-certificate The button that the person clicked was a Buy Gift Certificate button.
_cart For shopping cart purchases; these additional variables specify the
kind of shopping cart button that the person clicked:
add – Add to Cart buttons for the PayPal Shopping Cart
display – View Cart buttons for the PayPal Shopping Cart
upload – The Cart Upload command for third party carts
_s-xclick The button that the person clicked was protected from tampering by
using encryption.
============= ==IPN back=============
// read the post from PayPal system and add ‘cmd’
$req = ‘cmd=_notify-validate’;
foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$req .= “&$key=$value”;
}
// post back to PayPal system to validate
$header .= “POST /cgi-bin/webscr HTTP/1.0\r\n”;
$header .= “Content-Type: application/x-www-form-urlencoded\r\n”;
$header .= “Content-Length: ” . strlen($req) . “\r\n\r\n”;
$fp = fsockopen (’ssl://www.paypal.com’, 80, $errno, $errstr, 30);
// assign posted variables to local variables
$item_name = $_POST['item_name'];
$item_number = $_POST['item_number'];
$payment_status = $_POST['payment_status'];
$payment_amount = $_POST['mc_gross'];
$payment_currency = $_POST['mc_currency'];
$txn_id = $_POST['txn_id'];
$receiver_email = $_POST['receiver_email'];
$payer_email = $_POST['payer_email'];
if (!$fp) {
// HTTP ERROR
} else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
if (strcmp ($res, “VERIFIED”) == 0) {
// check the payment_status is Completed
// check that txn_id has not been previously processed
// check that receiver_email is your Primary PayPal email
// check that payment_amount/payment_currency are correct
// process payment
}
else if (strcmp ($res, “INVALID”) == 0) {
// log for manual investigation
}
}
fclose ($fp);
}