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

> ## Agent Instructions
> Test in the sandbox first: base URL https://api-sandbox.y.uno (Test Mode in the Dashboard). Production is https://api.y.uno (Live Mode).
> Every API request needs the public-api-key and private-secret-key headers. Get them in the Dashboard at https://dashboard.y.uno/developers (Developers > Credentials); sandbox and production keys are different.
> Send an X-Idempotency-Key (a UUID) when creating payments, refunds and cancels, so retries do not create duplicates.
> Start with the Quickstart (https://docs.y.uno/docs/quickstart.md) and the agent guide (https://docs.y.uno/agents.md). To search these docs from a coding agent, connect the docs MCP server at https://docs.y.uno/mcp.

# Reatribuir um meio de pagamento a outro cliente

> Reatribui um meio de pagamento cadastrado a um cliente diferente da mesma conta

Reatribua um meio de pagamento cadastrado a um cliente diferente da mesma conta. Envie o `customer_id` do cliente de destino no corpo da requisição. Somente meios de pagamento de cartão podem ser reatribuídos. A resposta retorna o meio de pagamento no mesmo formato da resposta de [Cadastrar meio de pagamento](https://docs.y.uno/pt-br/reference/payment-methods-direct-workflow/enroll-payment-method-api.md), com o novo proprietário no campo `customer_id`.

> [!NOTE]
>
> Para reatribuir o meio de pagamento, você precisa informar o `payment_method_id`, que é o `vaulted_token` recebido ao usar o endpoint [Cadastrar meio de pagamento](https://docs.y.uno/pt-br/reference/payment-methods-direct-workflow/enroll-payment-method-api.md).

Um meio de pagamento que já está atribuído a um cliente que tem dados não pode ser reatribuído, e a requisição é rejeitada com `409 CONFLICT`.

> [!WARNING]
>
> Depois que um meio de pagamento é reatribuído, o lojista é responsável por atualizar o identificador do cliente em todos os lugares onde o meio de pagamento já foi usado. Isso inclui qualquer assinatura criada com ele, o mapeamento próprio do lojista entre um usuário e o `vaulted_token` e qualquer par armazenado de cliente e meio de pagamento. A Yuno reatribui o meio de pagamento ao novo cliente, mas não atualiza essas referências do lado do lojista.


## OpenAPI

````yaml openapi/pt-br/payment-methods-direct-workflow/reassign-payment-method-api.json PATCH /payment-methods/{payment_method_id}
openapi: 3.1.0
info:
  title: customer-api
  version: 1.0.0
servers:
  - url: https://api-sandbox.y.uno/v1
    description: Sandbox
  - url: https://api.y.uno/v1
    description: Production (US)
security:
  - sec0: []
    sec1: []
paths:
  /payment-methods/{payment_method_id}:
    patch:
      summary: Reatribuir um meio de pagamento a outro cliente
      description: >-
        Reatribui um meio de pagamento cadastrado a um cliente diferente da
        mesma conta. Apenas meios de pagamento de cartão podem ser reatribuídos.
        A reatribuição falha quando o meio de pagamento já está atribuído a um
        cliente que tem dados. Retorna o meio de pagamento no mesmo formato da
        resposta de Enroll Payment Method, com o novo titular no campo
        `customer_id`.
      operationId: reassign-payment-method-api
      parameters:
        - name: payment_method_id
          in: path
          description: >-
            O identificador único do `payment_method`. É o `vaulted_token`
            recebido ao cadastrar um meio de pagamento com [Enroll Payment
            Method](/pt-br/reference/payment-methods-direct-workflow/enroll-payment-method-api)
            (UUID).
          schema:
            type: string
          required: true
        - name: X-account-code
          in: header
          description: O identificador único da sua conta (UUID).
          schema:
            type: string
            x-default: <Your X-account-code>
          required: true
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ReassignPaymentMethodInput'
            example:
              customer_id: b3f2c1a0-1234-4a5b-9c8d-000000000001
      responses:
        '200':
          description: >-
            O meio de pagamento reatribuído, incluindo o novo titular no campo
            `customer_id`.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PaymentMethod'
              example:
                idempotency_key: a0000000-0000-4000-8000-000000000010
                name: VISA ****1111
                description: VISA ****1111
                type: CARD
                category: CARD
                country: US
                parent_type: null
                status: ENROLLED
                sub_status: ENROLLED
                vaulted_token: b0000000-0000-4000-8000-000000000002
                callback_url: null
                action: null
                redirect_url: null
                created_at: '2024-06-04T12:47:46.992602Z'
                updated_at: '2024-06-04T12:47:46.992603Z'
                card_data:
                  iin: '41111111'
                  lfd: '1111'
                  holder_name: JOHN DOE
                  expiration_month: 3
                  expiration_year: 26
                  number_length: 16
                  security_code_length: 3
                  brand: VISA
                  issuer: JPMORGAN CHASE BANK N A
                  issuer_code: null
                  country_code: US
                  category: CREDIT
                  type: CREDIT
                  fingerprint: 55a7fe38-cdc3-45dc-8c5f-820751799c76
                last_successfully_used: null
                last_successfully_used_at: null
                preferred: null
                customer_id: b3f2c1a0-1234-4a5b-9c8d-000000000001
                verify: null
        '400':
          description: >-
            A requisição é inválida, o cliente de destino não existe ou o meio
            de pagamento não é um cartão.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BadRequestError'
              examples:
                Missing customer_id:
                  value:
                    code: INVALID_PARAMETERS
                    messages:
                      - The field 'customer_id' is required.
                Invalid customer_id:
                  value:
                    code: INVALID_PARAMETERS
                    messages:
                      - The field 'customer_id' must be a valid uuid v4.
                Malformed request body:
                  value:
                    code: BAD_REQUEST
                    messages:
                      - Bad request
                Target customer does not exist:
                  value:
                    code: CUSTOMER_NOT_FOUND
                    messages:
                      - Customer not found.
                Payment method is not a card:
                  value:
                    code: PAYMENT_METHOD_NOT_REASSIGNABLE
                    messages:
                      - Only card payment methods can be reassigned.
        '404':
          description: O meio de pagamento não existe para esta conta.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PaymentMethodNotFoundError'
              examples:
                Payment method not found:
                  value:
                    code: PAYMENT_METHOD_NOT_FOUND
                    messages:
                      - Payment method not found.
        '409':
          description: O meio de pagamento já está atribuído a um cliente que tem dados.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PaymentMethodConflictError'
              examples:
                Already assigned to a customer with data:
                  value:
                    code: CONFLICT
                    messages:
                      - >-
                        payment_method is already assigned to a customer with
                        data
      deprecated: false
components:
  schemas:
    ReassignPaymentMethodInput:
      type: object
      required:
        - customer_id
      properties:
        customer_id:
          type: string
          description: >-
            O identificador único do cliente ao qual o meio de pagamento é
            reatribuído (UUID). O meio de pagamento só pode ser reatribuído
            enquanto o cliente atual não tiver dados; caso contrário, a
            requisição retorna `409 CONFLICT`.
    PaymentMethod:
      type: object
      properties:
        idempotency_key:
          type: string
          example: a0000000-0000-4000-8000-000000000010
        name:
          type: string
          example: VISA ****1111
        description:
          type: string
          example: VISA ****1111
        type:
          type: string
          example: CARD
        category:
          type: string
          example: CARD
        country:
          type: string
          example: US
        parent_type: {}
        status:
          type: string
          example: ENROLLED
        sub_status:
          type: string
          example: ENROLLED
        vaulted_token:
          type: string
          example: b0000000-0000-4000-8000-000000000002
        callback_url: {}
        action: {}
        redirect_url: {}
        created_at:
          type: string
          example: '2024-06-04T12:47:46.992602Z'
        updated_at:
          type: string
          example: '2024-06-04T12:47:46.992603Z'
        card_data:
          type: object
          properties:
            iin:
              type: string
              example: '41111111'
            lfd:
              type: string
              example: '1111'
            holder_name:
              type: string
              description: >-
                Nome completo do titular do cartão conforme retornado pelo
                provedor de pagamento.
              example: JOHN DOE
            expiration_month:
              type: integer
              example: 3
              default: 0
            expiration_year:
              type: integer
              example: 26
              default: 0
            number_length:
              type: integer
              example: 16
              default: 0
            security_code_length:
              type: integer
              example: 3
              default: 0
            brand:
              type: string
              example: VISA
            issuer:
              type: string
              example: JPMORGAN CHASE BANK N A
            issuer_code: {}
            country_code:
              type: string
              description: Código de país ISO 3166-1 alpha-2 do país emissor do cartão.
              example: US
            category:
              type: string
              example: CREDIT
            type:
              type: string
              example: CREDIT
            fingerprint:
              type: string
              example: 55a7fe38-cdc3-45dc-8c5f-820751799c76
        last_successfully_used: {}
        last_successfully_used_at: {}
        preferred: {}
        customer_id:
          type: string
          description: >-
            O identificador único do cliente ao qual o meio de pagamento
            pertence agora. Retornado pela resposta da reatribuição para que
            você possa confirmar o novo titular.
          example: b3f2c1a0-1234-4a5b-9c8d-000000000001
        verify: {}
    BadRequestError:
      type: object
      properties:
        code:
          type: string
          description: Código de erro legível por máquina.
          enum:
            - INVALID_PARAMETERS
            - BAD_REQUEST
            - CUSTOMER_NOT_FOUND
            - PAYMENT_METHOD_NOT_REASSIGNABLE
        messages:
          type: array
          description: Descrição do erro legível por pessoas.
          items:
            type: string
    PaymentMethodNotFoundError:
      type: object
      properties:
        code:
          type: string
          description: Código de erro legível por máquina.
          enum:
            - PAYMENT_METHOD_NOT_FOUND
        messages:
          type: array
          description: Descrição do erro legível por pessoas.
          items:
            type: string
    PaymentMethodConflictError:
      type: object
      properties:
        code:
          type: string
          description: Código de erro legível por máquina.
          enum:
            - CONFLICT
        messages:
          type: array
          description: Descrição do erro legível por pessoas.
          items:
            type: string
  securitySchemes:
    sec0:
      type: apiKey
      in: header
      name: public-api-key
      x-default: <Your public-api-key>
    sec1:
      type: apiKey
      in: header
      name: private-secret-key
      x-default: <Your private-secret-key>

````

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