cancel-order-controller.php
function getPercentOfNumber($number, $percent){
return ($percent / 100) * $number;
}
$connection = mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
$connection->set_charset("utf8");
if (!$connection) {
die("Connection failed: " . mysqli_connect_error());
}
$order_id = $_POST['order_id'];
$sql = "SELECT *, HOUR(TIMEDIFF(pickupdate , NOW())) AS diff FROM orders WHERE id = '$order_id'";
$check_query = mysqli_query($connection,$sql);
$row = mysqli_fetch_array($check_query);
if( $row >= 1 ) {
if($row['diff'] > 24){
// if pickup date more 24h
$online_payment = $row['online_payment'] * 100;
$driver_payment = $row['driver_payment'] * 100;
// if online payment = 100%
if($driver_payment == 0){
if($online_payment >= 500 && $online_payment <= 2499){
$amount = $online_payment - 100;
} else {
$amount = getPercentOfNumber($online_payment, 3);
}
} else{
if($online_payment <= 100 ){
$amount = 0;
} else if($online_payment >= 101 && $online_payment <= 2499){
$amount = $online_payment - 100;
} else {
$amount = getPercentOfNumber($online_payment, 3);
}
}
// $refund = \Stripe\Refund::create([
// 'payment_intent' => $row['stripe_pi'],
// 'amount' => $amount,
// 'reason' => 'Cancel order before 24h'
// ]);
$out = array(
'id' => $row['stripe_pi'],
'diff' => $row['diff'],
'msg' => 'More 24h - you get '.$amount.'€',
'refund' => $refund
);
echo json_encode(['code'=>200, 'msg'=>$out]);
} else if($row['diff'] < 24 && $row['diff'] > 12) {
// if pickuptime more 12h - refund 85% if payment online 100% and 0% if payment partial
// $refund = \Stripe\Refund::create([
// 'payment_intent' => $row['stripe_pi'],
// 'amount' => $amount,
// 'reason' => 'Cancel order before 12h'
// ]);
$out = array(
'id' => $row['stripe_pi'],
'diff' => $row['diff'],
'msg' => 'More 12h',
);
echo json_encode(['code'=>200, 'msg'=> $out]);
} else {
// You are trying to cancel a transfer less than 12 hours before the time of booking. Your transfer payment becomes 15% of the price. Our regulation states that we do not return it
$msg = 'You not get refund this time!';
echo json_encode(['code'=>404, 'msg'=>$msg]);
}
} else {
$msg = 'no DATA!';
echo json_encode(['code'=>404, 'msg'=>$msg]);
}
mysqli_close($connection); // Connection Closed.