Skip to content

Commit

Permalink
Pass intent information along to signup call
Browse files Browse the repository at this point in the history
  • Loading branch information
tillh-stripe committed Sep 12, 2024
1 parent e0ba692 commit f20ff8e
Show file tree
Hide file tree
Showing 25 changed files with 151 additions and 25 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,
intentContext = intentContext,
)
)
}
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.IntentContext
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,11 @@ internal class FinancialConnectionsPlaygroundViewModel(
publishableKey = it.publishableKey,
ephemeralKey = it.ephemeralKey,
customerId = it.customerId,
intentContext = IntentContext(
id = it.id,
amount = it.amount,
currency = it.currency,
),
experience = settings.get<ExperienceSetting>().selectedOption,
integrationType = settings.get<IntegrationTypeSetting>().selectedOption,
)
Expand Down Expand Up @@ -480,6 +486,7 @@ sealed class FinancialConnectionsPlaygroundViewEffect {
val publishableKey: String,
val experience: Experience,
val integrationType: IntegrationType,
val intentContext: IntentContext,
) : 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,14 @@ class FinancialConnectionsSheet internal constructor(
val stripeAccountId: String? = null
) : Parcelable

@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
@Parcelize
data class IntentContext(
val id: String?,
val amount: Long?,
val currency: String?,
) : Parcelable

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

@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
fun presentInternal(
configuration: Configuration,
intentContext: IntentContext?,
) {
financialConnectionsSheetLauncher.present(
configuration = configuration,
intentContext = intentContext,
)
}

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,
intentContext = viewEffect.intentContext,
)
)
)
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 intentContext: FinancialConnectionsSheet.IntentContext?,
) : 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.IntentContext
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,
intentContext = initialArgs.retrieveIntentContext(),
)
)
}
} else {
Expand Down Expand Up @@ -540,3 +545,7 @@ internal class FinancialConnectionsSheetViewModel @Inject constructor(
return null
}
}

private fun FinancialConnectionsSheetActivityArgs.retrieveIntentContext(): IntentContext? {
return (this as? ForInstantDebits)?.intentContext
}
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,
intentContext: FinancialConnectionsSheet.IntentContext?,
) = FinancialConnectionsConsumerSessionRepository(
financialConnectionsConsumersApiService = financialConnectionsConsumersApiService,
provideApiRequestOptions = provideApiRequestOptions,
Expand All @@ -131,6 +134,7 @@ internal interface FinancialConnectionsSheetNativeModule {
locale = locale ?: Locale.getDefault(),
logger = logger,
isLinkWithStripe = isLinkWithStripe,
intentContext = intentContext,
)

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

@Provides
internal fun provideIntentContext(
initialState: FinancialConnectionsSheetNativeState,
): FinancialConnectionsSheet.IntentContext? {
return initialState.intentContext
}
}
}
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,
val intentContext: FinancialConnectionsSheet.IntentContext?,
) : 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,
intentContext: FinancialConnectionsSheet.IntentContext?
) {
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,
intentContext: FinancialConnectionsSheet.IntentContext?
) {
activityResultLauncher.launch(
FinancialConnectionsSheetActivityArgs.ForInstantDebits(
configuration
)
FinancialConnectionsSheetActivityArgs.ForInstantDebits(configuration, intentContext)
)
}
}
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,
intentContext: FinancialConnectionsSheet.IntentContext?
) {
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,
intentContext: FinancialConnectionsSheet.IntentContext?,
)
}
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 intentContext: FinancialConnectionsSheet.IntentContext?,
) : 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.IntentContext
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 intentContext: IntentContext?,
) {

/**
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,
intentContext = args.intentContext,
)

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

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

Expand Down Expand Up @@ -120,6 +124,16 @@ private class FinancialConnectionsConsumerSessionRepositoryImpl(
country = country,
name = null,
locale = locale,
amount = intentContext?.amount,
currency = intentContext?.currency,
financialIncentive = intentContext?.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 @@ -6,6 +6,7 @@ import androidx.activity.result.ActivityResultLauncher
import androidx.activity.result.ActivityResultRegistryOwner
import androidx.annotation.RestrictTo
import androidx.fragment.app.Fragment
import com.stripe.android.financialconnections.FinancialConnectionsSheet.IntentContext
import com.stripe.android.payments.bankaccount.navigation.CollectBankAccountContract
import com.stripe.android.payments.bankaccount.navigation.CollectBankAccountResult
import com.stripe.android.payments.bankaccount.navigation.CollectBankAccountResultInternal
Expand Down Expand Up @@ -137,6 +138,7 @@ sealed interface CollectBankAccountConfiguration : Parcelable {
@Parcelize
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
data class InstantDebits(
val email: String?
val email: String?,
val intentContext: IntentContext?,
) : Parcelable, CollectBankAccountConfiguration
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ internal class CollectBankAccountActivity : AppCompatActivity() {
financialConnectionsPaymentsProxy.present(
financialConnectionsSessionClientSecret = financialConnectionsSessionSecret,
publishableKey = publishableKey,
stripeAccountId = stripeAccountId
stripeAccountId = stripeAccountId,
intentContext = intentContext,
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.stripe.android.payments.bankaccount.ui

import com.stripe.android.financialconnections.FinancialConnectionsSheet.IntentContext
import com.stripe.android.payments.bankaccount.navigation.CollectBankAccountResultInternal

/**
Expand All @@ -16,7 +17,8 @@ internal sealed class CollectBankAccountViewEffect {
data class OpenConnectionsFlow(
val publishableKey: String,
val financialConnectionsSessionSecret: String,
val stripeAccountId: String?
val stripeAccountId: String?,
val intentContext: IntentContext?,
) : CollectBankAccountViewEffect()

/**
Expand Down
Loading

0 comments on commit f20ff8e

Please sign in to comment.