2

I am trying to implement in-app purchase for my Windows Store App (Metro App). I was referring to the code samples here, but when I triggered the RequestProductPurchaseAsync method nothing happens.

When I say nothing happens, it means literally nothing. No return results (the result was supposed to be a receipt since I passed in true for includeReceipt). Also, when I re-checked the ProductLicences[string].IsActive flag it will always return me false.

How do I test this out properly? Thanks a lot!

3 Answers 3

10

Make sure the app LicenseInformation.IsTrial is false, otherwise it won't work. In-app product purchases require that the app not be in trial. In a published app, the user would see an error stating that you can't do in-app product purchases under trial license. The simulator doesn't show this warning in the in-app purchase simulation dialog during testing.

You can either modify the initial state of the simulation (see the samples for how to do that) or call RequestAppPurchaseAsync(false) during the simulation run to get a full license for the app, then try the product purchase.

1
  • To get it to work I had to set both IsActive and IsTrial in the WindowsStoreProxy.xml file to true. If IsActive was false then it wouldn't work.
    – Grant
    Dec 4, 2012 at 16:08
4

We experienced and solved a similar problem. Using CurrentAppSimulator worked fine, but bringing up the real purchasing UI with CurrentApp did not.

In a production setting await CurrentApp.RequestProductPurchaseAsync(string,bool) seemed to never return (more specifically, it only returns once after the user has logged in -- subsequent calls did not return).

Additionally, after we tried to bring up the purchasing UI in our app, other applications using the purchasing UI had the same problem -- UI never shows.

Here is the problem code:

    private async void CommandInvokedHandler(IUICommand command)
    {
        switch (command.Label)
        {
            case "Continue":

                licenseInformation = CurrentApp.LicenseInformation;

                if (!licenseInformation.ProductLicenses[Notes.ProductName].IsActive)
                {
                    try
                    {
                        await CurrentApp.RequestProductPurchaseAsync(Notes.ProductName, false);
                        // The code never steps over
                    }

The somewhat-obvious problem with the code above is that the request to bring up the in-app purchase UI is made from within a modal dialog box command handler. The request hangs -- never returns. The not-so-obvious part is that it also blocks all subsequent requests from our application and every other application (until the user's session is restarted).

Upon moving the "try" block out of the command handler, and ensuring that there are no modal UI calls contesting the purchase request, purchasing worked without issue.

EDIT: You should restart (or re-login) to test this. Once the purchasing UI breaks, it will not show until you restart or re-login.

1
  • Thank you. Using a custom modal dialog box was the culprit found out per your answer.
    – Hong
    Dec 16, 2013 at 16:45
0

There is a small nuance to follow: to be able to purchase anything using CurrentAppSimulator one needs to call CurrentAppSimulator.RequestAppPurchaseAsync before making any purchase requests. After the operation returned by the call is done, you can successfully call CurrentAppSimulator.RequestProductPurchaseAsync (unless the IsTrial value in LicenseInformation element is set to false in the xml).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.