Accessing Digital Purchases

If you are a developer of an Android app that supports purchases of digital goods (that is, one-time purchases and subscriptions), Actions for Google allows you to access digital goods that your users purchased from your Android app. For example, a language-teaching Action can provide access to advanced Spanish lessons for users who purchased those lessons via their Android app.

To learn how to implement in-app purchases and subscriptions on Android, see In-app Billing.

For non-Android platforms, you'll need to ask your users to link their accounts. You can then use your user's account history to identify what purchases they've made on other surfaces.

Retrieving user purchases

To retrieve information about items that a user previously purchased through your app, you must connect your Action with your Android app, and then enable your Action to access user in-app purchases.

Figure 1. User interface for connecting Android apps and accessing digital goods in the Actions Console.

Follow these steps to retrieve user purchases:

  1. Set up access to Google Play purchases.

    1. In the Actions Console, navigate to Advanced Options > Brand verification.
    2. Under the Android apps section, connect an Android app with your Action. Enable the Access Play purchases option to select the Android apps for which you want to get user purchase data.
    1. Click Connect App to save your changes.
  2. Read the user's Entitlements info from the request JSON. If the Android app is successfully connected, the requests from Google Assistant to your fulfillment will include information about the user's purchases for the linked Android app. This data is included in the request JSON message. You do not need to make an explicit API call to retrieve this data.

    The code snippet below shows an example of what this request might look like.

{
  "user": {
    "userId": "xxxx",
    "locale": "en-US",
    "lastSeen": "2018-02-09T01:49:23Z",
    "packageEntitlements": [
      {
        "packageName": "com.abcd.edfg.hijk",
        "entitlements": [
          {
            "sku": "com.abcd.edfg.hijk",
            "skuType": "APP"
          }
        ]
      },
      {
        "packageName": "com.abcd.edfg.lmno",
        "entitlements": [
          {
            "sku": "lmno_jun_2017",
            "skuType": "SUBSCRIPTION",
            "inAppDetails": {
              "inAppPurchaseData": {
                "autoRenewing": true,
                "purchaseState": 0,
                "productId": "lmno_jun_2017",
                "purchaseToken": "12345",
                "developerPayload": "HSUSER_IW82",
                "packageName": "com.abcd.edfg.lmno",
                "orderId": "GPA.233.2.32.3300783",
                "purchaseTime": 1517385876421
              },
              "inAppDataSignature": "V+Q=="
            }
          }
        ]
      }
    ]
  },
  "conversation": {
    "conversationId": "1518141160297",
    "type": "NEW"
  },
  "inputs": [
    {
      "intent": "actions.intent.MAIN",
      "rawInputs": [
        {
          "inputType": "VOICE",
          "query": "Talk to My Test App"
        }
      ]
    }
  ],
  ...
}