Correct steps after in-app purchase is successful
c#, microsoft-metro, windows-8
Solution
As far as I know it's not automatically updated when you click OK. It only returns the correct status like it should do in the Windows Store.
What I think is an option to do, but I haven't implemented it myself is to use `ReloadSimulatorAsync(proxyFile)` method. Before you call this method you have to update the in-app-purchase.xml yourself save it and pass the file to the ReloadSimulatorAsync method.
Personally I would use the manual update of the xml file. But I can't Judge about that for your application / application flow.
A good start for automating this process is the sample "In-app purchase" app which you can find here. If you look in the code file InAppPurchase.xaml.cs you will see already a bit of code for your own implementation.
Problem
I tried the following code for in-app purchase. I'm using `CurrentAppSimulator` for testing purpose. ``` private async void history_Click(object sender, RoutedEventArgs e) { bool OK = true; // Get the license info // The next line is commented out for testing. // licenseInformation = CurrentApp.LicenseInformation; // The next line is commented out for production/release. LicenseInformation licenseInformation = CurrentAppSimulator.LicenseInformation; if (!licenseInformation.ProductLicenses["PremiumFeatures"].IsActive) { try { // The customer doesn't own this feature, so // show the purchase dialog. await CurrentAppSimulator.RequestProductPurchaseAsync("PremiumFeatures", false); // the in-app purchase was successful OK = true; } catch (Exception) { // The in-app purchase was not completed because // an error occurred. OK = false; } } else { // The customer already owns this feature. OK = true; } if (OK) { Frame.Navigate(typeof(HistoryPage)); } } ``` However, the dialog keep pop up, every time I perform `history_Click`, even I choose S_OK. I expect `licenseInformation.ProductLicenses["PremiumFeatures"].IsActive` should changed to true, after I buy the `PremiumFeatures`. I guess, perhaps when the in-app purchase was successful, I need to turn on `IsActive` flag, so that it will not show me purchase dialog again. ``` // the in-app purchase was successful OK = true; // Compile error!!! licenseInformation.ProductLicenses["PremiumFeatures"].IsActive = true; ``` OK. Seems like `IsActive` is a read only field. So, may I know, what is the correct way to handle purchase successful case? Update : After looking at Trial app and in-app purchase sample, I realize having the following code can have `IsActive` changed from `false` to `true` automatically, after purchasing successful. (But why it works?) ``` private async Task LoadInAppPurchaseProxyFileAsync() { StorageFolder proxyDataFolder = await Package.Current.InstalledLocation.GetFolderAsync("data"); StorageFile proxyFile = await proxyDataFolder.GetFileAsync("in-app-purchase.xml"); licenseChangeHandler = new LicenseChangedEventHandler(InAppPurchaseRefreshScenario); CurrentAppSimulator.LicenseInformation.LicenseChanged += licenseChangeHandler; await CurrentAppSimulator.ReloadSimulatorAsync(proxyFile); // setup application upsell message ListingInformation listing = await CurrentAppSimulator.LoadListingInformationAsync(); var product1 = listing.ProductListings["product1"]; var product2 = listing.ProductListings["product2"]; Product1SellMessage.Text = "You can buy " + product1.Name + " for: " + product1.FormattedPrice + "."; Product2SellMessage.Text = "You can buy " + product2.Name + " for: " + product2.FormattedPrice + "."; } ``` However, the "Is already bought" status is not persistence. If I close the app and start it again, it will thought my "Premium Feature" to "is not bought yet". How am I suppose the make this behavior persistence?