In-App purchase is showing different currency symbol for some countries

587 Views Asked by At

This is my code for getting the local price and currency symbol.

private func getLocalCurrencyAndPrice(from product: SKProduct) -> (currency: String, price: Double) {
    //Get the currency
    let numberFormatter = NumberFormatter()
    numberFormatter.numberStyle = .currency
    numberFormatter.locale = product.priceLocale
    let priceString = numberFormatter.string(from: 0)
    let currencyString = ((priceString?.replacingOccurrences(of: "0", with: ""))?.replacingOccurrences(of: ".", with: ""))?.replacingOccurrences(of: ",", with: "")
    let trimmedCurrency = currencyString?.trimmingCharacters(in: .whitespacesAndNewlines)
    
    //Get the price
    let price = (product.price.doubleValue).roundToDecimal(2)
    return (currency: trimmedCurrency ?? "", price: price)
}

And this is how I am getting separate values:

let currency = getLocalCurrencyAndPrice(from: product).currency
let price = getLocalCurrencyAndPrice(from: product).price

I have created sandbox users for different App Store regions from the App Store Connect. It shows almost all regional prices and currency symbols perfectly except for Indonesia, Taiwan & Korea.

For Indonesia, on the "App Store Connect" It is showing Rp as their currency symbol: (Please ignore the differences in currency amount for now for all 3 countries)

enter image description here

But on the application, it is showing IDR:

enter image description here

For Taiwan, on the "App Store Connect" & on the application, It is showing $ as their currency symbol:

enter image description here

But on the "Settings > App Store > Sandbox User > Manage" & "Purchase Pop-Up view", it is showing NT$ as their currency symbol:

enter image description here

For Korea, on the "App Store Connect", "Settings > App Store > Sandbox User > Manage" & "Purchase Pop-Up view", It is showing as their currency symbol:

enter image description here

But on the application, it is showing with a double line:

enter image description here

Why these mismatches are showing while I am getting the value from the same source? What have I done wrongly?

1

There are 1 best solutions below

0
Abdullah On

You can try following code. It has the solution of your specific problems i.e. for Indonesia, Taiwan and Korea, the method will return expected currency code. However this method has also some issue with currency code for some other countries like Pakistan.

func getSymbolForCurrencyCode(code: String) -> String {
    var candidates: [String] = []
    let locales: [String] = NSLocale.availableLocaleIdentifiers
    for localeID in locales {
        guard let symbol = findMatchingSymbol(localeID: localeID, currencyCode: code) else {
            continue
        }
        if symbol.count == 1 {
            return symbol
        }
        candidates.append(symbol)
    }
    return candidates[0]
}

func findMatchingSymbol(localeID: String, currencyCode: String) -> String? {
    let locale = Locale(identifier: localeID as String)
    if code != currencyCode {
        return nil
    }
    guard let symbol = locale.currencySymbol else {
        return nil


    }
    return symbol
}

Usage

let idr = getSymbolForCurrencyCode(code: "IDR")