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

Don't filter countries when they're not supported from Locale.getISOCountries on older Android versions. #6611

Merged
merged 4 commits into from
Apr 27, 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 @@ -5,6 +5,7 @@
### All SDKs
* [CHANGED][6608](https://github.com/stripe/stripe-android/pull/6608) Added a `stripe` prefix to our string resources to avoid name conflicts.
* [FIXED][6602](https://github.com/stripe/stripe-android/pull/6602) Fixed an issue which caused a compiler error (duplicate class) when including payments *and* identity SDKs.
* [FIXED][6611](https://github.com/stripe/stripe-android/pull/6611) Fixed an issue where countries might be filtered out on old Android versions (notably Kosovo).

## 20.24.0 - 2023-04-24

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.stripe.android.ui.core.elements

import androidx.annotation.RestrictTo
import com.stripe.android.core.model.CountryUtils
import com.stripe.android.ui.core.R
import com.stripe.android.uicore.address.AddressRepository
import com.stripe.android.uicore.elements.AddressElement
Expand All @@ -12,7 +13,6 @@ import com.stripe.android.uicore.elements.IdentifierSpec
import com.stripe.android.uicore.elements.SameAsShippingController
import com.stripe.android.uicore.elements.SameAsShippingElement
import com.stripe.android.uicore.elements.SectionElement
import com.stripe.android.uicore.elements.supportedBillingCountries
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.Transient
Expand All @@ -30,7 +30,7 @@ data class AddressSpec(
override val apiPath: IdentifierSpec = IdentifierSpec.Generic("billing_details[address]"),

@SerialName("allowed_country_codes")
val allowedCountryCodes: Set<String> = supportedBillingCountries,
val allowedCountryCodes: Set<String> = CountryUtils.supportedBillingCountries,

@SerialName("display_fields")
val displayFields: Set<DisplayField> = emptySet(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.stripe.android.ui.core.elements

import androidx.annotation.RestrictTo
import com.stripe.android.core.model.CountryUtils
import com.stripe.android.ui.core.CardBillingDetailsCollectionConfiguration
import com.stripe.android.ui.core.R
import com.stripe.android.uicore.address.AddressRepository
import com.stripe.android.uicore.elements.IdentifierSpec
import com.stripe.android.uicore.elements.SameAsShippingController
import com.stripe.android.uicore.elements.SameAsShippingElement
import com.stripe.android.uicore.elements.SectionElement
import com.stripe.android.uicore.elements.supportedBillingCountries
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

Expand All @@ -18,7 +18,7 @@ data class CardBillingSpec(
@SerialName("api_path")
override val apiPath: IdentifierSpec = IdentifierSpec.Generic("card_billing"),
@SerialName("allowed_country_codes")
val allowedCountryCodes: Set<String> = supportedBillingCountries,
val allowedCountryCodes: Set<String> = CountryUtils.supportedBillingCountries,
@SerialName("collection_mode")
val collectionMode: CardBillingDetailsCollectionConfiguration.AddressCollectionMode =
CardBillingDetailsCollectionConfiguration.AddressCollectionMode.Automatic,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.stripe.android.ui.core.elements

import androidx.annotation.RestrictTo
import com.stripe.android.core.model.CountryUtils
import com.stripe.android.uicore.elements.CountryConfig
import com.stripe.android.uicore.elements.CountryElement
import com.stripe.android.uicore.elements.DropdownFieldController
import com.stripe.android.uicore.elements.IdentifierSpec
import com.stripe.android.uicore.elements.supportedBillingCountries
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

Expand All @@ -21,7 +21,7 @@ data class CountrySpec(
override val apiPath: IdentifierSpec = IdentifierSpec.Country,

@SerialName("allowed_country_codes")
val allowedCountryCodes: Set<String> = supportedBillingCountries
val allowedCountryCodes: Set<String> = CountryUtils.supportedBillingCountries
) : FormItemSpec() {
fun transform(
initialValues: Map<IdentifierSpec, String?>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package com.stripe.android.ui.core.forms

import androidx.annotation.RestrictTo
import com.stripe.android.core.model.CountryUtils
import com.stripe.android.ui.core.elements.CardBillingSpec
import com.stripe.android.ui.core.elements.CardDetailsSectionSpec
import com.stripe.android.ui.core.elements.LayoutSpec
import com.stripe.android.uicore.elements.IdentifierSpec
import com.stripe.android.uicore.elements.supportedBillingCountries

@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
val LinkCardForm = LayoutSpec(
listOf(
CardDetailsSectionSpec(IdentifierSpec.Generic("card_details_section")),
CardBillingSpec(allowedCountryCodes = supportedBillingCountries)
CardBillingSpec(allowedCountryCodes = CountryUtils.supportedBillingCountries)
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,41 @@ import java.util.Locale

@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) // For paymentsheet -- this still auto-completes
object CountryUtils {

// This comes from: stripe-js-v3/blob/master/src/lib/shared/checkoutSupportedCountries.js
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
val supportedBillingCountries = setOf(
"AD", "AE", "AF", "AG", "AI", "AL", "AM", "AO", "AQ", "AR", "AT", "AU", "AW", "AX",
"AZ", "BA", "BB", "BD", "BE", "BF", "BG", "BH", "BI", "BJ", "BL", "BM", "BN", "BO",
"BQ", "BR", "BS", "BT", "BV", "BW", "BY", "BZ", "CA", "CD", "CF", "CG", "CH", "CI",
"CK", "CL", "CM", "CN", "CO", "CR", "CV", "CW", "CY", "CZ", "DE", "DJ", "DK", "DM",
"DO", "DZ", "EC", "EE", "EG", "EH", "ER", "ES", "ET", "FI", "FJ", "FK", "FO", "FR",
"GA", "GB", "GD", "GE", "GF", "GG", "GH", "GI", "GL", "GM", "GN", "GP", "GQ", "GR",
"GS", "GT", "GU", "GW", "GY", "HK", "HN", "HR", "HT", "HU", "ID", "IE", "IL", "IM",
"IN", "IO", "IQ", "IS", "IT", "JE", "JM", "JO", "JP", "KE", "KG", "KH", "KI", "KM",
"KN", "KR", "KW", "KY", "KZ", "LA", "LB", "LC", "LI", "LK", "LR", "LS", "LT", "LU",
"LV", "LY", "MA", "MC", "MD", "ME", "MF", "MG", "MK", "ML", "MM", "MN", "MO", "MQ",
"MR", "MS", "MT", "MU", "MV", "MW", "MX", "MY", "MZ", "NA", "NC", "NE", "NG", "NI",
"NL", "NO", "NP", "NR", "NU", "NZ", "OM", "PA", "PE", "PF", "PG", "PH", "PK", "PL",
"PM", "PN", "PR", "PS", "PT", "PY", "QA", "RE", "RO", "RS", "RU", "RW", "SA", "SB",
"SC", "SE", "SG", "SH", "SI", "SJ", "SK", "SL", "SM", "SN", "SO", "SR", "SS", "ST",
"SV", "SX", "SZ", "TA", "TC", "TD", "TF", "TG", "TH", "TJ", "TK", "TL", "TM", "TN",
"TO", "TR", "TT", "TV", "TW", "TZ", "UA", "UG", "US", "UY", "UZ", "VA", "VC", "VE",
"VG", "VN", "VU", "WF", "WS", "XK", "YE", "YT", "ZA", "ZM", "ZW"
)

private val CARD_POSTAL_CODE_COUNTRIES = setOf(
"US",
"GB",
"CA"
)

private fun localizedCountries(currentLocale: Locale) =
Locale.getISOCountries().map { code ->
Country(
CountryCode.create(code),
Locale("", code).getDisplayCountry(currentLocale)
)
}
private fun localizedCountries(currentLocale: Locale) = supportedBillingCountries.map { code ->
Country(
CountryCode.create(code),
Locale("", code).getDisplayCountry(currentLocale)
)
}

@JvmSynthetic
fun getDisplayCountry(countryCode: CountryCode, currentLocale: Locale): String =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,17 @@ class CountryUtilsTest {
.isEqualTo("Deutschland")
}

@Test
fun countryIsAvailableEvenWhenNotReturnedFrom_getISOCountries() {
// https://github.com/stripe/stripe-android/issues/6501
// We used to use Locale.getISOCountries instead of our hardcoded set.
// Some countries (notably Kosovo) wasn't available on some older Android versions.
assertThat(CountryUtils.getDisplayCountry(CountryCode.create("XK"), Locale.US))
.isEqualTo("Kosovo")
val country = CountryUtils.getCountryByCode(CountryCode.create("XK"), Locale.US)
assertThat(country).isEqualTo(Country("XK", "Kosovo"))
}

@Test
fun `getOrderedCountriesLocaleLanguage() in the language of the current locale`() {
val currentLocale = Locale("de", "DE")
Expand Down
3 changes: 0 additions & 3 deletions stripe-ui-core/api/stripe-ui-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,6 @@ public final class com/stripe/android/uicore/elements/AddressElementUIKt {
public final class com/stripe/android/uicore/elements/AddressTextFieldUIKt {
}

public final class com/stripe/android/uicore/elements/BillingSpecKt {
}

public final class com/stripe/android/uicore/elements/CheckboxElementUIKt {
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.stripe.android.uicore.elements

import com.google.common.truth.Truth.assertThat
import com.stripe.android.core.model.CountryUtils
import com.stripe.android.uicore.R
import org.junit.Test
import java.util.Locale
Expand Down Expand Up @@ -62,7 +63,7 @@ class CountryConfigTest {
locale = Locale.US
).displayItems
val supportedCountries = CountryConfig(
onlyShowCountryCodes = supportedBillingCountries,
onlyShowCountryCodes = CountryUtils.supportedBillingCountries,
locale = Locale.US
).displayItems

Expand All @@ -79,10 +80,10 @@ class CountryConfigTest {

assertThat(
defaultCountries.size
).isEqualTo(249)
).isEqualTo(235)
Copy link
Contributor

@jameswoo-stripe jameswoo-stripe Apr 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the size change due to us not updating the list of supported countries?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely a behavior change! Before we default was the Locale.getISOCountries, and filtered by supportedBillingCountries. No it's always just supportedBillingCountries.


assertThat(
supportedCountries.size
).isEqualTo(233)
).isEqualTo(235)
}
}