locked
Can't in-app purchase after upgrade to Windows 8 release version

    Question

  • Hi, 

    After upgrading from RP to Win8 Release version, I find that the in-app purchase doesn't work anymore.  I checked the Migrating guide doc, but find nothing.

    I created a small app to explain this problem. Since my app is not released yet, I test the in-app purchase with "Windows.ApplicationModel.Store.CurrentAppSimulator". :

    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="utf-8" />
        <title>TestStore</title>
    
        <!-- WinJS references -->
        <link href="//Microsoft.WinJS.1.0/css/ui-dark.css" rel="stylesheet" />
        <script src="//Microsoft.WinJS.1.0/js/base.js"></script>
        <script src="//Microsoft.WinJS.1.0/js/ui.js"></script>
    
        <!-- TestStore references -->
        <link href="/css/default.css" rel="stylesheet" />
        <script src="/js/default.js"></script>
        <script>
            var currentApp = Windows.ApplicationModel.Store.CurrentAppSimulator;
            var licenseInformation = currentApp.licenseInformation;
                    
            function init() {            
                test();
            }
            function pmt(msg) {
                var ul = document.getElementById("pmt");
                ul.innerHTML += "<li>" + msg + "</li>";
            }
            function test() {           
                if (licenseInformation.productLicenses.lookup("testf").isActive) {
                    pmt("active");
                }
                else {
                    pmt("not active");           
                }
            }
            function buy() {
                if (!licenseInformation.productLicenses.lookup("testf").isActive) {                
                    currentApp.requestProductPurchaseAsync("testf", true).then(
                        function () {
                            pmt("purchase ok");
                        },
                        function () {
                            pmt("purchase failed");
                        });
                }
                else {
                    pmt("already purchased");      
                }
            }
    
            
        </script>
    </head>
    <body onload="init()">
        
        <button onclick="test()">test</button>
        <button onclick="buy()">buy</button>
    
        <ul id="pmt"></ul>
    </body>
    </html>
    

    The problem is "licenseInformation.productLicenses.lookup("testf").isActive" always return "false" no matter I purchased the "testf" or not. It worked well in Win8 release preview.

    Any idea?

    Thank you very much.

    cheers 

    Alex


    woodhead is as woodhead does

    Thursday, August 23, 2012 5:45 AM

All replies

  • Alex,

    Have you reviewed the new sample?

    http://code.msdn.microsoft.com/windowsapps/Licensing-API-Sample-19712f1a

    -Jeff


    Jeff Sanders (MSFT)

    Friday, August 24, 2012 6:53 PM
    Moderator
  • Hello Alex,

    Are you still having problems with this?

    Thanks,

    James


    Windows Media SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/

    Monday, August 27, 2012 11:25 PM
    Moderator
  • Hi James,

    Yes, the problem is still there :-(

    I downloaded the example from the link Jeff posted, it WORKED well.

    I copy my code into the Example project, and it worked as well!

    Then I copy the code from the Example project into my project, it didn't work any more.

    I thought there might be something wrong with my project file.  Again I created a new empty project and copied the code below from Example into the project, it still didn't work. (I tested it by setting the break point. "licenseInformation.productLicenses.lookup("product2XX").isActive" was always false even purchase was successfully finished).

      var currentApp = Windows.ApplicationModel.Store.CurrentAppSimulator;
                var licenseInformation = currentApp.licenseInformation;
                if (!licenseInformation.productLicenses.lookup("product2XX").isActive) {
                        currentApp.requestProductPurchaseAsync("product2XX", false).done(
                        function () {
                            if (licenseInformation.productLicenses.lookup("product2XX").isActive) {
                                WinJS.log && WinJS.log("You bought Product 2.", "sample", "status");
                            } else {
                                WinJS.log && WinJS.log("", "sample", "status");
                            }
                        },
                        function () {
                            WinJS.log && WinJS.log("Unable to buy product 2.", "sample", "error");
                        });
                } else {
                    WinJS.log && WinJS.log("You already own Product 2.", "sample", "error");
                }

    Do I need to configure anything before I test the Store?

    Thank you very much.

    Cheers

    Alex


    woodhead is as woodhead does

    Thursday, August 30, 2012 4:35 AM
  • The short answer is yes!  You do need to do something besides just paste in this code.  You also have to set up the response etc...

    http://msdn.microsoft.com/library/windows/apps/Hh694065

    See this section:

    Step 5: Test the features using simulated calls to the License API

    Now, test your app using simulated calls to the license server. In JavaScript, C#, Visual Basic, or Visual C++, replace references to CurrentApp with  CurrentAppSimulator in the app's  initialization code.

    CurrentAppSimulator gets test-specific licensing info from an XML file called "WindowsStoreProxy.xml", located in <installation_folder>\Microsoft\Windows Store\ApiData. If this path and file don't exist, you must create them, either during installation or at run-time. If you try to access the CurrentAppSimulator.LicenseInformation property without WindowsStoreProxy.xml present in that specific location, you will get an error.

    Did you do all of this?

    -Jeff


    Jeff Sanders (MSFT)

    Thursday, August 30, 2012 1:41 PM
    Moderator
  • Hi Jeff,

    Thanks for your answer. I checked my application folder, there is a XML file called "WindowsStoreProxy.xml", but it is located in <installation_folder>\LocalState\Microsoft\Windows Store\ApiData.  There is a same file in the same folder of the Example project's application folder, I compare the content and find they are identical. The XML below the copied from that file:

    <?xml version="1.0" encoding="utf-16" ?>
    <CurrentApp>
        <ListingInformation>
            <App>
                <AppId>00000000-0000-0000-0000-000000000000</AppId>
                <LinkUri>http://apps.microsoft.com/webpdp/app/00000000-0000-0000-0000-000000000000</LinkUri>
                <CurrentMarket>en-US</CurrentMarket>
                <AgeRating>3</AgeRating>
                <MarketData xml:lang="en-us">
                    <Name>AppName</Name>
                    <Description>AppDescription</Description>
                    <Price>1.00</Price>
                    <CurrencySymbol>$</CurrencySymbol>
                    <CurrencyCode>USD</CurrencyCode>
                </MarketData>
            </App>
            <Product ProductId="1" LicenseDuration="0">
                <MarketData xml:lang="en-us">
                    <Name>Product1Name</Name>
                    <Price>1.00</Price>
                    <CurrencySymbol>$</CurrencySymbol>
                    <CurrencyCode>USD</CurrencyCode>
                </MarketData>
            </Product>
        </ListingInformation>
        <LicenseInformation>
            <App>
                <IsActive>true</IsActive>
                <IsTrial>true</IsTrial>
            </App>
            <Product ProductId="1">
                <IsActive>true</IsActive>
            </Product>
        </LicenseInformation>
    </CurrentApp>
    

    My project did work well before upgrade to Windows RTM. And now, I'm really confused.

    Thanks you very much.

    cheers

    Alex


    woodhead is as woodhead does

    Monday, September 03, 2012 12:05 AM
  • The only other thing I can suggest is:

    1. Build the Store purchase sample and see if that works fine for you.

    2.  Compare your code to the sample and look for differences.

    -Jeff


    Jeff Sanders (MSFT)

    Tuesday, September 04, 2012 3:20 PM
    Moderator
  • Hi Jeff,

    Thanks for your reply. I was busy with implementing the other features of my App, so I left this problem for a few days. Sorry for replying lately.

    This problem has been fixed by adding these lines when initialize:

    var that = this;
    		
    		Windows.ApplicationModel.Package.current.installedLocation.getFolderAsync("resource").done(
    		   function (folder) {
    		   	folder.getFileAsync("test-in-app-purchase.xml").done(function (file) {
    		   		that._currentApp.reloadSimulatorAsync(file);
    		   	});
    		   });

    "test-in-app-purchase.xml" is the "WindowsStoreProxy.xml" I posted before, without modifying a single character (of course my product id is not "1").

    I assume this is a bug of AppStore Simulator, because I've found nowhere mentioned about that I must call "reloadSimulatorAsync" first, and my code had worked before upgraded to Windows8 RTM.   Do I understand correctly?

    cheers

    Alex


    woodhead is as woodhead does

    Monday, September 10, 2012 10:27 AM
  • You are not using the default name for your file so you have to load it this way.

    -Jeff


    Jeff Sanders (MSFT)

    Tuesday, September 25, 2012 2:31 PM
    Moderator