> ## Documentation Index
> Fetch the complete documentation index at: https://dkkangoyazlmteknolojiticareta.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Mark Order On The Way

> Update order status to out for delivery

## Overview

Updates an order status from `CONFIRMED` to `IN_DELIVERY`, indicating that the order is on its way to the customer.

<Note>
  This endpoint is **only valid for restaurant couriers** (`courier_type: "restaurant"`). Platform couriers are managed externally.
</Note>

## Path Parameters

<ParamField path="order_id" type="string" required>
  Order's `payment_key` (UUID)
</ParamField>

## Headers

<ParamField header="Access-Token" type="string" required>
  Your API access token
</ParamField>

## Response

<ResponseField name="status" type="boolean">
  `true` if successful
</ResponseField>

<ResponseField name="data" type="string">
  `"OK"` on success
</ResponseField>

## Examples

<CodeGroup>
  ```bash cURL theme={null}
  curl -X PUT https://www.xn--dkkango-n2a.com/api/integrations/orders/ontheway/3e9caf87-5cb7-4c4e-adcb-fc2ec54cf24e \
    -H 'Access-Token: your-access-token'
  ```

  ```javascript JavaScript theme={null}
  const paymentKey = '3e9caf87-5cb7-4c4e-adcb-fc2ec54cf24e';

  const response = await fetch(
    `https://www.xn--dkkango-n2a.com/api/integrations/orders/ontheway/${paymentKey}`,
    {
      method: 'PUT',
      headers: {
        'Access-Token': 'your-access-token'
      }
    }
  );

  const data = await response.json();
  // Order is now IN_DELIVERY
  ```

  ```python Python theme={null}
  import requests

  payment_key = '3e9caf87-5cb7-4c4e-adcb-fc2ec54cf24e'

  response = requests.put(
      f'https://www.xn--dkkango-n2a.com/api/integrations/orders/ontheway/{payment_key}',
      headers={'Access-Token': 'your-access-token'}
  )

  data = response.json()
  # Order is now IN_DELIVERY
  ```

  ```php PHP theme={null}
  <?php
  $paymentKey = '3e9caf87-5cb7-4c4e-adcb-fc2ec54cf24e';
  $url = "https://www.xn--dkkango-n2a.com/api/integrations/orders/ontheway/{$paymentKey}";

  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_HTTPHEADER, array(
      'Access-Token: your-access-token'
  ));
  $response = curl_exec($ch);
  curl_close($ch);
  // Order is now IN_DELIVERY
  ?>
  ```
</CodeGroup>

## Success Response (200)

```json theme={null}
{
  "status": true,
  "data": "OK"
}
```

## Error Responses

<ResponseExample>
  ```json Authentication Error (401) theme={null}
  {
    "status": false,
    "error": "yetkisiz erişim"
  }
  ```

  ```json Invalid UUID (403) theme={null}
  {
    "status": false,
    "error": "URL hatalı"
  }
  ```

  ```json Not Found (404) theme={null}
  {
    "status": false,
    "error": "sipariş bulunamadı"
  }
  ```
</ResponseExample>

## Status Transition

```
CONFIRMED (status_id: 2)
    ↓
[/orders/ontheway called]
    ↓
IN_DELIVERY (status_id: 16)
```

<Info>
  The order status changes to `IN_DELIVERY` with `status_id: 16` (Restoran Kuryeye Verildi).
</Info>

## When to Call

<Steps>
  <Step title="Order Prepared">
    Kitchen has finished preparing the order
  </Step>

  <Step title="Courier Assigned">
    A courier has been assigned and is ready to leave
  </Step>

  <Step title="Courier Pickup">
    Courier picks up the order from restaurant
  </Step>

  <Step title="Call Endpoint">
    Call `/ontheway` to update status
  </Step>

  <Step title="Customer Notified">
    Customer receives notification that order is on the way
  </Step>
</Steps>

## Courier Type Check

<Warning>
  **Important:** Only call this for restaurant-managed deliveries!
</Warning>

```javascript theme={null}
async function markOnTheWay(order) {
  // Check courier type first
  if (order.courier_type !== 'restaurant') {
    console.log('Skipping: Not restaurant courier');
    return;
  }
  
  // Call endpoint
  await updateOrderStatus(order.payment_key, 'ontheway');
  
  // Notify courier
  notifyCourier(order);
}
```

## Integration Examples

<Tabs>
  <Tab title="Manual Dispatch">
    ```javascript theme={null}
    async function handleCourierDispatch(order, courier) {
      // 1. Assign courier in POS
      await assignCourier(order.id, courier.id);
      
      // 2. Print delivery slip
      await printDeliverySlip(order, courier);
      
      // 3. Update API
      await markOnTheWay(order.payment_key);
      
      // 4. Send SMS to courier
      await sendCourierSMS(courier.phone, order.address);
      
      console.log(`✅ Order ${order.id} dispatched to ${courier.name}`);
    }
    ```
  </Tab>

  <Tab title="Automatic Dispatch">
    ```javascript theme={null}
    async function autoDispatch() {
      // Get prepared orders
      const preparedOrders = await getOrdersByStatus('CONFIRMED');
      
      for (const order of preparedOrders) {
        if (order.courier_type !== 'restaurant') continue;
        
        // Find available courier
        const courier = await findAvailableCourier();
        
        if (courier) {
          await assignCourier(order.id, courier.id);
          await markOnTheWay(order.payment_key);
          
          console.log(`Auto-dispatched order ${order.id}`);
        }
      }
    }

    // Run every 2 minutes
    setInterval(autoDispatch, 120000);
    ```
  </Tab>

  <Tab title="QR Code Scan">
    ```javascript theme={null}
    async function handleQRScan(qrCode) {
      // Parse order from QR code
      const order = await parseOrderQR(qrCode);
      
      // Verify order status
      if (order.status !== 'CONFIRMED') {
        alert('Order not ready for delivery');
        return;
      }
      
      // Mark on the way
      await markOnTheWay(order.payment_key);
      
      // Courier confirmation
      showSuccessMessage('Order marked for delivery');
    }
    ```
  </Tab>
</Tabs>

## Tracking Integration

```javascript theme={null}
class DeliveryTracker {
  async startTracking(order, courier) {
    // 1. Mark as on the way
    await markOnTheWay(order.payment_key);
    
    // 2. Start GPS tracking
    const trackingSession = await this.gps.startSession({
      orderId: order.id,
      courierId: courier.id,
      destination: order.address
    });
    
    // 3. Send tracking link to customer
    await this.sendTrackingLink(order.customer.phone, trackingSession.url);
    
    // 4. Monitor progress
    trackingSession.on('arrived', async () => {
      // Auto-complete when arrived
      await completeOrder(order.payment_key);
    });
  }
}
```

## Best Practices

<AccordionGroup>
  <Accordion title="Verify Order Ready">
    ```javascript theme={null}
    async function safeDispatch(order) {
      // Check all items prepared
      const allReady = await checkAllItemsReady(order.id);
      if (!allReady) {
        alert('Not all items are ready!');
        return false;
      }
      
      // Check packaging complete
      const packaged = await isOrderPackaged(order.id);
      if (!packaged) {
        alert('Order not packaged!');
        return false;
      }
      
      // Dispatch
      await markOnTheWay(order.payment_key);
      return true;
    }
    ```
  </Accordion>

  <Accordion title="Courier Assignment">
    Ensure courier is properly assigned before marking on the way.
  </Accordion>

  <Accordion title="Customer Communication">
    Notify customer when order is dispatched (optional, platform may handle).
  </Accordion>

  <Accordion title="Log Dispatch Time">
    ```javascript theme={null}
    async function loggedDispatch(order) {
      const dispatchTime = new Date();
      
      await markOnTheWay(order.payment_key);
      
      await database.logDispatch({
        orderId: order.id,
        dispatchTime,
        estimatedArrival: calculateETA(order.address)
      });
    }
    ```
  </Accordion>
</AccordionGroup>

## Related Endpoints

<CardGroup cols={2}>
  <Card title="Accept Order" icon="check" href="/api-reference/orders/accept">
    Previous step: Accept order
  </Card>

  <Card title="Complete Order" icon="flag-checkered" href="/api-reference/orders/complete">
    Next step: Complete delivery
  </Card>

  <Card title="Order Lifecycle" icon="route" href="/guides/order-lifecycle">
    Complete order flow
  </Card>
</CardGroup>
