Skip to content

Commit

Permalink
Get supported brands from payment method object in BCMC
Browse files Browse the repository at this point in the history
COAND-795
  • Loading branch information
ozgur00 committed Oct 25, 2023
1 parent 95aae44 commit bd874a8
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ constructor(
): BcmcComponent {
assertSupported(paymentMethod)
val bcmcFactory = viewModelFactory(savedStateRegistryOwner, null) { savedStateHandle ->
val componentParams = componentParamsMapper.mapToParams(configuration, null)
val componentParams = componentParamsMapper.mapToParams(configuration, null, paymentMethod)
val httpClient = HttpClientFactory.getHttpClient(componentParams.environment)
val publicKeyService = PublicKeyService(httpClient)
val publicKeyRepository = DefaultPublicKeyRepository(publicKeyService)
Expand Down Expand Up @@ -176,7 +176,8 @@ constructor(
val bcmcFactory = viewModelFactory(savedStateRegistryOwner, null) { savedStateHandle ->
val componentParams = componentParamsMapper.mapToParams(
bcmcConfiguration = configuration,
sessionParams = SessionParamsFactory.create(checkoutSession)
sessionParams = SessionParamsFactory.create(checkoutSession),
paymentMethod = paymentMethod
)
val httpClient = HttpClientFactory.getHttpClient(componentParams.environment)
val publicKeyService = PublicKeyService(httpClient)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import com.adyen.checkout.card.SocialSecurityNumberVisibility
import com.adyen.checkout.card.internal.ui.model.CVCVisibility
import com.adyen.checkout.card.internal.ui.model.CardComponentParams
import com.adyen.checkout.card.internal.ui.model.StoredCVCVisibility
import com.adyen.checkout.components.core.PaymentMethod
import com.adyen.checkout.components.core.internal.ui.model.AnalyticsParams
import com.adyen.checkout.components.core.internal.ui.model.ComponentParams
import com.adyen.checkout.components.core.internal.ui.model.SessionParams
Expand All @@ -29,14 +30,17 @@ internal class BcmcComponentParamsMapper(
fun mapToParams(
bcmcConfiguration: BcmcConfiguration,
sessionParams: SessionParams?,
paymentMethod: PaymentMethod
): CardComponentParams {
return bcmcConfiguration
.mapToParamsInternal()
.mapToParamsInternal(
supportedCardBrands = paymentMethod.brands?.map { CardBrand(it) }
)
.override(overrideComponentParams)
.override(sessionParams ?: overrideSessionParams)
}

private fun BcmcConfiguration.mapToParamsInternal(): CardComponentParams {
private fun BcmcConfiguration.mapToParamsInternal(supportedCardBrands: List<CardBrand>?): CardComponentParams {
return CardComponentParams(
shopperLocale = shopperLocale,
environment = environment,
Expand All @@ -54,11 +58,7 @@ internal class BcmcComponentParamsMapper(
socialSecurityNumberVisibility = SocialSecurityNumberVisibility.HIDE,
cvcVisibility = CVCVisibility.HIDE_FIRST,
storedCVCVisibility = StoredCVCVisibility.HIDE,
supportedCardBrands = listOf(
CardBrand(cardType = CardType.BCMC),
CardBrand(cardType = CardType.MAESTRO),
CardBrand(cardType = CardType.VISA)
)
supportedCardBrands = supportedCardBrands ?: DEFAULT_SUPPORTED_CARD_BRANDS
)
}

Expand All @@ -85,4 +85,12 @@ internal class BcmcComponentParamsMapper(
amount = sessionParams.amount ?: amount,
)
}

companion object {
private val DEFAULT_SUPPORTED_CARD_BRANDS = listOf(
CardBrand(cardType = CardType.BCMC),
CardBrand(cardType = CardType.MAESTRO),
CardBrand(cardType = CardType.VISA)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import com.adyen.checkout.card.internal.ui.model.CVCVisibility
import com.adyen.checkout.card.internal.ui.model.CardComponentParams
import com.adyen.checkout.card.internal.ui.model.StoredCVCVisibility
import com.adyen.checkout.components.core.Amount
import com.adyen.checkout.components.core.PaymentMethod
import com.adyen.checkout.components.core.internal.ui.model.AnalyticsParams
import com.adyen.checkout.components.core.internal.ui.model.AnalyticsParamsLevel
import com.adyen.checkout.components.core.internal.ui.model.GenericComponentParams
Expand All @@ -37,7 +38,8 @@ internal class BcmcComponentParamsMapperTest {
val bcmcConfiguration = getBcmcConfigurationBuilder()
.build()

val params = BcmcComponentParamsMapper(null, null).mapToParams(bcmcConfiguration, null)
val params = BcmcComponentParamsMapper(null, null)
.mapToParams(bcmcConfiguration, null, PaymentMethod())

val expected = getCardComponentParams()

Expand All @@ -55,7 +57,8 @@ internal class BcmcComponentParamsMapperTest {
.setSubmitButtonVisible(false)
.build()

val params = BcmcComponentParamsMapper(null, null).mapToParams(bcmcConfiguration, null)
val params = BcmcComponentParamsMapper(null, null)
.mapToParams(bcmcConfiguration, null, PaymentMethod())

val expected = getCardComponentParams(
isHolderNameRequired = true,
Expand Down Expand Up @@ -87,7 +90,8 @@ internal class BcmcComponentParamsMapperTest {
)
)

val params = BcmcComponentParamsMapper(overrideParams, null).mapToParams(bcmcConfiguration, null)
val params = BcmcComponentParamsMapper(overrideParams, null)
.mapToParams(bcmcConfiguration, null, PaymentMethod())

val expected = getCardComponentParams(
shopperLocale = Locale.GERMAN,
Expand Down Expand Up @@ -123,7 +127,8 @@ internal class BcmcComponentParamsMapperTest {
installmentOptions = null,
amount = null,
returnUrl = "",
)
),
PaymentMethod()
)

val expected = getCardComponentParams(isStorePaymentFieldVisible = expectedValue)
Expand Down Expand Up @@ -154,7 +159,8 @@ internal class BcmcComponentParamsMapperTest {
installmentOptions = null,
amount = sessionsValue,
returnUrl = "",
)
),
PaymentMethod()
)

val expected = getCardComponentParams(
Expand Down

0 comments on commit bd874a8

Please sign in to comment.