Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show two decimal places for Serbian Dinar #7316

Merged
merged 3 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* [ADDED][7302](https://github.com/stripe/stripe-android/pull/7302) PaymentSheet now supports Alma for PaymentIntents in private beta.
* [ADDED][7191](https://github.com/stripe/stripe-android/pull/7191) `PaymentSheet.GooglePayConfiguration` now takes an optional `amount` and `label`. The `amount` will be displayed in Google Pay for SetupIntents, while `label` will be displayed for both PaymentIntents and SetupIntents.
* [ADDED][7308](https://github.com/stripe/stripe-android/pull/7308) PaymentSheet now supports Konbini for PaymentIntents.
* [FIXED][7316](https://github.com/stripe/stripe-android/pull/7316) Fixed an issue where amounts in Serbian Dinar were displayed incorrectly.

### Payments
* [ADDED][7191](https://github.com/stripe/stripe-android/pull/7191) `GooglePayLauncher` now takes an optional `label` when presenting Google Pay for PaymentIntents, and an optional `amount` and `label` when presenting for SetupIntents.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import kotlin.math.pow
object CurrencyFormatter {

private const val MAJOR_UNIT_BASE = 10.0

private val SERVER_DECIMAL_DIGITS = mapOf(
setOf("UGX", "AFN", "ALL", "AMD", "COP", "IDR", "ISK", "PKR", "LBP", "MMK", "LAK") to 2,
setOf("UGX", "AFN", "ALL", "AMD", "COP", "IDR", "ISK", "PKR", "LBP", "MMK", "LAK", "RSD") to 2,
)

fun format(
Expand All @@ -31,8 +32,7 @@ object CurrencyFormatter {
targetLocale: Locale = Locale.getDefault()
): String {
val amountCurrencyDecimalDigits = getDefaultDecimalDigits(amountCurrency)
val majorUnitAmount =
amount / MAJOR_UNIT_BASE.pow(amountCurrencyDecimalDigits.toDouble())
val majorUnitAmount = amount / MAJOR_UNIT_BASE.pow(amountCurrencyDecimalDigits.toDouble())

/**
* The currencyFormat for a country and region specifies many things including:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ class CurrencyFormatterTest {
assertThat(
CurrencyFormatter.format(
123412L,
Currency.getInstance("USD")
Currency.getInstance("USD"),
Locale.US,
)
).isEqualTo("$1,234.12")
}
Expand Down Expand Up @@ -236,6 +237,13 @@ class CurrencyFormatterTest {
assertThat(formattedAmount).isEqualTo("LAK50.99")
}

@Test
fun `Treats RSD as a two-decimal currency`() {
val currency = Currency.getInstance("RSD")
val formattedAmount = CurrencyFormatter.format(5099L, currency)
assertThat(formattedAmount).isEqualTo("RSD50.99")
}

companion object {
val LOCALE_ICELAND_LANGUAGE_ONLY = Locale("IS")
val LOCALE_AUSTRALIA_LANGUAGE_COUNTRY = Locale("en-AU", "AU")
Expand Down