Skip to content

Commit

Permalink
Pass intent information into bank auth flow
Browse files Browse the repository at this point in the history
  • Loading branch information
tillh-stripe committed Sep 16, 2024
1 parent ffdca76 commit ddc679b
Show file tree
Hide file tree
Showing 33 changed files with 171 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ class FinancialConnectionsPlaygroundActivity : AppCompatActivity() {
clientSecret = paymentIntentSecret,
configuration = CollectBankAccountConfiguration.InstantDebits(
email = email,
elementsContext = elementsContext,
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.stripe.android.Stripe
import com.stripe.android.confirmPaymentIntent
import com.stripe.android.financialconnections.FinancialConnections
import com.stripe.android.financialconnections.FinancialConnectionsSheet
import com.stripe.android.financialconnections.FinancialConnectionsSheet.ElementsContext
import com.stripe.android.financialconnections.FinancialConnectionsSheetForTokenResult
import com.stripe.android.financialconnections.FinancialConnectionsSheetResult
import com.stripe.android.financialconnections.analytics.FinancialConnectionsEvent
Expand Down Expand Up @@ -123,6 +124,12 @@ internal class FinancialConnectionsPlaygroundViewModel(
publishableKey = it.publishableKey,
ephemeralKey = it.ephemeralKey,
customerId = it.customerId,
elementsContext = ElementsContext(
id = it.id,
amount = it.amount,
currency = it.currency,
hostedSurface = ElementsContext.HostedSurface.PaymentSheet,
),
experience = settings.get<ExperienceSetting>().selectedOption,
integrationType = settings.get<IntegrationTypeSetting>().selectedOption,
)
Expand Down Expand Up @@ -480,6 +487,7 @@ sealed class FinancialConnectionsPlaygroundViewEffect {
val publishableKey: String,
val experience: Experience,
val integrationType: IntegrationType,
val elementsContext: ElementsContext,
) : FinancialConnectionsPlaygroundViewEffect()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ import kotlinx.serialization.Serializable
@Keep
@Serializable
data class CreateIntentResponse(
@SerialName("id") val id: String,
@SerialName("secret") val intentSecret: String,
@SerialName("publishable_key") val publishableKey: String,
@SerialName("ephemeral_key") val ephemeralKey: String? = null,
@SerialName("customer_id") val customerId: String? = null
@SerialName("customer_id") val customerId: String? = null,
@SerialName("amount") val amount: Long?,
@SerialName("currency") val currency: String?,
)
8 changes: 8 additions & 0 deletions financial-connections/api/financial-connections.api
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,14 @@ public final class com/stripe/android/financialconnections/FinancialConnectionsS
public synthetic fun newArray (I)[Ljava/lang/Object;
}

public final class com/stripe/android/financialconnections/FinancialConnectionsSheet$IntentContext$Creator : android/os/Parcelable$Creator {
public fun <init> ()V
public final fun createFromParcel (Landroid/os/Parcel;)Lcom/stripe/android/financialconnections/FinancialConnectionsSheet$IntentContext;
public synthetic fun createFromParcel (Landroid/os/Parcel;)Ljava/lang/Object;
public final fun newArray (I)[Lcom/stripe/android/financialconnections/FinancialConnectionsSheet$IntentContext;
public synthetic fun newArray (I)[Ljava/lang/Object;
}

public final class com/stripe/android/financialconnections/FinancialConnectionsSheetComposeKt {
public static final fun rememberFinancialConnectionsSheet (Lkotlin/jvm/functions/Function1;Landroidx/compose/runtime/Composer;I)Lcom/stripe/android/financialconnections/FinancialConnectionsSheet;
public static final fun rememberFinancialConnectionsSheetForToken (Lkotlin/jvm/functions/Function1;Landroidx/compose/runtime/Composer;I)Lcom/stripe/android/financialconnections/FinancialConnectionsSheet;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.stripe.android.financialconnections

import android.os.Parcelable
import androidx.activity.ComponentActivity
import androidx.annotation.RestrictTo
import androidx.fragment.app.Fragment
import com.stripe.android.financialconnections.launcher.FinancialConnectionsSheetForDataLauncher
import com.stripe.android.financialconnections.launcher.FinancialConnectionsSheetForTokenLauncher
Expand Down Expand Up @@ -32,6 +33,26 @@ class FinancialConnectionsSheet internal constructor(
val stripeAccountId: String? = null
) : Parcelable

/**
* Context for sessions created from Stripe Elements. This isn't intended to be
* part of the public API, but solely to be used by the Mobile Payment Element and
* CustomerSheet.
*/
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
@Parcelize
data class ElementsContext(
val id: String?,
val amount: Long?,
val currency: String?,
val hostedSurface: HostedSurface,
) : Parcelable {

enum class HostedSurface(val value: String) {
PaymentSheet(value = "payment_element"),
CustomerSheet(value = "customer_sheet"),
}
}

/**
* Present the [FinancialConnectionsSheet].
*
Expand All @@ -40,7 +61,10 @@ class FinancialConnectionsSheet internal constructor(
fun present(
configuration: Configuration
) {
financialConnectionsSheetLauncher.present(configuration)
financialConnectionsSheetLauncher.present(
configuration = configuration,
elementsContext = null,
)
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ internal class FinancialConnectionsSheetActivity : AppCompatActivity() {
context = this,
args = FinancialConnectionsSheetNativeActivityArgs(
initialSyncResponse = viewEffect.initialSyncResponse,
configuration = viewEffect.configuration
configuration = viewEffect.configuration,
elementsContext = viewEffect.elementsContext,
)
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ internal sealed class FinancialConnectionsSheetViewEffect {
*/
data class OpenNativeAuthFlow(
val configuration: FinancialConnectionsSheet.Configuration,
val initialSyncResponse: SynchronizeSessionResponse
val initialSyncResponse: SynchronizeSessionResponse,
val elementsContext: FinancialConnectionsSheet.ElementsContext?,
) : FinancialConnectionsSheetViewEffect()

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import androidx.lifecycle.viewModelScope
import androidx.lifecycle.viewmodel.initializer
import androidx.lifecycle.viewmodel.viewModelFactory
import com.stripe.android.core.Logger
import com.stripe.android.financialconnections.FinancialConnectionsSheet.ElementsContext
import com.stripe.android.financialconnections.FinancialConnectionsSheetActivity.Companion.getArgs
import com.stripe.android.financialconnections.FinancialConnectionsSheetState.AuthFlowStatus
import com.stripe.android.financialconnections.FinancialConnectionsSheetViewEffect.FinishWithResult
Expand Down Expand Up @@ -144,7 +145,11 @@ internal class FinancialConnectionsSheetViewModel @Inject constructor(
copy(
manifest = manifest,
webAuthFlowStatus = AuthFlowStatus.NONE,
viewEffect = OpenNativeAuthFlow(initialArgs.configuration, sync)
viewEffect = OpenNativeAuthFlow(
configuration = initialArgs.configuration,
initialSyncResponse = sync,
elementsContext = initialArgs.retrieveIntentContext(),
)
)
}
} else {
Expand Down Expand Up @@ -540,3 +545,7 @@ internal class FinancialConnectionsSheetViewModel @Inject constructor(
return null
}
}

private fun FinancialConnectionsSheetActivityArgs.retrieveIntentContext(): ElementsContext? {
return (this as? ForInstantDebits)?.elementsContext
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.stripe.android.core.Logger
import com.stripe.android.core.networking.ApiRequest
import com.stripe.android.core.networking.StripeNetworkClient
import com.stripe.android.core.version.StripeSdkVersion
import com.stripe.android.financialconnections.FinancialConnectionsSheet
import com.stripe.android.financialconnections.domain.AttachConsumerToLinkAccountSession
import com.stripe.android.financialconnections.domain.CreateInstantDebitsResult
import com.stripe.android.financialconnections.domain.HandleError
Expand All @@ -23,6 +24,7 @@ import com.stripe.android.financialconnections.model.SynchronizeSessionResponse
import com.stripe.android.financialconnections.navigation.NavigationManager
import com.stripe.android.financialconnections.navigation.NavigationManagerImpl
import com.stripe.android.financialconnections.network.FinancialConnectionsRequestExecutor
import com.stripe.android.financialconnections.presentation.FinancialConnectionsSheetNativeState
import com.stripe.android.financialconnections.repository.ConsumerSessionRepository
import com.stripe.android.financialconnections.repository.FinancialConnectionsAccountsRepository
import com.stripe.android.financialconnections.repository.FinancialConnectionsConsumerSessionRepository
Expand Down Expand Up @@ -123,6 +125,7 @@ internal interface FinancialConnectionsSheetNativeModule {
locale: Locale?,
logger: Logger,
isLinkWithStripe: IsLinkWithStripe,
elementsContext: FinancialConnectionsSheet.ElementsContext?,
) = FinancialConnectionsConsumerSessionRepository(
financialConnectionsConsumersApiService = financialConnectionsConsumersApiService,
provideApiRequestOptions = provideApiRequestOptions,
Expand All @@ -131,6 +134,7 @@ internal interface FinancialConnectionsSheetNativeModule {
locale = locale ?: Locale.getDefault(),
logger = logger,
isLinkWithStripe = isLinkWithStripe,
intentContext = elementsContext,
)

@Singleton
Expand Down Expand Up @@ -184,5 +188,12 @@ internal interface FinancialConnectionsSheetNativeModule {
linkSignupHandlerForNetworking.get()
}
}

@Provides
internal fun provideIntentContext(
initialState: FinancialConnectionsSheetNativeState,
): FinancialConnectionsSheet.ElementsContext? {
return initialState.elementsContext
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ sealed class FinancialConnectionsSheetActivityArgs(
@Parcelize
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
data class ForInstantDebits(
override val configuration: FinancialConnectionsSheet.Configuration
override val configuration: FinancialConnectionsSheet.Configuration,
internal val elementsContext: FinancialConnectionsSheet.ElementsContext? = null,
) : FinancialConnectionsSheetActivityArgs(configuration)

internal fun validate() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ class FinancialConnectionsSheetForDataLauncher(
}
)

override fun present(configuration: FinancialConnectionsSheet.Configuration) {
override fun present(
configuration: FinancialConnectionsSheet.Configuration,
elementsContext: FinancialConnectionsSheet.ElementsContext?
) {
activityResultLauncher.launch(
FinancialConnectionsSheetActivityArgs.ForData(
configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,12 @@ class FinancialConnectionsSheetForInstantDebitsLauncher(
)
)

override fun present(configuration: FinancialConnectionsSheet.Configuration) {
override fun present(
configuration: FinancialConnectionsSheet.Configuration,
elementsContext: FinancialConnectionsSheet.ElementsContext?
) {
activityResultLauncher.launch(
FinancialConnectionsSheetActivityArgs.ForInstantDebits(
configuration
)
FinancialConnectionsSheetActivityArgs.ForInstantDebits(configuration, elementsContext)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ internal class FinancialConnectionsSheetForTokenLauncher(
}
)

override fun present(configuration: FinancialConnectionsSheet.Configuration) {
override fun present(
configuration: FinancialConnectionsSheet.Configuration,
elementsContext: FinancialConnectionsSheet.ElementsContext?
) {
activityResultLauncher.launch(
FinancialConnectionsSheetActivityArgs.ForToken(
configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@ import com.stripe.android.financialconnections.FinancialConnectionsSheet

@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
interface FinancialConnectionsSheetLauncher {
fun present(configuration: FinancialConnectionsSheet.Configuration)
fun present(
configuration: FinancialConnectionsSheet.Configuration,
elementsContext: FinancialConnectionsSheet.ElementsContext? = null,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ import kotlinx.parcelize.Parcelize
@Parcelize
internal data class FinancialConnectionsSheetNativeActivityArgs constructor(
val configuration: FinancialConnectionsSheet.Configuration,
val initialSyncResponse: SynchronizeSessionResponse
val initialSyncResponse: SynchronizeSessionResponse,
val elementsContext: FinancialConnectionsSheet.ElementsContext? = null,
) : Parcelable
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import androidx.navigation.compose.NavHost
import com.stripe.android.core.Logger
import com.stripe.android.financialconnections.FinancialConnections
import com.stripe.android.financialconnections.FinancialConnectionsSheet
import com.stripe.android.financialconnections.FinancialConnectionsSheet.ElementsContext
import com.stripe.android.financialconnections.analytics.FinancialConnectionsAnalyticsEvent.AppBackgrounded
import com.stripe.android.financialconnections.analytics.FinancialConnectionsAnalyticsEvent.ClickNavBarBack
import com.stripe.android.financialconnections.analytics.FinancialConnectionsAnalyticsEvent.ClickNavBarClose
Expand Down Expand Up @@ -513,6 +514,7 @@ internal data class FinancialConnectionsSheetNativeState(
val initialPane: Pane,
val theme: Theme,
val isLinkWithStripe: Boolean,
val elementsContext: ElementsContext?,
) {

/**
Expand All @@ -533,6 +535,7 @@ internal data class FinancialConnectionsSheetNativeState(
theme = args.initialSyncResponse.manifest.theme?.toLocalTheme() ?: Theme.default,
viewEffect = null,
isLinkWithStripe = args.initialSyncResponse.manifest.isLinkWithStripe ?: false,
elementsContext = args.elementsContext,
)

companion object {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.stripe.android.financialconnections.repository

import com.stripe.android.core.Logger
import com.stripe.android.financialconnections.FinancialConnectionsSheet.ElementsContext
import com.stripe.android.financialconnections.domain.IsLinkWithStripe
import com.stripe.android.financialconnections.repository.api.FinancialConnectionsConsumersApiService
import com.stripe.android.financialconnections.repository.api.ProvideApiRequestOptions
Expand Down Expand Up @@ -65,6 +66,7 @@ internal interface FinancialConnectionsConsumerSessionRepository {
locale: Locale?,
logger: Logger,
isLinkWithStripe: IsLinkWithStripe,
elementsContext: ElementsContext?,
): FinancialConnectionsConsumerSessionRepository =
FinancialConnectionsConsumerSessionRepositoryImpl(
consumersApiService = consumersApiService,
Expand All @@ -74,6 +76,7 @@ internal interface FinancialConnectionsConsumerSessionRepository {
locale = locale,
logger = logger,
isLinkWithStripe = isLinkWithStripe,
elementsContext = elementsContext,
)
}
}
Expand All @@ -85,6 +88,7 @@ private class FinancialConnectionsConsumerSessionRepositoryImpl(
private val provideApiRequestOptions: ProvideApiRequestOptions,
private val locale: Locale?,
private val logger: Logger,
private val elementsContext: ElementsContext?,
isLinkWithStripe: IsLinkWithStripe,
) : FinancialConnectionsConsumerSessionRepository {

Expand Down Expand Up @@ -120,6 +124,16 @@ private class FinancialConnectionsConsumerSessionRepositoryImpl(
country = country,
name = null,
locale = locale,
amount = elementsContext?.amount,
currency = elementsContext?.currency,
financialIncentive = elementsContext?.id?.let {
mapOf(
"financial_incentive" to mapOf(
// This only supports payment intents for now
"payment_intent" to it,
)
)
},
requestOptions = provideApiRequestOptions(useConsumerPublishableKey = false),
requestSurface = requestSurface,
consentAction = EnteredPhoneNumberClickedSaveToLink,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ internal class LinkApiRepository @Inject constructor(
phoneNumber = phone,
country = country,
name = name,
amount = null,
currency = null,
financialIncentive = null,
locale = locale,
consentAction = consentAction,
requestOptions = buildRequestOptions(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import com.stripe.android.payments.bankaccount.navigation.CollectBankAccountCont

internal class CollectBankAccountForACHLauncher(
private val hostActivityLauncher: ActivityResultLauncher<CollectBankAccountContract.Args>,
private val hostedSurface: String?
) : CollectBankAccountLauncher {

override fun presentWithPaymentIntent(
Expand All @@ -20,7 +19,6 @@ internal class CollectBankAccountForACHLauncher(
stripeAccountId = stripeAccountId,
clientSecret = clientSecret,
configuration = configuration,
hostedSurface = hostedSurface,
attachToIntent = true
)
)
Expand All @@ -38,7 +36,6 @@ internal class CollectBankAccountForACHLauncher(
stripeAccountId = stripeAccountId,
clientSecret = clientSecret,
configuration = configuration,
hostedSurface = hostedSurface,
attachToIntent = true
)
)
Expand All @@ -63,7 +60,6 @@ internal class CollectBankAccountForACHLauncher(
customerId = customerId,
onBehalfOf = onBehalfOf,
amount = amount,
hostedSurface = hostedSurface,
currency = currency,
)
)
Expand All @@ -84,7 +80,6 @@ internal class CollectBankAccountForACHLauncher(
elementsSessionId = elementsSessionId,
configuration = configuration,
customerId = customerId,
hostedSurface = hostedSurface,
onBehalfOf = onBehalfOf,
)
)
Expand Down
Loading

0 comments on commit ddc679b

Please sign in to comment.