Skip to content

Commit

Permalink
Merge pull request #1353 from Adyen/refactor/amount
Browse files Browse the repository at this point in the history
Remove Amount.EMPTY
  • Loading branch information
jreij authored Oct 6, 2023
2 parents 5caf5de + d74aa65 commit b73deed
Show file tree
Hide file tree
Showing 130 changed files with 168 additions and 189 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Adyen3DS2Configuration private constructor(
override val environment: Environment,
override val clientKey: String,
override val analyticsConfiguration: AnalyticsConfiguration?,
override val amount: Amount,
override val amount: Amount?,
val uiCustomization: UiCustomization?,
val threeDSRequestorAppURL: String?,
) : Configuration {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ internal data class Adyen3DS2ComponentParams(
override val clientKey: String,
override val analyticsParams: AnalyticsParams,
override val isCreatedByDropIn: Boolean,
override val amount: Amount,
override val amount: Amount?,
val uiCustomization: UiCustomization?,
val threeDSRequestorAppURL: String?,
) : ComponentParams
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ internal class Adyen3DS2ComponentParamsMapperTest {
clientKey: String = TEST_CLIENT_KEY_1,
analyticsParams: AnalyticsParams = AnalyticsParams(AnalyticsParamsLevel.ALL),
isCreatedByDropIn: Boolean = false,
amount: Amount = Amount.EMPTY,
amount: Amount? = null,
uiCustomization: UiCustomization? = null,
threeDSRequestorAppURL: String? = null,
) = Adyen3DS2ComponentParams(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ACHDirectDebitConfiguration private constructor(
override val environment: Environment,
override val clientKey: String,
override val analyticsConfiguration: AnalyticsConfiguration?,
override val amount: Amount,
override val amount: Amount?,
override val isSubmitButtonVisible: Boolean?,
internal val genericActionConfiguration: GenericActionConfiguration,
val addressConfiguration: ACHDirectDebitAddressConfiguration?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import com.adyen.checkout.components.core.internal.PaymentObserverRepository
import com.adyen.checkout.components.core.internal.data.api.AnalyticsRepository
import com.adyen.checkout.components.core.internal.data.api.PublicKeyRepository
import com.adyen.checkout.components.core.internal.util.bufferedChannel
import com.adyen.checkout.components.core.internal.util.isEmpty
import com.adyen.checkout.components.core.paymentmethod.ACHDirectDebitPaymentMethod
import com.adyen.checkout.core.exception.CheckoutException
import com.adyen.checkout.core.exception.ComponentException
Expand Down Expand Up @@ -300,7 +299,7 @@ internal class DefaultACHDirectDebitDelegate(
order = order,
storePaymentMethod = if (showStorePaymentField()) outputData.shouldStorePaymentMethod else null,
paymentMethod = achPaymentMethod,
amount = componentParams.amount.takeUnless { it.isEmpty },
amount = componentParams.amount,
)

if (isAddressRequired(outputData.addressUIState)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import com.adyen.checkout.components.core.internal.data.api.AnalyticsRepository
import com.adyen.checkout.components.core.internal.ui.model.FieldState
import com.adyen.checkout.components.core.internal.ui.model.Validation
import com.adyen.checkout.components.core.internal.util.bufferedChannel
import com.adyen.checkout.components.core.internal.util.isEmpty
import com.adyen.checkout.components.core.paymentmethod.ACHDirectDebitPaymentMethod
import com.adyen.checkout.core.exception.CheckoutException
import com.adyen.checkout.core.internal.util.LogUtil
Expand Down Expand Up @@ -122,7 +121,7 @@ internal class StoredACHDirectDebitDelegate(
val paymentComponentData = PaymentComponentData(
paymentMethod = paymentMethod,
order = order,
amount = componentParams.amount.takeUnless { it.isEmpty },
amount = componentParams.amount,
)

return ACHDirectDebitComponentState(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ internal data class ACHDirectDebitComponentParams(
override val clientKey: String,
override val analyticsParams: AnalyticsParams,
override val isCreatedByDropIn: Boolean,
override val amount: Amount,
override val amount: Amount?,
override val isSubmitButtonVisible: Boolean,
val addressParams: AddressParams,
val isStorePaymentFieldVisible: Boolean,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,7 @@ internal class DefaultACHDirectDebitDelegateTest(
// configurationValue, expectedComponentStateValue
arguments(Amount("EUR", 100), Amount("EUR", 100)),
arguments(Amount("USD", 0), Amount("USD", 0)),
arguments(Amount.EMPTY, null),
arguments(null, null),
arguments(null, null),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ internal class StoredACHDirectDebitDelegateTest(
// configurationValue, expectedComponentStateValue
arguments(Amount("EUR", 100), Amount("EUR", 100)),
arguments(Amount("USD", 0), Amount("USD", 0)),
arguments(Amount.EMPTY, null),
arguments(null, null),
arguments(null, null),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ internal class ACHDirectDebitComponentParamsMapperTest {
clientKey: String = TEST_CLIENT_KEY_1,
analyticsParams: AnalyticsParams = AnalyticsParams(AnalyticsParamsLevel.ALL),
isCreatedByDropIn: Boolean = false,
amount: Amount = Amount.EMPTY,
amount: Amount? = null,
isSubmitButtonVisible: Boolean = true,
addressParams: AddressParams = AddressParams.FullAddress(
supportedCountryCodes = SUPPORTED_COUNTRY_LIST,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class GenericActionConfiguration private constructor(
override val environment: Environment,
override val clientKey: String,
override val analyticsConfiguration: AnalyticsConfiguration?,
override val amount: Amount,
override val amount: Amount?,
private val availableActionConfigs: HashMap<Class<*>, Configuration>,
) : Configuration {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ internal class TestActionDelegate :
override val environment: Environment = Environment.TEST
override val clientKey: String = ""
override val analyticsConfiguration: AnalyticsConfiguration? = null
override val amount: Amount = Amount.EMPTY
override val amount: Amount? = null

override fun describeContents(): Int {
throw NotImplementedError("This method shouldn't be used in tests")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class AwaitConfiguration private constructor(
override val environment: Environment,
override val clientKey: String,
override val analyticsConfiguration: AnalyticsConfiguration?,
override val amount: Amount
override val amount: Amount?
) : Configuration {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class BacsDirectDebitConfiguration private constructor(
override val environment: Environment,
override val clientKey: String,
override val analyticsConfiguration: AnalyticsConfiguration?,
override val amount: Amount,
override val amount: Amount?,
override val isSubmitButtonVisible: Boolean?,
internal val genericActionConfiguration: GenericActionConfiguration,
) : Configuration, ButtonConfiguration {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import com.adyen.checkout.components.core.internal.PaymentComponentEvent
import com.adyen.checkout.components.core.internal.PaymentObserverRepository
import com.adyen.checkout.components.core.internal.data.api.AnalyticsRepository
import com.adyen.checkout.components.core.internal.ui.model.ButtonComponentParams
import com.adyen.checkout.components.core.internal.util.isEmpty
import com.adyen.checkout.components.core.paymentmethod.BacsDirectDebitPaymentMethod
import com.adyen.checkout.core.internal.util.LogUtil
import com.adyen.checkout.core.internal.util.Logger
Expand Down Expand Up @@ -105,10 +104,12 @@ internal class DefaultBacsDirectDebitDelegate(
Logger.e(TAG, "Current mode is already $mode")
false
}

mode == BacsDirectDebitMode.CONFIRMATION && !outputData.isValid -> {
Logger.e(TAG, "Cannot set confirmation view when input is not valid")
false
}

else -> {
Logger.d(TAG, "Setting mode to $mode")
updateInputData { this.mode = mode }
Expand All @@ -133,6 +134,7 @@ internal class DefaultBacsDirectDebitDelegate(
submitHandler.onSubmit(state)
}
}

BacsDirectDebitMode.CONFIRMATION -> {
submitHandler.onSubmit(state)
}
Expand Down Expand Up @@ -199,7 +201,7 @@ internal class DefaultBacsDirectDebitDelegate(
shopperEmail = outputData.shopperEmailState.value,
paymentMethod = bacsDirectDebitPaymentMethod,
order = order,
amount = componentParams.amount.takeUnless { it.isEmpty },
amount = componentParams.amount,
)

return BacsDirectDebitComponentState(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import com.adyen.checkout.components.core.internal.ui.model.ButtonComponentParam
import com.adyen.checkout.components.core.internal.ui.model.FieldState
import com.adyen.checkout.components.core.internal.ui.model.Validation
import com.adyen.checkout.components.core.internal.util.CurrencyUtils
import com.adyen.checkout.components.core.internal.util.isEmpty
import com.adyen.checkout.core.internal.util.LogUtil
import com.adyen.checkout.core.internal.util.Logger
import com.adyen.checkout.ui.core.internal.ui.ComponentView
Expand Down Expand Up @@ -258,9 +257,10 @@ internal class BacsDirectDebitInputView @JvmOverloads constructor(
}

private fun setAmountConsentSwitchText(componentParams: ButtonComponentParams) {
if (!componentParams.amount.isEmpty) {
val amount = componentParams.amount
if (amount != null) {
val formattedAmount = CurrencyUtils.formatAmount(
componentParams.amount,
amount,
componentParams.shopperLocale
)
binding.switchConsentAmount.text =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ internal class DefaultBacsDirectDebitDelegateTest(
// configurationValue, expectedComponentStateValue
arguments(Amount("EUR", 100), Amount("EUR", 100)),
arguments(Amount("USD", 0), Amount("USD", 0)),
arguments(Amount.EMPTY, null),
arguments(null, null),
arguments(null, null),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class BcmcConfiguration private constructor(
override val environment: Environment,
override val clientKey: String,
override val analyticsConfiguration: AnalyticsConfiguration?,
override val amount: Amount,
override val amount: Amount?,
override val isSubmitButtonVisible: Boolean?,
val isHolderNameRequired: Boolean?,
val shopperReference: String?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import com.adyen.checkout.components.core.internal.data.api.PublicKeyRepository
import com.adyen.checkout.components.core.internal.ui.model.FieldState
import com.adyen.checkout.components.core.internal.ui.model.Validation
import com.adyen.checkout.components.core.internal.util.bufferedChannel
import com.adyen.checkout.components.core.internal.util.isEmpty
import com.adyen.checkout.components.core.paymentmethod.CardPaymentMethod
import com.adyen.checkout.core.exception.CheckoutException
import com.adyen.checkout.core.exception.ComponentException
Expand Down Expand Up @@ -238,7 +237,7 @@ internal class DefaultBcmcDelegate(
paymentMethod = cardPaymentMethod,
storePaymentMethod = if (showStorePaymentField()) outputData.shouldStorePaymentMethod else null,
shopperReference = componentParams.shopperReference,
amount = componentParams.amount.takeUnless { it.isEmpty },
amount = componentParams.amount,
)

return BcmcComponentState(paymentComponentData, isInputValid = true, isReady = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ internal data class BcmcComponentParams(
override val clientKey: String,
override val analyticsParams: AnalyticsParams,
override val isCreatedByDropIn: Boolean,
override val amount: Amount,
override val amount: Amount?,
override val isSubmitButtonVisible: Boolean,
val isHolderNameRequired: Boolean,
val shopperReference: String?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ internal class DefaultBcmcDelegateTest(
// configurationValue, expectedComponentStateValue
arguments(Amount("EUR", 100), Amount("EUR", 100)),
arguments(Amount("USD", 0), Amount("USD", 0)),
arguments(Amount.EMPTY, null),
arguments(null, null),
arguments(null, null),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ internal class BcmcComponentParamsMapperTest {
clientKey: String = TEST_CLIENT_KEY_1,
analyticsParams: AnalyticsParams = AnalyticsParams(AnalyticsParamsLevel.ALL),
isCreatedByDropIn: Boolean = false,
amount: Amount = Amount.EMPTY,
amount: Amount? = null,
isSubmitButtonVisible: Boolean = true,
isHolderNameRequired: Boolean = false,
shopperReference: String? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class BlikConfiguration private constructor(
override val environment: Environment,
override val clientKey: String,
override val analyticsConfiguration: AnalyticsConfiguration?,
override val amount: Amount,
override val amount: Amount?,
override val isSubmitButtonVisible: Boolean?,
internal val genericActionConfiguration: GenericActionConfiguration,
) : Configuration, ButtonConfiguration {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import com.adyen.checkout.components.core.internal.PaymentComponentEvent
import com.adyen.checkout.components.core.internal.PaymentObserverRepository
import com.adyen.checkout.components.core.internal.data.api.AnalyticsRepository
import com.adyen.checkout.components.core.internal.ui.model.ButtonComponentParams
import com.adyen.checkout.components.core.internal.util.isEmpty
import com.adyen.checkout.components.core.paymentmethod.BlikPaymentMethod
import com.adyen.checkout.core.internal.util.LogUtil
import com.adyen.checkout.core.internal.util.Logger
Expand Down Expand Up @@ -140,7 +139,7 @@ internal class DefaultBlikDelegate(
val paymentComponentData = PaymentComponentData(
paymentMethod = paymentMethod,
order = order,
amount = componentParams.amount.takeUnless { it.isEmpty },
amount = componentParams.amount,
)

return BlikComponentState(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import com.adyen.checkout.components.core.internal.PaymentComponentEvent
import com.adyen.checkout.components.core.internal.PaymentObserverRepository
import com.adyen.checkout.components.core.internal.data.api.AnalyticsRepository
import com.adyen.checkout.components.core.internal.ui.model.ButtonComponentParams
import com.adyen.checkout.components.core.internal.util.isEmpty
import com.adyen.checkout.components.core.paymentmethod.BlikPaymentMethod
import com.adyen.checkout.core.internal.util.LogUtil
import com.adyen.checkout.core.internal.util.Logger
Expand Down Expand Up @@ -118,7 +117,7 @@ internal class StoredBlikDelegate(
val paymentComponentData = PaymentComponentData(
paymentMethod = paymentMethod,
order = order,
amount = componentParams.amount.takeUnless { it.isEmpty },
amount = componentParams.amount,
)

return BlikComponentState(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ internal class DefaultBlikDelegateTest(
// configurationValue, expectedComponentStateValue
arguments(Amount("EUR", 100), Amount("EUR", 100)),
arguments(Amount("USD", 0), Amount("USD", 0)),
arguments(Amount.EMPTY, null),
arguments(null, null),
arguments(null, null),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class BoletoConfiguration private constructor(
override val environment: Environment,
override val clientKey: String,
override val analyticsConfiguration: AnalyticsConfiguration?,
override val amount: Amount,
override val amount: Amount?,
override val isSubmitButtonVisible: Boolean?,
val genericActionConfiguration: GenericActionConfiguration,
val isEmailVisible: Boolean?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import com.adyen.checkout.components.core.ShopperName
import com.adyen.checkout.components.core.internal.PaymentComponentEvent
import com.adyen.checkout.components.core.internal.PaymentObserverRepository
import com.adyen.checkout.components.core.internal.data.api.AnalyticsRepository
import com.adyen.checkout.components.core.internal.util.isEmpty
import com.adyen.checkout.components.core.paymentmethod.GenericPaymentMethod
import com.adyen.checkout.core.internal.util.LogUtil
import com.adyen.checkout.core.internal.util.Logger
Expand Down Expand Up @@ -238,7 +237,7 @@ internal class DefaultBoletoDelegate(
checkoutAttemptId = analyticsRepository.getCheckoutAttemptId(),
),
order = order,
amount = componentParams.amount.takeUnless { it.isEmpty },
amount = componentParams.amount,
socialSecurityNumber = outputData.socialSecurityNumberState.value,
shopperName = ShopperName(
firstName = outputData.firstNameState.value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ internal data class BoletoComponentParams(
override val clientKey: String,
override val analyticsParams: AnalyticsParams,
override val isCreatedByDropIn: Boolean,
override val amount: Amount,
override val amount: Amount?,
val addressParams: AddressParams,
val isEmailVisible: Boolean,
) : ComponentParams, ButtonParams
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ internal class DefaultBoletoDelegateTest(
// configurationValue, expectedComponentStateValue
Arguments.arguments(Amount("EUR", 100), Amount("EUR", 100)),
Arguments.arguments(Amount("USD", 0), Amount("USD", 0)),
Arguments.arguments(Amount.EMPTY, null),
Arguments.arguments(null, null),
Arguments.arguments(null, null),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ internal class BoletoComponentParamsMapperTest {
clientKey: String = TEST_CLIENT_KEY_1,
analyticsParams: AnalyticsParams = AnalyticsParams(AnalyticsParamsLevel.ALL),
isCreatedByDropIn: Boolean = false,
amount: Amount = Amount.EMPTY,
amount: Amount? = null,
addressParams: AddressParams = AddressParams.FullAddress(
defaultCountryCode = BRAZIL_COUNTRY_CODE,
supportedCountryCodes = SUPPORTED_COUNTRY_LIST_1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class CardConfiguration private constructor(
override val environment: Environment,
override val clientKey: String,
override val analyticsConfiguration: AnalyticsConfiguration?,
override val amount: Amount,
override val amount: Amount?,
override val isSubmitButtonVisible: Boolean?,
val isHolderNameRequired: Boolean?,
val supportedCardBrands: List<CardBrand>?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ import com.adyen.checkout.components.core.internal.data.api.PublicKeyRepository
import com.adyen.checkout.components.core.internal.ui.model.FieldState
import com.adyen.checkout.components.core.internal.ui.model.Validation
import com.adyen.checkout.components.core.internal.util.bufferedChannel
import com.adyen.checkout.components.core.internal.util.isEmpty
import com.adyen.checkout.components.core.paymentmethod.CardPaymentMethod
import com.adyen.checkout.core.exception.CheckoutException
import com.adyen.checkout.core.exception.ComponentException
Expand Down Expand Up @@ -704,7 +703,7 @@ internal class DefaultCardDelegate(
storePaymentMethod = if (showStorePaymentField()) stateOutputData.shouldStorePaymentMethod else null,
shopperReference = componentParams.shopperReference,
order = order,
amount = componentParams.amount.takeUnless { it.isEmpty },
amount = componentParams.amount,
).apply {
if (isSocialSecurityNumberRequired()) {
socialSecurityNumber = stateOutputData.socialSecurityNumberState.value
Expand Down
Loading

0 comments on commit b73deed

Please sign in to comment.