<?php

require('razorpay-php/Razorpay.php');
//session_start();

// Create the Razorpay Order

use Razorpay\Api\Api;

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

// We create an razorpay order using orders api
// Docs: https://docs.razorpay.com/docs/orders
//


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


$razorpayOrderId = $razorpayOrder['id'];
$razorpay_status = $razorpayOrder['status'];

//$_SESSION['razorpay_order_id'] = $razorpayOrderId;

$displayAmount = $amount = $orderData['amount'];
if($razorpay_status == 'created'){
    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 = array(
        "order_id" => $razorpayOrderId,
        "status" =>'created'   
    );


    if ($displayCurrency !== 'INR')
    {
        $data['display_currency']  = $displayCurrency;
        $data['display_amount']    = $displayAmount;
    }
}else{
    $data=  array(
        "status" =>'Failed',
        "description"=>$razorpayOrder['description']
        );
}


//print_r($data);

//$json = json_encode($data);

//require("checkout/".$checkout.".php");



?>