<?php

	include("config.php");

	if(isset($_POST['wep_order_id']) && $_POST['wep_order_id']!=''){
		?>




		<meta name="viewport" content="width=device-width, initial-scale=1.0">
	  	<style type="text/css">
	  		body{
	  			background-color: #efefef;
				justify-content: center;
	  			font-family: 'arial';
				align-items: center;
	  			font-size: 15px;
	  			color: #181818;
				display: flex;
	  		}
	  		.loaderDiv{
	  			text-align: center;
	  			line-height: 20px;
	  			margin:40px auto;
	  			width: 224px;
	  		}
	  		.loaderDiv img{
				margin: 0 auto;
				display: block;
				width: 130px;
	  		}
	  		.loaderDiv .title{
	  			font-weight: bold;
	  			font-size: 16px;
	  		}
	  	</style>


		<div class="loaderDiv">
			<div class="title">Please wait...</div>
			<img src="img/loader.png">
			Leaving or reloading this page may cause the transaction to fail.
		</div>



		<?php

		$wep_order_id 				= trim($_POST['wep_order_id']);
		$_POST['payment_method'] 	= strtolower($_POST['payment_method']);

		$cart_data_after_fee 	= getCart($wep_order_id);
		$_POST['checkout_data'] = $cart_data_after_fee;
		$post_json 				= json_encode($_POST);

		$check_wep_order_id_query = mysqli_query($Conn_db,"SELECT id from api_response where wep_order_id = '".$wep_order_id."'");
		if(mysqli_num_rows($check_wep_order_id_query)>0){
			mysqli_query($Conn_db,"update `api_response` set `is_deleted`='1' where `wep_order_id`='".$wep_order_id."'");
		}

		$sql_insert	= "INSERT into api_response (wep_order_id,post_data_from_bigcommerce, created_time, payment_method) values ('".$wep_order_id."','".mysqli_real_escape_string($Conn_db,$post_json)."', '".date('Y-m-d H:i:s')."', '".$_POST['payment_method']."')";
		 mysqli_query($Conn_db,$sql_insert);
		 $api_response_id = mysqli_insert_id($Conn_db);

	}
	?>

	<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>

	<?php
	if($api_response_id>0)
	{
			$cart_data_after_fee = getCart($wep_order_id);
			$_POST['checkout_data'] = $cart_data_after_fee;
			$amount             = $_POST['checkout_data']['data']['grand_total'];
		    $currency           = $_POST['checkout_data']['data']['cart']['currency']['code'];
		    $country            = $_POST['checkout_data']['data']['billing_address']['country_code'];
		    $firstName          = $_POST['checkout_data']['data']['billing_address']['first_name'];
		    $lastName           = $_POST['checkout_data']['data']['billing_address']['last_name'];
		    $email              = $_POST['checkout_data']['data']['billing_address']['email'];
		    $address1           = $_POST['checkout_data']['data']['billing_address']['address1'];
		    $city               = $_POST['checkout_data']['data']['billing_address']['city'];
		    $postalCode         = $_POST['checkout_data']['data']['billing_address']['postal_code'];
		    $stateOrProvince    = $_POST['checkout_data']['data']['billing_address']['state_or_province'];
		switch($_POST['payment_method']){	 
	 
			   
			   case 'nabil':
			      
			      include('nabil_payment_request.php');
			    break; 
			   
				  
			  default:
				  die("Invalid payment access.");
			  break;
		  }
	}

?>