{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/pricklymails-com/json-schema/pricklymails-com-create-checkout-request-schema.json",
  "title": "CreateCheckoutRequest",
  "description": "Request body for `POST /api/billing/checkout`.",
  "x-generated": "2026-11-10",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/pricklymails-com-billing-api-openapi.yml#/components/schemas/CreateCheckoutRequest",
  "type": "object",
  "required": [
    "target",
    "success_url",
    "cancel_url"
  ],
  "properties": {
    "cancel_url": {
      "type": "string",
      "description": "URL the buyer is redirected to when they cancel the checkout."
    },
    "locale": {
      "type": [
        "string",
        "null"
      ],
      "description": "Language of the hosted checkout page and of the terms the buyer accepts there (`\"en\"` or `\"fr\"`).\nEnglish when absent."
    },
    "success_url": {
      "type": "string",
      "description": "URL the buyer is redirected to after a successful payment."
    },
    "target": {
      "$ref": "#/$defs/CheckoutTargetRequest",
      "description": "What to check out: a plan subscription or a credit top-up."
    }
  },
  "$defs": {
    "CheckoutTargetRequest": {
      "oneOf": [
        {
          "type": "object",
          "description": "Subscribe to a plan.",
          "required": [
            "plan",
            "cycle",
            "type"
          ],
          "properties": {
            "cycle": {
              "type": "string",
              "description": "Billing cycle (`\"monthly\"` or `\"yearly\"`)."
            },
            "plan": {
              "type": "string",
              "description": "Plan code (e.g. `\"starter\"`, `\"pro\"`, `\"business\"`, `\"enterprise\"`)."
            },
            "type": {
              "type": "string",
              "enum": [
                "plan"
              ]
            }
          }
        },
        {
          "type": "object",
          "description": "One-time credit top-up.",
          "required": [
            "token_quantity",
            "type"
          ],
          "properties": {
            "token_quantity": {
              "type": "integer",
              "format": "int32",
              "description": "Number of tokens to purchase.\nMust be a multiple of the top-up step, between the minimum and maximum quantities (inclusive).\n`GET /api/config` returns these values as `topup.step_tokens`, `topup.min_tokens` and `topup.max_tokens`.",
              "minimum": 0
            },
            "type": {
              "type": "string",
              "enum": [
                "top_up"
              ]
            }
          }
        }
      ],
      "description": "Checkout target from the request body."
    }
  }
}