YetAnotherForum
Welcome Guest Search | Active Topics | Log In | Register

IPN working, but stops before the end Options
Fanel
#1 Posted : Monday, September 26, 2011 6:32:29 AM
Rank: Starting Member

Groups: Registered

Joined: 9/26/2011
Posts: 1
Hello,

here is my IPN file :

Code:
<?php
##############################################################
## Définitions des chemins d'accès à / et au dossier admin    ##
## Initialisation de l'interface                            ##
##############################################################
DEFINE( 'ROOT_PATH', '' );
DEFINE( 'ADMIN_PATH', ROOT_PATH . 'admin/' );
require_once( ROOT_PATH . 'init.php' );


##############################################################
## Traitements PHP                                            ##
##############################################################
//permet de traiter le retour ipn de paypal
// lire la publication du systeme PayPal et ajouter 'cmd'
$req = 'cmd=_notify-validate';

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

// renvoyer au systeme PayPal pour validation
$header = '';
$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";

//www.sandbox.paypal.com pour la phase de test
//www.paypal.com pour la phase réel.
$fp = fsockopen ('www.sandbox.paypal.com', 80, $errno, $errstr, 30);

// affecter les variables publiées aux variables locales

/*
$_POST['item_name'];
$_POST['item_number'];
$_POST['payment_status'];
$_POST['mc_gross'];
$_POST['mc_currency'];
$_POST['txn_id'];
$_POST['receiver_email'];
$_POST['payer_email'];
*/

//$object_model->print_r_pre($_POST);






if ($fp) {
    
    fputs ($fp, $header . $req);
    while (!feof($fp)) {
        $res = fgets ($fp, 1024);
        if (strcmp ($res, "VERIFIED") == 0) {
            
            // $_POST['custom'] = $_POST['id'];
            mail('david.micheau@adveris.fr', 'custom', $_POST['custom']);
            
            require_once( ROOT_PATH . 'core/classes/class.commande.php' );
            require_once( ROOT_PATH . 'core/classes/class.paiement.php' );
            
            // On valide la commande
            $commande = new Commande(mysql_real_escape_string($_POST['custom']));
            
            $commande->valider();
            
            // $site->print_r_pre($commande);
            // $site->print_r_pre($_SESSION);
            
            // On insère le paiement
            $paiement = new Paiement();
            $paiement->commande_id         = $commande->id;
            $paiement->user_id             = $commande->user_id;
            $paiement->total_ttc         = $commande->total_ttc;
            $paiement->paiement_type_id = 1;
            
            // $site->print_r_pre($paiement);
            
            $paiement->create();
            
            /********************************************************/
            /*         Ajout des crédits                                */
            /********************************************************/
            $panier = new Panier($commande->panier_id);
            // $site->print_r_pre($panier);
            
            foreach($panier->items as $item) {
                $pack = new Pack($item['item_id']);
                
                
                // $site->print_r_pre($pack);
                
                // Offres normales
                if($pack->type_id == 1) {
                    $sql->sql_query(sprintf("UPDATE " . TABLES__EMPLOYEURS . " SET credits_offres = credits_offres + %d WHERE id = %d", $pack->nb_offres * $item['item_quantite'], $session_user->employeur->id));
                }
                
                // Offres focus
                elseif($pack->type_id == 2) {
                    $sql->sql_query(sprintf("UPDATE " . TABLES__EMPLOYEURS . " SET credits_offres_focus = credits_offres + %d WHERE id = %d", $pack->nb_offres * $item['item_quantite'], $session_user->employeur->id));
                }
                
                // CVthèque
                elseif($pack->type_id == 3) {
                    // Si aucun accès cvthèque n'est en cours
                    $cvtheque_en_cours = $sql->get_value_from_query("SELECT id FROM " . TABLES__EMPLOYEURS . " WHERE CURDATE() BETWEEN credits_cvtheque_debut AND credits_cvtheque_fin");
                    if(empty($cvtheque_en_cours)) {
                        $sql->sql_query(sprintf("UPDATE " . TABLES__EMPLOYEURS . " SET credits_cvtheque_debut = CURDATE(), credits_cvtheque_fin = DATE_ADD(CURDATE(), INTERVAL %d MONTH)", $pack->duree_cvtheque));
                    }
                    // Sinon
                    else {
                        $sql->sql_query(sprintf("UPDATE " . TABLES__EMPLOYEURS . " SET credits_cvtheque_fin = DATE_ADD(credits_cvtheque_fin, INTERVAL %d MONTH)", $pack->duree_cvtheque));
                    }
                    
                }
                
                // Vitrine
                elseif($pack->type_id == 4) {
                    // Si aucun accès vitrine n'est en cours
                    $vitrine_en_cours = $sql->get_value_from_query("SELECT id FROM " . TABLES__EMPLOYEURS . " WHERE CURDATE() BETWEEN credits_vitrine_debut AND credits_vitrine_fin");
                    if(empty($vitrine_en_cours)) {
                        $sql->sql_query(sprintf("UPDATE " . TABLES__EMPLOYEURS . " SET credits_vitrine_debut = CURDATE(), credits_vitrine_fin = DATE_ADD(CURDATE(), INTERVAL %d MONTH)", $pack->duree_cvtheque));
                    }
                    // Sinon
                    else {
                        $sql->sql_query(sprintf("UPDATE " . TABLES__EMPLOYEURS . " SET credits_vitrine_fin = DATE_ADD(credits_vitrine_fin, INTERVAL %d MONTH)", $pack->duree_cvtheque));
                    }
                }
            }

            /********************************************************/
            /*         Fin de l'ajout des crédits                        */
            /********************************************************/
            
            
            
            $user = new User($commande->user_id);
            $panier = new Panier($commande->panier_id);
            
            // Envoi du mail
            $tpl = file_get_contents('templates/mails.header.htm');
            $tpl .= file_get_contents('templates/mails.commande.htm');
            $tpl .= file_get_contents('templates/mails.signature.htm');
            $tpl .= file_get_contents('templates/mails.footer.htm');
            

            $panier_str = '<table class="border">' . "\n";
            $panier_str .= '<thead>' . "\n";
            $panier_str .= '<tr>' . "\n";
            $panier_str .= '<th width="400" style="text-align:left;">Pack</th>' . "\n";
            $panier_str .= '<th width="100" style="text-align:right;">Prix</th>' . "\n";
            $panier_str .= '<th width="100" style="text-align:right;">Quantité</th>' . "\n";
            $panier_str .= '<th width="100" style="text-align:right;">Total</th>' . "\n";
            $panier_str .= '</tr>' . "\n";
            $panier_str .= '</thead>' . "\n";
            $panier_str .= '<tbody>' . "\n";
            
            foreach($panier->items as $item) {
                $pack = new Pack($item['item_id']);
            
                $panier_str .= '<tr>' . "\n";
                $panier_str .= '<td>' . $pack->nom . '</td>' . "\n";
                $panier_str .= '<td style="text-align:right;">' . number_format($item['item_prix'], 2, ',', ' ') . ' €</td>' . "\n";
                $panier_str .= '<td style="text-align:right;">' . $item['item_quantite'] . '</td>' . "\n";
                $panier_str .= '<td style="text-align:right;">' . number_format($item['item_prix'] * $item['item_quantite'], 2, ',', ' ') . ' €</td>' . "\n";
                $panier_str .= '</tr>' . "\n";
            
            }
            
            $panier_str .= '<tr>' . "\n";
            $panier_str .= '<td colspan="3">Total H.T. :</td>' . "\n";
            $panier_str .= '<td style="text-align:right;">' . number_format($commande->total_ht, 2, ',', ' ') . ' €</td>' . "\n";
            $panier_str .= '</tr>' . "\n";
            $panier_str .= '<tr>' . "\n";
            $panier_str .= '<tr>' . "\n";
            $panier_str .= '<td colspan="3">TVA :</td>' . "\n";
            $panier_str .= '<td style="text-align:right;">' . number_format($commande->total_tax, 2, ',', ' ') . ' €</td>' . "\n";
            $panier_str .= '</tr>' . "\n";
            $panier_str .= '<tr>' . "\n";
            $panier_str .= '<td colspan="3">Total T.T.C. :</td>' . "\n";
            $panier_str .= '<td style="text-align:right;">' . number_format($commande->total_ttc, 2, ',', ' ') . ' €</td>' . "\n";
            $panier_str .= '</tr>' . "\n";
            
            $panier_str .= '</tbody>' . "\n";
            $panier_str .= '</table>' . "\n";

            $tpl = str_replace("%PANIER%", $panier_str, $tpl);
            $tpl = str_replace("%SITE_NAME%", $config->site_name, $tpl);
            $tpl = str_replace("%SITE_URL%", $config->site_url, $tpl);
            $tpl = str_replace("%SITE_SHORT_URL%", $config->site_short_url, $tpl);
            $tpl = str_replace("%LOGO_URL%", $config->site_url . '/images/logo.jpg', $tpl);
            $tpl = str_replace("%SITE_MAIL%", $config->contact_mail, $tpl);
            
            // On remplace les infos de la signature
            $from_nom = 'L\'équipe ' . $config->site_name;
            $from_mail = $config->contact_mail;
            $tpl = str_replace("%SIGNATURE_FROM%", $from_nom, $tpl);
            $tpl = str_replace("%SIGNATURE_FROM_MAIL%", $from_mail, $tpl);
            
            // Envoi du mail
            $from = $config->site_name . ' <'.$from_mail.'>';
            $subject = mb_strtoupper($config->site_name, 'UTF-8') . ' : confirmation de votre commande';
            $content = $tpl;
            
            $headers = 'From: '. $from . "\n";
            $headers .= 'MIME-Version: 1.0' . "\n";
            $headers .= 'Return-Path: <'.$from_mail.'>' . "\n";
            $headers .= 'Content-type: text/html; charset=utf-8' . "\n";
            $headers .= 'X-Sender: <' . $config->site_short_url . '>' ." \n";
            $headers .= 'X-Mailer: PHP/'.phpversion() . "\n";
            
            // echo $content;
            
            // Envoi du mail au client
            $to = $user->mail;
            mail($to, $subject, $content, $headers);
            
            // Envoi du mail à l'administrateur
            $to = $config->contact_mail;
            // mail($to, $subject, $content, $headers);
            
            
            header('Location: commande.confirmation.php');
            exit();
            
            
            
        }
    }
    fclose ($fp);
}

?>


When I do a test paiement with paypal sandbox, my IPN is launched. I know it because my order is validated (line 69) and the payment is inserted in my database (line 83). But everythig coming next doesn' work. And if I run my IPN file in a browser (and manually setting $_POST['custom'], which is my order ID),everything works fine, from first to last line of code.

Any idea why this IPN is stopped in the middle of the process when called by paypal ?
Sponsor  
 
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

YAFVision Theme by Jaben Cargman (Tiny Gecko)
Powered by YAF | YAF © 2003-2009, Yet Another Forum.NET
This page was generated in 0.166 seconds.