Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the currency of an in-app purchase product on Windows Phone 8?

To track in-app purchases made with our Windows Phone 8 applications, we would like to know in which currency the purchases are made from inside the application. Right now we know the price using the FormattedPrice property, like so:

public static async void LoadProductListing()
{
    ListingInformation listings = await CurrentApp.LoadListingInformationAsync();
    ProductListing product = listings.ProductListings["SomeProductID"];

    String price = product.FormattedPrice;
}

This results in a price formatted with only a sign like €0,99 or $0.99. For this is fine, for e.g. $ this is not enough information: we still don't know whether it's US dollar, Canadian dollar, Australian dollar, or Chilean Peso (which sign is also $). We would like to have this information with a proper ISO 4217 currency code (like EUR, USD, CAD, AUD, CLP) or at least a symbol that explains the exact currency (like US$, C$, etc).

On Windows 8 it is possible to use the ListingInformation.CurrentMarket property to get the locale of the current market (and thus the currency used), however there is a remark in the documentation:

Windows Phone 8
This API is not implemented and will throw an exception if called.

We recon using the system locale is not precise enough: it might not be the same as the locale used for the current market (but we could be wrong there!).

Is there any way to properly determine the in-app purchase currency from within a Windows Phone 8 application?

like image 442
Arne Avatar asked Jan 03 '13 15:01

Arne


1 Answers

WP8 uses your Live ID payment profile region to select the market the phone uses and you cannot change this via a setting on the phone. I only happen to know this because my payment profile is set to Canada somehow (I'm from the US) and I am unable to change this via a setting on the phone.

However, back to the original question: your phone will always report the culture being used for in app purchases via System.Globalization.RegionInfo.CurrentRegion. Therefore, you can reliably get the correct currency code being used for in app purchases from:

var regionInfo = System.Globalization.RegionInfo.CurrentRegion;
var currencyCode = regionInfo.ISOCurrencySymbol;
like image 160
Tim Greenfield Avatar answered Sep 23 '22 11:09

Tim Greenfield