-
Notifications
You must be signed in to change notification settings - Fork 65
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 #1331 from Adyen/refactor/bcmc
Refactor BCMC
- Loading branch information
Showing
43 changed files
with
473 additions
and
1,422 deletions.
There are no files selected for viewing
90 changes: 10 additions & 80 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,106 +1,36 @@ | ||
/* | ||
* Copyright (c) 2019 Adyen N.V. | ||
* Copyright (c) 2023 Adyen N.V. | ||
* | ||
* This file is open source and available under the MIT license. See the LICENSE file for more info. | ||
* | ||
* Created by arman on 18/9/2019. | ||
* Created by ozgur on 22/8/2023. | ||
*/ | ||
|
||
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.bcmc.internal.ui.BcmcDelegate | ||
import com.adyen.checkout.card.CardBrand | ||
import com.adyen.checkout.card.CardType | ||
import com.adyen.checkout.card.CardComponent | ||
import com.adyen.checkout.card.internal.ui.CardDelegate | ||
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 internal constructor( | ||
private val bcmcDelegate: BcmcDelegate, | ||
private val genericActionDelegate: GenericActionDelegate, | ||
private val actionHandlingComponent: DefaultActionHandlingComponent, | ||
class BcmcComponent( | ||
cardDelegate: CardDelegate, | ||
genericActionDelegate: GenericActionDelegate, | ||
actionHandlingComponent: DefaultActionHandlingComponent, | ||
internal val componentEventHandler: ComponentEventHandler<BcmcComponentState>, | ||
) : 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() | ||
} | ||
|
||
) : CardComponent(cardDelegate, genericActionDelegate, actionHandlingComponent, componentEventHandler) { | ||
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.