使用示例令牌进行测试

对于直接集成,若想在您的服务器上测试令牌解密,您可以在构造 PaymentsClient 实例时通过设置 ENVIRONMENT_TEST 来生成示例令牌。

当您在环境设置为 ENVIRONMENT_TEST 的情况下构造 PaymentsClient 实例时,对 loadPaymentData 的调用会照常执行,并会要求用户选择一张真实的卡。不过,该调用其实并不会返回所选卡的实际信息,而且产生的令牌始终具有恒定载荷。

加密

ENVIRONMENT_TEST 中生成的令牌会使用您之前发送给 Google 的测试公钥进行加密。

这些令牌会使用 Google 的测试密钥进行签名。如果您使用的是 Tink,请确保设置了 .fetchSenderVerifyingKeysWith(GooglePaymentsPublicKeysManager.INSTANCE_TEST)(在构建 PaymentMethodTokenRecipient 对象时)。

测试载荷

令牌内的载荷取决于所选卡是否已令牌化(即是否已添加到 Google Pay)。此外,不同的令牌化卡会有不同的载荷,具体取决于卡网络。而无论卡网络为何,非令牌化卡的载荷始终相同。

对比以下示例,下列三个字段在您的测试载荷中可能会不同:

  • messageExpiration:时间戳,已设为自当前时间起的一周后。
  • messageId:针对每个载荷随机生成。
  • expirationYear:已设为自当前年份起的五年后。

使用的协议版本(ECv1 和 ECv2)不同,测试载荷的结构也所有不同。如果您要实施新的集成,请使用 ECv2 版本。如果您不确定使用哪个协议版本,请与您的 Google 联系人联系以进行确认。

非令牌化卡

以下示例展示了非令牌化卡的测试载荷:

ECv2

{
    "gatewayMerchantId": "some-merchant-id",
    "messageExpiration": "1561534717239",
    "messageId": "AH2EjteBXyoZR2TrJK_C2SKvwoG0dsw5WsQDkGOODXA_jwN0TF9j_I_NzWOLNwImcjBEfndMBiDgDJx9phz6H3D4jJQKy22-zcm38gaVcSPK3T_y7Qj1JEAZ-V0KgjpOXWBQTxC2M6vV",
    "paymentMethod": "CARD",
    "paymentMethodDetails": {
        "expirationYear": 2024,
        "expirationMonth": 12,
        "pan": "4111111111111111",
        "authMethod": "PAN_ONLY"
    }
}

ECv1

{
  "messageExpiration": "1507738377032",
  "paymentMethod": "CARD",
  "messageId": "AH2EjtcHYs1Ye-ZIZuZXd7eNO4QjQfZjBDtP2ti0tob_a5o22lHmGWHsBVYrrSylkFC3ZTsRdvMadQpwOGCIl7XxhTKcfElmgF7UFbcI8CeUZCWRmbTH5s7h69Baqr4FAM735VNThPiP",
  "paymentMethodDetails": {
    "expirationYear": 2022,
    "expirationMonth": 12,
    "pan": "4111111111111111"
  }
}

令牌化卡

“令牌化卡”是指添加到 Google Pay 的卡。

令牌化卡的测试载荷取决于所选卡的类型。以下三个示例显示了不同类型的令牌化卡的测试载荷:

Visa 卡

以下示例展示了令牌化 Visa 卡的测试载荷:

ECv2

{
    "gatewayMerchantId": "some-merchant-id",
    "messageExpiration": "1561533871082",
    "messageId": "AH2Ejtc8qBlP_MCAV0jJG7ErQKeDrkEUtQ0N3QRvPXWJc-jgC0VTfgmarDRZvTwuzirQPdUjkMkiQ7tnDidZbtlQTO-mAgMIdXRMuYedhZXnCcokmkJOOnE7jBn-pvkyBncOgpPWFFn3",
    "paymentMethod": "CARD",
    "paymentMethodDetails": {
        "expirationYear": 2024,
        "expirationMonth": 12,
        "pan": "4895370012003478",
        "authMethod": "CRYPTOGRAM_3DS",
        "eciIndicator": "07",
        "cryptogram": "AgAAAAAABk4DWZ4C28yUQAAAAAA="
    }
}

ECv1

{
  "messageExpiration": "1507738377032",
  "paymentMethod": "TOKENIZED_CARD",
  "messageId": "AH2EjtcHYs1Ye-ZIZuZXd7eNO4QjQfZjBDtP2ti0tob_a5o22lHmGWHsBVYrrSylkFC3ZTsRdvMadQpwOGCIl7XxhTKcfElmgF7UFbcI8CeUZCWRmbTH5s7h69Baqr4FAM735VNThPiP",
  "paymentMethodDetails": {
    "expirationYear": 2022,
    "dpan": "4895370012003478",
    "expirationMonth": 12,
    "authMethod": "3DS",
    "3dsCryptogram": "AgAAAAAABk4DWZ4C28yUQAAAAAA=",
    "eciIndicator": "07"
  }
}

American Express 卡

以下示例展示了 American Express 卡的测试载荷:

ECv2

{
    "gatewayMerchantId": "some-merchant-id",
    "messageExpiration": "1561534208255",
    "messageId": "AH2Ejtf3Lp6LzjK6BswXBvVKZapBJNgMUbVHF_TORaVi7lV0tvRfzvApsZm-RAXF_szQq9qS_BwLTgZGrXvk0ZydZwUISo4x6dxojDoz0fl7loXwZ8JApFrQWU__ExxljKY4Y4mu2aQz",
    "paymentMethod": "CARD",
    "paymentMethodDetails": {
        "expirationYear": 2024,
        "expirationMonth": 12,
        "pan": "370295136149943",
        "authMethod": "CRYPTOGRAM_3DS",
        "cryptogram": "JnPYbs6FkC1tiVLREAABoAAAkgA="
    }
}

ECv1

{
  "messageExpiration": "1507738377032",
  "paymentMethod": "TOKENIZED_CARD",
  "messageId": "AH2EjtcHYs1Ye-ZIZuZXd7eNO4QjQfZjBDtP2ti0tob_a5o22lHmGWHsBVYrrSylkFC3ZTsRdvMadQpwOGCIl7XxhTKcfElmgF7UFbcI8CeUZCWRmbTH5s7h69Baqr4FAM735VNThPiP",
  "paymentMethodDetails": {
    "expirationYear": 2022,
    "dpan": "370295136149943",
    "expirationMonth": 12,
    "authMethod": "3DS",
    "3dsCryptogram": "JnPYbs6FkC1tiVLREAABoAAAkgA="
  }
}

所有其他支付卡网络

以下示例展示了所有其他支付卡网络的令牌化卡的测试载荷:

ECv2

{
    "gatewayMerchantId": "some-merchant-id",
    "messageExpiration": "1561534208255",
    "messageId": "AH2EjterqtEqlB9vQvy2kJEugwCDYtMzVtLrVH26Qd1RDFK_EFsFmPdpPOqcCIedXNpAc6sCM61GuYM_bgVl930tU8I0Ar0WUx87MIw36skUC-IT_APvbx4qRqw9Hfu2W-7zY6LMdgZ5",
    "paymentMethod": "CARD",
    "paymentMethodDetails": {
        "expirationYear": 2024,
        "expirationMonth": 12,
        "pan": "5204240250197840",
        "authMethod": "CRYPTOGRAM_3DS",
        "cryptogram": "ALnt+yWSJdXBACMLLWMNGgADFA=="
    }
}

ECv1

{
  "messageExpiration": "1507738377032",
  "paymentMethod": "TOKENIZED_CARD",
  "messageId": "AH2EjtcHYs1Ye-ZIZuZXd7eNO4QjQfZjBDtP2ti0tob_a5o22lHmGWHsBVYrrSylkFC3ZTsRdvMadQpwOGCIl7XxhTKcfElmgF7UFbcI8CeUZCWRmbTH5s7h69Baqr4FAM735VNThPiP",
  "paymentMethodDetails": {
    "expirationYear": 2022,
    "dpan": "5204240250197840",
    "expirationMonth": 12,
    "authMethod": "3DS",
    "3dsCryptogram": "ALnt+yWSJdXBACMLLWMNGgADFA=="
  }
}