<?php
/**
 * Пример обработки ответов сервера оплаты
 * @author chayn1k [3DaVinci]
 */

$NETCAT_FOLDER = join( strstr(__FILE__, "/") ? "/" : "\\", array_slice( preg_split("/[\/\\\]+/", __FILE__), 0, -4 ) ).( strstr(__FILE__, "/") ? "/" : "\\" );

include_once ($NETCAT_FOLDER."vars.inc.php");
require_once ($ROOT_FOLDER."connect_io.php");

$nc_core->modules->load_env();

$content = DV_IMONEY_ORDER_NOT_DATA_FOR_SHOW;

$in_param = $nc_core->input->fetch_get_post();
$dv_imoney = new dv_imoney();

if($in_param['payment']){
	$link_info = dv_imoney::pay_link_decode($in_param['payment']);
	$order_info = $dv_imoney->get_order_info($link_info['id']);
	if($order_info['Status'] == $dv_imoney->ms_status(5)){
		$content = DV_IMONEY_PAYMENT_HAS_COMPLETED;
	} else {
		$content = $dv_imoney->show_pay_button($order_info['Message_ID'], 'form');
	}
}

if($in_param['orderId']){
	if ($_SERVER['REMOTE_ADDR'] == '91.212.151.242' || $_SERVER['X_FORWARDED_FOR'] == '91.212.151.242') {
		$result = $dv_imoney->handler(intval($in_param['orderId']));
		if ($result){
			$content = "OK\n";
			//echo DV_IMONEY_PAYMENT_SUCCESS;
		} else {
			$content = DV_IMONEY_PAYMENT_FAIL;
		}
	} else {
		$content = DV_IMONEY_PAYMENT_FAIL_NOT_IMONEY;
	}
}


