<?php

if (!isset($_SESSION)) {
    session_start();
}

require_once('../../lib/dbclass.php');
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: POST, GET, OPTIONS');
header('Access-Control-Max-Age: 1000');
header('Access-Control-Allow-Headers: Content-Type');


header('Pragma: no-cache');
header('Cache-Control: no-cache');
header('Expires: 0');

require('razorpay/config.php');
require('razorpay/razorpay-php/Razorpay.php');
use Razorpay\Api\Api;

$api = new Api($keyId, $keySecret);

// Generate random order ID and capture customer info
$ORDER_ID = rand(1000, 1000000);

$price = $_REQUEST['total'];

$custid = $_REQUEST['Custid'];



// Create Razorpay order data
$orderData = [
    'receipt'         => $ORDER_ID,
    'amount'          => $price * 100, // Amount in paise
    'currency'        => 'INR',
    'payment_capture' => 1, // Auto capture
    'notes'           => [
        'customer' => $_REQUEST['customer'],
        'mobile'   => $_REQUEST['mobile'],
        'App'      => sitename,
        'custid'   => $_REQUEST['Custid'],
    ],
];


$razorpayOrder   = $api->order->create($orderData);
$razorpayOrderId = $razorpayOrder['id'];



$message = 'True';
$data2   = $razorpayOrderId;

updateQuery("update tbl_transaction set orderid='$ORDER_ID' WHERE customerid=$custid");


echo json_encode(['Status' => $message, 'data' => $data2]);

return;
