Salve a tutti,
ho un sito tipo e-commerce che permette all'utente di pagare tramite paypal.
voglio memorizzare l'ordine in un database solo quando ho ricevuto conferma dell'avvenuto pagamento, e per questo ho visto che è disponibile IPN, fornito da paypal stesso.
ho attivato la funzione nel mio profilo paypal, e implemento il tutto nel modo seguente:

innanzitutto il form del pulsante paga con paypal:
Codice PHP:
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="mia mail">
<input type="hidden" name="lc" value="IT">
<?php echo '<input type="hidden" name="item_name" value="'.$nome_tipologia.'">'?>
<?php 
echo '<input type="hidden" name="amount" value="'.$_SESSION["costo_tot"].'">'?>
<input type="hidden" name="currency_code" value="EUR">
<input type="hidden" name="button_subtype" value="services">
<input type="hidden" name="no_note" value="1">
<input type="hidden" name="no_shipping" value="2">
<input type="hidden" name="rm" value="1">
<input type="hidden" name="return" value="mio url">
<input type="hidden" name="cancel_return" value="mio url">
<input type="hidden" name="notify_url" value="http://URL/ordine_completato.php">
<input type="hidden" name="bn" value="PP-BuyNowBF:btn_buynowCC_LG.gif:NonHosted">
<input type="image" src="https://www.paypalobjects.com/it_IT/IT/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - Il sistema di pagamento online più facile e sicuro!">
[img]https://www.paypalobjects.com/it_IT/i/scr/pixel.gif[/img]
</form>
poi lo script che deve comunicare col server per gestire l'IPN. ho semplicemente copiato il codice fornito da paypal, aggiungendo l'invio dell'email (quando riesco a farlo funzionare farò vari controlli e operazioni):
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";
$fp fsockopen ('ssl://www.paypal.com'443$errno$errstr30);

// assign posted variables to local variables
$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['payer_email'];

if (!
$fp
{
// HTTP ERROR

else 
{
    
fputs ($fp$header $req);
    while (!
feof($fp)) 
    {
        
$res fgets ($fp1024);
        if (
strcmp ($res"VERIFIED") == 0
        {
            
// 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

            
@mail("ind@dom.it","prova","ciao");
        }
        else if (
strcmp ($res"INVALID") == 0
        {
            
// log for manual investigation
        
}
    }
fclose ($fp);

questo script per adesso è su un mio spazio Altervista (lo dico perchè magari è il motivo del non funzionamento).

la cosa non funziona, infatti se vado sul mio profilo paypal, nella cronologia dei messaggi IPN, i 2 messaggi per i pagamenti di prova che ho effettuato sono ancora in invio, con già una decina di tentatativi effettuati.
dove sbaglio?
grazie