question

R. G. Ubiquity avatar image
R. G. Ubiquity asked

IAP 2.0: getPrice() returns Price instance, not String?

According to the IAP API 2.0 docs [1] com.amazon.device.iap.model.Product.getPrice() returns a String. However in the JAR file it seems like it returns a Price object, which then has additional methods like getCurrency() and getValue(). This is fine if just a doc bug, but I now cannot see a way to get a formatted price like "$0.99" -- I tried toString() but it returns the JSON verbatim. [1] https://developer.amazon.com/public/apis/earn/in-app-purchasing/javadocs-v2/in-app-purchasing-2.0-api-reference
iap
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

wgasek avatar image
wgasek answered
I have noticed the same thing. How should I now format localized price string? I can simply concatenate price and currency, but the order depends on locale. Bad user experience is now a must :( Maybe amazon IAP2.0 developers could introduce some helper method to get properly localized price string?
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

wgasek avatar image
wgasek answered
Hi again. You can format price afterall. My first thought was, that Price class has string fileds (currency and value). But it has java.util.Currency and java.math.BigDecimal. Anyone can use java.text.NumberFormat to format price properly. More details here: http://stackoverflow.com/questions/7828364/formatting-currencies-in-foreign-locales-in-java However documentation about this should be updated. B.R. Wojciech
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

bfg-wb avatar image
bfg-wb answered
So is this "getCurrency" call actually supported? I don't see it documented in the docs, but I want to use it and be able to rely on it. Does anyone have any experience with this call reporting the correct currency? Also, in that same vein, has anyone been able to test using a currency other than USD? Thanks for any assistance.
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

DougM@Amazon avatar image
DougM@Amazon answered
Hello bfg_wb, To answer your question, there is not a call to get the specific currency of a price. Under the UserData class there will be a string-valued function, getMarketplace() this will return wo character Alpha-2 code of ISO_3166-1 and one could use that to potentially determine what currency the price string will be in. The In-App item JSON file will actually omit the currency symbol such that you can insert a currency symbol of your choice into the price string when using it with the Amazon App Tester. As another note, the price out of the com.amazon.device.iap.model.Product 's getPrice() method really does return a java.lang.String .
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

dimanem avatar image
dimanem answered
Hi Doug, Couple of questions: 1. So the only way to get the currency code of an SKU is to keep track of getUserData().getMarketplace()? And how am i supposed to get the currency code from the marketPlace string? 2. What should be the full price format in the JSON? Something like USD10.99 / $10.99?
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

DougM@Amazon avatar image
DougM@Amazon answered
Hello dimanem, To answer your questions: The only way to get the currency code would be to infer it by using getUserData().getMarketplace(), since this is a user-based setting it would be applicable for all SKUs within the user's session of your app. So, you would get the US code rather than the USD currency code. The full price in the JSON file should be $10.99 for testing in currencies that would use the dollar symbol.
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.