PayZuDocs

授权前对收款执行的风险分析。

携带 fraudAnalysis 对象的收款会在授权前实时经过 PayZu 反欺诈引擎筛查。您可以按收款控制是否执行分析,以及如何处理分析结果。

反欺诈分析可以:

  • 自动批准交易
  • 因涉嫌欺诈而拒绝交易
  • 根据预先定义的规则转入人工审核

在跨境收款中,fraudAnalysis必填。请参阅跨境收款

工作原理

当收款携带 fraudAnalysis 对象创建时,该操作会进入风险评估,评估基于多种标准,例如客户数据、购买行为和订单特征。

要使用反欺诈,只需在创建交易请求的 creditCardPayment 内包含 fraudAnalysis 对象。该对象携带设备标识(fingerPrintId)、浏览器数据(browser)和 MDD 字段(definedFields)。

{
  "creditCardPayment": {
    "fraudAnalysis": {
      "fingerPrintId": "xyz123fingerprint",
      "browser": {
        "cookiesAccepted": true,
        "email": "joao.silva@example.com",
        "hostName": "host.example.com",
        "ipAddress": "192.168.0.1",
        "type": "Chrome"
      },
      "definedFields": [
        {
          "id": 1,
          "value": "Guest"
        }
      ]
    }
  }
}

definedFields 中可传入的取值列表请参阅 MDD 字段表

响应中没有独立的反欺诈字段。分析结果通过 creditCardPayment.statusreasonCodereasonMessage 返回:

分析结果响应中的字段
通过收款进入授权流程,status1(Authorized)或 2(PaymentConfirmed)
因涉嫌欺诈被拒status13(Aborted),reasonCode16(AbortedByFraud)
未完成reasonCode17(CouldNotAntifraud)

完整取值见交易状态与原因

获取 fingerPrintId

fingerPrintId 是由客户端自行生成的随机会话 id,应在支付请求中使用。每个 fingerprint 都是唯一的,有效期为 48 小时。

加载脚本

要获取 fingerprint,您需要在 HTML 页面中加载以下脚本:

<script src="https://static.payzu.io/scripts/antifraud.min.js"></script>

生成 id 并激活 fingerprint

之后,您需要生成一个随机 id 作为您的 fingerprint,并使用我们的脚本激活它。

完整示例:

<head>
  <script src="https://static.payzu.io/scripts/antifraud.min.js"></script>
</head>
<script>
  // 将用作 fingerprint 的随机 id
  const uuid = self.crypto.randomUUID();

  // 生产环境
  payzuAntiFraud.init({
    identifier: uuid,
  });

  ...

  // sandbox 环境
  payzuAntiFraud.init({
    identifier: uuid,
    sandbox: true,
  });

  ...
</script>

init 函数的参数:

参数默认值是否必填
identifier*
sandboxfalse

激活后,即可在 fraudAnalysis 字段中使用您的 fingerprint 来创建支付请求。

在收款中发送 fraudAnalysis

要使用反欺诈创建收款,需要在 creditCardPayment 中提供 fraudAnalysis 字段。在 browser 中,cookiesAcceptedipAddress 字段为必填。

{
  "customer": {
    "name": "João Silva",
    "identity": "12345678900",
    "identityType": "CPF",
    "email": "joao.silva@example.com",
    "phone": "5511912345678",
    "address": {
      "street": "Rua das Flores",
      "number": "123",
      "zipCode": "01234567",
      "city": "São Paulo",
      "state": "SP",
      "country": "Brasil",
      "district": "Centro"
    }
  },
  "creditCardPayment": {
    "fraudAnalysis": {
      "fingerPrintId": "xyz123fingerprint",
      "browser": {
        "cookiesAccepted": true,
        "email": "joao.silva@example.com",
        "hostName": "host.example.com",
        "ipAddress": "192.168.0.1",
        "type": "Chrome"
      },
      "definedFields": [
        {
          "id": 1,
          "value": "Guest"
        }
      ]
    }
  }
}

schema 中 customer 只要求 name。请求中带 fraudAnalysis 时,反欺诈还要求 identityidentityTypeemailphoneaddress;address 中只有 complement 可选。birthdate 仍为可选。

后续步骤

本页内容