Missing currencyCode in StoreKit2

Anyone knows if there is a good reason why StoreKit2 In App Purchase Product and Transaction objects do not contain a complete price with a priceLocale or a currencyCode?

I understand that we are supposed to use the preformatted displayPrice for user-facing labels. However for the app that we are working on we really need to know the currencyCode or priceLocale for accounting purposes otherwise there is really no way to know how much the user actually paid for the purchase.

Note: I know that App Store Connect API provides detailed financial reports, but our use case requires this information on the app-side.

  • Update: For the moment we are able to solve this issue by using a SKProductRequest.. SKProduct includes the priceLocale which is what we need. I hope StoreKit 2 can include this information as well in the future.

  • Update: It was announced in WWDC 2022 that the priceLocale would be reintroduced in Product. However the latest version of the beta SDK (Xcode 14.0 beta 2) does not contain it. A reference to a currency formatter style is introduced instead, with var priceFormatStyle: Decimal.FormatStyle.Currency which should allow formatting calculated user-facing strings.

Add a Comment

Replies

Hey you can you displayPrice will give you the price with local currency symbol. use product.displayPrice And you want to know user's App Store Account currencyCode you can find that from

        if let storeFront = SKPaymentQueue.default().storefront {             print(storeFront.countryCode) }

Thanks but these do not really answer the problem.

First, displayPrice is a String. We can not realistically parse that string and get back a numeric price value, even if we know the currency code.

Second, storeFront.countryCode gives a country code. Country code and currency code are two entirely different things.

You can also get currency code but with one trick for now: let price = product.price.formatted() // give you price in string let displayPrice = product.displayPrice let currencySymbol = displayPrice.replacingOccurrences(of: price, with: "")

We are using this quick fix for now. Until apple provide any proper solution. Hope will love your problem.

  • I suggest refraining from string parsing tricks if you do not want to have unexpected results at a locale where price strings are not formatted in an expected manner.

    SkProduct.priceLocale.currencyCode is the way to go. But that is present in StoreKit only and not present in StoreKit2.

    Our first solution was to explicitly decode the JSON payload StoreKit2 is sending and fetching the currency code from there. This data was eventually removed from the JSON.

    Our current solution is to mix the StoreKit and StoreKit2 and blend the data. It is quite ugly since the whole point of StoreKit2 is to provide an elegant API. But I would argue this is a safer solution compared to what you suggested.

    TLDR: Apple should provide currencyCode and/or priceLocale in Product.

  • This is a bad idea. You assume that there is a 1:1 mapping of currency symbols and currencies. That is wrong. For example $ could be USD or Mexican Peso or Chilean Peso, etc

Add a Comment

You can now use product.priceFormatStyle.currencyCode.