Docs

Google Play Store 

The Google Play Store integration helps you record in-app subscription purchases made on your Google Play Store app using Google billing libraries into Chargebee and maintain the subscription state in Chargebee by listening to Google server notifications .

What You Need to Know 

  • To monetize digital products or services on your app, you can use the in-app purchases solution offered by the Google Play Store. For detailed guidance on the Google Play billing system and monetization strategies, visit this page .
  • Since in-app purchases are made on the Google Play Store and the subscription state is managed by Google, Chargebee's billing engine doesn't control these subscriptions.
  • The omnichannel solution offered by Chargebee helps you record in-app subscription purchases made on the Google Play Store using the record a purchase API irrespective of the version of Google billing library  being used to make a purchase.
  • When you send a request to the Record a purchase API, Chargebee verifies the token and creates an omnichannel subscription.
  • Omnichannel subscriptions created in response to recorded purchases are managed in real-time through Google server notifications .
  • Before starting implementation, it is suggested that you review the Omnichannel subscriptions page to understand the solution, its benefits, and its limitations.
  • When an end user logs into the app with different accounts on the same Android device and uses the same Play Store account to purchase different subscriptions, Google considers this as an upgrade or downgrade rather than a new purchase, as long as the initial purchase token is valid. Chargebee similarly upgrades or downgrades the corresponding omnichannel subscription and ignores the Record a Purchase API request because the subscription already exists in Chargebee.
  • If a subscription purchase is made by the end user post subscription cancellation, then there are two scenarios
    • If the purchase token from the initial purchase is still active, Google treats the transaction as a subscription reactivation. However, Chargebee doesn't currently process reactivation notifications from Google. As a result, omnichannel subscriptions are not reactivated in Chargebee. Any Record a Purchase API request for such a re-purchase will be ignored since an omnichannel subscription linked to the same purchase_token already exists in Chargebee.
    • If the purchase_token from the initial purchase has expired, Google treats the transaction as a new subscription. Chargebee follows the same behavior and processes the Record a Purchase API request as a new subscription.
      Note: The purchase token associated with a Google in-app purchase will be active for 60 days after the subscription expires for the live Android apps.
  • To test new purchases from the same device, create different Google sandbox accounts and sign in with those accounts. You may also need to delete and reinstall your app to clear the purchase history associated with a sandbox account.
  • Ensure that the pre-requisites are completed before attempting to record a purchase in Chargebee
  • Ensure that Chargebee's notifications URL is configured in the Google Cloud Platform (GCP) so that Chargebee can maintain the subscription state by listening to Google notifications.
  • Refer to the web sequence diagram here to understand the purchase journey.

Prerequisites 

These are the steps that you need to complete to make your app ready for in-app purchases.

Configure in-app purchase products 

Configure the products that your app merchandises in Google Play Console .

Implement in-app purchases using Google Billing Library 

Google billing library offers the entire set of client APIs that help you retrieve the in-app purchase products configured in Google Play Console, make a purchase using billing library methods, and keep track of the purchase using the purchase token. Go through this Google documentation  to implement the billing library in your app and start with in-app purchases. For every transaction made using the Google billing library, Google will return a purchase token. You need to save this token at your backend and pass this token while invoking Record a purchase API for Chargebee to verify the purchase and create the corresponding omnichannel subscription.

Once you invoke the record of a purchase API of Chargebee with the purchase token, Chargebee will verify the purchase with Google servers using the purchases.subscriptionsV2 API , create a corresponding omnichannel subscription.

Create Omnichannel subscriptions for in-app purchases 

Once you have an active Chargebee test or live site, follow these steps to start recording in-app subscription purchases in Chargebee.

Connect Google App to Chargebee to generate unique App ID and Notifications URL 

Connect your apps listed in the Google Play Store to Chargebee to record and manage your Google Play Store subscriptions through Chargebee. Once your app is connected, Chargebee will generate a unique App ID that can be used for recording purchases and a unique Notifications URL that can be configured in the Google Cloud Platform to relay the Google in-app subscription state change events to Chargebee.

To connect your app with Chargebee, follow the steps:

  1. Login to your Chargebee site and navigate to Apps on the left menu. Click Go to Marketplace.

  2. Click Mobile App Stores > Google Play Store.

  3. Click Connect and Proceed.

  4. Enter Setup Credentials. Chargebee needs you to set up the credentials below to access Google Play Store APIs. To understand how to retrieve the setup credentials from the Google Play console.

    1. Account Name: This is the display name for your Google Play Store account on the Chargebee site. You can choose to give any unique name here, such as Acme Inc.
    2. App Name: This is the display name for your App in Chargebee. You can choose to give any unique name here to identify your app, such as Prodify, or you can retrieve the app name from the Google Play console account.
    3. Package Name: This is the unique identifier with which your app is registered in the Google Play Store. Enter the package name of the app that you want to connect with Chargebee. You can retrieve the package name associated with the Google Play console account.
    4. Service Account Credentials JSON: Chargebee needs this JSON file to connect to Google APIs on behalf of your app. So, click Browse or use the drag-and-drop function to upload the JSON file saved on your system during the service account creation. Learn more about generating the service account credentials JSON file.
      Note: All the above fields are mandatory to connect your Play Store app with Chargebee.
  5. After the successful connection, Chargebee generates a unique App ID for recording purchases via the Record a Purchase API, along with a notifications URL to be configured in the Google Cloud Platform to track subscription state change events.

Connect multiple Google Apps (Optional) 

If you want to connect multiple apps that are linked to the same or different Google Play Store account, then you need to follow these steps:

  1. Login to your Chargebee site and navigate to Apps on the left menu.

  2. Click Google Play Store to view the already connected apps under different accounts.

  3. Click Add App on this Apps page to connect another app to Chargebee.

  4. Click the account to which you want to connect the app, and you'll be redirected to the Setup Credentials page. Here, you can enter the app's credentials and connect them.

  5. If you want to connect the app to a different Google account, click Add app to a new account at the bottom. You'll be redirected to the Setup Credentials page, where you can enter the app's credentials along with the new account name to connect to the new app.

  6. Once the connection is successful, view all the apps belonging to all your accounts on the Apps page.

Record a Google purchase using the App ID and Create Omnichannel Subscription 

To view subscription purchases made on the Google Play Store in Chargebee, you must record these purchases using the Record a Purchase API. You need the App ID to invoke this API.

  1. Retrieve the App ID generated by Chargebee from the Apps page. or the App Settings page.

    • Option 1: Navigate to Apps > Google Play Store > Apps and Copy the App ID associated with the App.

    • Option 2 : Navigate to Apps > Google Play Store > Apps. On the Apps page, click on the application for which you want to retrieve the App ID, click App Settings, copy the App ID, and keep it for further use.

  2. Invoke the Record a Purchase API with the app_id, customer_id, and purchase_token parameters. This returns a recorded_purchase resource with the status in_process. Chargebee invokes Google APIs to initiate the verification of the purchase. After successful verification of the purchase, an omnichannel subscription will be created in Chargebee, and a webhook event omnichannel_subscription_created will be triggered.

Enable Realtime Subscription State Sync 

Omnichannel subscription state changes rely entirely on server notifications from Google. To allow Chargebee to receive and process these notifications, you must complete the following setup.

Set Up Notification URL in Google Cloud Platform for Subscription State Sync with Chargebee 

After the integration is successfully completed, Chargebee will generate a notification URL. Configure the notification URL in Google Cloud Platform to sync subscription state changes with Chargebee in real-time.

To set up the notification URL in Google Cloud Platform, follow these steps:

  1. Login to your Chargebee site and navigate to Apps on the left menu.
  2. Click Google Play Store.
  3. Click on the application for which you want to set up the Notifications URL.
  4. Click the App Settings and copy the Notification URL.
  5. Use this Notification URL as the endpoint URL for the topic generated in the GCP. To understand how to generate a topic and associate the notification URL with it, click here.

Subscribe to Omnichannel webhook events 

Once Chargebee's notification URL is successfully set in GCP, Chargebee will receive the Google server notifications for subscription state changes in the Play Store and generate corresponding omnichannel webhook events.

These omnichannel webhook events are needed for your downstream operations, such as provisioning content, generating reports, planning email campaigns, and more.

To receive these omnichannel subscription state change events from Chargebee, you need to subscribe to the omnichannel subscription webhook events. Learn all about Chargebee webhook events.

View Google In-App Purchases in Chargebee 

As an app developer, you may want to view in-app purchases and transactions made through the Google Store. Chargebee's Purchases page displays all recorded Google purchases.

To view in-app purchases in Chargebee, follow these steps:

  1. Login to your Chargebee site and navigate to Apps on the left menu.
  2. Click Google Play Store.
  3. Click on the application for which you want to view in-app purchases.
  4. Under Recorded Purchases, view the list of in-app purchases.

View Omnichannel Subscriptions in Chargebee 

As a customer care, marketing, or revenue growth professional, you can use Chargebee's Omnichannel Subscriptions page to view all the omnichannel subscriptions corresponding to all the apps listed on the Google Play Store. App-specific filters can be applied to view subscriptions corresponding to specific apps. You can click any omnichannel subscription ID and access the omnichannel subscription's details page to check the subscription details and respond to customer queries quickly.

Google Play Configurations 

To enable communication between Chargebee and Google servers, a connection needs to be established between Chargebee and Google. To establish this connection, Chargebee needs app details and service account credentials. Once the connection is established, the topic ID configurations need to be done in Google Play Console and Google Cloud Console for Chargebee to maintain the subscription state. The below steps detail these configurations and will be handy when you are connecting the Google App to Chargebee.

  1. Retrieve App name & package name
  2. Generate service account credentials
  3. Create a Topic ID in Google
  4. Create Subscription to the Topic with Chargebee's Notification URL
  5. Set up the topic to receive notifications from Google
  6. Configure the topic in Google Play Console

Retrieve App name and Package Name 

To retrieve your App Name and App Package Name, follow these steps:

  1. Login to your Google Play Store Console .

  2. Click Home from the main menu.

  3. Review the list of apps present in your Google Play Console.

  4. Click the specific App from the list and navigate to Dashboard to check the App Name and App Package Name.

    1. App Name
    2. App Package Name
  5. Take a note of the App Name and App Package Name that you want to connect with your Chargebee account.

Generate Service Account Credentials - JSON File 

To enable Chargebee servers to communicate with Google on behalf of your app, you need to provide service credentials by generating a service account credentials JSON file. Follow the steps carefully to generate this file.

Note

Google Play Service Credentials might require up to 36 hours to become fully operational with the Google Play Android Developer API.

Step 1: Enable Google Developer and Reporting APIs

These APIs have to be enabled to manage your app in the Google Play Store and consume the data from Google Play Console for reporting.

To enable Google Play Android Developer API and Google Play Developer Reporting API, follow these steps:

  1. Login to your Google Cloud Console .

  2. Select a project from the dropdown list.

  3. Optional: Click NEW PROJECT to create a new project if you do not have an existing project.

    Enter the Project name, Organization, and Location to create a new project and click CREATE.

  4. Navigate to APIs & Services > Enable APIs & services. Click + ENABLE APIS AND SERVICES.

  5. Search Google Play Android Developer API and Google Play Developer Reporting API.

  6. Enable both APIs.

  7. Post enabling these APIs, you'll be redirected to the Google Cloud API page. If you already have credentials to access this API then proceed to Step 2. If you don't have credentials to access these APIs, then follow below two steps

    1. Click Create Credentials.

    2. In the Credential Type screen, the API will be auto-selected for which you are going to create credentials. What data will you be accessing? option,select the Application data as Chargebee only needs the application data, and click Next.

    3. In the Service account details screen, enter the Service account name, Service account ID, and Service account description. To create a service account follow Step 2 and click CREATE AND CONTINUE > DONE.

    4. If you have just created credentials, a message will appear - To use this API, you may need credentials. This message appears because Google takes some time to validate credentials.

Step 2: Create a service account and download the service account credentials JSON file

You need to create a service account for Chargebee to make authorized API calls for your app.

To create a service account, follow these steps

  1. Navigate to IAM & Admin > Service Account in the Google Cloud Console. Ensure that the project for which the service account needs to be created is selected. Ideally, it is the same as the one selected in the previous step.

  2. Click Create Service Account.

  3. In the Service account details step, enter the Service account name, Service account ID, and Service account description, and click Create And Continue.

  4. In the Grant this service account access to project step, select the Role as Pub/Sub Admin and Monitoring Viewer, and click Continue. These roles enable receiving Google platform server notifications and monitoring the notification queue. You can skip the third step Grant users access to this service account and click DONE.

  5. In the Service accounts for screen, identify the recently created service account and click the ⋮ icon > Manage keys.

  6. In the Keys tab, click Add Key and create a new key.

  7. In the Key type, select JSON to create a private key for your associated service account and click CREATE to download the key.

  8. Save the downloaded key and click CLOSE.
    Note: This service account credentials JSON file needs to be uploaded to Chargebee while integrating your Android App. So please make sure that it is saved securely.

Step 3: Invite service account and grant access permissions

In order to manage the subscriptions with the notifications received from the Google Store and retrieve the financial data with the service account, you need to invite the service account as a user and grant the needed permissions in the Google Play Console.

To invite the service account as a user and grant the needed permissions, follow these steps:

  1. Open Google Play Console  and login using your Google developer account credentials.

  2. Navigate to Users and permissions and click Invite new users to invite the service account created in Step 2.

  3. Go to the Service accounts section in the Google Cloud Console and copy the service account that was created in Step 2.

  4. In the Invite user screen, paste this service account in the Email address field.

    1. Go to Permissions > Account permissions, add the following permissions to the service account, and click Invite user.
      1. View app information and download bulk reports: To view apps and download the reports

      2. View financial data, orders, and cancellation survey responses: To view financial data related to purchases

      3. Manage orders and subscriptions: To view and refund orders

  5. In the Users and permissions screen verify the invitation. You can see the newly created account as Active.

    Note: Use the generated service account credentials JSON file to connect your app to Chargebee. Refer to this step 4.

Create a Topic ID in Google 

To maintain any changes to the status of a subscription, it is important to set up Chargebee to receive notifications from Google, and to achieve this, the notification URL generated by Chargebee should be associated with the Topic ID created in Google Cloud Console. Once this configuration is done, the subscription state changes that happen in Google can be synced to Chargebee in real-time through real-time notifications via Google Real-Time Developer Notifications (RTDN).

This section will help you understand how to create a Topic ID in the Google Cloud console and configure the same in the Google Play console. Learn more  about the concept of Topics.

Follow the steps below to set up the Pub/Sub access to your Google Cloud Console project:

  1. Access Google Cloud Console  and click Sign up to initiate the creation of a project if you don't have Google Cloud Access.

  2. Specify the details required in the applicable fields and click Continue to proceed with the sign-up process.

  3. Complete the contact number verification and create a payment profile to complete the setup of your Google Cloud account.

  4. Review the details within the Google Cloud Dashboard.

  5. Click Create a Project from IAM & Admin in the left nav menu.
    Note: If you have already created a project, skip to Step 7.

  6. Specify the desired name in the Project Name field and click CREATE.
    Note: This project name cannot be edited or changed later.

  7. Click Topics from the Pub/Sub menu on the left nav or Search for Topic in Google Cloud Console and go to Topics.
    Note: This project name cannot be edited or changed later.

  8. Click Create Topic.

  9. Specific an applicable name for the topic in the Topic ID field, enable the checkboxes as in the image below and click CREATE TOPIC.

Create subscription to the topic with Chargebee's notification URL 

Follow the steps below to configure subscriptions to receive messages:

  1. Click Create Subscription from the More Actions menu.

  2. Update the following details on the Create subscription page.

    • Type applicable name in the Subscription ID field.

    • Select the Push radio button from the Delivery Type and paste the Notification URL generated by Chargebee in the End Point URL field.

  3. Click CREATE.

  4. Publish a test message to the Topic id to confirm functionality.

    • Click Topics to return to the topic list view.

    • Click applicable Topic ID to view details of the topic.

    • Scroll to the bottom of the page and click the MESSAGES tab.

    • Click Publish Message

    • Type applicable test message in the Message text-box and click PUBLISH.

    • Select the subscription from the drop-down list and check the message.

    • Click back to return to the topic list page.

Set up the Topic to Receive Notifications from Google 

Follow the steps below to associate your topic with a project to receive notifications from Google:

  1. Login to Google Cloud Platform.

  2. Click the drop-down list to select the applicable project that is linked to the Topic ID for which we want to receive notifications.
    Note: Make a note of the project name as it is required to configure your app to receive notifications.

  3. Click Topics from the Pub/Sub menu on the left nav.

  4. Select the applicable topic checkbox and click ADD PRINCIPAL in the PERMISSIONS tab.

  5. Update the following details in the Add Principals pop-up box.

    • Enter google-play-developer-notifications@system.gserviceaccount.com in the New Principal field.

    • Select Pub/Sub > Pub/Sub Publisher from the Role drop-down list.

    • Click Save.

    • The new principal with Pub/Sub access is added to the PERMISSIONS list.

Configure the Topic in Google Play Console 

Follow the steps below to configure the topic in Google Play Console:

  1. Copy the topic ID created in this step.

  2. Access your Google Play Console and select the applicable App.

  3. Navigate to Monetize > Monetization setup.

  4. Paste the Topic ID in the Topic Name field in the Real-time developer notifications section.

  5. Click Save and Send test Notification.

Was this article helpful?
Loading…