Skip to content

Commit

Permalink
Add FormHeaderInformation to EmbeddedFormInteractorFactory (#9986)
Browse files Browse the repository at this point in the history
  • Loading branch information
tjclawson-stripe authored Jan 28, 2025
1 parent 4f415a5 commit b76a650
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ import dagger.assisted.AssistedFactory
import dagger.assisted.AssistedInject

internal interface EmbeddedSheetLauncher {
fun launchForm(code: String, paymentMethodMetadata: PaymentMethodMetadata)
fun launchForm(
code: String,
paymentMethodMetadata: PaymentMethodMetadata,
hasSavedPaymentMethods: Boolean
)

fun launchManage(
paymentMethodMetadata: PaymentMethodMetadata,
Expand Down Expand Up @@ -82,8 +86,17 @@ internal class DefaultEmbeddedSheetLauncher @AssistedInject constructor(
}
}

override fun launchForm(code: String, paymentMethodMetadata: PaymentMethodMetadata) {
formActivityLauncher.launch(FormContract.Args(code, paymentMethodMetadata))
override fun launchForm(
code: String,
paymentMethodMetadata: PaymentMethodMetadata,
hasSavedPaymentMethods: Boolean
) {
val args = FormContract.Args(
selectedPaymentMethodCode = code,
paymentMethodMetadata = paymentMethodMetadata,
hasSavedPaymentMethods = hasSavedPaymentMethods
)
formActivityLauncher.launch(args)
}

override fun launchManage(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,14 @@ internal class DefaultEmbeddedContentHelper @AssistedInject constructor(
selection = selectionHolder.selection.value,
)
},
transitionToFormScreen = {
sheetLauncher?.launchForm(it, paymentMethodMetadata)
transitionToFormScreen = { code ->
sheetLauncher?.launchForm(
code = code,
paymentMethodMetadata = paymentMethodMetadata,
hasSavedPaymentMethods = customerStateHolder.paymentMethods.value.any {
it.type?.code == code
}
)
},
paymentMethods = customerStateHolder.paymentMethods,
mostRecentlySelectedSavedPaymentMethod = customerStateHolder.mostRecentlySelectedSavedPaymentMethod,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import javax.inject.Inject
internal class EmbeddedFormInteractorFactory @Inject constructor(
private val paymentMethodMetadata: PaymentMethodMetadata,
private val paymentMethodCode: PaymentMethodCode,
private val hasSavedPaymentMethods: Boolean,
private val embeddedSelectionHolder: EmbeddedSelectionHolder,
private val embeddedFormHelperFactory: EmbeddedFormHelperFactory,
@ViewModelScope private val viewModelScope: CoroutineScope
Expand Down Expand Up @@ -52,7 +53,10 @@ internal class EmbeddedFormInteractorFactory @Inject constructor(
usBankAccountArguments = usBankAccountFormArguments,
reportFieldInteraction = {
},
headerInformation = null,
headerInformation = paymentMethodMetadata.formHeaderInformationForCode(
code = paymentMethodCode,
customerHasSavedPaymentMethods = hasSavedPaymentMethods
),
isLiveMode = paymentMethodMetadata.stripeIntent.isLiveMode,
processing = stateFlowOf(false),
paymentMethodIncentive = PaymentMethodIncentiveInteractor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ internal interface FormActivityComponent {
@BindsInstance
fun selectedPaymentMethodCode(selectedPaymentMethodCode: PaymentMethodCode): Builder

@BindsInstance
fun hasSavedPaymentMethods(hasSavedPaymentMethods: Boolean): Builder

@BindsInstance
fun context(context: Context): Builder

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ internal class FormActivityViewModel @Inject constructor(
val component = DaggerFormActivityComponent.builder()
.paymentMethodMetadata(args.paymentMethodMetadata)
.selectedPaymentMethodCode(args.selectedPaymentMethodCode)
.hasSavedPaymentMethods(args.hasSavedPaymentMethods)
.context(extras.requireApplication())
.savedStateHandle(extras.createSavedStateHandle())
.build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ internal object FormContract : ActivityResultContract<FormContract.Args, FormRes
internal data class Args(
val selectedPaymentMethodCode: String,
val paymentMethodMetadata: PaymentMethodMetadata,
val hasSavedPaymentMethods: Boolean
) : Parcelable {
companion object {
fun fromIntent(intent: Intent): Args? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ internal class DefaultEmbeddedSheetLauncherTest {
fun `launchForm launches activity with correct parameters`() = testScenario {
val code = "test_code"
val paymentMethodMetadata = PaymentMethodMetadataFactory.create()
val expectedArgs = FormContract.Args(code, paymentMethodMetadata)
val expectedArgs = FormContract.Args(code, paymentMethodMetadata, false)

sheetLauncher.launchForm(code, paymentMethodMetadata)
sheetLauncher.launchForm(code, paymentMethodMetadata, false)
val launchCall = dummyActivityResultCallerScenario.awaitLaunchCall()
assertThat(launchCall).isEqualTo(expectedArgs)
}
Expand Down

0 comments on commit b76a650

Please sign in to comment.