public function getUberAccessToken() { $client_id = $this->config->item('uber_client_id'); $client_secret = $this->config->item('uber_client_secret'); $url = "https://login.uber.com/oauth/v2/token"; $post_fields = http_build_query([ 'client_id' => $client_id, 'client_secret' => $client_secret, 'grant_type' => 'client_credentials', 'scope' => 'delivery' ]); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $response = curl_exec($ch); $result = json_decode($response, true); curl_close($ch); return isset($result['access_token']) ? $result['access_token'] : null; } public function UberDirectCreateDelivery($order_id, $order, $order_products, $resturant) { $token = $this->getUberAccessToken(); if (!$token) { return ['status' => 'failed', 'message' => 'Uber Access Token Failed']; } $customer_id = $this->config->item('uber_customer_id'); // Business/Customer ID $url = "https://api.uber.com/v1/customers/" . $customer_id . "/deliveries"; // Map items for Uber structure $manifest_items = []; foreach ($order_products as $op) { $manifest_items[] = [ "name" => $op['item_name'], "quantity" => intval($op['item_qty']), "price" => floatval($op['item_cost']) * 100 // Prices in cents ]; } $request_body = json_encode([ "external_id" => $order_id, "manifest_items" => $manifest_items, "pickup_name" => $resturant->branch_name, "pickup_address" => $resturant->address, "pickup_phone_number" => $resturant->phone, "dropoff_name" => $order->customer_name, "dropoff_address" => $order->complete_address, "dropoff_phone_number" => $order->phone, "dropoff_instructions" => $order->delivery_note, "tip_by_customer" => intval($order->real_doordash_driver_tip * 100), // reusing tip variable, to be updated later "test_mode" => true // SANDBOX MODE ]); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $request_body); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_HTTPHEADER, [ "Content-Type: application/json", "Authorization: Bearer " . $token ]); $response = curl_exec($ch); $status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); return ['response' => $response, 'status_code' => $status_code]; }