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

# 将支付方式重新分配给其他客户

> 将已注册的支付方式重新分配给同一账户下的其他客户

将已注册的支付方式重新分配给同一账户下的其他客户。请在请求体中发送目标客户的 `customer_id`。只有卡支付方式可以重新分配。响应返回的支付方式结构与[注册支付方式](https://docs.y.uno/zh-hans/reference/payment-methods-direct-workflow/enroll-payment-method-api.md)响应相同，新的所有者显示在 `customer_id` 字段中。

> [!NOTE]
>
> 要重新分配支付方式，您需要提供 `payment_method_id`，即使用[注册支付方式](https://docs.y.uno/zh-hans/reference/payment-methods-direct-workflow/enroll-payment-method-api.md) endpoint 时收到的 `vaulted_token`。

如果支付方式已分配给一个有数据的客户，则无法重新分配，请求会被拒绝并返回 `409 CONFLICT`。

> [!WARNING]
>
> 支付方式重新分配后，商户负责在所有已使用该支付方式的地方更新客户标识符。这包括使用该支付方式创建的所有订阅、商户自身维护的用户与 `vaulted_token` 之间的映射，以及所有已存储的客户与支付方式组合。Yuno 会将支付方式重新分配给新客户，但不会更新商户端的这些引用。


## OpenAPI

````yaml openapi/zh-hans/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: 将支付方式重新分配给另一位客户
      description: >-
        将已注册的支付方式重新分配给同一账户下的另一位客户。仅支持重新分配卡支付方式。如果支付方式已分配给有数据的客户，重新分配会失败。返回的支付方式与注册支付方式响应的结构相同，新的所有者位于
        `customer_id` 字段中。
      operationId: reassign-payment-method-api
      parameters:
        - name: payment_method_id
          in: path
          description: >-
            `payment_method`
            的唯一标识符。该值是使用[注册支付方式](/zh-hans/reference/payment-methods-direct-workflow/enroll-payment-method-api)注册支付方式时收到的
            `vaulted_token`（UUID）。
          schema:
            type: string
          required: true
        - name: X-account-code
          in: header
          description: 您账户的唯一标识符（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: 已重新分配的支付方式，新的所有者位于 `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: 请求无效、目标客户不存在，或该支付方式不是卡。
          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: 该账户下不存在此支付方式。
          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: 该支付方式已分配给有数据的客户。
          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: >-
            支付方式被重新分配到的客户的唯一标识符（UUID）。仅当支付方式当前所属客户没有数据时才能重新分配，否则请求会返回 `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: 支付服务提供商返回的持卡人姓名全称。
              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: 卡发卡国家/地区的 ISO 3166-1 alpha-2 国家/地区代码。
              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: 支付方式现在所属客户的唯一标识符。重新分配响应会返回该值，方便您确认新的所有者。
          example: b3f2c1a0-1234-4a5b-9c8d-000000000001
        verify: {}
    BadRequestError:
      type: object
      properties:
        code:
          type: string
          description: 机器可读的错误代码。
          enum:
            - INVALID_PARAMETERS
            - BAD_REQUEST
            - CUSTOMER_NOT_FOUND
            - PAYMENT_METHOD_NOT_REASSIGNABLE
        messages:
          type: array
          description: 错误的可读描述。
          items:
            type: string
    PaymentMethodNotFoundError:
      type: object
      properties:
        code:
          type: string
          description: 机器可读的错误代码。
          enum:
            - PAYMENT_METHOD_NOT_FOUND
        messages:
          type: array
          description: 错误的可读描述。
          items:
            type: string
    PaymentMethodConflictError:
      type: object
      properties:
        code:
          type: string
          description: 机器可读的错误代码。
          enum:
            - CONFLICT
        messages:
          type: array
          description: 错误的可读描述。
          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.