How to configure In-App Purchases with iTunes Connect [Unity]

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

  • Follow this guide to setup your products in the iTunes Connect 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 leave the Android publickey field empty.
  • Add these two event handlers to your Start() method;

    // request products handler
    GDInAppService reqService = new GDInAppService();
    reqService.RegisterEvent += new InAppEventHandler(OnProductsRequested);
    GamedoniaStoreInAppPurchases.AddRequestService(reqService); 
    // buy products handler
    GDInAppService buyService = new GDInAppService();
    buyService.RegisterEvent += new InAppEventHandler(OnProductPurchased);
    GamedoniaStoreInAppPurchases.AddPurchaseService(buyService);
    
  • 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 iTunes Connect) whenever you need:

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

More info here: In-app Purchases guide