{
  "schemaVersion": 1,
  "snapshotDate": "2026-10-23",
  "slug": "reference-xero-payment-create",
  "title": "Xero Apply Invoice Payment",
  "section": "Library asset reference",
  "description": "Apply one accounting payment to an approved invoice with PUT /Payments. The bank/payment-enabled account must belong to the selected tenant. This records an accounting payment; it does not transfer money through a bank. Amount is in invoice",
  "kind": "node",
  "url": "/wiki/reference-xero-payment-create/",
  "markdown": "/wiki/reference-xero-payment-create/index.md",
  "json": "/wiki/reference-xero-payment-create/index.json",
  "headings": [
    {
      "id": "audited-socket-contract-21-october-2026",
      "title": "Audited socket contract (21 October 2026)",
      "depth": 2
    },
    {
      "id": "catalog-identity",
      "title": "Catalog identity",
      "depth": 2
    },
    {
      "id": "inputs",
      "title": "Inputs",
      "depth": 2
    },
    {
      "id": "outputs",
      "title": "Outputs",
      "depth": 2
    },
    {
      "id": "configuration-schema",
      "title": "Configuration schema",
      "depth": 2
    },
    {
      "id": "source-and-installed-versions",
      "title": "Source and installed versions",
      "depth": 2
    }
  ],
  "sources": [
    "../OpenNodeFlow-Library/work/catalog-all.mjs",
    "../OpenNodeFlow-Library/work/azure-pack-consolidation-20261022/catalog-policy.mjs",
    "../OpenNodeFlow-Library/work/developer-packs-20261022/catalog.mjs",
    "shared/seed.ts",
    "shared/storage-library.ts",
    "shared/variable-library.ts",
    "shared/control-flow.ts",
    "shared/remote-routes.ts",
    "server/runtime-library.ts",
    "shared/error-library.ts",
    "shared/storage-model.ts",
    "shared/builtin-documentation.ts"
  ],
  "family": "xero",
  "contract": {
    "key": "xero.payment.create",
    "slug": "xero-payment-create",
    "name": "Xero Apply Invoice Payment",
    "kind": "node",
    "family": "xero",
    "packId": null,
    "category": "Xero",
    "description": "Apply one accounting payment to an approved invoice with PUT /Payments. The bank/payment-enabled account must belong to the selected tenant. This records an accounting payment; it does not transfer money through a bank. Amount is in invoice currency and cannot exceed the provider outstanding balance. Scope accounting.payments. Reconciliation and explicit human approval belong before this action.",
    "inputs": [
      {
        "id": "exec",
        "name": "exec",
        "type": "control",
        "typeName": "Control",
        "required": false
      },
      {
        "id": "tenantId",
        "name": "tenantId",
        "type": "string",
        "typeName": "Text",
        "required": true
      },
      {
        "id": "idempotencyKey",
        "name": "idempotencyKey",
        "type": "string",
        "typeName": "Text",
        "required": true
      },
      {
        "id": "firstAttemptAt",
        "name": "firstAttemptAt",
        "type": "string",
        "typeName": "Text",
        "required": true
      },
      {
        "id": "payment",
        "name": "payment",
        "type": "@xero.paymentWrite",
        "typeName": "Xero Invoice Payment Write",
        "typeKey": "xero.paymentWrite",
        "typeVersion": 1,
        "required": true
      }
    ],
    "outputs": [
      {
        "id": "payment",
        "name": "payment",
        "type": "@xero.payment",
        "typeName": "Xero Payment",
        "typeKey": "xero.payment",
        "typeVersion": 1,
        "required": true
      },
      {
        "id": "receipt",
        "name": "receipt",
        "type": "@xero.writeReceipt",
        "typeName": "Xero Write Receipt",
        "typeKey": "xero.writeReceipt",
        "typeVersion": 1,
        "required": true
      },
      {
        "id": "metadata",
        "name": "metadata",
        "type": "@xero.metadata",
        "typeName": "Xero Response Metadata",
        "typeKey": "xero.metadata",
        "typeVersion": 1,
        "required": true
      },
      {
        "id": "next",
        "name": "next",
        "type": "control",
        "typeName": "Control",
        "required": false
      },
      {
        "id": "error",
        "name": "error",
        "type": "control",
        "typeName": "Control",
        "required": false
      }
    ],
    "configSchema": {
      "type": "object",
      "properties": {
        "authMode": {
          "type": "string",
          "enum": [
            "accessToken",
            "managedRefresh"
          ],
          "default": "accessToken",
          "description": "accessToken reads a current bearer secret; managedRefresh keeps rotating tokens encrypted in workspace storage."
        },
        "accessTokenSecret": {
          "type": "string",
          "default": "XERO_ACCESS_TOKEN"
        },
        "bootstrapTokenSecret": {
          "type": "string",
          "default": "XERO_OAUTH_BOOTSTRAP",
          "description": "JSON secret containing access_token, refresh_token and expires_at (ISO time). Used only when the storage key does not exist."
        },
        "clientIdSecret": {
          "type": "string",
          "default": "XERO_CLIENT_ID"
        },
        "clientSecretSecret": {
          "type": "string",
          "default": "XERO_CLIENT_SECRET"
        },
        "pkce": {
          "type": "boolean",
          "default": false
        },
        "tokenNamespace": {
          "type": "string",
          "default": "integration.xero.oauth",
          "minLength": 1
        },
        "tokenKey": {
          "type": "string",
          "default": "default",
          "minLength": 1
        },
        "mockBaseUrl": {
          "type": "string",
          "default": "",
          "description": "Tests only: HTTP loopback origin. Production endpoints cannot be overridden."
        },
        "requestTimeoutMs": {
          "type": "integer",
          "minimum": 100,
          "maximum": 30000,
          "default": 10000
        },
        "readRetries": {
          "type": "integer",
          "minimum": 0,
          "maximum": 2,
          "default": 1
        },
        "maxRetryDelayMs": {
          "type": "integer",
          "minimum": 0,
          "maximum": 10000,
          "default": 2000
        },
        "allowWrites": {
          "type": "boolean",
          "default": false,
          "description": "Explicitly permit this accounting write. Keep ONF automatic retries disabled."
        }
      },
      "required": [],
      "additionalProperties": false
    },
    "documentation": "Apply one accounting payment to an approved invoice with PUT /Payments. The bank/payment-enabled account must belong to the selected tenant. This records an accounting payment; it does not transfer money through a bank. Amount is in invoice currency and cannot exceed the provider outstanding balance. Scope accounting.payments. Reconciliation and explicit human approval belong before this action.\n\nInputs: tenantId, idempotencyKey, firstAttemptAt, payment. Outputs: payment, receipt, metadata. exec/next/error are control sockets. Throwing selects an explicitly wired error control route through ONF; data outputs are absent on that path.\n\nAuthentication: configure secret **names**, never literal credentials. Access-token mode reads XERO_ACCESS_TOKEN. Managed-refresh mode bootstraps once from XERO_OAUTH_BOOTSTRAP JSON containing access_token, refresh_token, expires_at; XERO_CLIENT_ID / XERO_CLIENT_SECRET hold client values. PKCE omits the secret. Rotated pairs are immediately CAS-persisted in encrypted workspace storage; a 60-second CAS lock serializes refresh. Never use the same refresh grant in different workspaces/namespaces/keys or another app. Do not inspect/export token records into logs. Crash between provider refresh and persistence needs recovery within Xero's documented refresh grace period. No tokens are returned.\n\nRequests use fixed HTTPS Xero hosts, no redirect following, bounded 2 MB response and per-request timeout. Only explicit HTTP loopback mock origins are accepted as overrides. Read HTTP 429/5xx retries are bounded to readRetries (0..2) and Retry-After/maxRetryDelayMs; a longer wait fails with metadata in the safe error message. Network failures and accounting writes are never internally retried. Configure ONF instance retries deliberately; keep write retries disabled. Errors omit raw provider bodies to avoid credential/PII disclosure.\n\nValidation: isolated local mock services only; live tenant consent and account access have not been verified. [Xero accounting requests](https://developer.xero.com/documentation/api/accounting/requests-and-responses/), [OAuth tokens](https://developer.xero.com/documentation/guides/oauth2/token-types/), [tenant connections](https://developer.xero.com/documentation/guides/oauth2/tenants/), [idempotency](https://developer.xero.com/documentation/guides/idempotent-requests/idempotency/), [rate limits](https://developer.xero.com/documentation/best-practices/api-call-efficiencies/rate-limits/).\n\nWRITE: allowWrites=true is required. Supply a stable domain idempotencyKey (1..128 chars) and the ORIGINAL firstAttemptAt. The node rejects firstAttemptAt older than five minutes; Xero retains keys for six minutes. Internal HTTP retries are zero. Reconcile uncertain completion through read operations before deliberate replay. Never generate a new key merely to bypass uncertainty. Xero applies business validation and tenant permissions.\n\n## Audited socket contract (21 October 2026)\n\nInputs:\n- `tenantId`: `string`; required.\n- `idempotencyKey`: `string`; required.\n- `firstAttemptAt`: `string`; required.\n- `payment`: `@xero.paymentWrite`; required.\n\nOutputs:\n- `payment`: `@xero.payment`; required.\n- `receipt`: `@xero.writeReceipt`; required.\n- `metadata`: `@xero.metadata`; required.\n\nConfiguration:\n- `authMode`: string; default \"accessToken\". accessToken reads a current bearer secret; managedRefresh keeps rotating tokens encrypted in workspace storage.\n- `accessTokenSecret`: string; default \"XERO_ACCESS_TOKEN\"\n- `bootstrapTokenSecret`: string; default \"XERO_OAUTH_BOOTSTRAP\". JSON secret containing access_token, refresh_token and expires_at (ISO time). Used only when the storage key does not exist.\n- `clientIdSecret`: string; default \"XERO_CLIENT_ID\"\n- `clientSecretSecret`: string; default \"XERO_CLIENT_SECRET\"\n- `pkce`: boolean; default false\n- `tokenNamespace`: string; default \"integration.xero.oauth\"\n- `tokenKey`: string; default \"default\"\n- `mockBaseUrl`: string; default \"\". Tests only: HTTP loopback origin. Production endpoints cannot be overridden.\n- `requestTimeoutMs`: integer; default 10000\n- `readRetries`: integer; default 1\n- `maxRetryDelayMs`: integer; default 2000\n- `allowWrites`: boolean; default false. Explicitly permit this accounting write. Keep ONF automatic retries disabled.\n\nKnown provider records and list elements have structural schemas. Explicit dynamic payloads, selected query results and provider extensions retain the recursive JSON Value vocabulary; they do not imply a known provider entity. Null is distinct from omission. Runtime validates the exact selected immutable type version; reading newer documentation never repins existing graphs. This audit used synthetic fixtures/local mocks and does not establish live provider authorization or delivery.",
    "runtime": "javascript",
    "tags": [
      "integration",
      "library-expansion",
      "xero"
    ],
    "source": "baseline-catalog"
  }
}
