> ## 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.

# Register a MED inbound refund credit (THIRD RAIL — moves money)

> Posts the receiving-side refund CREDIT on the local Midaz ledger when SPI settles a MED devolucao (the plugin is the SGCT server; JDPI calls this after the pacs.004 is received, contract §2.28). It posts a balanced COMMITTED double-entry (clearing credit, recipient debit-mirror) and mints the idCreditoSgct. The Authorization (Bearer) header is mandatory on this financial ingress: a missing/invalid token is a coded 401. A re-delivered credit for the same endToEndIdDevolucao echoes the prior idCreditoSgct with no second post (idempotent).



## OpenAPI

````yaml /en/openapi/v3-current/pix.yaml post /v1/med/credits/inbound
openapi: 3.1.0
info:
  description: Brazilian PIX Direct (DICT + SPI) plugin API.
  title: plugin-br-pix-jd
  version: 1.0.0
servers: []
security:
  - BearerAuth: []
paths:
  /v1/med/credits/inbound:
    post:
      tags:
        - MED Inbound Credit
      summary: Register a MED inbound refund credit (THIRD RAIL — moves money)
      description: >-
        Posts the receiving-side refund CREDIT on the local Midaz ledger when
        SPI settles a MED devolucao (the plugin is the SGCT server; JDPI calls
        this after the pacs.004 is received, contract §2.28). It posts a
        balanced COMMITTED double-entry (clearing credit, recipient
        debit-mirror) and mints the idCreditoSgct. The Authorization (Bearer)
        header is mandatory on this financial ingress: a missing/invalid token
        is a coded 401. A re-delivered credit for the same endToEndIdDevolucao
        echoes the prior idCreditoSgct with no second post (idempotent).
      operationId: registerMedInboundRefundCredit
      parameters:
        - description: >-
            Bearer access token (the financial-ingress gate; the handler fails
            closed with PIX-0082 when absent).
          in: header
          name: Authorization
          schema:
            description: >-
              Bearer access token (the financial-ingress gate; the handler fails
              closed with PIX-0082 when absent).
            examples:
              - Bearer eyJ...
            type: string
        - description: >-
            Idempotency key (= the endToEndIdDevolucao). Mandatory per the MED
            SPI credit contract.
          in: header
          name: Chave-Idempotencia
          required: true
          schema:
            description: >-
              Idempotency key (= the endToEndIdDevolucao). Mandatory per the MED
              SPI credit contract.
            examples:
              - D1111111120240918150000000000099
            type: string
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/InboundCreditBody'
        required: true
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/InboundCreditView'
          description: OK
        '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
        default:
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Detail'
          description: Error
components:
  schemas:
    InboundCreditBody:
      additionalProperties: true
      properties:
        codigoDevolucao:
          description: >-
            Refund reason code (BE08/FR01/MD06/SL02; §9.3.3 Obrg=Sim,
            tolerated-absent).
          examples:
            - BE08
          type: string
        dtContabil:
          description: SPI accounting date (§9.3.3, Obrg=Sim, aaaa-mm-dd).
          examples:
            - '2024-09-20'
          type: string
        dtHrLiquidacao:
          description: SPI settlement instant (§9.3.3, Obrg=Sim, UTC).
          examples:
            - '2024-09-20T04:00:01.001Z'
          type: string
        dtHrOp:
          description: Recebedor-informed original instant (UTC).
          examples:
            - '2024-09-20T04:00:01.001Z'
          type: string
        endToEndIdDevolucao:
          description: >-
            EndToEndId of the devolucao (pacs.004; the natural key / idempotency
            anchor, 32-char).
          examples:
            - D1234567820240101000000000000099
          type: string
        endToEndIdOriginal:
          description: >-
            EndToEndId of the original contested payment (32-char; §9.3.3
            Obrg=Sim, tolerated-absent).
          examples:
            - E1234567820240101000000000000001
          type: string
        idReqJdPi:
          description: The JDPI request id of the credit notification.
          examples:
            - f1e2d3c4-b5a6-7890-1234-567890abcdef
          type: string
        infEntreClientes:
          description: Payer-to-payee free-text information (§9.3.3, Obrg=Nao).
          examples:
            - Compra Paga
          type: string
        motivoDevolucao:
          description: Free-text refund detail.
          examples:
            - Devolucao MED.
          type: string
        pagador:
          $ref: '#/components/schemas/InboundCreditPagador'
          description: Payer (pagador) identity; retained for audit/observability.
        recebedor:
          $ref: '#/components/schemas/InboundCreditRecebedor'
          description: >-
            Recipient (recebedor) identity; the credit distribute leg target
            (design D2 mirror). recebedor.ispb is enforced by Validate().
        valor:
          description: Credited refund amount, in reais (a JSON number; JDPI 9.3.3).
          examples:
            - 150.85
          format: double
          type: number
      required:
        - idReqJdPi
        - endToEndIdDevolucao
        - valor
      type: object
    InboundCreditView:
      additionalProperties: false
      properties:
        dtHrCreditoSgct:
          description: The SGCT credit-commit instant (UTC, RFC 3339).
          examples:
            - '2024-09-20T04:00:01.001Z'
          type: string
        idCreditoSgct:
          description: The plugin-minted credit-entry id (GUID).
          examples:
            - 58F752C5-6376-3252-8305-A2DE3A8525D3
          type: string
        idReqJdPi:
          description: The JDPI request id (echoed).
          examples:
            - f1e2d3c4-b5a6-7890-1234-567890abcdef
          type: string
      required:
        - idReqJdPi
        - idCreditoSgct
        - dtHrCreditoSgct
      type: object
    Detail:
      additionalProperties: false
      properties:
        code:
          description: >-
            Stable, machine-readable domain error code scoped to the emitting
            service (format: <SERVICE>-NNNN).
          examples:
            - ERR-0001
          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
    InboundCreditPagador:
      additionalProperties: true
      properties:
        cpfCnpj:
          description: Payer CPF or CNPJ (a v5.5.0 string).
          examples:
            - '11111111111'
          type: string
        ispb:
          description: Payer participant ISPB (8 digits, a v5.5.0 string).
          examples:
            - '04358798'
          type: string
        nome:
          description: Payer name/legal name (§9.3.3 pagador.nome; audit-only).
          examples:
            - Fulano de Tal
          type: string
        nrAgencia:
          description: Payer branch (4 digits, a string).
          examples:
            - '0001'
          type: string
        nrConta:
          description: Payer account number (a string).
          examples:
            - '12345678'
          type: string
        tpConta:
          description: >-
            Payer account type (§9.3.3, 0 CC, 1 Salário, 2 Poupança, 3
            Pagamento, 4 PI; audit-only).
          examples:
            - 0
          format: int64
          type: integer
        tpPessoa:
          description: Payer person type (§9.3.3, 0 PF, 1 PJ; audit-only).
          examples:
            - 0
          format: int64
          type: integer
      required:
        - ispb
      type: object
    InboundCreditRecebedor:
      additionalProperties: true
      properties:
        cpfCnpj:
          description: Recipient CPF or CNPJ (a v5.5.0 string).
          examples:
            - '22222222222'
          type: string
        ispb:
          description: Recipient participant ISPB (8 digits, a v5.5.0 string).
          examples:
            - '17826860'
          type: string
        nrAgencia:
          description: Recipient branch (4 digits, a string).
          examples:
            - '0001'
          type: string
        nrConta:
          description: Recipient account number (a string).
          examples:
            - '87654321'
          type: string
        tpConta:
          description: >-
            Recipient account type (§9.3.3, 0 CC, 1 Salário, 2 Poupança, 3
            Pagamento, 4 PI). THIRD RAIL: disambiguates same-holder accounts.
          examples:
            - 0
          format: int64
          type: integer
        tpPessoa:
          description: Recipient person type (§9.3.3, 0 PF, 1 PJ).
          examples:
            - 1
          format: int64
          type: integer
      required:
        - ispb
      type: object
    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

````