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

# Cancel Refund

> Cancel a pending or processing refund

<Note>
  This endpoint cancels a refund that is in pending or processing status. Once a refund is completed, it cannot be cancelled.
</Note>

## Authentication

This endpoint requires a valid API key with `refunds:write` permissions.

```bash theme={null}
Authorization: Bearer YOUR_API_KEY
```

## Path Parameters

<ParamField path="id" type="string" required>
  The unique identifier of the refund to cancel
</ParamField>

## Request Body

<ParamField body="reason" type="string">
  Reason for cancellation
</ParamField>

<ParamField body="notify_customer" type="boolean">
  Whether to notify customer of cancellation
</ParamField>

### Response

Returns the cancelled refund object.

<RequestExample>
  ```bash cURL theme={null}
  curl --location --request POST 'https://api.stateset.com/v1/refunds/refund_0901f083-aa1c-43c5-af5c-0a9d2fc64e30/cancel' \
  --header 'Content-Type: application/json' \
  --header 'Authorization: Bearer YOUR_API_KEY' \
  --data-raw '{
      "reason": "Customer requested to keep the product",
      "notify_customer": true
  }'
  ```

  ```javascript Node.js theme={null}
  const refund = await stateset.refunds.cancel(
    'refund_0901f083-aa1c-43c5-af5c-0a9d2fc64e30',
    {
      reason: "Customer requested to keep the product",
      notify_customer: true
    }
  );
  ```

  ```python Python theme={null}
  refund = stateset.refunds.cancel(
    'refund_0901f083-aa1c-43c5-af5c-0a9d2fc64e30',
    reason="Customer requested to keep the product",
    notify_customer=True
  )
  ```
</RequestExample>

<ResponseExample>
  ```json Response theme={null}
  {
    "id": "refund_0901f083-aa1c-43c5-af5c-0a9d2fc64e30",
    "object": "refund",
    "order_id": "order_123456",
    "customer_id": "cust_abc123",
    "type": "partial",
    "status": "cancelled",
    "previous_status": "processing",
    "reason": "product_damaged",
    "reason_details": "Item arrived with scratches on the surface",
    "cancellation": {
      "reason": "Customer requested to keep the product",
      "cancelled_at": "2024-06-21T10:00:00Z",
      "cancelled_by": "user_456"
    },
    "amounts": {
      "subtotal": 4999,
      "tax": 450,
      "shipping": 0,
      "total": 5449,
      "currency": "USD"
    },
    "timeline": [
      {
        "status": "created",
        "timestamp": "2024-01-20T13:30:00Z",
        "actor": "customer"
      },
      {
        "status": "approved",
        "timestamp": "2024-01-20T13:30:01Z",
        "actor": "system"
      },
      {
        "status": "processing",
        "timestamp": "2024-01-20T13:30:02Z",
        "actor": "system"
      },
      {
        "status": "cancelled",
        "timestamp": "2024-06-21T10:00:00Z",
        "actor": "user_456",
        "note": "Customer requested to keep the product"
      }
    ],
    "updated_at": "2024-06-21T10:00:00Z",
    "notifications": {
      "customer_notified": true,
      "notification_sent_at": "2024-06-21T10:00:05Z"
    }
  }
  ```
</ResponseExample>
