How to validate in-app-purchase Android server side Java?

We used the same example, and made a bunch of changes to make it work:

  1. Instead of application name, use package name: replace .setApplicationName(applicationName) with .setApplicationName(packageName)

  2. Instead of P12, we use JSON key: GoogleCredential credential = GoogleCredential.fromStream(IOUtils.toInputStream(jsonCert));

where jsonCert is a JSON Key (Service Accounts -> Select an account -> Create key) looks like

{
"type": "service_account",
"project_id": "api-xxx",
"private_key_id": "xxx",
"private_key": "your_private_key",
"client_email": "[email protected]",
"client_id": "xxx",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://accounts.google.com/o/oauth2/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/api-server-service-account%40api-xxx.iam.gserviceaccount.com"
};

Update: as per @Q Locker, it might take some time for Google to provision a service account after creation ( up 2 days in @Q Locker's case).


Dmitry Bogdanovich's answer does not help.

Service account creation does not take effect immediately, in my case, I waited less than 2 days to make it work.