I have got everything to work well with the unity 5.3 in app purchase system, however I cant find a way to localize the price of my in app products in my store. On my button “buy sword” I want the price to be showed in the local currency. As it is now, the user has to click the button to see that (the android/apple pawment UI pops up with the localized price). Thats not very good user experience… So, how do I fix this? Do I have to buy a plugin? Wich one is best? // Erik
copy paste solution for everyone that finds this
add this to your IAPPurchauser.cs
public string GetPrice(string productID)
{
if (m_StoreController == null) InitializePurchasing();
return m_StoreController.products.WithID(productID).metadata.localizedPriceString;
}
in the editor it will show “$0.01” but on a device it will show up.
I’ve not used the Unity IAP system but it looks like this is what you’re after:
All you need to do is update the text on the button at an appropriate time (i.e. don’t hard-code it).
Keep in mind that this probably won’t work in the editor as the prices actually rely on the information being returned from Apple / Google, and this may not be possible within the editor. Basically, build to a device to test.
Bear in mind that if using a bitmap font it most likely won’t have all the currency symbols available.
A more reliable way to show currencies correctly is by using the ISO currency code, i.e USD instead of $.
Here is a method you can use to display any currency from your Unity IAP script.
public string GetPriceInIsoFormat(string productId)
{
return ProductCollection.WithID(productId).metadata.localizedPrice + " " + ProductCollection.WithID(productId).metadata.isoCurrencyCode;
}
//For localisation currency according to the country.
public static string GetProductPriceFromStore(string id)
{
if (m_StoreController != null && m_StoreController.products != null)
return m_StoreController.products.WithID(id).metadata.localizedPriceString;
else
return "";
}