使用ipn paypal pdo进行NoUpdate

时间:2018-06-29 02:19:24

标签: php pdo paypal payment-gateway paypal-ipn

我使用paypal ipn脚本更新用户表。 实际上,更新:

$db->query('UPDATE tlb_users SET maximum_account=1, package_id=1, expiration_date ='.$my_new_date.' WHERE id='.$custom.'');

$db->query("INSERT INTO tbl_historique VALUES ('', ".$custom.",'BASIC','1 Compte Instagram - 30 Jours','".$my_date."','".$my_new_date."')");*

不起作用。

这是我的代码,如果您看到某事..非常感谢! :)

<?php
$my_date=date("Y-m-d H:i:s");

#TA DATE EN TIME
$my_date_time=time("Y-m-d H:i:s");

#TU AJOUTES 30 jours
$my_new_date_time=$my_date_time+2592000;

#TU REPASSE EN FORMAT DATE
$my_new_date=date("Y-m-d H:i:s",$my_new_date_time);
file_put_contents('log', print_r($_POST,true));

// fonction pour vérifier l'unicité de txn_id
//function VerifIXNID($txn_id){
//  file_put_contents('log','Vérification txn_id ');
//  $db = new PDO("mysql:host=localhost;dbname=database","user","pass");
     // $nbreponse = $db->query("SELECT COUNT(*) FROM orders WHERE txn_id=".$txn_id)->fetchColumn();

     //  if($nbreponse > 0 ){
     //      return 1;
     //  }else{
    //      return 0;
     // }
 // }
/**-----------------------------------------------
* Email
-------------------------------------------------**/

$emailto = "user@user.com";
$emailfrom = "user@user.com";
$sujetprefix = "[PAYPAL]";
$charset = "utf-8";

$fichier_log = fopen('log.txt', 'w+');
$log = fgets($fichier_log);
$log .="(".date('Y-m-d')." ".date('H:i') .") - Le script est executé.";
fputs($fichier_log, $log);
$log = fgets($fichier_log);

// Adresse Email de la boutique
$email_account = "user@user.com";

$req = 'cmd=_notify-validate';

foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}

// post back to PayPal system to validate
// renvoyer a paypal pour validation

$header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Host: http://www.paypal.com\r\n";  // http://www.paypal.com for a     live site
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);

// assign posted variables to local variables
// Affecter les variables postées aux variables locales

$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['business'];
$num_cart_items = intval($_POST['num_cart_items']);
$custom = $_POST['custom'];

// numero de transaction
$txn_id = $_POST['txn_id'];

// ON Y MET LE PAQUET mais ça marche pas ...
//$photo = $_FILES['photo'];

//  parser la variable custom
parse_str($_POST['custom'],$custom);
/* $custom['user_id] = 1*/

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
  if($payment_status == "Completed"){
   file_put_contents('log','status completed');
    // check that receiver_email is your Primary PayPal email
    if($custom == $custom){
      file_put_contents('log','id utilisateur confirmée ');
        // check that txn_id has not been previously processed

        // if (VerifIXNID($txn_id) == 0) {

          file_put_contents('log','txn_id vérifier ');
          // check that payment_amount/payment_currency are correct

          // process payment                         
           $uid = $custom;

          // sauvegarder la commande  
          $data=serialize($_POST);

          /*sauvegarde des infos dans un fichier log*/
         // file_put_contents('log_'.$txn_id, print_r($_POST,true));

          // connexion a la base de données
          $db = new PDO('mysql:host=localhost;dbname=c9wroop','c9wroop','jRirZokckP7');
          $req = $db->query('SELECT * FROM tbl_users WHERE id='.$custom.' LIMIT 1');
          $d = $req->fetch(PDO::FETCH_ASSOC);
          if(!empty($d)){

           // $duration = $d['duration'];
           // $uid = $custom['user_id'];
            $data = serialize($_POST);

            //On met à jour la date d'expiration
          //$db->query('UPDATE tlb_users SET expiration = DATE_ADD(NOW(), INTERVAL '.$duration.' MONTH) WHERE id = '.$uid);
          $db->query('UPDATE tlb_users SET maximum_account=1, package_id=1, expiration_date ='.$my_new_date.' WHERE id='.$custom.'');
         // UPDATE tbl_users SET maximum_account=1, package_id=3, expiration_date='$my_new_date' where id='$custom'

          //La j'aimerais récupérer en plus donc photo, titre ,phone,postcode ,city ,street mais je n'y arrive pas          
          //$db->query("INSERT INTO orders (user_id,amount,created,datas,txn_id,photo) VALUES(".$uid.",".$payment_amount.",NOW(),'".$data."','".$txn_id."','".$photo."')");
           $db->query("INSERT INTO tbl_historique VALUES ('', ".$custom.",'BASIC','1 Compte Instagram - 30 Jours','".$my_date."','".$my_new_date."')");
           // $inserts = mysql_query("INSERT INTO tbl_historique VALUES ('','$custom','BASIC','1 Compte Instagram - 30 Jours','$my_date','$my_new_date')");

          file_put_contents('log','Le paiement à bien était confirmé');
          }else{
            file_put_contents('log','Le paiement ne correspond à aucune offre');
          }

          // Envoi du mail
           $mail_To = $emailto;
           $mail_Subject = "Votre commande sur notre boutique";
           $entetes  = "From: ".$emailfrom."\n"; 
           $entetes .= "Reply-To: ".$emailfrom."\n";
           $entetes .= "MIME-Version: 1.0 \n";
           $entetes .= "Content-Transfer-Encoding: 8bit \n";
           $entetes .= "Content-type: text/plain; charset=".$charset."\n";



           $mail_Body = "Bonjour,<br\>Merci d'avoir choisi notre site pour faire vos achats, Votre commande partira dans les plus brèfs délais.";
          // $mail_Body .= "\n";
          // $mail_Body .= "\n---------------------------------------------------------------------------------";                       
          // $mail_Body .= "\n" . "Nombre d'objets dans le panier: " . $num_cart_items;
          // if (strlen($item_name1) > 1) { $mail_Body .= "\n\n" . "1er objet en commande: " . $item_name1 . "\n" . "Numéro de l'objet 1: " . $item_number1 . " - " . "Quantité: " . $quantity1; }
          // if (strlen($item_name2) > 1) { $mail_Body .= "\n\n" . "2e objet en commande: " . $item_name2 . "\n" . "Numéro de l'objet 2: " . $item_number2 . " - " . "Quantité: " . $quantity2; }
          // if (strlen($item_name3) > 1) { $mail_Body .= "\n\n" . "3e objet en commande: " . $item_name3 . "\n" . "Numéro de l'objet 3: " . $item_number3 . " - " . "Quantité: " . $quantity3; }
          // if (strlen($item_name4) > 1) { $mail_Body .= "\n\n" . "4e objet en commande: " . $item_name4 . "\n" . "Numéro de l'objet 4: " . $item_number4 . " - " . "Quantité: " . $quantity4; }
          // if (strlen($item_name5) > 1) { $mail_Body .= "\n\n" . "5e objet en commande: " . $item_name5 . "\n" . "Numéro de l'objet 5: " . $item_number5 . " - " . "Quantité: " . $quantity5; }
          // if (strlen($item_name) > 1) {
          // $mail_Body .= "\n" . "Objet en commande: " . $item_name;
          // $mail_Body .= "\n" . "Numéro de l'objet: " . $item_number;
          // $mail_Body .= "\n" . "Quantité: " . $quantity;
          // }
          // $mail_Body .= "\n";

          // $mail_Body .= "\n---------------------------------------------------------------------------------";   
          // $mail_Body .= "\n";
          // $mail_Body .= "Equipe de ....";

           mail($mail_To, $mail_Subject, $mail_Body, $entetes);
          // }

        // }else{
        //  file_put_contents('log','Transaction déja éffectué ');
        // }

      }else{
            file_put_contents('log','le paiement ne correspond a aucune offre');
        }           
  }else{
    // problème sur le statut de paiement
    file_put_contents('log','Il y a un problème sur le statut de paiement');
  }
  exit();       
}
else if (strcmp ($res, "INVALID") == 0) {
    // log for manual investigation
    // transaction invalide
  file_put_contents('log','Transaction invalide');
 }
}
fclose ($fp);
}
?>

我的表单:

                <form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">     
              <input type="hidden" value="1.00" name="amount" />
              <input name="currency_code" type="hidden" value="EUR" />
  <input name="shipping" type="hidden" value="0.00" />
  <input name="tax" type="hidden" value="0.00" />
  <input name="return" type="hidden" value="https://www.weegoz.com/index.php/users/upgrade?act=ok" />
  <input name="cancel_return" type="hidden" value="https://www.weegoz.com/index.php/users/upgrade?act=pasok" />
  <input name="notify_url" type="hidden" value="https://www.weegoz.com/paiement.php" />
  <input name="cmd" type="hidden" value="_xclick" />
  <input name="business" type="hidden" value="user@user.com" />
  <input name="item_name" type="hidden" value="Compte Basic 30 Jours" />
  <input name="no_note" type="hidden" value="1" />
  <input name="lc" type="hidden" value="FR" />
  <input name="bn" type="hidden" value="PP-BuyNowBF" />
  <input name="custom" type="hidden" value="3" />
  <button type="submit" name="submit" class="btn yellow-crusta">Choisir ce Plan</button>
  </form>

0 个答案:

没有答案