# CancelChannelOrder

## Permission Scope

marketplace

## Overview

CancelChannelOrder records channel-originated cancellation before internal execution progresses too far. It preserves external traceability and prevents stale conversion jobs from materializing cancelled demand.

## Business Rules

- Pending or exceptional channel orders may be cancelled by the originating channel.
- Cancellation must block later stale conversion attempts for the same channel order.
- If an internal sales order already exists, downstream sales cancellation policy must be followed separately.

## Process Flow

```mermaid
flowchart TD
    A[Receive channel cancellation] --> B[Load channel order]
    B --> C{Cancellation allowed?}
    C -->|No| D[Return INVALID_CHANNEL_ORDER_STATUS]
    C -->|Yes| E[Set status to CANCELLED_BY_CHANNEL]
    E --> F[Return cancelled channel order]
```

## External Dependencies

- None

## Error Scenarios

- **CHANNEL_ORDER_NOT_FOUND**: Referenced channel order does not exist.
- **INVALID_CHANNEL_ORDER_STATUS**: Channel order status does not allow this operation

## Test Cases

- cancels a pending channel order
- cancels an exceptional channel order before replay
- prevents stale conversion after cancellation
