Purchase Simulation CurrentAppSimulator.RequestProductPurchaseAsync

I’m trying to make an in-app purchase for my Windows Store app (Metro app). I meant code samples here , but when I called the RequestProductPurchaseAsync method, nothing happens.

When I say that nothing happens, it literally means nothing. There are no return results (the result should have been a receipt since I passed in true for includeReceipt ). Also, when I re-checked the ProductLicences[string].IsActive , it will always return false to me.

How to check it right? Many thanks!

+2
source share
3 answers

Make sure the LicenseInformation.IsTrial application is set to false, otherwise it will not work. In-app purchases require the app to fail verification. In the published application, the user will see an error stating that you cannot make in-app purchases in the trial license. The simulator does not show this warning in the dialog box for modeling the purchase of an application during testing.

You can either change the initial state of the simulation (see examples for how to do this), or call RequestAppPurchaseAsync (false) during the simulation run to get the full license for the application, and then try to buy the product.

+10
source

We experienced and solved a similar problem. Using CurrentAppSimulator worked fine, but it didn't happen to create a real user interface for purchasing CurrentApp .

In the production setup, the wait for CurrentApp.RequestProductPurchaseAsync (string, bool) seemed to never return (more specifically, it returns only once after the user logs in - subsequent calls are not returned).

In addition, after we tried to identify the user interface for purchases in our application, other applications using the user interface for purchases had the same problem - the user interface is never displayed.

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 } 

A somewhat obvious problem with the above code is that the request to open the user interface for in-app purchase is made from the command handler of the modal dialog box. Request freezes - never returns. The not so obvious part is that it also blocks all subsequent requests from our application and any other application (until the user session is restarted).

After moving the "try" block from the command handler and ensuring that there are no modal user interface calls that challenge the purchase request, the purchase works without problems.

EDIT: you must restart (or re-enter) to verify this. As soon as the user interface is violated, it will not be displayed until you restart or log in.

+4
source

There is a small nuance: to be able to purchase something using CurrentAppSimulator , you need to call CurrentAppSimulator.RequestAppPurchaseAsync before making any purchase requests. After the operation CurrentAppSimulator.RequestProductPurchaseAsync by the call completes, you can successfully call CurrentAppSimulator.RequestProductPurchaseAsync (if the IsTrial value in the LicenseInformation element is not set to xml).

0
source

All Articles