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

> Posts the receiving-side refund CREDIT on the local Midaz ledger when SPI settles a MED devolucao. 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 /sgct/jdpi/spi/api/v2/credito/devolucao
openapi: 3.0.3
info:
  title: Plugin BR Pix Direct - Complete API
  description: |
    Complete API for Brazilian Pix instant payment system including
    Pix key dictionary operations, QR code generation/decoding, transactions and
    transaction limits.
  version: 1.0.0
servers:
  - url: https://plugin-pix-direct.api.lerian.net
  - url: https://plugin-pix-direct-qrcode.api.lerian.net
security:
  - bearerAuth: []
paths:
  /sgct/jdpi/spi/api/v2/credito/devolucao:
    post:
      tags:
        - MED API
      summary: Register a MED inbound refund credit
      description: >-
        Posts the receiving-side refund CREDIT on the local Midaz ledger when
        SPI settles a MED devolucao. 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).
      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).
            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.
            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
        default:
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Detail'
          description: Error
components:
  schemas:
    InboundCreditBody:
      additionalProperties: false
      properties:
        codigoDevolucao:
          description: Refund reason code (BE08/FR01/MD06/SL02).
          type: string
        dtContabil:
          description: SPI accounting date.
          type: string
        dtHrLiquidacao:
          description: SPI settlement instant.
          type: string
        dtHrOp:
          description: Recebedor-informed original instant (UTC).
          type: string
        endToEndIdDevolucao:
          description: >-
            EndToEndId of the devolucao (pacs.004; the natural key / idempotency
            anchor, 32-char).
          type: string
        endToEndIdOriginal:
          description: EndToEndId of the original contested payment (32-char).
          type: string
        idReqJdPi:
          description: The upstream request id of the credit notification.
          type: string
        motivoDevolucao:
          description: Free-text refund detail.
          type: string
        pagador:
          $ref: '#/components/schemas/InboundCreditPagador'
        recebedor:
          $ref: '#/components/schemas/InboundCreditRecebedor'
        valor:
          description: Credited refund amount, in reais.
          format: double
          type: number
      required:
        - idReqJdPi
        - endToEndIdDevolucao
        - valor
        - pagador
        - recebedor
      type: object
    InboundCreditView:
      additionalProperties: false
      properties:
        dtHrCreditoSgct:
          description: The settlement-gateway credit-commit instant (UTC, RFC 3339).
          type: string
        idCreditoSgct:
          description: The service-minted credit-entry id (GUID).
          type: string
        idReqJdPi:
          description: The upstream request id (echoed).
          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).
          type: string
        detail:
          description: >-
            A human-readable explanation specific to this occurrence of the
            problem.
          type: string
        errors:
          description: Optional list of individual error details
          items:
            $ref: '#/components/schemas/ErrorDetail'
          type: array
          nullable: true
        instance:
          description: >-
            A URI reference that identifies the specific occurrence of the
            problem.
          format: uri
          type: string
        status:
          description: HTTP status code
          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.
          type: string
        type:
          default: about:blank
          description: A URI reference to human-readable documentation for the error.
          format: uri
          type: string
      type: object
    InboundCreditPagador:
      additionalProperties: false
      properties:
        cpfCnpj:
          description: Payer CPF or CNPJ (a v5.5.0 string).
          type: string
        ispb:
          description: Payer participant ISPB (8 digits, a v5.5.0 string).
          type: string
        nome:
          description: Payer name/legal name.
          type: string
        nrAgencia:
          description: Payer branch (4 digits, a string).
          type: string
        nrConta:
          description: Payer account number (a string).
          type: string
      required:
        - ispb
      type: object
    InboundCreditRecebedor:
      additionalProperties: false
      properties:
        cpfCnpj:
          description: Recipient CPF or CNPJ (a v5.5.0 string).
          type: string
        ispb:
          description: Recipient participant ISPB (8 digits, a v5.5.0 string).
          type: string
        nrAgencia:
          description: Recipient branch (4 digits, a string).
          type: string
        nrConta:
          description: Recipient account number (a string).
          type: string
        tpConta:
          description: Recipient account type.
          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
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: >
        JWT Bearer token authentication. Obtain token from
        `/v1/login/oauth/access_token` endpoint

        using client credentials (clientId and clientSecret).


        Include token in Authorization header:

        `Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...`


        Token expires after 3600 seconds (1 hour).

````