FORM PAYPAL
codice:
<form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post" id="paypal_orig">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="mail@mail.it">
<input type='hidden' name='return' value="final.php?id=<?=$id?>">
<input type="hidden" name="currency_code" value="EUR" />
<input type="hidden" name="add" value="1">
<input type="hidden" name="custom" id="custom" value="<?=$id?>">
<input type="hidden" name="item_name" value="SMS2ALL">
<input type="hidden" name="item_number" value="1">
<?php
if($spesa<0.99){
$spesa=0.99;
}
echo"<input type='hidden' name='amount' value='".$spesa."' id='amount'>";
?>
<input type="submit" id="rinnova" value="PAGA" id="paga">
</form>
Sul sito di paypal va e riesco anche a tornare correttamente alla pagina final.php, il problema però è che il file php che uso come listener e dovrebbe occuparsi della riuscita del pagamento non va mai in esecuzione (da quel poco che ne capisco).
LISTENER IPN
codice:
<?
$req = 'cmd=_notify-validate';
foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
if($key=='custom'){
$sess_id=$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, $errstr, 30);
// 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 ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0) {
$to = 'support@bitage.com';
$subject = 'paypal';
$message = 'id che ha pagato: '.$sess_id;
$headers = 'From: test' . "\r\n" .
'Reply-To: test' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
session_destroy();
}
else if (strcmp ($res, "INVALID") == 0) {
// log for manual investigation
}
}
fclose ($fp);
}
$conn=mysql_connect('localhost', 'root', 'root');
if(!$conn){
}
else{
$db=mysql_select_db('sms2all');
if(!$db){
}
else{
$sql="select testo, mittente, destinatario from invio_messaggi where idsessione=".$_POST['custom'];
if(!mysql_query($sql)){
}
else{
$res=mysql_query($sql);
$url="api2.infobip.com";
$page="/api/sendsms/plain";
while($riga=mysql_fetch_array($res)){
$sql2="insert into pagamento(idsessione, stato_pagamento, data) values ('".$_POST['custom']."', 1, NOW())";
if(!mysql_query($sql2)){
}
else{
$sql3="update invio_messaggi set inviato=1 where destinatario='".$riga['destinatario']."'
and idsessione='".$_POST['custom']."'";
if(!mysql_query($sql3)){
}
else{
}
}
}
}
}
}
?>
qui ho leggermente variato i nomi delle pagine, però tenete conto che il giro lo fa giusto, semplicemente non fa le 2 query