Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 11

Discussione: paypall IPN verifica

  1. #1
    Utente di HTML.it
    Registrato dal
    Jul 2010
    Messaggi
    98

    paypall IPN verifica

    ciao a tutti,

    sto tribolando da un pò con la funzione che dovrebbe verificare l'IPN di ritorno dai pagamenti paypall,

    i pagamenti funzionano solo che con questo script non ricevo mai nessuna email :

    codice:
     error_reporting(E_ALL ^ E_NOTICE);
    $email = 'lamiaemail@mail.it';
    $header = "";
    $emailtext = "";
    // Read the post from PayPal and add 'cmd'
    $req = 'cmd=_notify-validate';
    if(function_exists('get_magic_quotes_gpc'))
    {
    	$get_magic_quotes_exits = true;
    }
    foreach ($_POST as $key => $value)
    // Handle escape characters, which depends on setting of magic quotes
    {
    	if($get_magic_quotes_exists == true && get_magic_quotes_gpc() == 1){
    		$value = urlencode(stripslashes($value));
    	} else {
    		$value = urlencode($value);
    	}
    	$req .= "&$key=$value";
    }
    // Post back to PayPal to validate
    $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 ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);
    
    
    // Process validation from PayPal
    // TODO: This sample does not test the HTTP response code. All
    // HTTP response codes must be handles or you should use an HTTP
    // library, such as cUrl
    
    if (!$fp) { // HTTP ERROR
    } else {
    // NO HTTP ERROR
    fputs ($fp, $header . $req);
    while (!feof($fp)) {
    	$res = fgets ($fp, 1024);
    	if (strcmp ($res, "VERIFIED") == 0) {
    		// TODO:
    		// Check the payment_status is Completed
    		// Check that txn_id has not been previously processed
    		// Check that receiver_email is your Primary PayPal email
    		// Check that payment_amount/payment_currency are correct
    		// Process payment
    		// If 'VERIFIED', send an email of IPN variables and values to the
    		// specified email address
    		foreach ($_POST as $key => $value){
    		$emailtext .= $key . " = " .$value ."\n\n";
    		}
    		mail($email, "Live-VERIFIED IPN", $emailtext . "\n\n" . $req);
    	} else if (strcmp ($res, "INVALID") == 0) {
    		// If 'INVALID', send an email. TODO: Log for manual investigation.
    		foreach ($_POST as $key => $value){
    		$emailtext .= $key . " = " .$value ."\n\n";
    		}
    		mail($email, "Live-INVALID IPN", $emailtext . "\n\n" . $req);
    	}
    }
    fclose ($fp);
    sto diventando matto perchè le email non arrivano mai , lo script è esattamente quello che fornisce paypall per i pagamenti.

    qualcuno sa aiutarmi?


  2. #2
    Utente di HTML.it
    Registrato dal
    Apr 2004
    Messaggi
    3,709
    intanto inserisci una riga di debug prima del comando "mail" per verificare che la riga stessa sia raggiunta (per esempio crea un file con un testo di debug): se tutto funziona allora è il comando "mail" che non va... potrebbe essere un problema di intestazioni non complete, in questo caso.

  3. #3
    senti ma stai testando con l'account di prova vero??

    altrimenti devo sostituire questo

    ssl://www.sandbox.paypal.com

    con qualcosa del genere ssl://www.paypal.com

    poi non ho guardato se il resto del tuo codice è ok

  4. #4
    Utente di HTML.it
    Registrato dal
    Jul 2010
    Messaggi
    98
    ciao si certo l'account è di prova...

    solo che ho provato mettendo una scrittura a un file per debuggare ma in nessuno dei casi scrive qualcosa su file niente di niente....

    adesso ho trovato uno script che usa cUrl e sembra che almeno scriva errore :

    Codice PHP:
    $req 'cmd=_notify-validate';

    // Run through the posted array
    foreach ($_POST as $key => $value)
    {
        
    // If magic quotes is enabled strip slashes
        
    if (get_magic_quotes_gpc())
        {
            
    $_POST[$key] = stripslashes($value);
            
    $value stripslashes($value);
        }
        
    $value urlencode($value);
        
    // Add the value to the request parameter
        
    $req .= "&$key=$value";
    }

    $url "http://www.sandbox.paypal.com/cgi-bin/webscr";
    $ch curl_init();    // Starts the curl handler
    curl_setopt($chCURLOPT_URL,$url); // Sets the paypal address for curl
    curl_setopt($chCURLOPT_FAILONERROR1);
    curl_setopt($chCURLOPT_RETURNTRANSFER,1); // Returns result to a variable instead of echoing
    curl_setopt($chCURLOPT_TIMEOUT3); // Sets a time limit for curl in seconds (do not set too low)
    curl_setopt($chCURLOPT_POST1); // Set curl to send data using post
    curl_setopt($chCURLOPT_POSTFIELDS$req); // Add the request parameters to the post
    $result curl_exec($ch); // run the curl process (and return the result to $result
    curl_close($ch);

    if (
    strcmp ($result"VERIFIED") == 0// It may seem strange but this function returns 0 if the result matches the string So you MUST check it is 0 and not just do strcmp ($result, "VERIFIED") (the if will fail as it will equate the result as false)
    {
        
    // Do some checks to ensure that the payment has been sent to the correct person
        // Check and ensure currency and amount are correct
        // Check that the transaction has not been processed before
        // Ensure the payment is complete
        
    $myFile ='../paypall.txt';
    $fh fopen($myFile'w') or die("can't open file");
    $stringData "VERIFIED";
    fwrite($fh$stringData);
    fclose($fh);
    }
    else
    {
        
    // Log an invalid request to look into
        
    $myFile ='../paypall.txt';
    $fh fopen($myFile'w') or die("can't open file");
    $stringData "ERROR  =>".$req."";
    fwrite($fh$stringData);
    fclose($fh);

    con questo codice quanto meno scrive al file.... e mi scriver esattamente "ERROR" come scritto nel codice dell'ultimo else{}



    non riesco a capire perchè tanto tribolare.... le api di paypall fanno schifo o sono io che mi perdo in un bicchiere d'acqua?

  5. #5
    Utente di HTML.it
    Registrato dal
    Jul 2010
    Messaggi
    98
    ho paura che siano le api paypall a far schifo allora nessuno sa rispondermi?

  6. #6
    Utente di HTML.it
    Registrato dal
    Apr 2004
    Messaggi
    3,709
    ma se ti scrive "...error..." vuol dire che la transazione non è verificata, quindi il problema è questo... magari non stai usando gli account di test esatti o annulli la transazione...

  7. #7
    Utente di HTML.it
    Registrato dal
    Jul 2010
    Messaggi
    98
    ti giuro ho ricontrollato i dati dell'account sia nel form sia al momento del pagamento sono giusti

    non capisco proprio guarda....

    grazie comunque del supporto davvero

  8. #8
    Utente di HTML.it
    Registrato dal
    Jul 2010
    Messaggi
    98
    aspetta.... adesso sono entrato su developer.paypall.com per verificare i dati degli account di test, vedo che l'account che sto usando per ricevere i pagamenti(business) risulta "unverified" ....può essere questo il problema? e se si sai come si fa a rendere verificato un account?

    grazie di cuore

  9. #9
    ciao è molto probabile che non perfezioni il pagamento se lo stato è unverified

    per gli account di test su developer.paypal io ti consiglio di non utilizzare quelli preconfigurati (che hanno settaggi per l'estero, valuta, ricezione pagamenti) ma di crearteli manualmente.

    se il tuo account di prova risulta non verificato vai su test accounts, lo selezioni e ci entri: fatto il login puoi cambiare tutti i settaggi come un normale account, e svolgi fittiziamente le operazioni che normalmente avresti fatto per verificare l'account, quindi devi cliccare su status unverified e fare quello che ti dice

    per queste operazioni puoi esserti utile anche la funzione test email senmpre su sandbox.paypal.com per cliccare su eventuali messaggi di verifica, soprattutto se gli account email degli utenti di prova sono fittizi

    comunque, se non dipendesse da unverified, per quanto riguarda lo script, hai provato a non utilizzare curl??



    Codice PHP:
    <?php
    $req 
    'cmd=_notify-validate';
    foreach (
    $_POST as $key => $value) {
        
    $value urlencode(stripslashes($value));
        
    $req .= "&$key=$value";
    }

    $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";

    $sandbox = isset($_POST['test_ipn']) ? true false;

    if (
    $sandbox) {
        
    $fp fsockopen ('ssl://www.sandbox.paypal.com'443$errno$errstr30);
    } else {
        
    $fp fsockopen ('ssl://www.paypal.com'443$errno$errstr30);
    }


    // recupero variabili da paypal
    // - per inviare messaggio mail
    // - per aggiornare database
    $item_name            $_POST['item_name'];
    $payment_amount        $_POST['mc_gross'];
    $txn_id             $_POST['txn_id'];
    $receiver_email        $_POST['receiver_email'];
    $payer_email         $_POST['payer_email'];
    $custom             $_POST['custom'];
    $payment_status        $_POST['payment_status'];


    if (!
    $fp) {
        
    // HTTP ERROR

    else {
        
    fputs ($fp$header $req);
        while (!
    feof($fp)) {
            
    $res fgets ($fp1024);
            
            if (
    strcmp ($res"VERIFIED") == 0) {
                
                if ((
    $payment_status == "Completed")) {
                
                
    // potresti controllare anche
                // $txn_id !=0
                // $receiver_email = tuo_account_paypal
                
                // mando email
                // aggiorno database
                // etc

                
    }
            } 

        }
        
        
    fclose($fp);
    }
    ?>

  10. #10
    Utente di HTML.it
    Registrato dal
    Jul 2010
    Messaggi
    98
    cioa guarda sei gentilissimo , sto perdendo ogni speranza nel frattempo

    nel form paypal io ho :

    Codice PHP:
    <form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
                        <
    input type="hidden" name="cmd" value="_xclick"/>
                        <
    input type="hidden" name="business" value="email_1291823428_biz@hotmail.it(business test email)"/>
                        <
    input type="hidden" name="txn_type" value="express checkout" /> 
    nello script IPN faccio come hai detto tu :

    Codice PHP:
    $req 'cmd=_notify-validate';
    foreach (
    $_POST as $key => $value) {
        
    $value urlencode(stripslashes($value));
        
    $req .= "&$key=$value";
    }

    $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";

    $sandbox = isset($_POST['test_ipn']) ? true false;

    if (
    $sandbox) {
        
    $fp fsockopen ('ssl://www.sandbox.paypal.com'443$errno$errstr30);
    } else {
        
    $fp fsockopen ('ssl://www.paypal.com'443$errno$errstr30);
    }


    // recupero variabili da paypal
    // - per inviare messaggio mail
    // - per aggiornare database
    $item_name            $_POST['item_name'];
    $payment_amount        $_POST['mc_gross'];
    $txn_id             $_POST['txn_id'];
    $receiver_email        $_POST['receiver_email'];
    $payer_email         $_POST['payer_email'];
    $custom             $_POST['custom'];
    $payment_status        $_POST['payment_status'];


    if (!
    $fp) {
        
    // HTTP ERROR
         // Log an invalid request to look into
        
    $myFile ='../paypal.txt';
    $fh fopen($myFile'w') or die("can't open file");
    $stringData "ERROR1  =>".$req."";
    fwrite($fh$stringData);
    fclose($fh);

    else {
        
    fputs ($fp$header $req);
        while (!
    feof($fp)) {
            
    $res fgets ($fp1024);
            
            if (
    strcmp ($res"VERIFIED") == 0) {
                
                if ((
    $payment_status == "Completed")) {
                
                
    // potresti controllare anche
                // $txn_id !=0
                // $receiver_email = tuo_account_paypal
                
                // mando email
                // aggiorno database
                // etc
                       
    $myFile ='../paypal.txt';
    $fh fopen($myFile'w') or die("can't open file");
    $stringData "VERIFIED";
    fwrite($fh$stringData);
    fclose($fh);

                }
            }

            else{
                  
    $myFile ='../paypall.txt';
    $fh fopen($myFile'w') or die("can't open file");
    $stringData "ERROR2";
    fwrite($fh$stringData);
    fclose($fh);
            }
           

        }
        
        
    fclose($fp);

    ho aggiunto un ultimo else{} allo script che mi hai fornito e per adesso viene sempre eseguito quello

    ovvero nel file mi ritrovo sempre la scritta "ERROR2"

    l'account business l'ho creato da zero e adesso risulta verified ..... davvero non capisco più cosa devo fare

    grazie ancora ma qua la vedo dura uscirne

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.