6 changed files with 133 additions and 23 deletions
@ -0,0 +1,50 @@ |
|||||
|
<?php |
||||
|
session_start(); |
||||
|
include_once './config.php'; |
||||
|
include_once './database.php'; |
||||
|
|
||||
|
header("Access-Control-Allow-Origin: *"); |
||||
|
header("Content-Type: application/json; charset=UTF-8"); |
||||
|
header("Access-Control-Allow-Methods: POST"); |
||||
|
header("Access-Control-Max-Age: 3600"); |
||||
|
header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With"); |
||||
|
|
||||
|
$databaseService = new DatabaseService(); |
||||
|
$conn = $databaseService->getConnection(); |
||||
|
|
||||
|
$data = json_decode(file_get_contents("php://input")); |
||||
|
$shipping = array( |
||||
|
"full_name" => $data->profile->first_name." ".$data->profile->last_name, |
||||
|
"address" => $data->address, |
||||
|
"city" => $data->city, |
||||
|
"zip_code" => $data->zip_code, |
||||
|
"province" => $data->province |
||||
|
); |
||||
|
|
||||
|
$query = "INSERT INTO `orders` |
||||
|
(`id`, `uid`, `date`, `items`, `total`, `status`, `token`, `shipping`, `traking`) |
||||
|
VALUES (NULL, ".intval($data->uid).", NOW(), '".json_encode($data->cart)."', ".floatval($data->total).", |
||||
|
'PAID', |
||||
|
'".trim($data->token)."', |
||||
|
'".json_encode($shipping)."', '')"; |
||||
|
|
||||
|
$stmt = $conn->prepare($query); |
||||
|
|
||||
|
if($stmt->execute()) { |
||||
|
http_response_code(200); |
||||
|
echo json_encode( |
||||
|
array( |
||||
|
"status" => 200, |
||||
|
"id" => $conn->lastInsertId() |
||||
|
)); |
||||
|
} else { |
||||
|
http_response_code(400); |
||||
|
echo json_encode( |
||||
|
array( |
||||
|
"status" => 400, |
||||
|
"message" => "Error inserting new order" |
||||
|
)); |
||||
|
} |
||||
|
|
||||
|
?> |
||||
|
|
Loading…
Reference in new issue