locked
Trial mode with ApplicationModel.Store.CurrentAppSimulator

    Question

  • I'm using the trial mode example code in my app I'm developing.  I hooked up an event listener for the license changed event as well as have a button with a click event to purchase the app, as in the example code.

    app.addEventListener("activated", function (args) {
            if (args.detail.kind === activation.ActivationKind.launch) {
                if (args.detail.previousExecutionState !== activation.ApplicationExecutionState.terminated) {
                    // TODO: This application has been newly launched. Initialize
                    // your application here.
    
                    //add share listener
                    var dataTransferManager = Windows.ApplicationModel.DataTransfer.DataTransferManager.getForCurrentView();
                    dataTransferManager.addEventListener("datarequested", dataRequested);
    
                    // Get the license info
                    var licenseInformation = currentApp.licenseInformation;
    
                    // Register for the license state change event.
                    licenseInformation.addEventListener("licensechanged", displayCurrentLicenseMode);
    
                    // Initialize the license proxy file
                    loadTrialModeProxyFile();
    
                 
    
                } else {
                    // TODO: This application has been reactivated from suspension.
                    // Restore application state here.
                }
    
                if (app.sessionState.history) {
                    nav.history = app.sessionState.history;
                }
                args.setPromise(WinJS.UI.processAll().then(function () {
                    if (nav.location) {
                        nav.history.current.initialPlaceholder = true;
                        return nav.navigate(nav.location, nav.state);
                    } else {
                        return nav.navigate(Application.navigator.home);
                    }
                }));
            }
        });

    The "buy" button click event listener code is this

      function doTrialConversion() {
            var licenseOutput = document.getElementById("licenseOutput");
            licenseOutput.innerHTML = "Buying the full license...";
            var licenseInformation = currentApp.licenseInformation;
            if (!licenseInformation.isActive || licenseInformation.isTrial) {
                currentApp.requestAppPurchaseAsync(false).done(
                function () {
                    if (licenseInformation.isActive && !licenseInformation.isTrial) {
                      //  WinJS.log && WinJS.log("You successfully upgraded your app to the fully-licensed version.", "sample", "status");
                        licenseOutput.innerHTML = "Thank you!  You have successfully upgraded your app to the " &
                                                   "fully-licensed version";
                    } else {
                        //WinJS.log && WinJS.log("You still have a trial license for this app.", "sample", "error");
                        licenseOutput.innerHTML = "Sorry, something went wrong.  You still have a trial version";
                    }
                },
                function () {
                    //WinJS.log && WinJS.log("The upgrade transaction failed. You still have a trial license for this app.", "sample", "error");
                    licenseOutput.innerHTML = "Sorry, something went wrong.  You still have a trial version";
                });
            } else {
                //WinJS.log && WinJS.log("You already bought this app and have a fully-licensed version.", "sample", "error");
            }
            displayCurrentLicenseMode();
        }
    

    When the buy button is clicked, the handler fires and simulates the purchase.  But, when the simulated purchase is done, the div's innerHTML is a "0".  Is this because of the async call to requestAppPurcaseAsync?   It also fires the license changed event handler which when I debug correctly reads the license as a full license.  But it still doesn't assign the div's innerHTML to "Full License".  Again, its just "0".  Here's the license changed event handler

     function displayCurrentLicenseMode() {
            var licenseOutput = document.getElementById("licenseOutput");
            var licenseInformation = currentApp.licenseInformation;
            if (licenseInformation.isActive) {
                if (licenseInformation.isTrial) {
                    licenseOutput.innerHTML = "Trial license";
                } else {
                    licenseOutput.innerHTML = "Full license";
                }
            } else {
                licenseOutput.innerHTML = "Inactive license";
            }
           
        }

    What is the proper way to do this?  Thank you!




    Bits of Fury

    Friday, July 12, 2013 3:47 AM