# Cancel Payment Request - Expire a Pending Checkout via API

> Cancel a pending hosted checkout for a Telegram or Discord subscription bot before it is paid.

Source: https://docs.botsubscription.com/api/payment-requests/cancel/

Cancel an existing hosted checkout that is still pending. BotSubscription expires the provider session first, then updates the local payment request—so a payment that completes at the same moment always wins over the cancellation.

<ApiEndpoint method="POST" endpoint="/v2/projects/{project_id}/payment-requests/{payment_request_id}/cancel" />

<ApiAuthorization type="Bearer API Key" />

The response includes the [payment-operation fields](https://docs.botsubscription.com/api/payment-requests/create/#handle-the-returned-status). A terminal response omits the live checkout URL; use [Get Payment Request](https://docs.botsubscription.com/api/payment-requests/get/) for customer identity and stored timestamps.

**API key scope:** `payment-requests:update` (required for restricted keys).

The request body and query string must both be empty.

An open payable checkout can block a new automatic trial with `409 SUBSCRIPTION_IN_PROGRESS` from [Create Payment Request](https://docs.botsubscription.com/api/payment-requests/create/#open-checkouts-and-retries). Use this endpoint with its saved ID, or wait for provider expiry. Cancellation is provider-dependent: a `409` means it could not be safely confirmed, so do not assume the checkout is cancelled or that a new trial can start.

<ApiSection title="Path Parameters">
  <ApiParameter name="project_id" type="string" required description="The unique identifier of the project." />
  <ApiParameter name="payment_request_id" type="string" required description="The unique identifier of the payment request to cancel (UUID)." />
</ApiSection>

<ApiSamplePane>

<ApiRequestSample title="Request">

```bash
curl -X POST "https://api.botsubscription.com/v2/projects/YOUR_PROJECT_ID/payment-requests/11111111-1111-1111-1111-111111111111/cancel" \
  -H "Authorization: Bearer YOUR_API_KEY"
```

```javascript
const project_id = 'YOUR_PROJECT_ID';
const payment_request_id = '11111111-1111-1111-1111-111111111111';
const response = await fetch(`https://api.botsubscription.com/v2/projects/${project_id}/payment-requests/${payment_request_id}/cancel`, {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer YOUR_API_KEY'
  }
});
const data = await response.json();
```

```python
import requests

project_id = 'YOUR_PROJECT_ID'
payment_request_id = '11111111-1111-1111-1111-111111111111'
response = requests.post(
    f'https://api.botsubscription.com/v2/projects/{project_id}/payment-requests/{payment_request_id}/cancel',
    headers={'Authorization': 'Bearer YOUR_API_KEY'}
)
data = response.json()
```

```php
$project_id = 'YOUR_PROJECT_ID';
$payment_request_id = '11111111-1111-1111-1111-111111111111';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.botsubscription.com/v2/projects/{$project_id}/payment-requests/{$payment_request_id}/cancel");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Authorization: Bearer YOUR_API_KEY']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
```

</ApiRequestSample>

<ApiResponseTabs>
  <ApiResponse status={200} description="Checkout cancelled">

```json
{
  "ok": true,
  "request_id": "11111111-1111-1111-1111-111111111111",
  "method": "POST",
  "path": "/v2/projects/11111111-1111-4111-8111-111111111111/payment-requests/11111111-1111-1111-1111-111111111111/cancel",
  "code": 200,
  "data": {
    "payment_request_id": "11111111-1111-1111-1111-111111111111",
    "request_type": "invoice",
    "amount": "1",
    "currency": "USD",
    "status": "expired",
    "provider_payment_id": "cs_test_example",
    "merchant_account_id": "22222222-2222-4222-8222-222222222222",
    "failure_reason": null,
    "payment_error_code": null,
    "provider": "stripe",
    "payment_request_data": {}
  }
}
```

  </ApiResponse>
  <ApiResponse status={409} description="Provider session could not be safely expired">

```json
{
  "ok": false,
  "request_id": "11111111-1111-1111-1111-111111111111",
  "method": "POST",
  "path": "/v2/projects/11111111-1111-4111-8111-111111111111/payment-requests/11111111-1111-1111-1111-111111111111/cancel",
  "code": 409,
  "error": {
    "error_code": "CONFLICT",
    "message": "The payment provider could not confirm the session was cancellable"
  }
}
```

  </ApiResponse>
  <ApiResponse status={404} description="Payment request not found">

```json
{
  "ok": false,
  "request_id": "11111111-1111-1111-1111-111111111111",
  "method": "POST",
  "path": "/v2/projects/11111111-1111-4111-8111-111111111111/payment-requests/11111111-1111-1111-1111-111111111111/cancel",
  "code": 404,
  "error": {
    "error_code": "NOT_FOUND",
    "message": "Payment request not found"
  }
}
```

  </ApiResponse>
  <ApiResponse status={401} description="Invalid or expired API key">

```json
{
  "ok": false,
  "request_id": "44444444-4444-4444-8444-444444444444",
  "method": "POST",
  "path": "/v2/projects/11111111-1111-4111-8111-111111111111/payment-requests/22222222-2222-4222-8222-222222222222/cancel",
  "code": 401,
  "error": {
    "message": "Invalid or expired authentication token.",
    "error_code": "UNAUTHORIZED"
  }
}
```

  </ApiResponse>
</ApiResponseTabs>

</ApiSamplePane>

If the provider returns an indeterminate result, BotSubscription responds with a retryable error rather than guessing at the outcome—retry the cancellation once the provider's state is clear.
