Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- // Recuperation des variables
- $date = $_POST['order_time'];
- $payment_method = $_POST['payment_method'];
- echo $details = $_POST['panel'];
- $details = json_decode($details, true);
- $id = $details['id_restau'];
- $contenu_cmd = $details['order'];
- $total_price1 = substr($_POST['total'],0,5);
- $total_price = floatval(str_replace(',', '.', $total_price1));
- $order = $_POST['order_type'];
- if(isset($_POST['adresse'])) {
- $numero = $_POST['numero'];
- $adresse = $_POST['adresse'];
- $ville = $_POST['ville'];
- $codepostal = $_POST['codepostal'];
- $codeentre = $_POST['codeentre'];
- $interphone = $_POST['interphone'];
- $batiment = $_POST['batiment'];
- $escalier = $_POST['escalier'];
- $etage = $_POST['etage'];
- $numappartement = $_POST['numappartement'];
- $societe = $_POST['societe'];
- $infossupp = $_POST['infossupp'];
- }
- // Conversion en JSON et envoi
- if(isset($_SESSION['user'])) {
- // Type de commande
- switch($order) {
- case 'available_on_the_spot' : $order_type = 1; break;
- case 'available_takeaway' : $order_type = 2; break;
- case 'available_delivery': $order_type = 3; break;
- }
- // Creation du tableau de la commande
- $commande = array( "idApp"=> $id,
- "idCard"=> "",
- "order_type"=> $order_type,
- "order_ready" => $date,
- "total_price"=> $total_price,
- "guid"=> "web_".$_SESSION['user']['infos_user']['email'],
- "payment_method"=> $payment_method,
- "order" => $contenu_cmd,
- "device_type" => "web" );
- if($order_type == 3) {
- $commande["delivery_data"]["customer_name"] = $_SESSION['user']['infos_user']['first_name']." ".$_SESSION['user']['infos_user']['last_name'];
- $commande["delivery_data"]["customer_phone"] = $_SESSION['user']['infos_user']['telephone'];
- $commande["delivery_data"]["customer_address"] = array(
- "entryCode"=> $codeentre,
- "building"=> $batiment,
- "level"=> $etage,
- "stairs" => $escalier,
- "extra"=> $infossupp,
- "company"=> $societe,
- "zipcode"=> $codepostal,
- "flatNumber" => $numappartement,
- "interphone" => $interphone,
- "city" => $ville,
- "main" => $numero.", ".$adresse);
- }
- // Requete
- include('../requires/url.dist.php');
- $ACCESS_TOKEN = $_SESSION['user']['infos_connexion']['access_token'];
- $REFRESH_TOKEN = $_SESSION['user']['infos_connexion']['refresh_token'];
- $url = $urlWebService.$urlAddCommande.$ACCESS_TOKEN ;
- echo $data = json_encode($commande);
- $options = array(
- 'http' => array(
- 'header' => "Content-type: application/json",
- 'method' => 'POST',
- 'content' => $data,
- ),
- );
- $context = stream_context_create($options);
- $result = file_get_contents($url, false, $context);
- $result = json_decode($result, true);
- // Traitement de la reponse
- if($result['error'] == 'OK') {
- echo json_encode($result);
- //initialiser le panier
- // $tab_php = $_SESSION['infos_restaurant_php'];
- // $_SESSION['panier'][$id] = array();
- // $_SESSION['panier'][$id]['items'] = array();
- // $_SESSION['panier'][$id]['menus'] = array();
- // $_SESSION['panier'][$id]['total_price'] = 0;
- } else {
- if($result['error'] == 'invalid_grant' && $result['error_description'] == "The access token provided has expired."){
- $infos_user_cnx = refreshToken($REFRESH_TOKEN);
- if($infos_user_cnx != false){
- $_SESSION['user']['infos_connexion'] = $infos_user_cnx;
- $url = $urlWebService.$urlAddCommande.$_SESSION['user']['infos_connexion']['access_token'];
- $context = stream_context_create($options);
- $result = file_get_contents($url, false, $context);
- $result = json_decode($result, true);
- if($result['error']== 'OK'){
- echo 'OK';
- $idOrder = $result['data']->idOrder;
- $_SESSION['idOrder'] = $idOrder;
- //initialiser le panier
- // $tab_php = $_SESSION['infos_restaurant_php'];
- // $_SESSION['panier'][$id] = array();
- // $_SESSION['panier'][$id]['items'] = array();
- // $_SESSION['panier'][$id]['menus'] = array();
- // $_SESSION['panier'][$id]['total_price'] = 0;
- }
- }
- echo $result['error'];
- } else {
- echo $result['error']; // Switch dans le JS
- }
- }
- } else {
- echo '<div class="alert alert-warning text-center"><p><i class="fa fa-exclamation-triangle fa-2x"></i></p><p>Connectez-vous avant de commander !</p></div>';
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement