In this tutorial, we’ll look at integrating the Google Play store with the brainCloud marketplace. By doing this, Google Android users will have the ability to validate purchased items from the Google Play store with brainCloud.
Note that apps still have to make the purchase directly with the Google Play Store. For more information on this process refer to the Google Play developer site.
brainCloud Portal Setup
Here are the steps to configure brainCloud for Google Play purchases.
- You should have set up your products in the brainCloud marketplace. Please refer to the Marketplace Configuration guide.
- You should have created the Google Store In-App products per the Google Developer documentation
Associate Google In-App Products with brainCloud Products
After setting up your products in the brainCloud marketplace, you’ll want to associate them with the Google product ids. In particular, we will be grabbing the product ids from the Google Play developer site and entering them into the appropriate brainCloud products.
- Log into the Google Play Developer site
- Select your App and go to the “In-App Products” section
- Select your IAP and grab the Google Product ID
(for this tutorial we’ll assume that the product id is com.braincloud.mygame.goldsack1)
- Log into the brainCloud Portal
- Go to the “Marketplace | Products” page in the Design tab
- Select the product you would like to associate.
- Click the “+ Edit Product” button
- Find your Price (or create one) and click the edit icon
- In the Edit Price dialog, click the + icon to add an entry for Google
- Enter your Google product id for this price – in our case “com.braincloud.mytestapp.goldsack1”.
- At this point, you may want to select your price to be the default if it isn’t already selected. You can do this back in the Edit Product page.
- You can now verify that your Product is coming back with the correct Google In-app Product id. Here is the output from the API Explorer “Product.GetInventory” call using “googlePlay” as the platform:
Google Certificates and Credentials
Once the products have been configured, you will need to add the appropriate Google credentials to brainCloud.
- Navigate to the Application IDs page
- Click the Google icon and notice the following fields
- The following sections will show you where to find the appropriate information
Google Package Name
- Log into the Google Play developer site
- Select your application
- Grab the package name
Google Service Account Email & p12 Certificate File
To validate purchases, brainCloud requires the usage of a Service Account to communicate with the Google Play backend servers.
- Log into the Google Console developer site
- Create a project (or select an existing project). Note that the Google Service Account can be used across multiple apps.
- Enable the Google Play Android Developer API
- Navigate to the Credentials page
- Create a new Service Account
- Select the p12 key type and click Create
- This should create a new Service Account and immediately download the p12 key file to your computer. If for some reason the browser did not download the p12 key file try Chrome.
- Upload the p12 key file to the brainCloud portal.
- Also, the Service Account should now show up on the Credentials page. Important: Grab the email address and save it to the brainCloud portal – Design | Core App Info | Application IDs, Google platform tab, Google Service Account Email field.
Linking the Google Console project to the Google Play app
For the Service Account to be active, you will need to link the console project to the Google Play app and give the Service Account permission to View Financial Reports. Note you will need to be the account owner in order to complete these steps.
- Log into the Google Play Developer Console
- Go to Settings | API Access
- Select the Google Console project to link to
- Verify that the project is linked and the Games Services Publishing API access is ON
- Next navigate to User accounts & rights
- Select the Service Account and turn on “View Financial Reports” permission. All other permissions can be disabled
- You should now be able to validate purchase with brainCloud.
Confirming the purchase Client Side
After making a purchase client side, GooglePlay will return a receipt with an orderId, productId, and purchaseToken that is used by the VerifyPurchase API call.
If your using Unity’s IAP Service, your code may look like this
public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs args)
var responseDictionary =
var receiptDataDictionary =
var payloadJson = (string)receiptDataDictionary["Payload"];
var payloadDictionary =
string innerPayloadJson = (string)payloadDictionary["json"];
var innerPayloadDictionary =
//brainCloud Expects a token, rather then purchaseToken. We convert that now
innerPayloadDictionary["token"] = innerPayloadDictionary["purchaseToken"];
var storeId = "googlePlay";
var contentJson = JsonWriter.Serialize(innerPayloadDictionary);
(response1, cbObject1) =>
//Award Purchased Item
if (string.Equals(args.purchasedProduct.definition.id, "currency_cashpack_500",
coins += 500;
}, (status1, code1, error1, cbObject1) =>
// Handle failed verification