<?php
session_start();
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST');
header("Access-Control-Allow-Headers: X-Requested-With");
header('Content-Type: application/json; charset=utf-8');


if(isset($_POST['user_id']) &&  isset($_POST['email']) && isset($_POST['amount']) && isset($_POST['ref']) && isset($_POST['app_id']) && isset($_POST['fee_type']))
{
    
include 'config.php';
$user_id=$_POST['user_id'];
$app_id=$_POST['app_id'];
$amount=$_POST['amount'];
$ref=$_POST['ref'];
$fee_type=$_POST['fee_type'];
$email=$_POST['email'];

$user_id=stripslashes($user_id);
$user_id=mysqli_escape_string($con, $user_id);

$auth=stripslashes($auth);
$auth=mysqli_escape_string($con, $auth);


$app_id=stripslashes($app_id);
$app_id=mysqli_escape_string($con, $app_id);



$ref=stripslashes($ref);
$ref=mysqli_escape_string($con, $ref);

$amount=stripslashes($amount);
$amount=mysqli_escape_string($con, $amount);

$fee_type=stripslashes($fee_type);
$fee_type=mysqli_escape_string($con, $fee_type);

$email=stripslashes($email);
$email=mysqli_escape_string($con, $email);


$date_t = date("d-m-Y");
$date_t2 = date("m/d/Y");
$date_t2 = strtotime($date_t);



           $sql="SELECT * FROM fees where fee_type = '$fee_type'";
           $resulta = mysqli_query($con,$sql) or die(mysqli_error($con));
           $rowa = mysqli_fetch_array($resulta);
           $amountx = $rowa['amount'];
       
       if($amountx == $amount)
       {
       
  $sqlz=$con->query("INSERT INTO reg_trans  (user_id, reference, app_id, fee_type, amount, email, status, date_t) 
      VALUES ('$user_id', '$ref', '$app_id', '$fee_type', '$amount',  '$email', 'Pending', '$date_t')") or die("Error: ".mysqli_error($con));

if($sqlz)
{
$status = true;
$suc = "Success";
}
}
else
{
$status = false;
$suc = "Invalid Amount";
}

$output = array('status' => $status, 'success'=>$suc, 'user_id' => $user_id, 'app_id'=> $app_id, 'ref'=> $ref, 'amount'=> $amount, 'fee_type'=> $fee_type);
echo json_encode($output); //output JSON data

}
else
{
$status = false;
$suc = "Incomplete Parameters";

$output = array('status' => $status, 'success'=>$suc);
echo json_encode($output); //output JSON data

}

?>