Archives pour le mot-clé «php»

Cryptage dynamique en php des boutons Paypal

Bonjour à tous,

Paypal dans son interface d’administration ne permet de crypter qu’un bouton à la fois, ce qui n’est pas très pratique quand on à 500 articles à vendre par exemple.

Nous allons donc voir comment crypter dynamiquement tout les boutons paypal buy now d’une page .

  1. Il faut bien entendu dans la page ou va apparaitre l’article à vendre inclure le script qui va crypter nos boutons.
    1. require_once("../paypal/crypt.php"); // représente le chemin du script
  2. Créer un certificat en cliquant ici et récupérer la Private Key (renommée my-prvkey.pem et le Public certificate my-pubcert.pem
  3. Allez dans l’administration de votre compte Paypal cliquez sur préférence puis sur certificats pour site marchand cliquez sur télécharger et récupérez paypal_cert_pem.txt et renommez le en paypal_cert.pem.
  4. Toujours dans la page certificats pour site marchand, cliquez sur Ajouter et sélectionnez votre certificat public généré à l’étape 2. Il vous attribue un numéro de certificat à conserver précieusement et à utiliser dans la variable ‘cert_id’ de l’étape suivante :
  5. passons maintenant au contenu de crypt.php
    1. //Sample PayPal Button Encryption: Copyright 2006,2007 StellarWebSolutions.com
    2. //Not for resale  - license agreement at
    3. //http://www.stellarwebsolutions.com/en/eula.php
    4. //Updated: 2007 04 04
    5.  
    6. #Set home directory for OpenSSL
    7. putenv("HOME=~");
    8.  
    9. # private key file to use
    10. $MY_KEY_FILE = "/var/www/vhosts/votresite.com/httpdocs/paypal/my-prvkey.pem";
    11.  
    12. # public certificate file to use
    13. $MY_CERT_FILE = "/var/www/vhosts/votresite.com/httpdocs/paypal/my-pubcert.pem";
    14.  
    15. # Paypal’s public certificate
    16. $PAYPAL_CERT_FILE = "/var/www/vhosts/votresite.com/httpdocs/paypal/paypal_cert.pem";
    17.  
    18. # path to the openssl binary
    19. $OPENSSL = "/usr/bin/openssl";
    20.  
    21. function paypal_encrypt($hash)
    22.         {
    23.                 //Sample PayPal Button Encryption: Copyright 2006,2007 StellarWebSolutions.com
    24.                 //Not for resale - license agreement at
    25.                 //http://www.stellarwebsolutions.com/en/eula.php
    26.  
    27.                 global $MY_KEY_FILE;
    28.                 global $MY_CERT_FILE;
    29.                 global $PAYPAL_CERT_FILE;
    30.                 global $OPENSSL;
    31.  
    32.                 if (!file_exists($MY_KEY_FILE)) {
    33.                         echo "ERROR: MY_KEY_FILE $MY_KEY_FILE not found\n";
    34.                 }
    35.                 if (!file_exists($MY_CERT_FILE)) {
    36.                         echo "ERROR: MY_CERT_FILE $MY_CERT_FILE not found\n";
    37.                 }
    38.                 if (!file_exists($PAYPAL_CERT_FILE)) {
    39.                         echo "ERROR: PAYPAL_CERT_FILE $PAYPAL_CERT_FILE not found\n";
    40.                 }
    41.                 if (!file_exists($OPENSSL)) {
    42.                         echo "ERROR: OPENSSL $OPENSSL not found\n";
    43.                 }
    44.  
    45.                 //Assign Build Notation for PayPal Support
    46.                 $hash[‘bn’]= ‘StellarWebSolutions.PHP_EWP’;
    47.  
    48.                 $openssl_cmd = "$OPENSSL smime -sign -signer $MY_CERT_FILE -inkey $MY_KEY_FILE " .
    49.                                         "-outform der -nodetach -binary | $OPENSSL smime -encrypt " .
    50.                                         "-des3 -binary -outform pem $PAYPAL_CERT_FILE";
    51.  
    52.                 $descriptors = array(
    53.                                 0 => array("pipe", "r"),
    54.                         1 => array("pipe", "w"),
    55.                 );
    56.  
    57.                 $process = proc_open($openssl_cmd, $descriptors, $pipes);
    58.  
    59.                 if (is_resource($process)) {
    60.                         foreach ($hash as $key => $value) {
    61.                                 if ($value != "") {
    62.                                         //echo "Adding to blob: $key=$value\n";
    63.                                         fwrite($pipes[0], "$key=$value\n");
    64.                                 }
    65.                         }
    66.                         fflush($pipes[0]);
    67.                                 fclose($pipes[0]);
    68.  
    69.                         $output = "";
    70.                         while (!feof($pipes[1])) {
    71.                                 $output .= fgets($pipes[1]);
    72.                         }
    73.                         //echo $output;
    74.                         fclose($pipes[1]);
    75.                         $return_value = proc_close($process);
    76.                         return $output;
    77.                 }
    78.                 return "ERROR";
    79.         };
    80. function paypal_button($title,$cost,$iduser) // choississez les variables à transmettre à la fonction (prix, nom de l’objet, etc)
    81.         {
    82.         $form = array(‘cmd’ => ‘_xclick’, //bouton paypal achat immédiat
    83.         ‘business’ => ‘votreadresse@monsite.com’, // adresse de votre compte paypal
    84.         ‘cert_id’ => ‘WWEEDZREXSSS’, // ici mettre le numéro de certificat obtenu dans l’interface d’administration paypal
    85.         ‘item_name’ => $title, //titre de l’objet vendu
    86.         ‘amount’ => $cost, // cout de l’objet
    87.         ’shipping’ => ‘0.00′, //frais de port
    88.         ‘no_shipping’ => ‘0′,
    89.         ‘return’ => ‘http://www.monsite.com/user/?action=user.credits&fin=ok’, // adresse de retour après le paiement
    90.         ‘notify_url’ => ‘http://www.monsite.com/paypal/paypal.php’, // adresse de notification ipn (voir autre tuto sur le site)
    91.         ‘cancel_return’ => ‘http://www.monsite.com/user/?action=user.credits’, // adresse de retour en cas d’annulation du paiement
    92.         ‘no_note’ => ‘1′,
    93.         ‘custom’ => $iduser."/credits/".$title."/".date("Y-m-d H:i:s"), // la variable custom permet de faire passer n’importe quel parametre de votre choix
    94.         ‘currency_code’ => ‘USD’, //Paiement en dollars ici
    95.         ‘tax’ => ‘0.00′,
    96.         ‘lc’ => ‘US’
    97.         );
    98.  
    99.         $encrypted = paypal_encrypt($form);
    100.         return $encrypted;
    101.  
    102.         }
    103.         ?>
  6. Retournons à la page où nous affichons l’article. Il ne reste plus qu’a crypter nos boutons à la demande
    1.  
    2. <form action="https://www.paypal.com/cgi-bin/webscr" method="post">
    3. <input name="cmd" value="_s-xclick" type="hidden" />
    4. <input name="encrypted" value="<? $bouton=paypal_button($vosvariable1,$vosvariable2,$vosvariable3); echo $bouton; ?>" type="hidden" />
    5. <input class="button68" value="Buy" type="submit" />
    6.                                         </form>

    Riens ne vous empêche d’intégrer cela à un for each ou while pour générer x boutons selon vos conditions

Ce tuto est terminé n’hésitez pas à poster un commentaire et si il vous à bien aidé à faire un don :

Si vous désirez que notre entreprise l’installe sur votre site Contactez nous

Tutorial Paypal : La récupération des données par IPN

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 :

  1.  
  2. # 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;
  3.  
  4. # Table structure for table `paypal_subscription_info` #
  5.  
  6. 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;
  7.  
  8. # Table structure for table `paypal_payment_info` #
  9.  
  10. 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

  1. $DB_Server = "localhost"; // Votre serveur de Base de donnée
  2.  
  3. $DB_Username = "toto"; //nom de l’utilisateur
  4.  
  5. $DB_Password = "pass"; // password
  6.  
  7. $DB_DBName = "nom_base"; // nom de la base
  8.  
  9. //create MySQL connection
  10.  
  11. $Connect = @mysql_connect($DB_Server, $DB_Username, $DB_Password)
  12.  
  13. or die("Couldn’t connect to MySQL:
  14. " . mysql_error() . "
  15. " . mysql_errno());
  16.  
  17. //select database
  18.  
  19. $Db = @mysql_select_db($DB_DBName, $Connect)
  20.  
  21. or die("Couldn’t select database:
  22. " . mysql_error(). "
  23. " . mysql_errno());
  24.  
  25. $notify_email =  "votremailréel@mail.com";         // Email ou vous allez recevoir le résultat du paiement
  26.  
  27. /////////////////////////////////////////////////
  28.  
  29. /////////////Begin Script below./////////////////
  30.  
  31. /////////////////////////////////////////////////
  32.  
  33. $paypal[’serveur’] = ‘www.sandbox.paypal.com’;      //mode test
  34.  
  35. //$paypal[’serveur’] = ‘www.paypal.com’;             A activer quand on passera en mode réel
  36.  
  37. // read the post from PayPal system and add ‘cmd’
  38.  
  39. $req = ‘cmd=_notify-validate’;
  40.  
  41. foreach ($_POST as $key => $value) {
  42.  
  43. $value = urlencode(stripslashes($value));
  44.  
  45. $req .= "&amp;$key=$value";
  46.  
  47. }
  48.  
  49. // post back to PayPal system to validate
  50.  
  51. $header = "POST /cgi-bin/webscr HTTP/1.0\r\n";
  52.  
  53. $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
  54.  
  55. $header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
  56.  
  57. $fp = fsockopen ($paypal[’serveur’], 80, $errno, $errstr, 30);
  58.  
  59. // assign posted variables to local variables
  60.  
  61. $item_name = $_POST[‘item_name’];
  62.  
  63. $business = $_POST[‘business’];
  64.  
  65. $item_number = $_POST[‘item_number’];
  66.  
  67. $payment_status = $_POST[‘payment_status’];
  68.  
  69. $mc_gross = $_POST[‘mc_gross’];
  70.  
  71. $payment_currency = $_POST[‘mc_currency’];
  72.  
  73. $txn_id = $_POST[‘txn_id’];
  74.  
  75. $receiver_email = $_POST[‘receiver_email’];
  76.  
  77. $receiver_id = $_POST[‘receiver_id’];
  78.  
  79. $quantity = $_POST[‘quantity’];
  80.  
  81. $num_cart_items = $_POST[‘num_cart_items’];
  82.  
  83. $payment_date = $_POST[‘payment_date’];
  84.  
  85. $first_name = $_POST[‘first_name’];
  86.  
  87. $last_name = $_POST[‘last_name’];
  88.  
  89. $payment_type = $_POST[‘payment_type’];
  90.  
  91. $payment_status = $_POST[‘payment_status’];
  92.  
  93. $payment_gross = $_POST[‘payment_gross’];
  94.  
  95. $payment_fee = $_POST[‘payment_fee’];
  96.  
  97. $settle_amount = $_POST[’settle_amount’];
  98.  
  99. $memo = $_POST[‘memo’];
  100.  
  101. $payer_email = $_POST[‘payer_email’];
  102.  
  103. $txn_type = $_POST[‘txn_type’];
  104.  
  105. $payer_status = $_POST[‘payer_status’];
  106.  
  107. $address_street = $_POST[‘address_street’];
  108.  
  109. $address_city = $_POST[‘address_city’];
  110.  
  111. $address_state = $_POST[‘address_state’];
  112.  
  113. $address_zip = $_POST[‘address_zip’];
  114.  
  115. $address_country = $_POST[‘address_country’];
  116.  
  117. $address_status = $_POST[‘address_status’];
  118.  
  119. $item_number = $_POST[‘item_number’];
  120.  
  121. $tax = $_POST[‘tax’];
  122.  
  123. $option_name1 = $_POST[‘option_name1′];
  124.  
  125. $option_selection1 = $_POST[‘option_selection1′];
  126.  
  127. $option_name2 = $_POST[‘option_name2′];
  128.  
  129. $option_selection2 = $_POST[‘option_selection2′];
  130.  
  131. $for_auction = $_POST[‘for_auction’];
  132.  
  133. $invoice = $_POST[‘invoice’];
  134.  
  135. $custom = $_POST[‘custom’];
  136.  
  137. $notify_version = $_POST[‘notify_version’];
  138.  
  139. $verify_sign = $_POST[‘verify_sign’];
  140.  
  141. $payer_business_name = $_POST[‘payer_business_name’];
  142.  
  143. $payer_id =$_POST[‘payer_id’];
  144.  
  145. $mc_currency = $_POST[‘mc_currency’];
  146.  
  147. $mc_fee = $_POST[‘mc_fee’];
  148.  
  149. $exchange_rate = $_POST[‘exchange_rate’];
  150.  
  151. $settle_currency  = $_POST[’settle_currency’];
  152.  
  153. $parent_txn_id  = $_POST[‘parent_txn_id’];
  154.  
  155. $pending_reason = $_POST[‘pending_reason’];
  156.  
  157. $reason_code = $_POST[‘reason_code’];
  158.  
  159. // subscription specific vars
  160.  
  161. $subscr_id = $_POST[’subscr_id’];
  162.  
  163. $subscr_date = $_POST[’subscr_date’];
  164.  
  165. $subscr_effective  = $_POST[’subscr_effective’];
  166.  
  167. $period1 = $_POST[‘period1′];
  168.  
  169. $period2 = $_POST[‘period2′];
  170.  
  171. $period3 = $_POST[‘period3′];
  172.  
  173. $amount1 = $_POST[‘amount1′];
  174.  
  175. $amount2 = $_POST[‘amount2′];
  176.  
  177. $amount3 = $_POST[‘amount3′];
  178.  
  179. $mc_amount1 = $_POST[‘mc_amount1′];
  180.  
  181. $mc_amount2 = $_POST[‘mc_amount2′];
  182.  
  183. $mc_amount3 = $_POST[‘mcamount3′];
  184.  
  185. $recurring = $_POST[‘recurring’];
  186.  
  187. $reattempt = $_POST[‘reattempt’];
  188.  
  189. $retry_at = $_POST[‘retry_at’];
  190.  
  191. $recur_times = $_POST[‘recur_times’];
  192.  
  193. $username = $_POST[‘username’];
  194.  
  195. $password = $_POST[‘password’];
  196.  
  197. //auction specific vars
  198.  
  199. $for_auction = $_POST[‘for_auction’];
  200.  
  201. $auction_closing_date  = $_POST[‘auction_closing_date’];
  202.  
  203. $auction_multi_item  = $_POST[‘auction_multi_item’];
  204.  
  205. $auction_buyer_id  = $_POST[‘auction_buyer_id’];
  206.  
  207. if (!$fp) {
  208.  
  209. // HTTP ERROR
  210.  
  211. } else {
  212.  
  213. fputs ($fp, $header . $req);
  214.  
  215. while (!feof($fp)) {
  216.  
  217. $res = fgets ($fp, 1024);
  218.  
  219. if (strcmp ($res, "VERIFIED") == 0) {
  220.  
  221. $fecha = date("m")."/".date("d")."/".date("Y");
  222.  
  223. $fecha = date("Y").date("m").date("d");
  224.  
  225. //check if transaction ID has been processed before
  226.  
  227. $checkquery = "select txnid from paypal_payment_info where txnid=’".$txn_id."’";
  228.  
  229. $sihay = mysql_query($checkquery) or die("Duplicate txn id check query failed:
  230. " . mysql_error() . "
  231. " . mysql_errno());
  232.  
  233. $nm = mysql_num_rows($sihay);
  234.  
  235. if ($nm == 0){
  236.  
  237. //execute query
  238.  
  239. if ($txn_type == "cart"){ //cas du panier (non évoqué dans ce tuto
  240.  
  241.     $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."’)";
  242.  
  243. $result = mysql_query($strQuery) or die("Cart - paypal_payment_info, Query failed:
  244. " . mysql_error() . "
  245. " . mysql_errno());
  246.  
  247.      for ($i = 1; $i <= $num_cart_items; $i++) {
  248.  
  249.          $itemname = "item_name".$i;
  250.  
  251.          $itemnumber = "item_number".$i;
  252.  
  253.          $on0 = "option_name1_".$i;
  254.  
  255.          $os0 = "option_selection1_".$i;
  256.  
  257.          $on1 = "option_name2_".$i;
  258.  
  259.          $os1 = "option_selection2_".$i;
  260.  
  261.          $quantity = "quantity".$i;
  262.  
  263. $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."’)";
  264.  
  265.          $result = mysql_query($struery) or die("Cart - paypal_cart_info, Query failed:
  266. " . mysql_error() . "
  267. " . mysql_errno());
  268.  
  269. }
  270.  
  271.     }
  272.  
  273. else{  // notre cas celui du bouton à achat immédiat
  274.  
  275.      $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."’)";
  276.  
  277.      $result = mysql_query($strQuery) or die("Default - paypal_payment_info, Query failed:
  278. " . mysql_error() . "
  279. " . mysql_errno());
  280.  
  281.   // ajoute dans la table créer le récapitulatif du paiement paypal
  282.  
  283. // ensuite on réalise notre propre traitement  par exemple ajout de crédit à un utilisateur etc etc
  284.  
  285. //traitement propre à votre site
  286. $tableau = explode("/",$custom);
  287.          $Member_ID=$tableau[0];
  288.          $Object_ID=$tableau[1];
  289.  
  290. requete sql etc
  291.   ….
  292.  
  293.   …
  294.  
  295.   …
  296.  
  297.   ….
  298.  
  299. }
  300.  
  301. // envoie un email de resultat
  302.  
  303.  echo "Verified";
  304.  
  305.      mail($notify_email, "VERIFIED IPN", "$res\n $req\n $strQuery\n $struery\n  $strQuery2","From: vente@votresite.com");
  306.  
  307. }
  308.  
  309. else {
  310.  
  311. // send an email
  312.  
  313. mail($notify_email, "VERIFIED DUPLICATED TRANSACTION", "$res\n $req \n $strQuery\n $struery\n  $strQuery2");
  314.  
  315. }
  316.  
  317. //subscription handling branch
  318.  
  319.     if ( $txn_type == "subscr_signup"  ||  $txn_type == "subscr_payment"  ) {
  320.  
  321. // insert subscriber payment info into paypal_payment_info table
  322.  
  323.       $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."’)";
  324.  
  325.       $result = mysql_query($strQuery) or die("Subscription - paypal_payment_info, Query failed:
  326. " . mysql_error() . "
  327. " . mysql_errno());
  328.  
  329. // insert subscriber info into paypal_subscription_info table
  330.  
  331.         $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."’)";
  332.  
  333.         $result = mysql_query($strQuery2) or die("Subscription - paypal_subscription_info, Query failed:
  334. " . mysql_error() . "
  335. " . mysql_errno());
  336.  
  337. mail($notify_email, "VERIFIED IPN", "$res\n $req\n $strQuery\n $struery\n  $strQuery2");
  338.  
  339. }
  340.  
  341. }
  342.  
  343. // si le paiement n’est pas valide
  344.  
  345. else if (strcmp ($res, "INVALID") == 0) {
  346.  
  347. // log for manual investigation
  348.  
  349. mail($notify_email, "INVALID IPN", "$res\n $req","From: vente@votresite.com");
  350.  
  351. }
  352.  
  353. }
  354.  
  355. fclose ($fp);
  356.  
  357. }
  358.  
  359. ?>

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 à