Ho provato a cercare e a fare da solo, ma mi mancano degli anelli di congiunzione

Dovrei integrare il sistema di notifica immediata di pagamento tramite PayPal.

Il concetto dovrebbe essere semplice...
- l'utente clicca sul tastino PAGA ADESSO
- vengono inviate alcune info alla pagina PayPal che elabora il pagamento
- a pagamento eseguito l'utente viene reindirizzato ad una pagina precisa del mio sito dove ho avrò bisogno di 2 variabili, l'ok dell'avenuto pagamento e l'indicazione di quale utente attivare (l'username per es.)

Ora, tutte le impostazione dal mio account PayPal le ho eseguite (come indicato in questo confuso (confondente) tutorial)
Ho creato il tasto "Paga Adesso":

Codice PHP:
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
    <input type="hidden" name="cmd" value="_s-xclick">
    <input type="hidden" name="usernamen" value="<?php echo $usernamen?>">
    <input type="hidden" name="hosted_button_id" value="XXXXXXXXX">
    <input type="image" src="https://www.paypal.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.paypal.com/it_IT/i/scr/pixel.gif[/img]
</form>
(si può notare che ho aggiunto un campo per l'username)

Ho anche creato la pagina dove deve puntare PayPal a pagamento ultimato:

Codice PHP:
<?php
// read the post from PayPal system and add 'cmd'
$req 'cmd=_notify-synch';

$tx_token $_GET['tx'];

$auth_token "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";

$req .= "&tx=$tx_token&at=$auth_token";


// 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 ('www.sandbox.paypal.com'80$errno$errstr30);
// If possible, securely post back to paypal using HTTPS
// Your PHP server will need to be SSL enabled
// $fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);

if (!$fp) {
// HTTP ERROR
} else {
fputs ($fp$header $req);
// read the body data
$res '';
$headerdone false;
while (!
feof($fp)) {
$line fgets ($fp1024);
if (
strcmp($line"\r\n") == 0) {
// read the header
$headerdone true;
}
else if (
$headerdone)
{
// header has been read. now read the contents
$res .= $line;
}
}

// parse the data
$lines explode("\n"$res);
$keyarray = array();
if (
strcmp ($lines[0], "SUCCESS") == 0) {
for (
$i=1$i<count($lines);$i++){
list(
$key,$val) = explode("="$lines[$i]);
$keyarray[urldecode($key)] = urldecode($val);
}
// 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
$firstname $keyarray['first_name'];
$lastname $keyarray['last_name'];
$itemname $keyarray['item_name'];
$amount $keyarray['mc_gross'];

echo (
"

<h3>Thank you for your purchase!</h3></p>"
);

echo (
"[b]Payment Details[/b]
\n"
);
echo (
"[*]Name: $firstname $lastname\n");
echo (
"[*]Item: $itemname\n");
echo (
"[*]Amount: $amount\n");
echo (
"");
}
else if (
strcmp ($lines[0], "FAIL") == 0) {
// log for manual investigation
}

}

fclose ($fp);

?>

Your transaction has been completed, and a receipt for your purchase has been emailed to you.
You may log into your account at [url='https://www.paypal.com'][url]www.paypal.com[/url][/url] to view details of this transaction.
Ma non so come far funzionare il tutto!!!
C'è qualcuno che può indirizzarmi verso un tutorial "comprensibile" per Dummies o aiutarmi a trovare una via di scampo?

Graziegraziegrazie