locked
In app purchases for Dummies!

    Question

  • Hello, am ready to deploy my app and i would love to include in app purchases.

    I tried implementing it with the following code i got from here

    http://msdn.microsoft.com/en-us/library/windows/apps/hh694067.aspx

    function appInit()
    {
        // some app initialization functions
    
            // Get current product object 
            // Execute only one of these statements. 
            // The next line is commented out for testing.
            // currentApp = Windows.ApplicationModel.Store.CurrentApp;
    
            // The next line is commented out for production/release.
            currentApp = Windows.ApplicationModel.Store.CurrentAppSimulator;
    
            // We should have either a real or a simulated CurrentProduct object here.
    
            // Get the license info
            licenseInformation = currentApp.licenseInformation;
    
        // other app initializations function
    }
    

    function buyFeature1() { if (!licenseInformation.productLicenses.lookup("featureName").isActive) { // The customer doesn't own this feature, so // show the purchase dialog.// note: currentApp is a reference to CurrentAppSimulator from a previous declaration currentApp.requestProductPurchaseAsync("featureName", false).then( function () { // the in-app purchase was successful }, function () { // The in-app purchase was not completed because // there was an error. }); } else { // The customer already owns this feature. } }

    But nothing seems to happen.i know this is a novice question. but i'l be glad if someone can provide a full simple working solution.Btw i've read the docs and downloaded the sample.i also have my storeproxy.xml file setup.

    but am less interested in testing via the simulator.I just want deploy ready code which i can include in my app and with a few tweaks post to the store

    THANKS!!


    Monday, March 4, 2013 10:00 PM

Answers

  • I think i finally got the first part of the code working.The major problemnow is that, i want to show the user the purchase dialog window with a custom buy button that enables the user purchase the full vrsion of my app.

    Here is my code

    $(document).ready(function () {
             $("#save").click(function () {
                 function appInit() {        
                currentApp = Windows.ApplicationModel.Store.CurrentApp;

                  
                 }

                 if (licenseInformation.productLicenses.lookup("Smileygramsave").isActive) {
                     var canvas = document.getElementById("myCanvas");
                     var now = document.getElementById('yusuf').innerHTML;
                     var den = now + '.png';
                     $('#myCanvas').click();
                     if (canvas.getContext) {
                         var ctx = canvas.getContext("2d");

                     }
                     var url = canvas.toDataURL("image/png");
                     var base64Data = url.replace("data:image/png;base64,", "");

                     var buffer = Windows.Security.Cryptography.CryptographicBuffer.decodeFromBase64String(base64Data);
                     var picLib = Windows.Storage.KnownFolders.picturesLibrary;

                     picLib.createFileAsync(den, Windows.Storage.CreationCollisionOption.replaceExisting).then(
                         function (file) {

                             return Windows.Storage.FileIO.writeBufferAsync(file, buffer);
                         }
                     ).done(
                         function () {
                             new Messi('Photo was saved successfully to your photo libary :)', { title: "<img src='/images/bar.png' width='150'/>" });
                         },
                         function (err) {
                             console.log("error: " + err);
                         }
                     );

                 }
                 else {
                     //Show purchase dialog with buy button.that enable the user to purchase the app
                 }
                
             });
         });






    Tuesday, March 5, 2013 5:27 AM

All replies

  • Hello,

    There is a sample that shows how you can use in-app purchases in Windows Store apps. The sample is here: http://code.msdn.microsoft.com/windowsapps/Licensing-API-Sample-19712f1a.

    Thanks,

    Prashant.

    Tuesday, March 5, 2013 2:12 AM
    Moderator
  • I think i finally got the first part of the code working.The major problemnow is that, i want to show the user the purchase dialog window with a custom buy button that enables the user purchase the full vrsion of my app.

    Here is my code

    $(document).ready(function () {
             $("#save").click(function () {
                 function appInit() {        
                currentApp = Windows.ApplicationModel.Store.CurrentApp;

                  
                 }

                 if (licenseInformation.productLicenses.lookup("Smileygramsave").isActive) {
                     var canvas = document.getElementById("myCanvas");
                     var now = document.getElementById('yusuf').innerHTML;
                     var den = now + '.png';
                     $('#myCanvas').click();
                     if (canvas.getContext) {
                         var ctx = canvas.getContext("2d");

                     }
                     var url = canvas.toDataURL("image/png");
                     var base64Data = url.replace("data:image/png;base64,", "");

                     var buffer = Windows.Security.Cryptography.CryptographicBuffer.decodeFromBase64String(base64Data);
                     var picLib = Windows.Storage.KnownFolders.picturesLibrary;

                     picLib.createFileAsync(den, Windows.Storage.CreationCollisionOption.replaceExisting).then(
                         function (file) {

                             return Windows.Storage.FileIO.writeBufferAsync(file, buffer);
                         }
                     ).done(
                         function () {
                             new Messi('Photo was saved successfully to your photo libary :)', { title: "<img src='/images/bar.png' width='150'/>" });
                         },
                         function (err) {
                             console.log("error: " + err);
                         }
                     );

                 }
                 else {
                     //Show purchase dialog with buy button.that enable the user to purchase the app
                 }
                
             });
         });






    Tuesday, March 5, 2013 5:27 AM