Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

package com.adyen.checkout.blik.internal.ui

import android.app.Application
import com.adyen.checkout.blik.internal.ui.state.BlikComponentStateFactory
import com.adyen.checkout.blik.internal.ui.state.BlikComponentStateReducer
import com.adyen.checkout.blik.internal.ui.state.BlikComponentStateValidator
Expand All @@ -28,7 +29,9 @@ internal class BlikFactory :
PaymentComponentFactory<BlikPaymentComponentState, BlikComponent>,
StoredPaymentComponentFactory<BlikPaymentComponentState, StoredBlikComponent> {

@Suppress("UNUSED_PARAMETER")
override fun create(
application: Application,
paymentMethod: PaymentMethod,
coroutineScope: CoroutineScope,
analyticsManager: AnalyticsManager,
Expand All @@ -49,13 +52,15 @@ internal class BlikFactory :
)
}

@Suppress("UNUSED_PARAMETER")
override fun create(
application: Application,
storedPaymentMethod: StoredPaymentMethod,
coroutineScope: CoroutineScope,
analyticsManager: AnalyticsManager,
checkoutConfiguration: CheckoutConfiguration,
componentParamsBundle: ComponentParamsBundle,
@Suppress("UNUSED_PARAMETER") checkoutCallbacks: CheckoutCallbacks,
checkoutCallbacks: CheckoutCallbacks,
): StoredBlikComponent {
val componentParams = componentParamsBundle.commonComponentParams
return StoredBlikComponent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

package com.adyen.checkout.card.internal.ui

import android.app.Application
import com.adyen.checkout.card.OnBinLookupCallback
import com.adyen.checkout.card.OnBinValueCallback
import com.adyen.checkout.card.getCardConfiguration
Expand Down Expand Up @@ -41,7 +42,9 @@ internal class CardFactory :
PaymentComponentFactory<CardPaymentComponentState, CardComponent>,
StoredPaymentComponentFactory<CardPaymentComponentState, StoredCardComponent> {

@Suppress("UNUSED_PARAMETER")
override fun create(
application: Application,
paymentMethod: PaymentMethod,
coroutineScope: CoroutineScope,
analyticsManager: AnalyticsManager,
Expand Down Expand Up @@ -84,13 +87,15 @@ internal class CardFactory :
}
}

@Suppress("UNUSED_PARAMETER")
override fun create(
application: Application,
storedPaymentMethod: StoredPaymentMethod,
coroutineScope: CoroutineScope,
analyticsManager: AnalyticsManager,
checkoutConfiguration: CheckoutConfiguration,
componentParamsBundle: ComponentParamsBundle,
@Suppress("UNUSED_PARAMETER") checkoutCallbacks: CheckoutCallbacks,
checkoutCallbacks: CheckoutCallbacks,
): StoredCardComponent {
val cardComponentParams = CardComponentParamsMapper().mapToParams(
componentParamsBundle = componentParamsBundle,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ internal class AdvancedPaymentFacilitatorFactory(
)

val paymentComponent = PaymentMethodProvider.get(
application = applicationContext.applicationContext as android.app.Application,
paymentMethod = paymentMethod,
coroutineScope = coroutineScope,
analyticsManager = analyticsManager,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

package com.adyen.checkout.core.components.internal

import android.app.Application
import androidx.annotation.RestrictTo
import com.adyen.checkout.core.analytics.internal.AnalyticsManager
import com.adyen.checkout.core.components.CheckoutCallbacks
Expand Down Expand Up @@ -39,6 +40,7 @@ interface PaymentComponentFactory<CS : BasePaymentComponentState, T : PaymentCom
*/
@Suppress("LongParameterList")
fun create(
application: Application,
paymentMethod: PaymentMethod,
coroutineScope: CoroutineScope,
analyticsManager: AnalyticsManager,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

package com.adyen.checkout.core.components.internal

import android.app.Application
import androidx.annotation.RestrictTo
import androidx.annotation.VisibleForTesting
import com.adyen.checkout.core.analytics.internal.AnalyticsManager
Expand Down Expand Up @@ -54,6 +55,7 @@ object PaymentMethodProvider {
*/
@Suppress("LongParameterList")
fun get(
application: Application,
paymentMethod: PaymentMethodResponse,
coroutineScope: CoroutineScope,
analyticsManager: AnalyticsManager,
Expand All @@ -64,6 +66,7 @@ object PaymentMethodProvider {
return when (paymentMethod) {
is PaymentMethod -> {
getPaymentComponent(
application = application,
paymentMethod = paymentMethod,
coroutineScope = coroutineScope,
analyticsManager = analyticsManager,
Expand All @@ -75,6 +78,7 @@ object PaymentMethodProvider {

is StoredPaymentMethod -> {
getStoredPaymentComponent(
application = application,
storedPaymentMethod = paymentMethod,
coroutineScope = coroutineScope,
analyticsManager = analyticsManager,
Expand All @@ -92,6 +96,7 @@ object PaymentMethodProvider {

@Suppress("LongParameterList")
private fun getPaymentComponent(
application: Application,
paymentMethod: PaymentMethod,
coroutineScope: CoroutineScope,
analyticsManager: AnalyticsManager,
Expand All @@ -103,6 +108,7 @@ object PaymentMethodProvider {

@Suppress("UNCHECKED_CAST")
return factories[txVariant]?.create(
application = application,
paymentMethod = paymentMethod,
coroutineScope = coroutineScope,
analyticsManager = analyticsManager,
Expand All @@ -117,6 +123,7 @@ object PaymentMethodProvider {

@Suppress("LongParameterList")
private fun getStoredPaymentComponent(
application: Application,
storedPaymentMethod: StoredPaymentMethod,
coroutineScope: CoroutineScope,
analyticsManager: AnalyticsManager,
Expand All @@ -128,6 +135,7 @@ object PaymentMethodProvider {

@Suppress("UNCHECKED_CAST")
return storedFactories[txVariant]?.create(
application = application,
storedPaymentMethod = storedPaymentMethod,
coroutineScope = coroutineScope,
analyticsManager = analyticsManager,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

package com.adyen.checkout.core.components.internal

import android.app.Application
import androidx.annotation.RestrictTo
import com.adyen.checkout.core.analytics.internal.AnalyticsManager
import com.adyen.checkout.core.components.CheckoutCallbacks
Expand Down Expand Up @@ -39,6 +40,7 @@ interface StoredPaymentComponentFactory<CS : BasePaymentComponentState, T : Paym
*/
@Suppress("LongParameterList")
fun create(
application: Application,
storedPaymentMethod: StoredPaymentMethod,
coroutineScope: CoroutineScope,
analyticsManager: AnalyticsManager,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ internal class SessionsPaymentFacilitatorFactory(
)

val paymentComponent = PaymentMethodProvider.get(
application = applicationContext.applicationContext as android.app.Application,
paymentMethod = paymentMethod,
coroutineScope = coroutineScope,
analyticsManager = analyticsManager,
Expand All @@ -77,25 +78,7 @@ internal class SessionsPaymentFacilitatorFactory(
checkoutCallbacks = checkoutCallbacks,
)

val sessionInteractor = SessionInteractor(
sessionRepository = SessionRepository(
sessionService = SessionService(
httpClient = HttpClientFactory.getHttpClient(checkoutConfiguration.environment),
),
clientKey = checkoutConfiguration.clientKey,
),
sessionSavedStateHandleContainer = sessionSavedStateHandleContainer,
analyticsManager = analyticsManager,
sessionResponse = sessionSavedStateHandleContainer.getSessionResponse(),
isFlowTakenOver = sessionSavedStateHandleContainer.isFlowTakenOver ?: false,
)

// TODO - Based on txVariant, needs to be abstracted away
val componentEventHandler =
SessionsComponentEventHandler<BasePaymentComponentState>(
sessionInteractor = sessionInteractor,
componentCallbacks = checkoutCallbacks.toSessionsComponentCallbacks(),
)
val componentEventHandler = createComponentEventHandler(sessionSavedStateHandleContainer, analyticsManager)

val actionProvider = ActionProvider(
analyticsManager = analyticsManager,
Expand All @@ -113,4 +96,27 @@ internal class SessionsPaymentFacilitatorFactory(
commonComponentParams = componentParamsBundle.commonComponentParams,
)
}

private fun createComponentEventHandler(
sessionSavedStateHandleContainer: SessionSavedStateHandleContainer,
analyticsManager: com.adyen.checkout.core.analytics.internal.AnalyticsManager,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

For better readability, you could import com.adyen.checkout.core.analytics.internal.AnalyticsManager at the top of the file and use the simple name AnalyticsManager here.

Suggested change
analyticsManager: com.adyen.checkout.core.analytics.internal.AnalyticsManager,
analyticsManager: AnalyticsManager,

): SessionsComponentEventHandler<BasePaymentComponentState> {
val sessionInteractor = SessionInteractor(
sessionRepository = SessionRepository(
sessionService = SessionService(
httpClient = HttpClientFactory.getHttpClient(checkoutConfiguration.environment),
),
clientKey = checkoutConfiguration.clientKey,
),
sessionSavedStateHandleContainer = sessionSavedStateHandleContainer,
analyticsManager = analyticsManager,
sessionResponse = sessionSavedStateHandleContainer.getSessionResponse(),
isFlowTakenOver = sessionSavedStateHandleContainer.isFlowTakenOver ?: false,
)

return SessionsComponentEventHandler(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The // TODO - Based on txVariant, needs to be abstracted away comment was removed during this refactoring. Since this logic is still generic, consider re-adding the TODO here to ensure this future work is not forgotten.

sessionInteractor = sessionInteractor,
componentCallbacks = checkoutCallbacks.toSessionsComponentCallbacks(),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

package com.adyen.checkout.core.components.internal

import android.app.Application
import com.adyen.checkout.core.analytics.internal.AnalyticsManager
import com.adyen.checkout.core.analytics.internal.TestAnalyticsManager
import com.adyen.checkout.core.common.Environment
Expand Down Expand Up @@ -107,6 +108,7 @@ internal class PaymentMethodProviderTest {
PaymentMethodProvider.register("txVariant", secondaryFactory)

val actualComponent = PaymentMethodProvider.get(
application = generateApplication(),
paymentMethod = PaymentMethod(type = "txVariant", name = "name"),
coroutineScope = this,
analyticsManager = TestAnalyticsManager(),
Expand All @@ -131,6 +133,7 @@ internal class PaymentMethodProviderTest {
PaymentMethodProvider.register("txVariant", secondaryFactory)

val actualComponent = PaymentMethodProvider.get(
application = generateApplication(),
paymentMethod = StoredPaymentMethod(type = "txVariant", name = "name"),
coroutineScope = this,
analyticsManager = TestAnalyticsManager(),
Expand Down Expand Up @@ -165,6 +168,7 @@ internal class PaymentMethodProviderTest {
PaymentMethodProvider.register("txVariant", factory)

val actualComponent = PaymentMethodProvider.get(
application = generateApplication(),
paymentMethod = PaymentMethod(type = "txVariant", name = "name"),
coroutineScope = this,
analyticsManager = TestAnalyticsManager(),
Expand All @@ -182,6 +186,7 @@ internal class PaymentMethodProviderTest {
PaymentMethodProvider.register("txVariant", storedFactory)

val actualComponent = PaymentMethodProvider.get(
application = generateApplication(),
paymentMethod = StoredPaymentMethod(type = "txVariant", name = "name"),
coroutineScope = this,
analyticsManager = TestAnalyticsManager(),
Expand All @@ -197,6 +202,7 @@ internal class PaymentMethodProviderTest {
fun `when get is called for an unregistered factory, then an error is thrown`() = runTest {
assertThrows<IllegalStateException> {
PaymentMethodProvider.get(
application = generateApplication(),
paymentMethod = PaymentMethod(type = "unregistered_txVariant", name = "name"),
coroutineScope = this,
analyticsManager = TestAnalyticsManager(),
Expand All @@ -211,6 +217,7 @@ internal class PaymentMethodProviderTest {
fun `when get is called for an unregistered stored factory, then an error is thrown`() = runTest {
assertThrows<IllegalStateException> {
PaymentMethodProvider.get(
application = generateApplication(),
paymentMethod = StoredPaymentMethod(type = "unregistered_txVariant", name = "name"),
coroutineScope = this,
analyticsManager = TestAnalyticsManager(),
Expand Down Expand Up @@ -239,6 +246,7 @@ internal class PaymentMethodProviderTest {
object :
PaymentComponentFactory<BasePaymentComponentState, PaymentComponent<BasePaymentComponentState>> {
override fun create(
application: Application,
paymentMethod: PaymentMethod,
coroutineScope: CoroutineScope,
analyticsManager: AnalyticsManager,
Expand All @@ -252,6 +260,7 @@ internal class PaymentMethodProviderTest {
object :
StoredPaymentComponentFactory<BasePaymentComponentState, PaymentComponent<BasePaymentComponentState>> {
override fun create(
application: Application,
storedPaymentMethod: StoredPaymentMethod,
coroutineScope: CoroutineScope,
analyticsManager: AnalyticsManager,
Expand All @@ -261,6 +270,10 @@ internal class PaymentMethodProviderTest {
) = paymentComponent
}

private fun generateApplication(): Application {
return org.mockito.Mockito.mock(Application::class.java)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

To improve code style, you can add import org.mockito.Mockito at the top of the file and use Mockito.mock(Application::class.java) here. With a static import like import org.mockito.Mockito.mock, you could simplify this to just mock(Application::class.java).

Suggested change
return org.mockito.Mockito.mock(Application::class.java)
return Mockito.mock(Application::class.java)

}

private fun generateCheckoutConfiguration() = CheckoutConfiguration(
shopperLocale = Locale.US,
environment = Environment.TEST,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

package com.adyen.checkout.googlepay.internal.ui

import android.app.Application
import com.adyen.checkout.core.analytics.internal.AnalyticsManager
import com.adyen.checkout.core.components.CheckoutCallbacks
import com.adyen.checkout.core.components.CheckoutConfiguration
Expand All @@ -18,14 +19,18 @@ import com.adyen.checkout.googlepay.internal.ui.state.GooglePayPaymentComponentS
import kotlinx.coroutines.CoroutineScope

internal class GooglePayFactory : PaymentComponentFactory<GooglePayPaymentComponentState, GooglePayComponent> {

@Suppress("UNUSED_PARAMETER")
override fun create(
application: Application,
paymentMethod: PaymentMethod,
coroutineScope: CoroutineScope,
analyticsManager: AnalyticsManager,
checkoutConfiguration: CheckoutConfiguration,
componentParamsBundle: ComponentParamsBundle,
checkoutCallbacks: CheckoutCallbacks
): GooglePayComponent {
// TODO - Implement GooglePayComponent creation
return GooglePayComponent()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

package com.adyen.checkout.mbway.internal.ui

import android.app.Application
import com.adyen.checkout.core.analytics.internal.AnalyticsManager
import com.adyen.checkout.core.components.CheckoutCallbacks
import com.adyen.checkout.core.components.CheckoutConfiguration
Expand All @@ -24,7 +25,9 @@ import kotlinx.coroutines.CoroutineScope

internal class MBWayFactory : PaymentComponentFactory<MBWayPaymentComponentState, MBWayComponent> {

@Suppress("UNUSED_PARAMETER")
override fun create(
application: Application,
paymentMethod: PaymentMethod,
coroutineScope: CoroutineScope,
analyticsManager: AnalyticsManager,
Expand Down
Loading