diff --git a/payments-core/src/main/java/com/stripe/android/PayWithGoogleUtils.kt b/payments-core/src/main/java/com/stripe/android/PayWithGoogleUtils.kt index c60f9ecd6c4..e4888468a63 100644 --- a/payments-core/src/main/java/com/stripe/android/PayWithGoogleUtils.kt +++ b/payments-core/src/main/java/com/stripe/android/PayWithGoogleUtils.kt @@ -3,6 +3,7 @@ package com.stripe.android import java.text.DecimalFormat import java.text.DecimalFormatSymbols import java.util.Currency +import java.util.Locale import kotlin.math.pow /** @@ -27,7 +28,8 @@ object PayWithGoogleUtils { for (i in 0 until totalLength) { builder.append('#') } - val noDecimalCurrencyFormat = DecimalFormat(builder.toString()) + val noDecimalCurrencyFormat = + DecimalFormat(builder.toString(), DecimalFormatSymbols.getInstance(Locale.ROOT)) noDecimalCurrencyFormat.currency = currency noDecimalCurrencyFormat.isGroupingUsed = false return noDecimalCurrencyFormat.format(price) @@ -49,9 +51,9 @@ object PayWithGoogleUtils { val modBreak = 10.0.pow(fractionDigits.toDouble()) val decimalPrice = price / modBreak - // No matter the Locale, Android Pay requires a dot for the decimal separator. - val symbolOverride = DecimalFormatSymbols() - symbolOverride.decimalSeparator = '.' + // No matter the Locale, Android Pay requires a dot for the decimal separator, and Arabic + // numbers. + val symbolOverride = DecimalFormatSymbols.getInstance(Locale.ROOT) val decimalFormat = DecimalFormat(builder.toString(), symbolOverride) decimalFormat.currency = currency decimalFormat.isGroupingUsed = false diff --git a/payments-core/src/test/java/com/stripe/android/PayWithGoogleUtilsTest.kt b/payments-core/src/test/java/com/stripe/android/PayWithGoogleUtilsTest.kt index d90d0058643..4de1e4c848e 100644 --- a/payments-core/src/test/java/com/stripe/android/PayWithGoogleUtilsTest.kt +++ b/payments-core/src/test/java/com/stripe/android/PayWithGoogleUtilsTest.kt @@ -53,4 +53,17 @@ class PayWithGoogleUtilsTest { val littlePrice = getPriceString(7, Currency.getInstance("CLP")) assertThat(littlePrice).isEqualTo("7") } + + @Test + fun getPriceString_whenLocaleWithArabicNumerals_returnsExpectedValue() { + Locale.setDefault(Locale.Builder().setLanguage("ar").setRegion("AE").build()) + val priceString = getPriceString(100, Currency.getInstance("USD")) + assertThat(priceString).isEqualTo("1.00") + + val littlePrice = getPriceString(8, Currency.getInstance("EUR")) + assertThat(littlePrice).isEqualTo("0.08") + + val bigPrice = getPriceString(20000000, Currency.getInstance("GBP")) + assertThat(bigPrice).isEqualTo("200000.00") + } }