# Checkout validation

When a user attempts to upgrade or change their subscription using the Bunny portal we call this a checkout.

In some cases you might want to check if the plan or quantity change should be allowed before letting the user proceed.

{% hint style="warning" %}
For example, you have a customer on a plan that includes 10 users and they have created 10 users on your platform. If they then tried to downgrade to a plan that only had 5 users you could use this webhook to block the change and provide a message explaning that they need to delete or deactivate some users before they can proceed with the change.
{% endhint %}

### Enabling checkout validation

To enable this webhook you will need to ensure that you have [enabled a webhook endpoint for your platform in Bunny](/developer/webhooks/webhooks.md).

Then on your platform enable the Checkout validation option.

<figure><img src="/files/DdXYIFuqH44p4eEfISKd" alt="" width="206"><figcaption></figcaption></figure>

### Checkout validation webhook payload

The payload that will be sent will contain information about the tenant on your platform that is requesting a change and the features and quantities that they will be change to.

```json
{
  "type": "CheckoutValidation",
  "payload": {
    "tenant": {
      "id": 132,
      "code": "8c665dde-69ae-4c53-990b-3d19bf71791e",
      "name": "Superdesk Inc"
    },
    "change": {
      "features": [
        {
          "code": "users",
          "name": "Users",
          "value": "",
          "quantity": 10,
          "plan": {
            "code": "enterprise",
            "name": "Enterprise"
          },
          "price_list": {
            "code": null,
            "name": "Enterprise Monthly"
          }
        },
        {
          "code": "widgets",
          "name": "Widgets",
          "value": "100",
          "quantity": 100,
          "plan": {
            "code": "enterprise",
            "name": "Enterprise"
          },
          "price_list": {
            "code": null,
            "name": "Enterprise Monthly"
          }
        }
      ]
    }
  }
}
```

If you wanted to validate the number of users you would use the Tenant code to look up the relevant tenant in your application, get a count of the users and then compare this to the number of users requested in the checkout validation payload.

### Responding to the webhook

If you opt-in to using the checkout validation webhook you must respond within 5 seconds with one of the following decisions.

#### Change approved

The user will be allowed to continue with the subscription change.

```
HTTP STATUS CODE: 200 - OK
```

No response body is required and will be ignored if provided.

#### Change denied

The user will not be able to continue and will be displayed the error message that you provide.

```
HTTP STATUS CODE: 422 - Unprocessable Content
```

The required JSON response body is an array of strings that explain why the subscription change is not possible.

{% code overflow="wrap" %}

```json
[
   "You have too many users to downgrade to this plan. Please remove some users and try again."
]
```

{% endcode %}

<figure><img src="/files/sYkiHq9hwo7KOJini5qM" alt="" width="375"><figcaption><p>The response from a denied checkout validation is displayed to the user.</p></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.bunny.com/developer/webhooks/checkout-validation.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
