<?php ob_start();
require_once 'lib/nusoap.php';
require_once 'config.php';
require_once 'telegram.php';
$telegram = new telegram(TOKEN,HOST,USERNAME,PASSWORD,DBNAME);

$TokenCode = IDPAYMD;
define('URL_INQUIRY', 'https://api.idpay.ir/v1.1/payment/inquiry');
define('URL_VERIFY', 'https://api.idpay.ir/v1.1/payment/verify');

if(!isset($_GET['type'])) exit;


$action = isset($_GET['action']) ? $_GET['action'] : 'pay';
$type = $_GET['type'];
$callback_url = baseURI."idpay.php?type=$type&action=verify";

if($type == 'renew'){
    if($action == 'pay'){
        $token = base64_decode($_GET['token']);
        $input = explode('#',$token); 
        $userid = intval($input[0]);
        $fid = intval($input[1]);
        $oid = intval($input[2]);

        $order = $telegram->db->query("select * from fl_order where id=$oid")->fetch(2);
        //$fid = $order['fileid'];
        $remark = $order['remark'];
        $server_id = $order['server_id'];
        $inbound_id = $order['inbound_id'];
        $respd = $telegram->db->query("select * from fl_file WHERE id='$fid' and active=1")->fetch(2);
        $name = $respd['title'];
        $days = $respd['days'];
        $volume = $respd['volume'];
        $price = $respd['price'];
        $seller = $telegram->db->query("select * from fl_sellers where userid=$userid")->fetch(2);
				if(!empty($seller)) $price = $price - (($price) * ($seller['percent'] / 100));
        
        $tkid = time();
        file_put_contents("state/$tkid-token-renew.txt", base64_encode($token));
        
        idpay_payment($price, $tkid, $callback_url);
    }elseif($action == 'verify'){
        if ($_SERVER['REQUEST_METHOD'] === 'POST') {
            $response = $_POST;
        }
        
        if ($_SERVER['REQUEST_METHOD'] === 'GET') {
            $response = $_GET;
        }
        
        if (empty($response['status']) ||
            empty($response['id']) ||
            empty($response['track_id']) ||
            empty($response['order_id'])
        ) {
        
            die('تراکنش با خطا مواجه شد');
        }
        
        if ($response['status'] != 10) {
            die('تراکنش با خطا مواجه شد');
        }
        $reference = intval($response['order_id']);
        $token = file_get_contents("state/$reference-token-renew.txt");
        if(!$token) exit;
        
        $input = explode('#',base64_decode($token));
        $userid = intval($input[0]);
        $fid = intval($input[1]);
        $oid = intval($input[2]);
        $order = $telegram->db->query("select * from fl_order where id=$oid")->fetch(2);
        //$fid = $order['fileid'];
        $remark = $order['remark'];
        $server_id = $order['server_id'];
        $inbound_id = $order['inbound_id'];
        $expire_date = $order['expire_date'];
        $expire_date = ($expire_date > $time) ? $expire_date : $time;
        $respd = $telegram->db->query("select * from fl_file WHERE id='$fid' and active=1")->fetch(2);
        $name = $respd['title'];
        $days = $respd['days'];
        $volume = $respd['volume'];
        $price = $respd['price'];
        
        $seller = $telegram->db->query("select * from fl_sellers where userid=$userid")->fetch(2);
				if(!empty($seller)) $price = $price - (($price) * ($seller['percent'] / 100));
				
        $time = time();

        $pay_result = idpay_verify($response, $price);
        if($pay_result == 'success'){
            unlink("state/$reference-token-renew.txt");
    
            require_once('vray.php');
            if($inbound_id > 0)
                $response = renew_client($server_id, $inbound_id, $remark, $volume, $days);
            else
                $response = renew_inbound($server_id, $remark, $volume, $days);
            if($response->success){
                $telegram->db->query("update fl_order set expire_date= $expire_date + $days * 86400,notif=0 where id='$oid'"); 
                $telegram->db->query("INSERT INTO `fl_extra_order` VALUES (NULL, '$userid', '$server_id', '$inbound_id', '$remark', '$price', '$time');");
                echo 'تراکنش با موفقیت انجام شد';
                //$msg = "✅ سفارش شما با موفقیت ثبت شد";
                //$telegram->sendMessage($userid, $msg);
                $telegram->sendMessage($userid, "✅سرویس $remark با موفقیت تمدید شد");
                
                //header("Location : ". baseURI."success");die;
        
            }else {
                die("مشکل فنی در ارتباط با سرور. لطفا به مدیریت اطلاع بدید");
            }
        }
        
        
    }
}

if($type == 'day'){
    if($action == 'pay'){
        $token = base64_decode($_GET['token']);
        $input = explode('#',$token); 
        $server_id = intval($input[0]);
        $inbound_id = intval($input[1]);
        $remark = htmlspecialchars(strip_tags($input[2]));
        $planid = intval($input[3]);
        $userid = intval($input[4]); 
        $res = $telegram->db->query("select * from extra_day where id=$planid")->fetch(2);  
        $price = $res['price'];
        $seller = $telegram->db->query("select * from fl_sellers where userid=$userid")->fetch(2);
				if(!empty($seller)) $price = $price - (($price) * ($seller['percent'] / 100));
        $volume = $res['volume'];
        
        $tkid = time();
        file_put_contents("state/$tkid-token-day.txt", base64_encode($token));
        
        idpay_payment($price, $tkid, $callback_url);
    }elseif($action == 'verify'){
        if ($_SERVER['REQUEST_METHOD'] === 'POST') {
            $response = $_POST;
        }
        
        if ($_SERVER['REQUEST_METHOD'] === 'GET') {
            $response = $_GET;
        }
        
        if (empty($response['status']) ||
            empty($response['id']) ||
            empty($response['track_id']) ||
            empty($response['order_id'])
        ) {
        
            die('تراکنش با خطا مواجه شد');
        }
        
        if ($response['status'] != 10) {
            die('تراکنش با خطا مواجه شد');
        }
        $reference = intval($response['order_id']);
        $token = file_get_contents("state/$reference-token-day.txt");
        if(!$token) exit;
        
        $input = explode('#',base64_decode($token));
        $server_id = intval($input[0]);
        $inbound_id = intval($input[1]);
        $remark = htmlspecialchars(strip_tags($input[2]));
        $planid = intval($input[3]);
        $userid = intval($input[4]); 
        $res = $telegram->db->query("select * from extra_day where id=$planid")->fetch(2);  
        $volume = $res['volume'];
        $price = $res['price'];
        $seller = $telegram->db->query("select * from fl_sellers where userid=$userid")->fetch(2);
				if(!empty($seller)) $price = $price - (($price) * ($seller['percent'] / 100));
				
        $time = time();
        
        $pay_result = idpay_verify($response, $price);
        if($pay_result == 'success'){
            unlink("state/$reference-token-day.txt");
    
            require_once('vray.php');
            if($inbound_id > 0)
                $response = update_client_traffic($server_id, $inbound_id, $remark, 0, $volume);
            else
                $response = update_inbound_traffic($server_id, $remark, 0, $volume);
            if($response->success){
                $telegram->db->query("update fl_order set expire_date= expire_date + $volume * 86400,notif=0 where remark='$remark'");
                $telegram->db->query("INSERT INTO `fl_extra_order` VALUES (NULL, '$userid', '$server_id', '$inbound_id', '$remark', '$price', '$time');");
                $telegram->sendMessage($userid, "✅$volume روز به مدت زمان سرویس شما اضافه شد");
                 echo 'تراکنش با موفقیت انجام شد';
                 $msg = "✅ سفارش شما با موفقیت ثبت شد";
                //$telegram->sendMessage($userid, $msg);
                
                header("Location : ". baseURI."success");die;
        
            }else {
                die("مشکل فنی در ارتباط با سرور. لطفا به مدیریت اطلاع بدید");
            }
        }
        
        
    }
}

if($type == 'volume'){
    if($action == 'pay'){
        $token = base64_decode($_GET['token']);
        $input = explode('#',$token); 
        $server_id = intval($input[0]);
        $inbound_id = intval($input[1]);
        $remark = htmlspecialchars(strip_tags($input[2]));
        $planid = intval($input[3]);
        $userid = intval($input[4]); 
        $res = $telegram->db->query("select * from extra_plan where id=$planid")->fetch(2);  
        $price = $res['price'];
        $volume = $res['volume'];
         $seller = $telegram->db->query("select * from fl_sellers where userid=$userid")->fetch(2);
				if(!empty($seller)) $price = $price - (($price) * ($seller['percent'] / 100));
        
        $tkid = time();
        file_put_contents("state/$tkid-token-volume.txt", base64_encode($token));
        
        
        idpay_payment($price, $tkid, $callback_url);
    }elseif($action == 'verify'){
        if ($_SERVER['REQUEST_METHOD'] === 'POST') {
            $response = $_POST;
        }
        
        if ($_SERVER['REQUEST_METHOD'] === 'GET') {
            $response = $_GET;
        }
        
        if (empty($response['status']) ||
            empty($response['id']) ||
            empty($response['track_id']) ||
            empty($response['order_id'])
        ) {
        
            die('تراکنش با خطا مواجه شد');
        }
        
        if ($response['status'] != 10) {
            die('تراکنش با خطا مواجه شد');
        }
        $reference = intval($response['order_id']);
        $token = file_get_contents("state/$reference-token-volume.txt"); 
        if(!$token) exit;
        
        $input = explode('#',base64_decode($token));
        $server_id = intval($input[0]);
        $inbound_id = intval($input[1]);
        $remark = htmlspecialchars(strip_tags($input[2]));
        $planid = intval($input[3]);
        $userid = intval($input[4]); 
        $res = $telegram->db->query("select * from extra_plan where id=$planid")->fetch(2);  
        $price = $res['price'];
         $seller = $telegram->db->query("select * from fl_sellers where userid=$userid")->fetch(2);
				if(!empty($seller)) $price = $price - (($price) * ($seller['percent'] / 100));
        $volume = $res['volume'];
        $time = time();

        $pay_result = idpay_verify($response, $price);
        if($pay_result == 'success'){
            unlink("state/$reference-token-volume.txt");
    
            require_once('vray.php');
            if($inbound_id > 0)
                $response = update_client_traffic($server_id, $inbound_id, $remark, $volume, 0);
            else
                $response = update_inbound_traffic($server_id, $remark, $volume, 0);
            if($response->success){
                $telegram->db->query("update fl_order set notif=0 where remark='$remark'");
                $telegram->db->query("INSERT INTO `fl_extra_order` VALUES (NULL, '$userid', '$server_id', '$inbound_id', '$remark', '$price', '$time');");
                $telegram->sendMessage($userid, "✅$volume گیگ به حجم سرویس شما اضافه شد");
                echo 'تراکنش با موفقیت انجام شد';
                //$msg = "✅ سفارش شما با موفقیت ثبت شد";
                //$telegram->sendMessage($userid, $msg);
                
                //header("Location : ". baseURI."success");die;
            }else {
                die("مشکل فنی در ارتباط با سرور. لطفا به مدیریت اطلاع بدید");
            }
        }
        
        
    }
}


if($type == 'buy'){
    if($action == 'pay'){
        if(!isset($_GET['token'])){
            header('location:https://t.me/'.botid);
            exit;
        }
        
        $token = base64_decode($_GET['token']); 
        $token = explode('.',$token);
        $userid = intval($token[0]);
        $fid = intval($token[1]);
        if($token[2]) $dcode = htmlspecialchars(strip_tags($token[2]));
        
        $file_detail = $telegram->db->query("select * from fl_file WHERE id=$fid")->fetch(2); 
        $date = time();
        $days = $file_detail['days'];
        $expire_date = $date + (86400 * $days);
        $protocol = $file_detail['protocol'];
        $price = $file_detail['price'];
         $seller = $telegram->db->query("select * from fl_sellers where userid=$userid")->fetch(2);
				if(!empty($seller)) $price = $price - (($price) * ($seller['percent'] / 100));
        $server_id = $file_detail['server_id'];
        $acount = $file_detail['acount'];
        $inbound_id = $file_detail['inbound_id'];
        
        if($dcode){
            $dcount = $telegram->db->query("select * from fl_discount WHERE code='$dcode' and active=1");
            if($dcount->rowCount() > 0){
                $amount = $dcount->fetch(2)['amount'];
                if($amount <= 100) {
                    $price = $price * (100-$amount)/100;
                }else {
                    $price = $price - $amount ;
                }
            }
        }
            
        if($acount == 0 and $inbound_id != 0){
            echo 'ظرفیت این کانکشن پر شده است';
            exit;
        }
        
        $order = $telegram->db->query("INSERT INTO `fl_order` VALUES (NULL,  {$userid}, '', {$fid}, $server_id, $inbound_id, '', '$protocol', $expire_date, '', $price,0, '$date', 0);");
        $order_id = $telegram->db->lastInsertId();
        idpay_payment($price, $order_id, $callback_url);
    }elseif($action == 'verify'){
        if ($_SERVER['REQUEST_METHOD'] === 'POST') {
            $response = $_POST;
        }
        
        if ($_SERVER['REQUEST_METHOD'] === 'GET') {
            $response = $_GET;
        }
        
        if (empty($response['status']) ||
            empty($response['id']) ||
            empty($response['track_id']) ||
            empty($response['order_id'])
        ) {
        
            die('تراکنش با خطا مواجه شد');
        }
        
        if ($response['status'] != 10) {
            die('تراکنش با خطا مواجه شد');
        }
        $order_id = intval($response['order_id']);
        if(!$order_id) exit;
        
        $orderDetails = $telegram->db->query("select * from fl_order where id={$order_id} and status=0")->fetch(2);
        if(empty($orderDetails)) die('این سفارش قبلا تایید شده است');
        $userid = $orderDetails['userid'];
        $fid = $orderDetails['fileid'];
        $file_detail = $telegram->db->query("select * from fl_file WHERE id=$fid")->fetch(2);
        $days = $file_detail['days'];
        $date = time();
        $expire_microdate = intval(floor(microtime(true) * 1000) + (864000 * $days * 100));
        $expire_date = $date + (86400 * $days);
        $type = $file_detail['type'];
        $volume = $file_detail['volume'];
        $protocol = $file_detail['protocol'];
        $price = $file_detail['price'];
         $seller = $telegram->db->query("select * from fl_sellers where userid=$userid")->fetch(2);
				if(!empty($seller)) $price = $price - (($price) * ($seller['percent'] / 100));
        $server_id = $file_detail['server_id'];
        $netType = $file_detail['type'];
        $acount = $file_detail['acount'];
        $inbound_id = $file_detail['inbound_id'];
        $limitip = $file_detail['limitip'];
        
        $price = $orderDetails['amount'];
        
        $pay_result = idpay_verify($response, $price);
        if($pay_result == 'success'){
            
            // V2ray Api
    require_once('vray.php');
    $uniqid = generateRandomString(42,$protocol); 

    $savedinfo = file_get_contents('savedinfo.txt');
    $savedinfo = explode('-',$savedinfo);
    $port = $savedinfo[0] + 1;
    $last_num = $savedinfo[1] + 1;

	$srv_remark = $telegram->db->query("select * from fl_server WHERE id=$server_id")->fetch(2)['remark'];
    $uremark = $telegram->db->query("select * from fl_remark where userid=$userid")->fetch(2);
    if($uremark) $uremark = $uremark['remark']; else $uremark = $srv_remark;
    $remark = "{$uremark}-{$last_num}";

    file_put_contents('savedinfo.txt',$port.'-'.$last_num);
    //$telegram->sendMessage($cuserid,"$server_id, $uniqid, $inbound_id, $expire_microdate, $remark, $volume");exit;
    
    if($inbound_id == 0){    
        $response = add_inbound($server_id, $uniqid, $protocol, $port, $expire_microdate, $remark, $volume, $netType); 
    }else {
        $response = add_inbount_client($server_id, $uniqid, $inbound_id, $expire_microdate, $remark, $volume, $limitip); 
    }
    
    //$telegram->sendMessage($cuserid,json_encode($response));exit;
    $gateways = $telegram->db->query("select * from gateway where id=1")->fetch(2);
	 
    $vray_link = genLink($server_id, $uniqid, $protocol, $remark, $port, $netType, $inbound_id);
    
    $token = generateRandomString2(16);
	$getLink_url = baseURI."sub.php?token=".$token;
	if($gateways['sublink'] == 1){
		$addsub = "\n\n 🔗 لینک هوشمند سرویس شما: \n <code>$getLink_url</code>";
	}
    $acc_text = "🔗 $remark \n <code>$vray_link</code> $addsub" . " \n  برای کپی کردن لینک روی آن کلیک کنید \n";

    
    
    include 'phpqrcode/qrlib.php';
    $path = 'images/';
    $file = $path.$userid.".png"; //unlink($file);
    $ecc = 'L';
    $pixel_Size = 10;
    $frame_Size = 5;
    QRcode::png($vray_link, $file, $ecc, $pixel_Size, $frame_Size);
    $msg = "
✅سفارش شما با موفقیت ثبت شد .
📝 شماره تراکنش : $refid
.";
        $telegram->sendMessage($userid, $msg);
		
	$telegram->sendPhoto($userid,$acc_text,$file);
$sndmsg = "
خرید درگاه IDPay 
قیمت : $price
آیدی کاربر : $userid
آیدی سرور : $server_id
لینک دریافتی :

$vray_link
";
    $telegram->sendMessage($sendchnl,$sndmsg);
	$order = $telegram->db->query("update `fl_order` set link='$vray_link',remark='$remark',status=1 where id=$order_id");
	
	if($inbound_id == 0) {
        $server_info = $telegram->db->query("SELECT * FROM fl_server WHERE id=$server_id")->fetch(2);
        if($server_info['ucount'] != 0)
            $telegram->db->query("UPDATE `fl_server` SET `ucount` = ucount - 1 WHERE id=$server_id");
    }else{
        if($acount != 0) 
            $telegram->db->query("UPDATE `fl_file` SET `acount` = acount - 1 WHERE id=$fid");
    }
    
	echo '<h1 style="text-align:right;color:green;">تراکنش با موفقیت انجام شد . لطفا به ربات برگردید :</h1>';
        $telegram->db->query("update fl_order set status=1 where id='$order_id'");
        
		
    // pay referer
    $userReferer = $telegram->db->query("select * from fl_subuser where userid=$userid");
    if($userReferer->rowCount() ){
        $ures = $userReferer->fetch(2);
        $userToplevel = $ures['toplevel_userid'];
        $ufname = $ures['fname'];
        $amount = ($price) * ($pursant / 100);
        $telegram->db->query("update fl_user set wallet= wallet + $amount WHERE userid=$userToplevel");
        $telegram->sendMessage($userToplevel, "💟کاربر {$ufname} یک خرید به مبلغ  $price تومان انجام داد و $pursant درصد آن یعنی $amount تومان به کیف پول شما اضافه شد👍"); 
    }
            //header("Location : ". baseURI."success");die;

            
        }
    } // verify
}


if($type == 'wallet'){
    if($action == 'pay'){
        $amount = intval($_GET['amount']);// echo $amount;die;
        //if($amount < $min_wallet_charge) die('مبلغ کمتر از 2هزار تومان است');
        $userid = intval($_GET['userid']);
        $result = $telegram->db->query("select * from fl_user WHERE userid='$userid'")->rowCount();
        if($result == 0) die('اطلاعات ارسال اشتباه است');
        $telegram->db->query("INSERT INTO `fl_wallet` VALUES (NULL, '',$amount, $userid, '','0', '$time');");
        $woid = $telegram->db->lastInsertId();
        idpay_payment($amount, $woid, $callback_url."&woid=$woid");
    }elseif($action == 'verify'){
        if ($_SERVER['REQUEST_METHOD'] === 'POST') {
            $response = $_POST;
        }
        
        if ($_SERVER['REQUEST_METHOD'] === 'GET') {
            $response = $_GET;
        }
        
        if (empty($response['status']) ||
            empty($response['id']) ||
            empty($response['track_id']) ||
            empty($response['order_id'])
        ) { die($response);
        
            die('تراکنش با خطا مواجه شد');
        }
        
        if ($response['status'] != 10) {
            die('تراکنش با خطا مواجه شد');
        }
        $woid = intval($_GET['woid']);
        if(!$woid) exit;
        
        $res = $telegram->db->query("select * from fl_wallet where id='$woid'")->fetch(2);
        $amount = $res['amount'];
        $userid = $res['userid'];
        $transid = $res['trans_id'];
        if($_GET['trackId'] != $transid) exit;
        
        $pay_result = idpay_verify($response, $amount);
        if($pay_result == 'success'){
            echo '<h1 style="text-align:right;color:green;">کیف پول شما با موفقیت شارژ شد</h1>' ; 
            $telegram->db->query("update fl_user set wallet= wallet + $amount where userid='$userid'");
            $telegram->db->query("update fl_wallet set status=1 where id=$woid");
            $msg = "✅ کیف پول شما به مبلغ $amount تومان شارژ شد ";
            $telegram->sendMessage($userid, $msg);
            //header("Location : ". baseURI."success");die;
        }else{
            die('تراکنش با خطا مواجه شد');
           // echo 'خطا در تایید تراکنش';
        }
    }
}


function idpay_payment($price, $woid, $callback_url){
    global $TokenCode, $telegram;
    
    $params = array(
        'order_id' => $woid,
        'amount' => $price * 10,
        'phone' => '09999999',
        'name' => 'گیفت استیم'. "#".rand(0,999999),
        'desc' => 'تحویل آنی',
        'callback' => $callback_url,
    );
    $res = idpay_payment_create($params, $TokenCode, false);

    //Redirect to URL You can do it also by creating a form
    if(!$res) {
        die('تراکنش با خطا مواجه شد');
    }
}

function idpay_verify($response,  $price){
    global $TokenCode;
    $inquiry = idpay_payment_get_inquiry($response, $TokenCode, false);

    if ($inquiry) {
        $payres = idpay_payment_verify($response, $TokenCode, false);
        if($payres){
            return 'success';
        }
    }
    die('تراکنش با خطا مواجه شد');
}

function idpay_payment_create($params, $apikey, $sandbox = false) {
    $header = array(
        'Content-Type: application/json',
        'X-API-KEY:' . $apikey,
        'X-SANDBOX:' . $sandbox,
    );
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, 'https://api.idpay.ir/v1.1/payment');
    curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($params));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);

    $result = curl_exec($ch);
    curl_close($ch);
    $result = json_decode($result);
    if (empty($result) || empty($result->link)) {

        die('تراکنش با خطا مواجه شد');
    }

    //.Redirect to payment form
    header('Location:' . $result->link);
    die;
}
function idpay_payment_get_inquiry($response, $apikey, $sandbox = false)
{

    $header = array(
        'Content-Type: application/json',
        'X-API-KEY:' . $apikey,
        'X-SANDBOX:' . $sandbox,
    );

    $params = array(
        'id' => $response['id'],
        'order_id' => $response['order_id'],
    );

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, URL_INQUIRY);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($params));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);

    $result = curl_exec($ch);
    curl_close($ch);

    $result = json_decode($result);

    if (empty($result) ||
        empty($result->status)
    ) {

        /*print 'Exception message:';
        print '<pre>';
        print_r($result);
        print '</pre>';*/

        return FALSE;
    }

    if ($result->status == 10) {
        return TRUE;
    }

    //print idpay_payment_get_message($result->status);

    return FALSE;
}

function idpay_payment_verify($response, $apikey, $sandbox = false)
{

    $header = array(
        'Content-Type: application/json',
        'X-API-KEY:' . $apikey,
        'X-SANDBOX:' . $sandbox,
    );

    $params = array(
        'id' => $response['id'],
        'order_id' => $response['order_id'],
    );

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, URL_VERIFY);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($params));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);

    $result = curl_exec($ch);
    curl_close($ch);

    $result = json_decode($result);

    if (empty($result) ||
        empty($result->status)
    ) {

        /*print 'Exception message:';
        print '<pre>';
        print_r($result);
        print '</pre>';*/

        return FALSE;
    }
    if($result->status) return true;
    /*print idpay_payment_get_message($result->status);

    print '<pre>';
    print_r($result);
    print '</pre>';*/
}

function idpay_payment_get_message($status)
{

    switch ($status) {
        case 1:
            return 'پرداخت انجام نشده است';

        case 2:
            return 'پرداخت ناموفق بوده است';

        case 3:
            return 'خطا رخ داده است';

        case 10:
            return 'در انتظار تایید پرداخت';

        case 100:
            return 'پرداخت تایید شده است';

        case 101:
            return 'پرداخت قبلاً تایید شده است';

        default:
            return 'Error handeling';
    }

    $result = sendcurl('https://pay.ir/payment/verify', [
        'api' => $config->merchant,
        'transId' => request('transId'),
    ]);
    $result = json_decode($result);
    if ($result->status) return $result; else return false;
}
