<?php



function redirect($url)
{
    if (!headers_sent()) {
        header('Location: ' . $url);
        exit;
    } else {
        echo '<script type="text/javascript">';
        echo 'window.location.href="' . $url . '";';
        echo '</script>';
        echo '<noscript>';
        echo '<meta http-equiv="refresh" content="0;url=' . $url . '" />';
        echo '</noscript>';
        exit;
    }
}


function sendmessage($text, $chatid, $keys)
{
    $send = "https://api.telegram.org/bot6395431401:AAH3VXdiFjRzP--O04rRweqciUe0V6Q1TmA/sendmessage?chat_id=$chatid&text=$text&parse_mode=Html&reply_markup=$keys";
    $c = curl_init($send);
    curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
    //curl_setopt(... other options you want...)
    curl_setopt($c, CURLOPT_FOLLOWLOCATION, true);
    //curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
    $sended = curl_exec($c);
    if (curl_error($c)) {
        die(curl_error($c));
    }
    // Get the status code
    $status = curl_getinfo($c, CURLINFO_HTTP_CODE);
    curl_close($c);
    $decodeData = json_decode($sended, true);
    $id_message = $decodeData['result']['message_id'];
    print $sended;
    return $id_message;
}



function connectd()
{
    include("asl.php");
    $conn = new PDO("mysql:host=$servername;dbname=$mydb", $username, $password, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8mb4"));
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    return $conn;
}
$conn = connectd();



$a_chid = $_GET["chid"];

$MerchantID = 'e4e0fbec-9b29-4cda-871b-4f3db888fe76';








$Amount = 100000;






$Authority = $_GET['Authority'];

if ($_GET['Status'] == 'OK') {


    $zara["encoding"] = "UTF-8";
    $client = new SoapClient('https://www.zarinpal.com/pg/services/WebGate/wsdl', $zara);


    $zara2["MerchantID"] = $MerchantID;
    $zara2["Authority"] = $Authority;
    $zara2["Amount"] = $Amount;

    $result = $client->PaymentVerification($zara2);

    if ($result->Status == 100) {
        $refid = $result->RefID;
        $nowtime = time();

        $sql = "update data set status=\"done\" ,ref_id=\"$refid\" where id='" . $a_chid . "' ";
        $conn->exec($sql);





        sendmessage(urlencode("
✅پرداخت شما با موفقیت انجام شد و رزرو نهایی شما ثبت گردید:
طبق آلارم انتخاب شده با شما هماهنگی های لازم صورت خواهد گرفت.

با تشکر🌸🌷
مجموعه هنری برادران عظیمی

کد پیگیری : $refid


"), $a_chid, '');



       // redirect("https://telegram.me/AzimiBro_Bot");
    } else {
        var_dump($result);

        sendmessage(urlencode("
خطا در پرداخت
 "), $a_chid, "");


        //redirect("https://telegram.me/AzimiBro_Bot");
    }
}
