home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
79.96.193.101
/
79.96.193.101.tar
/
79.96.193.101
/
www
/
paypal_callback.php
< prev
next >
Wrap
PHP Script
|
2014-10-20
|
6KB
|
159 lines
<?php
//============================================
// Easy 2.0
// Copyright : .exe Evolution
// Wersja : 2.0
// Uwagi : Brak
//============================================
define("BASEDIR", dirname(__FILE__));
include(BASEDIR . "/inc/init.php");
$tmpl = new Easy("templates/$THEME/");
include(BASEDIR . "/system/shop/shopinc.php");
$sql_pp = $db->Query("SELECT inst_id FROM ".PREFIX."_shop_payment_methods WHERE id='5'");
$row_pp = $sql_pp->fetchrow();
define("PEMAIL", $row_pp->inst_id);
$paypal_mail = PEMAIL;
$req = 'cmd=_notify-validate';
foreach($_POST as $key => $value){
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}
$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.paypal.com', 80, $errno, $errstr, 30);
$item_name = $_POST['item_name'];
$item_number = $_POST['item_number'];
$payment_status = $_POST['payment_status'];
$payment_amount = str_replace(',','.',$_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)
{
PutLog("PayPal payment: could not connect to www.paypal.com:80", PRIO_ERROR, __FILE__, __LINE__);
}
else
{
fputs ($fp, $header . $req);
while (!feof($fp))
{
$res = fgets ($fp, 1024);
if(strcmp($res, 'VERIFIED') == 0)
{
if(strcmp($_REQUEST['payment_status'], 'Completed') == 0)
{
if(trim(strtolower($_REQUEST['receiver_email'])) == trim(strtolower($paypal_mail)))
{
$cartId = $item_number;
$q = "
SELECT
a.*,
b.email
FROM
" . PREFIX . "_shop_orders as a,
" . PREFIX . "_user as b
WHERE
a.control = '$cartId' AND
a.ovall = ".$payment_amount." AND
a.status_o != 'failed' AND
a.status_o != 'ok' AND
b.uid = a.uid
";
$sql = $db->Query($q);
$row_u = $sql->fetchrow();
$uemail = $row_u->email;
if($sql->numrows() == 1){
$sql_first = $db->Query("UPDATE ". PREFIX ."_shop_orders SET status_o = 'progress' WHERE control = '$cartId' ");
$items = explode(',', $row_u->articles);
$download_files = '';
foreach($items as $item){
$sql_esd = $db->Query("SELECT id,artnumber,esd_download,esd_dltimes,esd_timespan FROM " . PREFIX . "_shop_articles WHERE artnumber='$item'");
$row_esd = $sql_esd->fetchrow();
$esd_timespan = ($row_esd->esd_timespan=='') ? 0 : $row_esd->esd_timespan ;
$time_end = mktime(date("H")+$esd_timespan, date("i"), date("s"),date("m"), date("d"), date("Y"));
if($row_esd->esd_download != '') {
$itemkey = makepass(10);
$sql_newesd = $db->Query("INSERT INTO " . PREFIX . "_shop_esd (id,uid,dltimes,dlid,dltimespan,itemkey) VALUES ('','$userId','','$row_esd->id','$time_end','$itemkey')");
$download_files .= "\n---------------------------------------\n$row_esd->esd_download ($row_esd->esd_dltimes ".$lang['shop_max_downloads_esd'].")\nhttp://" .$_SERVER['HTTP_HOST'] . str_replace('/paypal_callback.php','',$_SERVER['PHP_SELF']) . "/index.php?p=shop&action=downloadfile&file_id=$row_esd->id&itemkey=$itemkey\n";
$download_files_copy .= "\n$row_esd->esd_download";
}
}
if($download_files!=''){
$body_first = str_replace("__TRANSID__", $cartId, $lang['shop_subject_cc_transaction_ok_header']);
$mails = $body_first . "\n" . $download_files . "\n" . $lang['shop_footer_ccokesd_2'] . "\n\n" . SHOPADRESS;
$thismail = new MIMEMail();
$thismail->from_email = EMAILFROM;
$thismail->subject = $lang['shop_subject_cc_transaction_ok'];
$thismail->to = $uemail;
$thismail->headers();
$thismail->addtextpart( false, $mails);
$thismail->finish();
$thismail->send();
} else {
$body_first = str_replace("__TRANSID__", $cartId, $lang['shop_subject_cc_transaction_ok_header2']);
$mails = $body_first . "\n\n" . SHOPADRESS;
$thismail = new MIMEMail();
$thismail->from_email = EMAILFROM;
$thismail->subject = $lang['shop_subject_cc_transaction_ok'];
$thismail->to = $uemail;
$thismail->headers();
$thismail->addtextpart( false, $mails);
$thismail->finish();
$thismail->send();
}
$copybody = $lang['shop_subject_cc_transaction_ok_header_copy'];
$copybody = str_replace("__OVALL__", $payment_amount,$copybody);
$copybody = str_replace("__TRANSID__", $cartId ,$copybody);
$copybody = str_replace("__USERID__", $row_u->uid,$copybody);
$copybody = str_replace("__UEMAIL__", $uemail,$copybody);
if($download_files_copy!='') $copybody .= "\n\n" . $lang['shop_copy_esdfoot_admin'] . "\n" . $download_files_copy;
$thismail = new MIMEMail();
$thismail->from_email = EMAILFROM;
$thismail->subject = $lang['shop_subject_cc_transaction_ok'];
$thismail->to = EMAILTO;
$thismail->headers();
$thismail->addtextpart( false, $copybody);
$thismail->finish();
$thismail->send();
}
else
{
}
}
else
{
PutLog("PayPal payment: payment receiver is not \"" . $paypal_mail . "\" " . $_REQUEST['txn_id'] . ")", PRIO_WARNING, __FILE__, __LINE__);
}
}
}
else if(strcmp($res, 'INVALID') == 0)
{
PutLog("PayPal payment: got INVALID while trying to validate payment (" . (isset($_REQUEST['txn_id']) ? $_REQUEST['txn_id'] : 'n/a') . ")", PRIO_WARNING, __FILE__, __LINE__);
}
}
fclose ($fp);
}
?>