Test with sample tokens

For direct integrations, in order to test token decryption on your server, you can generate sample tokens if you set the environment to TEST when you construct a PaymentsClient instance.

When the PaymentsClient instance is constructed with the environment set to TEST, the calls to loadPaymentData work as usual and request that the user selects one of their real cards. However, it never actually returns real information from the card that was selected, and instead, the token that results always has a constant payload.

Encryption

The tokens produced in the environment TEST are encrypted with your test public key that was previously sent to Google.

The tokens are signed with Google's test keys. If you use Tink, ensure that .fetchSenderVerifyingKeysWith(GooglePaymentsPublicKeysManager.INSTANCE_TEST) is set when you build a PaymentMethodTokenRecipient object.

Test payload

The payload inside the token depends on whether the card that was selected is tokenized, which means added to Google Pay, or not. In addition, the payload for tokenized cards is different, which depends upon the card network. The payload for non-tokenized cards is always the same, regardless of card network.

The following three fields may differ in your test payload compared to the samples below:

  • messageExpiration: A timestamp set one week from the current time.
  • messageId: This is randomly generated for each payload.
  • expirationYear: This is set five years from the current year.

Non-tokenized card

The following example shows what a test payload of a non-tokenized card looks like:

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

Tokenized card

A "tokenized card" refers to the cards that have been added to Google Pay.

The test payload of a tokenized card depends on the type of card selected. The following examples show test payloads for different types of tokenized cards:

Visa:

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

American Express:

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

All other networks:

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