本页介绍了如何使用示例令牌来测试集成。
生成示例令牌
若要在您的服务器上测试令牌解密以进行直接集成,您可以在构建 PaymentsClient
实例时将环境设置为 TEST
,以生成示例令牌。
当您在环境设为 TEST
的情况下构建 PaymentsClient
实例时,对 loadPaymentData
的调用会照常执行,并会要求用户选择一张真实的卡。不过,这样其实并不会返回所选卡的实际信息,而且产生的令牌始终具有恒定载荷。
验证签名
在 TEST
环境中生成的令牌会使用您先前发送给 Google 的测试公钥进行加密。
这些令牌使用 Google 的测试密钥进行签名。如果您使用 Tink,请确保在构建 PaymentMethodTokenRecipient
对象时设置了 .fetchSenderVerifyingKeysWith(GooglePaymentsPublicKeysManager.INSTANCE_TEST)
。
解密载荷
解密示例令牌后,您将收到明文载荷。载荷结构取决于所选卡是否已被令牌化(即是否已添加到 Google Pay)。此外,令牌化卡的载荷是不同的,具体取决于支付卡网络。无论支付卡网络为何,非令牌化卡的载荷都始终相同。
与此页面中的示例相比,解密载荷中的以下三个字段可能会有所不同:
messageExpiration
:此字段是一个设为一周后(从当前时间算起)的时间戳。messageId
:这是为每个载荷随机生成的。expirationYear
:设为自当前年份起的五年后。
使用的协议版本(ECv1 和 ECv2)不同,解密载荷的结构也有所不同。如果您要实现新的集成,请使用 ECv2 版本。如果您不确定该使用哪个协议版本,请与您的 Google 联系人联系确认。
非令牌化卡
Visa 卡
下例展示了非令牌化 Visa 卡经过解密的载荷:
ECv2
{ "gatewayMerchantId": "some-merchant-id", "messageExpiration": "1650574736277", "messageId": "AH2Ejtc88ZHJ-2aYBQWzHwvp6l0JsCHgxVt8s91A-ZUikaXNbcjsFm6gg9ExeVR-jzIyT-mJvA_ntvfRsDDOH2jnKMjdTtXIJvPt0NBUU45R7-gnjxkx-sI0ldcWvbDHsV0735yFDbWk", "paymentMethod": "CARD", "paymentMethodDetails": { "expirationYear": 2028, "expirationMonth": 12, "pan": "4111111111111111", "authMethod": "PAN_ONLY" } }
ECv1
{ "messageExpiration": "1507738377032", "paymentMethod": "CARD", "messageId": "AH2EjtcHYs1Ye-ZIZuZXd7eNO4QjQfZjBDtP2ti0tob_a5o22lHmGWHsBVYrrSylkFC3ZTsRdvMadQpwOGCIl7XxhTKcfElmgF7UFbcI8CeUZCWRmbTH5s7h69Baqr4FAM735VNThPiP", "paymentMethodDetails": { "expirationYear": 2028, "expirationMonth": 12, "pan": "4111111111111111" } }
Mastercard 卡
下例展示了非令牌化 Mastercard 卡经过解密的载荷:
ECv2
{ "gatewayMerchantId": "some-merchant-id", "messageExpiration": "1650574585777", "messageId": "AH2Ejte23Sp0DBWqKVQ1d8ICVQialPGgXSsTT4NnCjNy3i-jdJg6B_wllO8590dFfrLg16GqGcuSrEPjl-sQZ-K8sKCL62ahwh5kzUv4ggLwioImJmuEuKfAiEQBRW0L8zlo0Nv6LFuk", "paymentMethod": "CARD", "paymentMethodDetails": { "expirationYear": 2028, "expirationMonth": 12, "pan": "5555555555554444", "authMethod": "PAN_ONLY" } }
ECv1
{ "messageExpiration": "1507738377032", "paymentMethod": "CARD", "messageId": "AH2EjtcHYs1Ye-ZIZuZXd7eNO4QjQfZjBDtP2ti0tob_a5o22lHmGWHsBVYrrSylkFC3ZTsRdvMadQpwOGCIl7XxhTKcfElmgF7UFbcI8CeUZCWRmbTH5s7h69Baqr4FAM735VNThPiP", "paymentMethodDetails": { "expirationYear": 2028, "expirationMonth": 12, "pan": "5555555555554444" } }
American Express 卡
下例展示了非令牌化 American Express 卡经过解密的载荷:
ECv2
{ "gatewayMerchantId": "some-merchant-id", "messageExpiration": "1650574857349", "messageId": "AH2EjtcmoURSXm2RhZ8ihnJrsty-7Ewm3NEnJDM-Atw9ewbIPvuarglows0vtaCV33b4z3PpM5RsMklbpe0aNPK5_BanGxmp_JSsOEtZYuf4m3cHTtKnxpQeonN07XDK-DUPKAaRwLfY", "paymentMethod": "CARD", "paymentMethodDetails": { "expirationYear": 2028, "expirationMonth": 12, "pan": "378282246310005", "authMethod": "PAN_ONLY" } }
ECv1
{ "messageExpiration": "1507738377032", "paymentMethod": "CARD", "messageId": "AH2EjtcHYs1Ye-ZIZuZXd7eNO4QjQfZjBDtP2ti0tob_a5o22lHmGWHsBVYrrSylkFC3ZTsRdvMadQpwOGCIl7XxhTKcfElmgF7UFbcI8CeUZCWRmbTH5s7h69Baqr4FAM735VNThPiP", "paymentMethodDetails": { "expirationYear": 2028, "expirationMonth": 12, "pan": "378282246310005" } }
Discover 卡
下例展示了非令牌化 Discover 卡经过解密的载荷:
ECv2
{ "gatewayMerchantId": "some-merchant-id", "messageExpiration": "1650574781399", "messageId": "AH2EjteSxPPpbJOXKXzG1Cqkh1kzJz0UP1AG4w75n9q7gCtWsawfRlqtUZofjIBnKlbozvASxKkkdbjv2-rOfNGd_st4kFqPeb6O3IE-fXeIcHzH8x56tMRylEnfnrF6x01ET8KdUeLS", "paymentMethod": "CARD", "paymentMethodDetails": { "expirationYear": 2028, "expirationMonth": 12, "pan": "6011111111111117", "authMethod": "PAN_ONLY" } }
ECv1
{ "messageExpiration": "1507738377032", "paymentMethod": "CARD", "messageId": "AH2EjtcHYs1Ye-ZIZuZXd7eNO4QjQfZjBDtP2ti0tob_a5o22lHmGWHsBVYrrSylkFC3ZTsRdvMadQpwOGCIl7XxhTKcfElmgF7UFbcI8CeUZCWRmbTH5s7h69Baqr4FAM735VNThPiP", "paymentMethodDetails": { "expirationYear": 2028, "expirationMonth": 12, "pan": "6011111111111117" } }
令牌化卡
“令牌化卡”是指添加到 Google Pay 的卡。
令牌化卡的解密载荷取决于所选卡的类型。以下三个示例显示了不同类型的令牌化卡的解密载荷:
Visa 卡
以下示例展示了令牌化 Visa 卡的解密载荷:
ECv2
{ "gatewayMerchantId": "some-merchant-id", "messageExpiration": "1561533871082", "messageId": "AH2Ejtc8qBlP_MCAV0jJG7ErQKeDrkEUtQ0N3QRvPXWJc-jgC0VTfgmarDRZvTwuzirQPdUjkMkiQ7tnDidZbtlQTO-mAgMIdXRMuYedhZXnCcokmkJOOnE7jBn-pvkyBncOgpPWFFn3", "paymentMethod": "CARD", "paymentMethodDetails": { "expirationYear": 2028, "expirationMonth": 12, "pan": "4895370012003478", "authMethod": "CRYPTOGRAM_3DS", "eciIndicator": "07", "cryptogram": "AgAAAAAABk4DWZ4C28yUQAAAAAA=" } }
ECv1
{ "messageExpiration": "1507738377032", "paymentMethod": "TOKENIZED_CARD", "messageId": "AH2EjtcHYs1Ye-ZIZuZXd7eNO4QjQfZjBDtP2ti0tob_a5o22lHmGWHsBVYrrSylkFC3ZTsRdvMadQpwOGCIl7XxhTKcfElmgF7UFbcI8CeUZCWRmbTH5s7h69Baqr4FAM735VNThPiP", "paymentMethodDetails": { "expirationYear": 2028, "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": 2028, "expirationMonth": 12, "pan": "370295136149943", "authMethod": "CRYPTOGRAM_3DS", "cryptogram": "JnPYbs6FkC1tiVLREAABoAAAkgA=" } }
ECv1
{ "messageExpiration": "1507738377032", "paymentMethod": "TOKENIZED_CARD", "messageId": "AH2EjtcHYs1Ye-ZIZuZXd7eNO4QjQfZjBDtP2ti0tob_a5o22lHmGWHsBVYrrSylkFC3ZTsRdvMadQpwOGCIl7XxhTKcfElmgF7UFbcI8CeUZCWRmbTH5s7h69Baqr4FAM735VNThPiP", "paymentMethodDetails": { "expirationYear": 2028, "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": 2028, "expirationMonth": 12, "pan": "5204240250197840", "authMethod": "CRYPTOGRAM_3DS", "cryptogram": "ALnt+yWSJdXBACMLLWMNGgADFA==" } }
ECv1
{ "messageExpiration": "1507738377032", "paymentMethod": "TOKENIZED_CARD", "messageId": "AH2EjtcHYs1Ye-ZIZuZXd7eNO4QjQfZjBDtP2ti0tob_a5o22lHmGWHsBVYrrSylkFC3ZTsRdvMadQpwOGCIl7XxhTKcfElmgF7UFbcI8CeUZCWRmbTH5s7h69Baqr4FAM735VNThPiP", "paymentMethodDetails": { "expirationYear": 2028, "dpan": "5204240250197840", "expirationMonth": 12, "authMethod": "3DS", "3dsCryptogram": "ALnt+yWSJdXBACMLLWMNGgADFA==" } }