Skip to content

Commit

Permalink
Display pay button in components if created by drop in
Browse files Browse the repository at this point in the history
COAND-838
  • Loading branch information
ozgur00 committed May 3, 2024
1 parent 35c30ea commit fc7ec91
Show file tree
Hide file tree
Showing 17 changed files with 231 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,23 @@ internal class ACHDirectDebitComponentParamsMapper(
commonComponentParamsMapperData.commonComponentParams,
commonComponentParamsMapperData.sessionParams,
achDirectDebitConfiguration,
commonComponentParamsMapperData.commonComponentParams.isCreatedByDropIn,
)
}

private fun mapToParams(
commonComponentParams: CommonComponentParams,
sessionParams: SessionParams?,
achDirectDebitConfiguration: ACHDirectDebitConfiguration?,
isCreatedByDropIn: Boolean
): ACHDirectDebitComponentParams {
return ACHDirectDebitComponentParams(
commonComponentParams = commonComponentParams,
isSubmitButtonVisible = achDirectDebitConfiguration?.isSubmitButtonVisible ?: true,
isSubmitButtonVisible = if (isCreatedByDropIn) {
true
} else {
achDirectDebitConfiguration?.isSubmitButtonVisible ?: true
},
addressParams = achDirectDebitConfiguration?.addressConfiguration?.mapToAddressParam()
?: AddressParams.FullAddress(
supportedCountryCodes = DEFAULT_SUPPORTED_COUNTRY_LIST,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,27 @@ internal class ACHDirectDebitComponentParamsMapperTest {
assertEquals(expected, params)
}

@Test
fun `when setSubmitButtonVisible is set to false in ach configuration and drop-in override params are set then card component params should have isSubmitButtonVisible true`() {
val configuration = CheckoutConfiguration(
environment = Environment.EUROPE,
clientKey = TEST_CLIENT_KEY_2,
) {
achDirectDebit {
setSubmitButtonVisible(false)
}
}
val dropInOverrideParams = DropInOverrideParams(Amount("EUR", 123L), null)
val params = achDirectDebitComponentParamsMapper.mapToParams(
checkoutConfiguration = configuration,
deviceLocale = DEVICE_LOCALE,
dropInOverrideParams = dropInOverrideParams,
componentSessionParams = null,
)

assertEquals(true, params.isSubmitButtonVisible)
}

@Test
fun `when a address is selected as FullAddress, addressParams should return FullAddress`() {
val addressConfiguration =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ internal class BcmcComponentParamsMapper(
commonComponentParamsMapperData.sessionParams,
bcmcConfiguration,
paymentMethod,
commonComponentParamsMapperData.commonComponentParams.isCreatedByDropIn,
)
}

Expand All @@ -57,10 +58,11 @@ internal class BcmcComponentParamsMapper(
sessionParams: SessionParams?,
bcmcConfiguration: BcmcConfiguration?,
paymentMethod: PaymentMethod,
isCreatedByDropIn: Boolean
): CardComponentParams {
return CardComponentParams(
commonComponentParams = commonComponentParams,
isSubmitButtonVisible = bcmcConfiguration?.isSubmitButtonVisible ?: true,
isSubmitButtonVisible = if (isCreatedByDropIn) true else bcmcConfiguration?.isSubmitButtonVisible ?: true,
isHolderNameRequired = bcmcConfiguration?.isHolderNameRequired ?: false,
shopperReference = bcmcConfiguration?.shopperReference,
isStorePaymentFieldVisible = getStorePaymentFieldVisible(sessionParams, bcmcConfiguration),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,29 @@ internal class BcmcComponentParamsMapperTest {
assertEquals(expected, params)
}

@Test
fun `when setSubmitButtonVisible is set to false in bcmc configuration and drop-in override params are set then card component params should have isSubmitButtonVisible true`() {
val configuration = CheckoutConfiguration(
environment = Environment.EUROPE,
clientKey = TEST_CLIENT_KEY_2,
) {
bcmc {
setSubmitButtonVisible(false)
}
}

val dropInOverrideParams = DropInOverrideParams(Amount("CAD", 123L), null)
val params = bcmcComponentParamsMapper.mapToParams(
configuration,
DEVICE_LOCALE,
dropInOverrideParams,
null,
PaymentMethod(),
)

assertEquals(true, params.isSubmitButtonVisible)
}

@ParameterizedTest
@MethodSource("enableStoreDetailsSource")
@Suppress("MaxLineLength")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ internal class BoletoComponentParamsMapper(

return BoletoComponentParams(
commonComponentParams = commonComponentParams,
isSubmitButtonVisible = boletoConfiguration?.isSubmitButtonVisible ?: true,
isSubmitButtonVisible = if (commonComponentParams.isCreatedByDropIn) {
true
} else {
boletoConfiguration?.isSubmitButtonVisible ?: true
},
addressParams = AddressParams.FullAddress(
defaultCountryCode = BRAZIL_COUNTRY_CODE,
supportedCountryCodes = DEFAULT_SUPPORTED_COUNTRY_LIST,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,26 @@ internal class BoletoComponentParamsMapperTest {
assertEquals(expected, params)
}

@Test
fun `when setSubmitButtonVisible is set to false in boleto configuration and drop-in override params are set then card component params should have isSubmitButtonVisible true`() {
val configuration = CheckoutConfiguration(
environment = Environment.EUROPE,
clientKey = TEST_CLIENT_KEY_2,
) {
boleto {
setSubmitButtonVisible(false)
}
}

val dropInOverrideParams = DropInOverrideParams(Amount("EUR", 20L), null)
val params = mapParams(
configuration = configuration,
dropInOverrideParams = dropInOverrideParams,
)

assertEquals(true, params.isSubmitButtonVisible)
}

@Test
fun `when send email is set, them params should match`() {
val configuration = createCheckoutConfiguration {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ internal class CardComponentParamsMapper(
commonComponentParamsMapperData.sessionParams,
cardConfiguration,
paymentMethod,
commonComponentParamsMapperData.commonComponentParams.isCreatedByDropIn,
)
}

Expand All @@ -93,11 +94,12 @@ internal class CardComponentParamsMapper(
sessionParams: SessionParams?,
cardConfiguration: CardConfiguration?,
paymentMethod: PaymentMethod?,
isCreatedByDropIn: Boolean
): CardComponentParams {
return CardComponentParams(
commonComponentParams = commonComponentParams,
isHolderNameRequired = cardConfiguration?.isHolderNameRequired ?: false,
isSubmitButtonVisible = cardConfiguration?.isSubmitButtonVisible ?: true,
isSubmitButtonVisible = if (isCreatedByDropIn) true else cardConfiguration?.isSubmitButtonVisible ?: true,
supportedCardBrands = getSupportedCardBrands(cardConfiguration, paymentMethod),
shopperReference = cardConfiguration?.shopperReference,
isStorePaymentFieldVisible = getStorePaymentFieldVisible(sessionParams, cardConfiguration),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,28 @@ internal class CardComponentParamsMapperTest {
assertEquals(expected, params)
}

@Test
fun `when setSubmitButtonVisible is set to false in card configuration and drop-in override params are set then card component params should have isSubmitButtonVisible true`() {
val configuration = CheckoutConfiguration(
environment = Environment.EUROPE,
clientKey = TEST_CLIENT_KEY_2,
) {
card {
setSubmitButtonVisible(false)
}
}
val dropInOverrideParams = DropInOverrideParams(Amount("EUR", 123L), null)
val params = cardComponentParamsMapper.mapToParams(
checkoutConfiguration = configuration,
deviceLocale = DEVICE_LOCALE,
dropInOverrideParams = dropInOverrideParams,
componentSessionParams = null,
paymentMethod = PaymentMethod(),
)

assertEquals(true, params.isSubmitButtonVisible)
}

@Test
fun `when supported card types are set in the card configuration then they should be used in the params`() {
val configuration = createCheckoutConfiguration {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ internal class CashAppPayComponentParamsMapper(
clientId = clientId,
scopeId = scopeId,
context = context,
isCreatedByDropIn = dropInOverrideParams != null,
)

if (params.returnUrl == null) {
Expand Down Expand Up @@ -97,6 +98,7 @@ internal class CashAppPayComponentParamsMapper(
clientId = null,
scopeId = null,
context = context,
isCreatedByDropIn = commonComponentParamsMapperData.commonComponentParams.isCreatedByDropIn,
)
}

Expand All @@ -108,10 +110,15 @@ internal class CashAppPayComponentParamsMapper(
clientId: String?,
scopeId: String?,
context: Context,
isCreatedByDropIn: Boolean
): CashAppPayComponentParams {
return CashAppPayComponentParams(
commonComponentParams = commonComponentParams,
isSubmitButtonVisible = cashAppPayConfiguration?.isSubmitButtonVisible ?: true,
isSubmitButtonVisible = if (isCreatedByDropIn) {
true
} else {
cashAppPayConfiguration?.isSubmitButtonVisible ?: true
},
cashAppPayEnvironment = getCashAppPayEnvironment(
commonComponentParams.environment,
cashAppPayConfiguration,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,39 @@ internal class CashAppPayComponentParamsMapperTest {
assertEquals(expected, params)
}

@Test
fun `when setSubmitButtonVisible is set to false in cash app configuration and drop-in override params are set then card component params should have isSubmitButtonVisible true`() {
val configuration = CheckoutConfiguration(
shopperLocale = Locale.GERMAN,
environment = Environment.EUROPE,
clientKey = TEST_CLIENT_KEY_2,
amount = Amount(
currency = "CAD",
value = 1235_00L,
),
analyticsConfiguration = AnalyticsConfiguration(AnalyticsLevel.NONE),
) {
cashAppPay {
setReturnUrl(TEST_RETURN_URL)
setAmount(Amount("USD", 1L))
setAnalyticsConfiguration(AnalyticsConfiguration(AnalyticsLevel.ALL))
setSubmitButtonVisible(false)
}
}

val dropInOverrideParams = DropInOverrideParams(Amount("EUR", 123L), null)
val params = cashAppPayComponentParamsMapper.mapToParams(
checkoutConfiguration = configuration,
deviceLocale = DEVICE_LOCALE,
dropInOverrideParams = dropInOverrideParams,
componentSessionParams = null,
paymentMethod = getDefaultPaymentMethod(),
context = Application(),
)

assertEquals(true, params.isSubmitButtonVisible)
}

@ParameterizedTest
@MethodSource("enableStoreDetailsSource")
fun `showStorePaymentField should match value set in sessions if it exists, otherwise should match configuration`(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,14 @@ class ButtonComponentParamsMapper(
dropInOverrideParams,
componentSessionParams,
)
val commonComponentParams = commonComponentParamsMapperData.commonComponentParams
return ButtonComponentParams(
commonComponentParams = commonComponentParamsMapperData.commonComponentParams,
isSubmitButtonVisible = (componentConfiguration as? ButtonConfiguration)?.isSubmitButtonVisible ?: true,
commonComponentParams = commonComponentParams,
isSubmitButtonVisible = if (commonComponentParams.isCreatedByDropIn) {
true
} else {
(componentConfiguration as? ButtonConfiguration)?.isSubmitButtonVisible ?: true
},
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class ButtonTestConfiguration private constructor(

private var isSubmitButtonVisible: Boolean? = null

override fun setSubmitButtonVisible(isSubmitButtonVisible: Boolean): ButtonConfigurationBuilder {
override fun setSubmitButtonVisible(isSubmitButtonVisible: Boolean): Builder {
this.isSubmitButtonVisible = isSubmitButtonVisible
return this
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,30 @@ internal class ButtonComponentParamsMapperTest {
assertEquals(expected, params)
}

@Test
fun `when setSubmitButtonVisible is set to false in button component configuration and drop-in override params are set then card component params should have isSubmitButtonVisible true`() {
val configuration = CheckoutConfiguration(
environment = Environment.EUROPE,
clientKey = TEST_CLIENT_KEY_2,
) {
val testConfiguration = ButtonTestConfiguration.Builder(Locale.CANADA, Environment.TEST, TEST_CLIENT_KEY_1)
.setSubmitButtonVisible(false)
.build()
addConfiguration(TEST_CONFIGURATION_KEY, testConfiguration)
}

val dropInOverrideParams = DropInOverrideParams(Amount("USD", 123L), null)
val params = buttonComponentParamsMapper.mapToParams(
checkoutConfiguration = configuration,
deviceLocale = DEVICE_LOCALE,
dropInOverrideParams = dropInOverrideParams,
componentSessionParams = null,
componentConfiguration = configuration.getConfiguration(TEST_CONFIGURATION_KEY),
)

assertEquals(true, params.isSubmitButtonVisible)
}

@ParameterizedTest
@MethodSource("amountSource")
fun `amount should match value set in sessions then drop in then component configuration`(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,13 @@ internal class GiftCardComponentParamsMapper(
)
val commonComponentParams = commonComponentParamsMapperData.commonComponentParams
val giftCardConfiguration = checkoutConfiguration.getGiftCardConfiguration()

return GiftCardComponentParams(
commonComponentParams = commonComponentParams,
isSubmitButtonVisible = giftCardConfiguration?.isSubmitButtonVisible ?: true,
isSubmitButtonVisible = if (commonComponentParams.isCreatedByDropIn) {
true
} else {
giftCardConfiguration?.isSubmitButtonVisible ?: true
},
isPinRequired = giftCardConfiguration?.isPinRequired ?: true,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,23 @@ internal class GiftCardComponentParamsMapperTest {
assertEquals(expected, params)
}

@Test
fun `when setSubmitButtonVisible is set to false in gift card configuration and drop-in override params are set then card component params should have isSubmitButtonVisible true`() {
val configuration = CheckoutConfiguration(
environment = Environment.EUROPE,
clientKey = TEST_CLIENT_KEY_2,
) {
giftCard {
setSubmitButtonVisible(false)
}
}

val dropInOverrideParams = DropInOverrideParams(Amount("CAD", 123L), null)
val params = giftCardComponentParamsMapper.mapToParams(configuration, DEVICE_LOCALE, dropInOverrideParams, null)

assertEquals(true, params.isSubmitButtonVisible)
}

@ParameterizedTest
@MethodSource("amountSource")
fun `amount should match value set in sessions then drop in then component configuration`(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,14 @@ class IssuerListComponentParamsMapper(
dropInOverrideParams,
componentSessionParams,
)
val commonComponentParams = commonComponentParamsMapperData.commonComponentParams
return IssuerListComponentParams(
commonComponentParams = commonComponentParamsMapperData.commonComponentParams,
isSubmitButtonVisible = componentConfiguration?.isSubmitButtonVisible ?: true,
commonComponentParams = commonComponentParams,
isSubmitButtonVisible = if (commonComponentParams.isCreatedByDropIn) {
true
} else {
componentConfiguration?.isSubmitButtonVisible ?: true
},
viewType = componentConfiguration?.viewType ?: IssuerListViewType.RECYCLER_VIEW,
hideIssuerLogos = componentConfiguration?.hideIssuerLogos ?: hideIssuerLogosDefaultValue,
)
Expand Down

0 comments on commit fc7ec91

Please sign in to comment.