Просмотр файла reg_webmoney.php

Размер файла: 2.71Kb
<?php
/*
Гудпага WebMoney. Вызывается когда проходит платеж через мерчанд
Автор: Denvas
*/
//==================================================//
//функция обработки ошибок
function error_handler ($type, $message, $file=__FILE__, $line=__LINE__){ 
    //ошибка
} //function error_handler
//обработчик ошибок
set_error_handler('error_handler'); 
//==================================================//

    include_once("config.php");
    include_once("session.php");

    $fd=fopen($path_log."/webmoney.log","ab");
    if($fd){
        fwrite($fd,date("Y-m-d H:i:s", time())."|".$_SERVER["REQUEST_URI"]."|".strtr(var_export($_POST,true),array("\n"=>" ","\r"=>"","\0"=>"\\0"))."|".(isset($_SERVER['HTTP_USER_AGENT'])?$_SERVER['HTTP_USER_AGENT']:"")."|".$_SERVER['REMOTE_ADDR']."|".(isset($_SERVER['HTTP_COOKIE'])?$_SERVER['HTTP_COOKIE']:"")."|".(isset($_SERVER['HTTP_REFERER'])?$_SERVER['HTTP_REFERER']:"")."\n");
        fclose($fd);
    };
        
    if((empty($_POST["LMI_PAYMENT_NO"]))||(empty($_POST["ses"])))ExitError("Not ID and SES");

    $payer_wm=$_POST['LMI_PAYER_WM'];
    $payer_purse=$_POST['LMI_PAYER_PURSE'];
    $amount=$_POST['LMI_PAYMENT_AMOUNT'];
    $payee_purse=$_POST['LMI_PAYEE_PURSE'];


    //сравнить кошелек и количество денег
    if(strcmp($webmoney_purse,$payee_purse)!=0)ExitError("Error purse ".$purse."!=".$payee_purse);
    //провести транзакцию
    if(!isset($_POST['LMI_PREREQUEST'])){
        $key=$_POST['LMI_PAYEE_PURSE'].$_POST['LMI_PAYMENT_AMOUNT'].$_POST['LMI_PAYMENT_NO'].$_POST['LMI_MODE'].$_POST['LMI_SYS_INVS_NO'].$_POST['LMI_SYS_TRANS_NO'].$_POST['LMI_SYS_TRANS_DATE'].$webmoney_secretkey.$_POST['LMI_PAYER_PURSE'].$_POST['LMI_PAYER_WM'];    
        $signature=strtoupper(md5($key));
        if(strcmp($signature,$_POST['LMI_HASH'])!=0)ExitError("Error signature ".$signature."!=".$_POST['LMI_HASH']);
        if(!empty($_POST['LMI_MODE']))ExitError("Test mode ".$_POST['LMI_MODE']);
        //получение данных
        $data["amount"]=$amount*$webmoney_balance/$webmoney_price;
        $data["session"]=$_POST["ses"];
        $ses=GetSession($data["session"]);
        if(!is_array($ses))NewSession($data["session"],0);
        $ses=GetSession($data["session"],$data["amount"]);
        if(!is_array($ses))ExitError("Error create session");
    };//if
    print "Yes";
    $SQL->Close();
//==================================================//
    function ExitError($error){
        global $path_log;
        print "error check transaction";
        $fd=@fopen($path_log."/webmoney_status_error.log","ab");
        if(!$fd)return 0;
        fwrite($fd,date("Y-m-d H:i:s", time())."|".$error."|".var_export($_POST,true)."\n");
        fclose($fd);
        exit;
    };
?>