Skip to content
Merged
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 @@ -51,7 +51,7 @@ internal class CardTokenizationBottomSheet : BaseBottomSheetDialogFragment<POCar
CardTokenizationViewModel.Factory(
app = requireActivity().application,
configuration = configuration,
eventDispatcher = PODefaultEventDispatchers.defaultCardTokenization
legacyEventDispatcher = PODefaultEventDispatchers.defaultCardTokenization
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ internal class CardTokenizationInteractor(
private val cardsRepository: POCardsRepository,
private val cardSchemeProvider: CardSchemeProvider,
private val addressSpecificationProvider: AddressSpecificationProvider,
private val legacyEventDispatcher: PODefaultCardTokenizationEventDispatcher, // TODO: remove before next major release.
private val legacyEventDispatcher: PODefaultCardTokenizationEventDispatcher?, // TODO: remove before next major release.
private val eventDispatcher: POEventDispatcher = POEventDispatcher
) : BaseInteractor() {

Expand Down Expand Up @@ -378,7 +378,7 @@ internal class CardTokenizationInteractor(
private suspend fun requestPreferredScheme(issuerInformation: POCardIssuerInformation) {
val request = POCardTokenizationPreferredSchemeRequest(issuerInformation)
latestPreferredSchemeRequest = request
if (legacyEventDispatcher.subscribedForPreferredSchemeRequest()) {
if (legacyEventDispatcher?.subscribedForPreferredSchemeRequest() == true) {
legacyEventDispatcher.send(request)
} else {
eventDispatcher.send(request)
Expand All @@ -388,7 +388,7 @@ internal class CardTokenizationInteractor(

private fun collectPreferredScheme() {
interactorScope.launch {
legacyEventDispatcher.preferredSchemeResponse.collect { response ->
legacyEventDispatcher?.preferredSchemeResponse?.collect { response ->
handlePreferredScheme(response)
}
}
Expand Down Expand Up @@ -696,9 +696,9 @@ internal class CardTokenizationInteractor(
card = card,
saveCard = _state.value.saveCardField.value.text.toBooleanStrictOrNull() ?: false
)
if (legacyEventDispatcher.subscribedForProcessTokenizedCard()) {
if (legacyEventDispatcher?.subscribedForProcessTokenizedCard() == true) {
legacyEventDispatcher.processTokenizedCard(card)
} else if (legacyEventDispatcher.subscribedForProcessTokenizedCardRequest()) {
} else if (legacyEventDispatcher?.subscribedForProcessTokenizedCardRequest() == true) {
legacyEventDispatcher.processTokenizedCardRequest(request)
} else {
eventDispatcher.send(request)
Expand All @@ -711,7 +711,7 @@ internal class CardTokenizationInteractor(

private fun handleCompletion() {
interactorScope.launch {
legacyEventDispatcher.completion.collect { result ->
legacyEventDispatcher?.completion?.collect { result ->
result.onSuccess {
_state.value.tokenizedCard?.let { card ->
complete(Success(card))
Expand Down Expand Up @@ -752,7 +752,7 @@ internal class CardTokenizationInteractor(
interactorScope.launch {
val request = POCardTokenizationShouldContinueRequest(failure)
latestShouldContinueRequest = request
if (legacyEventDispatcher.subscribedForShouldContinueRequest()) {
if (legacyEventDispatcher?.subscribedForShouldContinueRequest() == true) {
legacyEventDispatcher.send(request)
} else {
eventDispatcher.send(request)
Expand All @@ -763,7 +763,7 @@ internal class CardTokenizationInteractor(

private fun shouldContinueOnFailure() {
interactorScope.launch {
legacyEventDispatcher.shouldContinueResponse.collect { response ->
legacyEventDispatcher?.shouldContinueResponse?.collect { response ->
handleShouldContinue(response)
}
}
Expand Down Expand Up @@ -898,7 +898,7 @@ internal class CardTokenizationInteractor(

private fun dispatch(event: POCardTokenizationEvent) {
interactorScope.launch {
legacyEventDispatcher.send(event)
legacyEventDispatcher?.send(event)
eventDispatcher.send(event)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ internal class CardTokenizationViewModel private constructor(
class Factory(
private val app: Application,
private val configuration: POCardTokenizationConfiguration,
private val eventDispatcher: PODefaultCardTokenizationEventDispatcher
private val legacyEventDispatcher: PODefaultCardTokenizationEventDispatcher?
) : ViewModelProvider.Factory {
@Suppress("UNCHECKED_CAST")
override fun <T : ViewModel> create(modelClass: Class<T>): T =
Expand All @@ -55,7 +55,7 @@ internal class CardTokenizationViewModel private constructor(
cardsRepository = ProcessOut.instance.cards,
cardSchemeProvider = CardSchemeProvider(),
addressSpecificationProvider = AddressSpecificationProvider(app),
legacyEventDispatcher = eventDispatcher
legacyEventDispatcher = legacyEventDispatcher
)
) as T
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.card.tokenization.PODefaultCardTokenizationEventDispatcher
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
Expand Down Expand Up @@ -67,12 +66,11 @@ internal class DynamicCheckoutActivity : BaseTransparentPortraitActivity() {
private lateinit var configuration: PODynamicCheckoutConfiguration

private val viewModel: DynamicCheckoutViewModel by viewModels {
val cardTokenizationEventDispatcher = PODefaultCardTokenizationEventDispatcher()
val cardTokenization: CardTokenizationViewModel by viewModels {
CardTokenizationViewModel.Factory(
app = application,
configuration = cardTokenizationConfiguration(),
eventDispatcher = cardTokenizationEventDispatcher
legacyEventDispatcher = null
)
}
val nativeAlternativePaymentEventDispatcher = PODefaultNativeAlternativePaymentMethodEventDispatcher()
Expand All @@ -87,7 +85,6 @@ internal class DynamicCheckoutActivity : BaseTransparentPortraitActivity() {
app = application,
configuration = configuration,
cardTokenization = cardTokenization,
cardTokenizationEventDispatcher = cardTokenizationEventDispatcher,
nativeAlternativePayment = nativeAlternativePayment,
nativeAlternativePaymentEventDispatcher = nativeAlternativePaymentEventDispatcher
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ 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.card.tokenization.PODefaultCardTokenizationEventDispatcher
import com.processout.sdk.api.dispatcher.napm.PODefaultNativeAlternativePaymentMethodEventDispatcher
import com.processout.sdk.api.model.event.PODynamicCheckoutEvent
import com.processout.sdk.api.model.event.PODynamicCheckoutEvent.*
Expand Down Expand Up @@ -75,7 +74,6 @@ internal class DynamicCheckoutInteractor(
private val invoicesService: POInvoicesService,
private val googlePayService: POGooglePayService,
private val cardTokenization: CardTokenizationViewModel,
private val cardTokenizationEventDispatcher: PODefaultCardTokenizationEventDispatcher,
private val nativeAlternativePayment: NativeAlternativePaymentViewModel,
private val nativeAlternativePaymentEventDispatcher: PODefaultNativeAlternativePaymentMethodEventDispatcher,
private val eventDispatcher: POEventDispatcher = POEventDispatcher,
Expand Down Expand Up @@ -105,6 +103,7 @@ internal class DynamicCheckoutInteractor(

private var authorizeInvoiceJob: AuthorizeInvoiceJob? = null
private var latestInvoiceRequest: PODynamicCheckoutInvoiceRequest? = null
private var latestCardProcessingRequest: POCardTokenizationProcessingRequest? = null

init {
interactorScope.launch {
Expand All @@ -129,7 +128,6 @@ internal class DynamicCheckoutInteractor(
collectInvoice()
collectInvoiceAuthorizationRequest()
collectTokenizedCard()
collectPreferredScheme()
collectDefaultValues()
collectSavedPaymentMethodsConfiguration()
fetchConfiguration()
Expand Down Expand Up @@ -860,17 +858,18 @@ internal class DynamicCheckoutInteractor(
}

private fun collectTokenizedCard() {
interactorScope.launch {
cardTokenizationEventDispatcher.processTokenizedCardRequest.collect { request ->
_state.value.selectedPaymentMethod?.let { paymentMethod ->
_state.update { it.copy(processingPaymentMethod = paymentMethod) }
authorizeInvoice(
paymentMethod = paymentMethod,
source = request.card.id,
saveSource = request.saveCard,
clientSecret = configuration.invoiceRequest.clientSecret
)
}
eventDispatcher.subscribeForRequest<POCardTokenizationProcessingRequest>(
coroutineScope = interactorScope
) { request ->
_state.value.selectedPaymentMethod?.let { paymentMethod ->
_state.update { it.copy(processingPaymentMethod = paymentMethod) }
latestCardProcessingRequest = request
authorizeInvoice(
paymentMethod = paymentMethod,
source = request.card.id,
saveSource = request.saveCard,
clientSecret = configuration.invoiceRequest.clientSecret
)
}
}
}
Expand Down Expand Up @@ -930,8 +929,11 @@ internal class DynamicCheckoutInteractor(
return
}
when (state.processingPaymentMethod) {
is Card -> interactorScope.launch {
cardTokenizationEventDispatcher.complete(result)
is Card -> latestCardProcessingRequest?.let { request ->
interactorScope.launch {
latestCardProcessingRequest = null
eventDispatcher.send(request.toResponse(result))
}
}
is GooglePay,
is AlternativePayment,
Expand Down Expand Up @@ -1001,12 +1003,11 @@ internal class DynamicCheckoutInteractor(
}

private fun dispatchEvents() {
interactorScope.launch {
cardTokenizationEventDispatcher.events.collect { eventDispatcher.send(it) }
}
interactorScope.launch {
cardTokenizationEventDispatcher.preferredSchemeRequest.collect { request ->
eventDispatcher.send(request)
eventDispatcher.subscribeForRequest<POCardTokenizationShouldContinueRequest>(
coroutineScope = interactorScope
) { request ->
interactorScope.launch {
eventDispatcher.send(request.toResponse(shouldContinue = false))
}
}
interactorScope.launch {
Expand Down Expand Up @@ -1080,16 +1081,6 @@ internal class DynamicCheckoutInteractor(
POLogger.debug("Deleted local customer token: %s", tokenId)
}

private fun collectPreferredScheme() {
eventDispatcher.subscribeForResponse<POCardTokenizationPreferredSchemeResponse>(
coroutineScope = interactorScope
) { response ->
interactorScope.launch {
cardTokenizationEventDispatcher.preferredScheme(response)
}
}
}

private fun collectDefaultValues() {
eventDispatcher.subscribeForResponse<PONativeAlternativePaymentMethodDefaultValuesResponse>(
coroutineScope = interactorScope
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.card.tokenization.PODefaultCardTokenizationEventDispatcher
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
Expand Down Expand Up @@ -45,7 +44,6 @@ internal class DynamicCheckoutViewModel private constructor(
private val app: Application,
private val configuration: PODynamicCheckoutConfiguration,
private val cardTokenization: CardTokenizationViewModel,
private val cardTokenizationEventDispatcher: PODefaultCardTokenizationEventDispatcher,
private val nativeAlternativePayment: NativeAlternativePaymentViewModel,
private val nativeAlternativePaymentEventDispatcher: PODefaultNativeAlternativePaymentMethodEventDispatcher
) : ViewModelProvider.Factory {
Expand All @@ -65,7 +63,6 @@ internal class DynamicCheckoutViewModel private constructor(
.build()
),
cardTokenization = cardTokenization,
cardTokenizationEventDispatcher = cardTokenizationEventDispatcher,
nativeAlternativePayment = nativeAlternativePayment,
nativeAlternativePaymentEventDispatcher = nativeAlternativePaymentEventDispatcher
)
Expand Down