diff --git a/payments-core/src/main/java/com/stripe/android/ConfirmStripeIntentParamsFactory.kt b/payments-core/src/main/java/com/stripe/android/ConfirmStripeIntentParamsFactory.kt index af90cf5951b..dc420273190 100644 --- a/payments-core/src/main/java/com/stripe/android/ConfirmStripeIntentParamsFactory.kt +++ b/payments-core/src/main/java/com/stripe/android/ConfirmStripeIntentParamsFactory.kt @@ -22,7 +22,6 @@ sealed class ConfirmStripeIntentParamsFactory abstract fun create( createParams: PaymentMethodCreateParams, optionsParams: PaymentMethodOptionsParams? = null, - setupFutureUsage: ConfirmPaymentIntentParams.SetupFutureUsage? = null, ): T @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) @@ -78,40 +77,11 @@ internal class ConfirmPaymentIntentParamsFactory( override fun create( createParams: PaymentMethodCreateParams, optionsParams: PaymentMethodOptionsParams?, - setupFutureUsage: ConfirmPaymentIntentParams.SetupFutureUsage?, ): ConfirmPaymentIntentParams { return ConfirmPaymentIntentParams.createWithPaymentMethodCreateParams( paymentMethodCreateParams = createParams, clientSecret = clientSecret, - - /** - Sets `payment_method_options[card][setup_future_usage]` - - Note: PaymentSheet uses this `setup_future_usage` (SFU) value very differently from the top-level one: - We read the top-level SFU to know the merchant’s desired save behavior - We write payment method options SFU to set the customer’s desired save behavior - */ - // At this time, paymentMethodOptions card and us_bank_account is the only PM that - // supports setup future usage - paymentMethodOptions = when (createParams.typeCode) { - PaymentMethod.Type.Card.code -> { - PaymentMethodOptionsParams.Card(setupFutureUsage = setupFutureUsage) - } - PaymentMethod.Type.USBankAccount.code -> { - PaymentMethodOptionsParams.USBankAccount(setupFutureUsage = setupFutureUsage) - } - PaymentMethod.Type.Blik.code -> { - optionsParams - } - PaymentMethod.Type.Konbini.code -> { - optionsParams - } - PaymentMethod.Type.Link.code -> { - null - } - else -> { - PaymentMethodOptionsParams.Card(setupFutureUsage = null) - } - }, + paymentMethodOptions = optionsParams, shipping = shipping, ) } @@ -133,7 +103,6 @@ internal class ConfirmSetupIntentParamsFactory( override fun create( createParams: PaymentMethodCreateParams, optionsParams: PaymentMethodOptionsParams?, - setupFutureUsage: ConfirmPaymentIntentParams.SetupFutureUsage?, ): ConfirmSetupIntentParams { return ConfirmSetupIntentParams.create( paymentMethodCreateParams = createParams, diff --git a/payments-core/src/test/java/com/stripe/android/ConfirmPaymentIntentParamsFactoryTest.kt b/payments-core/src/test/java/com/stripe/android/ConfirmPaymentIntentParamsFactoryTest.kt index cd5b9944fcb..8e001316d08 100644 --- a/payments-core/src/test/java/com/stripe/android/ConfirmPaymentIntentParamsFactoryTest.kt +++ b/payments-core/src/test/java/com/stripe/android/ConfirmPaymentIntentParamsFactoryTest.kt @@ -20,7 +20,9 @@ class ConfirmPaymentIntentParamsFactoryTest { assertThat( factory.create( createParams = PaymentMethodCreateParamsFixtures.DEFAULT_CARD, - setupFutureUsage = ConfirmPaymentIntentParams.SetupFutureUsage.OffSession, + optionsParams = PaymentMethodOptionsParams.Card( + setupFutureUsage = ConfirmPaymentIntentParams.SetupFutureUsage.OffSession + ) ) ).isEqualTo( ConfirmPaymentIntentParams.createWithPaymentMethodCreateParams( @@ -39,7 +41,9 @@ class ConfirmPaymentIntentParamsFactoryTest { assertThat( factory.create( createParams = PaymentMethodCreateParamsFixtures.DEFAULT_CARD, - setupFutureUsage = ConfirmPaymentIntentParams.SetupFutureUsage.Blank, + optionsParams = PaymentMethodOptionsParams.Card( + setupFutureUsage = ConfirmPaymentIntentParams.SetupFutureUsage.Blank + ) ) ).isEqualTo( ConfirmPaymentIntentParams.createWithPaymentMethodCreateParams( @@ -58,7 +62,7 @@ class ConfirmPaymentIntentParamsFactoryTest { assertThat( factory.create( createParams = PaymentMethodCreateParamsFixtures.DEFAULT_CARD, - setupFutureUsage = null, + optionsParams = PaymentMethodOptionsParams.Card(), ) ).isEqualTo( ConfirmPaymentIntentParams.createWithPaymentMethodCreateParams( @@ -108,7 +112,6 @@ class ConfirmPaymentIntentParamsFactoryTest { val result = factoryWithConfig.create( createParams = PaymentMethodCreateParamsFixtures.DEFAULT_CARD, - setupFutureUsage = null, ) assertThat(result.shipping).isEqualTo(shippingDetails) diff --git a/paymentsheet/src/main/java/com/stripe/android/customersheet/CustomerSheetViewModel.kt b/paymentsheet/src/main/java/com/stripe/android/customersheet/CustomerSheetViewModel.kt index 511d6fd8c52..136a636b54a 100644 --- a/paymentsheet/src/main/java/com/stripe/android/customersheet/CustomerSheetViewModel.kt +++ b/paymentsheet/src/main/java/com/stripe/android/customersheet/CustomerSheetViewModel.kt @@ -18,7 +18,6 @@ import com.stripe.android.customersheet.CustomerAdapter.PaymentOption.Companion. import com.stripe.android.customersheet.analytics.CustomerSheetEventReporter import com.stripe.android.customersheet.injection.CustomerSheetViewModelScope import com.stripe.android.customersheet.util.isUnverifiedUSBankAccount -import com.stripe.android.model.ConfirmPaymentIntentParams import com.stripe.android.model.ConfirmSetupIntentParams import com.stripe.android.model.ConfirmStripeIntentParams import com.stripe.android.model.PaymentMethod @@ -816,7 +815,7 @@ internal class CustomerSheetViewModel @Inject constructor( ), paymentMethod = paymentMethod, shippingValues = null, - setupForFutureUsage = ConfirmPaymentIntentParams.SetupFutureUsage.OffSession, + customerRequestedSave = true, ) unconfirmedPaymentMethod = paymentMethod diff --git a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/IntentConfirmationInterceptor.kt b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/IntentConfirmationInterceptor.kt index 513371e0416..399505d963b 100644 --- a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/IntentConfirmationInterceptor.kt +++ b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/IntentConfirmationInterceptor.kt @@ -6,7 +6,6 @@ import com.stripe.android.core.injection.PUBLISHABLE_KEY import com.stripe.android.core.injection.STRIPE_ACCOUNT_ID import com.stripe.android.core.networking.ApiRequest import com.stripe.android.model.ConfirmPaymentIntentParams -import com.stripe.android.model.ConfirmPaymentIntentParams.SetupFutureUsage.OffSession import com.stripe.android.model.ConfirmStripeIntentParams import com.stripe.android.model.PaymentMethod import com.stripe.android.model.PaymentMethodCreateParams @@ -64,14 +63,14 @@ internal interface IntentConfirmationInterceptor { paymentMethodCreateParams: PaymentMethodCreateParams, paymentMethodOptionsParams: PaymentMethodOptionsParams? = null, shippingValues: ConfirmPaymentIntentParams.Shipping?, - setupForFutureUsage: ConfirmPaymentIntentParams.SetupFutureUsage?, + customerRequestedSave: Boolean, ): NextStep suspend fun intercept( initializationMode: PaymentSheet.InitializationMode, paymentMethod: PaymentMethod, shippingValues: ConfirmPaymentIntentParams.Shipping?, - setupForFutureUsage: ConfirmPaymentIntentParams.SetupFutureUsage?, + customerRequestedSave: Boolean, ): NextStep companion object { @@ -109,7 +108,7 @@ internal class DefaultIntentConfirmationInterceptor @Inject constructor( paymentMethodCreateParams: PaymentMethodCreateParams, paymentMethodOptionsParams: PaymentMethodOptionsParams?, shippingValues: ConfirmPaymentIntentParams.Shipping?, - setupForFutureUsage: ConfirmPaymentIntentParams.SetupFutureUsage?, + customerRequestedSave: Boolean, ): NextStep { return when (initializationMode) { is PaymentSheet.InitializationMode.DeferredIntent -> { @@ -117,7 +116,7 @@ internal class DefaultIntentConfirmationInterceptor @Inject constructor( intentConfiguration = initializationMode.intentConfiguration, shippingValues = shippingValues, paymentMethodCreateParams = paymentMethodCreateParams, - setupForFutureUsage = setupForFutureUsage, + customerRequestedSave = customerRequestedSave, ) } @@ -127,7 +126,6 @@ internal class DefaultIntentConfirmationInterceptor @Inject constructor( shippingValues = shippingValues, paymentMethodCreateParams = paymentMethodCreateParams, paymentMethodOptionsParams = paymentMethodOptionsParams, - setupForFutureUsage = setupForFutureUsage, ) } @@ -136,7 +134,6 @@ internal class DefaultIntentConfirmationInterceptor @Inject constructor( clientSecret = initializationMode.clientSecret, shippingValues = shippingValues, paymentMethodCreateParams = paymentMethodCreateParams, - setupForFutureUsage = setupForFutureUsage, ) } } @@ -146,7 +143,7 @@ internal class DefaultIntentConfirmationInterceptor @Inject constructor( initializationMode: PaymentSheet.InitializationMode, paymentMethod: PaymentMethod, shippingValues: ConfirmPaymentIntentParams.Shipping?, - setupForFutureUsage: ConfirmPaymentIntentParams.SetupFutureUsage?, + customerRequestedSave: Boolean, ): NextStep { return when (initializationMode) { is PaymentSheet.InitializationMode.DeferredIntent -> { @@ -154,7 +151,7 @@ internal class DefaultIntentConfirmationInterceptor @Inject constructor( intentConfiguration = initializationMode.intentConfiguration, paymentMethod = paymentMethod, shippingValues = shippingValues, - setupForFutureUsage = setupForFutureUsage, + customerRequestedSave = customerRequestedSave, ) } @@ -182,7 +179,7 @@ internal class DefaultIntentConfirmationInterceptor @Inject constructor( intentConfiguration: PaymentSheet.IntentConfiguration, paymentMethodCreateParams: PaymentMethodCreateParams, shippingValues: ConfirmPaymentIntentParams.Shipping?, - setupForFutureUsage: ConfirmPaymentIntentParams.SetupFutureUsage?, + customerRequestedSave: Boolean, ): NextStep { val productUsage = buildSet { addAll(paymentMethodCreateParams.attribution) @@ -201,7 +198,7 @@ internal class DefaultIntentConfirmationInterceptor @Inject constructor( intentConfiguration = intentConfiguration, paymentMethod = paymentMethod, shippingValues = shippingValues, - setupForFutureUsage = setupForFutureUsage, + customerRequestedSave = customerRequestedSave, ) }, onFailure = { error -> @@ -217,7 +214,7 @@ internal class DefaultIntentConfirmationInterceptor @Inject constructor( intentConfiguration: PaymentSheet.IntentConfiguration, paymentMethod: PaymentMethod, shippingValues: ConfirmPaymentIntentParams.Shipping?, - setupForFutureUsage: ConfirmPaymentIntentParams.SetupFutureUsage?, + customerRequestedSave: Boolean, ): NextStep { return when (val callback = IntentConfirmationInterceptor.createIntentCallback) { is CreateIntentCallback -> { @@ -225,7 +222,7 @@ internal class DefaultIntentConfirmationInterceptor @Inject constructor( createIntentCallback = callback, intentConfiguration = intentConfiguration, paymentMethod = paymentMethod, - shouldSavePaymentMethod = setupForFutureUsage == OffSession, + shouldSavePaymentMethod = customerRequestedSave, shippingValues = shippingValues, ) } @@ -336,7 +333,6 @@ internal class DefaultIntentConfirmationInterceptor @Inject constructor( shippingValues: ConfirmPaymentIntentParams.Shipping?, paymentMethodCreateParams: PaymentMethodCreateParams, paymentMethodOptionsParams: PaymentMethodOptionsParams? = null, - setupForFutureUsage: ConfirmPaymentIntentParams.SetupFutureUsage?, ): NextStep.Confirm { val paramsFactory = ConfirmStripeIntentParamsFactory.createFactory( clientSecret = clientSecret, @@ -345,7 +341,6 @@ internal class DefaultIntentConfirmationInterceptor @Inject constructor( val confirmParams = paramsFactory.create( paymentMethodCreateParams, paymentMethodOptionsParams, - setupForFutureUsage ) return NextStep.Confirm( diff --git a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/IntentConfirmationInterceptorKtx.kt b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/IntentConfirmationInterceptorKtx.kt index b67685b4016..f21e7a2bfa8 100644 --- a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/IntentConfirmationInterceptorKtx.kt +++ b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/IntentConfirmationInterceptorKtx.kt @@ -1,7 +1,6 @@ package com.stripe.android.paymentsheet import com.stripe.android.model.ConfirmPaymentIntentParams -import com.stripe.android.model.ConfirmPaymentIntentParams.SetupFutureUsage import com.stripe.android.paymentsheet.model.PaymentSelection import com.stripe.android.paymentsheet.model.PaymentSelection.CustomerRequestedSave @@ -12,18 +11,12 @@ internal suspend fun IntentConfirmationInterceptor.intercept( ): IntentConfirmationInterceptor.NextStep { return when (paymentSelection) { is PaymentSelection.New -> { - val setupFutureUsage = when (paymentSelection.customerRequestedSave) { - CustomerRequestedSave.RequestReuse -> SetupFutureUsage.OffSession - CustomerRequestedSave.RequestNoReuse -> SetupFutureUsage.Blank - CustomerRequestedSave.NoRequest -> null - } - intercept( initializationMode = initializationMode, paymentMethodOptionsParams = paymentSelection.paymentMethodOptionsParams, paymentMethodCreateParams = paymentSelection.paymentMethodCreateParams, shippingValues = shippingValues, - setupForFutureUsage = setupFutureUsage, + customerRequestedSave = paymentSelection.customerRequestedSave == CustomerRequestedSave.RequestReuse, ) } is PaymentSelection.Saved -> { @@ -31,7 +24,7 @@ internal suspend fun IntentConfirmationInterceptor.intercept( initializationMode = initializationMode, paymentMethod = paymentSelection.paymentMethod, shippingValues = shippingValues, - setupForFutureUsage = null, + customerRequestedSave = false, ) } else -> { diff --git a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/model/ConfirmStripeIntentParamsFactoryKtx.kt b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/model/ConfirmStripeIntentParamsFactoryKtx.kt index c0432e6b54f..7c38b9a8331 100644 --- a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/model/ConfirmStripeIntentParamsFactoryKtx.kt +++ b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/model/ConfirmStripeIntentParamsFactoryKtx.kt @@ -1,7 +1,6 @@ package com.stripe.android.paymentsheet.model import com.stripe.android.ConfirmStripeIntentParamsFactory -import com.stripe.android.model.ConfirmPaymentIntentParams import com.stripe.android.model.ConfirmStripeIntentParams internal fun ConfirmStripeIntentParamsFactory.create( @@ -13,20 +12,8 @@ internal fun ConfirmStripeIntentParamsFactory internal fun ConfirmStripeIntentParamsFactory.create( paymentSelection: PaymentSelection.New, ): T { - val setupFutureUsage = when (paymentSelection.customerRequestedSave) { - PaymentSelection.CustomerRequestedSave.RequestReuse -> { - ConfirmPaymentIntentParams.SetupFutureUsage.OffSession - } - PaymentSelection.CustomerRequestedSave.RequestNoReuse -> { - ConfirmPaymentIntentParams.SetupFutureUsage.Blank - } - PaymentSelection.CustomerRequestedSave.NoRequest -> { - null - } - } - return create( createParams = paymentSelection.paymentMethodCreateParams, - setupFutureUsage = setupFutureUsage, + optionsParams = paymentSelection.paymentMethodOptionsParams, ) } diff --git a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/model/PaymentSelection.kt b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/model/PaymentSelection.kt index 961756ba3cc..2a48754ab21 100644 --- a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/model/PaymentSelection.kt +++ b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/model/PaymentSelection.kt @@ -6,6 +6,7 @@ import androidx.annotation.DrawableRes import com.stripe.android.link.LinkPaymentDetails import com.stripe.android.model.Address import com.stripe.android.model.CardBrand +import com.stripe.android.model.ConfirmPaymentIntentParams import com.stripe.android.model.ConsumerPaymentDetails import com.stripe.android.model.PaymentMethod import com.stripe.android.model.PaymentMethod.Type.USBankAccount @@ -107,10 +108,10 @@ internal sealed class PaymentSelection : Parcelable { } } - enum class CustomerRequestedSave { - RequestReuse, - RequestNoReuse, - NoRequest + enum class CustomerRequestedSave(val setupFutureUsage: ConfirmPaymentIntentParams.SetupFutureUsage?) { + RequestReuse(ConfirmPaymentIntentParams.SetupFutureUsage.OffSession), + RequestNoReuse(ConfirmPaymentIntentParams.SetupFutureUsage.Blank), + NoRequest(null) } sealed class New : PaymentSelection() { diff --git a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/paymentdatacollection/ach/USBankAccountFormViewModel.kt b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/paymentdatacollection/ach/USBankAccountFormViewModel.kt index fd83a4cab18..bce968aa57b 100644 --- a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/paymentdatacollection/ach/USBankAccountFormViewModel.kt +++ b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/paymentdatacollection/ach/USBankAccountFormViewModel.kt @@ -16,6 +16,7 @@ import com.stripe.android.financialconnections.model.FinancialConnectionsAccount import com.stripe.android.model.Address import com.stripe.android.model.PaymentMethod import com.stripe.android.model.PaymentMethodCreateParams +import com.stripe.android.model.PaymentMethodOptionsParams import com.stripe.android.payments.bankaccount.CollectBankAccountConfiguration import com.stripe.android.payments.bankaccount.CollectBankAccountLauncher import com.stripe.android.payments.bankaccount.navigation.CollectBankAccountResultInternal @@ -468,6 +469,10 @@ internal class USBankAccountFormViewModel @Inject internal constructor( bankName: String, linkAccountId: String, ): PaymentSelection.New.USBankAccount { + val customerRequestedSave = customerRequestedSave( + showCheckbox = args.formArgs.showCheckbox, + saveForFutureUse = saveForFutureUse.value + ) return PaymentSelection.New.USBankAccount( labelResource = application.getString( R.string.stripe_paymentsheet_payment_method_item_card_number, @@ -487,16 +492,10 @@ internal class USBankAccountFormViewModel @Inject internal constructor( address = address.value, ) ), - paymentMethodOptionsParams = null, - customerRequestedSave = if (args.formArgs.showCheckbox) { - if (saveForFutureUse.value) { - PaymentSelection.CustomerRequestedSave.RequestReuse - } else { - PaymentSelection.CustomerRequestedSave.RequestNoReuse - } - } else { - PaymentSelection.CustomerRequestedSave.NoRequest - }, + paymentMethodOptionsParams = PaymentMethodOptionsParams.USBankAccount( + setupFutureUsage = customerRequestedSave.setupFutureUsage + ), + customerRequestedSave = customerRequestedSave, screenState = currentScreenState.value, input = PaymentSelection.New.USBankAccount.Input( name = name.value, @@ -596,3 +595,18 @@ internal fun PaymentSheet.Address.asAddressModel() = country = country, postalCode = postalCode, ) + +internal fun customerRequestedSave( + showCheckbox: Boolean, + saveForFutureUse: Boolean +): PaymentSelection.CustomerRequestedSave { + return if (showCheckbox) { + if (saveForFutureUse) { + PaymentSelection.CustomerRequestedSave.RequestReuse + } else { + PaymentSelection.CustomerRequestedSave.RequestNoReuse + } + } else { + PaymentSelection.CustomerRequestedSave.NoRequest + } +} diff --git a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/ui/AddPaymentMethod.kt b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/ui/AddPaymentMethod.kt index 22722d77332..ca5b547d78a 100644 --- a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/ui/AddPaymentMethod.kt +++ b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/ui/AddPaymentMethod.kt @@ -204,7 +204,9 @@ internal fun FormFieldValues.transformToPaymentSelection( val options = transformToPaymentMethodOptionsParams(paymentMethod) return if (paymentMethod.code == PaymentMethod.Type.Card.code) { PaymentSelection.New.Card( - paymentMethodOptionsParams = options, + paymentMethodOptionsParams = PaymentMethodOptionsParams.Card( + setupFutureUsage = userRequestedReuse.setupFutureUsage + ), paymentMethodCreateParams = params, brand = CardBrand.fromCode(fieldValuePairs[IdentifierSpec.CardBrand]?.value), customerRequestedSave = userRequestedReuse, diff --git a/paymentsheet/src/test/java/com/stripe/android/paymentsheet/DefaultIntentConfirmationInterceptorTest.kt b/paymentsheet/src/test/java/com/stripe/android/paymentsheet/DefaultIntentConfirmationInterceptorTest.kt index 3f6eae4fe1d..a797ab8051a 100644 --- a/paymentsheet/src/test/java/com/stripe/android/paymentsheet/DefaultIntentConfirmationInterceptorTest.kt +++ b/paymentsheet/src/test/java/com/stripe/android/paymentsheet/DefaultIntentConfirmationInterceptorTest.kt @@ -52,7 +52,7 @@ class DefaultIntentConfirmationInterceptorTest { initializationMode = InitializationMode.PaymentIntent("pi_1234_secret_4321"), paymentMethod = paymentMethod, shippingValues = null, - setupForFutureUsage = null, + customerRequestedSave = false, ) val confirmNextStep = nextStep as? IntentConfirmationInterceptor.NextStep.Confirm @@ -78,7 +78,7 @@ class DefaultIntentConfirmationInterceptorTest { initializationMode = InitializationMode.PaymentIntent("pi_1234_secret_4321"), paymentMethodCreateParams = createParams, shippingValues = null, - setupForFutureUsage = null, + customerRequestedSave = false, ) val confirmNextStep = nextStep as? IntentConfirmationInterceptor.NextStep.Confirm @@ -110,7 +110,7 @@ class DefaultIntentConfirmationInterceptorTest { ), paymentMethod = PaymentMethodFixtures.CARD_PAYMENT_METHOD, shippingValues = null, - setupForFutureUsage = null, + customerRequestedSave = false, ) } @@ -141,7 +141,7 @@ class DefaultIntentConfirmationInterceptorTest { initializationMode = InitializationMode.DeferredIntent(mock()), paymentMethodCreateParams = PaymentMethodCreateParamsFixtures.DEFAULT_CARD, shippingValues = null, - setupForFutureUsage = null, + customerRequestedSave = false, ) } @@ -177,7 +177,7 @@ class DefaultIntentConfirmationInterceptorTest { initializationMode = InitializationMode.DeferredIntent(mock()), paymentMethodCreateParams = PaymentMethodCreateParamsFixtures.DEFAULT_CARD, shippingValues = null, - setupForFutureUsage = null, + customerRequestedSave = false, ) assertThat(nextStep).isEqualTo( @@ -220,7 +220,7 @@ class DefaultIntentConfirmationInterceptorTest { initializationMode = InitializationMode.DeferredIntent(mock()), paymentMethod = PaymentMethodFixtures.CARD_PAYMENT_METHOD, shippingValues = null, - setupForFutureUsage = null, + customerRequestedSave = false, ) assertThat(nextStep).isEqualTo( @@ -249,7 +249,7 @@ class DefaultIntentConfirmationInterceptorTest { initializationMode = InitializationMode.DeferredIntent(mock()), paymentMethod = PaymentMethodFixtures.CARD_PAYMENT_METHOD, shippingValues = null, - setupForFutureUsage = null, + customerRequestedSave = false, ) assertThat(nextStep).isEqualTo( @@ -276,7 +276,7 @@ class DefaultIntentConfirmationInterceptorTest { initializationMode = InitializationMode.DeferredIntent(mock()), paymentMethod = PaymentMethodFixtures.CARD_PAYMENT_METHOD, shippingValues = null, - setupForFutureUsage = null, + customerRequestedSave = false, ) assertThat(nextStep).isEqualTo( @@ -324,7 +324,7 @@ class DefaultIntentConfirmationInterceptorTest { ), paymentMethod = paymentMethod, shippingValues = null, - setupForFutureUsage = null, + customerRequestedSave = false, ) assertThat(nextStep).isInstanceOf(IntentConfirmationInterceptor.NextStep.Confirm::class.java) @@ -363,7 +363,7 @@ class DefaultIntentConfirmationInterceptorTest { ), paymentMethod = paymentMethod, shippingValues = null, - setupForFutureUsage = null, + customerRequestedSave = false, ) assertThat(nextStep).isEqualTo( @@ -408,7 +408,7 @@ class DefaultIntentConfirmationInterceptorTest { ), paymentMethod = paymentMethod, shippingValues = null, - setupForFutureUsage = null, + customerRequestedSave = false, ) assertThat(nextStep).isEqualTo( @@ -437,12 +437,7 @@ class DefaultIntentConfirmationInterceptorTest { isFlowController = false, ) - val inputs = listOf( - null, - ConfirmPaymentIntentParams.SetupFutureUsage.Blank, - ConfirmPaymentIntentParams.SetupFutureUsage.OffSession, - ConfirmPaymentIntentParams.SetupFutureUsage.OnSession, - ) + val inputs = listOf(true, false) for (input in inputs) { IntentConfirmationInterceptor.createIntentCallback = @@ -462,11 +457,11 @@ class DefaultIntentConfirmationInterceptorTest { ), paymentMethod = paymentMethod, shippingValues = null, - setupForFutureUsage = input, + customerRequestedSave = input, ) } - assertThat(observedValues).containsExactly(false, false, true, false).inOrder() + assertThat(observedValues).containsExactly(true, false).inOrder() } @Test @@ -497,7 +492,7 @@ class DefaultIntentConfirmationInterceptorTest { ), paymentMethod = paymentMethod, shippingValues = null, - setupForFutureUsage = null, + customerRequestedSave = false, ) verify(stripeRepository, never()).retrieveStripeIntent(any(), any(), any()) diff --git a/paymentsheet/src/test/java/com/stripe/android/paymentsheet/paymentdatacollection/ach/USBankAccountFormViewModelTest.kt b/paymentsheet/src/test/java/com/stripe/android/paymentsheet/paymentdatacollection/ach/USBankAccountFormViewModelTest.kt index ff68d409a01..98967e731db 100644 --- a/paymentsheet/src/test/java/com/stripe/android/paymentsheet/paymentdatacollection/ach/USBankAccountFormViewModelTest.kt +++ b/paymentsheet/src/test/java/com/stripe/android/paymentsheet/paymentdatacollection/ach/USBankAccountFormViewModelTest.kt @@ -12,8 +12,10 @@ import com.stripe.android.financialconnections.model.BankAccount import com.stripe.android.financialconnections.model.FinancialConnectionsAccount import com.stripe.android.financialconnections.model.FinancialConnectionsSession import com.stripe.android.model.Address +import com.stripe.android.model.ConfirmPaymentIntentParams import com.stripe.android.model.PaymentIntent import com.stripe.android.model.PaymentMethod +import com.stripe.android.model.PaymentMethodOptionsParams import com.stripe.android.payments.bankaccount.CollectBankAccountLauncher import com.stripe.android.payments.bankaccount.navigation.CollectBankAccountResponseInternal import com.stripe.android.payments.bankaccount.navigation.CollectBankAccountResultInternal @@ -197,6 +199,29 @@ class USBankAccountFormViewModelTest { } } + @Test + fun `when payment options, verified bank account, then result has correct paymentMethodOptionsParams`() = runTest { + val viewModel = createViewModel( + defaultArgs.copy( + formArgs = defaultArgs.formArgs.copy(showCheckbox = true) + ) + ) + val bankAccount = mockVerifiedBankAccount() + + viewModel.result.test { + viewModel.handleCollectBankAccountResult(bankAccount) + + val currentScreenState = viewModel.currentScreenState.stateIn(viewModel.viewModelScope).value + viewModel.handlePrimaryButtonClick(currentScreenState as USBankAccountFormScreenState.MandateCollection) + + assertThat(awaitItem()?.paymentMethodOptionsParams).isEqualTo( + PaymentMethodOptionsParams.USBankAccount( + setupFutureUsage = ConfirmPaymentIntentParams.SetupFutureUsage.Blank + ) + ) + } + } + @Test fun `when reset, primary button launches bank account collection`() = runTest(UnconfinedTestDispatcher()) { @@ -957,6 +982,36 @@ class USBankAccountFormViewModelTest { } } + @Test + fun `customerRequestedSave equals RequestReuse when showCheckbox and saveForFutureUse`() { + assertThat( + customerRequestedSave( + showCheckbox = true, + saveForFutureUse = true + ) + ).isEqualTo(PaymentSelection.CustomerRequestedSave.RequestReuse) + } + + @Test + fun `customerRequestedSave equals RequestNoReuse when showCheckbox and not saveForFutureUse`() { + assertThat( + customerRequestedSave( + showCheckbox = true, + saveForFutureUse = false + ) + ).isEqualTo(PaymentSelection.CustomerRequestedSave.RequestNoReuse) + } + + @Test + fun `customerRequestedSave equals NoRequest when not showCheckbox and not saveForFutureUse`() { + assertThat( + customerRequestedSave( + showCheckbox = false, + saveForFutureUse = false + ) + ).isEqualTo(PaymentSelection.CustomerRequestedSave.NoRequest) + } + private fun createViewModel( args: USBankAccountFormViewModel.Args = defaultArgs ): USBankAccountFormViewModel { diff --git a/paymentsheet/src/test/java/com/stripe/android/utils/FakeIntentConfirmationInterceptor.kt b/paymentsheet/src/test/java/com/stripe/android/utils/FakeIntentConfirmationInterceptor.kt index acbdbd14585..be295a7e126 100644 --- a/paymentsheet/src/test/java/com/stripe/android/utils/FakeIntentConfirmationInterceptor.kt +++ b/paymentsheet/src/test/java/com/stripe/android/utils/FakeIntentConfirmationInterceptor.kt @@ -48,7 +48,7 @@ internal class FakeIntentConfirmationInterceptor : IntentConfirmationInterceptor paymentMethodCreateParams: PaymentMethodCreateParams, paymentMethodOptionsParams: PaymentMethodOptionsParams?, shippingValues: ConfirmPaymentIntentParams.Shipping?, - setupForFutureUsage: ConfirmPaymentIntentParams.SetupFutureUsage?, + customerRequestedSave: Boolean, ): IntentConfirmationInterceptor.NextStep { return channel.receive() } @@ -57,7 +57,7 @@ internal class FakeIntentConfirmationInterceptor : IntentConfirmationInterceptor initializationMode: PaymentSheet.InitializationMode, paymentMethod: PaymentMethod, shippingValues: ConfirmPaymentIntentParams.Shipping?, - setupForFutureUsage: ConfirmPaymentIntentParams.SetupFutureUsage?, + customerRequestedSave: Boolean, ): IntentConfirmationInterceptor.NextStep { return channel.receive() }