Viewing file: paypal_ipn.php (6.05 KB) -rw-rw-r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php
//header('HTTP/1.1 200 OK');
if (!isset($bbddhost))$bbddhost="localhost";
if (!isset($bbdduser))$bbdduser="papyr225_1";
if (!isset($bbddpassword))$bbddpassword="ilvm2rg2";
if (!isset($bbdd))$bbdd="papyr225_papyre";
if (!isset($localhost))$localhost="http://".$server_tratado;
date_default_timezone_set('Europe/Madrid');
//echo $_SERVER['REMOTE_ADDR'];
$handle=fopen ("/tmp/debug.log","w+");
foreach ($_REQUEST as $key=>$valor){
fwrite($handle,"$key=>$valor".chr(10));
}
$handle2=fopen ("/tmp/debug_sql.log","w+");
if ($_REQUEST['payment_status']=='Completed'){
if (!isset($conn)){
@$conn=&mysql_connect($bbddhost,$bbdduser,$bbddpassword)or die("error de conexion con BBDD");
mysql_set_charset('latin1',$conn);
mysql_select_db($bbdd,$conn)or die(mysql_error());
}
$sql ="INSERT INTO `papyr225_papyre`.`paypal` (
`fecha` ,
`mc_gross` ,
`protection_eligibility` ,
`address_status` ,
`payer_id` ,
`tax` ,
`address_street` ,
`payment_date` ,
`payment_status` ,
`charset` ,
`address_zip` ,
`first_name` ,
`mc_fee` ,
`address_country_code` ,
`address_name` ,
`notify_version` ,
`nick` ,
`payer_status` ,
`business` ,
`address_country` ,
`address_city` ,
`quantity` ,
`verify_sign` ,
`payer_email` ,
`txn_id` ,
`payment_type` ,
`last_name` ,
`address_state` ,
`receiver_email` ,
`payment_fee` ,
`receiver_id` ,
`txn_type` ,
`item_name` ,
`mc_currency` ,
`correo` ,
`residence_country` ,
`test_ipn` ,
`transaction_subject` ,
`payment_gross` ,
`ipn_track_id`
)
values
(
'".date('Y-m-d')."',
'".$_REQUEST['mc_gross']."',
'".$_REQUEST['protection_eligibility']."',
'".$_REQUEST['address_status']."',
'".$_REQUEST['payer_id']."',
'".$_REQUEST['tax']."',
'".$_REQUEST['address_street']."',
'".$_REQUEST['payment_date']."',
'".$_REQUEST['payment_status']."',
'".$_REQUEST['charset']."',
'".$_REQUEST['address_zip']."',
'".$_REQUEST['first_name']."',
'".$_REQUEST['mc_fee']."',
'".$_REQUEST['address_country_code']."',
'".$_REQUEST['address_name']."',
'".$_REQUEST['notify_version']."',
'".$_REQUEST['item_name']."',
'".$_REQUEST['payer_status']."',
'".$_REQUEST['business']."',
'".$_REQUEST['address_country']."',
'".$_REQUEST['address_city']."',
'".$_REQUEST['quantity']."',
'".$_REQUEST['verify_sign']."',
'".$_REQUEST['payer_email']."',
'".$_REQUEST['txn_id']."',
'".$_REQUEST['payment_type']."',
'".$_REQUEST['last_name']."',
'".$_REQUEST['address_state']."',
'".$_REQUEST['receiver_email']."',
'".$_REQUEST['payment_fee']."',
'".$_REQUEST['receiver_id']."',
'".$_REQUEST['txn_type']."',
'".$_REQUEST['item_name']."',
'".$_REQUEST['mc_currency']."',
'".$_REQUEST['item_number']."',
'".$_REQUEST['residence_country']."',
'".$_REQUEST['test_ipn']."',
'".$_REQUEST['transaction_subject']."',
'".$_REQUEST['payment_gross']."',
'".$_REQUEST['ipn_track_id']."')";
$res=mysql_query($sql,$conn);
fwrite($handle2,$sql.chr(10));
fwrite($handle2,mysql_error().chr(10));
// ahora, lo ponemos en las otras dos
$sql="select * from papyr225_papyre.patrocinadores where usuario='".$_REQUEST['item_name']."'";
$riis=mysql_query($sql,$conn);
if (mysql_num_rows($riis)>0){
$sql="update papyr225_papyre.patrocinadores set fecha = '".date('Y-m-d')."', grupo='patrocinador' where usuario='".$_REQUEST['item_name']."'";
mysql_query($sql,$conn);
}else{
// $sql="delete from papyr225_papyre.patrocinadores where usuario='".$_REQUEST['custom']."'";
// mysql_query($sql,$conn);
$sql="insert into papyr225_papyre.patrocinadores (usuario, correo, grupo,fecha) values('".$_REQUEST['item_name']."',
'".$_REQUEST['item_number']."','patrocinador','".date('Y-m-d')."')";
mysql_query($sql,$conn);
}
include("actualiza_patrocinadores.php");
}
//Leer POST del sistema de PayPal y a�adir 'cmd'
$req = 'cmd=_notify-validate';
foreach ($_POST as $key => $value) {
fwrite($handle,$value);
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}
fwrite($handle,$req);
//header para el sistema de paypal
$header = "POST /cgi-bin/webscr HTTP/1.1\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Host: www.paypal.com\r\n";
$header .= "Connection: close\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$header .= "Host: www.paypal.com:443\r\n";
// For live servers use $header .= "Host: www.paypal.com:443\r\n";
//header para el correo
$headers = 'From: [email protected]' . "\r\n" .
'Reply-To: [email protected]' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
//Si estamos usando el testeo de paypal:
$fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);
//En caso de querer usar PayPal oficialmente:
//$fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);
if (!$fp) {
mail("[email protected]", "error de http", $recibido , $headers);
// ERROR DE HTTP
}else{
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
$res=trim($res);
if (strcmp ($res, "VERIFIED") == 0) {
//Almacenamos todos los valores recibidos por $_POST.
foreach($_POST as $key => $value){
$recibido.= $key." = ". $value."\r\n";
}
//Enviamos por correo todos los datos , esto es solo para que ve�is como funciona
//En un caso real acceder�amos a una BBDD y almacenar�amos los datos.
fwrite($handle2,"----------------------------------------------------------".$recibido.chr(10));
// > Comprobando que payment_status es Completed
// > Comprobando que txn_id no ha sido previamente procesado
// > Comprobando que receiver_email es tu email primario de paypal
// > Comprobando que payment_amount/payment_currency son procesos de pago correctos
mail("[email protected]", "NOTIFICACION DE PAGO de ".$_REQUEST['item_name'], $recibido , $headers);
}else if (strcmp ($res, "INVALID") == 0) {
mail("[email protected]", "NOTIFICACION DE PAGO de ".$_REQUEST['item_name']." INVALIDA", "invalido",$headers);
}
}fclose ($fp);
}
?>
|