locked
how to handle in-app purchase simulated calls?

    Question

  • i had implemented in-app purchase in my windows 8 app built with html & js, now when i am running it on my pc through visual studio i get a window prompt with 2 buttons "continue" & "cancel", if i click continue then the purchase is made successfully & my in-app offer enabling code is executed, now my question is when i click cancel button still my in-app offer enabling code is executed, do i need any additional code to handle the "cancel" button click event??  
    Friday, July 25, 2014 12:39 PM

Answers

  • Double check this: licenseInformation.productLicenses.lookup("featureName").isActive

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    • Marked as answer by kranthi88 Wednesday, July 30, 2014 7:45 AM
    Wednesday, July 30, 2014 5:51 AM
    Moderator

All replies

  • after a little bit of trial & error i found that we need to add code to manage the "cancel" button clicked event through the below function in js

    currentapp.requestAppPurchaseAsync("fullversion", false).done(
                                function () {
                                    var mym = Windows.UI.Popups.MessageDialog("You canceled the purchase");
                                    mym.showAsync();
                                });
    • Marked as answer by kranthi88 Sunday, July 27, 2014 8:29 AM
    • Unmarked as answer by kranthi88 Monday, July 28, 2014 5:41 AM
    Sunday, July 27, 2014 8:29 AM
  • Correct, you have to attach a event handler while your cancel button clicked.


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    • Marked as answer by kranthi88 Monday, July 28, 2014 5:05 AM
    • Unmarked as answer by kranthi88 Monday, July 28, 2014 5:39 AM
    Monday, July 28, 2014 1:26 AM
    Moderator
  • i thought my code worked correctly but now i am facing another strange issue, i am getting purchase simulation twice, my code is below, can u please review it & suggest any mistake regarding "cancel" button eventhandler declaration

     function getfull() {
                var currentapp = Windows.ApplicationModel.Store.CurrentAppSimulator;
                var licenseinfo = currentapp.licenseInformation;
                if (!licenseinfo.productLicenses.lookup("fullversion").isActive) {

                    //code to handle "cancel" button click event
                   currentapp.requestAppPurchaseAsync("fullversion", false).done(
                                function () {
                                    var mym = Windows.UI.Popups.MessageDialog("u canceled the purchase");
                                    mym.showAsync();
                                });           

                      // code to handle purchase continue event 
                    currentapp.requestAppPurchaseAsync("fullversion", true).done(
                        function (reciept) {
                                //code to delete ads
                                $("#adunit1").remove();
                                $("#adunit2").remove();
                                $("#adunit3").remove();
                                $("#adunit4").remove();
                        }, errorhandler);
                    function errorhandler() {
                        var msg = Windows.UI.Popups.MessageDialog("Oops!! Something went wrong, please try again");
                        msg.showAsync();
                    }
                }
                else {
                    //code to show that user has already bought the feauture of fullversion
                    $("#adunit1").remove();
                    $("#adunit2").remove();
                    $("#adunit3").remove();
                    $("#adunit4").remove();
                    var confirm = Windows.UI.Popups.MessageDialog("U already bought the Ad-free version");
                    confirm.showAsync();
                }
            }

    Monday, July 28, 2014 5:38 AM
  • Hi kranthi88,

    If you are working with win8.1 app, CurrentApp.RequestProductPurchaseAsync | requestProductPurchaseAsync method is not available, but use RequestProductPurchaseAsync(productId) instead.

    And take a look at the documentation of this method, see the return value section:

    A string providing in-app transaction details for the provided productId. If includeReceipt is set true, the returned string will include a full receipt xml.

    No matter if your client purchase or not purchase your product, both events will be fired.

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Monday, July 28, 2014 8:39 AM
    Moderator
  • i am working with windows 8 app jamles (not 8.1), if both events are fired then how can i manage "cancel" button event in my code?
    • Edited by kranthi88 Monday, July 28, 2014 9:02 AM
    Monday, July 28, 2014 8:54 AM
  • Can you do something like:

        currentapp.requestAppPurchaseAsync("fullversion", true).done(
                 function () {
                     // to determine if the purchase is succeed here by if statement. 
                     if (...reciept.false...) {
                         var mym = Windows.UI.Popups.MessageDialog("u canceled the purchase");
                         mym.showAsync();
                     }
                     else {
                         $("#adunit1").remove();
                         $("#adunit2").remove();
                         $("#adunit3").remove();
                         $("#adunit4").remove();
                     },errorhandler
    
                 });  

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Monday, July 28, 2014 9:04 AM
    Moderator
  • i am not getting any reciept.false in my intellisense, can u elaborate this please 
    (...reciept.false...)
    Monday, July 28, 2014 9:42 AM
  • Hi kranthi88,

    Sorry my mistake, I tested the code with win8.1 but I did not recognize until you reply me.

    Here, let's go through the documentation: Enable in-app purchases from your app

    And you are working with in-app purchase, so probably requestAppPurchaseAsync() is not the correct one you should use. This API is used to enable user to buy full license for the current app.

    I think in your app, user can do a in-app purchase to disable the Ads, for this reason, we should look at the product information instead of app purchase.

    You may need use following code

            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 () {
                        $("#adunit1").remove();
                        $("#adunit2").remove();
                        $("#adunit3").remove();
                        $("#adunit4").remove();
                        //Check the license state to determine if the in-app purchase was successful.
                    },
                    function () {
                        var mym = Windows.UI.Popups.MessageDialog("u canceled the purchase");
                        mym.showAsync();
                        // The in-app purchase was not completed because 
                        // there was an error.
                    });
            }
            else {
                // The customer already owns this feature.
            }

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Tuesday, July 29, 2014 2:52 AM
    Moderator
  • thanx jamles your code is working fine but, how do i determine if the in-app purchase was successfull or not ??
    Tuesday, July 29, 2014 3:22 AM
  • Double check this: licenseInformation.productLicenses.lookup("featureName").isActive

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    • Marked as answer by kranthi88 Wednesday, July 30, 2014 7:45 AM
    Wednesday, July 30, 2014 5:51 AM
    Moderator
  • thanx jamles , its working fine now 
    Wednesday, July 30, 2014 7:44 AM