From bd874a8b4a57274e016fa0cf6d42081cb35b007e Mon Sep 17 00:00:00 2001 From: ozgur <6615094+ozgur00@users.noreply.github.com> Date: Tue, 24 Oct 2023 14:20:57 +0200 Subject: [PATCH] Get supported brands from payment method object in BCMC COAND-795 --- .../provider/BcmcComponentProvider.kt | 5 +++-- .../ui/model/BcmcComponentParamsMapper.kt | 22 +++++++++++++------ .../ui/model/BcmcComponentParamsMapperTest.kt | 16 +++++++++----- 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/bcmc/src/main/java/com/adyen/checkout/bcmc/internal/provider/BcmcComponentProvider.kt b/bcmc/src/main/java/com/adyen/checkout/bcmc/internal/provider/BcmcComponentProvider.kt index 377a2ad937..b651e49510 100644 --- a/bcmc/src/main/java/com/adyen/checkout/bcmc/internal/provider/BcmcComponentProvider.kt +++ b/bcmc/src/main/java/com/adyen/checkout/bcmc/internal/provider/BcmcComponentProvider.kt @@ -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) @@ -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) diff --git a/bcmc/src/main/java/com/adyen/checkout/bcmc/internal/ui/model/BcmcComponentParamsMapper.kt b/bcmc/src/main/java/com/adyen/checkout/bcmc/internal/ui/model/BcmcComponentParamsMapper.kt index 235810cd13..71b9c516a7 100644 --- a/bcmc/src/main/java/com/adyen/checkout/bcmc/internal/ui/model/BcmcComponentParamsMapper.kt +++ b/bcmc/src/main/java/com/adyen/checkout/bcmc/internal/ui/model/BcmcComponentParamsMapper.kt @@ -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 @@ -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?): CardComponentParams { return CardComponentParams( shopperLocale = shopperLocale, environment = environment, @@ -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 ) } @@ -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) + ) + } } diff --git a/bcmc/src/test/java/com/adyen/checkout/bcmc/internal/ui/model/BcmcComponentParamsMapperTest.kt b/bcmc/src/test/java/com/adyen/checkout/bcmc/internal/ui/model/BcmcComponentParamsMapperTest.kt index 95989dd39b..b2f4ca0abe 100644 --- a/bcmc/src/test/java/com/adyen/checkout/bcmc/internal/ui/model/BcmcComponentParamsMapperTest.kt +++ b/bcmc/src/test/java/com/adyen/checkout/bcmc/internal/ui/model/BcmcComponentParamsMapperTest.kt @@ -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 @@ -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() @@ -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, @@ -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, @@ -123,7 +127,8 @@ internal class BcmcComponentParamsMapperTest { installmentOptions = null, amount = null, returnUrl = "", - ) + ), + PaymentMethod() ) val expected = getCardComponentParams(isStorePaymentFieldVisible = expectedValue) @@ -154,7 +159,8 @@ internal class BcmcComponentParamsMapperTest { installmentOptions = null, amount = sessionsValue, returnUrl = "", - ) + ), + PaymentMethod() ) val expected = getCardComponentParams(