First I use my own class CurrentAppProxy, which uses CurrentAppSimulator in Debug mode and CurrentApp in Release. Then I use this code to purchase an InApp purchase, it works fine:
try { await CurrentAppProxy.RequestProductPurchaseAsync(PremiumName, false); // after closing the inApp purchase dialog, test, if it was bought if (licenseInformation.ProductLicenses[PremiumName].IsActive) { // set the local flag IsPremium = true; dialog = new MessageDialog(resourceLoader.GetString("ThanksForPremium")); await dialog.ShowAsync(); } // else do not show anything } catch (Exception) { // failed buying the premium dialog = new MessageDialog(resourceLoader.GetString("ErrorBuyingPremium")); dialog.ShowAsync(); }
edit: before accessing these properties, I initialize CurrentAppSimulator in debug mode using this:
StorageFolder proxyDataFolder = await Package.Current.InstalledLocation.GetFolderAsync("Assets"); StorageFile proxyFile = await proxyDataFolder.GetFileAsync("test-purchase.xml"); await CurrentAppSimulator.ReloadSimulatorAsync(proxyFile);
and below test-purchase.xml I got:
<LicenseInformation> <App> <IsActive>true</IsActive> <IsTrial>false</IsTrial> </App> <Product ProductId="premium"> <IsActive>false</IsActive> </Product> </LicenseInformation>
source share