IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

E-Commerce Discussion :

Paypal IPN: Problème avec fsockopen


Sujet :

E-Commerce

  1. #1
    Membre habitué Avatar de ilalaina
    Homme Profil pro
    Inscrit en
    Mai 2007
    Messages
    341
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Madagascar

    Informations forums :
    Inscription : Mai 2007
    Messages : 341
    Points : 187
    Points
    187
    Par défaut Paypal IPN: Problème avec fsockopen
    Bonjour à tous.
    Je rencontre un petit problème avec paypal IPN.
    Après paiement réussi par le client je renvoie les données postées au système paypal pour validation, comme indiqué dans la doc officielle.
    Ci-dessous mon code :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    // lire la publication du système PayPal et ajouter 'cmd'
    $req = 'cmd=_notify-validate';
    
    foreach($_POST as $key => $value)
    {
    	$value = urlencode(stripslashes($value));
    	$req .= "&$key=$value";
    }
    
    // renvoyer au système PayPal pour validation
    $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('www.beta-sandbox.paypal.com', 80, $errno, $errstr, 30);
    if(! $fp)
            {
                // ERREUR HTTP
                $this->erreur(PAYPAL_ERROR_MSG, $Custom->UrlRedirect);
            } else
            {
                fputs($fp, $header . $req);
                while(! feof($fp))
                {
                    $res = fgets($fp, 1024);
                    if(strcmp($res, "VERIFIED") == 0)
                    {
                        // transaction valide
    					...
    Mon problème est que le programme ne passe jamais sur ce test if(strcmp($res, "VERIFIED") == 0) alors que quand j'affiche $res j'obtiens :
    HTTP/1.1 200 OK

    Date: Thu, 04 Feb 2010 13:13:57 GMT

    Server: Apache

    Set-Cookie: c9MWDuvPtT9GIMyPc3jwol1VSlO=rM7FwBYswz5ShOiHcBpMnSVRl5p_PCChIqakgmQnzvCgC_mq2lVaGjdazt742VY7TluIDHUdELPyX2jtehmR1spKeUEd2uIKpz0tS44TBI9HnQzE-RwWX7G3jAw-cSKFZrpXuW%7chOu1p7HnNfc0Wz7zniKUe7SlDIi6FjsH6Ebnxsd7Sn_SmNRD5TLh3S-gTMgjlfaBL2yk5G%7cA7L_Q1bpYuLqnTG9HEXLAjLEPdWYrXbLwLwaJ1N7AKzwevu5z6aQvHDDaHVBZMvFISjuqm%7c1265289237; domain=.paypal.com; path=/

    Set-Cookie: cookie_check=yes; expires=Sun, 02-Feb-2020 13:13:57 GMT; domain=.paypal.com; path=/

    Set-Cookie: navcmd=_notify-validate; domain=.paypal.com; path=/

    Set-Cookie: navlns=0; expires=Wed, 30-Jan-2030 13:13:57 GMT; domain=.paypal.com; path=/

    Set-Cookie: Apache=10.191.196.11.50871265289237365; path=/; expires=Wed, 23-Dec-03 06:45:41 GMT

    Connection: close

    Content-Type: text/html; charset=UTF-8

    VERIFIED
    J'ai effectué plusieurs tests mais je n'arrive pas à trouver ce qui cloche dans ce code.

    Merci d'avance de votre aide.
    " ... On naît, on vit, on meurt, mais exister est un honneur ... "

  2. #2
    Membre habitué Avatar de ilalaina
    Homme Profil pro
    Inscrit en
    Mai 2007
    Messages
    341
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Madagascar

    Informations forums :
    Inscription : Mai 2007
    Messages : 341
    Points : 187
    Points
    187
    Par défaut
    Pour ceux qui en auront besoin j'ai résolu le problème en convertissant mon fichier en format unix(LF). C'est parce que strcmp effectue une comparaison binaire de deux chaînes, alors que fgets renvoie la ligne courante sur laquelle se trouve le pointeur du fichier : VERIFIED+LF != VERIFIED+CRLF.
    " ... On naît, on vit, on meurt, mais exister est un honneur ... "

  3. #3
    Candidat au Club
    Profil pro
    Inscrit en
    Mai 2005
    Messages
    4
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2005
    Messages : 4
    Points : 3
    Points
    3
    Par défaut
    Bonjour,

    J'ai le même soucis que toi à savoir que je ne pas dans if(strcmp($res, "VERIFIED") == 0)

    En fait la vriable $res ne me retourne que

    pourtant on utilise le même code :

    mon formulaire
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    $formHtml = "<form action=\"https://www.sandbox.paypal.com/cgi-bin/webscr\" method=\"post\">";
    			$formHtml.="<input type='hidden' value='".$pack_valeur."' name='amount' />";
    			$formHtml.="<input name='currency_code' type='hidden' value='EUR' />";
    			$formHtml.="<input name='shipping' type='hidden' value='0.00' />";
    			$formHtml.="<input name='tax' type='hidden' value='0.00' />";
    			$formHtml.="<input name='return' type='hidden' value= '". $this->_urlHome ."/achatcredits/return' />";
    			$formHtml.="<input name='cancel_return' type='hidden' value='". $this->_urlHome ."/achatcredits/cancel' />";
    			$formHtml.="<input name='notify_url' type='hidden' value='". $this->_urlHome ."/achatcredits/paiement' />";
    			$formHtml.="<input name='cmd' type='hidden' value='_xclick' />";
    			$formHtml.="<input name='business' type='hidden' value='sel_..._biz@gmail.com' />";
    			$formHtml.="<input name='item_name' type='hidden' value='".$libelle_pack."' />";
    			$formHtml.="<input name='no_note' type='hidden' value='1' />";
    			$formHtml.="<input name='lc' type='hidden' value='FR' />";
    			$formHtml.="<input name='bn' type='hidden' value='PP-BuyNowBF' />";
    			$formHtml.="<input name='custom' type='hidden' value='". $pack_id.'/'. $utilisateur_id ."' />";/** Variable: pack_id + utilisateur_id **/
    			$formHtml.="<input type='hidden' name='charset' value='UTF-8'>";
    			$formHtml.="<input type='submit' class='boutonBleu' style='margin-left: 235px; margin-top:20px; font-weight:bold;' value='Payer par Paypal &rsaquo;'>";
    			$formHtml.="</form>";
    et la vérification après le traitement
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    $req = 'cmd=_notify-validate';
    		
    		foreach ($post as $key => $value) {
    	        $value = urlencode(stripslashes($value));
    	        $req .= "&$key=$value";
    	    }
        	
            // renvoyer au système PayPal pour validation
    	    $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 ('www.sandbox.paypal.com', 80, $errno, $errstr, 30);
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
     if (!$fp) {
    		    // 	ERREUR HTTP	    	
    	    } else {
    	        fputs ($fp, $header . $req);
    	        while (!feof($fp)) {
    	            $res = fgets ($fp, 1024);	            
    	            if (strcmp ($res, "VERIFIED") == 0) {...

    J'ai loupé un truc ??
    Ce qui m'agace le plus, c'est que cela fonctionnait, il y a à peu près 2 mois (pas re tester depuis) !


    Merci d'avance

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. PayPal, problème avec IPN
    Par HwRZxLc4 dans le forum E-Commerce
    Réponses: 0
    Dernier message: 10/12/2008, 20h54
  2. Problème avec paypal
    Par Coussati dans le forum Applications
    Réponses: 7
    Dernier message: 04/03/2006, 23h41
  3. Problème avec la mémoire virtuelle
    Par Anonymous dans le forum CORBA
    Réponses: 13
    Dernier message: 16/04/2002, 16h10

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo