-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1385 from Adyen/revert-1331-refactor/bcmc
Revert "Refactor BCMC"
- Loading branch information
Showing
43 changed files
with
1,422 additions
and
473 deletions.
There are no files selected for viewing
90 changes: 80 additions & 10 deletions
90
bcmc/src/main/java/com/adyen/checkout/bcmc/BcmcComponent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,106 @@ | ||
/* | ||
* Copyright (c) 2023 Adyen N.V. | ||
* Copyright (c) 2019 Adyen N.V. | ||
* | ||
* This file is open source and available under the MIT license. See the LICENSE file for more info. | ||
* | ||
* Created by ozgur on 22/8/2023. | ||
* Created by arman on 18/9/2019. | ||
*/ | ||
|
||
package com.adyen.checkout.bcmc | ||
|
||
import androidx.lifecycle.LifecycleOwner | ||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import com.adyen.checkout.action.core.internal.ActionHandlingComponent | ||
import com.adyen.checkout.action.core.internal.DefaultActionHandlingComponent | ||
import com.adyen.checkout.action.core.internal.ui.GenericActionDelegate | ||
import com.adyen.checkout.bcmc.internal.provider.BcmcComponentProvider | ||
import com.adyen.checkout.card.CardComponent | ||
import com.adyen.checkout.card.internal.ui.CardDelegate | ||
import com.adyen.checkout.bcmc.internal.ui.BcmcDelegate | ||
import com.adyen.checkout.card.CardBrand | ||
import com.adyen.checkout.card.CardType | ||
import com.adyen.checkout.components.core.PaymentMethodTypes | ||
import com.adyen.checkout.components.core.internal.ButtonComponent | ||
import com.adyen.checkout.components.core.internal.ComponentEventHandler | ||
import com.adyen.checkout.components.core.internal.PaymentComponent | ||
import com.adyen.checkout.components.core.internal.PaymentComponentEvent | ||
import com.adyen.checkout.components.core.internal.toActionCallback | ||
import com.adyen.checkout.components.core.internal.ui.ComponentDelegate | ||
import com.adyen.checkout.core.internal.util.LogUtil | ||
import com.adyen.checkout.core.internal.util.Logger | ||
import com.adyen.checkout.ui.core.internal.ui.ButtonDelegate | ||
import com.adyen.checkout.ui.core.internal.ui.ComponentViewType | ||
import com.adyen.checkout.ui.core.internal.ui.ViewableComponent | ||
import com.adyen.checkout.ui.core.internal.util.mergeViewFlows | ||
import kotlinx.coroutines.flow.Flow | ||
|
||
/** | ||
* A [PaymentComponent] that supports the [PaymentMethodTypes.BCMC] payment method. | ||
*/ | ||
class BcmcComponent( | ||
cardDelegate: CardDelegate, | ||
genericActionDelegate: GenericActionDelegate, | ||
actionHandlingComponent: DefaultActionHandlingComponent, | ||
class BcmcComponent internal constructor( | ||
private val bcmcDelegate: BcmcDelegate, | ||
private val genericActionDelegate: GenericActionDelegate, | ||
private val actionHandlingComponent: DefaultActionHandlingComponent, | ||
internal val componentEventHandler: ComponentEventHandler<BcmcComponentState>, | ||
) : CardComponent(cardDelegate, genericActionDelegate, actionHandlingComponent, componentEventHandler) { | ||
) : ViewModel(), | ||
PaymentComponent, | ||
ViewableComponent, | ||
ButtonComponent, | ||
ActionHandlingComponent by actionHandlingComponent { | ||
|
||
override val delegate: ComponentDelegate get() = actionHandlingComponent.activeDelegate | ||
|
||
override val viewFlow: Flow<ComponentViewType?> = mergeViewFlows( | ||
viewModelScope, | ||
bcmcDelegate.viewFlow, | ||
genericActionDelegate.viewFlow, | ||
) | ||
|
||
init { | ||
bcmcDelegate.initialize(viewModelScope) | ||
genericActionDelegate.initialize(viewModelScope) | ||
componentEventHandler.initialize(viewModelScope) | ||
} | ||
|
||
internal fun observe( | ||
lifecycleOwner: LifecycleOwner, | ||
callback: (PaymentComponentEvent<BcmcComponentState>) -> Unit | ||
) { | ||
bcmcDelegate.observe(lifecycleOwner, viewModelScope, callback) | ||
genericActionDelegate.observe(lifecycleOwner, viewModelScope, callback.toActionCallback()) | ||
} | ||
|
||
internal fun removeObserver() { | ||
bcmcDelegate.removeObserver() | ||
genericActionDelegate.removeObserver() | ||
} | ||
|
||
override fun isConfirmationRequired(): Boolean = bcmcDelegate.isConfirmationRequired() | ||
|
||
override fun submit() { | ||
(delegate as? ButtonDelegate)?.onSubmit() ?: Logger.e(TAG, "Component is currently not submittable, ignoring.") | ||
} | ||
|
||
override fun setInteractionBlocked(isInteractionBlocked: Boolean) { | ||
(delegate as? BcmcDelegate)?.setInteractionBlocked(isInteractionBlocked) | ||
?: Logger.e(TAG, "Payment component is not interactable, ignoring.") | ||
} | ||
|
||
override fun onCleared() { | ||
super.onCleared() | ||
Logger.d(TAG, "onCleared") | ||
bcmcDelegate.onCleared() | ||
genericActionDelegate.onCleared() | ||
componentEventHandler.onCleared() | ||
} | ||
|
||
companion object { | ||
private val TAG = LogUtil.getTag() | ||
|
||
@JvmField | ||
val PROVIDER = BcmcComponentProvider() | ||
|
||
@JvmField | ||
val PAYMENT_METHOD_TYPES = listOf(PaymentMethodTypes.BCMC) | ||
|
||
internal val SUPPORTED_CARD_TYPE = CardBrand(cardType = CardType.BCMC) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.