locked
In App Purchase RRS feed

  • Question

  • Hello All,

    I am new with In-App Purchase, then I have a problem how to implement it in my App.
    I want to make In-App Purchase in my app using Durable. it is about buying same stage and level.
    But I don't know where I should define the cost of our levels or stages and how my app detect its cost.

    Anyone can help me please?
    :D
    Friday, April 18, 2014 6:38 AM

All replies

  • Take this code. We are using it in all our applications with Durable IAPs.

    public static class TrialHelper
        {
            public const string additionalFeatures = "here is your IAP product code";
            public static bool NoAdsFeature = false;
    
            public async static void BuyIAP()
            {
                try
                {
                    await CurrentApp.RequestProductPurchaseAsync(additionalFeatures, false);
    
                    LoadProducts();
                }
                catch { }
            }
    
            public static void LoadProducts()
            {
    #if NO_ADS
                NoAdsFeature = true;
                return;
    #endif
     
                try
                {
    
                    var productLicenses = CurrentApp.LicenseInformation.ProductLicenses;
    
                    NoAdsFeature = productLicenses.ContainsKey(additionalFeatures) && productLicenses[additionalFeatures].IsActive;
    
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine(ex.Message);
    
                }
            }
        }

    Just put your IAP code in additionalFeatures variable. You can name it as you want. Also there is one condition NO_ADS to test application . You can make copy of Debug solution configuration and add NO_ADS to the conditional compilation symbols in build section of project properties.

    Also do not forget to update your App.cs functions

    private void CheckTrial()
            {
                TrialHelper.LoadProducts();
            }
            // Code to execute when the application is launching (eg, from Start)
            // This code will not execute when the application is reactivated
            private void Application_Launching(object sender, LaunchingEventArgs e)
            {
                CheckTrial();
            }
    
            // Code to execute when the application is activated (brought to foreground)
            // This code will not execute when the application is first launched
            private void Application_Activated(object sender, ActivatedEventArgs e)
            {
                CheckTrial();
            }
    

    That's all what you need to use IAP in your application.

    Friday, April 18, 2014 10:36 AM