locked
Multiple In-App Purchases

    Question

  • Currently, I have a premium upgrade in my app and I check if the user has that premium upgrade by running

    licenseInformation.productLicenses.lookup('premium1').isActive

    I want to add another level of premium level called pro1 and some of the features are in both "plans", how do I check if the user has either plans active.  Do I have to call:

    if (licenseInformation.productLicenses.lookup('premium1').isActive || licenseInformation.productLicenses.lookup('pro1').isActive)

    Or is there an easier way to do this?  Maybe:

    if (licenseInformation.productLicenses.lookup(['premium1','pro1']).isActive)

    The reason I ask because I could potetially have tens of plans which would means my if statement will be HUGE...

    Also, does this call hit the internet everytime or is it cached?  Does it have performance implications if I have to check for say 10 differen licenses?  

    Imagine this scenario:

    if (licenseInformation.productLicenses.lookup('annualpro').isActive ||

    licenseInformation.productLicenses.lookup('annualplus').isActive ||

    licenseInformation.productLicenses.lookup('annualelite').isActive ||

    licenseInformation.productLicenses.lookup('monpro').isActive ||

    licenseInformation.productLicenses.lookup('monplus').isActive ||

    licenseInformation.productLicenses.lookup('monelite').isActive ||

    licenseInformation.productLicenses.lookup('quarterpro').isActive ||

    licenseInformation.productLicenses.lookup('quarterplus').isActive ||

    licenseInformation.productLicenses.lookup('quarterelite').isActive )

    will the above hit the internet 9 times?


    www.emadibrahim.com


    • Edited by Emad Friday, December 14, 2012 11:46 AM
    Friday, December 14, 2012 11:46 AM

Answers

  • Hi Emad,

    Currently, the only API for checking in-app purchase status is the LicenseInformation.ProductLicenses. We use this property to lookup a certain in-app license item and then check its isActive property.

    #LicenseInformation.ProductLicenses | productLicenses property (Windows)
    http://msdn.microsoft.com/en-us/library/windows/apps/windows.applicationmodel.store.licenseinformation.productlicenses.aspx

    In case you want to prepare your code for potential increasing in-app purchase items, you can consider add some custom helper javascript class/functions such as:

      

      function isInAppPurchaseValid(pName) {
            var currentApp = Windows.ApplicationModel.Store.CurrentAppSimulator;
            var inAppLicenses = currentApp.licenseInformation.productLicenses;
            if(inAppLicenses.hasKey(pName)){
                if (inAppLicenses.lookup(pName).isActive) return true;
            }
            return false;
        }

    to simplify the code. You can even make the helper function accept an Array of in-app purchase names and perform "IsAllValid" or "IsAnyValid" like checking logic.

     


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Emad Monday, December 17, 2012 1:30 PM
    Monday, December 17, 2012 6:02 AM
    Moderator

All replies

  • Hi Emad,

    Currently, the only API for checking in-app purchase status is the LicenseInformation.ProductLicenses. We use this property to lookup a certain in-app license item and then check its isActive property.

    #LicenseInformation.ProductLicenses | productLicenses property (Windows)
    http://msdn.microsoft.com/en-us/library/windows/apps/windows.applicationmodel.store.licenseinformation.productlicenses.aspx

    In case you want to prepare your code for potential increasing in-app purchase items, you can consider add some custom helper javascript class/functions such as:

      

      function isInAppPurchaseValid(pName) {
            var currentApp = Windows.ApplicationModel.Store.CurrentAppSimulator;
            var inAppLicenses = currentApp.licenseInformation.productLicenses;
            if(inAppLicenses.hasKey(pName)){
                if (inAppLicenses.lookup(pName).isActive) return true;
            }
            return false;
        }

    to simplify the code. You can even make the helper function accept an Array of in-app purchase names and perform "IsAllValid" or "IsAnyValid" like checking logic.

     


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Emad Monday, December 17, 2012 1:30 PM
    Monday, December 17, 2012 6:02 AM
    Moderator
  • Just to clarify Emad, remember to replace CurrentAppSimulator with CurrentApp before you package for distribution to the store.

    Steven, is this an area where there are any plans for improvement?  CurrentAppSimulator is very painful to work with, and does not behave like an actual purchase process would.  In effect, it only allows the developer to simulate a success.  It also requires debug code in the app (XML for license simulation, as well as code to read the licensing information), and that code then needs to be stripped before a distribution package is built.  More robust tools for simulating and testing this very important strata of application development would be appreciated.



    • Edited by tt92618 Monday, December 17, 2012 6:35 AM
    Monday, December 17, 2012 6:32 AM
  • As a side note:

    Ensure you accommodate the case where there may not be a connection or you will fail app certification for sure.

    -Jeff


    Jeff Sanders (MSFT)

    Monday, December 17, 2012 1:12 PM
    Moderator