> ## Documentation Index
> Fetch the complete documentation index at: https://docs.lerian.studio/llms.txt
> Use this file to discover all available pages before exploring further.

# Disconnect a provider from a tenant

> Disconnects one provider from the tenant of the credentials you authenticate with: records the disconnected state of the (tenant, provider) pair, deactivates the tenant's credential of that provider when there is one, and then revokes the tenant's inbound webhook connections for it in the control plane. A provider with no credential in the tenant is disconnected the same way.

GUARD. Under the exclusive locks of the tenant's route for the four operations, of the (tenant, provider) pair and of the provider's live credential, the disconnect is refused with 409 PBP-0703, and nothing changes, while some operation of the route points to the provider (`routedOperations`), or the provider has boletos PENDING or CREATED, batches with a submission not finalized, payments in a live status, or inbound notices accepted and not yet processed (`openOperations`). Every refusal is recorded with the actor, the reason and the counts.

EFFECT. From the commit, new payments and boletos of the provider are refused with 503 PBP-0704 and its new inbound notices with 401 PBP-0500. If the revocation fails after the state was recorded, the answer is 503 PBP-0008: the provider stays disconnected, and calling again completes the revocation; until then a reconnect is refused with 409 PBP-0703 REVOCATION_PENDING. The provider stays disconnected until reconnectProvider: the credential sync does not recreate its credential.

IDEMPOTENT under Idempotency-Key. A pair already disconnected answers `outcome: ALREADY_DISCONNECTED` with the `disconnectedAt` of the disconnect in force and re-applies its revocation. A retry with the key of an earlier disconnect answers from that disconnect and only completes its own revocation.

WHO MAY CALL IT: `admin:create`. A provider not installed here, of which the tenant has neither a credential nor a disconnect record, is answered 404 PBP-0005.



## OpenAPI

````yaml /pt/openapi/v3-current/payments.yaml post /v1/admin/providers/{provider_type}/disconnect
openapi: 3.1.0
info:
  description: >-
    API for the Lerian Payments interface via BTG. It covers boleto issuance,
    cancellation, and queries; bill payments (bankslip, utilities, and DARF) and
    queries; aggregated boleto and payment dashboards; provider connection and
    outbound webhook configuration; and the provider webhook receiver for
    settlement events.


    ERROR BODIES. A failed request arrives as an RFC 9457 problem document on
    application/problem+json. Branch on the code member. A license refusal
    carries an LCS code, listed in the License Manager error list.


    NOTICES. The webhooks section describes each notice Payments posts to the
    tenant's callback URL. Delivery does not guarantee order: order a boleto's
    notices by the occurredAt member of the body. Notices of one boleto recorded
    together never tie and follow the order of the facts; notices recorded at
    different moments can tie, and in a tie the boleto query tells the current
    state. The same notice can arrive more than once: after verifying its
    signature and its X-Webhook-Timestamp, discard repetitions by the eventId
    member of the body, equal to the X-Webhook-Id header and the same on every
    attempt.
  title: Payments — via BTG API
  version: 1.0.0
servers:
  - url: https://api.example.com
    description: >-
      Replace the example host with the URL provided during environment
      onboarding.
security: []
tags:
  - description: >-
      Tenant-level setup: connecting the banking provider and configuring where
      status notifications are delivered.
    name: Admin
  - description: Issuing, querying and cancelling boletos, and retrieving the rendered PDF.
    name: Boletos
  - description: >-
      Aggregated counts, amounts and breakdowns over a period, for boletos and
      for payments.
    name: Dashboards
  - description: >-
      The notices Payments posts to the tenant's callback URL, one per type
      enabled in enabledEvents, each signed with the configuration's secret.
      Each item describes the body, the delivery headers, when the notice is
      sent and which providers send it.
    name: Notices
  - description: >-
      Paying bankslips, utility bills and DARF tax slips, and querying those
      payments.
    name: Payments
  - description: >-
      The webhook the payment provider posts settlement events to. Authenticated
      with a credential agreed with the provider, not with the platform identity
      used by the rest of this API.
    name: Settlement
paths:
  /v1/admin/providers/{provider_type}/disconnect:
    post:
      tags:
        - Admin
      summary: Disconnect a provider from a tenant
      description: >-
        Disconnects one provider from the tenant of the credentials you
        authenticate with: records the disconnected state of the (tenant,
        provider) pair, deactivates the tenant's credential of that provider
        when there is one, and then revokes the tenant's inbound webhook
        connections for it in the control plane. A provider with no credential
        in the tenant is disconnected the same way.


        GUARD. Under the exclusive locks of the tenant's route for the four
        operations, of the (tenant, provider) pair and of the provider's live
        credential, the disconnect is refused with 409 PBP-0703, and nothing
        changes, while some operation of the route points to the provider
        (`routedOperations`), or the provider has boletos PENDING or CREATED,
        batches with a submission not finalized, payments in a live status, or
        inbound notices accepted and not yet processed (`openOperations`). Every
        refusal is recorded with the actor, the reason and the counts.


        EFFECT. From the commit, new payments and boletos of the provider are
        refused with 503 PBP-0704 and its new inbound notices with 401 PBP-0500.
        If the revocation fails after the state was recorded, the answer is 503
        PBP-0008: the provider stays disconnected, and calling again completes
        the revocation; until then a reconnect is refused with 409 PBP-0703
        REVOCATION_PENDING. The provider stays disconnected until
        reconnectProvider: the credential sync does not recreate its credential.


        IDEMPOTENT under Idempotency-Key. A pair already disconnected answers
        `outcome: ALREADY_DISCONNECTED` with the `disconnectedAt` of the
        disconnect in force and re-applies its revocation. A retry with the key
        of an earlier disconnect answers from that disconnect and only completes
        its own revocation.


        WHO MAY CALL IT: `admin:create`. A provider not installed here, of which
        the tenant has neither a credential nor a disconnect record, is answered
        404 PBP-0005.
      operationId: disconnectProvider
      parameters:
        - description: >-
            Tenant organization ID. Optional. The organization context is
            determined by the credentials you authenticate with; this header
            does not select or change it.
          in: header
          name: X-Organization-Id
          schema:
            description: >-
              Tenant organization ID. Optional. The organization context is
              determined by the credentials you authenticate with; this header
              does not select or change it.
            format: uuid
            type: string
        - description: >-
            Provider to disconnect, as the capabilities read names it. Matched
            case-insensitively.
          in: path
          name: provider_type
          required: true
          schema:
            description: >-
              Provider to disconnect, as the capabilities read names it. Matched
              case-insensitively.
            examples:
              - TESTPROV_A
            maxLength: 20
            minLength: 1
            pattern: ^[A-Za-z][A-Za-z0-9_]{0,19}$
            type: string
        - description: >-
            Client-supplied idempotency key, a UUID. Required: a request without
            it, with a value that is not a UUID, or with the nil UUID is refused
            with 400 PBP-0012.
          in: header
          name: Idempotency-Key
          required: true
          schema:
            description: >-
              Client-supplied idempotency key, a UUID. Required: a request
              without it, with a value that is not a UUID, or with the nil UUID
              is refused with 400 PBP-0012.
            type: string
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ProviderDisconnectionRequest'
              description: Why the provider is disconnected.
        required: true
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/DisconnectProviderResponse'
          description: OK
        '400':
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Detail'
          description: Bad Request
        '401':
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Detail'
          description: >-
            Authentication failed: the request carries no valid credential, or
            the credential does not identify a tenant. The error body is an RFC
            9457 problem document (`application/problem+json`) with error code
            `PBP-0003`. Obtain a valid bearer token and send the request again.
        '403':
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Detail'
          description: >-
            The authenticated principal is not allowed to perform this request.
            The error body is an RFC 9457 problem document
            (`application/problem+json`) with error code `PBP-0004`: the
            principal lacks permission for this operation, and the permission
            has to be granted before the request can succeed.
        '404':
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Detail'
          description: >-
            Not Found. PBP-0005: the provider is not installed and the tenant
            has neither a credential nor a disconnect record of it.
        '409':
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/ProviderDisconnectBlockedProblem'
          description: >-
            Conflict. PBP-0703: the provider is on the route, has open
            operations or has pending notices; `routedOperations` and
            `openOperations` say which and how many. While an earlier request
            under the same `Idempotency-Key` is still being processed, a request
            under that key is answered PBP-0007 and is not run. Send it again
            under the SAME key after a short wait: the key answers this code for
            at most five minutes after the earlier request arrived. Afterwards
            the same key answers with the earlier request's stored answer, with
            500 PBP-0002 when that answer cannot be replayed, or, when no answer
            was kept, by running the request. Do not send it under a new key to
            get past this answer: the earlier request may still take effect.
        '413':
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Detail'
          description: Request Entity Too Large
        '415':
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Detail'
          description: Unsupported Media Type
        '422':
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Detail'
          description: Unprocessable Entity
        '500':
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Detail'
          description: Internal Server Error
        '503':
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Detail'
          description: >-
            Service Unavailable. PBP-0008 means a dependency the request needs,
            authentication or the tenant's storage, is temporarily unavailable.
            The request was not processed; wait and send the same request again
            with the same Idempotency-Key.
      security:
        - BearerAuth: []
components:
  schemas:
    ProviderDisconnectionRequest:
      additionalProperties: false
      properties:
        reason:
          description: >-
            Why the provider is disconnected or reconnected. Recorded in the
            disconnect history, also when the call is refused. Must not carry
            personal data or secrets.
          examples:
            - Contrato com o provider encerrado em 30/11.
          maxLength: 500
          minLength: 1
          pattern: \S
          type: string
      required:
        - reason
      type: object
    DisconnectProviderResponse:
      additionalProperties: false
      properties:
        disconnectedAt:
          description: 'When the provider was disconnected, in UTC: the disconnect in force.'
          examples:
            - '2026-11-30T18:00:00Z'
          format: date-time
          type: string
        outcome:
          description: >-
            DISCONNECTED, this call put the pair in the disconnected state;
            ALREADY_DISCONNECTED, the pair was already disconnected (the
            revocation is still re-applied).
          enum:
            - DISCONNECTED
            - ALREADY_DISCONNECTED
          type: string
        providerType:
          description: Provider disconnected.
          examples:
            - TESTPROV_A
          type: string
        revokedConnections:
          description: >-
            Webhook connections of the provider that could still serve a
            delivery and no longer can. Zero is a success.
          examples:
            - 1
          format: int64
          minimum: 0
          type: integer
      required:
        - providerType
        - outcome
        - revokedConnections
        - disconnectedAt
      type: object
    Detail:
      additionalProperties: true
      properties:
        code:
          description: >-
            Stable, machine-readable domain error code scoped to the emitting
            service (format: <SERVICE>-NNNN).
          type: string
        detail:
          description: >-
            A human-readable explanation specific to this occurrence of the
            problem.
          examples:
            - Property foo is required but is missing.
          type: string
        errors:
          description: Optional list of individual error details
          items:
            $ref: '#/components/schemas/ErrorDetail'
          type:
            - array
            - 'null'
        instance:
          description: >-
            A URI reference that identifies the specific occurrence of the
            problem.
          examples:
            - https://example.com/error-log/abc123
          format: uri
          type: string
        status:
          description: HTTP status code
          examples:
            - 400
          format: int64
          type: integer
        title:
          description: >-
            A short, human-readable summary of the problem type. This value
            should not change between occurrences of the error.
          examples:
            - Bad Request
          type: string
        type:
          default: about:blank
          description: A URI reference to human-readable documentation for the error.
          examples:
            - https://example.com/errors/example
          format: uri
          type: string
        upstream:
          $ref: '#/components/schemas/Upstream'
          description: >-
            RFC 9457 extension member: the error a proxied third-party provider
            reported. Absent unless the emitting service explicitly surfaced
            one.
      type: object
    ProviderDisconnectBlockedProblem:
      allOf:
        - $ref: '#/components/schemas/Detail'
        - properties:
            openOperations:
              properties:
                boletoBatches:
                  description: Batches with a submission not finalized.
                  format: int64
                  minimum: 0
                  type: integer
                boletos:
                  description: Boletos PENDING or CREATED.
                  format: int64
                  minimum: 0
                  type: integer
                payments:
                  description: Payments in a live status.
                  format: int64
                  minimum: 0
                  type: integer
                pendingNotices:
                  description: Inbound notices accepted and not yet processed.
                  format: int64
                  minimum: 0
                  type: integer
              required:
                - boletos
                - boletoBatches
                - payments
                - pendingNotices
              type: object
            reason:
              description: >-
                Present only on the reconnect refusal: the revocation of the
                last disconnect has not completed.
              enum:
                - REVOCATION_PENDING
              type: string
            routedOperations:
              description: >-
                Operations of the route that point to the provider. Empty when
                only open operations block.
              items:
                enum:
                  - BOLETO_ISSUANCE
                  - BANKSLIP_PAYMENT
                  - BARCODE_BILL_PAYMENT
                  - DARF_PAYMENT
                type: string
              type: array
              uniqueItems: true
          type: object
      description: >-
        Problem document of the disconnect and reconnect 409. On the disconnect,
        `openOperations` and `routedOperations` are present only when code is
        PBP-0703. On the reconnect, PBP-0703 carries `reason` instead.
    ErrorDetail:
      additionalProperties: false
      properties:
        location:
          description: >-
            Where the error occurred, e.g. 'body.items[3].tags' or
            'path.thing-id'
          type: string
        message:
          description: Error message text
          type: string
        value:
          description: The value at the given location
      type: object
    Upstream:
      additionalProperties: false
      properties:
        code:
          description: The upstream provider's own error code, verbatim.
          examples:
            - E4001
          type: string
        message:
          description: >-
            The upstream provider's own error message, verbatim (bounded, never
            its raw response body).
          examples:
            - account not found at provider
          type: string
      type: object
  securitySchemes:
    BearerAuth:
      bearerFormat: JWT
      description: JWT bearer token issued by the identity provider.
      scheme: bearer
      type: http

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.