Visualizzazione dei risultati da 1 a 4 su 4

Discussione: Paypal IPN - Database

  1. #1

    Paypal IPN - Database

    Ciao ragazzi!
    Sono alle prese con il mio ecommerce. Devo integrare nel sito il sistema per gestire i pagamenti con PayPal. Vedendo la documentazione ho visto che per avere una corretta gestione dei dati occorre utilizzare il sistema IPN, così se per qualche motivo l'utente dovesse chiudere la finestra dei pagamenti, nel database avrei già il risultato (scusate la forma forse imprecisa dei verbi ma avete capito ).
    Ho provveduto a generare lo script che si occupa appunto di fare tutte le query
    Codice PHP:
    // read the post from PayPal system and add 'cmd'
    $req 'cmd=_notify-validate';
    foreach (
    $_POST as $key => $value) {
    $value urlencode(stripslashes($value));
    $req .= "&$key=$value";
    }
    // post back to PayPal system 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";
    $paypal_url "www.sandbox.paypal.com"// [url]www.paypal.com[/url]
    $fp fsockopen ('ssl://'.$paypal_url443$errno$errstr30);
    //... recupero di tutti i post....
    //DB connect creds and email 
    $notify_email =  "fabioxx91@hotmail.it";         //email address to which debug emails are sent to
    $DB_Server ""//your MySQL Server
    $DB_Username ""//your MySQL User Name
    $DB_Password ""//your MySQL Password
    $DB_DBName ""//your MySQL Database Name
    if (!$fp) {
    // HTTP ERROR
    } else {
    fputs ($fp$header $req);
    while (!
    feof($fp)) {
    $res fgets ($fp1024);
    if (
    strcmp ($res"VERIFIED") == 0) {
    //create MySQL connection
    $Connect = @mysql_connect($DB_Server$DB_Username$DB_Password)
    or die(
    "Couldn't connect to MySQL:
    mysql_error() . "
    mysql_errno());
    //select database
    $Db = @mysql_select_db($DB_DBName$Connect)
    or die(
    "Couldn't select database:
    mysql_error(). "
    mysql_errno());
    $fecha date("m")."/".date("d")."/".date("Y");
    $fecha date("Y").date("m").date("d");
    //check if transaction ID has been processed before
    $checkquery "select txnid from paypal_payment_info where txnid='".$txn_id."'";
    $sihay mysql_query($checkquery) or die("Duplicate txn id check query failed:
    mysql_error() . "
    mysql_errno());
    $nm mysql_num_rows($sihay);
    if (
    $nm == 0){
    //execute query
        
    if ($txn_type == "cart"){
        
    $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) 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."')";
         
    $result mysql_query($strQuery) or die("Cart - paypal_payment_info, Query failed:
    mysql_error() . "
    mysql_errno());
         for (
    $i 1$i <= $num_cart_items$i++) {
             
    $itemname "item_name".$i;
             
    $itemnumber "item_number".$i;
             
    $on0 "option_name1_".$i;
             
    $os0 "option_selection1_".$i;
             
    $on1 "option_name2_".$i;
             
    $os1 "option_selection2_".$i;
             
    $quantity "quantity".$i;
             
    $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."')";
             
    $result mysql_query($struery) or die("Cart - paypal_cart_info, Query failed:
    mysql_error() . "
    mysql_errno());
         }
        }
        else{
         
    $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) 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."')";
         
    $result mysql_query("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) 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."')") or die("Default - paypal_payment_info, Query failed:
    mysql_error() . "
    mysql_errno());
        }
        
    // send an email in any case
     
    echo "Verified";
         
    mail($notify_email"VERIFIED IPN""$res\n $req\n $strQuery\n $struery\n  $strQuery2");
    }
    else {
    // send an email
    mail($notify_email"VERIFIED DUPLICATED TRANSACTION""$res\n $req \n $strQuery\n $struery\n  $strQuery2");
    }
        
    //subscription handling branch
        
    if ( $txn_type == "subscr_signup"  ||  $txn_type == "subscr_payment"  ) {
          
    // insert subscriber payment info into paypal_payment_info table
          
    $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) 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."')";
          
    $result mysql_query($strQuery) or die("Subscription - paypal_payment_info, Query failed:
    mysql_error() . "
    mysql_errno());
             
    // insert subscriber info into paypal_subscription_info table
            
    $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."')";
            
    $result mysql_query($strQuery2) or die("Subscription - paypal_subscription_info, Query failed:
    mysql_error() . "
    mysql_errno());
                 
    mail($notify_email"VERIFIED IPN""$res\n $req\n $strQuery\n $struery\n  $strQuery2");
        }
    }
    // if the IPN POST was 'INVALID'...do this
    else if (strcmp ($res"INVALID") == 0) {
    // log for manual investigation
    mail($notify_email"INVALID IPN""$res\n $req");
    }
    }
    fclose ($fp);
    }
    mail($notify_email"INVALID IPN"$res); 
    Fatto questo, ho provveduto a creare nel mio database le tabelle che gli servono. Come notate alle prime righe, appena ricevuto il codice io avevo:
    Codice PHP:
    $paypal_url "www.paypal.com";
    $fp fsockopen ('ssl://'.$paypal_url443$errno$errstr30); 
    che poi, siccome lavoro con l'account di test ho trasformato in
    Codice PHP:
    $paypal_url "www.sandbox.paypal.com"// [url]www.paypal.com[/url]
    $fp fsockopen ('ssl://'.$paypal_url443$errno$errstr30); 
    non so se questo indirizzo è valido. L'ho trovato facendo qualche ricerca su google, ma non ho idea se potrebbe funzionare...anche se mi pare di no.

    RISULTATI
    Ho eseguito quindi il mio script, inviando il seguente modulo:
    codice:
    <form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
       <input type="hidden" name="cmd" value="_cart" />
       <input type="hidden" name="upload" value="1" />
       <input type="hidden" name="test_ipn" value="1" />
       <input type="hidden" name="business" value="admin_1237917534_per@infinito.it" />
       <input type="hidden" name="currency_code" value="EUR" />
       <input type="hidden" name="notify_url" value="paypal.php" />
       <input type="hidden" name="item_number_1" value="9788895774169" />
       <input type="hidden" name="item_name_1" value="titolo articolo 1" />
       <input type="hidden" name="amount_1" value="15" />
       <input type="hidden" name="item_number_2" value="9788895774121" />
       <input type="hidden" name="item_name_2" value="titolo articolo 2" />
       <input type="hidden" name="amount_2" value="18.5" />
    	<input name="submit_paypal" style="font-size: 18px;" value="Conferma ordine" type="submit">
     </form>
    Spedito il modulo, lavorando come TEST, quindi utilizzando il primo codice che ho postato non mi restituisce nessun errore via e-mail (cosa che invece succede quando uso l'account normale con i dati di test). Comunque sia, in nessun caso riesco ad avere tutti i dati nel database....anzi...sono sempre vuoti...Questo mi fa capire che forse non prosegue tutto come dovrebbe, nonostante il pagamento lo porto a termine dal sito di Paypal (tutti i dati su paypal.com una volta spedito il modulo sono infatti corretti).

    Come posso risolvere?
    Grazie mille!
    Realizzazione script php/mysql, per info:
    delrossofabio@gmail.com

    http://forum.html.it/forum/showthread.php?s=&threadid=1478962

  2. #2
    Utente di HTML.it L'avatar di diaz
    Registrato dal
    Apr 2000
    residenza
    Berlin
    Messaggi
    379
    ti viene creato un nuovo record nel database, anche se vuoto?
    se non ti viene restituito nessun messaggio, prova a verificare se hai correttamente impostato paypal con le opzioni di IPN.
    IPN é impostato su "on"?
    qual'é l'URL per IPN?
    E da quel giorno, se andavo da qualche parte, io ci andavo correndo!

    Tweeting @apphancer | Views my own – except when I say things I don’t really think.

  3. #3
    Utente di HTML.it L'avatar di diaz
    Registrato dal
    Apr 2000
    residenza
    Berlin
    Messaggi
    379
    <input type="hidden" name="notify_url" value="paypal.php" />
    se l'URL lo imposti dal form... a paypal sever il percorso assoluto e non relativo allo script di return


    inoltre...
    Codice PHP:
    // $paypalHost = 'www.paypal.com';
    $paypalHost 'www.sandbox.paypal.com';
    $fp fsockopen ($paypalHost80$errno$errstr30); 
    infine, perché la variabile $txn_type deve restituire "cart" per far inserire il record nel database? consultando velocemente il codice mi sfugge
    E da quel giorno, se andavo da qualche parte, io ci andavo correndo!

    Tweeting @apphancer | Views my own – except when I say things I don’t really think.

  4. #4
    Originariamente inviato da diaz
    ti viene creato un nuovo record nel database, anche se vuoto?
    se non ti viene restituito nessun messaggio, prova a verificare se hai correttamente impostato paypal con le opzioni di IPN.
    IPN é impostato su "on"?
    qual'é l'URL per IPN?
    No, non viene creato nemmeno un nuovo record. Il database risulta pulito come lo era originalmente.
    Nel pannello di controllo SandBox, io visualizzo due account: uno "Personal" e uno "Business". In tutti e due gli account ho questa opzione: "Payment Review" che può essere settata su "Disabled" oppure "Enabled". Nelle prove che ho effettuato, questo valore per entrambi gli account era settato su "Disabled", può essere questo?

    Posso anche modificare il valore "Test mode", posizionandolo su "Disabled" oppure "Enabled". Questa opzione però è valida solo nell'account "Business", in quello "Personal" mi scrive "N/A". Non sono presenti altre impostazioni....

    Il mio script IPN risiede qui: http://www.negozionweb.com/ecommerce...ypal.class.php.

    Originariamente inviato da diaz
    se l'URL lo imposti dal form... a paypal sever il percorso assoluto e non relativo allo script di return
    Sisi, il path nello script viene impostato correttamente con il percorso assoluto, qui non l'ho riscritto però originalmente è così...


    Originariamente inviato da diaz
    infine, perché la variabile $txn_type deve restituire "cart" per far inserire il record nel database? consultando velocemente il codice mi sfugge
    Nello script sembra che per far inserire la variabile il risultato deve essere appunto "cart", però io nel modulo invio "_cart". Se provo a modificarlo con "cart" nel modulo, non funziona dicendomi che non trova la pagina...



    Help
    Realizzazione script php/mysql, per info:
    delrossofabio@gmail.com

    http://forum.html.it/forum/showthread.php?s=&threadid=1478962

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.