<?php
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);

$checkSum  = '';
$paramList = [];
// 	print_r($_POST);
// 	exit;
$ORDER_ID   = $_POST['ORDER_ID'];
$CUST_ID    = $_POST['CUST_ID'];
$TXN_AMOUNT = $_POST['TXN_AMOUNT'];
$price      = $TXN_AMOUNT;
$contactno  = $_POST['MSISDN'];
$fname      = $_POST['name'];
$email      = $_POST['EMAIL'];




$INDUSTRY_TYPE_ID = $_POST['INDUSTRY_TYPE_ID'];
$CHANNEL_ID       = $_POST['CHANNEL_ID'];

// $paramList["CUST_ID"] = $CUST_ID;
// // Create an array having all required parameters for creating checksum.
// // $paramList["MID"] = PAYTM_MERCHANT_MID;
// $paramList["ORDER_ID"] = $ORDER_ID;
// $paramList["EMAIL"] = $_POST["EMAIL"];;
// $paramList["INDUSTRY_TYPE_ID"] = $INDUSTRY_TYPE_ID;
// $paramList["CHANNEL_ID"] = $CHANNEL_ID;
// $paramList["TXN_AMOUNT"] = $TXN_AMOUNT;
// // $paramList["WEBSITE"] = PAYTM_MERCHANT_WEBSITE;
// $paramList["MSISDN"] = $_POST["MSISDN"];
$paramList['CALLBACK_URL'] = 'https://monsoonvibespublica.com/user/payment/pgResponse.php';
$orderData                 = [
    'receipt'         => 3456,
    'amount'          => $price * 100, // 2000 rupees in paise
    'currency'        => 'INR',
    'payment_capture' => 1, // auto capture
];

$razorpayOrder = $api->order->create($orderData);

$razorpayOrderId = $razorpayOrder['id'];

$_SESSION['razorpay_order_id'] = $razorpayOrderId;

$displayAmount = $amount = $orderData['amount'];

if ($displayCurrency != 'INR') {
    $url      = "https://api.fixer.io/latest?symbols=$displayCurrency&base=INR";
    $exchange = json_decode(file_get_contents($url), true);

    $displayAmount = $exchange['rates'][$displayCurrency] * $amount / 100;
}

$data = [
    'key'         => $keyId,
    'amount'      => $amount,
    'name'        => 'Monsoon Vibes Publica',
    'description' => 'Coding for Everyone',
    'image'       => 'https://monsoonvibespublica.com/assets/image/monsoon_vibes.png',
    'prefill'     => [
    'name'    => $fname,
    'email'   => $email,
    'contact' => $contactno,
    ],
    'notes' => [
    'address'           => 'Hello World',
    'merchant_order_id' => '12312321',
    ],
    'theme' => [
    'color' => '#F37254',
    ],
    'order_id' => $razorpayOrderId,
];

if ($displayCurrency != 'INR') {
    $data['display_currency'] = $displayCurrency;
    $data['display_amount']   = $displayAmount;
}
$currency = $displayCurrency;

$json = json_encode($data);
// print_r($data);
// exit;
// order_OCiEZuoRH9Dt9R
// order_OCiFseedFERKP0
?>
<html>
<head>
<title>Merchant Check Out Page</title>
</head>
<body>
	
	<form action="pgresponse.php" method="POST">
  <script src="https://code.jquery.com/jquery-3.5.0.js"></script>


  <script
    src="https://checkout.razorpay.com/v1/checkout.js"
    data-key="<?php echo $data['key']?>"
    data-amount="<?php echo $data['amount']?>"
    data-currency="INR"
    data-name="<?php echo $data['name']?>"
    data-image="<?php echo $data['image']?>"
    data-description="<?php echo $data['description']?>"
    data-prefill.name="<?php echo $data['prefill']['name']?>"
    data-prefill.email="<?php echo $data['prefill']['email']?>"
    data-prefill.contact="<?php echo $data['prefill']['contact']?>"
    data-notes.shopping_order_id="3456"
    data-order_id="<?php echo $data['order_id']?>"
    <?php if ($displayCurrency != 'INR') { ?> data-display_amount="<?php echo $data['display_amount']?>" <?php } ?>
    <?php if ($displayCurrency != 'INR') { ?> data-display_currency="<?php echo $data['display_currency']?>" <?php } ?>
  >

  </script>
  <!-- Any extra fields to be submitted with the form but not sent to Razorpay -->
  <input type="hidden" name="shopping_order_id" value="3456">
  <input type="hidden" name="ORDER_ID" value="<?php echo $ORDER_ID ;?>">
  <input type="hidden" name="TXN_AMOUNT" value="<?php echo $TXN_AMOUNT;  ?>">
  <input type="hidden" name="currency" value="<?php echo $currency;  ?>">
  <!-- <input type="hidden" name="	" value="<?php ?>">
  <input type="hidden" name="ORDER_ID" value="<?php ?>">
  <input type="hidden" name="ORDER_ID" value="<?php ?>"> -->
</form>
<style>

.razorpay-payment-button { display: none; }

</style>

<script type="text/javascript">

$(document).ready(function(){

$('.razorpay-payment-button').click();

});

</script>

	</body>
</html>