使用範例代碼測試

本頁面說明如何使用範例代碼測試整合結果。

產生範例代碼

直接整合時,為了在伺服器中測試代碼解密功能,您可以在建立 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": 2027,
        "expirationMonth": 12,
        "pan": "4111111111111111",
        "authMethod": "PAN_ONLY"
    }
}

ECv1

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

Mastercard

以下是非權杖化 Mastercard 卡的已解密酬載示例:

ECv2

{
    "gatewayMerchantId": "some-merchant-id",
    "messageExpiration": "1650574585777",
    "messageId": "AH2Ejte23Sp0DBWqKVQ1d8ICVQialPGgXSsTT4NnCjNy3i-jdJg6B_wllO8590dFfrLg16GqGcuSrEPjl-sQZ-K8sKCL62ahwh5kzUv4ggLwioImJmuEuKfAiEQBRW0L8zlo0Nv6LFuk",
    "paymentMethod": "CARD",
    "paymentMethodDetails": {
        "expirationYear": 2027,
        "expirationMonth": 12,
        "pan": "5555555555554444",
        "authMethod": "PAN_ONLY"
    }
}

ECv1

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

American Express

以下是非權杖化 Amex 卡的已解密酬載示例:

ECv2

{
    "gatewayMerchantId": "some-merchant-id",
    "messageExpiration": "1650574857349",
    "messageId": "AH2EjtcmoURSXm2RhZ8ihnJrsty-7Ewm3NEnJDM-Atw9ewbIPvuarglows0vtaCV33b4z3PpM5RsMklbpe0aNPK5_BanGxmp_JSsOEtZYuf4m3cHTtKnxpQeonN07XDK-DUPKAaRwLfY",
    "paymentMethod": "CARD",
    "paymentMethodDetails": {
        "expirationYear": 2027,
        "expirationMonth": 12,
        "pan": "378282246310005",
        "authMethod": "PAN_ONLY"
    }
}

ECv1

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

Discover

以下是非權杖化 Discover 卡的已解密酬載示例:

ECv2

{
    "gatewayMerchantId": "some-merchant-id",
    "messageExpiration": "1650574781399",
    "messageId": "AH2EjteSxPPpbJOXKXzG1Cqkh1kzJz0UP1AG4w75n9q7gCtWsawfRlqtUZofjIBnKlbozvASxKkkdbjv2-rOfNGd_st4kFqPeb6O3IE-fXeIcHzH8x56tMRylEnfnrF6x01ET8KdUeLS",
    "paymentMethod": "CARD",
    "paymentMethodDetails": {
        "expirationYear": 2027,
        "expirationMonth": 12,
        "pan": "6011111111111117",
        "authMethod": "PAN_ONLY"
    }
}

ECv1

{
  "messageExpiration": "1507738377032",
  "paymentMethod": "CARD",
  "messageId": "AH2EjtcHYs1Ye-ZIZuZXd7eNO4QjQfZjBDtP2ti0tob_a5o22lHmGWHsBVYrrSylkFC3ZTsRdvMadQpwOGCIl7XxhTKcfElmgF7UFbcI8CeUZCWRmbTH5s7h69Baqr4FAM735VNThPiP",
  "paymentMethodDetails": {
    "expirationYear": 2027,
    "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": 2027,
        "expirationMonth": 12,
        "pan": "4895370012003478",
        "authMethod": "CRYPTOGRAM_3DS",
        "eciIndicator": "07",
        "cryptogram": "AgAAAAAABk4DWZ4C28yUQAAAAAA="
    }
}

ECv1

{
  "messageExpiration": "1507738377032",
  "paymentMethod": "TOKENIZED_CARD",
  "messageId": "AH2EjtcHYs1Ye-ZIZuZXd7eNO4QjQfZjBDtP2ti0tob_a5o22lHmGWHsBVYrrSylkFC3ZTsRdvMadQpwOGCIl7XxhTKcfElmgF7UFbcI8CeUZCWRmbTH5s7h69Baqr4FAM735VNThPiP",
  "paymentMethodDetails": {
    "expirationYear": 2027,
    "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": 2027,
        "expirationMonth": 12,
        "pan": "370295136149943",
        "authMethod": "CRYPTOGRAM_3DS",
        "cryptogram": "JnPYbs6FkC1tiVLREAABoAAAkgA="
    }
}

ECv1

{
  "messageExpiration": "1507738377032",
  "paymentMethod": "TOKENIZED_CARD",
  "messageId": "AH2EjtcHYs1Ye-ZIZuZXd7eNO4QjQfZjBDtP2ti0tob_a5o22lHmGWHsBVYrrSylkFC3ZTsRdvMadQpwOGCIl7XxhTKcfElmgF7UFbcI8CeUZCWRmbTH5s7h69Baqr4FAM735VNThPiP",
  "paymentMethodDetails": {
    "expirationYear": 2027,
    "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": 2027,
        "expirationMonth": 12,
        "pan": "5204240250197840",
        "authMethod": "CRYPTOGRAM_3DS",
        "cryptogram": "ALnt+yWSJdXBACMLLWMNGgADFA=="
    }
}

ECv1

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