Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Modifying localized prices

Discussion in 'Unity IAP' started by Swah, Nov 11, 2021.

  1. Swah

    Swah

    Joined:
    May 13, 2015
    Posts:
    80
    Hello,

    We've got an auto renewable app with a monthly and a yearly option. We can easily display the $/month and $/year localized price with metadata.localizedPriceString. Our problem is that we also need to show how both plans end up on a monthly basis. This means we need to convert the yearly plan from 34.99$/year to 2.92$/month.

    Options we've explored so far without success:
    - create a fake IAP on the stores just to get Unity IAP to give us that localized price. The value won't be exact though, since we need to choose between preset prices.
    - we can't hard code strings per locale. Prices can change over time, and the same price in the same country can be shown in different ways (34,99 $ VS $34.99).
    - we can't use the localizedPriceString and substitute numbers in it, because again different locales show numbers differently so we would need really sophisticated code to understand all possible variations.

    Are we missing an easier way to do this? It'd be great if we could send a decimal to Unity IAP (calculated from metadata.localizedPrice), and have Unity convert it into a localized price string. This could be an easy thing to do for Unity if it is the one doing this conversion in the first place, but I'm not sure if it gets these strings directly from stores or if it handles localization locally.
     
  2. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    We receive the values through the store API's, not locally in code. You would want two separate IAP products, one monthly and one yearly.
     
  3. Swah

    Swah

    Joined:
    May 13, 2015
    Posts:
    80
    Thanks for the quick answer @JeffDUnity3D . That is what I feared - it means there's no way to easily reconstruct the localized prices then. We already have two IAP products for monthly / yearly. We could create another dud monthly plan just to display that reduced localized monthly price, but it wouldn't be exact because the platforms force us to select predefined pricing tiers. It sounds like there's no easy way to do what we want at the moment.
     
  4. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    Can't you just divide the yearly localized price by 12? I might be missing something.
     
  5. Swah

    Swah

    Joined:
    May 13, 2015
    Posts:
    80
    @JeffDUnity3D we can't as far as I know. We have access to metadata.localizedPriceString, which is a string like "34,99 $". We can't easily replace numbers in this kind of string, because of how widely different localize strings look in other countries. In India for example, numbers are shown as "20.000,00" - we'd need to have code that understands all of these variations before we can modify these strings.

    We also have access to metadata.localizedPrice, which is a decimal that we can divide by 12. But then we can't transform that into a localized string that makes sense in all countries. We could just use that decimal and add the currency symbol next to it, but that is not what metadata.localizedPriceString does - there are many variations again, with the currency symbol being on different sides, etc. This means we'd need to display all prices using the metadata.localizedPrice+symbol method, and it wouldn't even look proper for many locales.

    Does this make sense?
     
  6. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    You wouldn't use string methods. Just convert the string to a number and divide? I would think that there would be culture invariant methods to do so. Unfortunately I would not have specifics, you might want to ask in the Scripting forum (don't mention IAP, you might get redirected!)
     
  7. Swah

    Swah

    Joined:
    May 13, 2015
    Posts:
    80
    @JeffDUnity3D I think I understand the miscommunication. The problem isn't to calculate the rebated price / month - as you point out we can either convert the string to a number or just use metadata.localizedPrice directly.

    The problem is that we can't display the resulting price back to users in a way that is consistent with what metadata.localizedPriceString shows. Once our code determines that the equivalent price per month is say $4.49 / month, we don't know how to display that number. It could be $4.49, or 4,49$, or (for other currencies) 2 490,00 ₽,
    CHF 28.00, etc. We don't have access to code that knows all of these variations, and can't easily substitute the number in metadata.localizedPriceString either.
     
    spider853 likes this.
  8. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    Yes, I suspect there are invariant methods that will properly convert the string to a (localized) numeric. You don't need to care or know what country/culture where the user is located.
     
  9. Swah

    Swah

    Joined:
    May 13, 2015
    Posts:
    80
    Interesting - it does look like there are string methods we can use for this. We'll need to make sure these work properly on all platforms. Thanks for your help, I'll post back here if the tests are inconclusive.
     
  10. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    You are welcome! Please keep us posted, It's an interesting problem. It would be great if the store API's themselves provided such a method, it seems like a very good selling point.
     
  11. Swah

    Swah

    Joined:
    May 13, 2015
    Posts:
    80
    Agreed, it would help. Using this method also means that we'll need to display all of our prices using it, because we would otherwise risk having differences between the platform's method and ours.
     
  12. spider853

    spider853

    Joined:
    Feb 16, 2018
    Posts:
    36
    Looking for the best solution for a similar problem, what did you ended up with?