<?php
/*
برای اولین بار اپن شد در کانال @IRA_Team

ذکر منبع اجباری منبع سورس کد های مختلف @IRA_Team
*/
// ------- Include -------
include '../../config.php';
// ------- Get -------
function postToZibal($path, $parameters)
{
    $url = 'https://gateway.zibal.ir/v1/' . $path;
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($parameters));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $response  = curl_exec($ch);
    curl_close($ch);
    return json_decode($response);
}
$user = $_GET['id'];
$amount = $_GET['amount'];
$sqlCdd    = "SELECT `id` FROM `user` WHERE `id`=$user";
$resultCdd = mysqli_query($connect, $sqlCdd);

$resCdd = mysqli_fetch_assoc($resultCdd);
if (isset($resCdd)) {
    $parameters = array(
        "merchant" => $merichentziball, //required
        "callbackUrl" => "$web/pay/ziball/back.php?amount=$amount&id=$user", //required
        "amount" => $amount, //required

        "orderId" => time(), //optional
        "mobile" => "09120000000", //optional for mpg
    );

    $response = postToZibal('request', $parameters);
    if ($response->result == 100) {
        $startGateWayUrl = "https://gateway.zibal.ir/start/" . $response->trackId;
        header('location: ' . $startGateWayUrl);
    } else {
        echo "errorCode: " . $response->result . "<br>";
        echo "message: " . $response->message;
    }
}
/*
برای اولین بار اپن شد در کانال @IRA_Team

ذکر منبع اجباری منبع سورس کد های مختلف @IRA_Team
*/