Allora ho buttato giu da quel che ho capito un esempio concreto ma sul db nn vengono registrate le notifiche di acquisto ..
File ipn.php
file Deposita.phpCodice PHP:<?php
// intercetta le variabili IPN inviate da PayPal
$req = 'cmd=_notify-validate';
// legge l'intero contenuto dell'array POST
foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}
// intestazione, prepara le variabili PayPal per la validazione
$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";
// apre una connessione al socket PayPal
// $fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);
$fp = fsockopen ('www.paypal.com', 80, $errno, $errstr, 30);
// converte le variabili inviate da IPN in variabili locali
$txn_id = filter_var($_POST['txn_id'], FILTER_SANITIZE_STRING);
$payment_status = filter_var($_POST['payment_status'], FILTER_SANITIZE_STRING);
$receiver_email = filter_var($_POST['receiver_email'], FILTER_SANITIZE_EMAIL);
$payer_email = filter_var($_POST['payer_email'], FILTER_SANITIZE_EMAIL);
$first_name = filter_var($_POST['first_name'], FILTER_SANITIZE_STRING);
$last_name = filter_var($_POST['last_name'], FILTER_SANITIZE_STRING);
$address_street = filter_var($_POST['address_street'], FILTER_SANITIZE_STRING);
$address_city = filter_var($_POST['address_city'], FILTER_SANITIZE_STRING);
$address_state = filter_var($_POST['address_state'], FILTER_SANITIZE_STRING);
$address_zip = filter_var($_POST['address_zip'], FILTER_SANITIZE_STRING);
// verifica l'apertura della connessione al socket
if (!$fp) {
// se la connessione non avviene l'esecuzione dello script viene bloccata
exit();
// in alternativa è per esempio possibile inviare un'email al venditore
} else {
// elaborazione delle informazioni
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
// azioni in caso di risposta positiva da parte di PayPal
if (strcmp ($res, "VERIFIED") == 0) {
// controllo sull'email del venditore
if($receiver_email == "admin_1329468280_biz@gmail.com"){
// connessione a MySQL tramite istanza
mysql_connect('localhost','*****','***');
mysql_select_db('******');
$count = mysql_query("SELECT id_ordini FROM notifiche WHERE txn_id = '$txn_id'");
// controllo sull'identificatore della transazione
if (mysql_affected_rows($count) == 0)
{
// query per l'inserimento dei dati
$result = mysql_query("INSERT INTO notifiche (txn_id, payment_status, payer_email, first_name, last_name, address_street, address_city, address_state, address_zip) VALUES ('$txn_id', '$payment_status', '$payer_email', '$first_name', '$last_name', '$address_street', '$address_city', '$address_state', '$address_zip')");
}
mysql_close();
}
}
// azione in caso di risposta negativa da parte di PayPal else
if (strcmp ($res, "INVALID") == 0) {
// è possibile eseguire qualsiasi operazione
// per esempio compilare un log degli errori o inviare una mail al venditore
}
}
// chiusura della sorgente di dati
fclose($fp);
}
?>
Il file ipn.php non dovrebbe registrare la notifica di acquisto come da codice?Codice PHP:
<form method="post" name="paypal_form" action="https://www.sandbox.paypal.com/cgi-bin/webscr">
<input type="hidden" name="business" value="admin_1329468280_biz@gmail.com" />
<input type="hidden" name="cmd" value="_xclick" />
<input type="hidden" name="return" value="<?php echo "http://".$_SERVER['HTTP_HOST']; ?>/conferma_pagamento.html" />
<input type="hidden" name="cancel_return" value="<?php echo "http://".$_SERVER['HTTP_HOST']; ?>/cancel.html" />
<input type="hidden" name="notify_url" value="<?php echo "http://".$_SERVER['HTTP_HOST']; ?>/ipn.php" />
<input type="hidden" name="rm" value="2" />
<input type="hidden" name="currency_code" value="EUR" />
<input type="hidden" name="lc" value="IT" />
<input type="hidden" name="cbt" value="Continua" />
<input type="hidden" name="shipping" value="7.00" />
<input type="hidden" name="cs" value="1" />
<input type="hidden" name="item_name" value="Monete Del Drago" />
<input type="hidden" name="amount" value="100.00" />
<input type="hidden" name="custom" value="ABR24" />
<!-- informazioni sull'acquirente
<input type="text" name="first_name" />
<input type="text" name="last_name" />
<input type="text" name="address1" />
<input type="text" name="city" />
<input type="text" name="state" />
<input type="text" name="zip" />
<input type="text" name="email" />
--->
<table id="lista_importi" cellspacing="0" cellpadding="5" border="0">
<tbody>
<tr>
<td colspan="2">[b]Scegli l'importo che si desidera aggiungere:[/b]<hr /></td>
</tr>
<tr>
<td><input type="radio" value="importo" value="200" />200 Monete Del Drago = € 3.00 (EUR)</td>
</tr>
<tr>
<td><input type="radio" value="importo" value="500" />500 Monete Del Drago = € 5.00 (EUR)</td>
</tr>
<tr>
<td><input type="radio" checked value="importo" value="1000" />1,000 Monete Del Drago = € 10.00 (EUR)</td>
</tr>
<tr>
<td><input type="radio" value="importo" value="1500" />1,500 Monete Del Drago = € 15.00 (EUR)</td>
</tr>
<tr>
<td><input type="radio" value="importo" value="2000" />2,000 Monete Del Drago = € 20.00 (EUR)</td>
</tr>
<tr>
<td><input type="radio" value="importo" value="3000" />3,000 Monete Del Drago = € 30.00 (EUR)</td>
</tr>
<tr>
<td><input type="radio" value="importo" value="5000" />5,000 Monete Del Drago = € 50.00 (EUR)</td>
</tr>
<tr>
<td><input type="radio" value="importo" value="7000" />7,000 Monete Del Drago = € 70.00 (EUR)</td>
</tr>
<tr>
<td><input type="radio" value="importo" value="10000" />10,000 Monete Del Drago = € 100.00 (EUR)</td>
</tr>
<tr>
<td><input type="image" src="http://www.paypal.com/it_IT/i/btn/x-click-but01.gif" border="0" name="submit" alt="Donazione" /></td>
</tr>
</tbody>
</table>
</form>


Rispondi quotando