Does anyone now how to get the price of an in-app purchase / product from the windows store? I've read all the documentation I could find on in-app purchases and I can't see a way
I've got a CurrentApp
object which contains LicenseInformation
and a LinkURI
. The latter is a link to the store so I could scrape the info from there using a HttpRequest but that seems like an awfully ugly hack
Does anyone know how to do what I'm trying to do?
Obtaining a list of in-app purchases is done through CurrentApp.loadListingInformationAsync, which gives you the app’s ListingInformation. From there, its productListings collection contains all of the in-app purchases you’ve registered through the Store dashboard, regardless of type (consumable, durable, etc.) This collection is a MapView of ProductListing objects, in which you'll find the formattedPrice that's suitable for display in your UI.
Note that the MapView doesn't support indexed lookup. You can use its lookup method using the product ID, or you can iterate the MapView using this code:
var iterator = listing.productListings.first()
var product;
while (iterator.hasCurrent) {
product = iterator.current.value;
// Use product.productId, name, formattedPrice, and productType to generate your UI.
iterator.moveNext();
};
Be aware that the numerical value of the price isn't included because it really doesn't make much sense for the app to try using it in calculations--the prices can be set independently for different locales with different currencies. That's why the API gives you a formatted price--already localized--so you can just display it in your UI without any additional manipulation.
If you need numerical values, then you'd have to provide that information to your app some other way, e.g. a file built into the package or a web service of your own.
I cover all the details of in-app purchases in Chapter 20 of my free ebook, Programming Windows Store Apps with HTML, CSS, and JavaScript, 2nd Edition.