{
  "openapi": "3.1.0",
  "info": {
    "title": "Payrudder API",
    "version": "v1",
    "description": "HTTP/JSON API of Payrudder: meters, usage events, customers, plans, subscriptions, invoices, payments and webhooks.\n\n- Tenant routes authenticate with `Authorization: Bearer prk_{test|live}_<prefix>_<secret>`. `prk_test_` keys act on the\n  account's sandbox tenant, `prk_live_` keys on its live tenant.\n- Field names are snake_case. Enums are strings. Per the protobuf JSON mapping, int64 values (`*_minor`, counts, sizes) are\n  rendered as JSON strings (`type: string, format: int64`) and accepted as strings or numbers. Decimal quantities and prices are strings.\n  The few objects built by hand (dashboards, overview, organization tables, the payment ledger,\n  bank-transfer receipts) send their int64 values as JSON numbers; their schemas say `type: integer, format: int64`.\n- Objects that come from protobuf messages always carry every field (they are `required` in the schema): a number is `0`, a string `\"\"`, a list `[]`,\n  and a timestamp or nested object that is not set is `null` (marked `nullable`). A field that can be left out of an object is not in `required`.\n- Lists that take `page_size` and `page_token` answer `next_page_token` (an empty string on the last page). A list without `page_token` returns its\n  whole set (or, for `limit`, the newest rows up to that limit) and says so.\n- Idempotency: `POST /v1/events` takes an `idempotency_key` per event; credits (`grantCredits`, `consumeCredits`), `createPaymentLink` and `createUploadSession`\n  also take it in the `Idempotency-Key` header. Every other write is not deduplicated by a key: a repeated create answers `409` where the object has a natural\n  unique key (customer, meter, plan, coupon, ...).\n- Errors always use the `Error` envelope. 429 responses carry `Retry-After` (seconds).\n"
  },
  "servers": [
    {
      "url": "https://api.payrudder.com",
      "description": "Payrudder"
    },
    {
      "url": "https://api-staging.payrudder.com",
      "description": "Staging"
    },
    {
      "url": "http://localhost:42800",
      "description": "Local stack"
    }
  ],
  "security": [
    {
      "apiKey": []
    }
  ],
  "paths": {
    "/v1/events": {
      "post": {
        "operationId": "ingestEvents",
        "summary": "Ingest usage events (1..500 per request, at most 1 MiB)",
        "description": "Answers `202` with one result per event, in request order, for any structurally valid batch. A bad event does not\nfail the batch: it comes back `rejected` with an `error_code`. Live keys must send an `idempotency_key` per event;\na retry with the same key and payload returns `duplicate` with the original `event_id`. `quantity` may be a JSON\nstring or number and is parsed as an exact decimal (never as a float).\nThe `ingest` rate limit is charged per event.\n",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/IngestEventsRequest"
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Accepted for processing",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/IngestEventsResponse"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "413": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          },
          "503": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Events"
        ],
        "x-codeSamples": [
          {
            "lang": "bash",
            "label": "curl",
            "source": "curl -sS https://api.payrudder.com/v1/events \\\n  -H \"Authorization: Bearer $PAYRUDDER_API_KEY\" \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\"events\":[{\"customer_external_id\":\"cus_42\",\"meter_code\":\"api_calls\",\"quantity\":\"1\",\"event_time\":\"'\"$(date -u +%Y-%m-%dT%H:%M:%SZ)\"'\",\"idempotency_key\":\"first-event-1\"}]}'"
          },
          {
            "lang": "typescript",
            "label": "TypeScript",
            "source": "import { Payrudder } from \"@payrudder/sdk\";\n\nconst payrudder = new Payrudder({ apiKey: process.env.PAYRUDDER_API_KEY, baseUrl: \"https://api.payrudder.com\" }); // prk_test_...\n\nawait payrudder.customers.createCustomer({ external_id: \"cus_42\", name: \"First customer\", email: \"first@example.com\" });\n\nconst results = await payrudder.events.ingest([\n  { customer_external_id: \"cus_42\", meter_code: \"api_calls\", quantity: \"1\", event_time: new Date(), idempotency_key: \"first-event-1\" },\n]);\nconsole.log(results[0].status); // accepted | duplicate | rejected"
          },
          {
            "lang": "python",
            "label": "Python",
            "source": "from datetime import datetime, timezone\nfrom payrudder import Payrudder\n\nclient = Payrudder(api_key=\"prk_test_...\", base_url=\"https://api.payrudder.com\")  # or PAYRUDDER_API_KEY / PAYRUDDER_BASE_URL\n\nclient.customers.create_customer({\"external_id\": \"cus_42\", \"name\": \"First customer\", \"email\": \"first@example.com\"})\n\nresults = client.events.ingest([\n    {\"customer_external_id\": \"cus_42\", \"meter_code\": \"api_calls\", \"quantity\": \"1\",\n     \"event_time\": datetime.now(timezone.utc).isoformat(), \"idempotency_key\": \"first-event-1\"},\n])\nprint(results[0][\"status\"])  # accepted | duplicate | rejected"
          },
          {
            "lang": "go",
            "label": "Go",
            "source": "package main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\t\"log\"\n\t\"time\"\n\n\tpayrudder \"github.com/nafrucom/payrudder-sdks/go\"\n)\n\nfunc main() {\n\tclient, err := payrudder.New(payrudder.WithAPIKey(\"prk_test_...\"), payrudder.WithBaseURL(\"https://api.payrudder.com\"))\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\tctx := context.Background()\n\tif _, err := client.Customers.CreateCustomer(ctx, &payrudder.CreateCustomerRequest{ExternalID: \"cus_42\", Name: \"First customer\", Email: \"first@example.com\"}); err != nil {\n\t\tlog.Fatal(err)\n\t}\n\tresults, err := client.Events.Ingest(ctx, []payrudder.IncomingEvent{{\n\t\tCustomerExternalID: \"cus_42\", MeterCode: \"api_calls\", Quantity: \"1\", EventTime: time.Now(), IdempotencyKey: \"first-event-1\",\n\t}})\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\tfmt.Println(results[0].Status)\n}"
          },
          {
            "lang": "php",
            "label": "PHP",
            "source": "use Payrudder\\Client;\n\n$client = new Client(apiKey: 'prk_test_...', baseUrl: 'https://api.payrudder.com');\n\n$client->customers->createCustomer(['external_id' => 'cus_42', 'name' => 'First customer', 'email' => 'first@example.com']);\n\n$result = $client->events->ingest([\n    ['customer_external_id' => 'cus_42', 'meter_code' => 'api_calls', 'quantity' => '1', 'event_time' => gmdate('c'), 'idempotency_key' => 'first-event-1'],\n]);\nvar_dump($result[0]->status);"
          }
        ]
      }
    },
    "/v1/events/corrections": {
      "post": {
        "operationId": "correctEvents",
        "summary": "Correct usage events (1..500 per request, at most 1 MiB)",
        "description": "A correction is a new event, never an edit: it names the `idempotency_key` of the event it corrects and the `quantity` that event should have had (`0` cancels it), with a\n`reason`. The service works out the difference between that and what the event stands at now (its own quantity plus every earlier correction of it) and adds it to the\n**period of the original event**, by the rules every event follows: while that period is open, or closed but inside its grace period, the usage of the period changes\nexactly; once it has passed its cutoff or been rated, the difference becomes **late usage** of that period, a (negative, for less) `LATE_USAGE` line on the invoice of the\nperiod the correction was accepted in. A finalized invoice is never changed.\n\nOnly events of meters that add (`SUM`, `COUNT`) and have no property filter can be corrected (`CORRECTION_UNSUPPORTED_METER` otherwise). For a `COUNT` meter an event is\none whatever its quantity, so the only corrections are `0` (cancel it) and any positive quantity (count it again). An event can be corrected as long as its idempotency\nkey is remembered, which is at least 45 and less than 76 days after it was first seen (`CORRECTION_UNKNOWN_EVENT` after). A correction cannot be corrected: send the\noriginal's key again with the quantity it should have. `customer_external_id` and `meter_code` must be the original's.\n\nThe answer is `202` with one result per correction, in request order, like `POST /v1/events`; the correction has its own `idempotency_key`, and a retry with the same key and\npayload is a `duplicate` and changes nothing. A refused correction claims no key. Who made it (the signed-in person, or the API key) and the reason are kept.\nThe `ingest` rate limit is charged per correction. A correction is not usage and is not metered as events.\n",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CorrectEventsRequest"
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Accepted for processing",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/IngestEventsResponse"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "413": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          },
          "503": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Events"
        ]
      }
    },
    "/v1/rejected-events": {
      "get": {
        "operationId": "listRejectedEvents",
        "summary": "Events refused by POST /v1/events, newest first",
        "description": "Every event `POST /v1/events` (or the corrections route) answered `rejected` is kept here, so a developer can see later what went wrong: the `error_code` and the API's\n`error_message`, the meter code and customer id as sent, the event time and the idempotency key. The properties and the quantity are never kept. The log of a tenant (an\nenvironment) holds the last 14 days and at most 10 000 rows, the oldest dropped first. A row is written just after the answer, best effort: it can be a moment late,\nand a rejection is missing when the database could not take the write or a burst of rejections outran the writer. Needs the `usage:read` permission.\n",
        "parameters": [
          {
            "name": "error_code",
            "in": "query",
            "description": "One of the error codes of `POST /v1/events`",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "meter",
            "in": "query",
            "description": "A meter code, as sent",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "page_size",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 200,
              "default": 50
            }
          },
          {
            "name": "page_token",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ListRejectedEventsResponse"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Rejected events"
        ]
      }
    },
    "/v1/rejected-events/summary": {
      "get": {
        "operationId": "getRejectedEventSummary",
        "summary": "Rejected events of the last 24 hours, by error code and by hour",
        "description": "Counts from the same log as `listRejectedEvents`. Only the rejected side is here: the number of accepted events per hour is not kept anywhere cheap to read, so there is\nno accepted-versus-rejected ratio. Needs the `usage:read` permission.\n",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RejectedEventSummary"
                }
              }
            }
          }
        },
        "tags": [
          "Rejected events"
        ]
      }
    },
    "/v1/customers": {
      "post": {
        "operationId": "createCustomer",
        "summary": "Create a customer",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateCustomerRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Customer"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Customers"
        ]
      },
      "get": {
        "operationId": "listCustomers",
        "summary": "List customers (ordered by external_id, or searched, narrowed and sorted)",
        "description": "With only `page_size` and `page_token` the list is in external id order and pages by a keyset token, which stays stable while customers are added. With any of the other parameters the list is searched, narrowed and sorted on the server: it is ordered by `sort` (newest first when unset), pages by position and reports `total`.\n",
        "parameters": [
          {
            "name": "page_size",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 500,
              "default": 100
            }
          },
          {
            "name": "page_token",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "search",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Words that must each appear in the external id, name, e-mail or tax id"
          },
          {
            "name": "sort",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "newest",
                "oldest",
                "name",
                "-name"
              ]
            }
          },
          {
            "name": "country",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "ISO 3166-1 alpha-2 codes, comma-separated: any of them"
          },
          {
            "name": "currency",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "ISO 4217 codes, comma-separated: any of them"
          },
          {
            "name": "subscription",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "active",
                "none"
              ]
            },
            "description": "Customers with a subscription that is not cancelled, or without one"
          },
          {
            "name": "created_from",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time"
            },
            "description": "Created at or after this time (a plain date is the start of that day, UTC)"
          },
          {
            "name": "created_to",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time"
            },
            "description": "Created before this time"
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ListCustomersResponse"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Customers"
        ]
      }
    },
    "/v1/customers/{external_id}": {
      "get": {
        "operationId": "getCustomer",
        "summary": "Get a customer by external id",
        "parameters": [
          {
            "$ref": "#/components/parameters/ExternalID"
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Customer"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Customers"
        ]
      }
    },
    "/v1/customers/{external_id}/payment-method": {
      "put": {
        "operationId": "setPaymentMethod",
        "summary": "Set the customer's PSP token (sandbox accepts only pm_sandbox_* tokens)",
        "parameters": [
          {
            "$ref": "#/components/parameters/ExternalID"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SetPaymentMethodRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Customer"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Customers"
        ]
      }
    },
    "/v1/customers/{external_id}/payment-method-setup": {
      "post": {
        "operationId": "createPaymentMethodSetup",
        "summary": "Make the link to the provider's page where the customer saves a card for later charges",
        "description": "For a provider that has the customer save a payment method on its own page (Stripe: Checkout in setup mode). The answer is the address of that page; you send it to the customer. Nothing is charged. When the customer has saved the card, the provider tells Payrudder and the method becomes the customer's payment method (the string a charge takes, `cus_...:pm_...` at Stripe), which later invoices are charged with: there is nothing to call afterwards. The customer is made at the provider once and remembered, so asking again for the same customer reuses it. **Payrudder collects and keeps no consent in this flow.** The provider's guide asks you to collect the customer's explicit consent to be charged without them present (the amount and timing, how the amount is decided, how to cancel) and to keep a record of it: send the link together with your terms and keep the agreement yourself. The page is made in the environment of the key (a `sk_test_` Stripe account for a sandbox key). `return_url` must be `https`. `404 payments.customer.not_ready` for a customer that does not exist, `501` for a provider that cannot do this, and the provider's own refusal when the environment has no account for it.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/ExternalID"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreatePaymentMethodSetupRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PaymentMethodSetup"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "501": {
            "$ref": "#/components/responses/Error"
          },
          "502": {
            "$ref": "#/components/responses/Error"
          },
          "503": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Customers"
        ]
      }
    },
    "/v1/customers/{external_id}/cards": {
      "get": {
        "operationId": "listCustomerCards",
        "summary": "The cards the payment provider holds for the customer",
        "description": "The cards of the provider's card storage (iyzico) under the user key the customer's payment method names, never a number: the bank, the first digits (BIN), the last four, the expiry. The card the customer's invoices are charged with is `in_use`. A customer with no stored card has an empty list and no provider. Payrudder cannot put a card in storage (it holds no card numbers): whoever holds the number puts it there and sets the payment method with `PUT /v1/customers/{external_id}/payment-method`. The sandbox has none.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/ExternalID"
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CustomerCards"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "502": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Customers"
        ]
      }
    },
    "/v1/customers/{external_id}/cards/{token}": {
      "delete": {
        "operationId": "deleteCustomerCard",
        "summary": "Delete one of the customer's stored cards at the provider",
        "description": "The card must be one of the customer's own (a token of another customer is `404 payments.card.not_found`, and nothing is sent to the provider). The customer's payment method is not changed: when the card was `in_use` the answer says so, and the next charge fails until a new payment method is set.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/ExternalID"
          },
          {
            "name": "token",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Deleted",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DeletedCustomerCard"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "502": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Customers"
        ]
      }
    },
    "/v1/customers/{external_id}/address": {
      "put": {
        "operationId": "setCustomerAddress",
        "summary": "Replace the customer's billing address",
        "description": "The address is printed on the customer's invoices (PDF and hosted page). Its country becomes the customer's country, which provider routing and tax read. An empty object clears the address and keeps the country.",
        "parameters": [
          {
            "$ref": "#/components/parameters/ExternalID"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AddressInput"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Customer"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Customers"
        ]
      }
    },
    "/v1/customers/{external_id}/contact": {
      "put": {
        "operationId": "setCustomerContact",
        "summary": "Replace the customer's name and e-mail address",
        "description": "Invoices, receipts and dunning mails carry the name and go to the e-mail address, in the customer's language. Name and e-mail are required, with the limits of customer creation. Language, kind and phone are optional; omit one to keep what the customer has (only the phone can be cleared, with an empty string). The external id cannot change.",
        "parameters": [
          {
            "$ref": "#/components/parameters/ExternalID"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CustomerContact"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Customer"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Customers"
        ]
      }
    },
    "/v1/customers/{external_id}/block": {
      "post": {
        "operationId": "blockCustomer",
        "summary": "Block a customer from new purchases",
        "description": "A blocked customer cannot get a new subscription or plan change (error key `plans.customer.blocked`), buy through a payment link or the portal, or have a\npayment link made for them (`billing.customer.blocked`); what exists runs on until you end it, and an invoice that was issued before stays payable, except after\na `fraud` or `chargeback` block. A price change you schedule skips them (`customer_blocked`). Blocking again keeps the block that is in force. The note is\nyours, up to 500 characters; `category` says why; `blocked_until` ends the block by itself (it must be in the future, and every check reads it, so the block\nstops holding at that time). Every block and lift is kept in the customer's history and sent as the `customer.blocked` / `customer.unblocked` webhook events\n(the end of a block by itself sends none). Usage ingestion is not affected, and entitlements are unless you set `suspend_service`: then every entitlement\ncheck of this customer answers `allowed: false` and `suspended: true` (the limits and the counted usage are untouched, and the events you send are still\naccepted and counted) until you lift the block or it ends by itself. The service is suspended only when the block is new: a block already in force is kept\nas it is, so lift it first to change it.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/ExternalID"
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/BlockCustomerRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Customer"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Customers"
        ]
      }
    },
    "/v1/customers/{external_id}/unblock": {
      "post": {
        "operationId": "unblockCustomer",
        "summary": "Lift a customer's block",
        "description": "Also clears a block that has ended by itself. A customer who was not blocked is returned as it is.",
        "parameters": [
          {
            "$ref": "#/components/parameters/ExternalID"
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Customer"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Customers"
        ]
      }
    },
    "/v1/customers/{external_id}/block-events": {
      "get": {
        "operationId": "listCustomerBlockEvents",
        "summary": "A customer's blocks and lifts, newest first",
        "description": "Who blocked or lifted, when, and why (the latest 100). Never changed or deleted.",
        "parameters": [
          {
            "$ref": "#/components/parameters/ExternalID"
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ListCustomerBlockEventsResponse"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Customers"
        ]
      }
    },
    "/v1/customers/{external_id}/appeals": {
      "get": {
        "operationId": "listCustomerBlockAppeals",
        "summary": "A blocked customer's appeals, newest first",
        "description": "The statements your customer sent from their portal link against a block (the latest 20), each with its status (`open`, `accepted`, `rejected`, or `closed` when the block was lifted some other way while it was open) and your answer. The statement is the customer's own words: treat it as untrusted text, never as markup. The category and the note of your block are never part of an appeal. Needs customers:read.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/ExternalID"
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ListCustomerBlockAppealsResponse"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Customers"
        ]
      }
    },
    "/v1/customers/{external_id}/appeals/{id}/decision": {
      "post": {
        "operationId": "decideCustomerBlockAppeal",
        "summary": "Accept or reject a blocked customer's appeal",
        "description": "`accepted` lifts the block exactly as `POST /v1/customers/{external_id}/unblock` does (the history row, the `customer.unblocked` webhook event and, when you have the mail on, the customer's notice) and records your decision in the same step. `rejected` needs an `answer` (up to 1000 characters); the block stays and the customer sees your answer on their portal and may send another appeal. An appeal that was decided or closed is refused with `plans.customer_appeal.not_open`. Both decisions are audit entries (`customer_block.appeal_decided`); no webhook event is sent for a submitted appeal or a rejection. Needs customers:write.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/ExternalID"
          },
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/DecideCustomerBlockAppealRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CustomerBlockAppeal"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Customers"
        ]
      }
    },
    "/v1/blocklist": {
      "get": {
        "operationId": "listBlocklist",
        "summary": "Your blocklist, newest first",
        "description": "The e-mail addresses, tax ids and external customer ids that a new customer, or a customer's new e-mail address or tax id, may not match (error key `plans.customer.blocklisted`, on creating a customer and on changing the contact details or the tax data). At most 1000 entries, so the list is not paged. Customers that exist when an entry is added are not touched: block them from the customer list. The operator keeps a platform-wide list of its own that holds the same gates for every app; it is not shown here and a refusal does not say which list it was. Needs customers:read.\n",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ListBlocklistResponse"
                }
              }
            }
          }
        },
        "tags": [
          "Blocklist"
        ]
      },
      "post": {
        "operationId": "addBlocklistEntry",
        "summary": "Put an e-mail address, a tax id or an external customer id on your blocklist",
        "description": "The value is normalised: an e-mail address in lower case, a tax id without spaces and dashes in capitals, an external id as it is. An entry that is there is returned as it is. The note is yours and is never shown to the person the entry is about. Recorded in the audit log without the value. Error key `plans.blocklist.full` at 1000 entries. Needs customers:write.\n",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AddBlocklistEntryRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BlocklistEntry"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Blocklist"
        ]
      }
    },
    "/v1/blocklist/{id}": {
      "delete": {
        "operationId": "removeBlocklistEntry",
        "summary": "Take an entry off your blocklist",
        "description": "Needs customers:write.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Removed"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Blocklist"
        ]
      }
    },
    "/v1/customers/{external_id}/tax": {
      "put": {
        "operationId": "setCustomerTax",
        "summary": "Replace the customer's tax data used on e-invoices",
        "description": "Tax id (VKN/TCKN in Turkey, VAT id in the EU), tax office (Turkey) and whether the customer is registered for e-fatura. Empty values clear them. An id that does not look right for the customer's country and kind is stored all the same: the customer comes back with tax_id_warning set, and tax_id_validated_at is set only for an id that passes the local checksum or shape check. Error key plans.customer.tax_invalid (only for an id that is not 5 to 20 letters and digits, or a tax office that is not one line).",
        "parameters": [
          {
            "$ref": "#/components/parameters/ExternalID"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CustomerTax"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Customer"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Customers"
        ]
      }
    },
    "/v1/contracts/versions": {
      "get": {
        "operationId": "listContractVersions",
        "summary": "The versions of the agreements you present to your customers, newest first",
        "description": "A version is one edition of an agreement (distance sales, pre-information, terms, privacy) in one or more languages. Needs contracts:read.",
        "parameters": [
          {
            "name": "kind",
            "in": "query",
            "schema": {
              "$ref": "#/components/schemas/ContractKind"
            }
          },
          {
            "name": "audience",
            "in": "query",
            "schema": {
              "$ref": "#/components/schemas/ContractAudience"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ListContractVersionsResponse"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Contracts"
        ]
      },
      "post": {
        "operationId": "publishContractVersion",
        "summary": "Publish the next version of an agreement",
        "description": "A version cannot be edited: this adds the next one to the series of (kind, audience), which becomes the one customers see. The texts are restricted markdown (`#` headings, `- ` and `1. ` lists, `**bold**`, blank-line paragraphs; raw HTML is shown as text) with `{{variable}}` placeholders from a fixed list (`seller_name`, `seller_address`, `seller_tax_id`, `seller_tax_office`, `seller_mersis`, `customer_name`, `customer_email`, `customer_address`, `order_description`, `order_total`, `order_currency`, `date`). A `material` version asks customers who accepted an earlier one to accept again; a minor one does not (the first version of a series is always material). Payrudder supplies starter texts for Turkish and English that must be reviewed by a lawyer; it does not say any text is legally sufficient. Error keys plans.contract.unknown_variable, plans.contract.body_required. Needs contracts:write.\n",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PublishContractVersionRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ContractVersion"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Contracts"
        ]
      }
    },
    "/v1/contracts/versions/{id}": {
      "get": {
        "operationId": "getContractVersion",
        "summary": "One version of an agreement",
        "parameters": [
          {
            "$ref": "#/components/parameters/ID"
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ContractVersion"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Contracts"
        ]
      }
    },
    "/v1/contracts/preview": {
      "post": {
        "operationId": "previewContract",
        "summary": "Render a text the way a customer would see it, with sample values",
        "description": "Reports the variables the text uses and any that do not exist. Nothing is stored.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PreviewContractRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PreviewContractResponse"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Contracts"
        ]
      }
    },
    "/v1/contracts/starter": {
      "get": {
        "operationId": "getContractStarter",
        "summary": "The starter text of an agreement in Turkish or English",
        "description": "A template to start from, with a notice on top that it is not legal advice and must be reviewed by a lawyer before use. There is no starter text in other languages (error key plans.contract.no_starter).",
        "parameters": [
          {
            "name": "kind",
            "in": "query",
            "required": true,
            "schema": {
              "$ref": "#/components/schemas/ContractKind"
            }
          },
          {
            "name": "locale",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "tr",
                "en"
              ]
            }
          },
          {
            "name": "audience",
            "in": "query",
            "schema": {
              "$ref": "#/components/schemas/ContractAudience"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GetContractStarterResponse"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Contracts"
        ]
      }
    },
    "/v1/contracts/settings": {
      "get": {
        "operationId": "getContractSettings",
        "summary": "Which agreements are required, whether the service starts at once, and how long evidence is kept",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ContractSettings"
                }
              }
            }
          }
        },
        "tags": [
          "Contracts"
        ]
      },
      "put": {
        "operationId": "setContractSettings",
        "summary": "Change which agreements are required",
        "description": "While `required_kinds` is not empty, no subscription is created for a customer who has not accepted the current version of each of them (error key plans.contract.not_accepted), and a hosted payment page asks for them next to the pay button. A kind can be required once a version of it is published (plans.contract.kind_unpublished). Renewals and dunning charges are never held back. With `immediate_start`, a consumer is asked for the request to start at once and the acknowledgement of losing the right of withdrawal as two separate boxes (plans.contract.consent_required). `retention_months` (12 to 120, default 36; 0 keeps the value) is how long the IP address and user agent of an acceptance are kept; the rest of the record stays.\n",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SetContractSettingsRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ContractSettings"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Contracts"
        ]
      }
    },
    "/v1/customers/{external_id}/contract-requirements": {
      "get": {
        "operationId": "getContractRequirements",
        "summary": "What the customer must accept before a subscription starts, with the text to show",
        "description": "For an embedded checkout. `customer_type` overrides the customer's own (a business customer gets the business texts; an unknown type is treated as a consumer). The order fills the variables of the texts.",
        "parameters": [
          {
            "$ref": "#/components/parameters/ExternalID"
          },
          {
            "name": "locale",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "customer_type",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "individual",
                "business"
              ]
            }
          },
          {
            "name": "order_description",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "order_total",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "order_currency",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GetContractRequirementsResponse"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Customers"
        ]
      }
    },
    "/v1/customers/{external_id}/contract-acceptances": {
      "get": {
        "operationId": "listContractAcceptances",
        "summary": "What the customer accepted, newest first",
        "description": "The customer's acceptance log, a page at a time (`page_size`, default 100, at most 200; the next page is `next_page_token`, empty on the last). The filters narrow it and combine: `kind`, `source` (api, hosted), `version_id` (one version of a text) and the time the customer accepted, `from` (inclusive) to `to` (exclusive), as RFC 3339 times.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/ExternalID"
          },
          {
            "name": "kind",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "distance_sales",
                "pre_info",
                "tos",
                "privacy"
              ]
            }
          },
          {
            "name": "source",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "api",
                "hosted"
              ]
            }
          },
          {
            "name": "version_id",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "from",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time"
            },
            "description": "Accepted at or after this time"
          },
          {
            "name": "to",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time"
            },
            "description": "Accepted before this time"
          },
          {
            "name": "page_size",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 200,
              "default": 100
            }
          },
          {
            "name": "page_token",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ListContractAcceptancesResponse"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Customers"
        ]
      },
      "post": {
        "operationId": "recordContractAcceptance",
        "summary": "Record that the customer accepted the current versions (an embedded checkout)",
        "description": "The evidence of one checkout moment: one row for each version, all in one group. Every version must be the current one of its series (plans.contract.version_stale otherwise) and `checkbox_text` is the words next to the box as the customer saw them. What you report about the customer's IP address, browser and time is your claim, and the record says so (`observed` is false for those fields); Payrudder's own payment pages record what they observed. Acceptances are append-only. The customer is mailed the page they accepted, in their language. Needs customers:write.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/ExternalID"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/RecordContractAcceptanceRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RecordContractAcceptanceResponse"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Customers"
        ]
      }
    },
    "/v1/contract-acceptances/{id}/snapshot": {
      "get": {
        "operationId": "getContractSnapshot",
        "summary": "The page the customer accepted, as it was rendered then",
        "description": "A self-contained HTML document in `html` (no script, no external resource), written again from the stored record. Its `sha256` is the `snapshot_sha256` of the acceptance, and the page that was mailed to the customer. It holds the seller's texts and the customer's name, so show it as untrusted content, for example in a sandboxed frame.\nWith `pdf=true` the same page is also drawn as a PDF, the customer's copy (text only, in Noto Sans, ending with the sha256 of the page it was drawn from): base64 in `pdf`. A page with a character the font cannot draw (an Arabic text, a name in Chinese) has no PDF: `pdf_unavailable` is true and the HTML page is the only copy.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/ID"
          },
          {
            "name": "pdf",
            "in": "query",
            "required": false,
            "schema": {
              "type": "boolean",
              "default": false
            },
            "description": "Also draw the page as a PDF"
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GetContractSnapshotResponse"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Contract acceptances"
        ]
      }
    },
    "/v1/customers/{external_id}/contract-withdrawals": {
      "post": {
        "operationId": "createContractWithdrawal",
        "summary": "Record that the customer withdrew from a contract",
        "description": "The seller decides and refunds; this keeps the statement, when it arrived and who decided what. Sends the webhook event contract.withdrawal_requested. The refund follows the seller's decision, never the statement: see setContractWithdrawalStatus and requestContractWithdrawalRefund. Needs customers:write.",
        "parameters": [
          {
            "$ref": "#/components/parameters/ExternalID"
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateContractWithdrawalRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ContractWithdrawal"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Customers"
        ]
      }
    },
    "/v1/contract-withdrawals": {
      "get": {
        "operationId": "listContractWithdrawals",
        "summary": "Withdrawal requests, newest first (at most 200)",
        "parameters": [
          {
            "name": "customer_external_id",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "received",
                "accepted",
                "rejected",
                "refunded"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ListContractWithdrawalsResponse"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Contract withdrawals"
        ]
      }
    },
    "/v1/contract-withdrawals/{id}/status": {
      "put": {
        "operationId": "setContractWithdrawalStatus",
        "summary": "Decide a withdrawal request, or mark an accepted one refunded",
        "description": "received becomes accepted or rejected, once; accepted becomes refunded (plans.contract.withdrawal_decided otherwise). Sends the webhook event contract.withdrawal_decided. Accepting a withdrawal that names an invoice also asks billing for the refund when the settings say `withdrawal_refund: full` (the default): a credit note that returns the amount to the card, for `refund_amount_minor` or whatever is left of the invoice. The decision is recorded first; what happened to the refund is on the returned withdrawal (`refund_state`, `credit_note_id`, `refund_note`) and never makes this call fail. An invoice paid by bank transfer or cash cannot go back through Payrudder: `refund_state` is `outside` and the seller refunds it by hand, then marks the withdrawal refunded. Needs customers:write. A key that does not also hold invoices:write cannot accept a withdrawal while the settings say `withdrawal_refund: full` (403 gateway.auth.permission_denied, nothing is decided): the refund is a credit note, and creating one needs invoices:write everywhere. Rejecting, or accepting while the setting is `none`, needs customers:write only.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/ID"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SetContractWithdrawalStatusRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ContractWithdrawal"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Contract withdrawals"
        ]
      }
    },
    "/v1/contract-withdrawals/{id}/refund": {
      "post": {
        "operationId": "requestContractWithdrawalRefund",
        "summary": "Ask for the refund of an accepted withdrawal",
        "description": "For a withdrawal whose settings say `withdrawal_refund: none`, or whose first request failed. Only an accepted withdrawal that names an invoice, once: a request under way or made already answers plans.contract.refund_not_possible. The refund is a credit note with `refund_to_card` for `amount_minor` (0 is whatever is left of the invoice), made by billing under its own rules (a paid invoice, never more than what is left of it, only a payment a provider can return). The answer is the withdrawal with its `refund_state`. Needs invoices:write, not only customers:write: it returns money to a card.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/ID"
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/RequestContractWithdrawalRefundRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ContractWithdrawal"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Contract withdrawals"
        ]
      }
    },
    "/v1/e-invoices": {
      "get": {
        "operationId": "listEInvoices",
        "summary": "The legal e-documents (e-fatura, e-arşiv, Peppol) of invoices and credit notes, newest first",
        "parameters": [
          {
            "name": "invoice_id",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "credit_note_id",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "pending",
                "issued",
                "failed",
                "cancelled"
              ]
            }
          },
          {
            "name": "page_size",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 200,
              "default": 50
            }
          },
          {
            "name": "page_token",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EInvoiceList"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "E-invoices"
        ]
      }
    },
    "/v1/e-invoices/{id}": {
      "get": {
        "operationId": "getEInvoice",
        "summary": "One e-document",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EInvoiceDocument"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "E-invoices"
        ]
      }
    },
    "/v1/e-invoices/{id}/files/{kind}": {
      "get": {
        "operationId": "getEInvoiceFile",
        "summary": "A presigned link to the UBL XML or the PDF of an issued e-document (5 minutes)",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "kind",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "xml",
                "pdf"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SignedUrl"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "E-invoices"
        ]
      }
    },
    "/v1/meters": {
      "post": {
        "operationId": "createMeter",
        "summary": "Create a meter, or the next version of an existing code",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateMeterRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Meter"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Meters"
        ]
      },
      "get": {
        "operationId": "listMeters",
        "summary": "List meters (latest version of each code)",
        "description": "Not paged: the response is the complete list.",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ListMetersResponse"
                }
              }
            }
          }
        },
        "tags": [
          "Meters"
        ]
      }
    },
    "/v1/meters/{code}": {
      "get": {
        "operationId": "getMeter",
        "summary": "Get the latest version of a meter",
        "parameters": [
          {
            "name": "code",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Meter"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Meters"
        ]
      }
    },
    "/v1/customers/{external_id}/usage": {
      "get": {
        "operationId": "getCustomerUsage",
        "summary": "On-time usage of a customer in a period, per meter",
        "description": "Quantities are exact decimals with the meter's scale. Usage that arrived after the period's cutoff is not\nincluded here: it is billed on a later invoice as late usage. `period` defaults to the current period in the\ntenant's time zone.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/ExternalID"
          },
          {
            "name": "period",
            "in": "query",
            "schema": {
              "type": "string",
              "pattern": "^[0-9]{4}-(0[1-9]|1[0-2])$",
              "examples": [
                "2026-11"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GetCustomerUsageResponse"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Customers"
        ]
      }
    },
    "/v1/customers/{external_id}/upcoming-invoice": {
      "get": {
        "operationId": "getUpcomingInvoice",
        "summary": "What the customer's next invoice would be if it were drafted now",
        "description": "An estimate of the regular invoice of the period that is still open (or, while a closed period's grace period runs, of that period): the usage and late usage so far, rated by\nthe plan version in force, the fixed fee, tax at the tenant's rate for the customer's country and the credit balance the invoice would use. It is computed by the same code\nthat drafts the real invoice, from the same inputs, and nothing is stored. It moves with every event until the period closes, and a change of plan, a coupon or a tax rate\nmade later can move it too: `estimate` is always `true`, and the response has no id and no number. A fixed fee invoiced in advance is its own invoice and is not in it.\nA customer with nothing to bill in the period gets `has_invoice: false` and no lines.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/ExternalID"
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UpcomingInvoice"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Customers"
        ]
      }
    },
    "/v1/customers/{external_id}/entitlements": {
      "get": {
        "operationId": "listEntitlements",
        "summary": "Usage against the limits of every meter the customer has an entitlement on",
        "description": "See `getEntitlement` for the semantics of each item. Not paged: the response is the complete list.",
        "parameters": [
          {
            "$ref": "#/components/parameters/ExternalID"
          },
          {
            "name": "period",
            "in": "query",
            "schema": {
              "type": "string",
              "pattern": "^[0-9]{4}-(0[1-9]|1[0-2])$",
              "examples": [
                "2026-11"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ListEntitlementsResponse"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Customers"
        ]
      }
    },
    "/v1/customers/{external_id}/entitlements/{meter}": {
      "get": {
        "operationId": "getEntitlement",
        "summary": "Usage of one meter against the customer's limit",
        "description": "Answered from near-real-time counters. They are eventually consistent (typically well under 2 s behind ingest):\n`as_of` is the ingest time of the newest event reflected in `used`. Payrudder never blocks ingest on a limit; call\nthis before serving your customer and decide what to do. A customer without an entitlement on the meter is\n`unlimited`. `period` defaults to the current period in the tenant's time zone.\n\nA limit counts over its `window`: the billing month, or an hour, a day, an ISO week, a calendar year or the customer's\nwhole lifetime, in the tenant's time zone. `period` picks the month of a monthly limit; every other window always\nreports its current one (`window_id`, ending at `resets_at`, which a lifetime window does not have). `allowed` follows\nthe limit's `mode`: a `hard` limit stops allowing at the limit, a `soft` or `notify` one keeps allowing and says\n`over_limit`. Every window's counter is reconciled against the aggregator every few minutes, so an event delivered\ntwice stops counting twice within one cycle.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/ExternalID"
          },
          {
            "name": "meter",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "period",
            "in": "query",
            "schema": {
              "type": "string",
              "pattern": "^[0-9]{4}-(0[1-9]|1[0-2])$",
              "examples": [
                "2026-11"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EntitlementStatus"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Customers"
        ]
      }
    },
    "/v1/customers/{external_id}/entitlement-overrides": {
      "get": {
        "operationId": "listEntitlementOverrides",
        "summary": "The customer's own limits, which replace its package's on their meters",
        "description": "Not paged: the response is the complete list.",
        "parameters": [
          {
            "$ref": "#/components/parameters/ExternalID"
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ListEntitlementOverridesResponse"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Customers"
        ]
      }
    },
    "/v1/customers/{external_id}/entitlement-overrides/{meter}": {
      "put": {
        "operationId": "setEntitlementOverride",
        "summary": "Give the customer its own limit on a meter",
        "description": "Replaces the entitlement the customer's package gives on the meter, or adds one on a meter the package does not limit, for every\nsubscription of the customer until the override is deleted. limits-svc applies it within seconds. `QUOTA_MODE_SOFT` needs every\ncurrent package of the customer to price the meter (the usage over the limit is billed at that price).\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/ExternalID"
          },
          {
            "name": "meter",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/EntitlementTerms"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EntitlementOverride"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Customers"
        ]
      },
      "delete": {
        "operationId": "deleteEntitlementOverride",
        "summary": "Return the customer to its package's limit on the meter",
        "parameters": [
          {
            "$ref": "#/components/parameters/ExternalID"
          },
          {
            "name": "meter",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Deleted"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Customers"
        ]
      }
    },
    "/v1/customers/{external_id}/members": {
      "get": {
        "operationId": "listCustomerMembers",
        "summary": "The people of a customer that is an organisation, the billing owner first",
        "description": "A customer can be an organisation: a university that buys mailboxes has many people who use the product, and one of them pays. Members are\nthose people as your application knows them (`external_id` is your own user id). Exactly one member can be the billing owner, the person\nwho manages payment. Not paged: at most the first 1000 members are returned, the owner first.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/ExternalID"
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ListCustomerMembersResponse"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Customers"
        ]
      }
    },
    "/v1/customers/{external_id}/members/{member_id}": {
      "get": {
        "operationId": "getCustomerMember",
        "summary": "One member, and whether they may manage billing",
        "description": "Ask this before you show your billing pages to a person. `can_manage_billing` is true for the customer's billing owner only.",
        "parameters": [
          {
            "$ref": "#/components/parameters/ExternalID"
          },
          {
            "name": "member_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CustomerMember"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Customers"
        ]
      },
      "put": {
        "operationId": "setCustomerMember",
        "summary": "Add a member to the customer, or change their name and e-mail",
        "description": "`member_id` is your own id of the person. The first member of a customer becomes its billing owner; everybody added after is a member\nuntil ownership is handed to them. A member that exists keeps its role.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/ExternalID"
          },
          {
            "name": "member_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 128
            }
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SetCustomerMemberRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CustomerMember"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Customers"
        ]
      },
      "delete": {
        "operationId": "deleteCustomerMember",
        "summary": "Remove a member from the customer",
        "description": "The billing owner can be removed only when nobody else is left (409 `plans.member.owner_must_transfer`). Hand ownership over first.",
        "parameters": [
          {
            "$ref": "#/components/parameters/ExternalID"
          },
          {
            "name": "member_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Deleted"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Customers"
        ]
      }
    },
    "/v1/customers/{external_id}/members/{member_id}/make-owner": {
      "post": {
        "operationId": "makeCustomerOwner",
        "summary": "Hand the billing ownership of the customer to this member",
        "description": "The owner until now stays as a member. Asking for the member who already is the owner changes nothing.",
        "parameters": [
          {
            "$ref": "#/components/parameters/ExternalID"
          },
          {
            "name": "member_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CustomerMember"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Customers"
        ]
      }
    },
    "/v1/plans": {
      "post": {
        "operationId": "createPlan",
        "summary": "Create a plan",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreatePlanRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Plan"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Plans"
        ]
      },
      "get": {
        "operationId": "listPlans",
        "summary": "List plans",
        "description": "Not paged: the response is the complete list.",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ListPlansResponse"
                }
              }
            }
          }
        },
        "tags": [
          "Plans"
        ]
      }
    },
    "/v1/plans/{code}/versions": {
      "post": {
        "operationId": "publishPlanVersion",
        "summary": "Publish the next immutable plan version",
        "parameters": [
          {
            "$ref": "#/components/parameters/PlanCode"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PublishPlanVersionRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PlanVersion"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Plans"
        ]
      }
    },
    "/v1/plans/{code}/versions/{version}": {
      "get": {
        "operationId": "getPlanVersion",
        "summary": "Get a plan version (a number or \"latest\")",
        "parameters": [
          {
            "$ref": "#/components/parameters/PlanCode"
          },
          {
            "name": "version",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "examples": [
                "1",
                "latest"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PlanVersion"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Plans"
        ]
      }
    },
    "/v1/subscriptions": {
      "get": {
        "operationId": "listSubscriptions",
        "summary": "Subscriptions, newest first (or searched, narrowed and sorted)",
        "description": "With `search`, `sort`, `state`, `currency`, `interval`, `started_from` or `started_to` the list is searched, narrowed and sorted on the server: it pages by position and reports `total`.\n",
        "parameters": [
          {
            "name": "customer",
            "in": "query",
            "description": "Customer external id",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "page_size",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 200,
              "default": 50
            }
          },
          {
            "name": "page_token",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "search",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Words that must each appear in the customer's external id or name, the plan's code or name, or the provider"
          },
          {
            "name": "sort",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "newest",
                "oldest"
              ]
            },
            "description": "By start time"
          },
          {
            "name": "state",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "trialing, active, past_due, paused or cancelled, comma-separated: any of them"
          },
          {
            "name": "currency",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "ISO 4217 codes, comma-separated: any of them"
          },
          {
            "name": "interval",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "month or year, comma-separated"
          },
          {
            "name": "started_from",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "name": "started_to",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ListSubscriptionsResponse"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Subscriptions"
        ]
      },
      "post": {
        "operationId": "createSubscription",
        "summary": "Subscribe a customer to a plan version (at most one overlapping subscription per customer)",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateSubscriptionRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Subscription"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Subscriptions"
        ]
      }
    },
    "/v1/subscriptions/{id}": {
      "get": {
        "operationId": "getSubscription",
        "summary": "One subscription with its state",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Subscription"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Subscriptions"
        ]
      },
      "delete": {
        "operationId": "cancelSubscription",
        "summary": "End a subscription (now, or at end_time)",
        "description": "With credit_unused=true the fee paid in advance for the rest of the current period is credited to the customer's balance (for a subscription billed in advance that Payrudder runs, ended now, without a coupon). The response is always {subscription, credited_minor}; credited_minor is \"0\" when nothing was credited.\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "end_time",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "name": "credit_unused",
            "in": "query",
            "schema": {
              "type": "boolean",
              "default": false
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CancelSubscriptionResponse"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Subscriptions"
        ]
      }
    },
    "/v1/subscriptions/{id}/pause": {
      "post": {
        "operationId": "pauseSubscription",
        "summary": "Stop the fixed fee until the subscription is resumed (usage is still billed)",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Subscription"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Subscriptions"
        ]
      }
    },
    "/v1/subscriptions/{id}/resume": {
      "post": {
        "operationId": "resumeSubscription",
        "summary": "Resume a paused subscription",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Subscription"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Subscriptions"
        ]
      }
    },
    "/v1/subscriptions/{id}/end-trial": {
      "post": {
        "operationId": "endTrial",
        "summary": "End a running trial now",
        "description": "The subscription becomes active now, as if its trial had been that long: a subscription billed in advance has its first fee due now and its billing\nperiods start now; for one billed in arrears whose version has `prorate_after_trial`, the first period is charged from now. The plan's normal limits\nreplace the trial limits at once. Sends `subscription.updated` and `entitlement.updated`. A subscription with no trial running is refused with\n`plans.subscription.not_trialing`; one a payment provider runs with `plans.subscription.run_by_provider`.\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Subscription"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Subscriptions"
        ]
      }
    },
    "/v1/subscriptions/{id}/cancel-at-period-end": {
      "post": {
        "operationId": "scheduleCancellation",
        "summary": "End the subscription at the end of its current billing period",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Subscription"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Subscriptions"
        ]
      },
      "delete": {
        "operationId": "withdrawCancellation",
        "summary": "Withdraw a scheduled cancellation",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Subscription"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Subscriptions"
        ]
      }
    },
    "/v1/subscriptions/{id}/change-plan": {
      "post": {
        "operationId": "changePlan",
        "summary": "Move the subscription to another plan version now, prorating the fixed fee",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ChangePlanRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ChangePlanResponse"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Subscriptions"
        ]
      }
    },
    "/v1/subscriptions/{id}/change-preview": {
      "post": {
        "operationId": "previewSubscriptionChange",
        "summary": "What a change of plan or interval would cost, without making it",
        "description": "The same calculation as the change itself, so the preview is what is then billed. For subscriptions whose fee is invoiced in advance.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ChangeRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ChangeQuote"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Subscriptions"
        ]
      }
    },
    "/v1/plans/{code}/price-changes": {
      "post": {
        "operationId": "schedulePriceChange",
        "summary": "Move every subscription on one plan version to another at its next renewal, and tell the customers",
        "description": "For each Payrudder-run subscription on `from_version` whose next renewal is at least `notice_days` away (default 30, at least 14), a change to `to_version`\n(default: the latest published) is scheduled for that renewal and the customer is mailed, in their language, when the new price starts and what each renewal costs.\nWith `effective_from` the subscription moves on its first period start on or after that date instead. The customer is mailed when the run schedules it, so at\nleast `notice_days` before; with `notice_send_days_before` the mail is held and goes out that many days before the new price (never later than the customer's notice;\na mail that is due already goes at once). The notice is the longer of `notice_days` and the operator's minimum for the customer's country (not legal advice, UNVERIFIED).\nThe others are listed in `skipped` with why: `renews_soon` (run it again later), `has_pending_change` (a change is waiting and is never replaced),\n`run_by_provider`, `not_changeable` (for example a fee invoiced in arrears) and `customer_blocked` (a blocked customer is not offered a new price). `dry_run` counts and changes nothing.\nEach scheduled change also sends the `subscription.change_scheduled` webhook event, and the run sends `price_change.scheduled` once.\nThe run is recorded as a price change (`price_change_id`; see `GET /v1/price-changes`). Running it again for the same plan and versions continues the open one:\nthe skipped subscriptions are tried again, and the ones it scheduled before are counted in `already_scheduled` and neither scheduled nor mailed a second time.\n",
        "parameters": [
          {
            "name": "code",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SchedulePriceChangeRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SchedulePriceChangeResponse"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Plans"
        ]
      }
    },
    "/v1/price-changes": {
      "get": {
        "operationId": "listPriceChanges",
        "summary": "The price changes made, newest first",
        "description": "Each with the number of subscriptions that are waiting for their renewal (`scheduled`), were moved (`applied`), were withdrawn or were skipped. The latest 100.",
        "parameters": [
          {
            "name": "plan_code",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Only the price changes of this plan"
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ListPriceChangesResponse"
                }
              }
            }
          }
        },
        "tags": [
          "Price changes"
        ]
      }
    },
    "/v1/price-changes/{id}": {
      "get": {
        "operationId": "getPriceChange",
        "summary": "One price change with its subscriptions and what became of each",
        "description": "The subscriptions by customer, a page at a time (`page_size` 1 to 500, default 500; `next_page_token` is empty on the last page), optionally only those in one state. The state of a scheduled one follows its change - waiting (`scheduled`), `applied` at the renewal, or `withdrawn`.",
        "parameters": [
          {
            "$ref": "#/components/parameters/ID"
          },
          {
            "name": "state",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "scheduled",
                "applied",
                "withdrawn",
                "skipped"
              ]
            }
          },
          {
            "name": "page_size",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 500,
              "default": 500
            }
          },
          {
            "name": "page_token",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GetPriceChangeResponse"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Price changes"
        ]
      }
    },
    "/v1/price-changes/{id}/retry": {
      "post": {
        "operationId": "retryPriceChange",
        "summary": "Try the skipped subscriptions of a price change again",
        "description": "Runs the price change again with the notice it was made with, for the subscriptions that were skipped (a renewal that was too close may be far enough now) and any that joined the version since. What is scheduled already is left alone. Refused with 409 `plans.price_change.withdrawn` once it was withdrawn.",
        "parameters": [
          {
            "$ref": "#/components/parameters/ID"
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SchedulePriceChangeResponse"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Price changes"
        ]
      }
    },
    "/v1/price-changes/{id}/withdraw": {
      "post": {
        "operationId": "withdrawPriceChange",
        "summary": "Cancel every change of a price change that is still waiting",
        "description": "Closes the price change and cancels the scheduled changes that have not taken effect, so those customers stay on the old price. A change that was applied stays, and\nthe mail that was sent is not taken back (tell those customers yourself). Calling it again finishes what an interrupted call left; a new run makes a new price change.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/ID"
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WithdrawPriceChangeResponse"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Price changes"
        ]
      }
    },
    "/v1/subscriptions/{id}/change": {
      "post": {
        "operationId": "changeSubscription",
        "summary": "Move a subscription to another plan version and/or interval, now or at the end of the paid period",
        "description": "An upgrade or monthly-to-yearly change is immediate and prorated; a downgrade or yearly-to-monthly change waits for the end of the period the customer has paid for\n(a scheduled change, shown on the subscription). A change of `quantity` alone is immediate and prorated, more seats or fewer. Whatever moves money is invoiced, or becomes a credit balance when the new plan costs less than the unused old time was worth.\nAnswers 409 `ABORTED` if the fee of the current period has not been invoiced yet; try again in a moment.\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ChangeRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ChangeSubscriptionResponse"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Subscriptions"
        ]
      }
    },
    "/v1/subscriptions/{id}/checkout": {
      "post": {
        "operationId": "createSubscriptionCheckout",
        "summary": "The page where the customer starts a subscription a payment provider renews (Paddle)",
        "description": "For a running subscription whose provider renews subscriptions itself and that the customer has not subscribed to there yet. The answer is a Payrudder page (a portal link of the customer, valid for 7 days) with the provider's payment form inside it. Payrudder creates the plan's product and price at the provider when it holds none. Once the customer has paid, the provider's subscription.created notification links the provider's subscription to this one and the provider renews it from then on. 409 `plans.subscription.already_subscribed` when the customer has subscribed already, `plans.subscription.no_checkout` for a subscription Payrudder renews (its invoices are paid on their own pages).\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "url",
                    "expires_at"
                  ],
                  "properties": {
                    "url": {
                      "type": "string",
                      "description": "The page to send the customer to"
                    },
                    "expires_at": {
                      "type": "string",
                      "format": "date-time"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Subscriptions"
        ]
      }
    },
    "/v1/subscriptions/{id}/coupon": {
      "post": {
        "operationId": "applyCoupon",
        "summary": "Redeem a coupon on a subscription that has none",
        "description": "A coupon takes something off a fixed fee Payrudder invoices in advance. A subscription a provider renews uses a discount at the provider instead.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ApplyCouponRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Subscription"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Subscriptions"
        ]
      },
      "delete": {
        "operationId": "removeCoupon",
        "summary": "Take the coupon off a subscription (the redemption is not given back)",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Subscription"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Subscriptions"
        ]
      }
    },
    "/v1/tax-rates": {
      "get": {
        "operationId": "getTaxRates",
        "summary": "The tax Payrudder adds to the invoices it raises, by customer country",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TaxRates"
                }
              }
            }
          }
        },
        "tags": [
          "Tax rates"
        ]
      },
      "put": {
        "operationId": "setTaxRates",
        "summary": "Replace the tax rates",
        "description": "Payrudder applies the rates as given, exclusive of the price, to the invoices it raises (monthly usage, fees in advance, plan changes) for customers whose country has a rate, or the rate with an empty country. It does not work out what is due where; the rates and their correctness are the tenant's. Invoices of a subscription a provider runs are taxed by the provider.\n",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/TaxRatesInput"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TaxRates"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Tax rates"
        ]
      }
    },
    "/v1/dunning-settings": {
      "get": {
        "operationId": "getDunningSettings",
        "summary": "How long Payrudder waits before it retries a declined payment",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DunningSettings"
                }
              }
            }
          }
        },
        "tags": [
          "Dunning settings"
        ]
      },
      "put": {
        "operationId": "setDunningSettings",
        "summary": "Replace the retry delays",
        "description": "Up to six delays, each 1 to 720 hours (minutes in a sandbox tenant). A declined charge is retried after the first delay, then the second, and so on; when the delays run out the invoice is given up as uncollectible. An empty list gives up on the first decline.\n",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/DunningSettingsInput"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DunningSettings"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Dunning settings"
        ]
      }
    },
    "/v1/credit-packs": {
      "get": {
        "operationId": "listCreditPacks",
        "summary": "The credit packs the tenant sells",
        "description": "Not paged: the response is the complete list.",
        "parameters": [
          {
            "name": "active",
            "in": "query",
            "schema": {
              "type": "boolean"
            },
            "description": "true leaves out packs withdrawn from sale"
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CreditPackList"
                }
              }
            }
          }
        },
        "tags": [
          "Credit packs"
        ]
      },
      "post": {
        "operationId": "createCreditPack",
        "summary": "Add a credit pack",
        "description": "A pack is a number of credits for a price in one currency. A customer buys it through a payment link; the credits are granted when the payment is confirmed.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreditPackInput"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CreditPack"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Credit packs"
        ]
      }
    },
    "/v1/credit-packs/{id}/activate": {
      "post": {
        "operationId": "activateCreditPack",
        "summary": "Put a credit pack back on sale",
        "parameters": [
          {
            "$ref": "#/components/parameters/ID"
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EmptyObject"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Credit packs"
        ]
      }
    },
    "/v1/credit-packs/{id}/deactivate": {
      "post": {
        "operationId": "deactivateCreditPack",
        "summary": "Withdraw a credit pack from sale",
        "description": "Credits already sold are not touched.",
        "parameters": [
          {
            "$ref": "#/components/parameters/ID"
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EmptyObject"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Credit packs"
        ]
      }
    },
    "/v1/customers/{external_id}/credits": {
      "get": {
        "operationId": "getCreditBalance",
        "summary": "What a customer can spend now",
        "description": "The balance leaves out credits whose time has passed. `lots` shows where it comes from, the credits that expire first at the top.",
        "parameters": [
          {
            "$ref": "#/components/parameters/ExternalID"
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CreditBalance"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Customers"
        ]
      }
    },
    "/v1/customers/{external_id}/credits/grant": {
      "post": {
        "operationId": "grantCredits",
        "summary": "Add credits to a customer",
        "description": "For a promotion, a goodwill gesture or a sale made outside Payrudder. With an `idempotency_key` (or the `Idempotency-Key` header) a repeat of the call adds nothing and returns `replayed: true`; the same key with other values is `billing.credits.key_reused`.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/ExternalID"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreditGrantInput"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CreditResult"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Customers"
        ]
      }
    },
    "/v1/customers/{external_id}/credits/consume": {
      "post": {
        "operationId": "consumeCredits",
        "summary": "Spend credits",
        "description": "Takes the credits that expire first. With too few credits nothing is taken and the answer is 409 `billing.credits.insufficient`. An `idempotency_key` (or the `Idempotency-Key` header) is required: a retried call returns the first result with `replayed: true` instead of charging twice.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/ExternalID"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreditConsumeInput"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CreditResult"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Customers"
        ]
      }
    },
    "/v1/customers/{external_id}/credits/ledger": {
      "get": {
        "operationId": "listCreditLedger",
        "summary": "Every change to a customer's credits, newest first",
        "parameters": [
          {
            "$ref": "#/components/parameters/ExternalID"
          },
          {
            "name": "page_size",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 200,
              "default": 50
            }
          },
          {
            "name": "page_token",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CreditLedgerPage"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Customers"
        ]
      }
    },
    "/v1/credits/settings": {
      "get": {
        "operationId": "getCreditSettings",
        "summary": "The low-balance threshold of the credits.low event",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CreditSettings"
                }
              }
            }
          }
        },
        "tags": [
          "Credits"
        ]
      },
      "put": {
        "operationId": "setCreditSettings",
        "summary": "Set the low-balance threshold",
        "description": "A consume that takes a customer's balance from at least `low_threshold` credits to fewer announces `credits.low` once (the webhook event). 0, the default, turns it off.\n",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreditSettingsInput"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CreditSettings"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Credits"
        ]
      }
    },
    "/v1/webhook-endpoints": {
      "post": {
        "operationId": "createWebhookEndpoint",
        "summary": "Register an HTTPS endpoint that receives Payrudder's events",
        "description": "Payrudder sends a signed JSON POST to the endpoint for each event of the types it asks for (all types if none). The response carries the signing secret, once; it cannot be read again, only rotated. Verify each delivery with the `Payrudder-Signature` header: `t=<unix seconds>,v1=<hex HMAC-SHA256 of \"<t>.<raw body>\" with the secret>` (two `v1` while a rotated secret is still accepted); reject a timestamp more than five minutes from your clock. Answer 2xx within 10 seconds; anything else is retried after 1 minute, 5 minutes, 30 minutes, 2 hours, 6 hours and 24 hours, then given up (a delivery can be sent again by hand). Events are delivered at least once and not in order: use the event `id` to ignore repeats. The URL must be https and public; at most 20 endpoints.\n",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateWebhookEndpointRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WebhookEndpoint"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Webhook endpoints"
        ]
      },
      "get": {
        "operationId": "listWebhookEndpoints",
        "summary": "The tenant's webhook endpoints",
        "description": "Not paged: the response is the complete list.",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ListWebhookEndpointsResponse"
                }
              }
            }
          }
        },
        "tags": [
          "Webhook endpoints"
        ]
      }
    },
    "/v1/webhook-endpoints/{id}": {
      "put": {
        "operationId": "updateWebhookEndpoint",
        "summary": "Replace an endpoint's url, description, event types and active flag",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/WebhookEndpointInput"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WebhookEndpoint"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Webhook endpoints"
        ]
      },
      "delete": {
        "operationId": "deleteWebhookEndpoint",
        "summary": "Delete an endpoint and its delivery history",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Deleted"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Webhook endpoints"
        ]
      }
    },
    "/v1/webhook-endpoints/{id}/rotate-secret": {
      "post": {
        "operationId": "rotateWebhookSecret",
        "summary": "Make a new signing secret (returned once); the old one keeps signing for 24 hours",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WebhookEndpoint"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Webhook endpoints"
        ]
      }
    },
    "/v1/webhook-endpoints/{id}/test": {
      "post": {
        "operationId": "sendTestWebhook",
        "summary": "Send a ping event to one endpoint",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "202": {
            "description": "Queued",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WebhookDelivery"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Webhook endpoints"
        ]
      }
    },
    "/v1/webhook-deliveries": {
      "get": {
        "operationId": "listWebhookDeliveries",
        "summary": "Deliveries, newest first, with how each attempt went",
        "parameters": [
          {
            "name": "endpoint_id",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "state",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "pending",
                "delivered",
                "failed"
              ]
            }
          },
          {
            "name": "page_size",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 200,
              "default": 50
            }
          },
          {
            "name": "page_token",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ListWebhookDeliveriesResponse"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Webhook deliveries"
        ]
      }
    },
    "/v1/webhook-deliveries/{id}/redeliver": {
      "post": {
        "operationId": "redeliverWebhook",
        "summary": "Send a delivery again from the start, whatever became of it",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "202": {
            "description": "Queued",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WebhookDelivery"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Webhook deliveries"
        ]
      }
    },
    "/v1/coupons": {
      "post": {
        "operationId": "createCoupon",
        "summary": "Make a coupon",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CouponInput"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Coupon"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Coupons"
        ]
      },
      "get": {
        "operationId": "listCoupons",
        "summary": "Coupons, newest first",
        "description": "Not paged: the response is the complete list.",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ListCouponsResponse"
                }
              }
            }
          }
        },
        "tags": [
          "Coupons"
        ]
      }
    },
    "/v1/coupons/{code}": {
      "delete": {
        "operationId": "deactivateCoupon",
        "summary": "Stop new redemptions of a coupon (subscriptions that have it keep it)",
        "parameters": [
          {
            "name": "code",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Coupon"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Coupons"
        ]
      }
    },
    "/v1/coupons/{code}/promotion-codes": {
      "post": {
        "operationId": "createPromotionCodes",
        "summary": "Make promotion codes for a coupon",
        "description": "Name the codes (2-40 letters, digits, - or _; the same in any case) or ask for count random ones (1-1000, prefix + 8 characters without 0, O, 1, I, L). Every code gets the template's limit, expiry and restrictions.",
        "parameters": [
          {
            "name": "code",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreatePromotionCodes"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CreatePromotionCodesResponse"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Coupons"
        ]
      }
    },
    "/v1/promotion-codes": {
      "get": {
        "operationId": "listPromotionCodes",
        "summary": "Promotion codes, newest first",
        "description": "The codes people type. A campaign's code is not listed here; see /v1/campaigns.",
        "parameters": [
          {
            "name": "coupon",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Only the codes of this coupon"
          },
          {
            "name": "state",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "active",
                "inactive"
              ]
            }
          },
          {
            "name": "search",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Part of the code"
          },
          {
            "name": "page_size",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 200,
              "default": 50
            }
          },
          {
            "name": "page_token",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ListPromotionCodesResponse"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Promotion codes"
        ]
      }
    },
    "/v1/promotion-codes/{code}": {
      "delete": {
        "operationId": "deactivatePromotionCode",
        "summary": "Stop new redemptions of one code (the coupon and its other codes keep working)",
        "parameters": [
          {
            "name": "code",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PromotionCode"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Promotion codes"
        ]
      }
    },
    "/v1/campaigns": {
      "post": {
        "operationId": "createCampaign",
        "summary": "Start a campaign, a discount that applies without a code",
        "description": "A campaign takes its discount off new purchases of its plans (new subscriptions) or credit packs from start_time up to expire_time, without a typed code. A typed code replaces it; renewals never get it. Two campaigns whose windows overlap may not share a plan or pack (an empty list means all of them): 409 coupon.campaign_overlap. The campaign is a coupon (coupon_code) with one code of its own (code). Sends campaign.started and campaign.ended.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CampaignInput"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Campaign"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Campaigns"
        ]
      },
      "get": {
        "operationId": "listCampaigns",
        "summary": "Campaigns, latest start first",
        "description": "Not paged: the response is the complete list.",
        "parameters": [
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "upcoming",
                "running",
                "ended"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ListCampaignsResponse"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Campaigns"
        ]
      }
    },
    "/v1/campaigns/{code}": {
      "delete": {
        "operationId": "endCampaign",
        "summary": "End a campaign now (purchases already made keep their discount)",
        "parameters": [
          {
            "name": "code",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The campaign's code"
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Campaign"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Campaigns"
        ]
      }
    },
    "/v1/coupon-redemptions": {
      "get": {
        "operationId": "listCouponRedemptions",
        "summary": "Uses of coupons, newest first",
        "description": "One row per use: the coupon and the code, the customer, what it was used on (the subscription, or the invoice of the purchase) and what it took off. A void or a full refund marks the row reversed.",
        "parameters": [
          {
            "name": "coupon",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "promotion_code",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "customer_external_id",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "page_size",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 200,
              "default": 50
            }
          },
          {
            "name": "page_token",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ListCouponRedemptionsResponse"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Coupon redemptions"
        ]
      }
    },
    "/v1/promotions/quote": {
      "post": {
        "operationId": "quotePromotion",
        "summary": "What a code would take off a purchase (claims nothing)",
        "description": "For a checkout page of your own. The answer is the discount or the bonus credits, or an error with a coupon.* key: coupon.expired, coupon.exhausted, coupon.not_applicable, coupon.currency_mismatch, coupon.already_used and the others in the error key list.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PromotionQuoteRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PromotionQuote"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Promotions"
        ]
      }
    },
    "/v1/customers/{external_id}/coupons": {
      "post": {
        "operationId": "grantCustomerCoupon",
        "summary": "Give a customer a coupon that their next eligible checkout uses without a code",
        "description": "One grant per (customer, source, source_ref); repeating it grants nothing more.",
        "parameters": [
          {
            "name": "external_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/GrantCustomerCouponRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GrantCustomerCouponResponse"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Customers"
        ]
      }
    },
    "/v1/affiliates/program": {
      "get": {
        "operationId": "getAffiliateProgram",
        "summary": "The partner program of this environment",
        "description": "One program per environment, so the sandbox and live have their own. 404 with the key affiliate.program.not_set before one is set.",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AffiliateProgram"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Affiliates"
        ]
      },
      "put": {
        "operationId": "setAffiliateProgram",
        "summary": "Set the rules of the partner program",
        "description": "Replaces the program. A change applies to commissions earned from then on, never to those already earned. A commission is a share of the net, pre-tax amount of a paid invoice (percent_bps) or a fixed amount in one currency (fixed, earned only on invoices in that currency).",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AffiliateProgramInput"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AffiliateProgram"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Affiliates"
        ]
      }
    },
    "/v1/affiliates": {
      "post": {
        "operationId": "createAffiliate",
        "summary": "Add a partner",
        "description": "The code (3 to 32 letters, numbers, - or _) is unique across the whole platform because the public link /r/<code> carries no tenant; leave it out for a random one. A partner you add is active unless you ask for pending.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateAffiliateRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Affiliate"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Affiliates"
        ]
      },
      "get": {
        "operationId": "listAffiliates",
        "summary": "Partners, newest first",
        "parameters": [
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "pending",
                "active",
                "suspended"
              ]
            }
          },
          {
            "name": "search",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Part of the code, e-mail address or name"
          },
          {
            "name": "page_size",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 200,
              "default": 50
            }
          },
          {
            "name": "page_token",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ListAffiliatesResponse"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Affiliates"
        ]
      }
    },
    "/v1/affiliates/referrals": {
      "get": {
        "operationId": "listAffiliateReferrals",
        "summary": "The customers partners brought, newest first",
        "description": "The customer's e-mail address is masked (j***@example.com).",
        "parameters": [
          {
            "name": "affiliate_id",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Only this partner's"
          },
          {
            "name": "page_size",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 200,
              "default": 50
            }
          },
          {
            "name": "page_token",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ListAffiliateReferralsResponse"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Affiliates"
        ]
      }
    },
    "/v1/affiliates/commissions": {
      "get": {
        "operationId": "listAffiliateCommissions",
        "summary": "Commissions and the reversal rows that net against them, newest first",
        "description": "One commission per paid invoice of a customer a partner brought, in the invoice's currency, on the net, pre-tax amount paid. It is pending for the program's hold (the refund window), then approved, then paid by a payout. A refund, void or credit note takes it back (reversed_minor); one already paid is netted by a negative row of kind reversal that the next payout takes.",
        "parameters": [
          {
            "name": "affiliate_id",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "pending",
                "approved",
                "paid",
                "reversed"
              ]
            }
          },
          {
            "name": "kind",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "commission",
                "reversal"
              ]
            }
          },
          {
            "name": "invoice_id",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "payout_id",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "from",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time"
            },
            "description": "Earned at or after"
          },
          {
            "name": "to",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time"
            },
            "description": "Earned before"
          },
          {
            "name": "page_size",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 200,
              "default": 50
            }
          },
          {
            "name": "page_token",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ListAffiliateCommissionsResponse"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Affiliates"
        ]
      }
    },
    "/v1/affiliates/commissions/reverse": {
      "post": {
        "operationId": "reverseAffiliateCommission",
        "summary": "Take a commission back for a chargeback, or by hand",
        "description": "Refunds, voids and credit notes reverse on their own. The same (invoice, reason, reference) takes back once. A commission that was paid is netted from the partner's next payout.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ReverseAffiliateCommissionRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ReverseAffiliateCommissionResponse"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Affiliates"
        ]
      }
    },
    "/v1/affiliates/balances": {
      "get": {
        "operationId": "getAffiliateBalances",
        "summary": "What each partner has, per currency",
        "description": "pending (in the hold), approved (available for a payout, net of reversals), paid (paid out, net of what was netted) and reversed (taken back in all). Currencies are never added together.",
        "parameters": [
          {
            "name": "affiliate_id",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GetAffiliateBalancesResponse"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Affiliates"
        ]
      }
    },
    "/v1/affiliates/funnel": {
      "get": {
        "operationId": "getAffiliateFunnel",
        "summary": "Clicks, referred customers, paying customers and commissions over a period",
        "parameters": [
          {
            "name": "from",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date"
            },
            "description": "First day, UTC; default 30 days before to"
          },
          {
            "name": "to",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date"
            },
            "description": "Last day, UTC; default today"
          },
          {
            "name": "affiliate_id",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AffiliateFunnel"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Affiliates"
        ]
      }
    },
    "/v1/affiliates/payouts": {
      "get": {
        "operationId": "listAffiliatePayouts",
        "summary": "Payouts to partners, newest first",
        "description": "A payout is the approved commissions of one partner in one currency (no conversion), with the negative rows that net earlier payments taken back. An open payout is worth what its commissions are worth now.",
        "parameters": [
          {
            "name": "affiliate_id",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "open",
                "paid",
                "cancelled"
              ]
            }
          },
          {
            "name": "page_size",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 200,
              "default": 50
            }
          },
          {
            "name": "page_token",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ListAffiliatePayoutsResponse"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Affiliates"
        ]
      },
      "post": {
        "operationId": "createAffiliatePayouts",
        "summary": "Batch the approved commissions into open payouts",
        "description": "For one partner or for every active partner, one payout per currency. A batch below the program's minimum payout, or not above zero, is skipped and reported; what is approved later joins a payout that is still open. A suspended partner is not paid; their balance is kept. A live environment that is not active pays nobody (affiliate.payout.tenant_not_active).",
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateAffiliatePayoutsRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CreateAffiliatePayoutsResponse"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Affiliates"
        ]
      }
    },
    "/v1/affiliates/payouts/{id}/pay": {
      "post": {
        "operationId": "markAffiliatePayoutPaid",
        "summary": "Record that you paid a payout, and post it",
        "description": "Payrudder moves no money: pay by hand or bank transfer, then say so. The commissions become paid and the journal gets the commission expense against the payable, and the payable against cash, balanced in the payout's currency. Doing it again changes nothing. In the sandbox the payout is fake and its postings say so.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/MarkAffiliatePayoutPaidRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AffiliatePayout"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Affiliates"
        ]
      }
    },
    "/v1/affiliates/payouts/{id}/cancel": {
      "post": {
        "operationId": "cancelAffiliatePayout",
        "summary": "Drop an open payout",
        "description": "Its commissions go back to being payable in another payout.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AffiliatePayout"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Affiliates"
        ]
      }
    },
    "/v1/affiliates/journal": {
      "get": {
        "operationId": "listAffiliateJournal",
        "summary": "The postings of paid payouts, with debit and credit totals per currency",
        "description": "totals cover the whole filter, not only the page. The books balance when debits equal credits in every currency; the database refuses to commit postings that do not.",
        "parameters": [
          {
            "name": "payout_id",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "currency",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "from",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "name": "to",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "name": "page_size",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 200,
              "default": 50
            }
          },
          {
            "name": "page_token",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ListAffiliateJournalResponse"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Affiliates"
        ]
      }
    },
    "/v1/affiliates/journal.csv": {
      "get": {
        "operationId": "exportAffiliateJournal",
        "summary": "The same postings as a CSV file, with a total line per currency",
        "parameters": [
          {
            "name": "payout_id",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "currency",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "from",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "name": "to",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "text/csv": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Affiliates"
        ]
      }
    },
    "/v1/affiliates/{id}": {
      "get": {
        "operationId": "getAffiliate",
        "summary": "One partner with their click and referral counts",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Affiliate"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Affiliates"
        ]
      },
      "patch": {
        "operationId": "updateAffiliate",
        "summary": "Change a partner's name, payout details or status",
        "description": "status active approves a pending partner or reinstates a suspended one; suspended stops new attributions and commissions but keeps what was approved. Nothing returns to pending.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UpdateAffiliateRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Affiliate"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Affiliates"
        ]
      }
    },
    "/v1/affiliates/{id}/promotion-code": {
      "put": {
        "operationId": "linkAffiliatePromotionCode",
        "summary": "Make a promotion code the partner's",
        "description": "A customer who redeems the code at a checkout is attributed to the partner, as if they had followed the link.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/LinkAffiliatePromotionCodeRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Affiliate"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Affiliates"
        ]
      }
    },
    "/v1/customers/{external_id}/referral": {
      "post": {
        "operationId": "attributeCustomer",
        "summary": "Say which partner brought a customer",
        "description": "For your own sign-up, which reads the ?ref= of the link. First touch wins: a customer who has an attribution keeps it. A refusal is a normal answer (attributed false and a reason), not an error: already_attributed, unknown_code, program_inactive, affiliate_inactive, expired, same_email, same_domain, same_payment_method.",
        "parameters": [
          {
            "name": "external_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AttributeCustomerRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AttributeCustomerResponse"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Customers"
        ]
      }
    },
    "/v1/subscriptions/{id}/scheduled-change": {
      "delete": {
        "operationId": "cancelScheduledChange",
        "summary": "Withdraw the change waiting for the end of the period",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Subscription"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Subscriptions"
        ]
      }
    },
    "/v1/reports/revenue": {
      "get": {
        "operationId": "getRevenueReport",
        "summary": "Invoices summed by period, payment provider, customer country and currency (currencies are never added together)",
        "parameters": [
          {
            "name": "from",
            "in": "query",
            "description": "First period, YYYY-MM",
            "schema": {
              "type": "string",
              "pattern": "^[0-9]{4}-(0[1-9]|1[0-2])$"
            }
          },
          {
            "name": "to",
            "in": "query",
            "description": "Last period, YYYY-MM",
            "schema": {
              "type": "string",
              "pattern": "^[0-9]{4}-(0[1-9]|1[0-2])$"
            }
          },
          {
            "name": "group_by",
            "in": "query",
            "description": "Comma-separated: period, provider, country (default period). Currency is always split",
            "schema": {
              "type": "string",
              "examples": [
                "period,provider"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GetRevenueReportResponse"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Reports"
        ]
      }
    },
    "/v1/reports/dunning": {
      "get": {
        "operationId": "getDunningReport",
        "summary": "Invoices whose payment has not gone through (declined and retrying, outcome unknown, given up)",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 500,
              "default": 100
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GetDunningReportResponse"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Reports"
        ]
      }
    },
    "/v1/reports/subscriptions": {
      "get": {
        "operationId": "getSubscriptionReport",
        "summary": "Subscriptions and monthly recurring revenue at the end of a month, with the new and the churned, by provider, country and currency",
        "parameters": [
          {
            "name": "month",
            "in": "query",
            "description": "YYYY-MM in the tenant's time zone; default the current month",
            "schema": {
              "type": "string",
              "pattern": "^[0-9]{4}-(0[1-9]|1[0-2])$"
            }
          },
          {
            "name": "group_by",
            "in": "query",
            "description": "Comma-separated: provider, country. Currency is always split",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GetSubscriptionReportResponse"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Reports"
        ]
      }
    },
    "/v1/routing-rules": {
      "get": {
        "operationId": "getRoutingRules",
        "summary": "The ordered rules that choose a new subscription's payment provider from the customer's country and the subscription's currency",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RoutingRules"
                }
              }
            }
          }
        },
        "tags": [
          "Routing rules"
        ]
      },
      "put": {
        "operationId": "setRoutingRules",
        "summary": "Replace the rules (first match wins; a rule with neither country nor currency is the catch-all and must be last). Existing subscriptions keep their provider",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/RoutingRulesInput"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RoutingRules"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Routing rules"
        ]
      }
    },
    "/v1/mail-settings": {
      "get": {
        "operationId": "getMailSettings",
        "summary": "Which kinds of e-mail Payrudder sends for the tenant (all on until switched off, except customer_notices, which is off until switched on)",
        "description": "Categories: `invoice_issued`, `payment_receipts`, `payment_failed`, `usage_alerts`, `system`, `customer_notices`. `customer_notices` is the notice to a customer that the seller blocked them or lifted the block (never with the seller's reason); it is **off** until the tenant switches it on, the other categories are on. A mail of a category that is off is dropped by the notifier\n(counted in `notifier_mail_dropped_total`), not retried. Whether a provider sends its own receipts is a separate rule (Paddle does, so Payrudder sends none for its payments).\n",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/MailSettings"
                }
              }
            }
          }
        },
        "tags": [
          "Mail settings"
        ]
      },
      "put": {
        "operationId": "setMailSettings",
        "summary": "Switch the listed categories on or off; the others keep their setting",
        "description": "An unknown category is rejected with the error key `plans.mail.unknown_category`. A category listed twice takes its last value.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/MailSettingsInput"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Every category with its new state",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/MailSettings"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Mail settings"
        ]
      }
    },
    "/v1/mail-suppressions": {
      "get": {
        "operationId": "listMailSuppressions",
        "summary": "The addresses the tenant's mail is not sent to",
        "description": "An address lands here when its mail bounced for good, drew a complaint, or the operator put it here by hand. Mail to it is dropped as done, whatever the mail is.\nIn address order, a page at a time (`page_size` 1 to 500, default 50; `next_page_token` is empty on the last page). On a deployment whose gateway is not connected to\nthe notifier the answer is 200 with an empty list and `connected` false (lifting an address, which is an action, answers 503 `gateway.mail.unavailable` there).\n",
        "parameters": [
          {
            "name": "page_size",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 500,
              "default": 50
            }
          },
          {
            "name": "page_token",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ListMailSuppressionsResponse"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "503": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Mail suppressions"
        ]
      }
    },
    "/v1/mail-suppressions/{address}": {
      "delete": {
        "operationId": "deleteMailSuppression",
        "summary": "Mail an address again",
        "description": "Lifts the suppression of one address. Lifting an address that is not on the list is 404 `gateway.mail.suppression_not_found`. An address that bounces again is put back by that bounce.",
        "parameters": [
          {
            "name": "address",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Lifted"
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "503": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Mail suppressions"
        ]
      }
    },
    "/v1/mail-messages": {
      "get": {
        "operationId": "listMailMessages",
        "summary": "The tenant's recent mail, newest first",
        "description": "The mail the notifier sent for the tenant's customers with what became of each: `sending`, `sent`, and what the provider reported (`delivered`, `delayed`,\n`bounced` for good, `soft_bounced`, `complained`). Mail without a tenant (Payrudder's own) is not in it. A page at a time (`page_size` 1 to 500, default 50).\nOn a deployment whose gateway is not connected to the notifier the answer is 200 with an empty list and `connected` false.\n",
        "parameters": [
          {
            "name": "page_size",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 500,
              "default": 50
            }
          },
          {
            "name": "page_token",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ListMailMessagesResponse"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "503": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Mail messages"
        ]
      }
    },
    "/v1/mail-previews/price-change": {
      "post": {
        "operationId": "previewPriceChangeMail",
        "summary": "The notice a customer would get of a price change, without sending anything",
        "description": "Renders the price-change notice in the language given (the tenant's default when none), with the date written in the tenant's time zone and the amount, in the tenant's\ncurrency, the way that language writes money. It is the mail the notifier would send; nothing is sent or kept. Show `html` in a sandboxed frame.\n",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PriceChangeMailPreviewRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RenderedMail"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "503": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Mail previews"
        ]
      }
    },
    "/v1/routing-rules/preview": {
      "post": {
        "operationId": "previewRouting",
        "summary": "Where a customer in a country paying in a currency would go, without creating anything",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PreviewRoutingRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PreviewRoutingResponse"
                }
              }
            }
          }
        },
        "tags": [
          "Routing rules"
        ]
      }
    },
    "/v1/invoices": {
      "get": {
        "operationId": "listInvoices",
        "summary": "List invoices (ordered by id, or searched, narrowed and sorted)",
        "description": "With `search`, `sort`, `kind`, `created_from`, `created_to` or more than one `status` the list is searched, narrowed and sorted on the server: it is ordered by `sort` (newest first when unset), pages by position and reports `total`. Without them it is in id order and pages by a keyset token.\n",
        "parameters": [
          {
            "name": "customer",
            "in": "query",
            "description": "Customer external id",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "period",
            "in": "query",
            "schema": {
              "type": "string",
              "pattern": "^[0-9]{4}-(0[1-9]|1[0-2])$"
            }
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "draft, open, paid, uncollectible or void; several comma-separated: any of them"
          },
          {
            "name": "page_size",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 500,
              "default": 100
            }
          },
          {
            "name": "page_token",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "search",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Words that must each appear in the invoice number, the customer's external id or name, or the period"
          },
          {
            "name": "sort",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "newest",
                "oldest",
                "amount",
                "-amount"
              ]
            }
          },
          {
            "name": "kind",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "REGULAR, CORRECTION, FEE or LINK, comma-separated: any of them"
          },
          {
            "name": "created_from",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time"
            },
            "description": "Created at or after this time (a plain date is the start of that day, UTC)"
          },
          {
            "name": "created_to",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time"
            },
            "description": "Created before this time"
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ListInvoicesResponse"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Invoices"
        ]
      }
    },
    "/v1/credit-notes": {
      "get": {
        "operationId": "listCreditNotes",
        "summary": "Credit notes, newest first",
        "parameters": [
          {
            "name": "invoice_id",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "customer",
            "in": "query",
            "description": "Customer external id",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "page_size",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 200,
              "default": 50
            }
          },
          {
            "name": "page_token",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ListCreditNotesResponse"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Credit notes"
        ]
      }
    },
    "/v1/credit-notes/{id}/retry-refund": {
      "post": {
        "operationId": "retryCreditNoteRefund",
        "summary": "Ask the payment provider again for a refund to the card that failed",
        "description": "Only a credit note whose refund failed: `409 billing.credit_note.refund_not_failed` for any other. Settling a failed refund by hand (it was made at the provider some other way) is the operator's. Needs `invoices:write`.\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CreditNote"
                }
              }
            }
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Credit notes"
        ]
      }
    },
    "/v1/credit-notes/{id}": {
      "get": {
        "operationId": "getCreditNote",
        "summary": "A credit note",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CreditNote"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Credit notes"
        ]
      }
    },
    "/v1/invoices/{id}": {
      "get": {
        "operationId": "getInvoice",
        "summary": "One invoice with its lines",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Invoice"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Invoices"
        ]
      }
    },
    "/v1/invoices/{id}/links": {
      "post": {
        "operationId": "createInvoiceLink",
        "summary": "Make a link to the invoice that its customer can open without signing in",
        "description": "The link shows the finalized invoice as a page, and its PDF once it is rendered. It is unguessable (256 random bits; only a hash is kept), works until expires_in_days (default 90, at most 365) or until revoked, and the token is returned once. The page is not indexed or cached, loads nothing from elsewhere, and is available in English, Turkish, German, French, Spanish and Arabic (`?lang=` or the browser's language). The url is absolute when the deployment has a public address set.\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateInvoiceLinkRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CreateInvoiceLinkResponse"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Invoices"
        ]
      },
      "delete": {
        "operationId": "revokeInvoiceLinks",
        "summary": "Make every link to the invoice stop working",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RevokeInvoiceLinksResponse"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Invoices"
        ]
      }
    },
    "/v1/payment-links": {
      "post": {
        "operationId": "createPaymentLink",
        "summary": "Make a payment link for an open invoice, or ad hoc for a fixed amount",
        "description": "`kind: invoice` (needs `invoice_id`, a finalized unpaid invoice) or `kind: adhoc` (needs `amount_minor`, optionally `currency` - the tenant's by default - `description` and a `customer_external_id`; the invoice is made when the customer first presses Continue). The token is returned once. `Idempotency-Key` (or `idempotency_key`) makes a retry return the link made the first time, without the token (`replayed: true`); the same key with other parameters is refused. Single-use links stop after one paid invoice; a reusable ad-hoc link makes one invoice per use.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreatePaymentLinkRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Replayed: the link made the first time, without the token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CreatedPaymentLink"
                }
              }
            }
          },
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CreatedPaymentLink"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Payment links"
        ]
      },
      "get": {
        "operationId": "listPaymentLinks",
        "summary": "List payment links",
        "parameters": [
          {
            "name": "kind",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "invoice",
                "adhoc"
              ]
            }
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "active",
                "paid",
                "expired",
                "revoked"
              ]
            }
          },
          {
            "name": "invoice_id",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "customer",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "The customer's external id"
          },
          {
            "name": "page_size",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 200,
              "default": 50
            }
          },
          {
            "name": "page_token",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ListPaymentLinksResponse"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Payment links"
        ]
      }
    },
    "/v1/payment-links/{id}": {
      "get": {
        "operationId": "getPaymentLink",
        "summary": "One payment link",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PaymentLink"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Payment links"
        ]
      },
      "delete": {
        "operationId": "revokePaymentLink",
        "summary": "Revoke a payment link",
        "description": "The link and the invoice links it handed out stop working. Unpaid invoices made from an ad-hoc link are voided; paid ones are untouched. Revoking twice is not an error.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PaymentLink"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Payment links"
        ]
      }
    },
    "/v1/customers/{external_id}/session": {
      "put": {
        "operationId": "connectCustomer",
        "summary": "Connect a customer and get the link to their customer page",
        "description": "The one call a sign-in needs. `external_id` is your own id of the customer: a person's user id, or for an organisation your organisation id with\nthe signed-in user as `member`. The customer is created when it does not exist, and its name, e-mail and language are updated when they changed\n(unchanged values write nothing). A `member` is added or updated; the first member of an organisation becomes its billing owner and every member\nuses the service. The link to the customer page is made for the billing owner only (for anybody else `url` is null and `billing_owner` false); it\nworks for `expires_in_days` (default 1). With `plan_code` and no running subscription, the page opens with that plan chosen. A new organisation\nwithout `email` takes its first member's e-mail as its billing contact.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/ExternalID"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ConnectCustomerRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ConnectCustomerResponse"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Customers"
        ]
      }
    },
    "/v1/customers/{external_id}/access": {
      "get": {
        "operationId": "getCustomerAccess",
        "summary": "Whether the customer may use the service now, by subscription, payment and limits",
        "description": "One answer for a middleware: the customer's subscription, the meters asked for, `allowed` and the `reason` that decided. An unknown customer is\n200 with `allowed` false and reason `no_customer`. `notices` lists what to show the customer, ready for a banner. Denied: `suspended` (you suspended the service), `no_subscription`, `cancelled`, `paused`,\n`unpaid` (an invoice became uncollectible), `awaiting_payment` (the first fee invoice is not paid yet, outside a trial), `limit_reached` (a meter asked\nfor is at a hard limit; limits count in a trial too) and `not_member` (`member` given and not a member of the customer). Allowed: `ok`, `trialing`\nand `past_due` (a renewal is being retried; show a notice). For an organisation ask with the organisation id: every member gets the same answer.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/ExternalID"
          },
          {
            "name": "meters",
            "in": "query",
            "description": "Meter codes, comma-separated, at most 20",
            "schema": {
              "type": "string",
              "examples": [
                "api_calls,seats"
              ]
            }
          },
          {
            "name": "member",
            "in": "query",
            "description": "Your own id of the person; checks that they are a member of the customer",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CustomerAccess"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Customers"
        ]
      }
    },
    "/v1/customers/{external_id}/portal-links": {
      "post": {
        "operationId": "createPortalLink",
        "summary": "Make the link to a customer's payment page",
        "description": "Shows the customer's invoices, payments, PDFs and receipts, read-only, with a pay button on open invoices. Works until expires_in_days (default 30, at most 365) or until revoked; the token is returned once.",
        "parameters": [
          {
            "name": "external_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreatePortalLinkRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CreatePortalLinkResponse"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Customers"
        ]
      },
      "delete": {
        "operationId": "revokePortalLinks",
        "summary": "Make every portal link of the customer stop working",
        "parameters": [
          {
            "name": "external_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RevokePortalLinksResponse"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Customers"
        ]
      }
    },
    "/v1/customers/{external_id}/payments": {
      "get": {
        "operationId": "listCustomerPayments",
        "summary": "The customer's invoices and the payments recorded for them",
        "description": "The same rows the customer sees on their payment page, newest first (charges and refunds from the ledger; an invoice may have several attempts).",
        "parameters": [
          {
            "name": "external_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 200,
              "default": 100
            },
            "description": "How many invoices to read; there is no page_token, so a customer with more invoices cannot be listed completely"
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ListCustomerPaymentsResponse"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "503": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Customers"
        ]
      }
    },
    "/v1/invoices/{id}/pdf": {
      "get": {
        "operationId": "getInvoicePdf",
        "summary": "A presigned link to the invoice PDF (valid for 5 minutes)",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SignedUrl"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Invoices"
        ]
      }
    },
    "/v1/invoices/{id}/payment-wait": {
      "get": {
        "operationId": "getInvoicePaymentWait",
        "summary": "What an invoice's payment is waiting for (a first charge that is held, a customer who has to confirm it)",
        "description": "Only `state` is always set. `PAYMENT_HELD`: the first charge was not sent because the payment gate said no (see `hold_reason`); `since_time` is when it began to be held and `next_check_time` when Payrudder looks again (it charges the invoice then if nothing holds it any more). `PAYMENT_ACTION_REQUIRED`: the card needs the customer to confirm the payment with their bank (3-D Secure); the customer was mailed a link to the invoice page at `since_time` (the mail log says whether it arrived), Payrudder asks the provider again at `next_check_time`, and if the customer has not confirmed by `window_ends_time` the payment counts as declined and dunning applies. Any other state answers the state alone.\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PaymentWait"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Invoices"
        ]
      }
    },
    "/v1/invoices/{id}/release": {
      "post": {
        "operationId": "releaseHeldInvoice",
        "summary": "Ask again for an invoice whose first charge is held, and charge it if nothing holds it any more",
        "description": "Payrudder asks the payment gate again, as it does every hour. When the gate lets the invoice through the charge is sent now (answer `PAYMENT_REQUESTED`); when the customer is still blocked for fraud or a chargeback, or the environment is on hold, the invoice stays held (answer `PAYMENT_HELD`, see `hold_reason` of the payment-wait read): to charge a blocked customer, lift the block first. `409 billing.invoice.not_held` when the invoice's first charge is not held. Recorded in the audit log.\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InvoiceSaga"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Invoices"
        ]
      }
    },
    "/v1/invoices/{id}/credit-notes": {
      "post": {
        "operationId": "createCreditNote",
        "summary": "Correct one of your paid invoices with a numbered credit note, added to the customer's credit balance or refunded to the card",
        "description": "An issued invoice is never edited. The note's amount goes to the customer's credit balance in the invoice's currency and pays their next invoice, or, with refund_to_card, back to the card through the payment provider that took the payment (the note's refund_state says whether it went through; a refund nobody answers is sent again, and a failed one can be retried with POST /v1/credit-notes/{id}/retry-refund). The notes of an invoice never add up to more than the invoice. Only a paid invoice can be credited: `409 billing.credit_note.not_paid` for any other, `409 billing.credit_note.fully_credited` when nothing is left of it, `409 billing.credit_note.nothing_to_refund` when refund_to_card is asked of a payment no provider can return. Works on the invoices of the key's (or the signed-in person's) own environment only. Needs `invoices:write`. Recorded in the audit log (`credit_note.issued`).\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateCreditNoteRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CreditNote"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Invoices"
        ]
      }
    },
    "/v1/invoices/{id}/void": {
      "post": {
        "operationId": "voidHeldInvoice",
        "summary": "Void an invoice whose first charge is held",
        "description": "Nothing was charged, so nothing is refunded; the invoice becomes `void` (answer `VOIDED`) and the `invoice.voided` webhook event is sent. Only an invoice whose first charge is held can be voided here: `409 billing.invoice.not_held` for any other, a paid one included. Recorded in the audit log.\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InvoiceSaga"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Invoices"
        ]
      }
    },
    "/v1/audit-events": {
      "get": {
        "operationId": "listAuditEvents",
        "summary": "The audit log of the tenant, newest first",
        "description": "Who did what and when, for the actions that change money or access: API keys created, rotated and revoked; members invited, changed and removed; plan versions published; webhook endpoints created, changed, deleted and their secrets rolled; customers blocked and unblocked; credit notes and refunds; the operator's invoice actions; payment provider accounts connected, replaced, removed and made the default; the tenant's status and settings. Each entry has the actor (a person, an API key, the operator or the system), the target, a one-line summary with no secret in it, a small `detail` object, the address and the request id. The log is append-only: the database refuses any change to an entry. It is read from several services and merged; when one does not answer, `incomplete` is true and `unavailable_sources` names it. Needs the permission `audit:read` (an admin key has it; the `read_only` role does not). A person who is a viewer of the account may not read it.\n",
        "parameters": [
          {
            "name": "action",
            "in": "query",
            "description": "Action names such as api_key.created, or an area such as api_key.*, separated by commas",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "actor",
            "in": "query",
            "description": "An actor id (user id, API key id) or an e-mail address",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "target_type",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "target_id",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "from",
            "in": "query",
            "description": "Inclusive, RFC 3339",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "name": "to",
            "in": "query",
            "description": "Exclusive, RFC 3339",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "name": "page_size",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 200,
              "default": 50
            }
          },
          {
            "name": "page_token",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ListAuditEventsResponse"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Audit events"
        ]
      }
    },
    "/v1/audit-events/export": {
      "get": {
        "operationId": "exportAuditEvents",
        "summary": "The audit log as CSV (the newest 5000 entries of the filter)",
        "description": "The same filter as `listAuditEvents`, one line per entry with the columns id, create_time, tenant_id, account_id, actor_type, actor_id, actor_email, action, target_type, target_id, summary, detail (JSON), before_hash, after_hash, source_ip, request_id. A cell that starts with `=`, `+`, `-` or `@` gets a leading `'`, so a spreadsheet does not run it. An export that cannot read every service fails with `503 audit.unavailable` rather than leave entries out. Needs `audit:read`.\n",
        "parameters": [
          {
            "name": "action",
            "in": "query",
            "description": "Action names such as api_key.created, or an area such as api_key.*, separated by commas",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "actor",
            "in": "query",
            "description": "An actor id (user id, API key id) or an e-mail address",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "target_type",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "target_id",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "from",
            "in": "query",
            "description": "Inclusive, RFC 3339",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "name": "to",
            "in": "query",
            "description": "Exclusive, RFC 3339",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "text/csv": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "503": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Audit events"
        ]
      }
    },
    "/v1/payments": {
      "get": {
        "operationId": "listPayments",
        "summary": "The tenant's payments (charges and refunds), newest first (or searched, narrowed and sorted)",
        "description": "Reads the tenant's whole payment ledger from the payment service and folds it: the rows one provider reference left behind (a charge that was pending and then succeeded) are one payment with its most settled outcome. Amounts are minor-unit strings, each in its own currency; they are never summed across currencies. The list is searched, narrowed and sorted on the server, pages by position (`page_token` is the `next_page_token` of the page before) and reports `total`. Provider references and decline details are not part of the answer. `503` when the payment service does not answer.\n",
        "parameters": [
          {
            "name": "page_size",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 200,
              "default": 100
            }
          },
          {
            "name": "page_token",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 200,
              "default": 100
            },
            "description": "The older name of page_size; page_size wins when both are given"
          },
          {
            "name": "search",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Words that must each appear in the payment's id, provider, provider reference, invoice id or amount (minor units); a payment also matches when its invoice's number, customer external id or customer name matches the whole search"
          },
          {
            "name": "sort",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "newest",
                "oldest",
                "amount",
                "-amount"
              ]
            },
            "description": "newest (the default) and oldest are by occurred_at"
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "paid, processing, failed or refunded, comma-separated: any of them"
          },
          {
            "name": "kind",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "charge or refund, comma-separated"
          },
          {
            "name": "occurred_from",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time"
            },
            "description": "Occurred at or after this time (a plain date is the start of that day, UTC)"
          },
          {
            "name": "invoice_id",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Only the payments of these invoices: up to 200 invoice ids, comma-separated"
          },
          {
            "name": "occurred_to",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time"
            },
            "description": "Occurred before this time"
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ListPaymentsResponse"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "503": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Payments"
        ]
      }
    },
    "/v1/payments/{id}": {
      "get": {
        "operationId": "getPayment",
        "summary": "One payment, as the list shows it",
        "description": "`id` is the payment's `id` from `GET /v1/payments`. A payment that settled since keeps answering under the id the list gives now; the id of a row it was folded from does not. `404 gateway.payments.not_found` for a payment that is not yours, `503` when the payment service does not answer.\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Payment"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "503": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Payments"
        ]
      }
    },
    "/v1/disputes": {
      "get": {
        "operationId": "listDisputes",
        "summary": "The cases customers opened with their banks about a payment, newest first",
        "description": "A dispute (a chargeback, or an inquiry that may become one) is kept as the provider last reported it: `outcome` is `open` while it is undecided (for a chargeback the provider has taken the money back until it decides), `won` when it ended in your favour or never became a chargeback, `lost` when the cardholder won. Each step is also sent as the `payment.disputed` webhook event. A dispute of a payment Payrudder did not make has no `invoice_id`. Stripe's and Paddle's own words are in `provider_status`; UNVERIFIED against a live account. `503` when the payment service does not answer.\n",
        "parameters": [
          {
            "name": "invoice_id",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Only the disputes of this invoice"
          },
          {
            "name": "outcome",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "open",
                "won",
                "lost"
              ]
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 200,
              "default": 100
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ListDisputesResponse"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "503": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Disputes"
        ]
      }
    },
    "/v1/disputes/{id}/history": {
      "get": {
        "operationId": "listDisputeHistory",
        "summary": "The notes and marks you made on a dispute, newest first",
        "description": "What you did with the case inside Payrudder: each note, and each time it was marked as handled or the mark was lifted. `id` is the case's `id` as `GET /v1/disputes` gives it. `actor` (who) is left out for a viewer of the account, as in the audit log. At most the newest 200. `404 payments.dispute.not_found` for a case that is not yours.\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ListDisputeEventsResponse"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "503": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Disputes"
        ]
      }
    },
    "/v1/disputes/{id}/notes": {
      "post": {
        "operationId": "addDisputeNote",
        "summary": "Write a note on a dispute",
        "description": "A note is for you and your colleagues: what you found out, what you answered at the provider, where the evidence is. It is kept with the case, one to 2000 characters, and recorded in the audit log without its text. Payrudder sends it nowhere: the case is answered at the provider, Payrudder submits no evidence.\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AddDisputeNoteRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DisputeEvent"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "503": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Disputes"
        ]
      }
    },
    "/v1/disputes/{id}/handled": {
      "put": {
        "operationId": "setDisputeHandled",
        "summary": "Mark a dispute as handled in Payrudder, or lift the mark",
        "description": "Your own mark: it says you have dealt with the case (answered it at the provider, accepted it, refunded it). It changes nothing at the provider, in the payment ledger, or in what was announced (`payment.disputed`). Setting what is already set is not an error and writes nothing. Recorded in the audit log. The answer is the case as it stands.\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SetDisputeHandledRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Dispute"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "503": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Disputes"
        ]
      }
    },
    "/v1/assets/uploads": {
      "post": {
        "operationId": "createUploadSession",
        "summary": "Open a direct multipart upload session for up to 50 files",
        "description": "Returns, for each file, presigned S3 `UploadPart` URLs for its first (up to 100) parts. Upload the parts in parallel\nstraight to S3 (PUT, each part `part_size` bytes except the last), keep the `ETag` of each answer, then call\n`complete`. The session lasts 24 hours. `Idempotency-Key` makes retries return the same session.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateUploadSessionRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UploadSession"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Assets"
        ]
      }
    },
    "/v1/assets/uploads/{session}": {
      "delete": {
        "operationId": "abortUploadSession",
        "summary": "Abort a session and every unfinished file in it",
        "parameters": [
          {
            "name": "session",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UploadSession"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Assets"
        ]
      }
    },
    "/v1/assets/uploads/{session}/files/{asset}": {
      "get": {
        "operationId": "getUploadFile",
        "summary": "State of one file, including the parts S3 already holds (to resume an interrupted upload)",
        "parameters": [
          {
            "name": "session",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "asset",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UploadFile"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Assets"
        ]
      },
      "delete": {
        "operationId": "abortUploadFile",
        "summary": "Abort one file of a session",
        "parameters": [
          {
            "name": "session",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "asset",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UploadSession"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Assets"
        ]
      }
    },
    "/v1/assets/uploads/{session}/files/{asset}/parts": {
      "post": {
        "operationId": "presignParts",
        "summary": "More (or refreshed) presigned part URLs of a file",
        "parameters": [
          {
            "name": "session",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "asset",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "from",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "default": 1
            }
          },
          {
            "name": "count",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 100
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PresignPartsResponse"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Assets"
        ]
      }
    },
    "/v1/assets/uploads/{session}/files/{asset}/complete": {
      "post": {
        "operationId": "completeUploadFile",
        "summary": "Verify the uploaded parts, assemble the object and make the asset READY",
        "description": "Idempotent. If the parts do not match what S3 holds (a missing part or a wrong ETag), the asset comes back\n`REJECTED` with `reject_reason: PART_MISMATCH` and nothing is left in storage.\n",
        "parameters": [
          {
            "name": "session",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "asset",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CompleteUploadFileRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Asset"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Assets"
        ]
      }
    },
    "/v1/assets": {
      "post": {
        "operationId": "uploadAssets",
        "summary": "Upload up to 20 small files in one multipart/form-data request",
        "description": "Files are streamed through the gateway into storage (at most 25 MiB each, 100 MiB per request); use an upload\nsession for larger files. An optional first part `metadata` picks each file's purpose:\n`{\"files\": {\"logo.png\": {\"purpose\": \"invoice_logo\"}}}` (default `general`). The answer is `200` with one result per\nfile, in order: a bad file is `rejected` with an `error_code` and does not fail the others. The `write` rate limit\nis charged per file.\n",
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "properties": {
                  "metadata": {
                    "type": "string",
                    "description": "JSON"
                  },
                  "file": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "format": "binary"
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Per-file results",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UploadAssetsResponse"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "413": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Assets"
        ]
      },
      "get": {
        "operationId": "listAssets",
        "summary": "List READY assets",
        "parameters": [
          {
            "name": "purpose",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "invoice_logo",
                "invoice_attachment",
                "general"
              ]
            }
          },
          {
            "name": "page_size",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 500,
              "default": 100
            }
          },
          {
            "name": "page_token",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ListAssetsResponse"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Assets"
        ]
      }
    },
    "/v1/tenant/invoice-logo": {
      "put": {
        "operationId": "setInvoiceLogo",
        "summary": "Draw a READY invoice_logo asset on the tenant's invoice PDFs",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SetInvoiceLogoRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SetInvoiceLogoResponse"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Tenant"
        ]
      },
      "delete": {
        "operationId": "clearInvoiceLogo",
        "summary": "Remove the invoice logo",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ClearInvoiceLogoResponse"
                }
              }
            }
          }
        },
        "tags": [
          "Tenant"
        ]
      }
    },
    "/v1/assets/{id}": {
      "get": {
        "operationId": "getAsset",
        "summary": "One asset",
        "parameters": [
          {
            "$ref": "#/components/parameters/ID"
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Asset"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Assets"
        ]
      },
      "delete": {
        "operationId": "deleteAsset",
        "summary": "Delete a READY asset (its bytes leave the storage quota)",
        "parameters": [
          {
            "$ref": "#/components/parameters/ID"
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Asset"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Assets"
        ]
      }
    },
    "/v1/assets/{id}/download": {
      "get": {
        "operationId": "downloadAsset",
        "summary": "A presigned link (5 minutes) that downloads the file as an attachment",
        "parameters": [
          {
            "$ref": "#/components/parameters/ID"
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SignedUrl"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Assets"
        ]
      }
    },
    "/v1/analytics/usage": {
      "get": {
        "operationId": "getAnalyticsUsage",
        "summary": "Usage series of one meter (estimates; invoices come from billing)",
        "description": "Near-real-time, from ClickHouse. The default series comes from an hourly rollup that may over-count by the duplicate\ndelivery rate (`precision: estimated`); `exact=true` recomputes it from deduplicated events and covers at most one day\n(`precision: exact`).\n",
        "parameters": [
          {
            "name": "meter",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "from",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "name": "to",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "name": "granularity",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "hour",
                "day"
              ],
              "default": "hour"
            }
          },
          {
            "name": "customer",
            "in": "query",
            "description": "Customer external id",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "exact",
            "in": "query",
            "schema": {
              "type": "boolean",
              "default": false
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GetAnalyticsUsageResponse"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Analytics"
        ]
      }
    },
    "/v1/analytics/top-customers": {
      "get": {
        "operationId": "getTopCustomers",
        "summary": "Customers ranked by usage of a meter in a billing period (deduplicated)",
        "parameters": [
          {
            "name": "meter",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "period",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[0-9]{4}-(0[1-9]|1[0-2])$"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 10
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GetTopCustomersResponse"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Analytics"
        ]
      }
    },
    "/v1/sandbox/close-period": {
      "post": {
        "operationId": "sandboxClosePeriod",
        "summary": "Sandbox only - close a period now and run the real billing flow",
        "description": "Lowers the period's cutoff to now + 5 s, then billing runs exactly as at month end: watermark (starting 30 s after\nthe new cutoff), rating, numbering (`SBX-…`) and the invoice saga with mock payments. Poll `GET /v1/invoices`.\n`period` defaults to the current period. Live keys get 403.\n",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SandboxClosePeriodRequest"
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Accepted",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BillingRun"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Sandbox"
        ]
      }
    },
    "/v1/sandbox/customers/{external_id}/payment-scenario": {
      "post": {
        "operationId": "setPaymentScenario",
        "summary": "Sandbox only - choose the mock payment outcome for a customer",
        "description": "`{\"scenario\": \"declined\"}` sets `pm_sandbox_declined`. Live keys get 403.",
        "parameters": [
          {
            "$ref": "#/components/parameters/ExternalID"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SetPaymentScenarioRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Customer"
                }
              }
            }
          },
          "403": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "Sandbox"
        ]
      }
    },
    "/v1/sandbox/scenarios": {
      "get": {
        "operationId": "sandboxScenarios",
        "tags": [
          "Sandbox"
        ],
        "summary": "The payment scenarios of a sandbox customer",
        "description": "What each pm_sandbox_* payment method does. Sandbox keys only.",
        "security": [
          {
            "apiKey": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SandboxScenariosResponse"
                }
              }
            }
          },
          "403": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/v1/sandbox/invoices/{id}/simulate": {
      "post": {
        "operationId": "sandboxSimulateInvoice",
        "tags": [
          "Sandbox"
        ],
        "summary": "Run an invoice's payment again under a scenario",
        "description": "Sets the invoice's customer to the scenario (it stays their payment method) and retries the invoice's payment. When the payment cannot run again now (paid, or in progress) the scenario is still set and `retried` is false with the reason in `retry_error`. Sandbox keys only.\n",
        "security": [
          {
            "apiKey": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/ID"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SandboxSimulateInvoiceRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SandboxSimulateInvoiceResponse"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "IngestEventsRequest": {
        "type": "object",
        "required": [
          "events"
        ],
        "properties": {
          "events": {
            "type": "array",
            "minItems": 1,
            "maxItems": 500,
            "items": {
              "$ref": "#/components/schemas/IncomingEvent"
            }
          }
        }
      },
      "IncomingEvent": {
        "type": "object",
        "required": [
          "customer_external_id",
          "meter_code",
          "quantity",
          "event_time"
        ],
        "properties": {
          "idempotency_key": {
            "type": "string",
            "pattern": "^[A-Za-z0-9_.:-]{1,128}$",
            "description": "Required for live keys. Optional in sandbox (then no dedup)."
          },
          "customer_external_id": {
            "type": "string"
          },
          "meter_code": {
            "type": "string"
          },
          "quantity": {
            "description": "Non-negative decimal with at most the meter's quantity_scale decimal places. A string or a JSON number.",
            "oneOf": [
              {
                "type": "string",
                "examples": [
                  "1500",
                  "1.250"
                ]
              },
              {
                "type": "number"
              }
            ]
          },
          "event_time": {
            "type": "string",
            "format": "date-time",
            "description": "Not older than 35 days, not more than 5 minutes ahead."
          },
          "properties": {
            "type": "object",
            "additionalProperties": {
              "type": "string"
            },
            "description": "At most 32 entries and 4 KiB in total."
          }
        }
      },
      "IngestEventsResponse": {
        "type": "object",
        "required": [
          "results"
        ],
        "properties": {
          "results": {
            "type": "array",
            "description": "One per request event, same order.",
            "items": {
              "$ref": "#/components/schemas/EventResult"
            }
          }
        }
      },
      "EventResult": {
        "type": "object",
        "required": [
          "status"
        ],
        "properties": {
          "status": {
            "type": "string",
            "enum": [
              "accepted",
              "duplicate",
              "rejected"
            ]
          },
          "event_id": {
            "type": "string",
            "description": "Set for accepted and duplicate (the original id)."
          },
          "error_code": {
            "type": "string",
            "enum": [
              "UNKNOWN_METER",
              "UNKNOWN_CUSTOMER",
              "EVENT_TOO_OLD",
              "EVENT_IN_FUTURE",
              "INVALID_EVENT_TIME",
              "INVALID_QUANTITY",
              "INVALID_QUANTITY_PRECISION",
              "IDEMPOTENCY_KEY_REQUIRED",
              "IDEMPOTENCY_KEY_INVALID",
              "IDEMPOTENCY_KEY_REUSED",
              "INVALID_PROPERTIES",
              "INVALID_CORRECTION",
              "CORRECTION_UNKNOWN_EVENT",
              "CORRECTION_MISMATCH",
              "CORRECTION_UNSUPPORTED_METER",
              "CORRECTION_OF_CORRECTION"
            ]
          },
          "error_message": {
            "type": "string"
          }
        }
      },
      "Error": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "object",
            "required": [
              "code",
              "key",
              "message"
            ],
            "properties": {
              "code": {
                "type": "string",
                "examples": [
                  "INVALID_ARGUMENT",
                  "UNAUTHENTICATED",
                  "RESOURCE_EXHAUSTED"
                ]
              },
              "key": {
                "type": "string",
                "description": "Stable and dotted, service first (billing.credit_note.not_paid). Translate the key, not the message. The list is docs/error-keys.md; an error without its own key gets common.<reason>",
                "examples": [
                  "billing.credit_note.not_paid",
                  "common.not_found"
                ]
              },
              "message": {
                "type": "string"
              },
              "details": {
                "type": "array",
                "description": "Left out when there is no field to point at",
                "items": {
                  "type": "object",
                  "required": [
                    "field",
                    "description"
                  ],
                  "properties": {
                    "field": {
                      "type": "string"
                    },
                    "description": {
                      "type": "string"
                    }
                  }
                }
              },
              "request_id": {
                "type": "string",
                "description": "The X-Request-Id of the call; missing on an answer written by payments-worker"
              }
            }
          }
        }
      },
      "CorrectEventsRequest": {
        "type": "object",
        "required": [
          "corrections"
        ],
        "properties": {
          "corrections": {
            "type": "array",
            "minItems": 1,
            "maxItems": 500,
            "items": {
              "$ref": "#/components/schemas/EventCorrection"
            }
          }
        }
      },
      "EventCorrection": {
        "type": "object",
        "required": [
          "corrects",
          "reason",
          "customer_external_id",
          "meter_code",
          "quantity"
        ],
        "properties": {
          "idempotency_key": {
            "type": "string",
            "pattern": "^[A-Za-z0-9_.:-]{1,128}$",
            "description": "The correction's own key. Required for live keys. Optional in sandbox (then no dedup)."
          },
          "corrects": {
            "type": "string",
            "pattern": "^[A-Za-z0-9_.:-]{1,128}$",
            "description": "The idempotency_key of the event to correct, as it was sent"
          },
          "reason": {
            "type": "string",
            "minLength": 1,
            "maxLength": 500,
            "description": "Why. Kept with the correction"
          },
          "customer_external_id": {
            "type": "string",
            "description": "The customer of the event being corrected"
          },
          "meter_code": {
            "type": "string",
            "description": "The meter of the event being corrected"
          },
          "quantity": {
            "description": "The quantity the corrected event should have had, a non-negative decimal with at most the meter's quantity_scale decimal places. A string or a JSON number. 0 cancels the event.",
            "oneOf": [
              {
                "type": "string",
                "examples": [
                  "1500",
                  "1.250"
                ]
              },
              {
                "type": "number"
              }
            ]
          }
        }
      },
      "ListRejectedEventsResponse": {
        "type": "object",
        "required": [
          "events",
          "next_page_token"
        ],
        "properties": {
          "events": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/RejectedEvent"
            }
          },
          "next_page_token": {
            "type": "string",
            "description": "Empty on the last page"
          }
        }
      },
      "RejectedEvent": {
        "type": "object",
        "required": [
          "id",
          "error_code",
          "error_message",
          "meter_code",
          "customer_external_id",
          "event_time",
          "received_time",
          "idempotency_key"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "error_code": {
            "type": "string",
            "description": "One of the error codes of POST /v1/events"
          },
          "error_message": {
            "type": "string",
            "description": "The API's own message, in English"
          },
          "meter_code": {
            "type": "string",
            "description": "As sent; may name a meter that does not exist"
          },
          "customer_external_id": {
            "type": "string",
            "description": "As sent; may name a customer that does not exist"
          },
          "event_time": {
            "type": "string",
            "format": "date-time",
            "nullable": true,
            "description": "Null when the event carried no time"
          },
          "received_time": {
            "type": "string",
            "format": "date-time"
          },
          "idempotency_key": {
            "type": "string",
            "description": "As sent; empty when the event had none"
          }
        }
      },
      "RejectedEventSummary": {
        "type": "object",
        "required": [
          "total",
          "by_code",
          "hourly"
        ],
        "properties": {
          "total": {
            "type": "integer",
            "description": "Rejected events of the last 24 hours"
          },
          "by_code": {
            "type": "array",
            "description": "Most frequent first",
            "items": {
              "type": "object",
              "required": [
                "error_code",
                "count"
              ],
              "properties": {
                "error_code": {
                  "type": "string"
                },
                "count": {
                  "type": "integer"
                }
              }
            }
          },
          "hourly": {
            "type": "array",
            "description": "24 buckets, oldest first; the last one is the current hour",
            "items": {
              "type": "object",
              "required": [
                "hour",
                "rejected"
              ],
              "properties": {
                "hour": {
                  "type": "string",
                  "format": "date-time",
                  "description": "The start of the hour (UTC)"
                },
                "rejected": {
                  "type": "integer"
                }
              }
            }
          }
        }
      },
      "CreateCustomerRequest": {
        "type": "object",
        "required": [
          "external_id",
          "name",
          "email"
        ],
        "properties": {
          "external_id": {
            "type": "string",
            "maxLength": 128
          },
          "name": {
            "type": "string"
          },
          "email": {
            "type": "string",
            "format": "email"
          },
          "payment_method": {
            "type": "string"
          },
          "country": {
            "type": "string",
            "pattern": "^[A-Z]{2}$",
            "description": "ISO 3166-1 alpha-2"
          },
          "billing_currency": {
            "type": "string",
            "description": "ISO 4217; default is the tenant's currency"
          },
          "address": {
            "$ref": "#/components/schemas/AddressInput"
          },
          "locale": {
            "type": "string",
            "enum": [
              "en",
              "tr",
              "de",
              "fr",
              "es",
              "ar"
            ],
            "description": "The language of the customer's mails, receipts and payment pages"
          },
          "customer_type": {
            "type": "string",
            "enum": [
              "individual",
              "business"
            ],
            "description": "A person or a taxpayer"
          },
          "phone": {
            "type": "string",
            "description": "The customer's mobile number in international form, e.g. +90 532 123 45 67 or 0090 532 123 45 67; stored as E.164 (+905321234567). A number without the + or 00 prefix is refused: it cannot be read without a country."
          },
          "referral_code": {
            "type": "string",
            "description": "The code of the partner whose link or code brought this customer (phase 47). A code that cannot attribute does not fail the creation."
          },
          "referral_touch_time": {
            "type": "string",
            "format": "date-time",
            "description": "When the visitor followed that link; default now"
          }
        }
      },
      "AddressInput": {
        "type": "object",
        "description": "A postal address as printed on an invoice. Every part is optional.",
        "properties": {
          "line1": {
            "type": "string",
            "maxLength": 120
          },
          "line2": {
            "type": "string",
            "maxLength": 120
          },
          "city": {
            "type": "string",
            "maxLength": 120
          },
          "region": {
            "type": "string",
            "maxLength": 120,
            "description": "State, province or county"
          },
          "postal_code": {
            "type": "string",
            "maxLength": 20
          },
          "country": {
            "type": "string",
            "pattern": "^[A-Z]{2}$",
            "description": "ISO 3166-1 alpha-2"
          }
        }
      },
      "Customer": {
        "type": "object",
        "required": [
          "id",
          "external_id",
          "name",
          "email",
          "payment_method",
          "create_time",
          "country",
          "billing_currency",
          "address",
          "tax_id",
          "tax_office",
          "e_invoice_registered",
          "locale",
          "customer_type",
          "block_reason",
          "block_category",
          "service_suspended",
          "phone",
          "tax_id_warning",
          "trial_used"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "external_id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "email": {
            "type": "string"
          },
          "payment_method": {
            "type": "string"
          },
          "create_time": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "country": {
            "type": "string",
            "description": "ISO 3166-1 alpha-2"
          },
          "billing_currency": {
            "type": "string",
            "description": "ISO 4217"
          },
          "address": {
            "allOf": [
              {
                "$ref": "#/components/schemas/Address"
              }
            ],
            "nullable": true
          },
          "tax_id": {
            "type": "string"
          },
          "tax_office": {
            "type": "string"
          },
          "e_invoice_registered": {
            "type": "boolean"
          },
          "locale": {
            "type": "string",
            "description": "The language of the customer's mails, receipts and payment pages: en, tr, de, fr, es or ar. Empty is the browser's language (pages) and English (mails)."
          },
          "customer_type": {
            "type": "string",
            "description": "individual (a person) or business (a taxpayer with a tax id). Empty is unknown."
          },
          "block_time": {
            "type": "string",
            "format": "date-time",
            "nullable": true,
            "description": "Set while the customer is blocked: no new subscription, plan change or purchase (existing subscriptions run on). A block whose blocked_until has passed has ended, whatever this says."
          },
          "block_reason": {
            "type": "string",
            "description": "The seller's own note on the block; never shown to the customer."
          },
          "block_category": {
            "type": "string",
            "description": "Why: fraud, chargeback, abuse, request or other; empty when none was given."
          },
          "blocked_until": {
            "type": "string",
            "format": "date-time",
            "nullable": true,
            "description": "When the block ends by itself; absent: until it is lifted."
          },
          "service_suspended": {
            "type": "boolean",
            "description": "The block also suspends the customer's service: every entitlement check answers allowed false. Read it with block_time and blocked_until, it holds only while the block does."
          },
          "phone": {
            "type": "string",
            "description": "The customer's mobile number as E.164 (+905321234567); empty when none."
          },
          "tax_id_validated_at": {
            "type": "string",
            "format": "date-time",
            "nullable": true,
            "description": "When tax_id last passed the local check (a TCKN or VKN checksum, the shape of a European VAT id). Not a registry lookup: no VIES, no GİB query. Absent when the id is empty or not recognised."
          },
          "tax_id_warning": {
            "type": "string",
            "description": "One of tr_individual, tr_business, tr_any, tr_is_tckn, tr_is_vkn, eu_vat, or empty. A hint, never a refusal: the id does not look like the kind of number this customer should have (tr_individual: not a TCKN; tr_business: not a VKN; tr_any: neither; tr_is_tckn: a business was given a TCKN; tr_is_vkn: an individual was given a VKN; eu_vat: a business in the EU has no VAT id of its country's shape). Worked out from the stored id, country and customer_type, so it follows a change of any of them. Empty: nothing to say."
          },
          "trial_used": {
            "type": "boolean",
            "description": "The customer has had a trial (a subscription that was ever trialing, cancelled ones included). Filled by GET /v1/customers/{external_id}; false in lists"
          }
        }
      },
      "Address": {
        "type": "object",
        "description": "A postal address as printed on an invoice. Every part is optional.",
        "required": [
          "line1",
          "line2",
          "city",
          "region",
          "postal_code",
          "country"
        ],
        "properties": {
          "line1": {
            "type": "string",
            "maxLength": 120
          },
          "line2": {
            "type": "string",
            "maxLength": 120
          },
          "city": {
            "type": "string",
            "maxLength": 120
          },
          "region": {
            "type": "string",
            "maxLength": 120,
            "description": "State, province or county"
          },
          "postal_code": {
            "type": "string",
            "maxLength": 20
          },
          "country": {
            "type": "string",
            "pattern": "^[A-Z]{2}$",
            "description": "ISO 3166-1 alpha-2"
          }
        }
      },
      "ListCustomersResponse": {
        "type": "object",
        "required": [
          "customers",
          "next_page_token"
        ],
        "properties": {
          "total": {
            "type": "integer",
            "description": "How many rows match, on a searched, narrowed or sorted list; 0 on the plain list"
          },
          "customers": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Customer"
            }
          },
          "next_page_token": {
            "type": "string"
          }
        }
      },
      "SetPaymentMethodRequest": {
        "type": "object",
        "required": [
          "payment_method"
        ],
        "properties": {
          "payment_method": {
            "type": "string"
          }
        }
      },
      "CreatePaymentMethodSetupRequest": {
        "type": "object",
        "required": [
          "return_url"
        ],
        "properties": {
          "provider": {
            "type": "string",
            "enum": [
              "stripe"
            ],
            "default": "stripe",
            "description": "The provider whose page it is; only Stripe has one"
          },
          "return_url": {
            "type": "string",
            "format": "uri",
            "maxLength": 2000,
            "description": "Where the provider sends the customer after the page. `https` only"
          }
        }
      },
      "PaymentMethodSetup": {
        "type": "object",
        "required": [
          "url",
          "ref"
        ],
        "properties": {
          "url": {
            "type": "string",
            "description": "The provider's page: send it to the customer"
          },
          "ref": {
            "type": "string",
            "description": "The provider's reference of the page (Stripe's Checkout Session id)"
          }
        }
      },
      "CustomerCards": {
        "type": "object",
        "required": [
          "provider",
          "cards"
        ],
        "properties": {
          "provider": {
            "type": "string",
            "description": "The provider that holds the cards; empty when the customer has none"
          },
          "cards": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/StoredCard"
            }
          }
        }
      },
      "StoredCard": {
        "type": "object",
        "required": [
          "token",
          "alias",
          "bin",
          "last4",
          "type",
          "association",
          "family",
          "bank",
          "expire_month",
          "expire_year",
          "in_use"
        ],
        "properties": {
          "token": {
            "type": "string",
            "description": "The provider's card token (cardToken): what the delete names"
          },
          "alias": {
            "type": "string"
          },
          "bin": {
            "type": "string",
            "description": "The first digits of the number (the BIN)"
          },
          "last4": {
            "type": "string"
          },
          "type": {
            "type": "string",
            "description": "CREDIT_CARD, DEBIT_CARD or PREPAID_CARD"
          },
          "association": {
            "type": "string",
            "description": "VISA, MASTER_CARD, ..."
          },
          "family": {
            "type": "string"
          },
          "bank": {
            "type": "string"
          },
          "expire_month": {
            "type": "string"
          },
          "expire_year": {
            "type": "string"
          },
          "in_use": {
            "type": "boolean",
            "description": "The customer's payment method names this card"
          }
        }
      },
      "DeletedCustomerCard": {
        "type": "object",
        "required": [
          "provider",
          "deleted",
          "was_in_use"
        ],
        "properties": {
          "provider": {
            "type": "string"
          },
          "deleted": {
            "type": "boolean"
          },
          "was_in_use": {
            "type": "boolean",
            "description": "The deleted card was the one the customer's payment method names: set a new payment method"
          }
        }
      },
      "CustomerContact": {
        "type": "object",
        "required": [
          "name",
          "email"
        ],
        "properties": {
          "name": {
            "type": "string",
            "maxLength": 200
          },
          "email": {
            "type": "string",
            "format": "email"
          },
          "locale": {
            "type": "string",
            "enum": [
              "en",
              "tr",
              "de",
              "fr",
              "es",
              "ar"
            ],
            "description": "The language of the customer's mails, receipts and payment pages; omit to keep it"
          },
          "customer_type": {
            "type": "string",
            "enum": [
              "individual",
              "business"
            ],
            "description": "A person or a taxpayer; omit to keep it"
          },
          "phone": {
            "type": "string",
            "description": "The customer's mobile number in international form (+90 532 123 45 67 or 0090 532 123 45 67), stored as E.164. Omit to keep the stored number; send an empty string to clear it."
          }
        }
      },
      "BlockCustomerRequest": {
        "type": "object",
        "properties": {
          "reason": {
            "type": "string",
            "maxLength": 500,
            "description": "Your note on why; never shown to the customer."
          },
          "category": {
            "$ref": "#/components/schemas/CustomerBlockCategory"
          },
          "blocked_until": {
            "type": "string",
            "format": "date-time",
            "description": "When the block ends by itself; must be in the future. Absent: until you lift it."
          },
          "suspend_service": {
            "type": "boolean",
            "description": "Also suspend the customer's service: every entitlement check answers allowed false (suspended true) until the block is lifted or ends. Usage is still accepted and counted. Default false."
          }
        }
      },
      "CustomerBlockCategory": {
        "type": "string",
        "enum": [
          "fraud",
          "chargeback",
          "abuse",
          "request",
          "other"
        ],
        "description": "Why the customer is blocked. fraud and chargeback also refuse paying an invoice that is open."
      },
      "ListCustomerBlockEventsResponse": {
        "type": "object",
        "required": [
          "events"
        ],
        "properties": {
          "events": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/CustomerBlockEvent"
            }
          }
        }
      },
      "CustomerBlockEvent": {
        "type": "object",
        "required": [
          "id",
          "action",
          "category",
          "reason",
          "suspend_service",
          "actor",
          "create_time"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "action": {
            "type": "string",
            "enum": [
              "blocked",
              "unblocked"
            ]
          },
          "category": {
            "type": "string",
            "description": "Empty when none was given; else a CustomerBlockCategory"
          },
          "reason": {
            "type": "string"
          },
          "blocked_until": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "suspend_service": {
            "type": "boolean",
            "description": "On a block: whether it also suspended the customer's service"
          },
          "actor": {
            "type": "string",
            "description": "A person's address, key:<api key id>, or operator"
          },
          "create_time": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "ListCustomerBlockAppealsResponse": {
        "type": "object",
        "required": [
          "appeals"
        ],
        "properties": {
          "appeals": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/CustomerBlockAppeal"
            }
          }
        }
      },
      "CustomerBlockAppeal": {
        "type": "object",
        "required": [
          "id",
          "status",
          "statement",
          "answer",
          "decided_by",
          "create_time"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "status": {
            "type": "string",
            "enum": [
              "open",
              "accepted",
              "rejected",
              "closed"
            ]
          },
          "statement": {
            "type": "string",
            "maxLength": 2000,
            "description": "The customer's own words. Untrusted: show as text only"
          },
          "answer": {
            "type": "string",
            "maxLength": 1000,
            "description": "Your answer; empty until decided, and for an accepted appeal that had none"
          },
          "decided_by": {
            "type": "string",
            "description": "A person's address, key:<api key id>, or system for a closed appeal"
          },
          "create_time": {
            "type": "string",
            "format": "date-time"
          },
          "decide_time": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          }
        }
      },
      "DecideCustomerBlockAppealRequest": {
        "type": "object",
        "required": [
          "decision"
        ],
        "properties": {
          "decision": {
            "type": "string",
            "enum": [
              "accepted",
              "rejected"
            ]
          },
          "answer": {
            "type": "string",
            "maxLength": 1000,
            "description": "Required to reject"
          }
        }
      },
      "ListBlocklistResponse": {
        "type": "object",
        "required": [
          "entries"
        ],
        "properties": {
          "entries": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/BlocklistEntry"
            }
          }
        }
      },
      "BlocklistEntry": {
        "type": "object",
        "required": [
          "id",
          "kind",
          "value",
          "note",
          "created_by",
          "create_time"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "kind": {
            "type": "string",
            "enum": [
              "email",
              "tax_id",
              "external_id"
            ]
          },
          "value": {
            "type": "string",
            "description": "The normalised value"
          },
          "note": {
            "type": "string",
            "description": "The owner's own note; never shown to the person the entry is about"
          },
          "created_by": {
            "type": "string",
            "description": "A person's address, key:<api key id>, or operator"
          },
          "create_time": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "AddBlocklistEntryRequest": {
        "type": "object",
        "required": [
          "kind",
          "value"
        ],
        "properties": {
          "kind": {
            "type": "string",
            "enum": [
              "email",
              "tax_id",
              "external_id"
            ]
          },
          "value": {
            "type": "string",
            "maxLength": 320
          },
          "note": {
            "type": "string",
            "maxLength": 500
          }
        }
      },
      "CustomerTax": {
        "type": "object",
        "properties": {
          "tax_id": {
            "type": "string",
            "maxLength": 40,
            "description": "VKN/TCKN (Turkey) or VAT id (EU)"
          },
          "tax_office": {
            "type": "string",
            "maxLength": 120,
            "description": "Vergi dairesi (Turkey)"
          },
          "e_invoice_registered": {
            "type": "boolean",
            "description": "The customer is registered for e-fatura"
          }
        }
      },
      "ContractKind": {
        "type": "string",
        "enum": [
          "distance_sales",
          "pre_info",
          "tos",
          "privacy"
        ]
      },
      "ContractAudience": {
        "type": "string",
        "enum": [
          "consumer",
          "business"
        ],
        "description": "A business customer gets the business series when one is published, else the consumer's."
      },
      "ListContractVersionsResponse": {
        "type": "object",
        "required": [
          "versions"
        ],
        "properties": {
          "versions": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ContractVersion"
            }
          }
        }
      },
      "ContractVersion": {
        "type": "object",
        "required": [
          "id",
          "kind",
          "audience",
          "number",
          "material",
          "bodies",
          "sha256",
          "note",
          "author",
          "create_time",
          "variables",
          "current",
          "has_template_notice"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "kind": {
            "$ref": "#/components/schemas/ContractKind"
          },
          "audience": {
            "$ref": "#/components/schemas/ContractAudience"
          },
          "number": {
            "type": "integer",
            "format": "int32",
            "minimum": 1
          },
          "material": {
            "type": "boolean",
            "description": "Customers who accepted an earlier version are asked again."
          },
          "bodies": {
            "type": "object",
            "additionalProperties": {
              "type": "string"
            },
            "description": "Language (en, tr, de, fr, es, ar) to the text."
          },
          "sha256": {
            "type": "string",
            "description": "Hex sha256 over the kind, audience and every text."
          },
          "note": {
            "type": "string"
          },
          "author": {
            "type": "string"
          },
          "create_time": {
            "type": "string",
            "format": "date-time"
          },
          "variables": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "current": {
            "type": "boolean",
            "description": "The newest version of its series."
          },
          "has_template_notice": {
            "type": "boolean",
            "description": "A text still carries the starter notice (template, have a lawyer review)."
          }
        }
      },
      "PublishContractVersionRequest": {
        "type": "object",
        "required": [
          "kind",
          "bodies"
        ],
        "properties": {
          "kind": {
            "$ref": "#/components/schemas/ContractKind"
          },
          "audience": {
            "$ref": "#/components/schemas/ContractAudience"
          },
          "bodies": {
            "type": "object",
            "additionalProperties": {
              "type": "string"
            },
            "minProperties": 1
          },
          "material": {
            "type": "boolean"
          },
          "note": {
            "type": "string",
            "maxLength": 500
          }
        }
      },
      "PreviewContractRequest": {
        "type": "object",
        "required": [
          "body"
        ],
        "properties": {
          "body": {
            "type": "string"
          },
          "locale": {
            "type": "string"
          }
        }
      },
      "PreviewContractResponse": {
        "type": "object",
        "required": [
          "html",
          "variables",
          "unknown_variables"
        ],
        "properties": {
          "html": {
            "type": "string",
            "description": "Safe HTML; the variables are shown with sample values inside <mark>."
          },
          "variables": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "unknown_variables": {
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        }
      },
      "GetContractStarterResponse": {
        "type": "object",
        "required": [
          "body",
          "locale"
        ],
        "properties": {
          "body": {
            "type": "string"
          },
          "locale": {
            "type": "string",
            "enum": [
              "tr",
              "en"
            ]
          }
        }
      },
      "ContractSettings": {
        "type": "object",
        "required": [
          "required_kinds",
          "immediate_start",
          "retention_months",
          "published_kinds",
          "update_time",
          "withdrawal_refund",
          "renewal_notice_days",
          "renewal_cancel_texts",
          "withdrawal_function"
        ],
        "properties": {
          "required_kinds": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ContractKind"
            }
          },
          "immediate_start": {
            "type": "boolean"
          },
          "retention_months": {
            "type": "integer",
            "format": "int32",
            "minimum": 12,
            "maximum": 120
          },
          "published_kinds": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ContractKind"
            },
            "description": "Kinds that have a published consumer version."
          },
          "update_time": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "withdrawal_refund": {
            "type": "string",
            "enum": [
              "full",
              "none"
            ],
            "description": "What accepting a withdrawal does about the money. full (the default) asks billing for a refund of the invoice to the card; none leaves it to the seller. The seller decides the withdrawal either way."
          },
          "renewal_notice_days": {
            "type": "integer",
            "format": "int32",
            "minimum": 0,
            "maximum": 60,
            "description": "How many days before a renewal the customer is mailed the renewal notice (price, date, how to cancel). 0 is off; default 7. Only for a subscription whose fixed fee is invoiced in advance and a customer who accepted an agreement."
          },
          "renewal_cancel_texts": {
            "type": "object",
            "additionalProperties": {
              "type": "string",
              "maxLength": 1000
            },
            "description": "Language (en, tr, de, fr, es, ar) to the seller's own words on how to cancel, printed in the renewal notice."
          },
          "withdrawal_function": {
            "type": "boolean",
            "description": "Consumers can withdraw from a contract on the hosted pages and are sent an acknowledgement (Directive 2011/83/EU art. 11a). Only while agreements are required. Default on."
          }
        }
      },
      "SetContractSettingsRequest": {
        "type": "object",
        "properties": {
          "required_kinds": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ContractKind"
            }
          },
          "immediate_start": {
            "type": "boolean"
          },
          "retention_months": {
            "type": "integer",
            "format": "int32",
            "description": "0 keeps the current value."
          },
          "withdrawal_refund": {
            "type": "string",
            "enum": [
              "full",
              "none"
            ],
            "description": "Empty keeps the current value."
          },
          "renewal_notice_days": {
            "type": "integer",
            "format": "int32",
            "minimum": 0,
            "maximum": 60,
            "description": "Absent keeps the current value; 0 switches the notice off."
          },
          "renewal_cancel_texts": {
            "type": "object",
            "additionalProperties": {
              "type": "string",
              "maxLength": 1000
            },
            "description": "A language sent with a text sets it, with an empty text removes it; a language not sent keeps its text."
          },
          "withdrawal_function": {
            "type": "boolean",
            "description": "Absent keeps the current value."
          }
        }
      },
      "GetContractRequirementsResponse": {
        "type": "object",
        "required": [
          "enforced",
          "requirements",
          "satisfied",
          "immediate_start",
          "missing_kinds",
          "audience"
        ],
        "properties": {
          "enforced": {
            "type": "boolean",
            "description": "The seller requires agreements at all."
          },
          "requirements": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ContractRequirement"
            }
          },
          "satisfied": {
            "type": "boolean"
          },
          "immediate_start": {
            "type": "boolean",
            "description": "A consumer is asked for the request to start at once and the waiver acknowledgement."
          },
          "missing_kinds": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ContractKind"
            },
            "description": "Required kinds with no published version: a payment is refused."
          },
          "audience": {
            "$ref": "#/components/schemas/ContractAudience"
          }
        }
      },
      "ContractRequirement": {
        "type": "object",
        "required": [
          "kind",
          "version_id",
          "version_number",
          "audience",
          "locale",
          "body_html",
          "body_sha256",
          "accepted",
          "accept_time",
          "has_template_notice"
        ],
        "properties": {
          "kind": {
            "$ref": "#/components/schemas/ContractKind"
          },
          "version_id": {
            "type": "string",
            "format": "uuid"
          },
          "version_number": {
            "type": "integer",
            "format": "int32"
          },
          "audience": {
            "$ref": "#/components/schemas/ContractAudience"
          },
          "locale": {
            "type": "string",
            "description": "The language of the text served."
          },
          "body_html": {
            "type": "string",
            "description": "The text as safe HTML, variables resolved."
          },
          "body_sha256": {
            "type": "string"
          },
          "accepted": {
            "type": "boolean"
          },
          "accept_time": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "has_template_notice": {
            "type": "boolean"
          }
        }
      },
      "ListContractAcceptancesResponse": {
        "type": "object",
        "required": [
          "acceptances",
          "next_page_token"
        ],
        "properties": {
          "acceptances": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ContractAcceptance"
            }
          },
          "next_page_token": {
            "type": "string",
            "description": "Pass it as page_token for the next page; empty on the last page"
          }
        }
      },
      "ContractAcceptance": {
        "type": "object",
        "required": [
          "id",
          "group_id",
          "customer_id",
          "version_id",
          "kind",
          "audience",
          "version_number",
          "version_sha256",
          "locale_requested",
          "locale_served",
          "body_sha256",
          "context_kind",
          "context_ref",
          "source",
          "observed",
          "checkbox_text",
          "immediate_start_consent",
          "immediate_start_text",
          "withdrawal_waiver_acknowledged",
          "withdrawal_waiver_text",
          "variables",
          "snapshot_sha256",
          "ip",
          "user_agent",
          "accept_time",
          "customer_external_id"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "group_id": {
            "type": "string",
            "format": "uuid",
            "description": "The versions accepted together share it."
          },
          "customer_id": {
            "type": "string",
            "description": "Empty for a guest payment."
          },
          "version_id": {
            "type": "string",
            "format": "uuid"
          },
          "kind": {
            "$ref": "#/components/schemas/ContractKind"
          },
          "audience": {
            "$ref": "#/components/schemas/ContractAudience"
          },
          "version_number": {
            "type": "integer",
            "format": "int32"
          },
          "version_sha256": {
            "type": "string"
          },
          "locale_requested": {
            "type": "string"
          },
          "locale_served": {
            "type": "string"
          },
          "body_sha256": {
            "type": "string",
            "description": "Hex sha256 of the text served."
          },
          "context_kind": {
            "type": "string",
            "enum": [
              "hosted_invoice",
              "api"
            ]
          },
          "context_ref": {
            "type": "string"
          },
          "source": {
            "type": "string",
            "enum": [
              "hosted",
              "api"
            ]
          },
          "observed": {
            "type": "object",
            "additionalProperties": {
              "type": "boolean"
            },
            "description": "ip, user_agent, time, text: true when Payrudder observed it, false when the seller claimed it."
          },
          "checkbox_text": {
            "type": "string"
          },
          "immediate_start_consent": {
            "type": "boolean"
          },
          "immediate_start_text": {
            "type": "string"
          },
          "withdrawal_waiver_acknowledged": {
            "type": "boolean"
          },
          "withdrawal_waiver_text": {
            "type": "string"
          },
          "variables": {
            "type": "object",
            "additionalProperties": {
              "type": "string"
            }
          },
          "snapshot_sha256": {
            "type": "string"
          },
          "ip": {
            "type": "string",
            "description": "Blank once the retention period passed."
          },
          "user_agent": {
            "type": "string"
          },
          "accept_time": {
            "type": "string",
            "format": "date-time"
          },
          "customer_external_id": {
            "type": "string"
          }
        }
      },
      "RecordContractAcceptanceRequest": {
        "type": "object",
        "required": [
          "items"
        ],
        "properties": {
          "locale": {
            "type": "string",
            "description": "The language the page was shown in."
          },
          "context_ref": {
            "type": "string",
            "maxLength": 200,
            "description": "Your reference for the checkout (an order id)."
          },
          "items": {
            "type": "array",
            "minItems": 1,
            "maxItems": 4,
            "items": {
              "$ref": "#/components/schemas/ContractAcceptanceItem"
            }
          },
          "immediate_start_consent": {
            "type": "boolean"
          },
          "immediate_start_text": {
            "type": "string"
          },
          "withdrawal_waiver_acknowledged": {
            "type": "boolean"
          },
          "withdrawal_waiver_text": {
            "type": "string"
          },
          "ip": {
            "type": "string",
            "description": "Your claim about the customer's address."
          },
          "user_agent": {
            "type": "string",
            "description": "Your claim about the customer's browser."
          },
          "accept_time": {
            "type": "string",
            "format": "date-time",
            "description": "When the customer accepted; empty is now."
          },
          "customer_type": {
            "type": "string",
            "enum": [
              "individual",
              "business"
            ]
          },
          "order": {
            "$ref": "#/components/schemas/ContractOrder"
          }
        }
      },
      "ContractAcceptanceItem": {
        "type": "object",
        "required": [
          "version_id",
          "checkbox_text"
        ],
        "properties": {
          "version_id": {
            "type": "string",
            "format": "uuid"
          },
          "checkbox_text": {
            "type": "string",
            "maxLength": 1000,
            "description": "The words next to the box, as the customer saw them."
          }
        }
      },
      "ContractOrder": {
        "type": "object",
        "properties": {
          "description": {
            "type": "string"
          },
          "total": {
            "type": "string",
            "description": "Formatted for a person, e.g. 12.00."
          },
          "currency": {
            "type": "string"
          }
        }
      },
      "RecordContractAcceptanceResponse": {
        "type": "object",
        "required": [
          "group_id",
          "acceptances"
        ],
        "properties": {
          "group_id": {
            "type": "string",
            "format": "uuid"
          },
          "acceptances": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ContractAcceptance"
            }
          }
        }
      },
      "GetContractSnapshotResponse": {
        "type": "object",
        "required": [
          "html",
          "sha256",
          "group_id"
        ],
        "properties": {
          "html": {
            "type": "string"
          },
          "sha256": {
            "type": "string"
          },
          "group_id": {
            "type": "string",
            "format": "uuid"
          },
          "pdf": {
            "type": "string",
            "format": "byte",
            "description": "The page as a PDF, base64; only with pdf=true and when the page can be drawn"
          },
          "pdf_unavailable": {
            "type": "boolean",
            "description": "true when pdf=true was asked and the page cannot be drawn in the PDF font"
          }
        }
      },
      "CreateContractWithdrawalRequest": {
        "type": "object",
        "properties": {
          "subscription_id": {
            "type": "string",
            "format": "uuid"
          },
          "invoice_id": {
            "type": "string",
            "format": "uuid"
          },
          "statement": {
            "type": "string",
            "maxLength": 2000
          },
          "receive_time": {
            "type": "string",
            "format": "date-time",
            "description": "When the statement reached you; empty is now."
          },
          "source": {
            "type": "string",
            "enum": [
              "api",
              "console"
            ]
          }
        }
      },
      "ContractWithdrawal": {
        "type": "object",
        "required": [
          "id",
          "customer_id",
          "customer_external_id",
          "subscription_id",
          "invoice_id",
          "statement",
          "source",
          "status",
          "receive_time",
          "decide_time",
          "decided_by",
          "decision_note",
          "credit_note_id",
          "refund_state",
          "refund_note",
          "refund_time"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "customer_id": {
            "type": "string",
            "format": "uuid"
          },
          "customer_external_id": {
            "type": "string"
          },
          "subscription_id": {
            "type": "string"
          },
          "invoice_id": {
            "type": "string"
          },
          "statement": {
            "type": "string"
          },
          "source": {
            "type": "string",
            "enum": [
              "api",
              "console",
              "hosted"
            ]
          },
          "status": {
            "type": "string",
            "enum": [
              "received",
              "accepted",
              "rejected",
              "refunded"
            ]
          },
          "receive_time": {
            "type": "string",
            "format": "date-time"
          },
          "decide_time": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "decided_by": {
            "type": "string"
          },
          "decision_note": {
            "type": "string"
          },
          "credit_note_id": {
            "type": "string",
            "description": "The credit note billing made to refund the invoice, once one was requested (GET /v1/credit-notes/{id} says how the refund went)."
          },
          "refund_state": {
            "type": "string",
            "enum": [
              "none",
              "requesting",
              "requested",
              "refunded",
              "refund_failed",
              "outside",
              "failed"
            ],
            "description": "none: nothing asked of billing; requesting: being asked; requested: a credit note exists and the provider has not answered; refunded: the provider returned the money; refund_failed: the credit note exists and the provider did not return the money, retry the credit note's refund (a second credit note would credit the invoice twice), refund_note says why; outside: the money cannot go back through Payrudder (a bank transfer, cash), refund it by hand; failed: billing refused or did not answer, ask again with POST /v1/contract-withdrawals/{id}/refund. refunded and refund_failed are copied from the credit note's own result (credit_note.refunded, credit_note.refund_failed). The withdrawal's status stays the seller's to set."
          },
          "refund_note": {
            "type": "string"
          },
          "refund_time": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          }
        }
      },
      "ListContractWithdrawalsResponse": {
        "type": "object",
        "required": [
          "withdrawals"
        ],
        "properties": {
          "withdrawals": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ContractWithdrawal"
            }
          }
        }
      },
      "SetContractWithdrawalStatusRequest": {
        "type": "object",
        "required": [
          "status"
        ],
        "properties": {
          "status": {
            "type": "string",
            "enum": [
              "accepted",
              "rejected",
              "refunded"
            ]
          },
          "note": {
            "type": "string",
            "maxLength": 1000
          },
          "refund_amount_minor": {
            "type": "string",
            "format": "int64",
            "description": "Accepting only: the amount to refund when the settings ask for a refund, in minor units; 0 or absent is whatever is left of the invoice."
          }
        }
      },
      "RequestContractWithdrawalRefundRequest": {
        "type": "object",
        "properties": {
          "amount_minor": {
            "type": "string",
            "format": "int64",
            "description": "In minor units; 0 or absent is whatever is left of the invoice."
          }
        }
      },
      "EInvoiceList": {
        "type": "object",
        "required": [
          "documents",
          "next_page_token",
          "total"
        ],
        "properties": {
          "documents": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/EInvoiceDocument"
            }
          },
          "next_page_token": {
            "type": "string"
          },
          "total": {
            "type": "string",
            "format": "int64"
          }
        }
      },
      "EInvoiceDocument": {
        "type": "object",
        "required": [
          "id",
          "kind",
          "invoice_id",
          "credit_note_id",
          "number",
          "status",
          "document_type",
          "provider",
          "environment",
          "legal_number",
          "external_id",
          "attempts",
          "next_attempt_at",
          "last_error_key",
          "last_error",
          "has_xml",
          "has_pdf",
          "created_at",
          "issued_at",
          "updated_at"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "kind": {
            "type": "string",
            "enum": [
              "invoice",
              "credit_note"
            ]
          },
          "invoice_id": {
            "type": "string",
            "format": "uuid"
          },
          "credit_note_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "number": {
            "type": "string",
            "description": "Payrudder's invoice or credit note number"
          },
          "status": {
            "type": "string",
            "enum": [
              "pending",
              "issued",
              "failed",
              "cancelled"
            ]
          },
          "document_type": {
            "type": "string",
            "enum": [
              "",
              "e-fatura",
              "e-arsiv",
              "peppol"
            ],
            "description": "Empty until known"
          },
          "provider": {
            "type": "string"
          },
          "environment": {
            "type": "string",
            "enum": [
              "sandbox",
              "live"
            ]
          },
          "legal_number": {
            "type": "string"
          },
          "external_id": {
            "type": "string"
          },
          "attempts": {
            "type": "integer"
          },
          "next_attempt_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "last_error_key": {
            "type": "string",
            "examples": [
              "einvoice.provider.rejected"
            ]
          },
          "last_error": {
            "type": "string",
            "description": "English text"
          },
          "has_xml": {
            "type": "boolean"
          },
          "has_pdf": {
            "type": "boolean"
          },
          "created_at": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "issued_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          }
        }
      },
      "SignedUrl": {
        "type": "object",
        "description": "A time-limited link to a stored file (invoice PDF, uploaded asset, e-invoice document). GET it without credentials until expires_at.",
        "required": [
          "url",
          "expires_at"
        ],
        "properties": {
          "url": {
            "type": "string",
            "format": "uri"
          },
          "expires_at": {
            "type": "string",
            "format": "date-time",
            "description": "RFC 3339, UTC"
          }
        }
      },
      "CreateMeterRequest": {
        "type": "object",
        "required": [
          "code",
          "aggregation",
          "unit_label"
        ],
        "properties": {
          "code": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9_]{0,62}$"
          },
          "aggregation": {
            "type": "string",
            "enum": [
              "AGGREGATION_SUM",
              "AGGREGATION_COUNT",
              "AGGREGATION_MAX",
              "AGGREGATION_UNIQUE",
              "AGGREGATION_LAST"
            ],
            "description": "How a customer's events of a billing period combine into one quantity. SUM adds the quantities, COUNT counts the events, MAX keeps the\nlargest quantity. UNIQUE counts the distinct values of the event property named by value_property (an event without the property is not\ncounted; quantity_scale must be 0). LAST is the quantity of the latest event of the period by event_time, ties broken by event id; an\nevent that arrives after the period's cutoff never changes it. A code cannot change into or out of UNIQUE or LAST in a later version.\n"
          },
          "value_property": {
            "type": "string",
            "description": "Required for SUM, MAX and LAST (the event property holding the quantity) and for UNIQUE (the property whose distinct values are counted)"
          },
          "filter": {
            "type": "object",
            "additionalProperties": {
              "type": "object",
              "properties": {
                "values": {
                  "type": "array",
                  "items": {
                    "type": "string"
                  }
                }
              }
            }
          },
          "quantity_scale": {
            "type": "integer",
            "minimum": 0,
            "maximum": 6,
            "description": "Decimal places, fixed per code"
          },
          "unit_label": {
            "type": "string",
            "maxLength": 32,
            "description": "Any unit of your choice: tokens, GB-h, seats, minutes",
            "examples": [
              "tokens"
            ]
          },
          "category": {
            "type": "string",
            "maxLength": 64,
            "description": "Any group of your choice to file the meter under (compute, storage, AI); changes nothing in metering or billing",
            "examples": [
              "AI"
            ]
          }
        }
      },
      "Meter": {
        "type": "object",
        "required": [
          "code",
          "aggregation",
          "value_property",
          "filter",
          "quantity_scale",
          "unit_label",
          "category",
          "version",
          "create_time"
        ],
        "properties": {
          "code": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9_]{0,62}$"
          },
          "aggregation": {
            "type": "string",
            "enum": [
              "AGGREGATION_SUM",
              "AGGREGATION_COUNT",
              "AGGREGATION_MAX",
              "AGGREGATION_UNIQUE",
              "AGGREGATION_LAST"
            ]
          },
          "value_property": {
            "type": "string",
            "description": "Required for SUM, MAX, UNIQUE and LAST"
          },
          "filter": {
            "type": "object",
            "additionalProperties": {
              "type": "object",
              "required": [
                "values"
              ],
              "properties": {
                "values": {
                  "type": "array",
                  "items": {
                    "type": "string"
                  }
                }
              }
            }
          },
          "quantity_scale": {
            "type": "integer",
            "minimum": 0,
            "maximum": 6,
            "description": "Decimal places, fixed per code"
          },
          "unit_label": {
            "type": "string",
            "maxLength": 32,
            "description": "Any unit of your choice: tokens, GB-h, seats, minutes",
            "examples": [
              "tokens"
            ]
          },
          "category": {
            "type": "string",
            "maxLength": 64,
            "description": "Any group of your choice to file the meter under (compute, storage, AI); changes nothing in metering or billing",
            "examples": [
              "AI"
            ]
          },
          "version": {
            "type": "integer"
          },
          "create_time": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          }
        }
      },
      "ListMetersResponse": {
        "type": "object",
        "required": [
          "meters"
        ],
        "properties": {
          "meters": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Meter"
            }
          }
        }
      },
      "GetCustomerUsageResponse": {
        "type": "object",
        "required": [
          "customer_external_id",
          "period_id",
          "usage"
        ],
        "properties": {
          "customer_external_id": {
            "type": "string"
          },
          "period_id": {
            "type": "string"
          },
          "usage": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/GetCustomerUsageUsage"
            }
          }
        }
      },
      "GetCustomerUsageUsage": {
        "type": "object",
        "required": [
          "meter_code",
          "quantity",
          "event_count"
        ],
        "properties": {
          "meter_code": {
            "type": "string"
          },
          "quantity": {
            "type": "string",
            "examples": [
              "1500.250"
            ]
          },
          "event_count": {
            "type": "string",
            "format": "int64"
          }
        }
      },
      "UpcomingInvoice": {
        "type": "object",
        "required": [
          "estimate",
          "customer_external_id",
          "period_id",
          "period_start",
          "period_end",
          "currency",
          "lines",
          "subtotal_minor",
          "tax_minor",
          "credit_minor",
          "total_minor",
          "credit_surplus_minor",
          "as_of",
          "has_invoice"
        ],
        "properties": {
          "estimate": {
            "type": "boolean",
            "description": "Always true. The preview is never the invoice"
          },
          "customer_external_id": {
            "type": "string"
          },
          "period_id": {
            "type": "string",
            "examples": [
              "2026-11"
            ],
            "description": "The period whose invoice this is, in the tenant's time zone"
          },
          "period_start": {
            "type": "string",
            "format": "date-time"
          },
          "period_end": {
            "type": "string",
            "format": "date-time"
          },
          "currency": {
            "type": "string"
          },
          "lines": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/InvoiceLine"
            },
            "description": "The lines as the invoice would have them, in order: fixed fee, usage, late usage, tax, and the credit"
          },
          "subtotal_minor": {
            "type": "string",
            "format": "int64",
            "description": "Before tax and after the credit, as on an invoice"
          },
          "tax_minor": {
            "type": "string",
            "format": "int64"
          },
          "credit_minor": {
            "type": "string",
            "format": "int64",
            "description": "The credit balance the invoice would use, a positive number"
          },
          "total_minor": {
            "type": "string",
            "format": "int64",
            "description": "What would be charged; never negative"
          },
          "credit_surplus_minor": {
            "type": "string",
            "format": "int64",
            "description": "What the lines come to below zero, which the real invoice would add to the customer's credit balance instead of charging a negative total; 0 normally"
          },
          "as_of": {
            "type": "string",
            "format": "date-time",
            "description": "The clock of the estimate"
          },
          "has_invoice": {
            "type": "boolean",
            "description": "False when the customer has no subscription in the period and no late usage to bill"
          }
        }
      },
      "InvoiceLine": {
        "type": "object",
        "required": [
          "line_no",
          "kind",
          "meter_code",
          "origin_period_id",
          "quantity",
          "amount_minor",
          "description",
          "service_from",
          "service_to"
        ],
        "properties": {
          "line_no": {
            "type": "integer"
          },
          "kind": {
            "type": "string",
            "enum": [
              "BASE_FEE",
              "USAGE",
              "LATE_USAGE",
              "CREDIT",
              "CORRECTION",
              "DISCOUNT",
              "TAX",
              "ITEM"
            ]
          },
          "meter_code": {
            "type": "string"
          },
          "origin_period_id": {
            "type": "string"
          },
          "quantity": {
            "type": "string",
            "examples": [
              "1.250"
            ]
          },
          "amount_minor": {
            "type": "string",
            "format": "int64"
          },
          "description": {
            "type": "string"
          },
          "service_from": {
            "type": "string",
            "format": "date-time",
            "description": "The service period the line covers, nullable: true"
          },
          "service_to": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "tax_rate_bps": {
            "type": "integer",
            "description": "ITEM lines and the TAX line of each rate of an order: the VAT rate in basis points (2000 is 20 %); 0 or absent for other lines"
          }
        }
      },
      "ListEntitlementsResponse": {
        "type": "object",
        "required": [
          "items"
        ],
        "properties": {
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/EntitlementStatus"
            }
          }
        }
      },
      "EntitlementStatus": {
        "type": "object",
        "required": [
          "customer_external_id",
          "meter_code",
          "period_id",
          "used",
          "limit",
          "unlimited",
          "allowed",
          "as_of",
          "window",
          "window_id",
          "resets_at",
          "mode",
          "over_limit",
          "overridden",
          "suspended"
        ],
        "properties": {
          "customer_external_id": {
            "type": "string"
          },
          "meter_code": {
            "type": "string"
          },
          "period_id": {
            "type": "string",
            "examples": [
              "2026-11"
            ]
          },
          "used": {
            "type": "string",
            "description": "Exact decimal with the meter's scale, examples: [\"10.500\"]"
          },
          "limit": {
            "type": [
              "string",
              "null"
            ],
            "description": "Exact decimal; null when unlimited, examples: [\"10.500\"]"
          },
          "unlimited": {
            "type": "boolean"
          },
          "allowed": {
            "type": "boolean",
            "description": "(unlimited, used < limit, or a soft or notify limit) and not suspended"
          },
          "as_of": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "window": {
            "type": "string",
            "enum": [
              "hour",
              "day",
              "week",
              "month",
              "year",
              "lifetime"
            ],
            "description": "What the limit counts over; month for a meter without a limit"
          },
          "window_id": {
            "type": "string",
            "description": "The window used counts in: period_id for a month, 2026-11-05T13, 2026-11-05, 2026-W45, 2026 for a year or all for the lifetime",
            "examples": [
              "2026-11-05"
            ]
          },
          "resets_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "description": "When the window ends and used starts again from zero; null for the lifetime window"
          },
          "mode": {
            "type": "string",
            "enum": [
              "hard",
              "soft",
              "notify"
            ]
          },
          "over_limit": {
            "type": "boolean",
            "description": "not unlimited and used >= limit, whatever the mode"
          },
          "overridden": {
            "type": "boolean",
            "description": "The limit is the customer's own override, not its package's"
          },
          "suspended": {
            "type": "boolean",
            "description": "You suspended this customer's service (a block with suspend_service): allowed is false on every meter, with or without a limit. Usage is still accepted and counted."
          }
        }
      },
      "ListEntitlementOverridesResponse": {
        "type": "object",
        "required": [
          "overrides"
        ],
        "properties": {
          "overrides": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/EntitlementOverride"
            }
          }
        }
      },
      "EntitlementOverride": {
        "type": "object",
        "required": [
          "customer_external_id",
          "meter_code",
          "create_time",
          "update_time",
          "limit",
          "alert_thresholds_pct",
          "window",
          "mode"
        ],
        "properties": {
          "customer_external_id": {
            "type": "string"
          },
          "meter_code": {
            "type": "string"
          },
          "create_time": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "update_time": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "limit": {
            "type": "string",
            "description": "Decimal in meter units; \"0\" = unlimited"
          },
          "alert_thresholds_pct": {
            "type": "array",
            "maxItems": 10,
            "items": {
              "type": "integer",
              "minimum": 1,
              "maximum": 1000
            },
            "description": "Strictly ascending percentages of the limit at which an alert fires; empty = 80 and 100",
            "examples": [
              [
                50,
                80,
                100
              ]
            ]
          },
          "window": {
            "$ref": "#/components/schemas/QuotaWindow"
          },
          "mode": {
            "$ref": "#/components/schemas/QuotaMode"
          }
        }
      },
      "QuotaWindow": {
        "type": "string",
        "description": "What a limit counts over, in the tenant's time zone. Unspecified is the month (the billing period). A year is the calendar year (twelve billing periods); a lifetime limit never starts again.",
        "enum": [
          "QUOTA_WINDOW_UNSPECIFIED",
          "QUOTA_WINDOW_MONTH",
          "QUOTA_WINDOW_HOUR",
          "QUOTA_WINDOW_DAY",
          "QUOTA_WINDOW_WEEK",
          "QUOTA_WINDOW_YEAR",
          "QUOTA_WINDOW_LIFETIME"
        ]
      },
      "QuotaMode": {
        "type": "string",
        "description": "What reaching the limit means for `allowed` (Payrudder never refuses usage events). HARD (also unspecified): allowed turns false at the\nlimit. SOFT: allowed stays true and the usage over the limit is billed at the meter's price, which the package must have. NOTIFY: allowed\nstays true; only the alerts are sent.\n",
        "enum": [
          "QUOTA_MODE_UNSPECIFIED",
          "QUOTA_MODE_HARD",
          "QUOTA_MODE_SOFT",
          "QUOTA_MODE_NOTIFY"
        ]
      },
      "EntitlementTerms": {
        "type": "object",
        "required": [
          "limit"
        ],
        "properties": {
          "limit": {
            "type": "string",
            "description": "Decimal in meter units; \"0\" = unlimited"
          },
          "alert_thresholds_pct": {
            "type": "array",
            "maxItems": 10,
            "items": {
              "type": "integer",
              "minimum": 1,
              "maximum": 1000
            },
            "description": "Strictly ascending percentages of the limit at which an alert fires; empty = 80 and 100",
            "examples": [
              [
                50,
                80,
                100
              ]
            ]
          },
          "window": {
            "$ref": "#/components/schemas/QuotaWindow"
          },
          "mode": {
            "$ref": "#/components/schemas/QuotaMode"
          }
        }
      },
      "ListCustomerMembersResponse": {
        "type": "object",
        "required": [
          "members"
        ],
        "properties": {
          "members": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/CustomerMember"
            }
          }
        }
      },
      "CustomerMember": {
        "type": "object",
        "required": [
          "external_id",
          "customer_external_id",
          "role",
          "can_manage_billing"
        ],
        "properties": {
          "external_id": {
            "type": "string",
            "description": "Your own id of the person."
          },
          "customer_external_id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "email": {
            "type": "string"
          },
          "role": {
            "type": "string",
            "enum": [
              "owner",
              "member"
            ],
            "description": "`owner` is the one member who manages billing."
          },
          "can_manage_billing": {
            "type": "boolean",
            "description": "Whether this person may open the payment page, pay and change the card: true for the owner only."
          },
          "create_time": {
            "type": "string",
            "format": "date-time"
          },
          "update_time": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "SetCustomerMemberRequest": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "maxLength": 200
          },
          "email": {
            "type": "string",
            "description": "A plain e-mail address, or empty."
          }
        }
      },
      "CreatePlanRequest": {
        "type": "object",
        "required": [
          "code",
          "name"
        ],
        "properties": {
          "code": {
            "type": "string"
          },
          "name": {
            "type": "string"
          }
        }
      },
      "Plan": {
        "type": "object",
        "required": [
          "id",
          "code",
          "name",
          "latest_version",
          "create_time"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "code": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "latest_version": {
            "type": "integer"
          },
          "create_time": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          }
        }
      },
      "ListPlansResponse": {
        "type": "object",
        "required": [
          "plans"
        ],
        "properties": {
          "plans": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Plan"
            }
          }
        }
      },
      "PublishPlanVersionRequest": {
        "type": "object",
        "properties": {
          "base_fee_minor": {
            "type": "string",
            "format": "int64"
          },
          "fees": {
            "type": "array",
            "description": "Fixed fees other than the tenant currency's monthly one (base_fee_minor), per currency and interval; no duplicates. A yearly subscription needs a yearly fee in its currency, including the tenant's",
            "items": {
              "$ref": "#/components/schemas/CurrencyFeeInput"
            }
          },
          "prices": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/PriceInput"
            }
          },
          "entitlements": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/EntitlementInput"
            }
          },
          "trial_days": {
            "type": "integer",
            "minimum": 0,
            "maximum": 365,
            "description": "The trial a new subscription to this version gets unless its request says otherwise; 0 is none"
          },
          "prorate_after_trial": {
            "type": "boolean",
            "description": "Left out: true. When a trial ends inside a billing period, charge the first period from the trial's end to the period's end instead of the whole fee; false charges the whole fee as versions published before this rule do"
          },
          "trial_once_per_customer": {
            "type": "boolean",
            "description": "Left out: false. A customer who has had a trial before (any subscription that was ever trialing, cancelled ones included) gets no trial from this version: the subscription starts active and says trial_skipped already_used. A request's own trial_days is not checked"
          },
          "trial_entitlements": {
            "type": "array",
            "description": "Limits while a subscription to this version is trialing, one per meter, on meters the version prices or limits. Needs trial_days above 0. A meter left out keeps its normal limit during the trial; a customer's override still wins",
            "items": {
              "$ref": "#/components/schemas/EntitlementInput"
            }
          }
        }
      },
      "CurrencyFeeInput": {
        "type": "object",
        "properties": {
          "currency": {
            "type": "string"
          },
          "base_fee_minor": {
            "type": "string",
            "format": "int64"
          },
          "interval": {
            "type": "string",
            "enum": [
              "SUBSCRIPTION_INTERVAL_MONTH",
              "SUBSCRIPTION_INTERVAL_YEAR"
            ],
            "description": "Default month"
          }
        }
      },
      "PriceInput": {
        "type": "object",
        "required": [
          "meter_code"
        ],
        "properties": {
          "meter_code": {
            "type": "string"
          },
          "per_unit": {
            "type": "object",
            "properties": {
              "unit_price": {
                "type": "string",
                "examples": [
                  "0.002"
                ]
              }
            }
          },
          "tiered": {
            "type": "object",
            "properties": {
              "tiers": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "up_to": {
                      "type": "string",
                      "description": "Empty on the last (unbounded) tier"
                    },
                    "unit_price": {
                      "type": "string"
                    },
                    "flat_fee_minor": {
                      "type": "string",
                      "format": "int64"
                    }
                  }
                }
              }
            }
          },
          "package": {
            "type": "object",
            "properties": {
              "package_size": {
                "type": "string"
              },
              "package_price_minor": {
                "type": "string",
                "format": "int64"
              }
            }
          },
          "included": {
            "type": "string",
            "description": "Quantity of every billing period that is free: the model prices only what is above it. Empty or 0 = none",
            "examples": [
              "1000"
            ]
          }
        }
      },
      "EntitlementInput": {
        "type": "object",
        "required": [
          "meter_code",
          "limit"
        ],
        "properties": {
          "meter_code": {
            "type": "string"
          },
          "limit": {
            "type": "string",
            "description": "Decimal in meter units; \"0\" = unlimited"
          },
          "alert_thresholds_pct": {
            "type": "array",
            "maxItems": 10,
            "items": {
              "type": "integer",
              "minimum": 1,
              "maximum": 1000
            },
            "description": "Strictly ascending percentages of the limit at which an alert fires; empty = 80 and 100",
            "examples": [
              [
                50,
                80,
                100
              ]
            ]
          },
          "window": {
            "$ref": "#/components/schemas/QuotaWindow"
          },
          "mode": {
            "$ref": "#/components/schemas/QuotaMode"
          }
        }
      },
      "PlanVersion": {
        "type": "object",
        "required": [
          "id",
          "plan_id",
          "plan_code",
          "version",
          "base_fee_minor",
          "prices",
          "entitlements",
          "publish_time",
          "trial_days",
          "prorate_after_trial",
          "trial_once_per_customer",
          "trial_entitlements",
          "fees"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "plan_id": {
            "type": "string",
            "format": "uuid"
          },
          "plan_code": {
            "type": "string"
          },
          "version": {
            "type": "integer"
          },
          "base_fee_minor": {
            "type": "string",
            "format": "int64"
          },
          "prices": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Price"
            }
          },
          "entitlements": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Entitlement"
            }
          },
          "publish_time": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "trial_days": {
            "type": "integer",
            "description": "The trial a new subscription to this version gets unless its request says otherwise; 0 is none"
          },
          "prorate_after_trial": {
            "type": "boolean",
            "description": "When a trial ends inside a billing period, the fixed fee of that first period is charged from the trial's end to the period's end instead of in full. False for a version published before the rule existed (it charged the whole period and keeps doing so)"
          },
          "trial_once_per_customer": {
            "type": "boolean",
            "description": "A customer who has had a trial before gets no trial from this version"
          },
          "trial_entitlements": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Entitlement"
            },
            "description": "Limits while trialing, on the meters that have one; the others keep their normal limit"
          },
          "fees": {
            "type": "array",
            "description": "Fixed fees other than the tenant currency's monthly one, per currency and interval",
            "items": {
              "$ref": "#/components/schemas/CurrencyFee"
            }
          }
        }
      },
      "Price": {
        "type": "object",
        "required": [
          "meter_code",
          "included"
        ],
        "properties": {
          "meter_code": {
            "type": "string"
          },
          "per_unit": {
            "type": "object",
            "required": [
              "unit_price"
            ],
            "properties": {
              "unit_price": {
                "type": "string",
                "examples": [
                  "0.002"
                ]
              }
            }
          },
          "tiered": {
            "type": "object",
            "required": [
              "tiers"
            ],
            "properties": {
              "tiers": {
                "type": "array",
                "items": {
                  "type": "object",
                  "required": [
                    "up_to",
                    "unit_price",
                    "flat_fee_minor"
                  ],
                  "properties": {
                    "up_to": {
                      "type": "string",
                      "description": "Empty on the last (unbounded) tier"
                    },
                    "unit_price": {
                      "type": "string"
                    },
                    "flat_fee_minor": {
                      "type": "string",
                      "format": "int64"
                    }
                  }
                }
              }
            }
          },
          "package": {
            "type": "object",
            "required": [
              "package_size",
              "package_price_minor"
            ],
            "properties": {
              "package_size": {
                "type": "string"
              },
              "package_price_minor": {
                "type": "string",
                "format": "int64"
              }
            }
          },
          "included": {
            "type": "string",
            "description": "Quantity of every billing period that is free: the model prices only what is above it. Empty or 0 = none",
            "examples": [
              "1000"
            ]
          }
        }
      },
      "Entitlement": {
        "type": "object",
        "required": [
          "meter_code",
          "limit",
          "alert_thresholds_pct",
          "window",
          "mode"
        ],
        "properties": {
          "meter_code": {
            "type": "string"
          },
          "limit": {
            "type": "string",
            "description": "Decimal in meter units; \"0\" = unlimited"
          },
          "alert_thresholds_pct": {
            "type": "array",
            "maxItems": 10,
            "items": {
              "type": "integer",
              "minimum": 1,
              "maximum": 1000
            },
            "description": "Strictly ascending percentages of the limit at which an alert fires; empty = 80 and 100",
            "examples": [
              [
                50,
                80,
                100
              ]
            ]
          },
          "window": {
            "$ref": "#/components/schemas/QuotaWindow"
          },
          "mode": {
            "$ref": "#/components/schemas/QuotaMode"
          }
        }
      },
      "CurrencyFee": {
        "type": "object",
        "required": [
          "currency",
          "base_fee_minor",
          "interval"
        ],
        "properties": {
          "currency": {
            "type": "string"
          },
          "base_fee_minor": {
            "type": "string",
            "format": "int64"
          },
          "interval": {
            "type": "string",
            "enum": [
              "SUBSCRIPTION_INTERVAL_MONTH",
              "SUBSCRIPTION_INTERVAL_YEAR"
            ],
            "description": "Default month"
          }
        }
      },
      "ListSubscriptionsResponse": {
        "type": "object",
        "required": [
          "subscriptions",
          "next_page_token"
        ],
        "properties": {
          "total": {
            "type": "integer",
            "description": "How many rows match, on a searched, narrowed or sorted list; 0 on the plain list"
          },
          "subscriptions": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Subscription"
            }
          },
          "next_page_token": {
            "type": "string"
          }
        }
      },
      "Subscription": {
        "type": "object",
        "required": [
          "id",
          "customer_id",
          "customer_external_id",
          "plan_version_id",
          "start_time",
          "end_time",
          "create_time",
          "state",
          "interval",
          "currency",
          "trial_end_time",
          "cancel_at_period_end",
          "pause_time",
          "provider",
          "provider_ref",
          "owner",
          "plan_code",
          "plan_version",
          "fee_timing",
          "scheduled_change",
          "coupon_code",
          "quantity",
          "changed_from_id",
          "trial_skipped"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "customer_id": {
            "type": "string",
            "format": "uuid"
          },
          "customer_external_id": {
            "type": "string"
          },
          "plan_version_id": {
            "type": "string",
            "format": "uuid"
          },
          "start_time": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "end_time": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "create_time": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "state": {
            "type": "string",
            "enum": [
              "SUBSCRIPTION_STATE_TRIALING",
              "SUBSCRIPTION_STATE_ACTIVE",
              "SUBSCRIPTION_STATE_PAST_DUE",
              "SUBSCRIPTION_STATE_PAUSED",
              "SUBSCRIPTION_STATE_CANCELLED"
            ]
          },
          "interval": {
            "type": "string",
            "enum": [
              "SUBSCRIPTION_INTERVAL_MONTH",
              "SUBSCRIPTION_INTERVAL_YEAR"
            ]
          },
          "currency": {
            "type": "string"
          },
          "trial_end_time": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "cancel_at_period_end": {
            "type": "boolean"
          },
          "pause_time": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "provider": {
            "type": "string"
          },
          "provider_ref": {
            "type": "string",
            "description": "The provider's id of the subscription, once it is linked"
          },
          "owner": {
            "type": "string",
            "enum": [
              "payrudder",
              "provider"
            ],
            "description": "Who renews it and retries failed renewals; a provider-owned subscription is changed at the provider"
          },
          "plan_code": {
            "type": "string"
          },
          "plan_version": {
            "type": "integer"
          },
          "fee_timing": {
            "type": "string",
            "enum": [
              "FEE_TIMING_ADVANCE",
              "FEE_TIMING_ARREARS"
            ]
          },
          "scheduled_change": {
            "allOf": [
              {
                "$ref": "#/components/schemas/ScheduledChange"
              }
            ],
            "nullable": true
          },
          "coupon_code": {
            "type": "string"
          },
          "quantity": {
            "type": "integer",
            "description": "Seats: a plain multiplier of the plan's fixed fee, 1 unless set"
          },
          "changed_from_id": {
            "type": "string"
          },
          "trial_skipped": {
            "type": "string",
            "description": "Only in the answer to POST /v1/subscriptions: why the subscription has no trial although its version offers one. already_used: the version gives one trial per customer and this customer has had one, so it starts active and is billed now. Empty otherwise"
          }
        }
      },
      "ScheduledChange": {
        "type": "object",
        "required": [
          "plan_code",
          "plan_version",
          "interval",
          "effective_time",
          "quantity"
        ],
        "properties": {
          "plan_code": {
            "type": "string"
          },
          "plan_version": {
            "type": "integer"
          },
          "interval": {
            "type": "string",
            "enum": [
              "SUBSCRIPTION_INTERVAL_MONTH",
              "SUBSCRIPTION_INTERVAL_YEAR"
            ]
          },
          "effective_time": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "quantity": {
            "type": "integer",
            "description": "The seats the subscription has from then"
          }
        }
      },
      "CreateSubscriptionRequest": {
        "type": "object",
        "required": [
          "customer_external_id",
          "plan_code"
        ],
        "properties": {
          "customer_external_id": {
            "type": "string"
          },
          "plan_code": {
            "type": "string"
          },
          "plan_version": {
            "type": "integer",
            "description": "0 = latest"
          },
          "start_time": {
            "type": "string",
            "format": "date-time"
          },
          "trial_days": {
            "type": "integer",
            "minimum": 0,
            "maximum": 365,
            "description": "Left out: the package version's own default trial. 0: no trial whatever the default is"
          },
          "interval": {
            "type": "string",
            "enum": [
              "SUBSCRIPTION_INTERVAL_MONTH",
              "SUBSCRIPTION_INTERVAL_YEAR"
            ]
          },
          "currency": {
            "type": "string",
            "description": "Default is the customer's billing currency, then the tenant's"
          },
          "provider": {
            "type": "string",
            "description": "The payment provider that sells it (for example paddle); default is the tenant's default account"
          },
          "coupon_code": {
            "type": "string",
            "description": "A coupon to redeem on the new subscription"
          },
          "quantity": {
            "type": "integer",
            "minimum": 1,
            "maximum": 100000,
            "description": "Seats: the fixed fee is multiplied by it, usage prices are not. Default 1. Only for a subscription Payrudder runs and bills in advance"
          },
          "fee_timing": {
            "type": "string",
            "enum": [
              "FEE_TIMING_ADVANCE",
              "FEE_TIMING_ARREARS"
            ],
            "description": "Default advance: the fixed fee is invoiced at the start of each period, usage at the close of the month. Arrears (monthly only) bills the fee with the month's usage. A provider that renews subscriptions itself bills the fee."
          }
        }
      },
      "CancelSubscriptionResponse": {
        "type": "object",
        "required": [
          "subscription",
          "credited_minor"
        ],
        "properties": {
          "subscription": {
            "$ref": "#/components/schemas/Subscription"
          },
          "credited_minor": {
            "type": "string",
            "format": "int64",
            "description": "Minor units of the subscription's currency credited to the customer; \"0\" unless credit_unused credited something"
          }
        }
      },
      "ChangePlanRequest": {
        "type": "object",
        "required": [
          "plan_code"
        ],
        "properties": {
          "plan_code": {
            "type": "string"
          },
          "plan_version": {
            "type": "integer",
            "description": "0 = latest"
          },
          "change_time": {
            "type": "string",
            "format": "date-time",
            "description": "Default now"
          }
        }
      },
      "ChangePlanResponse": {
        "type": "object",
        "required": [
          "subscription",
          "old_plan_fee_minor",
          "new_plan_fee_minor"
        ],
        "properties": {
          "subscription": {
            "allOf": [
              {
                "$ref": "#/components/schemas/Subscription"
              }
            ],
            "nullable": true
          },
          "old_plan_fee_minor": {
            "type": "string",
            "format": "int64",
            "description": "The old plan's share of the current month's fixed fee, up to change_time (informational; billing recomputes it)"
          },
          "new_plan_fee_minor": {
            "type": "string",
            "format": "int64",
            "description": "The new plan's share of the current month's fixed fee, from change_time (informational; billing recomputes it)"
          }
        }
      },
      "ChangeRequest": {
        "type": "object",
        "properties": {
          "plan_code": {
            "type": "string",
            "description": "Empty keeps the plan (to change the interval only)"
          },
          "plan_version": {
            "type": "integer",
            "description": "0 = latest"
          },
          "interval": {
            "type": "string",
            "enum": [
              "SUBSCRIPTION_INTERVAL_MONTH",
              "SUBSCRIPTION_INTERVAL_YEAR"
            ],
            "description": "Default keeps the interval"
          },
          "timing": {
            "type": "string",
            "enum": [
              "CHANGE_TIMING_IMMEDIATELY",
              "CHANGE_TIMING_PERIOD_END"
            ],
            "description": "Default depends on the direction of the change"
          },
          "proration": {
            "type": "string",
            "enum": [
              "CHANGE_PRORATION_PRORATE",
              "CHANGE_PRORATION_FULL",
              "CHANGE_PRORATION_NONE"
            ],
            "description": "Default prorate. Prorate keeps the cycle within an interval; full starts a new cycle now; none moves no money now"
          },
          "change_time": {
            "type": "string",
            "format": "date-time",
            "description": "Default now; not in the future"
          },
          "quantity": {
            "type": "integer",
            "minimum": 1,
            "maximum": 100000,
            "description": "The new number of seats; 0 or absent keeps it. A change of seats alone is immediate and prorated in either direction unless timing says otherwise: the unused time of the old seats is credited and the new seats are charged for the rest of the period"
          }
        }
      },
      "ChangeQuote": {
        "type": "object",
        "required": [
          "timing",
          "proration",
          "effective_time",
          "period_start",
          "period_end",
          "credit_minor",
          "charge_minor",
          "net_minor",
          "currency",
          "next_renewal_time",
          "next_renewal_minor",
          "plan_code",
          "plan_version",
          "interval",
          "quantity"
        ],
        "properties": {
          "timing": {
            "type": "string",
            "enum": [
              "CHANGE_TIMING_IMMEDIATELY",
              "CHANGE_TIMING_PERIOD_END"
            ]
          },
          "proration": {
            "type": "string",
            "enum": [
              "CHANGE_PRORATION_PRORATE",
              "CHANGE_PRORATION_FULL",
              "CHANGE_PRORATION_NONE"
            ]
          },
          "effective_time": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "period_start": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "period_end": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "credit_minor": {
            "type": "string",
            "description": "The unused, prepaid part of the old fee",
            "format": "int64"
          },
          "charge_minor": {
            "type": "string",
            "description": "What the new plan costs from the change, format: int64"
          },
          "net_minor": {
            "type": "string",
            "description": "charge - credit: positive is invoiced, negative becomes a credit balance",
            "format": "int64"
          },
          "currency": {
            "type": "string"
          },
          "next_renewal_time": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "next_renewal_minor": {
            "type": "string",
            "format": "int64"
          },
          "plan_code": {
            "type": "string"
          },
          "plan_version": {
            "type": "integer"
          },
          "interval": {
            "type": "string",
            "enum": [
              "SUBSCRIPTION_INTERVAL_MONTH",
              "SUBSCRIPTION_INTERVAL_YEAR"
            ]
          },
          "quantity": {
            "type": "integer",
            "description": "The seats after the change"
          }
        }
      },
      "SchedulePriceChangeRequest": {
        "type": "object",
        "required": [
          "from_version"
        ],
        "properties": {
          "from_version": {
            "type": "integer",
            "minimum": 1,
            "description": "The plan version the subscriptions are on now"
          },
          "to_version": {
            "type": "integer",
            "minimum": 0,
            "description": "The version they move to; 0 or absent is the latest published"
          },
          "notice_days": {
            "type": "integer",
            "minimum": 0,
            "maximum": 365,
            "description": "Days before the new price starts that the customer must be told at the least: absent or 0 is the platform's default (30 until the operator changes it), otherwise at least 14. A customer in a country with a longer minimum (the operator's table) is told that much earlier, or skipped as `renews_soon`."
          },
          "effective_from": {
            "type": "string",
            "format": "date-time",
            "nullable": true,
            "description": "The date the new price starts from. Each subscription then moves on its first period start on or after it (a monthly one on the first renewal from that date, a yearly one perhaps months later) instead of on its next renewal. At least `notice_days` from now and at most two years. A run that continues an open price change must name the date that price change has, or none if it has none (409 `plans.price_change.date_differs`)."
          },
          "notice_send_days_before": {
            "type": "integer",
            "minimum": 0,
            "maximum": 365,
            "description": "Optional: send each customer's notice mail this many days before their new price starts, instead of when the run schedules it. Absent or 0 sends at once; otherwise at least `notice_days` and at most 365. A customer is never told later than their notice (the longer of `notice_days` and the minimum of their country), and a mail that is due already goes at once. A held mail waits in the price change and is sent by a sweep within minutes of its time; withdrawing the price change cancels it, and the operator's kill switch holds it. A run that continues an open price change must name the same value (409 `plans.price_change.date_differs`)."
          },
          "dry_run": {
            "type": "boolean",
            "description": "Only count; change nothing and mail nobody"
          }
        }
      },
      "SchedulePriceChangeResponse": {
        "type": "object",
        "required": [
          "scheduled",
          "scheduled_subscription_ids",
          "skipped",
          "to_version",
          "notice_days"
        ],
        "properties": {
          "scheduled": {
            "type": "integer",
            "description": "Scheduled by this run"
          },
          "scheduled_subscription_ids": {
            "type": "array",
            "items": {
              "type": "string",
              "format": "uuid"
            }
          },
          "skipped": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/PriceChangeSkipped"
            }
          },
          "to_version": {
            "type": "integer"
          },
          "notice_days": {
            "type": "integer"
          },
          "price_change_id": {
            "type": "string",
            "description": "The price change this run made or continued; empty for a dry run when none is open"
          },
          "already_scheduled": {
            "type": "integer",
            "description": "Scheduled by this price change before: not scheduled or mailed again"
          }
        }
      },
      "PriceChangeSkipped": {
        "type": "object",
        "required": [
          "subscription_id",
          "customer_external_id",
          "reason"
        ],
        "properties": {
          "subscription_id": {
            "type": "string",
            "format": "uuid"
          },
          "customer_external_id": {
            "type": "string"
          },
          "reason": {
            "type": "string",
            "enum": [
              "renews_soon",
              "has_pending_change",
              "run_by_provider",
              "not_changeable",
              "customer_blocked"
            ]
          }
        }
      },
      "ListPriceChangesResponse": {
        "type": "object",
        "required": [
          "price_changes"
        ],
        "properties": {
          "price_changes": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/PriceChange"
            }
          }
        }
      },
      "PriceChange": {
        "type": "object",
        "required": [
          "id",
          "plan_code",
          "from_version",
          "to_version",
          "notice_days",
          "effective_time",
          "effective_from",
          "notice_send_days_before",
          "state",
          "created_by",
          "create_time",
          "withdraw_time",
          "withdrawn_by",
          "scheduled",
          "applied",
          "withdrawn",
          "skipped"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "plan_code": {
            "type": "string"
          },
          "from_version": {
            "type": "integer"
          },
          "to_version": {
            "type": "integer"
          },
          "notice_days": {
            "type": "integer",
            "description": "The notice of the latest run"
          },
          "effective_time": {
            "type": "string",
            "format": "date-time",
            "description": "The earliest date a customer's price changes: the first scheduled renewal (until one is scheduled, the end of the notice)"
          },
          "effective_from": {
            "type": "string",
            "format": "date-time",
            "nullable": true,
            "description": "The date the seller chose the new price to start from; null when each subscription moves on its next renewal"
          },
          "notice_send_days_before": {
            "type": "integer",
            "description": "Days before the new price that the notice mails go out; 0 when they go out as the run schedules the change"
          },
          "state": {
            "type": "string",
            "enum": [
              "open",
              "withdrawn"
            ]
          },
          "created_by": {
            "type": "string",
            "description": "The signed-in person's address, key:<id> for an API key, or the operator"
          },
          "create_time": {
            "type": "string",
            "format": "date-time"
          },
          "withdraw_time": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "withdrawn_by": {
            "type": "string"
          },
          "scheduled": {
            "type": "integer",
            "description": "Subscriptions waiting for their renewal"
          },
          "applied": {
            "type": "integer",
            "description": "Subscriptions moved to the new price"
          },
          "withdrawn": {
            "type": "integer",
            "description": "Subscriptions whose change was cancelled (by a withdrawal, or because the seller or the customer changed the subscription)"
          },
          "skipped": {
            "type": "integer",
            "description": "Subscriptions left out; retry tries them again"
          }
        }
      },
      "GetPriceChangeResponse": {
        "type": "object",
        "required": [
          "price_change",
          "items",
          "next_page_token"
        ],
        "properties": {
          "price_change": {
            "$ref": "#/components/schemas/PriceChange"
          },
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/PriceChangeItem"
            }
          },
          "next_page_token": {
            "type": "string"
          }
        }
      },
      "PriceChangeItem": {
        "type": "object",
        "required": [
          "subscription_id",
          "customer_external_id",
          "state",
          "reason",
          "effective_time",
          "notify_time"
        ],
        "properties": {
          "subscription_id": {
            "type": "string",
            "format": "uuid"
          },
          "customer_external_id": {
            "type": "string"
          },
          "state": {
            "type": "string",
            "enum": [
              "scheduled",
              "applied",
              "withdrawn",
              "skipped"
            ]
          },
          "reason": {
            "type": "string",
            "description": "Why it was skipped (as in PriceChangeSkipped); empty otherwise"
          },
          "effective_time": {
            "type": "string",
            "format": "date-time",
            "nullable": true,
            "description": "The renewal the new price starts on; unset for a skipped one"
          },
          "notify_time": {
            "type": "string",
            "format": "date-time",
            "nullable": true,
            "description": "When the customer's mail was queued; unset for a skipped one"
          }
        }
      },
      "WithdrawPriceChangeResponse": {
        "type": "object",
        "required": [
          "price_change",
          "withdrawn"
        ],
        "properties": {
          "price_change": {
            "$ref": "#/components/schemas/PriceChange"
          },
          "withdrawn": {
            "type": "integer",
            "description": "How many waiting changes this call cancelled"
          }
        }
      },
      "ChangeSubscriptionResponse": {
        "type": "object",
        "required": [
          "subscription",
          "quote",
          "scheduled"
        ],
        "properties": {
          "subscription": {
            "allOf": [
              {
                "$ref": "#/components/schemas/Subscription"
              }
            ],
            "nullable": true
          },
          "quote": {
            "allOf": [
              {
                "$ref": "#/components/schemas/ChangeQuote"
              }
            ],
            "nullable": true
          },
          "scheduled": {
            "type": "boolean",
            "description": "True when the change waits for the end of the period"
          }
        }
      },
      "ApplyCouponRequest": {
        "type": "object",
        "required": [
          "code"
        ],
        "properties": {
          "code": {
            "type": "string"
          }
        }
      },
      "TaxRates": {
        "type": "object",
        "required": [
          "rates"
        ],
        "properties": {
          "rates": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "country",
                "name",
                "rate_bps"
              ],
              "properties": {
                "country": {
                  "type": "string",
                  "description": "ISO 3166-1 alpha-2; empty for every country without a rate of its own"
                },
                "name": {
                  "type": "string",
                  "description": "Shown on the invoice, e.g. VAT"
                },
                "rate_bps": {
                  "type": "integer",
                  "minimum": 0,
                  "maximum": 10000,
                  "description": "2000 is 20 %"
                }
              }
            }
          }
        }
      },
      "TaxRatesInput": {
        "type": "object",
        "properties": {
          "rates": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "country": {
                  "type": "string",
                  "description": "ISO 3166-1 alpha-2; empty for every country without a rate of its own"
                },
                "name": {
                  "type": "string",
                  "description": "Shown on the invoice, e.g. VAT"
                },
                "rate_bps": {
                  "type": "integer",
                  "minimum": 0,
                  "maximum": 10000,
                  "description": "2000 is 20 %"
                }
              }
            }
          }
        }
      },
      "DunningSettings": {
        "type": "object",
        "required": [
          "retry_hours",
          "defaults_in_use",
          "update_time"
        ],
        "properties": {
          "retry_hours": {
            "type": "array",
            "maxItems": 6,
            "items": {
              "type": "integer",
              "minimum": 1,
              "maximum": 720
            }
          },
          "defaults_in_use": {
            "type": "boolean",
            "readOnly": true,
            "description": "True when nothing was set and the service-wide delays apply"
          },
          "update_time": {
            "type": "string",
            "format": "date-time",
            "readOnly": true,
            "nullable": true
          },
          "block_on_chargeback": {
            "type": "boolean",
            "description": "A formal dispute (a chargeback) of a customer's payment blocks the customer, category chargeback. Off unless you turn it on; it blocks only when the dispute opens and never lifts the block by itself."
          }
        }
      },
      "DunningSettingsInput": {
        "type": "object",
        "properties": {
          "retry_hours": {
            "type": "array",
            "maxItems": 6,
            "items": {
              "type": "integer",
              "minimum": 1,
              "maximum": 720
            }
          },
          "block_on_chargeback": {
            "type": "boolean",
            "description": "Absent: kept as it is. retry_hours is replaced as before (absent is none)."
          }
        }
      },
      "CreditPackList": {
        "type": "object",
        "required": [
          "packs"
        ],
        "properties": {
          "packs": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/CreditPack"
            }
          }
        }
      },
      "CreditPack": {
        "type": "object",
        "required": [
          "id",
          "name",
          "credits",
          "price_minor",
          "currency",
          "active",
          "create_time",
          "validity_days"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "name": {
            "type": "string"
          },
          "credits": {
            "type": "string",
            "format": "int64"
          },
          "price_minor": {
            "type": "string",
            "format": "int64"
          },
          "currency": {
            "type": "string"
          },
          "active": {
            "type": "boolean"
          },
          "create_time": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "validity_days": {
            "type": "integer",
            "description": "0: the credits bought never expire"
          }
        }
      },
      "CreditPackInput": {
        "type": "object",
        "required": [
          "name",
          "credits",
          "price_minor",
          "currency"
        ],
        "properties": {
          "name": {
            "type": "string",
            "maxLength": 80
          },
          "credits": {
            "type": "string",
            "description": "int64, above zero (a number is accepted too)",
            "format": "int64"
          },
          "price_minor": {
            "type": "string",
            "description": "int64 minor units of the currency, above zero",
            "format": "int64"
          },
          "currency": {
            "type": "string",
            "minLength": 3,
            "maxLength": 3
          },
          "validity_days": {
            "type": "integer",
            "minimum": 0,
            "maximum": 3650,
            "description": "The credits bought expire after this many days; 0 or absent: they never expire"
          }
        }
      },
      "EmptyObject": {
        "type": "object",
        "description": "An empty JSON object"
      },
      "CreditBalance": {
        "type": "object",
        "required": [
          "balance",
          "next_expire_time",
          "lots"
        ],
        "properties": {
          "balance": {
            "type": "string",
            "format": "int64"
          },
          "next_expire_time": {
            "type": "string",
            "format": "date-time",
            "nullable": true,
            "description": "When some of the credits run out; null when none does"
          },
          "lots": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/CreditLot"
            }
          }
        }
      },
      "CreditLot": {
        "type": "object",
        "required": [
          "id",
          "granted",
          "remaining",
          "source",
          "expire_time",
          "create_time"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "granted": {
            "type": "string",
            "format": "int64"
          },
          "remaining": {
            "type": "string",
            "format": "int64"
          },
          "source": {
            "type": "string",
            "enum": [
              "purchase",
              "promo",
              "manual"
            ]
          },
          "expire_time": {
            "type": "string",
            "format": "date-time",
            "nullable": true,
            "description": "Null: the credits never expire"
          },
          "create_time": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          }
        }
      },
      "CreditGrantInput": {
        "type": "object",
        "required": [
          "credits",
          "source"
        ],
        "properties": {
          "credits": {
            "type": "string",
            "description": "int64, above zero (a number is accepted too)",
            "format": "int64"
          },
          "source": {
            "type": "string",
            "enum": [
              "promo",
              "manual"
            ]
          },
          "expire_time": {
            "type": "string",
            "format": "date-time",
            "description": "Must lie in the future; leave out for credits that never expire"
          },
          "reason": {
            "type": "string",
            "maxLength": 200
          },
          "idempotency_key": {
            "type": "string",
            "maxLength": 128
          }
        }
      },
      "CreditResult": {
        "type": "object",
        "required": [
          "balance",
          "replayed"
        ],
        "properties": {
          "balance": {
            "type": "string",
            "description": "int64 as a string: what the customer can spend after the call",
            "format": "int64"
          },
          "replayed": {
            "type": "boolean",
            "description": "True when the key had been used: nothing changed"
          }
        }
      },
      "CreditConsumeInput": {
        "type": "object",
        "required": [
          "credits",
          "idempotency_key"
        ],
        "properties": {
          "credits": {
            "type": "string",
            "description": "int64, above zero (a number is accepted too)",
            "format": "int64"
          },
          "reason": {
            "type": "string",
            "maxLength": 200
          },
          "idempotency_key": {
            "type": "string",
            "maxLength": 128,
            "description": "Required, here or in the Idempotency-Key header"
          }
        }
      },
      "CreditLedgerPage": {
        "type": "object",
        "required": [
          "entries",
          "next_page_token"
        ],
        "properties": {
          "entries": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/CreditLedgerEntry"
            }
          },
          "next_page_token": {
            "type": "string"
          }
        }
      },
      "CreditLedgerEntry": {
        "type": "object",
        "required": [
          "id",
          "lot_id",
          "kind",
          "amount",
          "reason",
          "idempotency_key",
          "source",
          "create_time"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "lot_id": {
            "type": "string",
            "format": "uuid"
          },
          "kind": {
            "type": "string",
            "enum": [
              "grant",
              "consume",
              "expire",
              "revoke"
            ]
          },
          "amount": {
            "type": "string",
            "description": "int64 as a string; negative for consume, expire and revoke (a revoke takes back the credits of a credit pack whose invoice was voided or credited; 0 when none of them was left to take, and its reason says how many could not be)",
            "format": "int64"
          },
          "reason": {
            "type": "string"
          },
          "idempotency_key": {
            "type": "string"
          },
          "source": {
            "type": "string",
            "enum": [
              "purchase",
              "promo",
              "manual"
            ],
            "description": "Where the credits it touched came from; a purchase is a credit pack that was paid for"
          },
          "create_time": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          }
        }
      },
      "CreditSettings": {
        "type": "object",
        "required": [
          "low_threshold"
        ],
        "properties": {
          "low_threshold": {
            "type": "string",
            "description": "int64 credits; 0 turns credits.low off",
            "format": "int64"
          }
        }
      },
      "CreditSettingsInput": {
        "type": "object",
        "properties": {
          "low_threshold": {
            "type": "string",
            "description": "int64 credits; 0 turns credits.low off",
            "format": "int64"
          }
        }
      },
      "CreateWebhookEndpointRequest": {
        "type": "object",
        "required": [
          "url"
        ],
        "properties": {
          "url": {
            "type": "string",
            "format": "uri",
            "maxLength": 2000,
            "description": "https only, a public address, no credentials"
          },
          "description": {
            "type": "string",
            "maxLength": 200
          },
          "event_types": {
            "type": "array",
            "description": "Empty means every type",
            "items": {
              "$ref": "#/components/schemas/WebhookEventType"
            }
          }
        }
      },
      "WebhookEventType": {
        "type": "string",
        "enum": [
          "invoice.finalized",
          "invoice.paid",
          "invoice.voided",
          "invoice.uncollectible",
          "credit_note.created",
          "credit_note.refunded",
          "credit_note.refund_failed",
          "subscription.created",
          "subscription.changed",
          "subscription.change_scheduled",
          "subscription.cancelled",
          "subscription.cancellation_scheduled",
          "subscription.cancellation_withdrawn",
          "subscription.paused",
          "subscription.resumed",
          "subscription.moved_to_provider",
          "subscription.trial_will_end",
          "subscription.updated",
          "payment_link.created",
          "payment_link.paid",
          "payment_link.expired",
          "payment.disputed",
          "credits.purchased",
          "credits.low",
          "customer.blocked",
          "customer.unblocked",
          "entitlement.updated",
          "price_change.scheduled",
          "campaign.started",
          "campaign.ended",
          "contract.accepted",
          "contract.version_published",
          "contract.withdrawal_requested",
          "contract.withdrawal_decided",
          "plan.created",
          "plan.version_published"
        ]
      },
      "WebhookEndpoint": {
        "type": "object",
        "required": [
          "id",
          "url",
          "description",
          "event_types",
          "active",
          "secret",
          "create_time"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "url": {
            "type": "string"
          },
          "description": {
            "type": "string"
          },
          "event_types": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "active": {
            "type": "boolean"
          },
          "secret": {
            "type": "string",
            "description": "whsec_…; only in the response of create and rotate-secret"
          },
          "create_time": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          }
        }
      },
      "ListWebhookEndpointsResponse": {
        "type": "object",
        "required": [
          "endpoints"
        ],
        "properties": {
          "endpoints": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/WebhookEndpoint"
            }
          }
        }
      },
      "WebhookEndpointInput": {
        "type": "object",
        "required": [
          "url",
          "active"
        ],
        "properties": {
          "url": {
            "type": "string",
            "format": "uri",
            "maxLength": 2000,
            "description": "https only, a public address, no credentials"
          },
          "description": {
            "type": "string",
            "maxLength": 200
          },
          "event_types": {
            "type": "array",
            "description": "Empty means every type",
            "items": {
              "$ref": "#/components/schemas/WebhookEventType"
            }
          },
          "active": {
            "type": "boolean",
            "description": "A PUT replaces the endpoint: leaving active out deactivates it"
          }
        }
      },
      "WebhookDelivery": {
        "type": "object",
        "required": [
          "id",
          "event_id",
          "event_type",
          "endpoint_id",
          "state",
          "attempts",
          "next_attempt_time",
          "last_status",
          "last_error",
          "create_time",
          "delivered_time"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "event_id": {
            "type": "string",
            "format": "uuid",
            "description": "The id inside the delivered body and the Payrudder-Event-Id header"
          },
          "event_type": {
            "type": "string",
            "description": "A WebhookEventType, or ping for the test event"
          },
          "endpoint_id": {
            "type": "string",
            "format": "uuid"
          },
          "state": {
            "type": "string",
            "enum": [
              "WEBHOOK_DELIVERY_STATE_PENDING",
              "WEBHOOK_DELIVERY_STATE_DELIVERED",
              "WEBHOOK_DELIVERY_STATE_FAILED"
            ]
          },
          "attempts": {
            "type": "integer"
          },
          "next_attempt_time": {
            "type": "string",
            "format": "date-time",
            "description": "Set while the delivery is pending",
            "nullable": true
          },
          "last_status": {
            "type": "integer",
            "description": "HTTP status of the last attempt; 0 when no attempt got an answer"
          },
          "last_error": {
            "type": "string"
          },
          "create_time": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "delivered_time": {
            "type": "string",
            "format": "date-time",
            "nullable": true,
            "description": "Set once the endpoint answered 2xx"
          }
        }
      },
      "ListWebhookDeliveriesResponse": {
        "type": "object",
        "required": [
          "deliveries",
          "next_page_token"
        ],
        "properties": {
          "deliveries": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/WebhookDelivery"
            }
          },
          "next_page_token": {
            "type": "string"
          }
        }
      },
      "CouponInput": {
        "type": "object",
        "required": [
          "code"
        ],
        "properties": {
          "code": {
            "type": "string",
            "description": "2–40 letters, digits, - or _"
          },
          "name": {
            "type": "string"
          },
          "id": {
            "type": "string",
            "format": "uuid",
            "readOnly": true
          },
          "percent_bps": {
            "type": "integer",
            "minimum": 1,
            "maximum": 10000,
            "description": "1000 is 10 %. Use one of percent_bps, amount_minor and bonus_percent_bps"
          },
          "amount_minor": {
            "type": "string",
            "description": "Minor units of currency; applies only in that currency",
            "format": "int64"
          },
          "currency": {
            "type": "string"
          },
          "bonus_percent_bps": {
            "type": "integer",
            "minimum": 1,
            "maximum": 100000,
            "description": "Extra credits on a credit purchase, in the same lot: 1000 is 10 % more. Credit purchases only"
          },
          "applies_to": {
            "type": "array",
            "items": {
              "type": "string",
              "enum": [
                "COUPON_TARGET_SUBSCRIPTION",
                "COUPON_TARGET_CREDIT_PURCHASE",
                "COUPON_TARGET_PAYMENT"
              ]
            },
            "description": "Where the coupon works; empty means all three (a bonus coupon: credit purchases)"
          },
          "duration": {
            "type": "string",
            "enum": [
              "COUPON_DURATION_ONCE",
              "COUPON_DURATION_REPEATING",
              "COUPON_DURATION_FOREVER"
            ],
            "description": "How long a subscription keeps the coupon; required when it applies to subscriptions"
          },
          "duration_periods": {
            "type": "integer",
            "description": "For a repeating coupon, how many fees"
          },
          "max_redemptions": {
            "type": "integer",
            "description": "0 or absent = unlimited. Counts the uses through all the coupon's codes"
          },
          "redeemed": {
            "type": "integer",
            "readOnly": true,
            "description": "The uses that count against the limit"
          },
          "expire_time": {
            "type": "string",
            "format": "date-time"
          },
          "active": {
            "type": "boolean",
            "readOnly": true
          },
          "create_time": {
            "type": "string",
            "format": "date-time",
            "readOnly": true
          },
          "promotion_code_count": {
            "type": "integer",
            "readOnly": true
          },
          "without_default_code": {
            "type": "boolean",
            "writeOnly": true,
            "description": "Do not make the promotion code with the coupon's own text that a new coupon gets"
          }
        }
      },
      "Coupon": {
        "type": "object",
        "required": [
          "code",
          "name",
          "id",
          "percent_bps",
          "amount_minor",
          "currency",
          "bonus_percent_bps",
          "applies_to",
          "duration",
          "duration_periods",
          "max_redemptions",
          "redeemed",
          "expire_time",
          "active",
          "create_time",
          "promotion_code_count",
          "without_default_code"
        ],
        "properties": {
          "code": {
            "type": "string",
            "description": "2–40 letters, digits, - or _"
          },
          "name": {
            "type": "string"
          },
          "id": {
            "type": "string",
            "format": "uuid",
            "readOnly": true
          },
          "percent_bps": {
            "type": "integer",
            "minimum": 1,
            "maximum": 10000,
            "description": "1000 is 10 %. Use one of percent_bps, amount_minor and bonus_percent_bps"
          },
          "amount_minor": {
            "type": "string",
            "description": "Minor units of currency; applies only in that currency",
            "format": "int64"
          },
          "currency": {
            "type": "string"
          },
          "bonus_percent_bps": {
            "type": "integer",
            "minimum": 1,
            "maximum": 100000,
            "description": "Extra credits on a credit purchase, in the same lot: 1000 is 10 % more. Credit purchases only"
          },
          "applies_to": {
            "type": "array",
            "items": {
              "type": "string",
              "enum": [
                "COUPON_TARGET_SUBSCRIPTION",
                "COUPON_TARGET_CREDIT_PURCHASE",
                "COUPON_TARGET_PAYMENT"
              ]
            },
            "description": "Where the coupon works; empty means all three (a bonus coupon: credit purchases)"
          },
          "duration": {
            "type": "string",
            "enum": [
              "COUPON_DURATION_ONCE",
              "COUPON_DURATION_REPEATING",
              "COUPON_DURATION_FOREVER"
            ],
            "description": "How long a subscription keeps the coupon; required when it applies to subscriptions"
          },
          "duration_periods": {
            "type": "integer",
            "description": "For a repeating coupon, how many fees"
          },
          "max_redemptions": {
            "type": "integer",
            "description": "0 or absent = unlimited. Counts the uses through all the coupon's codes"
          },
          "redeemed": {
            "type": "integer",
            "readOnly": true,
            "description": "The uses that count against the limit"
          },
          "expire_time": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "active": {
            "type": "boolean",
            "readOnly": true
          },
          "create_time": {
            "type": "string",
            "format": "date-time",
            "readOnly": true,
            "nullable": true
          },
          "promotion_code_count": {
            "type": "integer",
            "readOnly": true
          },
          "without_default_code": {
            "type": "boolean",
            "writeOnly": true,
            "description": "Do not make the promotion code with the coupon's own text that a new coupon gets"
          }
        }
      },
      "ListCouponsResponse": {
        "type": "object",
        "required": [
          "coupons"
        ],
        "properties": {
          "coupons": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Coupon"
            }
          }
        }
      },
      "CreatePromotionCodes": {
        "type": "object",
        "properties": {
          "template": {
            "$ref": "#/components/schemas/PromotionCodeInput"
          },
          "codes": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Name the codes, or ask for count"
          },
          "count": {
            "type": "integer",
            "minimum": 1,
            "maximum": 1000
          },
          "prefix": {
            "type": "string",
            "description": "For random codes; at most 20 characters"
          }
        }
      },
      "PromotionCodeInput": {
        "type": "object",
        "description": "What a customer types. Many codes point to one coupon, each with its own limit, expiry and restrictions.",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid",
            "readOnly": true
          },
          "coupon_id": {
            "type": "string",
            "format": "uuid",
            "readOnly": true
          },
          "coupon_code": {
            "type": "string",
            "readOnly": true
          },
          "code": {
            "type": "string",
            "readOnly": true
          },
          "active": {
            "type": "boolean",
            "readOnly": true
          },
          "max_redemptions": {
            "type": "integer",
            "description": "0 or absent = unlimited"
          },
          "redeemed": {
            "type": "integer",
            "readOnly": true
          },
          "expire_time": {
            "type": "string",
            "format": "date-time"
          },
          "first_purchase_only": {
            "type": "boolean",
            "description": "Only a customer who has paid for nothing yet"
          },
          "one_per_customer": {
            "type": "boolean"
          },
          "min_amount_minor": {
            "type": "string",
            "description": "A purchase under this amount cannot use the code; needs min_amount_currency",
            "format": "int64"
          },
          "min_amount_currency": {
            "type": "string"
          },
          "allowed_plans": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Plan codes; empty means any"
          },
          "allowed_packs": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Credit pack ids; empty means any"
          },
          "allowed_currencies": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Empty means any"
          },
          "restore_on_reversal": {
            "type": "boolean",
            "description": "A void or full refund gives the use back to the count. Off by default"
          },
          "create_time": {
            "type": "string",
            "format": "date-time",
            "readOnly": true
          }
        }
      },
      "CreatePromotionCodesResponse": {
        "type": "object",
        "required": [
          "codes"
        ],
        "properties": {
          "codes": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/PromotionCode"
            }
          }
        }
      },
      "PromotionCode": {
        "type": "object",
        "description": "What a customer types. Many codes point to one coupon, each with its own limit, expiry and restrictions.",
        "required": [
          "id",
          "coupon_id",
          "coupon_code",
          "code",
          "active",
          "max_redemptions",
          "redeemed",
          "expire_time",
          "first_purchase_only",
          "one_per_customer",
          "min_amount_minor",
          "min_amount_currency",
          "allowed_plans",
          "allowed_packs",
          "allowed_currencies",
          "restore_on_reversal",
          "create_time"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid",
            "readOnly": true
          },
          "coupon_id": {
            "type": "string",
            "format": "uuid",
            "readOnly": true
          },
          "coupon_code": {
            "type": "string",
            "readOnly": true
          },
          "code": {
            "type": "string",
            "readOnly": true
          },
          "active": {
            "type": "boolean",
            "readOnly": true
          },
          "max_redemptions": {
            "type": "integer",
            "description": "0 or absent = unlimited"
          },
          "redeemed": {
            "type": "integer",
            "readOnly": true
          },
          "expire_time": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "first_purchase_only": {
            "type": "boolean",
            "description": "Only a customer who has paid for nothing yet"
          },
          "one_per_customer": {
            "type": "boolean"
          },
          "min_amount_minor": {
            "type": "string",
            "description": "A purchase under this amount cannot use the code; needs min_amount_currency",
            "format": "int64"
          },
          "min_amount_currency": {
            "type": "string"
          },
          "allowed_plans": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Plan codes; empty means any"
          },
          "allowed_packs": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Credit pack ids; empty means any"
          },
          "allowed_currencies": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Empty means any"
          },
          "restore_on_reversal": {
            "type": "boolean",
            "description": "A void or full refund gives the use back to the count. Off by default"
          },
          "create_time": {
            "type": "string",
            "format": "date-time",
            "readOnly": true,
            "nullable": true
          },
          "automatic": {
            "type": "boolean",
            "readOnly": true,
            "description": "A campaign's code (see /v1/campaigns)"
          },
          "start_time": {
            "type": "string",
            "format": "date-time",
            "readOnly": true,
            "nullable": true,
            "description": "A campaign's code works from this time on"
          }
        }
      },
      "ListPromotionCodesResponse": {
        "type": "object",
        "required": [
          "codes",
          "next_page_token",
          "total"
        ],
        "properties": {
          "codes": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/PromotionCode"
            }
          },
          "next_page_token": {
            "type": "string"
          },
          "total": {
            "type": "integer"
          }
        }
      },
      "CampaignInput": {
        "type": "object",
        "required": [
          "name",
          "target",
          "start_time",
          "expire_time"
        ],
        "properties": {
          "name": {
            "type": "string"
          },
          "percent_bps": {
            "type": "integer",
            "minimum": 1,
            "maximum": 10000,
            "description": "1000 is 10 %. Use one of percent_bps, amount_minor and bonus_percent_bps"
          },
          "amount_minor": {
            "type": "string",
            "format": "int64",
            "description": "Minor units of currency; needs currency. int64 as a string (a number is accepted)"
          },
          "currency": {
            "type": "string"
          },
          "bonus_percent_bps": {
            "type": "integer",
            "minimum": 1,
            "maximum": 100000,
            "description": "Extra credits on a credit pack purchase: 1000 is 10 % more. Packs only"
          },
          "duration": {
            "type": "string",
            "enum": [
              "COUPON_DURATION_ONCE",
              "COUPON_DURATION_REPEATING",
              "COUPON_DURATION_FOREVER"
            ],
            "description": "How many fees of a new subscription get it; plans only, default once"
          },
          "duration_periods": {
            "type": "integer",
            "description": "For a repeating campaign, how many fees"
          },
          "target": {
            "type": "string",
            "enum": [
              "plans",
              "packs"
            ]
          },
          "plans": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Plan codes; empty means every plan"
          },
          "packs": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Credit pack ids; empty means every pack"
          },
          "start_time": {
            "type": "string",
            "format": "date-time"
          },
          "expire_time": {
            "type": "string",
            "format": "date-time",
            "description": "After start_time"
          },
          "max_redemptions": {
            "type": "integer",
            "description": "0 or absent = unlimited"
          },
          "first_purchase_only": {
            "type": "boolean",
            "description": "Only a customer who has paid for nothing yet"
          },
          "one_per_customer": {
            "type": "boolean"
          }
        }
      },
      "Campaign": {
        "type": "object",
        "description": "A discount that new purchases get without a code, from start_time up to expire_time",
        "required": [
          "code",
          "name",
          "status",
          "start_time",
          "expire_time",
          "target",
          "plans",
          "packs",
          "percent_bps",
          "amount_minor",
          "currency",
          "bonus_percent_bps",
          "duration",
          "duration_periods",
          "max_redemptions",
          "redeemed",
          "first_purchase_only",
          "one_per_customer",
          "coupon_code"
        ],
        "properties": {
          "code": {
            "type": "string",
            "description": "The campaign's own code; typing it at checkout finds nothing"
          },
          "name": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "upcoming",
              "running",
              "ended"
            ],
            "description": "ended once expire_time passed or the campaign was ended early"
          },
          "start_time": {
            "type": "string",
            "format": "date-time"
          },
          "expire_time": {
            "type": "string",
            "format": "date-time"
          },
          "target": {
            "type": "string",
            "enum": [
              "plans",
              "packs"
            ]
          },
          "plans": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Plan codes; empty means every plan"
          },
          "packs": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Credit pack ids; empty means every pack"
          },
          "percent_bps": {
            "type": "integer"
          },
          "amount_minor": {
            "type": "string",
            "format": "int64"
          },
          "currency": {
            "type": "string"
          },
          "bonus_percent_bps": {
            "type": "integer"
          },
          "duration": {
            "type": "string",
            "enum": [
              "COUPON_DURATION_UNSPECIFIED",
              "COUPON_DURATION_ONCE",
              "COUPON_DURATION_REPEATING",
              "COUPON_DURATION_FOREVER"
            ]
          },
          "duration_periods": {
            "type": "integer"
          },
          "max_redemptions": {
            "type": "integer",
            "description": "0 = unlimited"
          },
          "redeemed": {
            "type": "integer"
          },
          "first_purchase_only": {
            "type": "boolean"
          },
          "one_per_customer": {
            "type": "boolean"
          },
          "coupon_code": {
            "type": "string",
            "description": "The coupon behind the campaign; its uses are in /v1/coupon-redemptions"
          }
        }
      },
      "ListCampaignsResponse": {
        "type": "object",
        "required": [
          "campaigns"
        ],
        "properties": {
          "campaigns": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Campaign"
            }
          }
        }
      },
      "ListCouponRedemptionsResponse": {
        "type": "object",
        "required": [
          "redemptions",
          "next_page_token",
          "total"
        ],
        "properties": {
          "redemptions": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/CouponRedemption"
            }
          },
          "next_page_token": {
            "type": "string"
          },
          "total": {
            "type": "integer"
          }
        }
      },
      "CouponRedemption": {
        "type": "object",
        "required": [
          "id",
          "coupon_code",
          "promotion_code",
          "customer_external_id",
          "target",
          "target_id",
          "invoice_id",
          "discount_minor",
          "bonus_credits",
          "currency",
          "create_time",
          "reverse_time"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "coupon_code": {
            "type": "string"
          },
          "promotion_code": {
            "type": "string",
            "description": "Empty when an operator applied the coupon or it came from a grant"
          },
          "customer_external_id": {
            "type": "string"
          },
          "target": {
            "type": "string",
            "enum": [
              "COUPON_TARGET_SUBSCRIPTION",
              "COUPON_TARGET_CREDIT_PURCHASE",
              "COUPON_TARGET_PAYMENT"
            ]
          },
          "target_id": {
            "type": "string",
            "format": "uuid",
            "description": "The subscription, or the invoice"
          },
          "invoice_id": {
            "type": "string",
            "format": "uuid"
          },
          "discount_minor": {
            "type": "string",
            "description": "What it took off; a subscription's grows with each fee",
            "format": "int64"
          },
          "bonus_credits": {
            "type": "string",
            "format": "int64"
          },
          "currency": {
            "type": "string"
          },
          "create_time": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "reverse_time": {
            "type": "string",
            "format": "date-time",
            "description": "Set when a void or a full refund reversed it, nullable: true"
          }
        }
      },
      "PromotionQuoteRequest": {
        "type": "object",
        "required": [
          "target",
          "currency"
        ],
        "properties": {
          "code": {
            "type": "string"
          },
          "customer_external_id": {
            "type": "string",
            "description": "Needed by codes that are first-purchase-only or one per customer"
          },
          "target": {
            "type": "string",
            "enum": [
              "COUPON_TARGET_CREDIT_PURCHASE",
              "COUPON_TARGET_PAYMENT"
            ]
          },
          "amount_minor": {
            "type": "string",
            "description": "The price before the discount, format: int64"
          },
          "currency": {
            "type": "string"
          },
          "item": {
            "type": "string",
            "description": "The credit pack id, for codes restricted to some packs"
          },
          "credits": {
            "type": "string",
            "description": "The credits sold, for a bonus coupon"
          },
          "prior_purchases": {
            "type": "boolean",
            "description": "The customer has paid for something before"
          }
        }
      },
      "PromotionQuote": {
        "type": "object",
        "required": [
          "applied",
          "coupon_code",
          "coupon_name",
          "promotion_code",
          "discount_minor",
          "bonus_credits",
          "total_minor",
          "currency",
          "redemption_id"
        ],
        "properties": {
          "applied": {
            "type": "boolean"
          },
          "coupon_code": {
            "type": "string"
          },
          "coupon_name": {
            "type": "string"
          },
          "promotion_code": {
            "type": "string"
          },
          "discount_minor": {
            "type": "string",
            "format": "int64"
          },
          "bonus_credits": {
            "type": "string",
            "format": "int64"
          },
          "total_minor": {
            "type": "string",
            "description": "The price after the discount, never below zero",
            "format": "int64"
          },
          "currency": {
            "type": "string"
          },
          "redemption_id": {
            "type": "string"
          }
        }
      },
      "GrantCustomerCouponRequest": {
        "type": "object",
        "required": [
          "coupon_code",
          "source",
          "source_ref"
        ],
        "properties": {
          "coupon_code": {
            "type": "string"
          },
          "source": {
            "type": "string",
            "description": "Who gives it, e.g. operator or affiliate"
          },
          "source_ref": {
            "type": "string"
          }
        }
      },
      "GrantCustomerCouponResponse": {
        "type": "object",
        "required": [
          "granted"
        ],
        "properties": {
          "granted": {
            "type": "boolean"
          }
        }
      },
      "AffiliateProgram": {
        "type": "object",
        "description": "The rules of the partner program of one environment.",
        "required": [
          "status",
          "commission_kind",
          "commission_value",
          "currency",
          "commission_term",
          "commission_term_value",
          "attribution_window_days",
          "hold_days",
          "min_payout_minor",
          "referred_coupon_code",
          "daily_click_cap",
          "landing_url",
          "auto_approve",
          "create_time",
          "update_time"
        ],
        "properties": {
          "status": {
            "type": "string",
            "enum": [
              "draft",
              "active",
              "paused"
            ],
            "description": "paused and draft earn nothing and turn the links off"
          },
          "commission_kind": {
            "type": "string",
            "enum": [
              "percent_bps",
              "fixed"
            ]
          },
          "commission_value": {
            "type": "string",
            "description": "Basis points of the net, pre-tax amount paid (1000 is 10 %), or minor units of currency for fixed",
            "format": "int64"
          },
          "currency": {
            "type": "string",
            "description": "Only for fixed; a percentage follows the currency of each invoice"
          },
          "commission_term": {
            "type": "string",
            "enum": [
              "first_invoices",
              "months",
              "lifetime"
            ]
          },
          "commission_term_value": {
            "type": "integer",
            "description": "N invoices or N months; absent for lifetime"
          },
          "attribution_window_days": {
            "type": "integer",
            "minimum": 1,
            "maximum": 365,
            "default": 30
          },
          "hold_days": {
            "type": "integer",
            "minimum": 0,
            "maximum": 180,
            "description": "How long a commission waits (the refund window) before it can be paid"
          },
          "min_payout_minor": {
            "type": "string",
            "format": "int64"
          },
          "referred_coupon_code": {
            "type": "string",
            "description": "Coupon a referred customer gets on their next checkout"
          },
          "daily_click_cap": {
            "type": "integer",
            "minimum": 1,
            "maximum": 100000,
            "default": 1000
          },
          "landing_url": {
            "type": "string",
            "description": "Where /r/<code> sends the visitor; empty shows a plain page. A public http(s) address: a host name (not an IP address, localhost or a name without a dot), no user name or password"
          },
          "auto_approve": {
            "type": "boolean",
            "description": "A partner who applies is active at once"
          },
          "create_time": {
            "type": "string",
            "format": "date-time",
            "readOnly": true,
            "nullable": true
          },
          "update_time": {
            "type": "string",
            "format": "date-time",
            "readOnly": true,
            "nullable": true
          }
        }
      },
      "AffiliateProgramInput": {
        "type": "object",
        "description": "The rules of the partner program of one environment.",
        "required": [
          "commission_kind",
          "commission_value"
        ],
        "properties": {
          "status": {
            "type": "string",
            "enum": [
              "draft",
              "active",
              "paused"
            ],
            "description": "paused and draft earn nothing and turn the links off"
          },
          "commission_kind": {
            "type": "string",
            "enum": [
              "percent_bps",
              "fixed"
            ]
          },
          "commission_value": {
            "type": "string",
            "description": "Basis points of the net, pre-tax amount paid (1000 is 10 %), or minor units of currency for fixed"
          },
          "currency": {
            "type": "string",
            "description": "Only for fixed; a percentage follows the currency of each invoice"
          },
          "commission_term": {
            "type": "string",
            "enum": [
              "first_invoices",
              "months",
              "lifetime"
            ]
          },
          "commission_term_value": {
            "type": "integer",
            "description": "N invoices or N months; absent for lifetime"
          },
          "attribution_window_days": {
            "type": "integer",
            "minimum": 1,
            "maximum": 365,
            "default": 30
          },
          "hold_days": {
            "type": "integer",
            "minimum": 0,
            "maximum": 180,
            "description": "How long a commission waits (the refund window) before it can be paid"
          },
          "min_payout_minor": {
            "type": "string",
            "format": "int64"
          },
          "referred_coupon_code": {
            "type": "string",
            "description": "Coupon a referred customer gets on their next checkout"
          },
          "daily_click_cap": {
            "type": "integer",
            "minimum": 1,
            "maximum": 100000,
            "default": 1000
          },
          "landing_url": {
            "type": "string",
            "description": "Where /r/<code> sends the visitor; empty shows a plain page. A public http(s) address: a host name (not an IP address, localhost or a name without a dot), no user name or password"
          },
          "auto_approve": {
            "type": "boolean",
            "description": "A partner who applies is active at once"
          },
          "create_time": {
            "type": "string",
            "format": "date-time",
            "readOnly": true
          },
          "update_time": {
            "type": "string",
            "format": "date-time",
            "readOnly": true
          }
        }
      },
      "CreateAffiliateRequest": {
        "type": "object",
        "required": [
          "email"
        ],
        "properties": {
          "email": {
            "type": "string",
            "format": "email"
          },
          "name": {
            "type": "string"
          },
          "code": {
            "type": "string"
          },
          "payout_method": {
            "type": "string",
            "enum": [
              "manual",
              "bank_transfer"
            ]
          },
          "payout_details": {
            "type": "string",
            "maxLength": 1000
          },
          "pending": {
            "type": "boolean"
          }
        }
      },
      "Affiliate": {
        "type": "object",
        "required": [
          "id",
          "code",
          "email",
          "name",
          "status",
          "payout_method",
          "payout_details",
          "source",
          "signed_in",
          "clicks",
          "referrals",
          "approve_time",
          "create_time",
          "link"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "code": {
            "type": "string"
          },
          "email": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "pending",
              "active",
              "suspended"
            ]
          },
          "payout_method": {
            "type": "string",
            "enum": [
              "manual",
              "bank_transfer"
            ]
          },
          "payout_details": {
            "type": "string"
          },
          "source": {
            "type": "string",
            "enum": [
              "owner",
              "application"
            ]
          },
          "signed_in": {
            "type": "boolean",
            "description": "The partner has signed in and claimed this affiliate"
          },
          "clicks": {
            "type": "string",
            "format": "int64"
          },
          "referrals": {
            "type": "string",
            "format": "int64"
          },
          "approve_time": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "create_time": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "link": {
            "type": "string",
            "description": "The partner's public referral link, https://<gateway>/r/<code>"
          }
        }
      },
      "ListAffiliatesResponse": {
        "type": "object",
        "required": [
          "affiliates",
          "next_page_token",
          "total"
        ],
        "properties": {
          "affiliates": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Affiliate"
            }
          },
          "next_page_token": {
            "type": "string"
          },
          "total": {
            "type": "integer"
          }
        }
      },
      "ListAffiliateReferralsResponse": {
        "type": "object",
        "required": [
          "referrals",
          "next_page_token",
          "total"
        ],
        "properties": {
          "referrals": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/AffiliateReferral"
            }
          },
          "next_page_token": {
            "type": "string"
          },
          "total": {
            "type": "integer"
          }
        }
      },
      "AffiliateReferral": {
        "type": "object",
        "required": [
          "affiliate_id",
          "affiliate_code",
          "customer_external_id",
          "customer_email_masked",
          "source",
          "attribute_time"
        ],
        "properties": {
          "affiliate_id": {
            "type": "string",
            "format": "uuid"
          },
          "affiliate_code": {
            "type": "string"
          },
          "customer_external_id": {
            "type": "string"
          },
          "customer_email_masked": {
            "type": "string"
          },
          "source": {
            "type": "string",
            "enum": [
              "link",
              "code",
              "api"
            ]
          },
          "attribute_time": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          }
        }
      },
      "ListAffiliateCommissionsResponse": {
        "type": "object",
        "required": [
          "commissions",
          "next_page_token",
          "total"
        ],
        "properties": {
          "commissions": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/AffiliateCommission"
            }
          },
          "next_page_token": {
            "type": "string"
          },
          "total": {
            "type": "integer"
          }
        }
      },
      "AffiliateCommission": {
        "type": "object",
        "required": [
          "id",
          "affiliate_id",
          "affiliate_code",
          "customer_external_id",
          "kind",
          "invoice_id",
          "invoice_number",
          "currency",
          "invoice_total_minor",
          "net_minor",
          "amount_minor",
          "reversed_minor",
          "status",
          "parent_id",
          "earn_time",
          "approve_after_time",
          "approve_time",
          "pay_time",
          "payout_id"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "affiliate_id": {
            "type": "string",
            "format": "uuid"
          },
          "affiliate_code": {
            "type": "string"
          },
          "customer_external_id": {
            "type": "string"
          },
          "kind": {
            "type": "string",
            "enum": [
              "commission",
              "reversal"
            ]
          },
          "invoice_id": {
            "type": "string",
            "format": "uuid"
          },
          "invoice_number": {
            "type": "string"
          },
          "currency": {
            "type": "string"
          },
          "invoice_total_minor": {
            "type": "string",
            "description": "What the invoice came to, tax included",
            "format": "int64"
          },
          "net_minor": {
            "type": "string",
            "description": "The base: the net, pre-tax amount actually paid",
            "format": "int64"
          },
          "amount_minor": {
            "type": "string",
            "description": "The commission; negative on a reversal row",
            "format": "int64"
          },
          "reversed_minor": {
            "type": "string",
            "description": "How much of the commission has been taken back, format: int64"
          },
          "status": {
            "type": "string",
            "enum": [
              "pending",
              "approved",
              "paid",
              "reversed"
            ]
          },
          "parent_id": {
            "type": "string",
            "format": "uuid"
          },
          "earn_time": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "approve_after_time": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "approve_time": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "pay_time": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "payout_id": {
            "type": "string",
            "format": "uuid"
          }
        }
      },
      "ReverseAffiliateCommissionRequest": {
        "type": "object",
        "required": [
          "invoice_id",
          "reason"
        ],
        "properties": {
          "invoice_id": {
            "type": "string",
            "format": "uuid"
          },
          "reason": {
            "type": "string",
            "enum": [
              "chargeback",
              "manual"
            ]
          },
          "reference": {
            "type": "string",
            "maxLength": 100,
            "description": "Names this reversal; required for manual"
          },
          "amount_minor": {
            "type": "string",
            "description": "How much to take back; 0 or absent is all that is left",
            "format": "int64"
          },
          "note": {
            "type": "string",
            "maxLength": 500
          }
        }
      },
      "ReverseAffiliateCommissionResponse": {
        "type": "object",
        "required": [
          "reversed_minor",
          "commission"
        ],
        "properties": {
          "reversed_minor": {
            "type": "string",
            "description": "How much this call took back; 0 on a repeat",
            "format": "int64"
          },
          "commission": {
            "allOf": [
              {
                "$ref": "#/components/schemas/AffiliateCommission"
              }
            ],
            "nullable": true
          }
        }
      },
      "GetAffiliateBalancesResponse": {
        "type": "object",
        "required": [
          "balances"
        ],
        "properties": {
          "balances": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/AffiliateBalance"
            }
          }
        }
      },
      "AffiliateBalance": {
        "type": "object",
        "required": [
          "affiliate_id",
          "currency",
          "pending_minor",
          "approved_minor",
          "paid_minor",
          "reversed_minor"
        ],
        "properties": {
          "affiliate_id": {
            "type": "string",
            "format": "uuid"
          },
          "currency": {
            "type": "string"
          },
          "pending_minor": {
            "type": "string",
            "format": "int64"
          },
          "approved_minor": {
            "type": "string",
            "format": "int64"
          },
          "paid_minor": {
            "type": "string",
            "format": "int64"
          },
          "reversed_minor": {
            "type": "string",
            "format": "int64"
          }
        }
      },
      "AffiliateFunnel": {
        "type": "object",
        "required": [
          "from_date",
          "to_date",
          "clicks",
          "referrals",
          "paying_customers",
          "commissions"
        ],
        "properties": {
          "from_date": {
            "type": "string",
            "format": "date"
          },
          "to_date": {
            "type": "string",
            "format": "date"
          },
          "clicks": {
            "type": "string",
            "format": "int64"
          },
          "referrals": {
            "type": "string",
            "description": "Customers attributed in the period, format: int64"
          },
          "paying_customers": {
            "type": "string",
            "description": "Customers with a commission earned in the period, format: int64"
          },
          "commissions": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "currency",
                "earned_minor",
                "reversed_minor"
              ],
              "properties": {
                "currency": {
                  "type": "string"
                },
                "earned_minor": {
                  "type": "string",
                  "format": "int64"
                },
                "reversed_minor": {
                  "type": "string",
                  "format": "int64"
                }
              }
            }
          }
        }
      },
      "ListAffiliatePayoutsResponse": {
        "type": "object",
        "required": [
          "payouts",
          "next_page_token",
          "total"
        ],
        "properties": {
          "payouts": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/AffiliatePayout"
            }
          },
          "next_page_token": {
            "type": "string"
          },
          "total": {
            "type": "integer"
          }
        }
      },
      "AffiliatePayout": {
        "type": "object",
        "required": [
          "id",
          "affiliate_id",
          "affiliate_code",
          "currency",
          "total_minor",
          "commission_count",
          "method",
          "payout_details",
          "reference",
          "status",
          "fake",
          "create_time",
          "pay_time",
          "cancel_time"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "affiliate_id": {
            "type": "string",
            "format": "uuid"
          },
          "affiliate_code": {
            "type": "string"
          },
          "currency": {
            "type": "string"
          },
          "total_minor": {
            "type": "string",
            "description": "Open: what its commissions are worth now. Paid: what was paid",
            "format": "int64"
          },
          "commission_count": {
            "type": "integer"
          },
          "method": {
            "type": "string",
            "enum": [
              "manual",
              "bank_transfer"
            ]
          },
          "payout_details": {
            "type": "string"
          },
          "reference": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "open",
              "paid",
              "cancelled"
            ]
          },
          "fake": {
            "type": "boolean",
            "description": "A payout of a sandbox environment: nothing was or will be paid"
          },
          "create_time": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "pay_time": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "cancel_time": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          }
        }
      },
      "CreateAffiliatePayoutsRequest": {
        "type": "object",
        "properties": {
          "affiliate_id": {
            "type": "string",
            "format": "uuid"
          },
          "currency": {
            "type": "string"
          }
        }
      },
      "CreateAffiliatePayoutsResponse": {
        "type": "object",
        "required": [
          "payouts",
          "skipped"
        ],
        "properties": {
          "payouts": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/AffiliatePayout"
            }
          },
          "skipped": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/CreateAffiliatePayoutsSkipped"
            }
          }
        }
      },
      "CreateAffiliatePayoutsSkipped": {
        "type": "object",
        "required": [
          "affiliate_id",
          "currency",
          "total_minor",
          "reason"
        ],
        "properties": {
          "affiliate_id": {
            "type": "string",
            "format": "uuid"
          },
          "currency": {
            "type": "string"
          },
          "total_minor": {
            "type": "string",
            "format": "int64"
          },
          "reason": {
            "type": "string",
            "enum": [
              "below_minimum",
              "not_positive"
            ]
          }
        }
      },
      "MarkAffiliatePayoutPaidRequest": {
        "type": "object",
        "properties": {
          "reference": {
            "type": "string",
            "maxLength": 200,
            "description": "Your note, e.g. the bank transfer reference"
          }
        }
      },
      "ListAffiliateJournalResponse": {
        "type": "object",
        "required": [
          "entries",
          "totals",
          "next_page_token",
          "total"
        ],
        "properties": {
          "entries": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/AffiliateJournalEntry"
            }
          },
          "totals": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ListAffiliateJournalTotal"
            }
          },
          "next_page_token": {
            "type": "string"
          },
          "total": {
            "type": "integer"
          }
        }
      },
      "AffiliateJournalEntry": {
        "type": "object",
        "required": [
          "id",
          "payout_id",
          "affiliate_id",
          "post_time",
          "currency",
          "account",
          "debit_minor",
          "credit_minor",
          "memo",
          "fake"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "payout_id": {
            "type": "string",
            "format": "uuid"
          },
          "affiliate_id": {
            "type": "string",
            "format": "uuid"
          },
          "post_time": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "currency": {
            "type": "string"
          },
          "account": {
            "type": "string",
            "enum": [
              "commission_expense",
              "commissions_payable",
              "cash"
            ]
          },
          "debit_minor": {
            "type": "string",
            "format": "int64"
          },
          "credit_minor": {
            "type": "string",
            "format": "int64"
          },
          "memo": {
            "type": "string"
          },
          "fake": {
            "type": "boolean"
          }
        }
      },
      "ListAffiliateJournalTotal": {
        "type": "object",
        "required": [
          "currency",
          "debit_minor",
          "credit_minor"
        ],
        "properties": {
          "currency": {
            "type": "string"
          },
          "debit_minor": {
            "type": "string",
            "format": "int64"
          },
          "credit_minor": {
            "type": "string",
            "format": "int64"
          }
        }
      },
      "UpdateAffiliateRequest": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string"
          },
          "payout_method": {
            "type": "string",
            "enum": [
              "manual",
              "bank_transfer"
            ]
          },
          "payout_details": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "active",
              "suspended"
            ]
          }
        }
      },
      "LinkAffiliatePromotionCodeRequest": {
        "type": "object",
        "required": [
          "promotion_code"
        ],
        "properties": {
          "promotion_code": {
            "type": "string"
          }
        }
      },
      "AttributeCustomerRequest": {
        "type": "object",
        "required": [
          "code"
        ],
        "properties": {
          "code": {
            "type": "string"
          },
          "source": {
            "type": "string",
            "enum": [
              "link",
              "code",
              "api"
            ]
          },
          "touch_time": {
            "type": "string",
            "format": "date-time",
            "description": "When the visitor followed the link; default now"
          }
        }
      },
      "AttributeCustomerResponse": {
        "type": "object",
        "required": [
          "attributed",
          "reason"
        ],
        "properties": {
          "attributed": {
            "type": "boolean"
          },
          "reason": {
            "type": "string"
          }
        }
      },
      "GetRevenueReportResponse": {
        "type": "object",
        "required": [
          "rows"
        ],
        "properties": {
          "rows": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/GetRevenueReportRow"
            }
          }
        }
      },
      "GetRevenueReportRow": {
        "type": "object",
        "required": [
          "period",
          "provider",
          "country",
          "currency",
          "invoices",
          "billed_minor",
          "collected_minor",
          "refunded_minor",
          "outstanding_minor",
          "uncollectible_minor",
          "void_minor",
          "credited_minor"
        ],
        "properties": {
          "period": {
            "type": "string"
          },
          "provider": {
            "type": "string"
          },
          "country": {
            "type": "string"
          },
          "currency": {
            "type": "string"
          },
          "invoices": {
            "type": "string",
            "format": "int64"
          },
          "billed_minor": {
            "type": "string",
            "description": "Finalized invoices that are not void, format: int64"
          },
          "collected_minor": {
            "type": "string",
            "description": "Paid, format: int64"
          },
          "refunded_minor": {
            "type": "string",
            "description": "Invoices that were refunded, format: int64"
          },
          "outstanding_minor": {
            "type": "string",
            "description": "Open, format: int64"
          },
          "uncollectible_minor": {
            "type": "string",
            "format": "int64"
          },
          "void_minor": {
            "type": "string",
            "format": "int64"
          },
          "credited_minor": {
            "type": "string",
            "description": "Credit notes issued against these invoices, format: int64"
          }
        }
      },
      "GetDunningReportResponse": {
        "type": "object",
        "required": [
          "invoices",
          "summary"
        ],
        "properties": {
          "invoices": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/GetDunningReportInvoice"
            }
          },
          "summary": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/GetDunningReportSummary"
            }
          }
        }
      },
      "GetDunningReportInvoice": {
        "type": "object",
        "required": [
          "invoice_id",
          "number",
          "customer_external_id",
          "period",
          "provider",
          "currency",
          "total_minor",
          "state",
          "dunning_attempt",
          "next_attempt_time",
          "last_error"
        ],
        "properties": {
          "invoice_id": {
            "type": "string",
            "format": "uuid"
          },
          "number": {
            "type": "string"
          },
          "customer_external_id": {
            "type": "string"
          },
          "period": {
            "type": "string"
          },
          "provider": {
            "type": "string"
          },
          "currency": {
            "type": "string"
          },
          "total_minor": {
            "type": "string",
            "format": "int64"
          },
          "state": {
            "type": "string",
            "enum": [
              "PAYMENT_DECLINED",
              "PAYMENT_UNKNOWN",
              "PAYMENT_PENDING",
              "PAYMENT_ACTION_REQUIRED",
              "PAYMENT_HELD",
              "UNCOLLECTIBLE"
            ]
          },
          "dunning_attempt": {
            "type": "integer"
          },
          "next_attempt_time": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "last_error": {
            "type": "string"
          }
        }
      },
      "GetDunningReportSummary": {
        "type": "object",
        "required": [
          "state",
          "provider",
          "currency",
          "invoices",
          "total_minor"
        ],
        "properties": {
          "state": {
            "type": "string"
          },
          "provider": {
            "type": "string"
          },
          "currency": {
            "type": "string"
          },
          "invoices": {
            "type": "string",
            "format": "int64"
          },
          "total_minor": {
            "type": "string",
            "format": "int64"
          }
        }
      },
      "GetSubscriptionReportResponse": {
        "type": "object",
        "required": [
          "month",
          "rows"
        ],
        "properties": {
          "month": {
            "type": "string"
          },
          "rows": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/GetSubscriptionReportRow"
            }
          }
        }
      },
      "GetSubscriptionReportRow": {
        "type": "object",
        "required": [
          "provider",
          "country",
          "currency",
          "active",
          "trialing",
          "paused",
          "past_due",
          "mrr_minor",
          "new_subscriptions",
          "new_mrr_minor",
          "churned",
          "churned_mrr_minor",
          "plan_code"
        ],
        "properties": {
          "provider": {
            "type": "string"
          },
          "country": {
            "type": "string"
          },
          "currency": {
            "type": "string"
          },
          "active": {
            "type": "string",
            "format": "int64"
          },
          "trialing": {
            "type": "string",
            "format": "int64"
          },
          "paused": {
            "type": "string",
            "format": "int64"
          },
          "past_due": {
            "type": "string",
            "format": "int64"
          },
          "mrr_minor": {
            "type": "string",
            "description": "Fixed fees per month of active and past due subscriptions, format: int64"
          },
          "new_subscriptions": {
            "type": "string",
            "format": "int64"
          },
          "new_mrr_minor": {
            "type": "string",
            "format": "int64"
          },
          "churned": {
            "type": "string",
            "description": "Ended with no successor; a plan change or provider migration is not churn, format: int64"
          },
          "churned_mrr_minor": {
            "type": "string",
            "format": "int64"
          },
          "plan_code": {
            "type": "string"
          }
        }
      },
      "RoutingRules": {
        "type": "object",
        "required": [
          "rules"
        ],
        "properties": {
          "rules": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "country",
                "currency",
                "provider"
              ],
              "properties": {
                "country": {
                  "type": "string",
                  "pattern": "^[A-Z]{2}$",
                  "description": "ISO 3166-1 alpha-2; empty matches any country"
                },
                "currency": {
                  "type": "string",
                  "description": "ISO 4217; empty matches any currency"
                },
                "provider": {
                  "type": "string",
                  "pattern": "^(banktransfer|iyzico|paddle|paytr|stripe)(~[a-z0-9][a-z0-9-]{0,30})?$",
                  "description": "The account the rule sends to: a provider, or a provider with the label of one of its further accounts (paddle~eu)."
                }
              }
            }
          }
        }
      },
      "RoutingRulesInput": {
        "type": "object",
        "properties": {
          "rules": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "country": {
                  "type": "string",
                  "pattern": "^[A-Z]{2}$",
                  "description": "ISO 3166-1 alpha-2; empty matches any country"
                },
                "currency": {
                  "type": "string",
                  "description": "ISO 4217; empty matches any currency"
                },
                "provider": {
                  "type": "string",
                  "pattern": "^(banktransfer|iyzico|paddle|paytr|stripe)(~[a-z0-9][a-z0-9-]{0,30})?$",
                  "description": "The account the rule sends to: a provider, or a provider with the label of one of its further accounts (paddle~eu)."
                }
              }
            }
          }
        }
      },
      "MailSettings": {
        "type": "object",
        "required": [
          "categories"
        ],
        "properties": {
          "categories": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "category",
                "enabled"
              ],
              "properties": {
                "category": {
                  "type": "string",
                  "enum": [
                    "invoice_issued",
                    "payment_receipts",
                    "payment_failed",
                    "usage_alerts",
                    "system",
                    "customer_notices"
                  ]
                },
                "enabled": {
                  "type": "boolean"
                }
              }
            }
          }
        }
      },
      "MailSettingsInput": {
        "type": "object",
        "properties": {
          "categories": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "category": {
                  "type": "string",
                  "enum": [
                    "invoice_issued",
                    "payment_receipts",
                    "payment_failed",
                    "usage_alerts",
                    "system",
                    "customer_notices"
                  ]
                },
                "enabled": {
                  "type": "boolean"
                }
              }
            }
          }
        }
      },
      "ListMailSuppressionsResponse": {
        "type": "object",
        "required": [
          "suppressions",
          "next_page_token",
          "connected"
        ],
        "properties": {
          "suppressions": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/MailSuppression"
            }
          },
          "next_page_token": {
            "type": "string"
          },
          "connected": {
            "type": "boolean",
            "description": "False when this deployment's gateway is not connected to the notifier (the list is then empty because nothing was asked, not because nothing is suppressed)."
          }
        }
      },
      "MailSuppression": {
        "type": "object",
        "required": [
          "address",
          "reason",
          "detail",
          "create_time"
        ],
        "properties": {
          "address": {
            "type": "string"
          },
          "reason": {
            "type": "string",
            "enum": [
              "bounce",
              "complaint",
              "manual"
            ]
          },
          "detail": {
            "type": "string",
            "description": "What the provider or the operator said."
          },
          "create_time": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "ListMailMessagesResponse": {
        "type": "object",
        "required": [
          "messages",
          "next_page_token",
          "connected"
        ],
        "properties": {
          "messages": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/MailMessage"
            }
          },
          "next_page_token": {
            "type": "string"
          },
          "connected": {
            "type": "boolean",
            "description": "False when this deployment's gateway is not connected to the notifier (the log is then empty because nothing was asked, not because no mail was sent)."
          }
        }
      },
      "MailMessage": {
        "type": "object",
        "required": [
          "key",
          "kind",
          "template",
          "recipient",
          "state",
          "claim_time",
          "send_time"
        ],
        "properties": {
          "key": {
            "type": "string",
            "description": "The notifier's key for the mail (one mail has one key, however often it was asked for)."
          },
          "kind": {
            "type": "string",
            "description": "What asked for it: command, limit, trial, price_change, contract, renewal or withdrawal."
          },
          "template": {
            "type": "string"
          },
          "recipient": {
            "type": "string"
          },
          "state": {
            "type": "string",
            "enum": [
              "sending",
              "sent",
              "delivered",
              "delayed",
              "bounced",
              "soft_bounced",
              "complained"
            ]
          },
          "claim_time": {
            "type": "string",
            "format": "date-time"
          },
          "send_time": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          }
        }
      },
      "PriceChangeMailPreviewRequest": {
        "type": "object",
        "required": [
          "plan_code",
          "effective_time",
          "new_renewal_minor"
        ],
        "properties": {
          "locale": {
            "type": "string",
            "description": "The customer's language: en, tr, de, fr, es or ar; empty is the tenant's default language."
          },
          "customer_name": {
            "type": "string",
            "maxLength": 200
          },
          "plan_code": {
            "type": "string",
            "maxLength": 200
          },
          "effective_time": {
            "type": "string",
            "format": "date-time",
            "description": "When the new price starts."
          },
          "new_renewal_minor": {
            "type": "string",
            "format": "int64",
            "description": "The new renewal fee in the tenant's currency, in minor units (a string like every amount; a plain number is read too)."
          }
        }
      },
      "RenderedMail": {
        "type": "object",
        "required": [
          "subject",
          "html",
          "text"
        ],
        "properties": {
          "subject": {
            "type": "string"
          },
          "html": {
            "type": "string"
          },
          "text": {
            "type": "string"
          }
        }
      },
      "PreviewRoutingRequest": {
        "type": "object",
        "properties": {
          "country": {
            "type": "string",
            "examples": [
              "TR"
            ]
          },
          "currency": {
            "type": "string",
            "examples": [
              "TRY"
            ]
          }
        }
      },
      "PreviewRoutingResponse": {
        "type": "object",
        "required": [
          "provider",
          "rule_index",
          "owner",
          "can_charge"
        ],
        "properties": {
          "provider": {
            "type": "string",
            "description": "Empty when no rule matches (the tenant's default account)"
          },
          "rule_index": {
            "type": "integer",
            "description": "-1 when no rule matches"
          },
          "owner": {
            "type": "string",
            "enum": [
              "payrudder",
              "provider"
            ]
          },
          "can_charge": {
            "type": "boolean"
          }
        }
      },
      "ListInvoicesResponse": {
        "type": "object",
        "required": [
          "invoices",
          "next_page_token"
        ],
        "properties": {
          "total": {
            "type": "integer",
            "description": "How many rows match, on a searched, narrowed or sorted list; 0 on the plain list"
          },
          "invoices": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Invoice"
            }
          },
          "next_page_token": {
            "type": "string"
          }
        }
      },
      "Invoice": {
        "type": "object",
        "required": [
          "id",
          "customer_id",
          "customer_external_id",
          "period_id",
          "kind",
          "number",
          "currency",
          "subtotal_minor",
          "total_minor",
          "status",
          "saga_state",
          "create_time",
          "finalize_time",
          "lines",
          "payments",
          "plan_version_id",
          "pdf_object_key",
          "credit_surplus_minor"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "customer_id": {
            "type": "string"
          },
          "customer_external_id": {
            "type": "string"
          },
          "customer_name": {
            "type": "string",
            "description": "The customer's name as frozen on the invoice when it was issued; absent when none was recorded. Filled on the list (GET /v1/invoices) and on a single invoice"
          },
          "period_id": {
            "type": "string"
          },
          "kind": {
            "type": "string",
            "enum": [
              "REGULAR",
              "CORRECTION",
              "FEE",
              "LINK"
            ],
            "description": "FEE: a fixed fee invoiced in advance for one period, or what a plan change moved. LINK: made from an ad-hoc payment link"
          },
          "number": {
            "type": "string",
            "examples": [
              "INV-2026-000123"
            ]
          },
          "currency": {
            "type": "string"
          },
          "subtotal_minor": {
            "type": "string",
            "format": "int64"
          },
          "total_minor": {
            "type": "string",
            "format": "int64"
          },
          "status": {
            "type": "string",
            "enum": [
              "draft",
              "open",
              "paid",
              "uncollectible",
              "void"
            ]
          },
          "saga_state": {
            "type": "string"
          },
          "create_time": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "finalize_time": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "lines": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/InvoiceLine"
            }
          },
          "payments": {
            "type": "array",
            "description": "Payments recorded by hand by the operator (they do not come through a payment provider), oldest first. Only the single-invoice reads fill it.",
            "items": {
              "$ref": "#/components/schemas/InvoicePayment"
            }
          },
          "plan_version_id": {
            "type": "string"
          },
          "pdf_object_key": {
            "type": "string"
          },
          "credit_surplus_minor": {
            "type": "string",
            "format": "int64",
            "description": "What the lines came to below zero (late-usage corrections larger than everything else on the invoice). The total is never negative, so this was added to the customer's credit balance instead, once per invoice, and their next invoices use it. 0 for every other invoice"
          }
        }
      },
      "InvoicePayment": {
        "type": "object",
        "required": [
          "id",
          "invoice_id",
          "method",
          "amount_minor",
          "currency",
          "received_at",
          "reference",
          "note",
          "recorded_by",
          "recorded_at"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "invoice_id": {
            "type": "string"
          },
          "method": {
            "type": "string",
            "enum": [
              "bank_transfer",
              "cash",
              "other"
            ]
          },
          "amount_minor": {
            "type": "string",
            "format": "int64"
          },
          "currency": {
            "type": "string"
          },
          "received_at": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "reference": {
            "type": "string"
          },
          "note": {
            "type": "string"
          },
          "recorded_by": {
            "type": "string"
          },
          "recorded_at": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          }
        }
      },
      "ListCreditNotesResponse": {
        "type": "object",
        "required": [
          "credit_notes",
          "next_page_token"
        ],
        "properties": {
          "credit_notes": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/CreditNote"
            }
          },
          "next_page_token": {
            "type": "string"
          }
        }
      },
      "CreditNote": {
        "type": "object",
        "required": [
          "id",
          "number",
          "invoice_id",
          "invoice_number",
          "customer_id",
          "customer_external_id",
          "currency",
          "total_minor",
          "tax_minor",
          "reason",
          "create_time",
          "disposition",
          "refund_state",
          "refund_error"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "number": {
            "type": "string",
            "description": "CN-2026-000007 (live) or SBX-CN-2026-000007 (sandbox)"
          },
          "invoice_id": {
            "type": "string",
            "format": "uuid"
          },
          "invoice_number": {
            "type": "string"
          },
          "customer_id": {
            "type": "string",
            "format": "uuid"
          },
          "customer_external_id": {
            "type": "string"
          },
          "currency": {
            "type": "string"
          },
          "total_minor": {
            "type": "string",
            "format": "int64"
          },
          "tax_minor": {
            "type": "string",
            "format": "int64",
            "description": "The part of total_minor that is the invoice's tax given back: the note's share of the invoice's total taken from the invoice's tax, so the notes of an invoice give back its tax exactly. 0 for an untaxed invoice and for a note made before this field existed"
          },
          "reason": {
            "type": "string"
          },
          "create_time": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "disposition": {
            "type": "string",
            "enum": [
              "CREDIT_NOTE_DISPOSITION_CREDIT",
              "CREDIT_NOTE_DISPOSITION_REFUND"
            ],
            "description": "Where the amount went: the credit balance, or back to the card"
          },
          "refund_state": {
            "type": "string",
            "enum": [
              "REFUND_STATE_REQUESTED",
              "REFUND_STATE_REFUNDED",
              "REFUND_STATE_FAILED"
            ],
            "description": "Only for a refund to the card"
          },
          "refund_error": {
            "type": "string"
          }
        }
      },
      "CreateInvoiceLinkRequest": {
        "type": "object",
        "properties": {
          "expires_in_days": {
            "type": "integer",
            "minimum": 1,
            "maximum": 365,
            "default": 90
          }
        }
      },
      "CreateInvoiceLinkResponse": {
        "type": "object",
        "required": [
          "token",
          "url",
          "expires_at"
        ],
        "properties": {
          "token": {
            "type": "string"
          },
          "url": {
            "type": "string"
          },
          "expires_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "RevokeInvoiceLinksResponse": {
        "type": "object",
        "required": [
          "revoked"
        ],
        "properties": {
          "revoked": {
            "type": "integer"
          }
        }
      },
      "CreatePaymentLinkRequest": {
        "type": "object",
        "properties": {
          "kind": {
            "type": "string",
            "enum": [
              "invoice",
              "adhoc",
              "credit_pack"
            ],
            "description": "Default: invoice when invoice_id is set, credit_pack when pack_id is set, else adhoc"
          },
          "invoice_id": {
            "type": "string",
            "format": "uuid"
          },
          "pack_id": {
            "type": "string",
            "format": "uuid",
            "description": "credit_pack: the active credit pack to sell. Its price and currency become the link's amount; they are never taken from the request"
          },
          "quantity": {
            "type": "integer",
            "minimum": 1,
            "maximum": 1000,
            "description": "credit_pack: how many packs one payment buys (default 1)"
          },
          "amount_minor": {
            "type": "string",
            "description": "adhoc: a positive int64 in minor units (a string or a number)",
            "format": "int64"
          },
          "currency": {
            "type": "string",
            "description": "adhoc: ISO 4217; the tenant's currency when empty"
          },
          "description": {
            "type": "string",
            "maxLength": 200,
            "description": "adhoc: what it is for; printed on the invoice"
          },
          "customer_external_id": {
            "type": "string",
            "description": "adhoc: make the invoice out to this customer. credit_pack: required, the customer who receives the credits"
          },
          "single_use": {
            "type": "boolean",
            "description": "Default true for adhoc, false for invoice"
          },
          "promotion_code": {
            "type": "string",
            "description": "adhoc and credit_pack, optional: a promotion code the payer gets without typing it (a one-off invoice with a discount). Checked against the link's own amount now (a coupon.* error if it does not work); claimed when the payer continues. An invoice that exists is not changed, so a kind invoice link takes none"
          },
          "required_contracts": {
            "type": "array",
            "uniqueItems": true,
            "items": {
              "type": "string",
              "enum": [
                "distance_sales",
                "pre_info",
                "tos",
                "privacy"
              ]
            },
            "description": "Optional: the agreements the payer must accept on this link's page. The list replaces the seller's tenant-wide required_kinds for this link (it does not add to it); empty or absent: the setting applies. The texts must be published before the link is used, or the page offers no way to pay. An ad-hoc link hands its list to the invoice link the payer continues on. 400 billing.payment_link.bad_required_contracts for an unknown kind or one named twice"
          },
          "return_url": {
            "type": "string",
            "maxLength": 2000,
            "description": "Optional: the \"return to app\" address the link's page offers its payer, instead of the return address set on the app in the console. https on a public host name, or http(s) on localhost. An ad-hoc link hands it to the invoice link the payer continues on. 400 billing.payment_link.bad_return_url otherwise"
          },
          "expires_in_days": {
            "type": "integer",
            "minimum": 1,
            "maximum": 365,
            "description": "Default 30 for adhoc, 90 for invoice"
          },
          "idempotency_key": {
            "type": "string",
            "maxLength": 200
          },
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/LinkItem"
            },
            "description": "kind adhoc: the order. Unit prices include VAT; the invoice has a line per item and the VAT per rate. A link with items is single-use and needs a buyer, a billing address and customer_external_id or customer_email"
          },
          "customer_email": {
            "type": "string",
            "description": "kind adhoc: the buyer's e-mail; finds or makes the customer when customer_external_id is not given"
          },
          "order_ref": {
            "type": "string",
            "maxLength": 200,
            "description": "kind adhoc: the shop's own reference for the order; goes to the invoice, the webhook events and the return URL"
          },
          "buyer": {
            "$ref": "#/components/schemas/LinkBuyer"
          },
          "shipping_address": {
            "$ref": "#/components/schemas/AddressInput",
            "description": "Needed when an item is physical, with line1, city and a two-letter country (400 billing.link.shipping_required); passed to the payment provider, never stored after payment, expiry or revocation, and never returned"
          }
        }
      },
      "LinkItem": {
        "type": "object",
        "required": [
          "name",
          "quantity",
          "unit_amount_minor",
          "vat_rate_bps"
        ],
        "properties": {
          "ref": {
            "type": "string",
            "maxLength": 100,
            "description": "The seller's own reference for the item (a SKU); optional"
          },
          "name": {
            "type": "string",
            "maxLength": 200
          },
          "quantity": {
            "type": "string",
            "format": "int64",
            "description": "int64 as a string (a number is accepted in a request)"
          },
          "unit_amount_minor": {
            "type": "string",
            "format": "int64",
            "description": "Price of one, VAT included, minor units; int64 as a string"
          },
          "vat_rate_bps": {
            "type": "integer",
            "minimum": 1,
            "maximum": 10000,
            "description": "2000 is 20 %. 0 (no VAT) is not supported"
          },
          "physical": {
            "type": "boolean",
            "description": "A physical item needs a shipping address on the link"
          }
        }
      },
      "LinkBuyer": {
        "type": "object",
        "description": "Who the invoice is made out to when the link has items. 400 billing.link.buyer_required when a field below is missing or malformed",
        "properties": {
          "name": {
            "type": "string",
            "maxLength": 200,
            "description": "Required with items"
          },
          "tax_id": {
            "type": "string",
            "pattern": "^([0-9]{10,11})?$",
            "description": "A 10-digit VKN or an 11-digit TCKN; empty for a consumer without one (a buyer in Turkey is then invoiced as 11111111111)"
          },
          "billing_address": {
            "$ref": "#/components/schemas/AddressInput",
            "description": "Required with items: line1, city and a two-letter country; each field at most 200 characters"
          }
        }
      },
      "CreatedPaymentLink": {
        "type": "object",
        "required": [
          "id",
          "kind",
          "status",
          "pack_id",
          "quantity",
          "credits",
          "promotion_code",
          "required_contracts",
          "return_url",
          "invoice_id",
          "customer_external_id",
          "single_use",
          "amount_minor",
          "currency",
          "description",
          "create_time",
          "expire_time",
          "revoke_time",
          "paid_count",
          "last_paid_time",
          "use_count",
          "idempotency_key",
          "token",
          "url",
          "replayed"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "kind": {
            "type": "string",
            "enum": [
              "invoice",
              "adhoc",
              "credit_pack"
            ]
          },
          "status": {
            "type": "string",
            "enum": [
              "active",
              "paid",
              "expired",
              "revoked"
            ],
            "description": "paid: a single-use link that was paid"
          },
          "pack_id": {
            "type": "string",
            "description": "kind credit_pack: the pack sold"
          },
          "quantity": {
            "type": "integer",
            "description": "kind credit_pack: how many packs one use buys"
          },
          "credits": {
            "type": "string",
            "description": "kind credit_pack: the credits one paid use grants (the pack's credits times the quantity, frozen when the link was made); int64 as a string",
            "format": "int64"
          },
          "promotion_code": {
            "type": "string",
            "description": "The code the seller chose for the link (adhoc and credit_pack): applied when the payer continues, unless the payer types another"
          },
          "required_contracts": {
            "type": "array",
            "items": {
              "type": "string",
              "enum": [
                "distance_sales",
                "pre_info",
                "tos",
                "privacy"
              ]
            },
            "description": "The agreements the payer accepts on this link's page instead of the seller's tenant-wide setting (GET /v1/contracts/settings); empty: the setting applies"
          },
          "return_url": {
            "type": "string",
            "description": "The \"return to app\" address this link's page offers instead of the app's setting; empty: the app's"
          },
          "invoice_id": {
            "type": "string",
            "description": "kind invoice: the invoice; empty for an ad-hoc link (its invoices are made on use)"
          },
          "customer_external_id": {
            "type": "string"
          },
          "single_use": {
            "type": "boolean"
          },
          "amount_minor": {
            "type": "string",
            "description": "kind adhoc: int64 minor units as a string",
            "format": "int64"
          },
          "currency": {
            "type": "string"
          },
          "description": {
            "type": "string"
          },
          "create_time": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "expire_time": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "revoke_time": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "paid_count": {
            "type": "integer",
            "description": "Invoices paid through the link"
          },
          "last_paid_time": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "use_count": {
            "type": "integer",
            "description": "Invoices the link created (ad hoc)"
          },
          "idempotency_key": {
            "type": "string"
          },
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/LinkItem"
            },
            "description": "kind adhoc: the order. Unit prices include VAT; the invoice has a line per item and the VAT per rate. A link with items is single-use and needs a buyer, a billing address and customer_external_id or customer_email"
          },
          "customer_email": {
            "type": "string",
            "description": "kind adhoc: the buyer's e-mail; finds or makes the customer when customer_external_id is not given"
          },
          "order_ref": {
            "type": "string",
            "maxLength": 200,
            "description": "kind adhoc: the shop's own reference for the order; goes to the invoice, the webhook events and the return URL"
          },
          "buyer": {
            "$ref": "#/components/schemas/LinkBuyer"
          },
          "token": {
            "type": "string",
            "description": "The secret part of the link; shown once, empty on a replay"
          },
          "url": {
            "type": "string",
            "description": "Absolute when the deployment has a public address set; empty on a replay"
          },
          "replayed": {
            "type": "boolean"
          }
        }
      },
      "ListPaymentLinksResponse": {
        "type": "object",
        "required": [
          "links",
          "next_page_token"
        ],
        "properties": {
          "links": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/PaymentLink"
            }
          },
          "next_page_token": {
            "type": "string"
          }
        }
      },
      "PaymentLink": {
        "type": "object",
        "required": [
          "id",
          "kind",
          "status",
          "pack_id",
          "quantity",
          "credits",
          "promotion_code",
          "required_contracts",
          "return_url",
          "invoice_id",
          "customer_external_id",
          "single_use",
          "amount_minor",
          "currency",
          "description",
          "create_time",
          "expire_time",
          "revoke_time",
          "paid_count",
          "last_paid_time",
          "use_count",
          "idempotency_key"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "kind": {
            "type": "string",
            "enum": [
              "invoice",
              "adhoc",
              "credit_pack"
            ]
          },
          "status": {
            "type": "string",
            "enum": [
              "active",
              "paid",
              "expired",
              "revoked"
            ],
            "description": "paid: a single-use link that was paid"
          },
          "pack_id": {
            "type": "string",
            "description": "kind credit_pack: the pack sold"
          },
          "quantity": {
            "type": "integer",
            "description": "kind credit_pack: how many packs one use buys"
          },
          "credits": {
            "type": "string",
            "description": "kind credit_pack: the credits one paid use grants (the pack's credits times the quantity, frozen when the link was made); int64 as a string",
            "format": "int64"
          },
          "promotion_code": {
            "type": "string",
            "description": "The code the seller chose for the link (adhoc and credit_pack): applied when the payer continues, unless the payer types another"
          },
          "required_contracts": {
            "type": "array",
            "items": {
              "type": "string",
              "enum": [
                "distance_sales",
                "pre_info",
                "tos",
                "privacy"
              ]
            },
            "description": "The agreements the payer accepts on this link's page instead of the seller's tenant-wide setting (GET /v1/contracts/settings); empty: the setting applies"
          },
          "return_url": {
            "type": "string",
            "description": "The \"return to app\" address this link's page offers instead of the app's setting; empty: the app's"
          },
          "invoice_id": {
            "type": "string",
            "description": "kind invoice: the invoice; empty for an ad-hoc link (its invoices are made on use)"
          },
          "customer_external_id": {
            "type": "string"
          },
          "single_use": {
            "type": "boolean"
          },
          "amount_minor": {
            "type": "string",
            "description": "kind adhoc: int64 minor units as a string",
            "format": "int64"
          },
          "currency": {
            "type": "string"
          },
          "description": {
            "type": "string"
          },
          "create_time": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "expire_time": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "revoke_time": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "paid_count": {
            "type": "integer",
            "description": "Invoices paid through the link"
          },
          "last_paid_time": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "use_count": {
            "type": "integer",
            "description": "Invoices the link created (ad hoc)"
          },
          "idempotency_key": {
            "type": "string"
          },
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/LinkItem"
            },
            "description": "kind adhoc: the order. Unit prices include VAT; the invoice has a line per item and the VAT per rate. A link with items is single-use and needs a buyer, a billing address and customer_external_id or customer_email"
          },
          "customer_email": {
            "type": "string",
            "description": "kind adhoc: the buyer's e-mail; finds or makes the customer when customer_external_id is not given"
          },
          "order_ref": {
            "type": "string",
            "maxLength": 200,
            "description": "kind adhoc: the shop's own reference for the order; goes to the invoice, the webhook events and the return URL"
          },
          "buyer": {
            "$ref": "#/components/schemas/LinkBuyer"
          }
        }
      },
      "ConnectCustomerRequest": {
        "type": "object",
        "required": [
          "name"
        ],
        "properties": {
          "name": {
            "type": "string",
            "description": "The person's name, or the organisation's name when `member` is given"
          },
          "email": {
            "type": "string",
            "format": "email",
            "description": "Required for a person. An organisation may leave it out: a new one takes its first member's e-mail."
          },
          "locale": {
            "type": "string",
            "enum": [
              "en",
              "tr",
              "de",
              "fr",
              "es",
              "ar"
            ],
            "description": "The language of the customer's mails and pages"
          },
          "plan_code": {
            "type": "string",
            "description": "The plan the customer page opens with when the customer has no running subscription"
          },
          "member": {
            "$ref": "#/components/schemas/ConnectCustomerMember"
          },
          "expires_in_days": {
            "type": "integer",
            "minimum": 1,
            "maximum": 365,
            "default": 1
          }
        }
      },
      "ConnectCustomerMember": {
        "type": "object",
        "required": [
          "id"
        ],
        "properties": {
          "id": {
            "type": "string",
            "minLength": 1,
            "maxLength": 128,
            "description": "Your own id of the person"
          },
          "name": {
            "type": "string",
            "maxLength": 200
          },
          "email": {
            "type": "string",
            "description": "A plain e-mail address, or empty."
          }
        }
      },
      "ConnectCustomerResponse": {
        "type": "object",
        "required": [
          "url",
          "expires_at",
          "customer",
          "created",
          "billing_owner"
        ],
        "properties": {
          "url": {
            "type": [
              "string",
              "null"
            ],
            "description": "The customer page; null for a member who is not the billing owner"
          },
          "expires_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "customer": {
            "$ref": "#/components/schemas/Customer"
          },
          "created": {
            "type": "boolean",
            "description": "The customer was created by this call"
          },
          "billing_owner": {
            "type": "boolean",
            "description": "The person manages payment: true for a person, and for the organisation's billing owner"
          }
        }
      },
      "CustomerAccess": {
        "type": "object",
        "required": [
          "customer_external_id",
          "allowed",
          "reason",
          "subscription",
          "meters",
          "notices"
        ],
        "properties": {
          "customer_external_id": {
            "type": "string"
          },
          "allowed": {
            "type": "boolean"
          },
          "reason": {
            "type": "string",
            "enum": [
              "ok",
              "trialing",
              "past_due",
              "no_customer",
              "not_member",
              "suspended",
              "no_subscription",
              "cancelled",
              "paused",
              "unpaid",
              "awaiting_payment",
              "limit_reached"
            ]
          },
          "subscription": {
            "allOf": [
              {
                "$ref": "#/components/schemas/CustomerAccessSubscription"
              }
            ],
            "nullable": true
          },
          "meters": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/EntitlementStatus"
            },
            "description": "One per meter asked for, in the order asked"
          },
          "notices": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/AccessNotice"
            },
            "description": "What to show the customer (a banner, a line on a usage page), most serious first; empty when there is nothing to say"
          }
        }
      },
      "CustomerAccessSubscription": {
        "type": "object",
        "required": [
          "id",
          "state",
          "plan_code",
          "trial_ends_at",
          "cancel_at_period_end"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "state": {
            "type": "string",
            "enum": [
              "SUBSCRIPTION_STATE_TRIALING",
              "SUBSCRIPTION_STATE_ACTIVE",
              "SUBSCRIPTION_STATE_PAST_DUE",
              "SUBSCRIPTION_STATE_PAUSED",
              "SUBSCRIPTION_STATE_CANCELLED"
            ]
          },
          "plan_code": {
            "type": "string"
          },
          "trial_ends_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "cancel_at_period_end": {
            "type": "boolean"
          }
        }
      },
      "AccessNotice": {
        "type": "object",
        "required": [
          "code",
          "severity",
          "meter_code",
          "at"
        ],
        "description": "suspended (critical): you suspended the service. payment_required (critical): the first payment is not made, or an invoice became uncollectible.\npayment_overdue (warning): a renewal is being retried. trial_ending (info): the trial ends within 7 days, `at` says when. subscription_ending (info): it is\ncancelled at the end of the paid period, `at` says when when known. limit_reached (critical): a hard limit of `meter_code` is reached. limit_exceeded (warning):\na soft or notify limit is passed. limit_near (warning): 80 % of the limit is used.\n",
        "properties": {
          "code": {
            "type": "string",
            "enum": [
              "suspended",
              "payment_required",
              "payment_overdue",
              "trial_ending",
              "subscription_ending",
              "limit_reached",
              "limit_exceeded",
              "limit_near"
            ]
          },
          "severity": {
            "type": "string",
            "enum": [
              "info",
              "warning",
              "critical"
            ]
          },
          "meter_code": {
            "type": "string",
            "description": "The meter, for a limit notice; empty otherwise"
          },
          "at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          }
        }
      },
      "CreatePortalLinkRequest": {
        "type": "object",
        "properties": {
          "expires_in_days": {
            "type": "integer",
            "minimum": 1,
            "maximum": 365,
            "default": 30
          },
          "member_external_id": {
            "type": "string",
            "description": "The member of the customer the link is for (your own id of the person). The link is made only for the customer's billing owner: anybody else gets 403 `gateway.members.not_owner`. Leave it out when your application decides this itself."
          }
        }
      },
      "CreatePortalLinkResponse": {
        "type": "object",
        "required": [
          "token",
          "url",
          "expires_at",
          "customer_id"
        ],
        "properties": {
          "token": {
            "type": "string"
          },
          "url": {
            "type": "string"
          },
          "expires_at": {
            "type": "string",
            "format": "date-time"
          },
          "customer_id": {
            "type": "string"
          }
        }
      },
      "RevokePortalLinksResponse": {
        "type": "object",
        "required": [
          "revoked"
        ],
        "properties": {
          "revoked": {
            "type": "integer"
          }
        }
      },
      "ListCustomerPaymentsResponse": {
        "type": "object",
        "required": [
          "invoices",
          "payments"
        ],
        "properties": {
          "invoices": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Invoice"
            }
          },
          "payments": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/CustomerPayment"
            }
          }
        }
      },
      "CustomerPayment": {
        "type": "object",
        "required": [
          "invoice_id",
          "invoice_number",
          "kind",
          "status",
          "amount_minor",
          "currency",
          "provider",
          "environment",
          "occurred_at"
        ],
        "properties": {
          "invoice_id": {
            "type": "string",
            "format": "uuid"
          },
          "invoice_number": {
            "type": "string"
          },
          "kind": {
            "type": "string",
            "enum": [
              "charge",
              "refund"
            ]
          },
          "status": {
            "type": "string",
            "enum": [
              "succeeded",
              "declined",
              "failed",
              "pending"
            ]
          },
          "amount_minor": {
            "type": "string",
            "format": "int64"
          },
          "currency": {
            "type": "string"
          },
          "provider": {
            "type": "string"
          },
          "environment": {
            "type": "string",
            "enum": [
              "sandbox",
              "live"
            ]
          },
          "occurred_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "PaymentWait": {
        "type": "object",
        "required": [
          "state"
        ],
        "properties": {
          "state": {
            "type": "string",
            "examples": [
              "PAYMENT_HELD"
            ],
            "description": "The invoice's saga state (`Invoice.saga_state`). Everything below is set only for PAYMENT_HELD and PAYMENT_ACTION_REQUIRED"
          },
          "since_time": {
            "type": "string",
            "format": "date-time",
            "description": "When the payment began to wait. For PAYMENT_ACTION_REQUIRED, the moment the mail asking the customer to confirm it was asked for (not proof that it was delivered)"
          },
          "next_check_time": {
            "type": "string",
            "format": "date-time",
            "description": "When Payrudder looks again (the next pass over held charges, or the next question to the provider)"
          },
          "hold_reason": {
            "type": "string",
            "enum": [
              "customer_blocked",
              "tenant_on_hold",
              "none"
            ],
            "description": "PAYMENT_HELD only, asked of the payment gate now. `customer_blocked`: the customer is blocked for fraud or a chargeback. `tenant_on_hold`: the operator has suspended, frozen or banned the environment. `none`: nothing holds it now, the next pass charges it. Absent when the gate could not be asked"
          },
          "window_ends_time": {
            "type": "string",
            "format": "date-time",
            "description": "PAYMENT_ACTION_REQUIRED only: when the payment counts as declined if the customer has not confirmed it. Absent when the payment service did not answer"
          }
        }
      },
      "InvoiceSaga": {
        "type": "object",
        "required": [
          "id",
          "invoice_id",
          "state",
          "attempt",
          "dunning_attempt",
          "last_error",
          "version"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "invoice_id": {
            "type": "string"
          },
          "state": {
            "type": "string"
          },
          "attempt": {
            "type": "integer"
          },
          "dunning_attempt": {
            "type": "integer"
          },
          "last_error": {
            "type": "string"
          },
          "version": {
            "type": "integer"
          }
        }
      },
      "CreateCreditNoteRequest": {
        "type": "object",
        "properties": {
          "amount_minor": {
            "type": "string",
            "description": "int64 minor units; 0 or absent = what is left of the invoice",
            "format": "int64"
          },
          "reason": {
            "type": "string",
            "maxLength": 500
          },
          "refund_to_card": {
            "type": "boolean",
            "description": "Refund the amount to the card instead of adding it to the credit balance"
          }
        }
      },
      "ListAuditEventsResponse": {
        "type": "object",
        "required": [
          "events",
          "next_page_token",
          "incomplete",
          "unavailable_sources"
        ],
        "properties": {
          "events": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/AuditEvent"
            }
          },
          "next_page_token": {
            "type": "string"
          },
          "incomplete": {
            "type": "boolean",
            "description": "A service that keeps part of the log did not answer: the page may lack its entries"
          },
          "unavailable_sources": {
            "type": "array",
            "items": {
              "type": "string",
              "enum": [
                "plans",
                "billing",
                "payments"
              ]
            }
          }
        }
      },
      "AuditEvent": {
        "type": "object",
        "required": [
          "id",
          "tenant_id",
          "account_id",
          "actor_type",
          "actor_id",
          "actor_email",
          "action",
          "target_type",
          "target_id",
          "summary",
          "detail_json",
          "before_hash",
          "after_hash",
          "source_ip",
          "request_id",
          "create_time"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "tenant_id": {
            "type": "string",
            "description": "Empty for an entry that belongs to no tenant"
          },
          "account_id": {
            "type": "string",
            "description": "Set for an entry that is an account's and no tenant's (its members)"
          },
          "actor_type": {
            "type": "string",
            "enum": [
              "user",
              "api_key",
              "operator",
              "system"
            ]
          },
          "actor_id": {
            "type": "string"
          },
          "actor_email": {
            "type": "string"
          },
          "action": {
            "type": "string",
            "description": "<area>.<what>, for example api_key.created",
            "examples": [
              "api_key.created"
            ]
          },
          "target_type": {
            "type": "string"
          },
          "target_id": {
            "type": "string"
          },
          "summary": {
            "type": "string",
            "description": "One line for a person; secrets are masked"
          },
          "detail_json": {
            "type": "string",
            "description": "A small JSON object of what changed, as text; it holds no secret"
          },
          "before_hash": {
            "type": "string"
          },
          "after_hash": {
            "type": "string"
          },
          "source_ip": {
            "type": "string"
          },
          "request_id": {
            "type": "string"
          },
          "create_time": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          }
        }
      },
      "ListPaymentsResponse": {
        "type": "object",
        "required": [
          "payments",
          "truncated"
        ],
        "properties": {
          "payments": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Payment"
            }
          },
          "truncated": {
            "type": "boolean",
            "description": "Always false: the whole ledger is read. Kept for older clients"
          },
          "total": {
            "type": "integer",
            "description": "How many payments match"
          },
          "next_page_token": {
            "type": "string",
            "description": "The page_token of the next page; empty on the last one"
          }
        }
      },
      "Payment": {
        "type": "object",
        "required": [
          "id",
          "invoice_id",
          "provider",
          "kind",
          "status",
          "amount_minor",
          "currency",
          "occurred_at"
        ],
        "properties": {
          "id": {
            "type": "string",
            "description": "The ledger row that carries the outcome"
          },
          "invoice_id": {
            "type": "string"
          },
          "provider": {
            "type": "string"
          },
          "kind": {
            "type": "string",
            "enum": [
              "charge",
              "refund"
            ]
          },
          "status": {
            "type": "string",
            "enum": [
              "paid",
              "processing",
              "failed",
              "refunded"
            ]
          },
          "amount_minor": {
            "type": "string",
            "format": "int64"
          },
          "currency": {
            "type": "string"
          },
          "occurred_at": {
            "type": "string",
            "format": "date-time"
          },
          "invoice_number": {
            "type": "string",
            "description": "The number of the payment's invoice; absent for a payment without an invoice or an invoice without a number yet"
          },
          "customer_external_id": {
            "type": "string",
            "description": "The external id of the invoice's customer, as frozen on the invoice; absent without an invoice"
          },
          "customer_name": {
            "type": "string",
            "description": "The customer's name as frozen on the invoice; absent when none was recorded"
          }
        }
      },
      "ListDisputesResponse": {
        "type": "object",
        "required": [
          "disputes"
        ],
        "properties": {
          "disputes": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Dispute"
            }
          }
        }
      },
      "Dispute": {
        "type": "object",
        "required": [
          "id",
          "provider",
          "dispute_id",
          "payment_ref",
          "amount_minor",
          "currency",
          "outcome",
          "formal",
          "provider_status",
          "opened_time",
          "handled",
          "note_count"
        ],
        "properties": {
          "id": {
            "type": "string",
            "description": "Payrudder's id of the case"
          },
          "provider": {
            "type": "string",
            "examples": [
              "stripe"
            ]
          },
          "dispute_id": {
            "type": "string",
            "description": "The provider's reference of the case (Stripe's du_..., Paddle's cb_ or cbw_ and the transaction)"
          },
          "payment_ref": {
            "type": "string",
            "description": "The payment that is disputed, as the provider calls it (a Stripe PaymentIntent id, a Paddle transaction id)"
          },
          "invoice_id": {
            "type": "string",
            "format": "uuid",
            "description": "The invoice of that payment; absent for a payment Payrudder did not make"
          },
          "amount_minor": {
            "type": "string",
            "format": "int64",
            "description": "The disputed amount"
          },
          "currency": {
            "type": "string"
          },
          "outcome": {
            "type": "string",
            "enum": [
              "open",
              "won",
              "lost"
            ]
          },
          "formal": {
            "type": "boolean",
            "description": "A chargeback proper, which takes the money back; false is an inquiry or a warning ahead of one"
          },
          "provider_status": {
            "type": "string",
            "description": "The provider's own word (Stripe's needs_response, under_review, won, lost, warning_closed ...)"
          },
          "reason": {
            "type": "string",
            "description": "The cardholder's reason in the provider's words (Stripe's fraudulent, product_not_received ...); absent when the provider does not say"
          },
          "evidence_due_time": {
            "type": "string",
            "format": "date-time",
            "description": "When your evidence is due; absent when the provider does not say"
          },
          "opened_time": {
            "type": "string",
            "format": "date-time"
          },
          "closed_time": {
            "type": "string",
            "format": "date-time",
            "description": "Absent while the case is open"
          },
          "fee_minor": {
            "type": "string",
            "format": "int64",
            "description": "What the provider took for the case, when a notification said (in `fee_currency`, which is the currency the provider settles in and can differ from `currency`). It is also a row of the payment ledger of its own. Stripe's is read from the balance transactions of the dispute and Paddle's from the chargeback fee of the payout totals; UNVERIFIED against a live account. Absent when no notification named a fee"
          },
          "fee_currency": {
            "type": "string",
            "description": "The currency of `fee_minor`"
          },
          "handled": {
            "type": "boolean",
            "description": "Your own mark that you dealt with the case (`PUT /v1/disputes/{id}/handled`). It changes nothing at the provider"
          },
          "handled_time": {
            "type": "string",
            "format": "date-time",
            "description": "Absent when the case is not marked"
          },
          "handled_by": {
            "type": "string",
            "description": "Who marked it; absent when it is not marked, for a viewer of the account, and for an API key that holds no audit:read (the read_only and billing roles)"
          },
          "note_count": {
            "type": "integer",
            "format": "int64",
            "description": "How many notes you wrote (`GET /v1/disputes/{id}/history`)"
          }
        }
      },
      "ListDisputeEventsResponse": {
        "type": "object",
        "required": [
          "events"
        ],
        "properties": {
          "events": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/DisputeEvent"
            }
          }
        }
      },
      "DisputeEvent": {
        "type": "object",
        "required": [
          "id",
          "action",
          "create_time"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "action": {
            "type": "string",
            "enum": [
              "note",
              "handled",
              "unhandled"
            ],
            "description": "A note, the mark that the case was handled, or that mark lifted"
          },
          "note": {
            "type": "string",
            "description": "The text of a note; absent for a mark"
          },
          "actor": {
            "type": "string",
            "description": "Who: the person's address, or the API key as `api_key:<id>`; absent for a viewer of the account"
          },
          "create_time": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "AddDisputeNoteRequest": {
        "type": "object",
        "required": [
          "note"
        ],
        "properties": {
          "note": {
            "type": "string",
            "minLength": 1,
            "maxLength": 2000
          }
        }
      },
      "SetDisputeHandledRequest": {
        "type": "object",
        "required": [
          "handled"
        ],
        "properties": {
          "handled": {
            "type": "boolean"
          }
        }
      },
      "CreateUploadSessionRequest": {
        "type": "object",
        "required": [
          "files"
        ],
        "properties": {
          "files": {
            "type": "array",
            "maxItems": 50,
            "items": {
              "$ref": "#/components/schemas/CreateUploadSessionFile"
            }
          }
        }
      },
      "CreateUploadSessionFile": {
        "type": "object",
        "required": [
          "filename",
          "content_type",
          "size",
          "purpose"
        ],
        "properties": {
          "filename": {
            "type": "string"
          },
          "content_type": {
            "type": "string",
            "examples": [
              "application/pdf"
            ]
          },
          "size": {
            "type": "integer"
          },
          "purpose": {
            "type": "string",
            "enum": [
              "invoice_logo",
              "invoice_attachment",
              "general"
            ]
          },
          "sha256": {
            "type": "string",
            "description": "Optional hex sha256 of the whole file"
          }
        }
      },
      "UploadSession": {
        "type": "object",
        "required": [
          "id",
          "status",
          "expire_time",
          "files"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "OPEN",
              "COMPLETED",
              "EXPIRED",
              "ABORTED"
            ]
          },
          "expire_time": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "files": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/UploadFile"
            }
          }
        }
      },
      "UploadFile": {
        "type": "object",
        "required": [
          "asset_id",
          "filename",
          "status",
          "reject_reason",
          "size",
          "part_size",
          "part_count",
          "presigned_parts",
          "uploaded_parts"
        ],
        "properties": {
          "asset_id": {
            "type": "string"
          },
          "filename": {
            "type": "string"
          },
          "status": {
            "type": "string"
          },
          "reject_reason": {
            "type": "string"
          },
          "size": {
            "type": "string",
            "format": "int64"
          },
          "part_size": {
            "type": "string",
            "format": "int64"
          },
          "part_count": {
            "type": "integer"
          },
          "presigned_parts": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/PresignedPart"
            }
          },
          "uploaded_parts": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "part_number",
                "size",
                "etag"
              ],
              "properties": {
                "part_number": {
                  "type": "integer"
                },
                "size": {
                  "type": "string",
                  "format": "int64"
                },
                "etag": {
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "PresignedPart": {
        "type": "object",
        "required": [
          "part_number",
          "url"
        ],
        "properties": {
          "part_number": {
            "type": "integer"
          },
          "url": {
            "type": "string",
            "format": "uri"
          }
        }
      },
      "PresignPartsResponse": {
        "type": "object",
        "required": [
          "parts"
        ],
        "properties": {
          "parts": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/PresignedPart"
            }
          }
        }
      },
      "CompleteUploadFileRequest": {
        "type": "object",
        "required": [
          "parts"
        ],
        "properties": {
          "parts": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/CompleteUploadFilePart"
            }
          }
        }
      },
      "CompleteUploadFilePart": {
        "type": "object",
        "required": [
          "part_number",
          "etag"
        ],
        "properties": {
          "part_number": {
            "type": "integer"
          },
          "etag": {
            "type": "string"
          }
        }
      },
      "Asset": {
        "type": "object",
        "required": [
          "id",
          "session_id",
          "purpose",
          "filename",
          "content_type",
          "size_bytes",
          "sha256",
          "status",
          "reject_reason",
          "create_time",
          "complete_time"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "session_id": {
            "type": "string"
          },
          "purpose": {
            "type": "string",
            "enum": [
              "PURPOSE_INVOICE_LOGO",
              "PURPOSE_INVOICE_ATTACHMENT",
              "PURPOSE_GENERAL"
            ]
          },
          "filename": {
            "type": "string"
          },
          "content_type": {
            "type": "string"
          },
          "size_bytes": {
            "type": "string",
            "format": "int64"
          },
          "sha256": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "ASSET_STATUS_PENDING",
              "ASSET_STATUS_UPLOADING",
              "ASSET_STATUS_SCANNING",
              "ASSET_STATUS_READY",
              "ASSET_STATUS_REJECTED",
              "ASSET_STATUS_ABORTED",
              "ASSET_STATUS_CORRUPT",
              "ASSET_STATUS_DELETED"
            ]
          },
          "reject_reason": {
            "type": "string",
            "examples": [
              "PART_MISMATCH"
            ]
          },
          "create_time": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "complete_time": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          }
        }
      },
      "UploadAssetsResponse": {
        "type": "object",
        "required": [
          "results"
        ],
        "properties": {
          "results": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/UploadAssetsResult"
            }
          }
        }
      },
      "UploadAssetsResult": {
        "type": "object",
        "required": [
          "filename",
          "status"
        ],
        "properties": {
          "filename": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "created",
              "rejected"
            ]
          },
          "asset": {
            "$ref": "#/components/schemas/Asset"
          },
          "error_code": {
            "type": "string",
            "examples": [
              "CONTENT_TYPE_MISMATCH"
            ]
          },
          "message": {
            "type": "string"
          }
        }
      },
      "ListAssetsResponse": {
        "type": "object",
        "required": [
          "assets",
          "next_page_token"
        ],
        "properties": {
          "assets": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Asset"
            }
          },
          "next_page_token": {
            "type": "string"
          }
        }
      },
      "SetInvoiceLogoRequest": {
        "type": "object",
        "required": [
          "asset_id"
        ],
        "properties": {
          "asset_id": {
            "type": "string",
            "format": "uuid"
          }
        }
      },
      "SetInvoiceLogoResponse": {
        "type": "object",
        "required": [
          "invoice_logo_asset_id"
        ],
        "properties": {
          "invoice_logo_asset_id": {
            "type": "string"
          }
        }
      },
      "ClearInvoiceLogoResponse": {
        "type": "object",
        "required": [
          "invoice_logo_asset_id"
        ],
        "properties": {
          "invoice_logo_asset_id": {
            "type": "string"
          }
        }
      },
      "GetAnalyticsUsageResponse": {
        "type": "object",
        "required": [
          "precision",
          "quantity_scale",
          "points"
        ],
        "properties": {
          "precision": {
            "type": "string",
            "enum": [
              "estimated",
              "exact"
            ]
          },
          "quantity_scale": {
            "type": "integer"
          },
          "points": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/GetAnalyticsUsagePoint"
            }
          }
        }
      },
      "GetAnalyticsUsagePoint": {
        "type": "object",
        "required": [
          "start",
          "quantity",
          "event_count"
        ],
        "properties": {
          "start": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "quantity": {
            "type": "string",
            "examples": [
              "1.500"
            ]
          },
          "event_count": {
            "type": "string",
            "format": "int64"
          }
        }
      },
      "GetTopCustomersResponse": {
        "type": "object",
        "required": [
          "precision",
          "quantity_scale",
          "customers"
        ],
        "properties": {
          "precision": {
            "type": "string"
          },
          "quantity_scale": {
            "type": "integer"
          },
          "customers": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/GetTopCustomersCustomer"
            }
          }
        }
      },
      "GetTopCustomersCustomer": {
        "type": "object",
        "required": [
          "customer_id",
          "customer_external_id",
          "quantity",
          "event_count"
        ],
        "properties": {
          "customer_id": {
            "type": "string"
          },
          "customer_external_id": {
            "type": "string"
          },
          "quantity": {
            "type": "string"
          },
          "event_count": {
            "type": "string",
            "format": "int64"
          }
        }
      },
      "SandboxClosePeriodRequest": {
        "type": "object",
        "properties": {
          "period": {
            "type": "string",
            "pattern": "^[0-9]{4}-(0[1-9]|1[0-2])$"
          }
        }
      },
      "BillingRun": {
        "type": "object",
        "required": [
          "tenant_id",
          "period_id",
          "status",
          "cutoff_time",
          "invoice_count",
          "last_error",
          "generation",
          "start_time",
          "complete_time"
        ],
        "properties": {
          "tenant_id": {
            "type": "string"
          },
          "period_id": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "RUN_STATUS_SCHEDULED",
              "RUN_STATUS_WAITING_WATERMARK",
              "RUN_STATUS_RATING",
              "RUN_STATUS_INVOICING",
              "RUN_STATUS_COMPLETED",
              "RUN_STATUS_FAILED"
            ]
          },
          "cutoff_time": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "invoice_count": {
            "type": "integer"
          },
          "last_error": {
            "type": "string"
          },
          "generation": {
            "type": "integer"
          },
          "start_time": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "complete_time": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          }
        }
      },
      "SetPaymentScenarioRequest": {
        "type": "object",
        "required": [
          "scenario"
        ],
        "properties": {
          "scenario": {
            "type": "string",
            "enum": [
              "success",
              "declined",
              "insufficient_funds_once",
              "error_then_success",
              "timeout_committed",
              "timeout_not_committed"
            ]
          }
        }
      },
      "SandboxScenariosResponse": {
        "type": "object",
        "required": [
          "scenarios"
        ],
        "properties": {
          "scenarios": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/SandboxScenariosScenario"
            }
          }
        }
      },
      "SandboxScenariosScenario": {
        "type": "object",
        "required": [
          "scenario",
          "payment_method",
          "outcome",
          "description"
        ],
        "properties": {
          "scenario": {
            "type": "string",
            "examples": [
              "declined"
            ]
          },
          "payment_method": {
            "type": "string",
            "examples": [
              "pm_sandbox_declined"
            ]
          },
          "outcome": {
            "type": "string",
            "enum": [
              "paid",
              "uncollectible",
              "paid_after_retry",
              "paid_after_status_query",
              "paid_after_recharge"
            ]
          },
          "default": {
            "type": "boolean"
          },
          "description": {
            "type": "string"
          }
        }
      },
      "SandboxSimulateInvoiceRequest": {
        "type": "object",
        "required": [
          "scenario"
        ],
        "properties": {
          "scenario": {
            "type": "string",
            "description": "A name from /v1/sandbox/scenarios, with or without the pm_sandbox_ prefix."
          }
        }
      },
      "SandboxSimulateInvoiceResponse": {
        "type": "object",
        "required": [
          "invoice_id",
          "customer_external_id",
          "scenario",
          "payment_method",
          "retried"
        ],
        "properties": {
          "invoice_id": {
            "type": "string"
          },
          "customer_external_id": {
            "type": "string"
          },
          "scenario": {
            "type": "string"
          },
          "payment_method": {
            "type": "string"
          },
          "retried": {
            "type": "boolean"
          },
          "retry_error": {
            "type": "string"
          }
        }
      }
    },
    "responses": {
      "Error": {
        "description": "Error envelope",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      }
    },
    "parameters": {
      "ExternalID": {
        "name": "external_id",
        "in": "path",
        "required": true,
        "schema": {
          "type": "string"
        }
      },
      "ID": {
        "name": "id",
        "in": "path",
        "required": true,
        "schema": {
          "type": "string",
          "format": "uuid"
        }
      },
      "PlanCode": {
        "name": "code",
        "in": "path",
        "required": true,
        "schema": {
          "type": "string"
        }
      },
      "IdempotencyKey": {
        "name": "Idempotency-Key",
        "in": "header",
        "required": false,
        "description": "Makes a retry safe: a repeat with the same key and the same payload does not do the work twice (credits answer the current balance with replayed: true, a payment link answers the first link without its token, an upload session answers the first session); the same key with another payload is a 409. The body field idempotency_key, where the operation has one, wins over the header.",
        "schema": {
          "type": "string",
          "minLength": 1,
          "maxLength": 200
        }
      }
    },
    "securitySchemes": {
      "apiKey": {
        "type": "http",
        "scheme": "bearer",
        "description": "prk_{test|live}_<prefix>_<secret>"
      }
    }
  },
  "tags": [
    {
      "name": "Affiliates"
    },
    {
      "name": "Analytics"
    },
    {
      "name": "Assets"
    },
    {
      "name": "Audit events"
    },
    {
      "name": "Blocklist"
    },
    {
      "name": "Campaigns"
    },
    {
      "name": "Contract acceptances"
    },
    {
      "name": "Contract withdrawals"
    },
    {
      "name": "Contracts"
    },
    {
      "name": "Coupon redemptions"
    },
    {
      "name": "Coupons"
    },
    {
      "name": "Credit notes"
    },
    {
      "name": "Credit packs"
    },
    {
      "name": "Credits"
    },
    {
      "name": "Customers"
    },
    {
      "name": "Disputes"
    },
    {
      "name": "Dunning settings"
    },
    {
      "name": "E-invoices"
    },
    {
      "name": "Events"
    },
    {
      "name": "Invoices"
    },
    {
      "name": "Mail messages"
    },
    {
      "name": "Mail previews"
    },
    {
      "name": "Mail settings"
    },
    {
      "name": "Mail suppressions"
    },
    {
      "name": "Meters"
    },
    {
      "name": "Payment links"
    },
    {
      "name": "Payments"
    },
    {
      "name": "Plans"
    },
    {
      "name": "Price changes"
    },
    {
      "name": "Promotion codes"
    },
    {
      "name": "Promotions"
    },
    {
      "name": "Rejected events"
    },
    {
      "name": "Reports"
    },
    {
      "name": "Routing rules"
    },
    {
      "name": "Sandbox"
    },
    {
      "name": "Subscriptions"
    },
    {
      "name": "Tax rates"
    },
    {
      "name": "Tenant"
    },
    {
      "name": "Webhook deliveries"
    },
    {
      "name": "Webhook endpoints"
    }
  ]
}
