<?php
$protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 'https://' : 'http://';
 $txnAmount = $_GET['amount'];
$txnNote = $_GET['Player_ID'];
$redirecturl = $protocol . $_SERVER['HTTP_HOST'] . "/success.php";
$yyy=date("Ymdhis") ;
$order_idll="Sdev".$yyy;

// URL of the PHP page
$url = $protocol . $_SERVER['HTTP_HOST'] . '/api/create-order';



// Data to be sent in the POST request
$data = array(
    'customer_mobile' => '9883535597',
    'user_token' => '64f06fc9c26552c69d7ed4eba3459e1e',
    'amount' => "$txnAmount",
    'order_id' => "$txnNote".time(),
    'redirect_url' => $redirecturl,
    'remark1' => $txnNote,
    'remark2' => 'test2',
);

// Initialize cURL session
$ch = curl_init();

// Set cURL options
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

// Execute cURL session and store the response
$response = curl_exec($ch);

// Check for cURL errors
if (curl_errno($ch)) {
    echo 'cURL Error: ' . curl_error($ch);
}

// Close cURL session
curl_close($ch);


// Decode the JSON response
$jsonResponse = json_decode($response, true);

// Check if decoding was successful
if ($jsonResponse !== null) {
    
    
    // Redirect the user to the payment URL
    $paymentUrl = $jsonResponse['result']['payment_url'];
    header('Location: ' . $paymentUrl);
    exit;
    
} else {
    echo 'Failed to decode JSON response.';
}
?>