Google Play
SDK integration
dependencies {
implementation ("com.devtodev:android-google-purchases:*.*.*")
// Starting from version 6.0.0
implementation ("com.android.billingclient:billing:*.*.*")
}
To initialize the service, call the startAutoTracking
method of the DTDPurchases
interface. Call the method after the SDK initialization call:
val config = DTDAnalyticsConfiguration()
DTDAnalytics.initialize("App ID", config, context)
DTDGooglePurchases.initialize(context)
DTDGooglePurchases.startAutoTracking()
Subscription restore
The SDK will automatically restore the list of previously purchased subscriptions at the first launch of the autotracking service. No additional integration is required.
Settings in Google Cloud Platform Console
Google Play Android Developer API
Go to Google Cloud Console under your Google account. Select the project (1) for which you want to configure Google Play Developer API. Then go to the APIs and services section (2).

Go to the Library section.

Find the Google Play Developer API section.

Press
ENABLE
to enable the Google Play Androd Developer API.

Service account
Go to the Service accounts section.
Select the project to link the service account and where you will collect subscription data later. Create a new project if it is not in the list.
In the list of available service keys, click
CREATE SERVICE ACCOUNT
.Fill in the Service account name field. The Service Account ID field will be filled in automatically (use the screenshot below as an example) and click
CREATE AND CONTINUE
.s Skip the optional steps 2-3 and click
DONE
at the end of the form.After creating a service account, you will be returned to the available Service accounts list. Select the created account and open the KEYS tab (1), click
ADD KEY
(2), and then select the JSON key type option (3) in the pop-up window. ClickCREATE
to confirm your choice. The generated private key file will be downloaded automatically. You will need to upload this key to devtodev later in the following steps (see Settings on devtodev side).Go to the IAM section (1) in the Permissions tab and click
GRANT ACCESS
(2) to add roles to the service account. In the New principals section (3), enter the service account address and grant it the Pub/Sub Subscriber role (4). If you do not have this role, you need to activate the Pub/Sub service in the Cloud Console (activate Pub/Sub API). Save the changes (5).
Pub/Sub service
Go to the list of topics in the Pub/Sub service.
Select the project where you would like to collect subscription data. Click
CREATE TOPIC
.To create a topic: fill in the Topic ID (use the screenshot below as an example), disable Add a default subscription option (1) and click
CREATE
(2).Select a topic, click on three dots and select View permissions.
Click
ADD PRINCIPAL
to add the service account.Add the
[email protected]
service account and grant it the role of Pub/Sub Publisher. Save the changes.Open the list of subscriptions and click
CREATE SUBSCRIPTION
.In the appeared form:
Specify the Subscription ID (1).
Fill in the Topic name in Select a Cloud Pub/Sub topic field (2).
In the Delivery type select Push (3).
Copy Endpoint URL from devtodev (see steps 8-9) and insert it in the Endpoint URL field (4). All other parameters remain unchanged. Save the changes.
To get Endpoint URL, go to devtodev, select the same app and open app settings (Settings → Payments integration → Subscriptions). Click
Integrate
.Copy the Endpoint URL and paste it in the corresponding field in Google Cloud (step 7).
Settings on devtodev side
Go to Settings → Payments integration → IAP auto tracking and click
edit
(3).Fill in the integration form with the data obtained earlier:
Android App ID
Upload the Private key file obtained in Service Account step.
Click
Save
.When the integration is complete, the status will change to Active.
If you use subscriptions, go to Payments integration → Subscriptions and click
Integrate
.Upload the Private key file obtained in Service Account step (1). Specify Android App ID (2). Add all existing subscriptions, specifying the bundle, subscription period, and name for each subscription. Click
Save
(3) to finish integration.
Settings in Google Play Console
Service account and User permissions
To set up user permission, you need to log into your Google Play Console account and invite your previously created service account.
Sign into the Google Play Developer Console.
In the Users and permissions section, you can add users and manage their permissions.
Go to Users and permissions.
Click
Invite new users
.
Add Service Account as a new user:
Add your service account email in the Email address field (1).
In the Permissions section (2) select the apps (3) accessible to the service account. Click
Apply
(5). Grant permissions to individual apps, or use account permissions to grant access to all apps in your developer account.Grant the necessary rights to perform actions (see next step Account permissions).
Open Account permissions tab. Grant the following permissions:
View app information (1)
View app quality information (2)
View financial data (3)
Click
Apply
to confirm.

Click
Invite user
to finish the user setup.
Monetisation setup
After creating a subscription in the Pub/Sub service, you'll need to register the created topic as a target for Real-time developer notifications (RTDN).
Go to the app’s Monetise with Play → Monetisation setup section.
Enter the full name of the topic in the Topic name field.
Tick the Enable real-time notifications checkbox.
Send a test notification using the link below (4). If everything is configured correctly, the test notification will change the integration status of the Subscriptions in devtodev to Active (Settings → Payments integration → Subscriptions → Market connection).
Click
Save changes
to finish the setup.

Last updated
Was this helpful?