{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/tip4serv-com/json-schema/tip4serv-com-product-schema.json",
  "title": "Product",
  "x-generated": "2026-11-26",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/tip4serv-com-openapi.json#/components/schemas/Product",
  "type": "object",
  "properties": {
    "id": {
      "type": "integer",
      "description": "Unique identifier of the product."
    },
    "name": {
      "type": "string",
      "description": "Name of the product."
    },
    "status": {
      "type": "boolean",
      "description": "Indicates whether the product is enabled."
    },
    "slug": {
      "type": "string",
      "description": "URL-friendly name of the product."
    },
    "price": {
      "type": "integer",
      "description": "Current price of the product after any applicable discounts. Expressed in the store's currency, or the requested display currency if the `currency` parameter was used."
    },
    "old_price": {
      "type": "integer",
      "description": "Original price of the product without discounts. Expressed in the store's currency, or the requested display currency if the `currency` parameter was used."
    },
    "percent_off": {
      "type": "integer",
      "description": "Percentage off from the original price if a discount applies."
    },
    "recurring_discount": {
      "type": "boolean",
      "description": "Indicates whether the discount is applied on each occurrence of the subscription."
    },
    "discount_end": {
      "type": "integer",
      "description": "Timestamp of the discount expiration. *(expressed in the store timezone)*"
    },
    "donation": {
      "type": "boolean",
      "description": "Indicates if the product is a donation-type product, this allow the user to choose the amount of the donation,  `price` therefore defines the minimum donation amount."
    },
    "min_donation": {
      "type": "number",
      "description": "Minimum donation amount (only present if donation is true). If currency parameter is used, this value is converted to the requested currency."
    },
    "description": {
      "type": "string",
      "description": "Full description of the product."
    },
    "gallery": {
      "type": "array",
      "description": "List of all images related to the product.",
      "items": {
        "type": "string"
      }
    },
    "youtube": {
      "type": "string",
      "description": "URL of the video associated with the product."
    },
    "category": {
      "oneOf": [
        {
          "type": "integer"
        },
        {
          "$ref": "#/$defs/Category"
        }
      ],
      "description": "Category the product belongs to (integer or full category object if details are enabled)."
    },
    "featured": {
      "type": "boolean",
      "description": "Indicates whether the product is featured."
    },
    "stock": {
      "type": "integer",
      "description": "Available stock of the product."
    },
    "trial": {
      "type": "integer",
      "description": "Number of trial days available for this product."
    },
    "renewal_start": {
      "type": "string",
      "description": "If trial days are enabled, defines when commands in the \"Do this after each renewal payment\" event start.\n\nAccepted values:  \n`first_payment`, `second_payment`\n"
    },
    "delivery_method": {
      "type": "string",
      "description": "Indicates the delivery method used to deliver the actions of the product. Can\nPossible values:\n- `all_servers` : will deliver the product commands on every servers. - `server_choice` : the user will be prompted to choose on which server he wish to receive his product. - `auto_detect` : Tip4Serv will automatically detect on which server the user is connected, and deliver only on this server.\nIf no option is specified, the default option will be set to `all_servers`"
    },
    "server_choice": {
      "type": "boolean",
      "description": "Indicates whether the customer can select the server for product delivery.\n⚠ This flag is deprecated, please use delivery_mode instead, to know the delivery method of the actions."
    },
    "quantity": {
      "type": "boolean",
      "description": "Indicates whether the customer can select the quantity to purchase."
    },
    "cmd_multiplier": {
      "type": "boolean",
      "description": "If quantity is selectable, determines whether commands are multiplied by the chosen quantity."
    },
    "files": {
      "type": "boolean",
      "description": "Indicates if the product provides downloadable files upon purchase."
    },
    "subscription": {
      "type": "boolean",
      "description": "Indicates whether the product is a subscription."
    },
    "disable_giftcard_payments": {
      "type": "boolean",
      "description": "Indicates whether the product can be purchased with a giftcard. If not specified this option will be set to false by default. If set to true a customer won't be able to purchase this product with a giftcard.\n"
    },
    "giftcard": {
      "type": "boolean",
      "description": "Indicates whether the product supports gift cards."
    },
    "giftcard_expiration": {
      "type": "boolean",
      "description": "Indicates whether the generated gift card will eventually expire."
    },
    "giftcard_expiration_duration_periodicity": {
      "type": "string",
      "description": "Unit of time for the gift card expiration duration.\n\nPossible values:  \n- `day` – duration in days   - `week` – duration in weeks   - `month` – duration in months   - `year` – duration in years\n\nExample: If `duration_periodicity = month` and `period_num = 3`, the giftcard will expire 3 months after the purchase.\n"
    },
    "giftcard_expiration_period_num": {
      "type": "integer",
      "description": "Number of `duration_periodicity` units before the giftcard expires.\nExamples:  \n- Giftcard expires after 3 months  \n- Giftcard expires after 1 year\nExample: `period_num: 3` → charge every 3 months\n"
    },
    "enable_stock": {
      "type": "boolean",
      "description": "Indicates if stock management is enabled for the product."
    },
    "subscription_cycle": {
      "type": "string",
      "description": "Determines whether subscriptions are recurring or expire by default. Accepted values:   `each`, `expire`"
    },
    "cumul_sub": {
      "type": "boolean",
      "description": "If set to false prevents customers from subscribing to the same product multiple times."
    },
    "onetime_sub": {
      "type": "boolean",
      "description": "Allows customers to purchase the product for a single billing cycle without subscribing."
    },
    "enable_trial": {
      "type": "boolean",
      "description": "Indicates whether trial days are enabled."
    },
    "purchase_limit": {
      "$ref": "#/$defs/PurchaseLimit",
      "description": "Rules limiting the number of times a customer can purchase the product."
    },
    "duration_periodicity": {
      "type": "string",
      "description": "Unit of time for the subscription duration.\n\nPossible values:  \n- `day` – duration in days  \n- `week` – duration in weeks  \n- `month` – duration in months  \n- `year` – duration in years\n\nExample: If `duration_periodicity = month` and `period_num = 3`, the subscription lasts 3 months.\n"
    },
    "period_num": {
      "type": "number",
      "description": "Number of `duration_periodicity` units before the subscription expires or the next charge occurs.\n\nExamples:  \n- Charge the customer every 3 months  \n- Charge the customer every 1 year\n\nAccepted ranges:  \n- 1–99 for days  \n- 1–52 for weeks  \n- 1–12 for months  \n- 1–1 for years\n\nExample: `period_num: 3` → charge every 3 months\n"
    },
    "custom_rules": {
      "type": "array",
      "description": "Array of custom rules applied to the product's custom fields.",
      "items": {
        "$ref": "#/$defs/CustomRule"
      }
    },
    "custom_fields": {
      "type": "array",
      "description": "Array of custom fields attached to the product.",
      "items": {
        "$ref": "#/$defs/CustomField"
      }
    },
    "created_date": {
      "type": "integer",
      "description": "Timestamp of product creation in the store's timezone."
    },
    "last_edited": {
      "type": "integer",
      "description": "Timestamp of the last product modification in the store's timezone."
    },
    "server_options": {
      "type": "array",
      "description": "Array of server options to choose, will be sent if the delivery_method is  `server_choice`.",
      "items": {
        "$ref": "#/$defs/ServerChoice"
      }
    },
    "actions": {
      "type": "object",
      "description": "Array of different actions to execute, indexed by it's server ID.",
      "additionalProperties": {
        "$ref": "#/$defs/Action"
      }
    },
    "currency": {
      "type": "string",
      "description": "Currency in which all prices are expressed. Matches the requested `currency` parameter, or the store's default currency if not specified."
    }
  },
  "required": [
    "id",
    "name",
    "slug",
    "price",
    "status",
    "description",
    "gallery",
    "category",
    "featured",
    "stock",
    "trial",
    "server_choice",
    "delivery_method",
    "quantity",
    "files",
    "subscription",
    "giftcard",
    "enable_stock",
    "cumul_sub",
    "enable_trial",
    "created_date",
    "last_edited",
    "actions"
  ],
  "$defs": {
    "Action": {
      "type": "object",
      "description": "Each server ID maps to event arrays. Game servers use `{str, event}`. Discord servers support `{channel, message}`, `{give_role: role_id}` on payment, and `{del_role: role_id}` on refund or expiry. Role actions are not supported for renewal.",
      "properties": {
        "payment_role_required": {
          "type": "array",
          "description": "Discord role IDs a customer must already have to purchase this product.",
          "items": {
            "type": "string",
            "pattern": "^[1-9][0-9]*$"
          }
        },
        "payment_command": {
          "type": "array",
          "description": "Actions executed after payment; Discord actions may send messages or add roles.",
          "items": {
            "allOf": [
              {
                "$ref": "#/$defs/SimpleServerCommand"
              },
              {
                "not": {
                  "required": [
                    "del_role"
                  ]
                }
              }
            ]
          }
        },
        "refund_command": {
          "type": "array",
          "description": "Actions executed after a refund; Discord actions may send messages or remove roles.",
          "items": {
            "allOf": [
              {
                "$ref": "#/$defs/SimpleServerCommand"
              },
              {
                "not": {
                  "required": [
                    "give_role"
                  ]
                }
              }
            ]
          }
        },
        "renewal_command": {
          "type": "array",
          "description": "Actions executed after subscription renewal; Discord role actions are not supported.",
          "items": {
            "allOf": [
              {
                "$ref": "#/$defs/SimpleServerCommand"
              },
              {
                "not": {
                  "anyOf": [
                    {
                      "required": [
                        "give_role"
                      ]
                    },
                    {
                      "required": [
                        "del_role"
                      ]
                    }
                  ]
                }
              }
            ]
          }
        },
        "expire_command": {
          "type": "array",
          "description": "Actions executed when a subscription expires; Discord actions may send messages or remove roles.",
          "items": {
            "allOf": [
              {
                "$ref": "#/$defs/SimpleServerCommand"
              },
              {
                "not": {
                  "required": [
                    "give_role"
                  ]
                }
              }
            ]
          }
        }
      }
    },
    "Category": {
      "type": "object",
      "properties": {
        "id": {
          "type": "integer",
          "format": "int64",
          "description": "Unique identifier of the category."
        },
        "name": {
          "type": "string",
          "description": "Name of the category."
        },
        "description": {
          "type": "string",
          "description": "Description of the category."
        },
        "slug": {
          "type": "string",
          "description": "URL-friendly name of the category."
        },
        "hide": {
          "type": "boolean",
          "description": "Determines if the category is hidden."
        },
        "main_redirect": {
          "type": "boolean",
          "description": "Redirect to home page if category is accessed."
        },
        "parent_id": {
          "type": "integer",
          "format": "int64",
          "description": "Parent category ID if this is a sub-category."
        }
      },
      "required": [
        "id",
        "name",
        "slug",
        "hide",
        "main_redirect"
      ]
    },
    "CustomField": {
      "type": "object",
      "properties": {
        "id": {
          "type": "integer",
          "format": "int64",
          "description": "Unique identifier of the custom field."
        },
        "order": {
          "type": "integer",
          "format": "int64",
          "description": "Priority order of the custom field."
        },
        "name": {
          "type": "string",
          "description": "Name of the custom field."
        },
        "type": {
          "type": "string",
          "description": "Type of custom field. Accepted values: `text`, `checkbox`, `number`, `selection`\n"
        },
        "marker": {
          "type": "string",
          "description": "Placeholder marker used in commands."
        },
        "if_not_filled": {
          "type": "string",
          "description": "Behavior if field is left empty. Accepted values: `do_not_execute`, `remove_marker`, `use_default`"
        },
        "default_value": {
          "type": "string",
          "description": "Default value used if `if_not_filled` is set to `use_default`."
        },
        "required": {
          "type": "boolean",
          "description": "Indicates if the custom field is mandatory."
        },
        "minimum": {
          "type": "integer",
          "description": "Minimum value if field type is `number`."
        },
        "maximum": {
          "type": "integer",
          "description": "Maximum value if field type is `number`."
        },
        "step": {
          "type": "integer",
          "description": "Increment step if field type is `number`."
        },
        "number_type": {
          "type": "string",
          "description": "Specifies number input type. Accepted values: `number`, `range`"
        },
        "price": {
          "type": "integer",
          "description": "Additional price added to product if field is selected."
        },
        "options": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/CustomFieldOption"
          },
          "description": "Options available if field type is `selection`."
        }
      },
      "required": [
        "id",
        "order",
        "name",
        "type",
        "required"
      ]
    },
    "CustomFieldOption": {
      "type": "object",
      "properties": {
        "id": {
          "type": "integer",
          "description": "Unique identifier of the option."
        },
        "order": {
          "type": "integer",
          "description": "Priority order of the option."
        },
        "name": {
          "type": "string",
          "description": "Name of the option."
        },
        "value": {
          "type": "integer",
          "description": "Value corresponding to the option."
        },
        "price": {
          "type": "integer",
          "description": "Price adjustment if option is selected."
        }
      },
      "required": [
        "id",
        "order",
        "name",
        "value",
        "price"
      ]
    },
    "CustomRule": {
      "type": "object",
      "properties": {
        "id": {
          "type": "integer",
          "format": "int64",
          "description": "Unique identifier of the custom rule."
        },
        "order": {
          "type": "integer",
          "format": "int64",
          "description": "Priority order of the custom rule."
        },
        "name": {
          "type": "string",
          "description": "Name of the custom rule."
        },
        "type": {
          "type": "string",
          "description": "Type of custom rule. Accepted values: `number_limit`"
        },
        "min": {
          "type": "integer",
          "format": "int64",
          "description": "Minimum value if the rule type is `number_limit`."
        },
        "max": {
          "type": "integer",
          "format": "int64",
          "description": "Maximum value if the rule type is `number_limit`."
        },
        "fields": {
          "type": "array",
          "description": "IDs of custom fields affected by this rule.",
          "items": {
            "type": "number",
            "format": "int64"
          }
        }
      },
      "required": [
        "id",
        "order",
        "name",
        "type"
      ]
    },
    "PurchaseLimit": {
      "type": "object",
      "properties": {
        "purchase_times": {
          "type": "integer",
          "description": "Maximum number of times the product can be purchased."
        },
        "type": {
          "type": "string",
          "description": "Defines when the purchase limit applies.\n\nAccepted values:  \n- `every` → limit purchases to a recurring time period  \n- `only` → limit purchases permanently\n"
        },
        "cycle": {
          "type": "integer",
          "description": "Number of time units before the purchase limit resets.\n\nExample:  \n- Limit purchases to 1 time every 1 month  \n- Limit purchases to 1 time every 3 months\n\nAccepted ranges: 1–99 for days, 1–52 for weeks, 1–12 for months, 1–1 for years\n"
        },
        "periodicity": {
          "type": "string",
          "description": "Unit of time used to define the purchase limit.\n\nAccepted values: `day`, `week`, `month`, `year`\n"
        }
      },
      "required": [
        "purchase_times",
        "type",
        "cycle",
        "periodicity"
      ]
    },
    "ServerChoice": {
      "type": "object",
      "properties": {
        "id": {
          "type": "integer",
          "description": "Server ID"
        },
        "name": {
          "type": "string",
          "description": "Server Name"
        }
      },
      "required": [
        "id",
        "name"
      ]
    },
    "SimpleServerCommand": {
      "type": "object",
      "description": "A game-server command or one Discord action. Discord messages require `channel` and `message`; `private_message` sends a DM. Role actions are restricted to payment, refund, and expiry events.",
      "properties": {
        "str": {
          "type": "string",
          "description": "Content of the command to be executed"
        },
        "event": {
          "type": "string",
          "description": "Event triggering the execution of the command. Can take the following values: `Execute`, `Must be online`",
          "enum": [
            "Execute",
            "Must be online",
            "Disabled"
          ]
        },
        "channel": {
          "type": "string",
          "description": "Discord channel ID, or `private_message` to DM the purchaser.",
          "pattern": "^(?:[1-9][0-9]*|private_message)$"
        },
        "message": {
          "type": "string",
          "maxLength": 2000,
          "description": "Discord message text. Provide this together with `channel`."
        },
        "give_role": {
          "type": "string",
          "description": "Discord role ID to add after payment.",
          "pattern": "^[1-9][0-9]*$"
        },
        "del_role": {
          "type": "string",
          "description": "Discord role ID to remove after refund or expiry.",
          "pattern": "^[1-9][0-9]*$"
        }
      },
      "oneOf": [
        {
          "required": [
            "str"
          ]
        },
        {
          "required": [
            "channel",
            "message"
          ]
        },
        {
          "required": [
            "give_role"
          ]
        },
        {
          "required": [
            "del_role"
          ]
        }
      ]
    }
  }
}