How to configure In-App Purchases with Google Play [Unity]

To enable In-App purchases in your game, you need to follow these steps:

  • Follow this guide to setup your products in the Google Play store.
  • Setup a Unity project with the Gamedonia SDK by following these steps.
  • Add the GamedoniaStoreInAppPurchases Script (located at Assets/Plugins/Gamedonia) to your Gamedonia Prefab and set it up like this. You can get the Android Public key in the Services and APIs section of the Google Play Developers Console.
  • Modify the AndroidManifest.xml (located at Plugin/Android) like this.
  • Add these two event handlers to your Start() method;

    // request products handler
    GDInAppService reqService = new GDInAppService();
    reqService.RegisterEvent += new InAppEventHandler(OnProductsRequested);
    // buy products handler
    GDInAppService buyService = new GDInAppService();
    buyService.RegisterEvent += new InAppEventHandler(OnProductPurchased);
  • Create the 2 callback methods ( OnProductsRequested and OnProductPurchased ):

    private void OnProductsRequested() {
    if (GamedoniaStore.productsRequestResponse.success) {
        foreach (KeyValuePair<string, Product> entry in GamedoniaStore.productsRequestResponse.products) {
            Product product = (Product)entry.Value;
        //TODO process the products
    } else {
            //TODO process request products failure
    private void OnProductPurchased() { 
    PurchaseResponse purchase = GamedoniaStore.purchaseResponse;
    //TODO: process the purchase details here
  • Execute the calls to the request and buy methods (with the exact product id from the Google Play Developer Console) your whenever you need:

    string [] keys = new string[1];
    keys[0] = "PRODUCT_ID";
    GamedoniaStore.RequestProducts(keys, keys.Length);
  • A pop-up will appear in order to confirm or reject the transaction.

More info here: In-app Purchases guide