Vous devez avoir suivi l’étape 2 Création du bouton HTML “Acheter maintenant” avant de passer à celle-ci.
Passons maintenant à la page de récupération des données
notify.php qui devra être placé à l’adresse indiqué dans la variable notify_url de votre bouton dans cet exemple : http://www.monsite.com/paypal/notify.php
tout d’abord nous devons créer dans notre base de donnée une table qui contiendra l’historique des transactions paypal.
j’utilise ici l’exemple donné par PaypalTech.com qui va nous permettre d’arriver à nos fins
Voici les tables à créer dans votre base de donnée :
-
-
# Table structure for table `paypal_cart_info` #CREATE TABLE `paypal_cart_info` ( `txnid` varchar(30) NOT NULL default ”, `itemname` varchar(255) NOT NULL default ”, `itemnumber` varchar(50) default NULL, `os0` varchar(20) default NULL, `on0` varchar(50) default NULL, `os1` varchar(20) default NULL, `on1` varchar(50) default NULL, `quantity` char(3) NOT NULL default ”, `invoice` varchar(255) NOT NULL default ”, `custom` varchar(255) NOT NULL default ” ) TYPE=MyISAM;
-
-
# Table structure for table `paypal_subscription_info` #
-
-
CREATE TABLE `paypal_subscription_info` ( `subscr_id` varchar(255) NOT NULL DEFAULT ”, `sub_event` varchar(50) NOT NULL DEFAULT ”, `subscr_date` varchar(255) NOT NULL DEFAULT ”, `subscr_effective` varchar(255) NOT NULL DEFAULT ”, `period1` varchar(255) NOT NULL DEFAULT ”, `period2` varchar(255) NOT NULL DEFAULT ”, `period3` varchar(255) NOT NULL DEFAULT ”, `amount1` varchar(255) NOT NULL DEFAULT ”, `amount2` varchar(255) NOT NULL DEFAULT ”, `amount3` varchar(255) NOT NULL DEFAULT ”, `mc_amount1` varchar(255) NOT NULL DEFAULT ”, `mc_amount2` varchar(255) NOT NULL DEFAULT ”, `mc_amount3` varchar(255) NOT NULL DEFAULT ”, `recurring` varchar(255) NOT NULL DEFAULT ”, `reattempt` varchar(255) NOT NULL DEFAULT ”, `retry_at` varchar(255) NOT NULL DEFAULT ”, `recur_times` varchar(255) NOT NULL DEFAULT ”, `username` varchar(255) NOT NULL DEFAULT ”, `password` varchar(255) DEFAULT NULL, `payment_txn_id` varchar(50) NOT NULL DEFAULT ”, `subscriber_emailaddress` varchar(255) NOT NULL DEFAULT ”, `datecreation` date NOT NULL DEFAULT ‘0000-00-00′ ) TYPE=MyISAM;
-
-
# Table structure for table `paypal_payment_info` #
-
-
CREATE TABLE `paypal_payment_info` ( `firstname` varchar(100) NOT NULL DEFAULT ”, `lastname` varchar(100) NOT NULL DEFAULT ”, `buyer_email` varchar(100) NOT NULL DEFAULT ”, `street` varchar(100) NOT NULL DEFAULT ”, `city` varchar(50) NOT NULL DEFAULT ”, `state` char(3) NOT NULL DEFAULT ”, `zipcode` varchar(11) NOT NULL DEFAULT ”, `memo` varchar(255) DEFAULT NULL, `itemname` varchar(255) DEFAULT NULL, `itemnumber` varchar(50) DEFAULT NULL, `os0` varchar(20) DEFAULT NULL, `on0` varchar(50) DEFAULT NULL, `os1` varchar(20) DEFAULT NULL, `on1` varchar(50) DEFAULT NULL, `quantity` char(3) DEFAULT NULL, `paymentdate` varchar(50) NOT NULL DEFAULT ”, `paymenttype` varchar(10) NOT NULL DEFAULT ”, `txnid` varchar(30) NOT NULL DEFAULT ”, `mc_gross` varchar(6) NOT NULL DEFAULT ”, `mc_fee` varchar(5) NOT NULL DEFAULT ”, `paymentstatus` varchar(15) NOT NULL DEFAULT ”, `pendingreason` varchar(10) DEFAULT NULL, `txntype` varchar(10) NOT NULL DEFAULT ”, `tax` varchar(10) DEFAULT NULL, `mc_currency` varchar(5) NOT NULL DEFAULT ”, `reasoncode` varchar(20) NOT NULL DEFAULT ”, `custom` varchar(255) NOT NULL DEFAULT ”, `country` varchar(20) NOT NULL DEFAULT ”, `datecreation` date NOT NULL DEFAULT ‘0000-00-00′ ) TYPE=MyISAM;
et voici maintenant la structure de notre fichier
-
$DB_Server = "localhost"; // Votre serveur de Base de donnée
-
-
$DB_Username = "toto"; //nom de l’utilisateur
-
-
$DB_Password = "pass"; // password
-
-
$DB_DBName = "nom_base"; // nom de la base
-
-
//create MySQL connection
-
-
-
-
//select database
-
-
-
-
$notify_email = "votremailréel@mail.com"; // Email ou vous allez recevoir le résultat du paiement
-
-
/////////////////////////////////////////////////
-
-
/////////////Begin Script below./////////////////
-
-
/////////////////////////////////////////////////
-
-
$paypal[’serveur’] = ‘www.sandbox.paypal.com’; //mode test
-
-
//$paypal[’serveur’] = ‘www.paypal.com’; A activer quand on passera en mode réel
-
-
// read the post from PayPal system and add ‘cmd’
-
-
$req = ‘cmd=_notify-validate’;
-
-
foreach ($_POST as $key => $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";
-
-
-
-
// assign posted variables to local variables
-
-
$item_name = $_POST[‘item_name’];
-
-
$business = $_POST[‘business’];
-
-
$item_number = $_POST[‘item_number’];
-
-
$payment_status = $_POST[‘payment_status’];
-
-
$mc_gross = $_POST[‘mc_gross’];
-
-
$payment_currency = $_POST[‘mc_currency’];
-
-
$txn_id = $_POST[‘txn_id’];
-
-
$receiver_email = $_POST[‘receiver_email’];
-
-
$receiver_id = $_POST[‘receiver_id’];
-
-
$quantity = $_POST[‘quantity’];
-
-
$num_cart_items = $_POST[‘num_cart_items’];
-
-
$payment_date = $_POST[‘payment_date’];
-
-
$first_name = $_POST[‘first_name’];
-
-
$last_name = $_POST[‘last_name’];
-
-
$payment_type = $_POST[‘payment_type’];
-
-
$payment_status = $_POST[‘payment_status’];
-
-
$payment_gross = $_POST[‘payment_gross’];
-
-
$payment_fee = $_POST[‘payment_fee’];
-
-
$settle_amount = $_POST[’settle_amount’];
-
-
$memo = $_POST[‘memo’];
-
-
$payer_email = $_POST[‘payer_email’];
-
-
$txn_type = $_POST[‘txn_type’];
-
-
$payer_status = $_POST[‘payer_status’];
-
-
$address_street = $_POST[‘address_street’];
-
-
$address_city = $_POST[‘address_city’];
-
-
$address_state = $_POST[‘address_state’];
-
-
$address_zip = $_POST[‘address_zip’];
-
-
$address_country = $_POST[‘address_country’];
-
-
$address_status = $_POST[‘address_status’];
-
-
$item_number = $_POST[‘item_number’];
-
-
$tax = $_POST[‘tax’];
-
-
$option_name1 = $_POST[‘option_name1′];
-
-
$option_selection1 = $_POST[‘option_selection1′];
-
-
$option_name2 = $_POST[‘option_name2′];
-
-
$option_selection2 = $_POST[‘option_selection2′];
-
-
$for_auction = $_POST[‘for_auction’];
-
-
$invoice = $_POST[‘invoice’];
-
-
$custom = $_POST[‘custom’];
-
-
$notify_version = $_POST[‘notify_version’];
-
-
$verify_sign = $_POST[‘verify_sign’];
-
-
$payer_business_name = $_POST[‘payer_business_name’];
-
-
$payer_id =$_POST[‘payer_id’];
-
-
$mc_currency = $_POST[‘mc_currency’];
-
-
$mc_fee = $_POST[‘mc_fee’];
-
-
$exchange_rate = $_POST[‘exchange_rate’];
-
-
$settle_currency = $_POST[’settle_currency’];
-
-
$parent_txn_id = $_POST[‘parent_txn_id’];
-
-
$pending_reason = $_POST[‘pending_reason’];
-
-
$reason_code = $_POST[‘reason_code’];
-
-
// subscription specific vars
-
-
$subscr_id = $_POST[’subscr_id’];
-
-
$subscr_date = $_POST[’subscr_date’];
-
-
$subscr_effective = $_POST[’subscr_effective’];
-
-
$period1 = $_POST[‘period1′];
-
-
$period2 = $_POST[‘period2′];
-
-
$period3 = $_POST[‘period3′];
-
-
$amount1 = $_POST[‘amount1′];
-
-
$amount2 = $_POST[‘amount2′];
-
-
$amount3 = $_POST[‘amount3′];
-
-
$mc_amount1 = $_POST[‘mc_amount1′];
-
-
$mc_amount2 = $_POST[‘mc_amount2′];
-
-
$mc_amount3 = $_POST[‘mcamount3′];
-
-
$recurring = $_POST[‘recurring’];
-
-
$reattempt = $_POST[‘reattempt’];
-
-
$retry_at = $_POST[‘retry_at’];
-
-
$recur_times = $_POST[‘recur_times’];
-
-
$username = $_POST[‘username’];
-
-
$password = $_POST[‘password’];
-
-
//auction specific vars
-
-
$for_auction = $_POST[‘for_auction’];
-
-
$auction_closing_date = $_POST[‘auction_closing_date’];
-
-
$auction_multi_item = $_POST[‘auction_multi_item’];
-
-
$auction_buyer_id = $_POST[‘auction_buyer_id’];
-
-
if (!$fp) {
-
-
// HTTP ERROR
-
-
} else {
-
-
-
-
-
-
-
-
//check if transaction ID has been processed before
-
-
$checkquery = "select txnid from paypal_payment_info where txnid=’".$txn_id."’";
-
-
-
-
if ($nm == 0){
-
-
//execute query
-
-
if ($txn_type == "cart"){ //cas du panier (non évoqué dans ce tuto
-
-
$strQuery = "insert into paypal_payment_info(paymentstatus,buyer_email,firstname,lastname,street,city,state,zipcode,country,mc_gross,mc_fee,memo,paymenttype,paymentdate,txnid,pendingreason,reasoncode,tax,datecreation,custom) values (’".$payment_status."’,'".$payer_email."’,'".$first_name."’,'".$last_name."’,'".$address_street."’,'".$address_city."’,'".$address_state."’,'".$address_zip."’,'".$address_country."’,'".$mc_gross."’,'".$mc_fee."’,'".$memo."’,'".$payment_type."’,'".$payment_date."’,'".$txn_id."’,'".$pending_reason."’,'".$reason_code."’,'".$tax."’,'".$fecha."’,'".$custom."’)";
-
-
-
for ($i = 1; $i <= $num_cart_items; $i++) {
-
-
$itemname = "item_name".$i;
-
-
$itemnumber = "item_number".$i;
-
-
$on0 = "option_name1_".$i;
-
-
$os0 = "option_selection1_".$i;
-
-
$on1 = "option_name2_".$i;
-
-
$os1 = "option_selection2_".$i;
-
-
$quantity = "quantity".$i;
-
-
$struery = "insert into paypal_cart_info(txnid,itemnumber,itemname,os0,on0,os1,on1,quantity,invoice,custom) values (’".$txn_id."’,'".$_POST[$itemnumber]."’,'".$_POST[$itemname]."’,'".$_POST[$on0]."’,'".$_POST[$os0]."’,'".$_POST[$on1]."’,'".$_POST[$os1]."’,'".$_POST[$quantity]."’,'".$invoice."’,'".$custom."’)";
-
-
-
}
-
-
}
-
-
else{ // notre cas celui du bouton à achat immédiat
-
-
$strQuery = "insert into paypal_payment_info(paymentstatus,buyer_email,firstname,lastname,street,city,state,zipcode,country,mc_gross,mc_fee,itemnumber,itemname,os0,on0,os1,on1,quantity,memo,paymenttype,paymentdate,txnid,pendingreason,reasoncode,tax,datecreation,custom) values (’".$payment_status."’,'".$payer_email."’,'".$first_name."’,'".$last_name."’,'".$address_street."’,'".$address_city."’,'".$address_state."’,'".$address_zip."’,'".$address_country."’,'".$mc_gross."’,'".$mc_fee."’,'".$item_number."’,'".$item_name."’,'".$option_name1."’,'".$option_selection1."’,'".$option_name2."’,'".$option_selection2."’,'".$quantity."’,'".$memo."’,'".$payment_type."’,'".$payment_date."’,'".$txn_id."’,'".$pending_reason."’,'".$reason_code."’,'".$tax."’,'".$fecha."’,'".$custom."’)";
-
-
-
// ajoute dans la table créer le récapitulatif du paiement paypal
-
-
// ensuite on réalise notre propre traitement par exemple ajout de crédit à un utilisateur etc etc
-
-
//traitement propre à votre site
-
$Member_ID=$tableau[0];
-
$Object_ID=$tableau[1];
-
-
requete sql etc
-
….
-
-
…
-
-
…
-
-
….
-
-
}
-
-
// envoie un email de resultat
-
-
echo "Verified";
-
-
mail($notify_email, "VERIFIED IPN", "$res\n $req\n $strQuery\n $struery\n $strQuery2","From: vente@votresite.com");
-
-
}
-
-
else {
-
-
// send an email
-
-
mail($notify_email, "VERIFIED DUPLICATED TRANSACTION", "$res\n $req \n $strQuery\n $struery\n $strQuery2");
-
-
}
-
-
//subscription handling branch
-
-
if ( $txn_type == "subscr_signup" || $txn_type == "subscr_payment" ) {
-
-
// insert subscriber payment info into paypal_payment_info table
-
-
$strQuery = "insert into paypal_payment_info(paymentstatus,buyer_email,firstname,lastname,street,city,state,zipcode,country,mc_gross,mc_fee,memo,paymenttype,paymentdate,txnid,pendingreason,reasoncode,tax,datecreation,custom) values (’".$payment_status."’,'".$payer_email."’,'".$first_name."’,'".$last_name."’,'".$address_street."’,'".$address_city."’,'".$address_state."’,'".$address_zip."’,'".$address_country."’,'".$mc_gross."’,'".$mc_fee."’,'".$memo."’,'".$payment_type."’,'".$payment_date."’,'".$txn_id."’,'".$pending_reason."’,'".$reason_code."’,'".$tax."’,'".$fecha."’,'".$custom."’)";
-
-
-
// insert subscriber info into paypal_subscription_info table
-
-
$strQuery2 = "insert into paypal_subscription_info(subscr_id , sub_event, subscr_date ,subscr_effective,period1,period2, period3, amount1 ,amount2 ,amount3, mc_amount1, mc_amount2, mc_amount3, recurring, reattempt,retry_at, recur_times, username ,password, payment_txn_id, subscriber_emailaddress, datecreation) values (’".$subscr_id."’, ‘".$txn_type."’,'".$subscr_date."’,'".$subscr_effective."’,'".$period1."’,'".$period2."’,'".$period3."’,'".$amount1."’,'".$amount2."’,'".$amount3."’,'".$mc_amount1."’,'".$mc_amount2."’,'".$mc_amount3."’,'".$recurring."’,'".$reattempt."’,'".$retry_at."’,'".$recur_times."’,'".$username."’,'".$password."’, ‘".$txn_id."’,'".$payer_email."’,'".$fecha."’)";
-
-
-
-
}
-
-
}
-
-
// si le paiement n’est pas valide
-
-
-
// log for manual investigation
-
-
-
}
-
-
}
-
-
-
}
-
-
?>
Une fois les test effectués en version virtuelle il ne vous restera plus qu’a modifier l’url www.sandbox.paypal.com présente dans les scripts par www.paypal.com et à donner votre vrai email paypal de vendeur
Dans une deuxième partie nous verrons comment crypter le bouton pour que les variables n’apparaissent pas dans le code source et pour éviter les fraudes
Si vous avez trouvez ce tutorial utile n’hésitez pas à laisser un commentaire ou à
