{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://docs.pybara.com/pybara-js/checkout.schema.json",
  "title": "Pybara.checkout() config",
  "description": "Config object for Pybara.checkout() in @pybara/pybara-js — bind once per site. The checkout refuses to open until the site is verified in Pybara Wallet (_pybara-payto DNS record) and the widget terms are accepted. The open() payment params are under #/$defs/payment.",
  "type": "object",
  "additionalProperties": false,
  "required": ["recipientPrincipal", "siteUrl", "siteName"],
  "properties": {
    "recipientPrincipal": {
      "type": "string",
      "minLength": 1,
      "not": { "enum": ["2vxsx-fae", "aaaaa-aa"] },
      "description": "Recipient's wallet principal — the same one the site's _pybara-payto DNS record lists. The registry does not serve it; the integrator passes it. Never the anonymous principal (2vxsx-fae) or the management canister (aaaaa-aa): both are refused."
    },
    "siteUrl": {
      "type": "string",
      "minLength": 1,
      "description": "The site's URL as registered in Pybara Wallet, e.g. 'https://example.com'. Normalized by the SDK: a bare domain reads as https, query/fragment/default ports/trailing slashes drop, a path is kept."
    },
    "siteName": {
      "type": "string",
      "minLength": 1,
      "description": "Site display name — shown in the checkout frame and stored as the subscription name on recurring payments."
    },
    "currency": {
      "type": "string",
      "pattern": "^[A-Z]{3}$",
      "description": "The currency open() charges in when its own currency is absent (ISO 4217, uppercase, e.g. 'EUR'): set it once on a single-currency site. No default — open() refuses when neither is set."
    },
    "platform": {
      "type": "string",
      "pattern": "^[a-z0-9-]{1,64}$",
      "default": "pybara-js",
      "description": "The integration surface reported in the payment log's platform field: a lowercase slug — first-party consumers set their own (e.g. 'pybara-donate'). A label, never used for a decision."
    },
    "siteCountry": {
      "type": "string",
      "pattern": "^[A-Za-z]{2}$",
      "description": "Site base country (ISO 3166-1 alpha-2)."
    },
    "thankYouMessage": {
      "type": "string",
      "description": "Replaces the success screen's default title."
    },
    "locale": {
      "type": "string",
      "description": "The checkout's language, a BCP 47 tag ('fr', 'de-DE', 'zh-CN'), usually the site's: shown when Pybara has it, otherwise the payer's own language."
    },
    "onAvailability": {
      "description": "function (Availability) => void — whether a payment would go through right now, before any click: called once the checkout is ready, then after each precheck({ amount, currency }). Act on availability.status: 'available' (show Pybara), 'unavailable' (hide it: nothing on the page can fix it), 'below-minimum' (disable the button and show availability.message, e.g. 'Minimum €0.70'), 'retry-later' (keep it). availability.detail, in English, says what is missing and who fixes it, and is also printed to the console. Never branch on availability.reason. Not expressible in JSON."
    },
    "thankYouRedirectUrl": {
      "type": "string",
      "format": "uri",
      "description": "Redirect target once the payer leaves the success screen (PDF receipt, member area)."
    },
    "recipientTosVersion": {
      "type": "string",
      "description": "The terms version the recipient (site operator) accepted, e.g. '1-0' — forwarded so settle stores it with the payment log."
    },
    "recipientTosAcceptedAt": {
      "type": "string",
      "format": "date-time",
      "description": "Recipient terms acceptance timestamp (ISO 8601 UTC) — same forwarding role as recipientTosVersion."
    },
    "pluginVersion": {
      "type": "string",
      "description": "The integration version forwarding the payment — set by Pybara plugins only. When set, the widget terms gate is skipped: plugins check their own terms server-side."
    },
    "staging": {
      "type": "boolean",
      "default": false,
      "description": "Staging environment — staging canisters and staging.pybara.io. Never on a live site."
    },
    "debug": {
      "type": "boolean",
      "default": false,
      "description": "Console diagnostics."
    }
  },
  "$defs": {
    "payment": {
      "title": "checkout.open() params",
      "description": "One payment attempt — the params of a single open() call.",
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "amount": {
          "oneOf": [
            { "type": "string", "pattern": "^(0|[1-9][0-9]*)(\\.[0-9]+)?$" },
            { "type": "number", "exclusiveMinimum": 0 }
          ],
          "examples": ["12.34", "1000", "5"],
          "description": "The amount in the currency's major units, as a decimal string ('12.34' for €12.34, '1000' for ¥1,000); a number is accepted and turned into its decimal text. The checkout reads it with the currency's ISO 4217 minor units and refuses more decimals than the currency holds ('12.345' EUR, '1000.5' JPY), so the page never needs to know them. No minimum is checked here: the checkout shows its own, in the payer's currency. Omit it for a 'Donate' button with no amount: the checkout then asks the donor how much."
        },
        "suggestedAmounts": {
          "type": "array",
          "maxItems": 4,
          "items": {
            "oneOf": [
              { "type": "string", "pattern": "^(0|[1-9][0-9]*)(\\.[0-9]+)?$" },
              { "type": "number", "exclusiveMinimum": 0 }
            ]
          },
          "examples": [["5", "10", "25"]],
          "description": "Without amount: up to four amounts the checkout offers the donor as buttons beside an amount field, in the currency's major units. Without them, the donor types the amount. Ask the site owner which amounts to suggest, if any, rather than inventing them."
        },
        "currency": {
          "type": "string",
          "pattern": "^[A-Z]{3}$",
          "description": "The currency charged (ISO 4217, uppercase) — the checkout config's when absent; one of the two is required. A multi-currency site passes it on every call."
        },
        "uiPath": {
          "type": "string",
          "pattern": "^[a-z0-9-]{1,64}$",
          "description": "Which of your surfaces opened the checkout: 'form' for your own button or form calling open() (the default), 'button' when a rendered Pybara button did (set for you), or your own slug — logged as the payment's ui_path."
        },
        "frequency": {
          "enum": ["weekly", "monthly", "yearly", "every2min"],
          "description": "Recurring pull interval — omit for a one-time payment. 'every2min' exists for testing."
        },
        "durationMonths": {
          "enum": [3, 6, 12, 24],
          "description": "Recurring length in months, checked by the checkout — omit with frequency for an unlimited subscription."
        },
        "donorIsAnonymous": {
          "type": "boolean",
          "description": "Hide the payer's identity on the public record."
        },
        "donorMessage": {
          "type": "string",
          "description": "Message from the payer to the recipient — seeds the field the payer can edit on the confirm screen."
        },
        "wantsTaxReceipt": {
          "type": "boolean",
          "description": "Prefills the 'I'd like a tax receipt' checkbox — shown only when the recipient is registered and issues receipts."
        },
        "donorFirstName": { "type": "string" },
        "donorLastName": { "type": "string" },
        "donorEmail": { "type": "string", "description": "Prefills the receipt-address field — a payer who leaves an email gets a payment record." },
        "donorCompany": { "type": "string" },
        "donorCountry": { "type": "string" },
        "donorAddressLine1": { "type": "string" },
        "donorAddressLine2": { "type": "string" },
        "donorAddressCity": { "type": "string" },
        "donorAddressState": { "type": "string" },
        "donorAddressPostalCode": { "type": "string" },
        "donorAddressCountry": { "type": "string" },
        "onSuccess": { "description": "function (CheckoutResult) => void — called once the payment is confirmed on-chain; not expressible in JSON." },
        "onError": { "description": "function (Error) => void — called on frame-level errors; not expressible in JSON." },
        "onClose": { "description": "function () => void — called when the payer closes the checkout; not expressible in JSON." }
      }
    },
    "buttons": {
      "title": "checkout.buttons(options)",
      "description": "A 'Pybara' button, served by Pybara, that opens this checkout on the payer's click. Draw it with .render(element or selector), as often as wanted; .destroy() removes them. Its look follows availability by itself; call checkout.precheck({ amount, currency }) when the form changes.",
      "type": "object",
      "additionalProperties": false,
      "required": ["createPayment"],
      "properties": {
        "style": {
          "type": "object",
          "description": "Passed to the button as given. Copy a PayPal button's style and the two match.",
          "properties": {
            "color": { "type": "string", "description": "'brand' | 'black' | 'white' (PayPal's names; its 'gold', 'blue', 'silver' read as 'brand'). Default 'brand'." },
            "shape": { "type": "string", "description": "'pill' | 'rect' | 'sharp'. Default 'pill'." },
            "height": { "type": "number", "minimum": 25, "maximum": 55, "description": "CSS pixels, PayPal's range. Default 45." },
            "borderRadius": { "type": "number", "minimum": 0, "description": "CSS pixels, overriding shape's corners, as PayPal's style.borderRadius. Above half the height it draws a pill." }
          }
        },
        "hideWhenUnavailable": { "type": "boolean", "description": "Collapse the button to no height when Pybara is unavailable here; by default its slot stays, empty." },
        "createPayment": { "description": "function () => payment | Promise<payment> — called on the click: the payment from the form's current values, as open() takes it (amount, currency, frequency, donor fields), without callbacks; not expressible in JSON." },
        "onStateChange": { "description": "function (Availability) => void — the checkout's availability answer, once per answer; e.g. show availability.message below the minimum. Not expressible in JSON." },
        "onSuccess": { "description": "function (CheckoutResult) => void — the payment is confirmed on-chain; not expressible in JSON." },
        "onError": { "description": "function (Error) => void — a refusal from createPayment(), open() or the checkout; not expressible in JSON." },
        "onClose": { "description": "function () => void — the payer closed the checkout; not expressible in JSON." }
      }
    }
  }
}
