How to get separate price and currency information for an in-app purchase?

Panda Pajama picture Panda Pajama · Jun 11, 2013 · Viewed 20.4k times · Source

I am implementing in-app purchases for an app with support for several countries.

The In-App Billing Version 3 API claims that:

No currency conversion or formatting is necessary: prices are reported in the user's currency and formatted according to their locale.

This is actually true, since skuGetDetails() takes care of all necessary formatting. The response includes a field called price, which contains the

Formatted price of the item, including its currency sign. The price does not include tax.

However, I need the ISO 4217 currency code (retrievable if I know the store locale) and the actual non-formatted price (optimally in a float or decimal variable) so I can do further processing and analysis myself.

Parsing the return of skuGetDetails() is not a reliable idea, because many countries share the same currency symbols.

Currencies

How can I get the ISO 4217 currency code and non-formatted price of an in-app purchase with the In-App Billing Version 3 API?

Answer

Steven Craft picture Steven Craft · Apr 8, 2015

Full information can be found here, but essentially in August 2014 this was resolved with:

The getSkuDetails() method

This method returns product details for a list of product IDs. In the response Bundle sent by Google Play, the query results are stored in a String ArrayList mapped to the DETAILS_LIST key. Each String in the details list contains product details for a single product in JSON format. The fields in the JSON string with the product details are summarized below

price_currency_code ISO 4217 currency code for price. For example, if price is specified in British pounds sterling, price_currency_code is "GBP".

price_amount_micros Price in micro-units, where 1,000,000 micro-units equal one unit of the currency. For example, if price is "€7.99", price_amount_micros is "7990000".