> ## 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.

# Get Cancel Reasons

> Retrieve list of order cancellation reasons

## Overview

Returns the list of available cancellation reasons that can be used when canceling orders.

## 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="array">
  Array of cancellation reason objects

  <Expandable title="Cancel Reason Object">
    <ResponseField name="id" type="integer">
      Unique reason ID (1-8)
    </ResponseField>

    <ResponseField name="reason" type="string">
      Description of the cancellation reason (in Turkish)
    </ResponseField>
  </Expandable>
</ResponseField>

## Examples

<CodeGroup>
  ```bash cURL theme={null}
  curl -X GET https://www.xn--dkkango-n2a.com/api/integrations/orders/cancel-reasons \
    -H 'Access-Token: your-access-token'
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch(
    'https://www.xn--dkkango-n2a.com/api/integrations/orders/cancel-reasons',
    {
      headers: {
        'Access-Token': 'your-access-token'
      }
    }
  );

  const data = await response.json();
  console.log('Cancel reasons:', data.data);
  ```

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

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

  data = response.json()
  print('Cancel reasons:', data['data'])
  ```

  ```php PHP theme={null}
  <?php
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, 'https://www.xn--dkkango-n2a.com/api/integrations/orders/cancel-reasons');
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_HTTPHEADER, array(
      'Access-Token: your-access-token'
  ));
  $response = curl_exec($ch);
  curl_close($ch);

  $data = json_decode($response, true);
  print_r($data['data']);
  ?>
  ```
</CodeGroup>

## Success Response (200)

```json theme={null}
{
  "status": true,
  "data": [
    {
      "id": 1,
      "reason": "Ürün tükendi"
    },
    {
      "id": 2,
      "reason": "Adres bulunamıyor"
    },
    {
      "id": 3,
      "reason": "Yoğunluk nedeniyle"
    },
    {
      "id": 4,
      "reason": "Müşteri iptal etti"
    },
    {
      "id": 5,
      "reason": "Teknik sorun"
    },
    {
      "id": 6,
      "reason": "Çok uzak teslimat adresi"
    },
    {
      "id": 7,
      "reason": "Ödeme problemi"
    },
    {
      "id": 8,
      "reason": "Diğer"
    }
  ]
}
```

## Error Response (401)

```json theme={null}
{
  "status": false,
  "error": "yetkisiz erişim"
}
```

## Cancel Reasons Reference

| ID | Reason (Turkish)         | English Translation      | When to Use                 |
| -- | ------------------------ | ------------------------ | --------------------------- |
| 1  | Ürün tükendi             | Product out of stock     | Ingredient unavailable      |
| 2  | Adres bulunamıyor        | Address not found        | Invalid/unclear address     |
| 3  | Yoğunluk nedeniyle       | Due to congestion        | Restaurant too busy         |
| 4  | Müşteri iptal etti       | Customer canceled        | Customer requested          |
| 5  | Teknik sorun             | Technical issue          | System/equipment failure    |
| 6  | Çok uzak teslimat adresi | Delivery address too far | Outside service area        |
| 7  | Ödeme problemi           | Payment problem          | Payment verification failed |
| 8  | Diğer                    | Other                    | Any other reason            |

## Use Cases

<AccordionGroup>
  <Accordion title="Build Cancellation UI">
    Display reasons in dropdown menu for staff.

    ```javascript theme={null}
    async function buildCancelDialog() {
      const reasons = await getCancelReasons();
      
      const dropdown = reasons.map(r => `
        <option value="${r.id}">${r.reason}</option>
      `).join('');
      
      return `
        <select id="cancelReason">
          ${dropdown}
        </select>
      `;
    }
    ```
  </Accordion>

  <Accordion title="Initialize POS">
    Cache reasons when POS starts.

    ```javascript theme={null}
    async function initializePOS() {
      const reasons = await getCancelReasons();
      
      // Store in local cache
      localStorage.setItem('cancelReasons', 
        JSON.stringify(reasons));
      
      console.log('Cancel reasons cached');
    }
    ```
  </Accordion>

  <Accordion title="Validate Reason ID">
    Ensure valid reason before canceling.

    ```javascript theme={null}
    function validateCancelReason(reasonId) {
      const reasons = getCachedReasons();
      const validIds = reasons.map(r => r.id);
      
      if (!validIds.includes(reasonId)) {
        throw new Error(`Invalid reason_id: ${reasonId}`);
      }
      
      return true;
    }
    ```
  </Accordion>

  <Accordion title="Reason Lookup">
    Get reason text by ID.

    ```javascript theme={null}
    function getReasonText(reasonId) {
      const reasons = getCachedReasons();
      const reason = reasons.find(r => r.id === reasonId);
      
      return reason ? reason.reason : 'Unknown';
    }

    // Usage
    console.log(getReasonText(3)); // "Yoğunluk nedeniyle"
    ```
  </Accordion>
</AccordionGroup>

## Integration Example

```javascript theme={null}
class CancelOrderDialog {
  async show(order) {
    // 1. Fetch reasons
    const reasons = await this.getCancelReasons();
    
    // 2. Show dialog with reasons
    const selectedReasonId = await this.showDialog(order, reasons);
    
    if (selectedReasonId) {
      // 3. Validate
      this.validateReason(selectedReasonId, reasons);
      
      // 4. Cancel order
      await this.cancelOrder(order.payment_key, selectedReasonId);
      
      // 5. Log cancellation
      await this.logCancellation({
        orderId: order.id,
        reasonId: selectedReasonId,
        reasonText: this.getReasonText(selectedReasonId, reasons),
        timestamp: new Date(),
        user: currentUser.id
      });
      
      // 6. Notify
      showSuccessMessage('Order canceled successfully');
    }
  }
  
  async showDialog(order, reasons) {
    return new Promise((resolve) => {
      const dialog = createDialog({
        title: `Cancel Order ${order.id}?`,
        content: `
          <p>Select cancellation reason:</p>
          <select id="reason-select">
            ${reasons.map(r => 
              `<option value="${r.id}">${r.reason}</option>`
            ).join('')}
          </select>
        `,
        buttons: [
          {
            text: 'Cancel Order',
            onClick: () => {
              const reasonId = document.getElementById('reason-select').value;
              resolve(parseInt(reasonId));
            }
          },
          {
            text: 'Keep Order',
            onClick: () => resolve(null)
          }
        ]
      });
      
      dialog.show();
    });
  }
}
```

## Caching Strategy

<Note>
  Cancel reasons rarely change. Cache them locally to improve performance.
</Note>

```javascript theme={null}
class CancelReasonsCache {
  constructor() {
    this.reasons = null;
    this.lastFetch = null;
    this.cacheDuration = 24 * 60 * 60 * 1000; // 24 hours
  }
  
  async getReasons() {
    const now = Date.now();
    
    // Return cached if recent
    if (this.reasons && (now - this.lastFetch) < this.cacheDuration) {
      return this.reasons;
    }
    
    // Fetch fresh
    const response = await fetch('/orders/cancel-reasons');
    const data = await response.json();
    this.reasons = data.data;
    this.lastFetch = now;
    
    return this.reasons;
  }
  
  invalidate() {
    this.reasons = null;
    this.lastFetch = null;
  }
  
  getById(id) {
    return this.reasons?.find(r => r.id === id);
  }
  
  getText(id) {
    return this.getById(id)?.reason || 'Unknown';
  }
}

// Usage
const reasonsCache = new CancelReasonsCache();

// Get all reasons
const reasons = await reasonsCache.getReasons();

// Get specific reason text
const reason = reasonsCache.getText(3); // "Yoğunluk nedeniyle"
```

## Best Practices

<Tabs>
  <Tab title="Always Fetch First">
    ```javascript theme={null}
    // ✅ Good: Fetch reasons before showing dialog
    async function cancelOrder(order) {
      const reasons = await getCancelReasons();
      const reasonId = await showCancelDialog(order, reasons);
      await cancelOrder(order.payment_key, reasonId);
    }
    ```
  </Tab>

  <Tab title="Cache Locally">
    ```javascript theme={null}
    // ✅ Good: Cache for performance
    const cachedReasons = await reasonsCache.getReasons();

    // Use cached data
    showCancelDialog(order, cachedReasons);
    ```
  </Tab>

  <Tab title="Validate Before Cancel">
    ```javascript theme={null}
    // ✅ Good: Validate reason ID
    function validateAndCancel(order, reasonId) {
      if (reasonId < 1 || reasonId > 8) {
        throw new Error('Invalid reason_id');
      }
      
      return cancelOrder(order.payment_key, reasonId);
    }
    ```
  </Tab>
</Tabs>

## Related Endpoints

<CardGroup cols={2}>
  <Card title="Cancel Order" icon="xmark" href="/api-reference/orders/cancel">
    Use these reasons to cancel orders
  </Card>

  <Card title="Get Variables" icon="sliders" href="/api-reference/orders/variables">
    Another variables endpoint
  </Card>
</CardGroup>
