Buongiorno....
andando sul sito di PAYPAL e ho notato che sono cambiati i sintassi di pagamenti PAYPAL tramite IPN e devo dirti che funziona ma c'è un dubbio e ti spiego...
La pagina HTML dove c'è il pulsante PAGA PAYPAL è così
E su IPN.PHP è codificato così
Ma se qualcuno prendere rubando l'URL tramite VISUALIZZA SORGENTE PAGINA questo codice
Copiando e incollando
Quando carica e appare la scritta
E ho notato che viene inserito lo stesso nel database mysql anche se è INVALID, perchè?
Cosa ho sbagliato?
Se ho messo la IF su if(strcmp($res, "VERIFIED") == 0) e if(strcmp ($res, "INVALID") == 0) come può essere?
andando sul sito di PAYPAL e ho notato che sono cambiati i sintassi di pagamenti PAYPAL tramite IPN e devo dirti che funziona ma c'è un dubbio e ti spiego...
La pagina HTML dove c'è il pulsante PAGA PAYPAL è così
HTML:
<form method="post" name="paypal_form" action="https://www.sandbox.paypal.com/cgi-bin/webscr">
<input type="hidden" name="business" value="sb-km22v1237710@business.example.com" />
<input type="hidden" name="cmd" value="_xclick" />
<!-- informazioni sulla transazione -->
<input type="hidden" name="return" value="http://www.prova.com/grazie.php" />
<input type="hidden" name="cancel_return" value="http://www.prova.com/ritorna.php" />
<input type="hidden" name="notify_url" value="http://www.prova.com/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" />
<!-- informazioni sul pagamento -->
<input type="hidden" name="shipping" value="7.00" />
<input type="hidden" name="cs" value="1" />
<!-- informazioni sul prodotto -->
<input type="hidden" name="item_name" value="Guida PayPal IPN con PHP" />
<input type="hidden" name="amount" value="100.00" />
<!-- questo campo conterrà le info che torneranno al sito e viene usato per passare l'id utente o altre info -->
<input type="hidden" name="custom" value="ABR24" />
<!-- pulsante pagamento -->
<input type="image" src="http://www.paypal.com/it_IT/i/btn/x-click-but01.gif" border="0" name="submit" alt="Paga subito con PayPal" />
</form>
E su IPN.PHP è codificato così
PHP:
<?php
$raw_post_data = file_get_contents('php://input');
$raw_post_array = explode('&', $raw_post_data);
$myPost = array();
foreach ($raw_post_array as $keyval)
{
$keyval = explode ('=', $keyval);
if(count($keyval) == 2)
{
$myPost[$keyval[0]] = urldecode($keyval[1]);
}
}
$req = 'cmd=_notify-validate';
if(function_exists('get_magic_quotes_gpc'))
{
$get_magic_quotes_exists = true;
}
foreach($myPost as $key => $value)
{
if($get_magic_quotes_exists == true && get_magic_quotes_gpc() == 1)
{
$value = urlencode(stripslashes($value));
} else {
$value = urlencode($value);
}
$req .= "&". $key ."=". $value ."";
}
$ch = curl_init('https://ipnpb.sandbox.paypal.com/cgi-bin/webscr');
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: Close'));
if(!($res = curl_exec($ch)))
{
// error_log("Got " . curl_error($ch) . " when processing IPN data");
curl_close($ch);
exit;
}
if(strcmp($res, "VERIFIED") == 0)
{
$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'];
$query = "SELECT txnid FROM ". $database_gestionale .".carrello_prenotazioni WHERE txnid='". $txn_id ."'";
$count = mysqli_query($connessione, $query);
$disponibile = mysqli_num_rows($count);
// controllo sull'identificatore della transazione
if($disponibile == 0)
{
$queryPayPal = "INSERT INTO ". $database_gestionale .".carrello_prenotazioni (txnid) VALUES ('". $txn_id ."')";
mysqli_query($connessione, $queryPayPal);
$queryVideoUtente = "INSERT INTO ". $database_gestionale .".utenti_video (titolo) VALUES ('Prova OK')";
mysqli_query($connessione, $queryVideoUtente);
}
} elseif(strcmp ($res, "INVALID") == 0)
{
echo "The response from IPN was: <b>". $res ."</b>";
}
curl_close($ch);
?>
Ma se qualcuno prendere rubando l'URL tramite VISUALIZZA SORGENTE PAGINA questo codice
HTML:
<input type="hidden" name="notify_url" value="http://www.prova.com/ipn.php" />
Copiando e incollando
Quando carica e appare la scritta
HTML:
The response from IPN was: INVALID
E ho notato che viene inserito lo stesso nel database mysql anche se è INVALID, perchè?
Cosa ho sbagliato?
Se ho messo la IF su if(strcmp($res, "VERIFIED") == 0) e if(strcmp ($res, "INVALID") == 0) come può essere?