Вход Регистрация
Файл: online_easysoft.php
Строк: 226
<?
$full_home_path 
dirname(__FILE__);
require_once(
$full_home_path."/_rootload.php");

$inputXML $GLOBALS['HTTP_RAW_POST_DATA'];
$inputArray xmlToArrayL($inputXML);

# $inputArray[Request][DateTime];
# $inputArray[Request][Sign];

# $inputArray[Request][Check][ServiceId];
# $inputArray[Request][Check][Account];

# $inputArray[Request][Payment][ServiceId];
# $inputArray[Request][Payment][Account];
# $inputArray[Request][Payment][OrderId];
# $inputArray[Request][Payment][Amount];

# $inputArray[Request][Confirm][ServiceId];
# $inputArray[Request][Confirm][PaymentId];

mconnect();

$paysystem = @mysql_query("select * from pay_systems where type='easysoft'");
$paysystem = @mysql_fetch_object($paysystem);

$easysoft_serviceid $paysystem->text1;
$easysoft_pubkey $paysystem->text2;
$easysoft_privkey $paysystem->text3;
$easysoft_ip $paysystem->area1;
$easysoft_nacenka $paysystem->small1;

if (
$inputXML) {
    
$userBalanceEnable GetSetting("userBalanceEnable");

    if (
$paysystem->active and $userBalanceEnable) {
        if (
$easysoft_ip) {
            if (
IsIPInIPs($ip,$easysoft_ip)) {
                if (
easySoftCheckSign($inputXML$inputArray[Request][Sign], $easysoft_pubkey)) {
                    if (
$inputArray[Request][Check][ServiceId]) {
                        if (
preg_match("/^d+$/",$inputArray[Request][Check][Account])) {
                            
$user GetUserById($inputArray[Request][Check][Account]);
                            if (
$user->id) {
                                if (
$user->surname and $user->name) { $user_name $user->surname." ".$user->name." ".$user->otchestvo; } else { $user_name $user->login; }

                                
$balance $user->money;
                                
$balance $balance GetCurrencyKoeficientByCode("UAH");
                                
$balance round($balance,2);

                                
easySoftSendResponse("0""OK""<AccountInfo><Name>$user_name</Name><Email>".$user->email."</Email><Balance>$balance</Balance></AccountInfo>"$easysoft_privkey);
                            } 
                            else {
                                
$error_msg "Идентификатор абонента не найден.";
                                
easySoftSendResponse("-1"$error_msg""$easysoft_privkey);
                            }
                        }
                        else {
                            
$error_msg "Неверный формат идентификатора абонента.";
                            
easySoftSendResponse("-1"$error_msg""$easysoft_privkey);
                        }
                    }
                    else if (
$inputArray[Request][Payment][ServiceId]) {
                        if (
preg_match("/^d+$/",$inputArray[Request][Payment][Account])) {
                            
$user GetUserById($inputArray[Request][Payment][Account]);
                            if (
$user->id) {
                                if (
$inputArray[Request][Payment][Amount] > 0) {
                                    
$bill = @mysql_query("select id from bills where merchantId='".$inputArray[Request][Payment][OrderId]."' and merchantType='easysoft'");
                                    if (@
mysql_num_rows($bill) > 0) {
                                        
$bill = @mysql_fetch_object($bill);
                                        
$bill_id $bill->id;
                                    } else {
                                        
$money $inputArray[Request][Payment][Amount] - ($inputArray[Request][Payment][Amount]/100)*$easysoft_nacenka;
                                        
$money $money GetCurrencyKoeficientByCode("UAH");
                                        
$money round($money,2);

                                        @
mysql_query("insert into bills (uid,money,created,addfunds,history,merchantmoney,merchantId,merchantType) values('$user->id','$money',NOW(),'1','$user->login','$money','".$inputArray[Request][Payment][OrderId]."','easysoft')");
                                        
$bill_id = @mysql_insert_id();
                                    }

                                    
easySoftSendResponse("0""OK""<PaymentId>$bill_id</PaymentId>"$easysoft_privkey);
                                }
                                else {
                                    
$error_msg "Сумма платежа не может быть меньше или равна нулю.";
                                    
easySoftSendResponse("-1"$error_msg""$easysoft_privkey);
                                }
                            }
                            else {
                                
$error_msg "Идентификатор абонента не найден.";
                                
easySoftSendResponse("-1"$error_msg""$easysoft_privkey);
                            }
                        }
                        else {
                            
$error_msg "Неверный формат идентификатора абонента.";
                            
easySoftSendResponse("-1"$error_msg""$easysoft_privkey);
                        }
                    }
                    else if (
$inputArray[Request][Confirm][ServiceId]) {
                        
$bill GetBillById($inputArray[Request][Confirm][PaymentId]);
                        if (
$bill->id) {
                            
MakeBillPayed($bill->id,1,"EasySoft (order_id: $bill->merchantId)");

                            
$bill GetBillById($bill->id);
                            
$pay_dt = @str_replace(" ""T"$bill->payeddt);

                            
easySoftSendResponse("0""OK""<OrderDate>$pay_dt</OrderDate>"$easysoft_privkey);
                        }
                        else {
                            
$error_msg "Счет не найден.";
                            
easySoftSendResponse("-1"$error_msg""$easysoft_privkey);
                        }
                    }
                    else {
                        
$error_msg "Не удалось определить тип запроса, либо отсутствует значение ServiceId.";
                        
easySoftSendResponse("-1"$error_msg""$easysoft_privkey);
                    }
                }
                else {
                    
$error_msg "Ошибка проверки подписи запроса.";
                    
easySoftSendResponse("-1"$error_msg""$easysoft_privkey);
                }
            }
            else {
                
$error_msg "IP-адрес $ip отсутствует в списке доступа.";
                
easySoftSendResponse("-1"$error_msg""$easysoft_privkey);
            }
        }
        else {
            
$error_msg "Не задан список IP-адресов для доступа.";
            
easySoftSendResponse("-1"$error_msg""$easysoft_privkey);
        }
    } 
    else {
        
$error_msg "Прием платежа запрещен провайдером.";
        
easySoftSendResponse("-1"$error_msg""$easysoft_privkey);
    }

else {
    
$error_msg "Отсутствует XML-запрос.";
    
easySoftSendResponse("-1"$error_msg""$easysoft_privkey);
}

if (
$error_msg) {
    
$manager_email=GetSetting('manager_email');

    
$msg "Автоматическая оплата через EasySoft отклонена биллинг-системой по причине:nn$error_msgnn$inputXMLnn$responseXML";
    
$subject "Ошибка автоматической оплаты [EasySoft]";

    
$admEmails=GetAdminEmailsWhereTrueParam("senderror");
    if (
count($admEmails) > 0) {
        
WriteMailLog($subject,$msg);
    }
    while (list(
$i,$em) = @each($admEmails)) {
        
sendmail($em,'',$manager_email,$subject,$msg);
    }
}

mclose();






function 
easySoftSendResponse($status_code$status_detail$params$private_key){
    global 
$responseXML;

    
$response "<Response>
<StatusCode>
$status_code</StatusCode>
<StatusDetail>
$status_detail</StatusDetail>
<DateTime>"
.date('Y-m-dTH:i:s'time())."</DateTime>
<Sign></Sign>
$params
</Response>"


    
$response=easySoftAddSign($response$private_key);

    
$responseXML $response;

    print 
$response;


function 
easySoftAddSign($xml$private_key) {
    if (
$private_key) {
            
$fp fopen($private_key"r");         
            
$pkeyid fread($fp8192);
            
fclose($fp);
            
$pr_key openssl_get_privatekey($pkeyid);  
            
openssl_sign($xml$sign$pr_key);
            
$hexsign bin2hex($sign); 
            return 
str_replace("<Sign></Sign>""<Sign>".strtoupper($hexsign)."</Sign>"$xml);
    } else {
        return 
$xml;
    }
}

function 
easySoftCheckSign($xml$sign$public_key) {
    if (
$public_key) {
            
$fp fopen($public_key"r");         
            
$pkeyid fread($fp8192);
            
fclose($fp);
            
$pub_key openssl_get_publickey($pkeyid);
            
$xml str_replace($sign''$xml);
            
$bin_sign pack("H*"$sign);
            return 
openssl_verify($xml$bin_sign$pub_key);
    } else {
        return 
true;
    }
}

?>
Онлайн: 1
Реклама