<?php
//////////////////////////////////////////////////
//////////////////////////////////////////********
////////// Multi Payment API ////////********
////////// Made for DTweb 2.0 ////////********
////////// http://DarksTeam.net ////////********
////////// by r00tme ////////********
//////////////////////////////////////////********
////* Report bugs to r00tme => DarksTeam.net /////
//////////////////////////////////////////////////
require $_SERVER['DOCUMENT_ROOT']."/configs/config.php";
require $_SERVER['DOCUMENT_ROOT']."/inc/main_funcs.php";
$log = "";
if(isset($_GET[$option['unique_method_key']]) || isset($_GET['method'])){
if(isset($_GET)){
foreach($_GET as $keys=>$valus){
$log .= "&$keys=$valus";
}
}
if(!empty($_GET[$option['unique_method_key']]) || !empty($_GET['method'])){
//===============================PayPal==IPN===============================================================
if($_GET['method'] === "paypal"){
$req = 'cmd=_notify-validate';
foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}
if($option['ppal_debug']===1){
make_log('/Payments/Paypal/',"[".date("H:i:s", time())."]".$req);
}
$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, $ERROR_NO, $ERROR_STR, 30);
if ($fp) {
$payer_email = addslashes($_POST['payer_email']);
$receiver_email = addslashes( $_POST['receiver_email']);
$item_number = addslashes($_POST['item_number']);
$tax = doubleval(addslashes($_POST['tax']));
$mc_gross = addslashes($_POST['mc_gross']);
$txn_type = addslashes($_POST['txn_type']);
$payment_status = addslashes($_POST['payment_status']);
$currency = addslashes($_POST['mc_currency']);
$transaction_id = addslashes($_POST['txn_id']);
fputs($fp, $header.$req);
while (!feof($fp)) {
$res = fgets($fp, 1024);
if (strcmp($res, "VERIFIED") == 0) {
make_log('/Payments/Paypal/',"[".date("H:i:s", time())."] PayPal sent [status: VERIFIED] [item_number: ".$item_number."]\n");
if (strtolower($receiver_email) == strtolower($option['paypal_email'])) {
$check_for_temp = mssql_query("Select amount,currency,memb___id,credits from DTweb_PayPal_Orders where hash='".$item_number."'");
if ($check_for_temp) {
if (($txn_type == 'web_accept' OR $txn_type == 'subscr_payment') AND $payment_status == 'Completed') {
$check_for_temp = mssql_fetch_array($check_for_temp);
make_log('/Payments/Paypal/',"[".date("H:i:s", time())."] PayPal sent [payment status: ".$payment_status."] [transaction id: ".$transaction_id."] [userid: ".$check_for_temp['memb___id']."] ".$mc_gross." ".$currency."\n");
$order_cost = $check_for_temp['amount'];
if ($tax > 0) {
$mc_gross -= $tax;
}
if ($mc_gross == $order_cost) {
if ($currency == $check_for_temp['currency']) {
$check_if_transaction_exist = mssql_query("Select id from DTweb_PayPal_Transactions where transaction_id='".$transaction_id."'");
if (mssql_num_rows($check_if_transaction_exist) <= 0) {
$order_date_time = time();
$insert_txn_id = mssql_query("INSERT INTO DTweb_PayPal_Transactions (transaction_id,amount,currency,memb___id,credits,order_date,status,payer_email)VALUES('".$transaction_id."','".$mc_gross."','".$currency."','".$check_for_temp['memb___id']."','".$check_for_temp['credits']."','".$order_date_time."','".$payment_status."','".$payer_email."')");
if ($insert_txn_id) {
make_log('/Payments/Paypal/',"[".date("H:i:s", time())."] [PayPal Donate Step 1/2] Insert Transaction Infos [transaction id: ".$transaction_id."] [amount: ".$mc_gross." ".$currency."] [userid: ".$check_for_temp['memb___id']."] [credits: ".number_format($check_for_temp['credits'])."]\n");
$check_for_memb_id = mssql_query("Select memb___id from MEMB_CREDITS where memb___id='".$check_for_temp['memb___id']."'");
if (!$check_for_memb_id) {
$set_credits = mssql_query("insert into MEMB_CREDITS (memb___id,Credits)VALUES('".$check_for_temp['memb___id']."','".$check_for_temp['credits']."')");
}
else {
$set_credits = mssql_query("Update MEMB_CREDITS set Credits=Credits+'".$check_for_temp['credits']."' where memb___id='".$check_for_temp['memb___id']."'");
}
if ($set_credits) {
make_log('/Payments/Paypal/',"[".date("H:i:s", time())."] [PayPal Donate Step 2/2] Set Credits [userid: ".$check_for_temp['memb___id']."] [credits: ".number_format($check_for_temp['credits'])."]\n");
}
}
}
}
}
}
elseif ($payment_status == 'Reversed' OR $payment_status == 'Refunded') {
make_log('/Payments/Paypal/',"[".date("H:i:s", time())."] PayPal sent [payment status: ".$payment_status."] [transaction id: ".$transaction_id."] [userid: ".$check_for_temp['memb___id']."]\n");
if ($option['paypal_punish'] === 1) {
$update_transaction_info = mssql_query("Update DTweb_PayPal_Transactions set status='".$payment_status."' where transaction_id='".$transaction_id."'");
if ($update_transaction_info) {
$bloc_userid = mssql_query("Update memb_info set bloc_code='1' where memb___id='".$check_for_temp['memb___id']."'");
if ($bloc_userid) {
make_log('/Payments/Paypal/',"[".date("H:i:s", time())."] [PayPal Donate Punishment] Block account [userid: ".$check_for_temp['memb___id']."]\n");
}
}
}
}
}
}
}
elseif (strcmp($res, "INVALID") == 0) {
make_log('/Payments/Paypal/',"[".date("H:i:s", time())."] PayPal sent [status: INVALID] [transaction id: ".$transaction_id."] or direct access is attempted ".ip()."\n");
}
else{
header("Location:/");
}
}
fclose ($fp);
header("Location:/"); // Comment this line to debug the module
}
}
else{
switch($_GET[$option['unique_method_key']]){
//=========================PayGol====API================================================================
default : header("Location:/"); break;
}
}
}
else{
header("Location:/");
}
}
else{
header("Location:/");
}
?>