Skip to content

Commit

Permalink
Merge pull request #1325 from Adyen/fix/address_crash
Browse files Browse the repository at this point in the history
Fix address fetch crash (v4)
  • Loading branch information
OscarSpruit authored Aug 31, 2023
2 parents 6b2d175 + 31b1dd7 commit 02403eb
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
17 changes: 11 additions & 6 deletions card/src/main/java/com/adyen/checkout/card/AddressDelegate.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import com.adyen.checkout.card.api.model.AddressItem
import com.adyen.checkout.card.repository.AddressRepository
import com.adyen.checkout.card.ui.AddressSpecification
import com.adyen.checkout.components.base.Configuration
import com.adyen.checkout.core.exception.CheckoutException
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
Expand All @@ -39,12 +40,16 @@ class AddressDelegate(
cache[countryCode]?.let {
_statesFlow.tryEmit(it)
} ?: coroutineScope.launch {
val states = addressRepository.getAddressData(
environment = configuration.environment,
dataType = AddressDataType.STATE,
localeString = configuration.shopperLocale.toLanguageTag(),
countryCode = countryCode
)
val states = try {
addressRepository.getAddressData(
environment = configuration.environment,
dataType = AddressDataType.STATE,
localeString = configuration.shopperLocale.toLanguageTag(),
countryCode = countryCode
)
} catch (e: CheckoutException) {
emptyList()
}
if (states.isNotEmpty()) {
cache.put(countryCode, states)
}
Expand Down
7 changes: 6 additions & 1 deletion card/src/main/java/com/adyen/checkout/card/CardComponent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,12 @@ class CardComponent private constructor(

private fun requestCountryList(cardDelegate: NewCardDelegate) {
viewModelScope.launch {
val countries = cardDelegate.getCountryList()
val countries = try {
cardDelegate.getCountryList()
} catch (e: CheckoutException) {
notifyException(e)
emptyList()
}
val countryOptions = AddressFormUtils.initializeCountryOptions(cardConfiguration.addressConfiguration, countries)
countryOptions.firstOrNull { it.selected }?.let {
inputData.address.country = it.code
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@

package com.adyen.checkout.card.ui

import androidx.annotation.Keep
import androidx.annotation.StyleRes
import com.adyen.checkout.card.R

/**
* Specification for address form alternatives depending on the country.
*/
@Suppress("LongParameterList")
enum class AddressSpecification(
@Keep
internal enum class AddressSpecification(
internal val street: AddressFieldSpec,
internal val houseNumber: AddressFieldSpec,
internal val apartmentSuite: AddressFieldSpec,
Expand Down

0 comments on commit 02403eb

Please sign in to comment.