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

# Cancel & Refund

> Cancel a subscription immediately and credit its most recent invoice.

Cancel a subscription **immediately** and credit the full amount of its most recent paid invoice back to your Stripe billing account balance. Designed for reseller organizations whose end-customer's payment failed after our subscription had already renewed.

<Warning>
  This cancels the subscription immediately (not at period end) and queues the proxies for deletion right away. The order is marked expired.
</Warning>

## Requirements

* **Organization API key only** — user-scoped keys receive **403**
* The `cancel_refund` feature must be enabled for your organization (contact support)
* Must be called within **3 days (72 hours)** of the most recent invoice payment
* The order must be active or cancelled (not expired), and **not** a crypto subscription

## Effects

When successful:

1. The order is marked **expired**
2. The Stripe subscription is cancelled **immediately** (not at period end)
3. The invoice amount is credited to the Stripe customer the order was billed to
4. The proxies are queued for deletion right away

## Request

### Headers

| Header          | Value                   | Required |
| --------------- | ----------------------- | -------- |
| `Authorization` | `Bearer {your_api_key}` | Yes      |

### Path Parameters

<ParamField path="subscription_id" type="string" required>
  The subscription ID from order creation.
</ParamField>

<ParamField path="product_id" type="string" required>
  The product ID (e.g., `"captcha"`).
</ParamField>

### Example Request

```bash theme={null}
curl -X POST "https://dashboard.statproxies.com/api/v2/order/cancel-refund/sub_1RqJP3JB4G9i6PKHDwmKPJOb/captcha" \
  -H "Authorization: Bearer {your_api_key}"
```

## Response

### Success Response

```json theme={null}
{
  "response": "success",
  "message": "Subscription cancelled and account credited",
  "details": {
    "order_id": "sub_1rqjp3jb4g9i6pkhdwmkpjob",
    "subscription_id": "sub_1RqJP3JB4G9i6PKHDwmKPJOb",
    "credit_amount": 25.5,
    "credit_amount_cents": 2550,
    "invoice_id": "in_1RqJP3JB4G9i6PKHAbCdEfGh",
    "hours_since_renewal": 5.25
  }
}
```

### Response Fields

<ResponseField name="response" type="string">
  Status of the request.
</ResponseField>

<ResponseField name="message" type="string">
  Human-readable result message.
</ResponseField>

<ResponseField name="details.order_id" type="string">
  The order ID that was processed.
</ResponseField>

<ResponseField name="details.subscription_id" type="string">
  The Stripe subscription that was cancelled.
</ResponseField>

<ResponseField name="details.credit_amount" type="number">
  Amount credited, in dollars.
</ResponseField>

<ResponseField name="details.credit_amount_cents" type="integer">
  Amount credited, in cents.
</ResponseField>

<ResponseField name="details.invoice_id" type="string">
  The Stripe invoice that was credited.
</ResponseField>

<ResponseField name="details.hours_since_renewal" type="number">
  Hours between the invoice payment and this request.
</ResponseField>

### Error Responses

#### 403 Forbidden - Not an Organization Key

```json theme={null}
{
  "response": "error",
  "message": "This endpoint is only available for organization API keys"
}
```

#### 403 Forbidden - Feature Not Enabled

```json theme={null}
{
  "response": "error",
  "message": "Post-renewal cancellation feature is not enabled for your organization. Contact support to enable this feature."
}
```

#### 400 Bad Request - No Billing Account

```json theme={null}
{
  "response": "error",
  "message": "Organization does not have a billing account configured. Contact support."
}
```

#### 400 Bad Request - Order Not Processable

```json theme={null}
{
  "response": "error",
  "message": "Order cannot be processed (current status: expired)"
}
```

#### 400 Bad Request - Crypto Subscription

```json theme={null}
{
  "response": "error",
  "message": "This endpoint does not support crypto subscriptions. Contact support for manual processing."
}
```

#### 400 Bad Request - No Paid Invoices

```json theme={null}
{
  "response": "error",
  "message": "No paid invoices found for this subscription"
}
```

#### 400 Bad Request - Refund Window Passed

```json theme={null}
{
  "response": "error",
  "message": "Refund window has passed. The most recent payment was 5 day(s) ago. Credits are only available within 3 days of renewal."
}
```

#### 404 Not Found

```json theme={null}
{
  "response": "error",
  "message": "Order not found"
}
```

#### 409 Conflict - Already Processed

```json theme={null}
{
  "response": "error",
  "message": "This order has already been processed for cancellation"
}
```

#### 500 Internal Server Error

```json theme={null}
{
  "response": "error",
  "message": "Internal server error"
}
```

## Related Endpoints

<CardGroup cols={2}>
  <Card title="Delete Order" icon="trash" href="/api-reference/order/delete-order">
    Schedule a cancellation at period end (no immediate refund).
  </Card>

  <Card title="List Orders" icon="list" href="/api-reference/order/list-orders">
    Check an order's current status.
  </Card>
</CardGroup>
