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

# 卡片 Fingerprint

> 使用卡片 fingerprint 检测重复的卡片注册并去重，无需存储卡数据。

卡片 fingerprint 是卡片 PAN 的加密哈希值，可唯一标识一张特定的支付卡。Yuno 在[支付方式对象](https://docs.y.uno/reference/payment-methods-direct-workflow/the-payment-method-object-api.md)中以 `fingerprint` 返回该值。当同一客户多次注册同一张卡时，Yuno 会创建多个独立的注册，各自具有不同的 `vaulted_token` 值，而 fingerprint 可帮助您检测重复项。

**关键特性：**

* 在同一张卡的多次注册中**保持一致**
* 对每个不同的卡号**是唯一的**
* 不暴露完整卡号，从而**保障 PCI 合规**
* 无需存储或访问敏感卡数据即可**实现去重**

> [!WARNING]
>
> 在客户输入卡片信息之前，您无法检查 fingerprint。这是 PCI 合规要求。

\*\*变通方法：\*\*在注册表单之前显示已保存的卡片，让客户看到自己已经保存了哪些卡片。

## 工作原理

### 同一张卡，多次注册

```json theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
// First enrollment
{
  "vaulted_token": "b82b7682-def1-4d46-ad51-7da446b2966c",
  "card_data": {
    "fingerprint": "fp_abc123xyz789",
    "iin": "41111111",
    "lfd": "1111"
  }
}

// Second enrollment of the SAME card
{
  "vaulted_token": "7ce53292-c402-4e3d-8ddd-a49268633294",  // Different token
  "card_data": {
    "fingerprint": "fp_abc123xyz789",  // Same fingerprint!
    "iin": "41111111",
    "lfd": "1111"
  }
}
```

### 不同的卡片

```json theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
{
  "vaulted_token": "...",
  "card_data": {
    "fingerprint": "fp_different456",  // Different fingerprint
    "iin": "52222222",
    "lfd": "2222"
  }
}
```

## 为什么会出现重复注册

为避免运营问题，Yuno 不会自动阻止重复的卡片注册。当客户多次注册同一张卡时：

* 每次注册都会创建一个**新的 `vaulted_token`**
* **不会自动去重**
* 无论到期日期或持卡人信息是否发生变化，**均适用**此规则

请在您这一侧使用 fingerprint 实现去重。

## 实施指南

### 第 1 步：检索现有支付方式

使用[检索已注册的支付方式](https://docs.y.uno/reference/payment-methods-direct-workflow/retrieve-enrolled-payment-methods-api.md) endpoint 列出客户现有的卡片。

```bash theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
GET /v1/customers/{customer_id}/payment-methods
```

**响应：**

```json theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
{
  "payment_methods": [
    {
      "vaulted_token": "token_1",
      "card_data": {
        "fingerprint": "fp_abc123",
        "iin": "41111111",
        "lfd": "1111",
        "brand": "VISA"
      }
    },
    {
      "vaulted_token": "token_2",
      "card_data": {
        "fingerprint": "fp_xyz789",
        "iin": "52222222",
        "lfd": "2222",
        "brand": "MASTERCARD"
      }
    }
  ]
}
```

### 第 2 步：注册后检查重复项

```javascript theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
async function checkForDuplicates(customerId, newCardFingerprint) {
  // Get existing payment methods
  const existingMethods = await getCustomerPaymentMethods(customerId);
  
  // Extract fingerprints (filter out nulls)
  const existingFingerprints = existingMethods
    .map(method => method.card_data?.fingerprint)
    .filter(Boolean);
  
  // Check for duplicates
  const isDuplicate = existingFingerprints.includes(newCardFingerprint);
  
  if (isDuplicate) {
    // Handle duplicate (see options below)
    console.log('Duplicate card detected');
  }
  
  return isDuplicate;
}
```

### 第 3 步：处理重复项

检测到重复项时，您有几种选择：

\*\*推荐：\*\*对于大多数集成，推荐选项 A（阻止注册）。仅当您的产品有意允许同一张卡保存多个副本时，才使用 B 或 C。

#### 选项 A：阻止注册（推荐，用户体验最佳）

```javascript theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
// Before enrollment, fetch existing cards and display them
// Show user: "You already have these cards saved:"
// - VISA ending in 1111
// - MASTERCARD ending in 2222
//
// This prevents the duplicate enrollment from happening
```

#### 选项 B：注册后通知

```javascript theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
enrollmentStatus: async ({ status, vaultedToken }) => {
  if (status === 'ENROLLED' && vaultedToken) {
    const newCard = await getPaymentMethodDetails(customerId, vaultedToken);
    const isDuplicate = await checkForDuplicates(
      customerId, 
      newCard.card_data?.fingerprint
    );
    
    if (isDuplicate) {
      // Notify user
      showNotification("This card was already saved. We've removed the duplicate.");
      
      // Optionally remove the duplicate
      await unenrollPaymentMethod(customerId, vaultedToken);
    } else {
      showNotification("Card saved successfully!");
    }
  }
}
```

#### 选项 C：保留两次注册

```javascript theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
// Allow duplicates for customer flexibility
// Display all cards with visual indicators:
// - VISA •••• 1111 (Primary)
// - VISA •••• 1111 (Duplicate - added Jan 15)
```

## 完整实施示例

```javascript theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
// Enrollment flow with duplicate detection
const enrollmentFlow = {
  
  // 1. Customer completes enrollment via SDK
  enrollmentStatus: async ({ status, vaultedToken }) => {
    if (status !== 'ENROLLED' || !vaultedToken) {
      return;
    }
    
    try {
      // 2. Fetch the newly enrolled payment method
      const newCard = await fetch(
        `/api/payment-methods/${vaultedToken}`
      ).then(r => r.json());
      
      const newFingerprint = newCard.card_data?.fingerprint;
      
      // 3. Handle cases where fingerprint is not available
      if (!newFingerprint) {
        console.warn('Fingerprint not available for this card');
        showNotification("Card saved successfully!");
        return;
      }
      
      // 4. Get existing cards for this customer
      const existingCards = await fetch(
        `/api/customers/${customerId}/payment-methods`
      ).then(r => r.json());
      
      // 5. Check for duplicates
      const duplicates = existingCards.payment_methods.filter(card => 
        card.card_data?.fingerprint === newFingerprint &&
        card.vaulted_token !== vaultedToken  // Exclude the newly enrolled card
      );
      
      // 6. Handle duplicate
      if (duplicates.length > 0) {
        const confirmRemove = await showConfirmDialog(
          "This card is already saved to your account. " +
          "Would you like to remove the duplicate?"
        );
        
        if (confirmRemove) {
          await fetch(
            `/api/payment-methods/${vaultedToken}`,
            { method: 'DELETE' }
          );
          showNotification("Duplicate card removed.");
        } else {
          showNotification("Card saved. You now have multiple copies of this card.");
        }
      } else {
        showNotification("Card saved successfully!");
      }
      
    } catch (error) {
      console.error('Error checking for duplicates:', error);
      // Fail gracefully - card is still enrolled
      showNotification("Card saved successfully!");
    }
  }
};
```

## 重要注意事项

### Fingerprint 可用性

对于某些支付方式或服务提供商，`fingerprint` 字段可能为 `null`。使用前请始终检查 fingerprint 是否存在：

```javascript theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
const fingerprint = card.card_data?.fingerprint;

if (!fingerprint) {
  // Handle this case gracefully
  // Option 1: Skip duplicate detection
  // Option 2: Use alternative matching (IIN + LFD)
  // Option 3: Log and notify your team
  console.warn('Fingerprint not available');
}
```

**替代匹配方式：**

```javascript theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
// Fallback: Match by IIN + LFD + expiration
const isSameCard = (card1, card2) => {
  return card1.card_data?.iin === card2.card_data?.iin &&
         card1.card_data?.lfd === card2.card_data?.lfd &&
         card1.card_data?.expiration_month === card2.card_data?.expiration_month &&
         card1.card_data?.expiration_year === card2.card_data?.expiration_year;
};
```

> [!WARNING]
>
> 不同的卡片可能具有相同的 IIN 和 LFD。

### 卡片更新

卡片更新时 fingerprint 的行为：

| 变更 | Fingerprint 行为 |
| - | - |
| **卡号变更** | ✅ 生成**新的** fingerprint |
| **到期日期变更** | ❌ fingerprint **保持不变** |
| **持卡人姓名变更** | ❌ fingerprint **保持不变** |
| **卡片重新发行（卡号相同）** | ❌ fingerprint **保持不变** |

### 网络令牌 fingerprint

对于网络令牌，Yuno 使用 `network_token_fingerprint`，其工作方式与卡片 fingerprint 类似，作用范围限定于您的组织以及 PCI vault 中网络令牌的唯一标识符。这意味着同一 PAN 的重复注册可以映射到同一个网络令牌。更多详情，请参阅 [Network Tokens](https://docs.y.uno/zh-hans/docs/security-and-compliance/network-tokens.md)。

## 使用场景

### 避免钱包杂乱

帮助用户避免多次保存同一张卡：

```javascript theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
// Show before enrollment form
"You already have these cards saved:
 - VISA ending in 1111
 - MASTERCARD ending in 2222"
```

### 改善用户体验

自动清理重复项：

```javascript theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
if (isDuplicate) {
  await removeOlderDuplicate(vaultedToken);
  showMessage("We updated your saved card.");
}
```

### 数据清理

批量识别并删除重复注册：

```javascript theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
async function cleanupDuplicates(customerId) {
  const cards = await getPaymentMethods(customerId);
  const fingerprints = new Map();
  
  for (const card of cards.payment_methods) {
    const fp = card.card_data?.fingerprint;
    if (!fp) continue;
    
    if (fingerprints.has(fp)) {
      // Keep the most recent, remove older duplicates
      const existing = fingerprints.get(fp);
      const newerCard = new Date(card.created_at) > new Date(existing.created_at) 
        ? card 
        : existing;
      const olderCard = newerCard === card ? existing : card;
      
      await unenrollPaymentMethod(customerId, olderCard.vaulted_token);
      fingerprints.set(fp, newerCard);
    } else {
      fingerprints.set(fp, card);
    }
  }
}
```

### 分析与监控

跟踪重复注册率：

```javascript theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
// Log duplicate events for monitoring
if (isDuplicate) {
  analytics.track('duplicate_card_enrolled', {
    customer_id: customerId,
    fingerprint: fingerprint.substring(0, 10), // Partial for privacy
    duplicate_count: duplicates.length + 1
  });
}
```


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