From b6c58466bdc699f70622aadf924eac3abb6ea823 Mon Sep 17 00:00:00 2001 From: Vitalii Vanziak Date: Fri, 25 Apr 2025 17:26:19 +0300 Subject: [PATCH 1/7] PONativeAlternativePaymentDelegate --- .../PONativeAlternativePaymentDelegate.kt | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 ui/src/main/kotlin/com/processout/sdk/ui/napm/PONativeAlternativePaymentDelegate.kt diff --git a/ui/src/main/kotlin/com/processout/sdk/ui/napm/PONativeAlternativePaymentDelegate.kt b/ui/src/main/kotlin/com/processout/sdk/ui/napm/PONativeAlternativePaymentDelegate.kt new file mode 100644 index 000000000..aa60e4ba0 --- /dev/null +++ b/ui/src/main/kotlin/com/processout/sdk/ui/napm/PONativeAlternativePaymentDelegate.kt @@ -0,0 +1,25 @@ +package com.processout.sdk.ui.napm + +import com.processout.sdk.api.model.event.PONativeAlternativePaymentMethodEvent +import com.processout.sdk.api.model.response.PONativeAlternativePaymentMethodParameter + +/** + * Delegate that allows to handle events during native alternative payments. + */ +interface PONativeAlternativePaymentDelegate { + + /** + * Invoked on native alternative payment lifecycle events. + */ + fun onEvent(event: PONativeAlternativePaymentMethodEvent) {} + + /** + * Allows to prefill default values for the given parameters during native alternative payment. + * Return a map where key is a [PONativeAlternativePaymentMethodParameter.key] and value is a custom default value. + * It's not mandatory to provide default values for all parameters. + */ + suspend fun defaultValues( + gatewayConfigurationId: String, + parameters: List + ): Map = emptyMap() +} From b373fde16dfa8d40a3a602a00c4bd584d2b28444 Mon Sep 17 00:00:00 2001 From: Vitalii Vanziak Date: Fri, 25 Apr 2025 17:44:56 +0300 Subject: [PATCH 2/7] Added delegate and its logic to PONativeAlternativePaymentLauncher --- .../PONativeAlternativePaymentLauncher.kt | 84 ++++++++++++++++++- 1 file changed, 81 insertions(+), 3 deletions(-) diff --git a/ui/src/main/kotlin/com/processout/sdk/ui/napm/PONativeAlternativePaymentLauncher.kt b/ui/src/main/kotlin/com/processout/sdk/ui/napm/PONativeAlternativePaymentLauncher.kt index 8ba003437..1d8004a2c 100644 --- a/ui/src/main/kotlin/com/processout/sdk/ui/napm/PONativeAlternativePaymentLauncher.kt +++ b/ui/src/main/kotlin/com/processout/sdk/ui/napm/PONativeAlternativePaymentLauncher.kt @@ -5,16 +5,26 @@ import androidx.activity.ComponentActivity import androidx.activity.result.ActivityResultLauncher import androidx.core.app.ActivityOptionsCompat import androidx.fragment.app.Fragment +import androidx.lifecycle.lifecycleScope import com.processout.sdk.R +import com.processout.sdk.api.dispatcher.POEventDispatcher +import com.processout.sdk.api.model.event.PONativeAlternativePaymentMethodEvent +import com.processout.sdk.api.model.request.PONativeAlternativePaymentMethodDefaultValuesRequest +import com.processout.sdk.api.model.response.toResponse import com.processout.sdk.core.POUnit import com.processout.sdk.core.ProcessOutActivityResult +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.launch /** * Launcher that starts [NativeAlternativePaymentActivity] and provides the result. */ class PONativeAlternativePaymentLauncher private constructor( + private val scope: CoroutineScope, private val launcher: ActivityResultLauncher, - private val activityOptions: ActivityOptionsCompat + private val activityOptions: ActivityOptionsCompat, + private val delegate: PONativeAlternativePaymentDelegate, + private val eventDispatcher: POEventDispatcher = POEventDispatcher ) { companion object { @@ -24,13 +34,34 @@ class PONativeAlternativePaymentLauncher private constructor( */ fun create( from: Fragment, + delegate: PONativeAlternativePaymentDelegate, callback: (ProcessOutActivityResult) -> Unit ) = PONativeAlternativePaymentLauncher( + scope = from.lifecycleScope, launcher = from.registerForActivityResult( NativeAlternativePaymentActivityContract(), callback ), - activityOptions = createActivityOptions(from.requireContext()) + activityOptions = createActivityOptions(from.requireContext()), + delegate = delegate + ) + + /** + * Creates the launcher from Fragment. + * __Note:__ Required to call in _onCreate()_ to register for activity result. + */ + @Deprecated(message = "Use alternative function.") + fun create( + from: Fragment, + callback: (ProcessOutActivityResult) -> Unit + ) = PONativeAlternativePaymentLauncher( + scope = from.lifecycleScope, + launcher = from.registerForActivityResult( + NativeAlternativePaymentActivityContract(), + callback + ), + activityOptions = createActivityOptions(from.requireContext()), + delegate = object : PONativeAlternativePaymentDelegate {} ) /** @@ -39,14 +70,36 @@ class PONativeAlternativePaymentLauncher private constructor( */ fun create( from: ComponentActivity, + delegate: PONativeAlternativePaymentDelegate, callback: (ProcessOutActivityResult) -> Unit ) = PONativeAlternativePaymentLauncher( + scope = from.lifecycleScope, launcher = from.registerForActivityResult( NativeAlternativePaymentActivityContract(), from.activityResultRegistry, callback ), - activityOptions = createActivityOptions(from) + activityOptions = createActivityOptions(from), + delegate = delegate + ) + + /** + * Creates the launcher from Activity. + * __Note:__ Required to call in _onCreate()_ to register for activity result. + */ + @Deprecated(message = "Use alternative function.") + fun create( + from: ComponentActivity, + callback: (ProcessOutActivityResult) -> Unit + ) = PONativeAlternativePaymentLauncher( + scope = from.lifecycleScope, + launcher = from.registerForActivityResult( + NativeAlternativePaymentActivityContract(), + from.activityResultRegistry, + callback + ), + activityOptions = createActivityOptions(from), + delegate = object : PONativeAlternativePaymentDelegate {} ) private fun createActivityOptions(context: Context) = @@ -55,6 +108,31 @@ class PONativeAlternativePaymentLauncher private constructor( ) } + init { + dispatchEvents() + dispatchDefaultValues() + } + + private fun dispatchEvents() { + eventDispatcher.subscribe( + coroutineScope = scope + ) { delegate.onEvent(it) } + } + + private fun dispatchDefaultValues() { + eventDispatcher.subscribeForRequest( + coroutineScope = scope + ) { request -> + scope.launch { + val defaultValues = delegate.defaultValues( + gatewayConfigurationId = request.gatewayConfigurationId, + parameters = request.parameters + ) + eventDispatcher.send(request.toResponse(defaultValues)) + } + } + } + /** * Launches the activity. */ From f101d9c433150638b836e6f93cb326005f15f5eb Mon Sep 17 00:00:00 2001 From: Vitalii Vanziak Date: Fri, 25 Apr 2025 17:50:51 +0300 Subject: [PATCH 3/7] Update example app --- .../example/ui/screen/nativeapm/NativeApmFragment.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/example/src/main/kotlin/com/processout/example/ui/screen/nativeapm/NativeApmFragment.kt b/example/src/main/kotlin/com/processout/example/ui/screen/nativeapm/NativeApmFragment.kt index b93a9c829..2f9105990 100644 --- a/example/src/main/kotlin/com/processout/example/ui/screen/nativeapm/NativeApmFragment.kt +++ b/example/src/main/kotlin/com/processout/example/ui/screen/nativeapm/NativeApmFragment.kt @@ -17,6 +17,7 @@ import com.processout.sdk.core.onFailure import com.processout.sdk.core.onSuccess import com.processout.sdk.ui.napm.PONativeAlternativePaymentConfiguration import com.processout.sdk.ui.napm.PONativeAlternativePaymentConfiguration.Button +import com.processout.sdk.ui.napm.PONativeAlternativePaymentDelegate import com.processout.sdk.ui.napm.PONativeAlternativePaymentLauncher import com.processout.sdk.ui.nativeapm.PONativeAlternativePaymentMethodConfiguration import com.processout.sdk.ui.nativeapm.PONativeAlternativePaymentMethodLauncher @@ -48,7 +49,10 @@ class NativeApmFragment : BaseFragment( showAlert(result.toMessage()) } } - launcherCompose = PONativeAlternativePaymentLauncher.create(from = this) { result -> + launcherCompose = PONativeAlternativePaymentLauncher.create( + from = this, + delegate = object : PONativeAlternativePaymentDelegate {} + ) { result -> viewModel.reset() result.onSuccess { showAlert(getString(R.string.success)) From 88a1af00e5439ee69abcf7a7a727712480b6b045 Mon Sep 17 00:00:00 2001 From: Vitalii Vanziak Date: Tue, 29 Apr 2025 14:32:04 +0300 Subject: [PATCH 4/7] legacyEventDispatcher --- .../sdk/ui/checkout/DynamicCheckoutActivity.kt | 2 +- .../ui/napm/NativeAlternativePaymentBottomSheet.kt | 2 +- .../ui/napm/NativeAlternativePaymentInteractor.kt | 12 +++++++----- .../sdk/ui/napm/NativeAlternativePaymentViewModel.kt | 4 ++-- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/ui/src/main/kotlin/com/processout/sdk/ui/checkout/DynamicCheckoutActivity.kt b/ui/src/main/kotlin/com/processout/sdk/ui/checkout/DynamicCheckoutActivity.kt index f828a7a4b..31547c484 100644 --- a/ui/src/main/kotlin/com/processout/sdk/ui/checkout/DynamicCheckoutActivity.kt +++ b/ui/src/main/kotlin/com/processout/sdk/ui/checkout/DynamicCheckoutActivity.kt @@ -78,7 +78,7 @@ internal class DynamicCheckoutActivity : BaseTransparentPortraitActivity() { NativeAlternativePaymentViewModel.Factory( app = application, configuration = nativeAlternativePaymentConfiguration(), - eventDispatcher = nativeAlternativePaymentEventDispatcher + legacyEventDispatcher = nativeAlternativePaymentEventDispatcher ) } DynamicCheckoutViewModel.Factory( diff --git a/ui/src/main/kotlin/com/processout/sdk/ui/napm/NativeAlternativePaymentBottomSheet.kt b/ui/src/main/kotlin/com/processout/sdk/ui/napm/NativeAlternativePaymentBottomSheet.kt index efacd14ed..5204e8846 100644 --- a/ui/src/main/kotlin/com/processout/sdk/ui/napm/NativeAlternativePaymentBottomSheet.kt +++ b/ui/src/main/kotlin/com/processout/sdk/ui/napm/NativeAlternativePaymentBottomSheet.kt @@ -56,7 +56,7 @@ internal class NativeAlternativePaymentBottomSheet : BaseBottomSheetDialogFragme gatewayConfigurationId = String(), submitButton = Button() ), - eventDispatcher = PODefaultEventDispatchers.defaultNativeAlternativePaymentMethod + legacyEventDispatcher = PODefaultEventDispatchers.defaultNativeAlternativePaymentMethod ) } diff --git a/ui/src/main/kotlin/com/processout/sdk/ui/napm/NativeAlternativePaymentInteractor.kt b/ui/src/main/kotlin/com/processout/sdk/ui/napm/NativeAlternativePaymentInteractor.kt index d55797bce..47e6b2e2c 100644 --- a/ui/src/main/kotlin/com/processout/sdk/ui/napm/NativeAlternativePaymentInteractor.kt +++ b/ui/src/main/kotlin/com/processout/sdk/ui/napm/NativeAlternativePaymentInteractor.kt @@ -16,6 +16,7 @@ import coil.request.CachePolicy import coil.request.ImageRequest import coil.request.ImageResult import com.processout.sdk.R +import com.processout.sdk.api.dispatcher.POEventDispatcher import com.processout.sdk.api.dispatcher.napm.PODefaultNativeAlternativePaymentMethodEventDispatcher import com.processout.sdk.api.model.event.PONativeAlternativePaymentMethodEvent import com.processout.sdk.api.model.event.PONativeAlternativePaymentMethodEvent.* @@ -63,7 +64,8 @@ internal class NativeAlternativePaymentInteractor( private val barcodeBitmapProvider: BarcodeBitmapProvider, private val mediaStorageProvider: MediaStorageProvider, private val captureRetryStrategy: PORetryStrategy, - private val eventDispatcher: PODefaultNativeAlternativePaymentMethodEventDispatcher, + private val legacyEventDispatcher: PODefaultNativeAlternativePaymentMethodEventDispatcher?, // TODO: remove before next major release. + private val eventDispatcher: POEventDispatcher = POEventDispatcher, private var logAttributes: Map = logAttributes( invoiceId = configuration.invoiceId, gatewayConfigurationId = configuration.gatewayConfigurationId @@ -261,7 +263,7 @@ internal class NativeAlternativePaymentInteractor( focusedFieldId = focusedFieldId ) val isLoading = _state.value is Loading - if (eventDispatcher.subscribedForDefaultValuesRequest()) { + if (legacyEventDispatcher?.subscribedForDefaultValuesRequest() == true) { _state.update { if (isLoading) { Loaded(updatedStateValue) @@ -368,14 +370,14 @@ internal class NativeAlternativePaymentInteractor( parameters = parameters ) latestDefaultValuesRequest = request - eventDispatcher.send(request) + legacyEventDispatcher?.send(request) POLogger.debug("Requested to provide default values for payment parameters: %s", request) } } private fun collectDefaultValues() { interactorScope.launch { - eventDispatcher.defaultValuesResponse.collect { response -> + legacyEventDispatcher?.defaultValuesResponse?.collect { response -> if (response.uuid == latestDefaultValuesRequest?.uuid) { latestDefaultValuesRequest = null POLogger.debug("Collected default values for payment parameters: %s", response) @@ -922,7 +924,7 @@ internal class NativeAlternativePaymentInteractor( private fun dispatch(event: PONativeAlternativePaymentMethodEvent) { interactorScope.launch { - eventDispatcher.send(event) + legacyEventDispatcher?.send(event) POLogger.debug("Event has been sent: %s", event) } } diff --git a/ui/src/main/kotlin/com/processout/sdk/ui/napm/NativeAlternativePaymentViewModel.kt b/ui/src/main/kotlin/com/processout/sdk/ui/napm/NativeAlternativePaymentViewModel.kt index 67ad1d222..fa6c7a387 100644 --- a/ui/src/main/kotlin/com/processout/sdk/ui/napm/NativeAlternativePaymentViewModel.kt +++ b/ui/src/main/kotlin/com/processout/sdk/ui/napm/NativeAlternativePaymentViewModel.kt @@ -42,7 +42,7 @@ internal class NativeAlternativePaymentViewModel private constructor( class Factory( private val app: Application, private val configuration: PONativeAlternativePaymentConfiguration, - private val eventDispatcher: PODefaultNativeAlternativePaymentMethodEventDispatcher + private val legacyEventDispatcher: PODefaultNativeAlternativePaymentMethodEventDispatcher? ) : ViewModelProvider.Factory { @Suppress("UNCHECKED_CAST") override fun create(modelClass: Class): T = @@ -62,7 +62,7 @@ internal class NativeAlternativePaymentViewModel private constructor( maxDelay = 90 * 1000, factor = 1.45 ), - eventDispatcher = eventDispatcher + legacyEventDispatcher = legacyEventDispatcher ) ) as T } From fd030fa7b3743a5c60d1fc1644c229572d716096 Mon Sep 17 00:00:00 2001 From: Vitalii Vanziak Date: Tue, 29 Apr 2025 14:34:18 +0300 Subject: [PATCH 5/7] eventDispatcher.send(event) --- .../processout/sdk/ui/napm/NativeAlternativePaymentInteractor.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/ui/src/main/kotlin/com/processout/sdk/ui/napm/NativeAlternativePaymentInteractor.kt b/ui/src/main/kotlin/com/processout/sdk/ui/napm/NativeAlternativePaymentInteractor.kt index 47e6b2e2c..fce6e94ac 100644 --- a/ui/src/main/kotlin/com/processout/sdk/ui/napm/NativeAlternativePaymentInteractor.kt +++ b/ui/src/main/kotlin/com/processout/sdk/ui/napm/NativeAlternativePaymentInteractor.kt @@ -925,6 +925,7 @@ internal class NativeAlternativePaymentInteractor( private fun dispatch(event: PONativeAlternativePaymentMethodEvent) { interactorScope.launch { legacyEventDispatcher?.send(event) + eventDispatcher.send(event) POLogger.debug("Event has been sent: %s", event) } } From f5c2a48f5c7dff6e45befb849e08b072b075b542 Mon Sep 17 00:00:00 2001 From: Vitalii Vanziak Date: Tue, 29 Apr 2025 15:34:40 +0300 Subject: [PATCH 6/7] Request and collect default values --- .../NativeAlternativePaymentInteractor.kt | 56 +++++++++++-------- 1 file changed, 32 insertions(+), 24 deletions(-) diff --git a/ui/src/main/kotlin/com/processout/sdk/ui/napm/NativeAlternativePaymentInteractor.kt b/ui/src/main/kotlin/com/processout/sdk/ui/napm/NativeAlternativePaymentInteractor.kt index fce6e94ac..a9e228157 100644 --- a/ui/src/main/kotlin/com/processout/sdk/ui/napm/NativeAlternativePaymentInteractor.kt +++ b/ui/src/main/kotlin/com/processout/sdk/ui/napm/NativeAlternativePaymentInteractor.kt @@ -262,21 +262,14 @@ internal class NativeAlternativePaymentInteractor( fields = fields, focusedFieldId = focusedFieldId ) - val isLoading = _state.value is Loading - if (legacyEventDispatcher?.subscribedForDefaultValuesRequest() == true) { - _state.update { - if (isLoading) { - Loaded(updatedStateValue) - } else { - Submitted(updatedStateValue) - } + _state.update { + if (_state.value is Loading) { + Loaded(updatedStateValue) + } else { + Submitted(updatedStateValue) } - requestDefaultValues(parameters) - } else if (isLoading) { - startUserInput(updatedStateValue) - } else { - continueUserInput(updatedStateValue) } + requestDefaultValues(parameters) } private fun failWithUnknownInputParameter( @@ -370,7 +363,11 @@ internal class NativeAlternativePaymentInteractor( parameters = parameters ) latestDefaultValuesRequest = request - legacyEventDispatcher?.send(request) + if (legacyEventDispatcher?.subscribedForDefaultValuesRequest() == true) { + legacyEventDispatcher.send(request) + } else { + eventDispatcher.send(request) + } POLogger.debug("Requested to provide default values for payment parameters: %s", request) } } @@ -378,16 +375,27 @@ internal class NativeAlternativePaymentInteractor( private fun collectDefaultValues() { interactorScope.launch { legacyEventDispatcher?.defaultValuesResponse?.collect { response -> - if (response.uuid == latestDefaultValuesRequest?.uuid) { - latestDefaultValuesRequest = null - POLogger.debug("Collected default values for payment parameters: %s", response) - _state.whenLoaded { stateValue -> - startUserInput(stateValue.updateFieldValues(response.defaultValues)) - } - _state.whenSubmitted { stateValue -> - continueUserInput(stateValue.updateFieldValues(response.defaultValues)) - } - } + handleDefaultValues(response) + } + } + eventDispatcher.subscribeForResponse( + coroutineScope = interactorScope + ) { response -> + handleDefaultValues(response) + } + } + + private fun handleDefaultValues( + response: PONativeAlternativePaymentMethodDefaultValuesResponse + ) { + if (response.uuid == latestDefaultValuesRequest?.uuid) { + latestDefaultValuesRequest = null + POLogger.debug("Collected default values for payment parameters: %s", response) + _state.whenLoaded { stateValue -> + startUserInput(stateValue.updateFieldValues(response.defaultValues)) + } + _state.whenSubmitted { stateValue -> + continueUserInput(stateValue.updateFieldValues(response.defaultValues)) } } } From eac0c13d3a768254a255453f688529d158e0e7af Mon Sep 17 00:00:00 2001 From: Vitalii Vanziak Date: Tue, 29 Apr 2025 16:25:58 +0300 Subject: [PATCH 7/7] Remove legacy dispatcher from DC --- .../ui/checkout/DynamicCheckoutActivity.kt | 7 +-- .../ui/checkout/DynamicCheckoutInteractor.kt | 44 ++++++------------- .../ui/checkout/DynamicCheckoutViewModel.kt | 7 +-- 3 files changed, 17 insertions(+), 41 deletions(-) diff --git a/ui/src/main/kotlin/com/processout/sdk/ui/checkout/DynamicCheckoutActivity.kt b/ui/src/main/kotlin/com/processout/sdk/ui/checkout/DynamicCheckoutActivity.kt index 31547c484..ede5b87cc 100644 --- a/ui/src/main/kotlin/com/processout/sdk/ui/checkout/DynamicCheckoutActivity.kt +++ b/ui/src/main/kotlin/com/processout/sdk/ui/checkout/DynamicCheckoutActivity.kt @@ -23,7 +23,6 @@ import androidx.lifecycle.compose.collectAsStateWithLifecycle import com.google.android.gms.wallet.Wallet.WalletOptions import com.processout.sdk.R import com.processout.sdk.api.ProcessOut -import com.processout.sdk.api.dispatcher.napm.PODefaultNativeAlternativePaymentMethodEventDispatcher import com.processout.sdk.api.model.event.POSavedPaymentMethodsEvent import com.processout.sdk.api.model.event.POSavedPaymentMethodsEvent.DidDeleteCustomerToken import com.processout.sdk.api.model.request.POInvoiceRequest @@ -73,20 +72,18 @@ internal class DynamicCheckoutActivity : BaseTransparentPortraitActivity() { legacyEventDispatcher = null ) } - val nativeAlternativePaymentEventDispatcher = PODefaultNativeAlternativePaymentMethodEventDispatcher() val nativeAlternativePayment: NativeAlternativePaymentViewModel by viewModels { NativeAlternativePaymentViewModel.Factory( app = application, configuration = nativeAlternativePaymentConfiguration(), - legacyEventDispatcher = nativeAlternativePaymentEventDispatcher + legacyEventDispatcher = null ) } DynamicCheckoutViewModel.Factory( app = application, configuration = configuration, cardTokenization = cardTokenization, - nativeAlternativePayment = nativeAlternativePayment, - nativeAlternativePaymentEventDispatcher = nativeAlternativePaymentEventDispatcher + nativeAlternativePayment = nativeAlternativePayment ) } diff --git a/ui/src/main/kotlin/com/processout/sdk/ui/checkout/DynamicCheckoutInteractor.kt b/ui/src/main/kotlin/com/processout/sdk/ui/checkout/DynamicCheckoutInteractor.kt index e8440fb7e..53c315336 100644 --- a/ui/src/main/kotlin/com/processout/sdk/ui/checkout/DynamicCheckoutInteractor.kt +++ b/ui/src/main/kotlin/com/processout/sdk/ui/checkout/DynamicCheckoutInteractor.kt @@ -11,9 +11,9 @@ import coil.request.ImageRequest import coil.request.ImageResult import com.processout.sdk.R import com.processout.sdk.api.dispatcher.POEventDispatcher -import com.processout.sdk.api.dispatcher.napm.PODefaultNativeAlternativePaymentMethodEventDispatcher import com.processout.sdk.api.model.event.PODynamicCheckoutEvent import com.processout.sdk.api.model.event.PODynamicCheckoutEvent.* +import com.processout.sdk.api.model.event.PONativeAlternativePaymentMethodEvent import com.processout.sdk.api.model.event.PONativeAlternativePaymentMethodEvent.WillSubmitParameters import com.processout.sdk.api.model.request.* import com.processout.sdk.api.model.response.* @@ -75,7 +75,6 @@ internal class DynamicCheckoutInteractor( private val googlePayService: POGooglePayService, private val cardTokenization: CardTokenizationViewModel, private val nativeAlternativePayment: NativeAlternativePaymentViewModel, - private val nativeAlternativePaymentEventDispatcher: PODefaultNativeAlternativePaymentMethodEventDispatcher, private val eventDispatcher: POEventDispatcher = POEventDispatcher, private var logAttributes: Map = logAttributes( invoiceId = configuration.invoiceRequest.invoiceId @@ -123,12 +122,11 @@ internal class DynamicCheckoutInteractor( private suspend fun start() { handleCompletions() - dispatchEvents() dispatchSideEffects() + collectEvents() collectInvoice() collectInvoiceAuthorizationRequest() collectTokenizedCard() - collectDefaultValues() collectSavedPaymentMethodsConfiguration() fetchConfiguration() } @@ -995,14 +993,7 @@ internal class DynamicCheckoutInteractor( } } - private fun dispatch(event: PODynamicCheckoutEvent) { - interactorScope.launch { - eventDispatcher.send(event) - POLogger.debug("Event has been sent: %s", event) - } - } - - private fun dispatchEvents() { + private fun collectEvents() { eventDispatcher.subscribeForRequest( coroutineScope = interactorScope ) { request -> @@ -1010,18 +1001,19 @@ internal class DynamicCheckoutInteractor( eventDispatcher.send(request.toResponse(shouldContinue = false)) } } - interactorScope.launch { - nativeAlternativePaymentEventDispatcher.events.collect { event -> - if (event is WillSubmitParameters) { - _state.update { it.copy(processingPaymentMethod = _state.value.selectedPaymentMethod) } - } - eventDispatcher.send(event) + eventDispatcher.subscribe( + coroutineScope = interactorScope + ) { event -> + if (event is WillSubmitParameters) { + _state.update { it.copy(processingPaymentMethod = _state.value.selectedPaymentMethod) } } } + } + + private fun dispatch(event: PODynamicCheckoutEvent) { interactorScope.launch { - nativeAlternativePaymentEventDispatcher.defaultValuesRequest.collect { request -> - eventDispatcher.send(request) - } + eventDispatcher.send(event) + POLogger.debug("Event has been sent: %s", event) } } @@ -1081,16 +1073,6 @@ internal class DynamicCheckoutInteractor( POLogger.debug("Deleted local customer token: %s", tokenId) } - private fun collectDefaultValues() { - eventDispatcher.subscribeForResponse( - coroutineScope = interactorScope - ) { response -> - interactorScope.launch { - nativeAlternativePaymentEventDispatcher.provideDefaultValues(response) - } - } - } - private fun cancel() { val failure = ProcessOutResult.Failure( code = Cancelled, diff --git a/ui/src/main/kotlin/com/processout/sdk/ui/checkout/DynamicCheckoutViewModel.kt b/ui/src/main/kotlin/com/processout/sdk/ui/checkout/DynamicCheckoutViewModel.kt index d3044b64d..91ecab1de 100644 --- a/ui/src/main/kotlin/com/processout/sdk/ui/checkout/DynamicCheckoutViewModel.kt +++ b/ui/src/main/kotlin/com/processout/sdk/ui/checkout/DynamicCheckoutViewModel.kt @@ -7,7 +7,6 @@ import androidx.lifecycle.viewModelScope import com.google.android.gms.wallet.Wallet.WalletOptions import com.processout.sdk.R import com.processout.sdk.api.ProcessOut -import com.processout.sdk.api.dispatcher.napm.PODefaultNativeAlternativePaymentMethodEventDispatcher import com.processout.sdk.api.model.response.PODynamicCheckoutPaymentMethod.Display import com.processout.sdk.api.service.googlepay.PODefaultGooglePayService import com.processout.sdk.ui.card.tokenization.CardTokenizationViewModel @@ -44,8 +43,7 @@ internal class DynamicCheckoutViewModel private constructor( private val app: Application, private val configuration: PODynamicCheckoutConfiguration, private val cardTokenization: CardTokenizationViewModel, - private val nativeAlternativePayment: NativeAlternativePaymentViewModel, - private val nativeAlternativePaymentEventDispatcher: PODefaultNativeAlternativePaymentMethodEventDispatcher + private val nativeAlternativePayment: NativeAlternativePaymentViewModel ) : ViewModelProvider.Factory { @Suppress("UNCHECKED_CAST") override fun create(modelClass: Class): T = @@ -63,8 +61,7 @@ internal class DynamicCheckoutViewModel private constructor( .build() ), cardTokenization = cardTokenization, - nativeAlternativePayment = nativeAlternativePayment, - nativeAlternativePaymentEventDispatcher = nativeAlternativePaymentEventDispatcher + nativeAlternativePayment = nativeAlternativePayment ) ) as T }