Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Renames LinkAccountSession to FinancialConnectionsSession. #4910

Merged
merged 14 commits into from
Apr 28, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ class FinancialConnectionsExampleViewModel : ViewModel() {
fun onFinancialConnectionsSheetResult(result: FinancialConnectionsSheetResult) {
val statusText = when (result) {
is Completed -> {
val linkedAccountList = result.linkAccountSession.linkedAccounts
linkedAccountList.linkedAccounts.joinToString("\n") {
val linkedAccountList = result.financialConnectionsSession.accounts
linkedAccountList.financialConnectionsAccounts.joinToString("\n") {
"${it.institutionName} - ${it.displayName} - ${it.last4} - ${it.category}/${it.subcategory}"
}
}
Expand Down
364 changes: 182 additions & 182 deletions financial-connections/api/financial-connections.api

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import com.stripe.android.financialconnections.launcher.FinancialConnectionsShee
import kotlinx.parcelize.Parcelize

/**
* A drop in class to present the Link Account Session Auth Flow.
* A drop in class to present the Financial Connections Auth Flow.
*
* This *must* be called unconditionally, as part of initialization path,
* typically as a field initializer of an Activity or Fragment.
Expand All @@ -21,12 +21,12 @@ class FinancialConnectionsSheet internal constructor(
/**
* Configuration for a [FinancialConnectionsSheet]
*
* @param linkAccountSessionClientSecret the client secret for the Link Account Session
* @param financialConnectionsSessionClientSecret the session client secret
* @param publishableKey the Stripe publishable key
*/
@Parcelize
data class Configuration(
val linkAccountSessionClientSecret: String,
val financialConnectionsSessionClientSecret: String,
val publishableKey: String,
) : Parcelable

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ internal class FinancialConnectionsSheetActivity : AppCompatActivity() {
}

/**
* If the back button is pressed during the manifest fetch or link account session fetch
* If the back button is pressed during the manifest fetch or session fetch
* return canceled result
*/
override fun onBackPressed() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import android.os.Bundle
import android.os.Parcelable
import androidx.activity.result.contract.ActivityResultContract
import androidx.core.os.bundleOf
import com.stripe.android.financialconnections.model.LinkAccountSession
import com.stripe.android.financialconnections.model.FinancialConnectionsSession
import com.stripe.android.model.Token
import kotlinx.parcelize.Parcelize
import java.security.InvalidParameterException
Expand Down Expand Up @@ -48,9 +48,9 @@ internal class FinancialConnectionsSheetContract :
) : Args(configuration)

fun validate() {
if (configuration.linkAccountSessionClientSecret.isBlank()) {
if (configuration.financialConnectionsSessionClientSecret.isBlank()) {
throw InvalidParameterException(
"The link account session client secret cannot be an empty string."
"The session client secret cannot be an empty string."
)
}
if (configuration.publishableKey.isBlank()) {
Expand All @@ -70,11 +70,11 @@ internal class FinancialConnectionsSheetContract :
internal sealed class Result : Parcelable {
/**
* The customer completed the connections session.
* @param linkAccountSession The link account session connected
* @param financialConnectionsSession The financial connections session connected
*/
@Parcelize
data class Completed(
val linkAccountSession: LinkAccountSession,
val financialConnectionsSession: FinancialConnectionsSession,
val token: Token? = null
) : Result()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.stripe.android.connections

import android.os.Parcelable
import com.stripe.android.financialconnections.model.LinkAccountSession
import com.stripe.android.financialconnections.model.FinancialConnectionsSession
import com.stripe.android.model.Token
import kotlinx.parcelize.Parcelize

Expand All @@ -11,11 +11,11 @@ import kotlinx.parcelize.Parcelize
sealed class FinancialConnectionsSheetForTokenResult : Parcelable {
/**
* The customer completed the connections session.
* @param linkAccountSession The link account session connected
* @param financialConnectionsSession The financial connections session connected
*/
@Parcelize
data class Completed(
val linkAccountSession: LinkAccountSession,
val financialConnectionsSession: FinancialConnectionsSession,
val token: Token
) : FinancialConnectionsSheetForTokenResult()

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

import android.os.Parcelable
import com.stripe.android.financialconnections.model.LinkAccountSession
import com.stripe.android.financialconnections.model.FinancialConnectionsSession
import kotlinx.parcelize.Parcelize

/**
Expand All @@ -10,11 +10,11 @@ import kotlinx.parcelize.Parcelize
sealed class FinancialConnectionsSheetResult : Parcelable {
/**
* The customer completed the connections session.
* @param linkAccountSession The link account session connected
* @param financialConnectionsSession The financial connections session connected
*/
@Parcelize
data class Completed(
val linkAccountSession: LinkAccountSession
val financialConnectionsSession: FinancialConnectionsSession
) : FinancialConnectionsSheetResult()

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.stripe.android.financialconnections

import androidx.lifecycle.SavedStateHandle
import com.stripe.android.financialconnections.model.LinkAccountSessionManifest
import com.stripe.android.financialconnections.model.FinancialConnectionsSessionManifest

/**
* Class containing all of the data needed to represent the screen.
*/
internal data class FinancialConnectionsSheetState(
val activityRecreated: Boolean = false,
val manifest: LinkAccountSessionManifest? = null,
val manifest: FinancialConnectionsSessionManifest? = null,
val authFlowActive: Boolean = false
) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import androidx.savedstate.SavedStateRegistryOwner
import com.stripe.android.connections.domain.FetchLinkAccountSessionForToken
import com.stripe.android.financialconnections.FinancialConnectionsSheetContract.Result.Canceled
import com.stripe.android.financialconnections.FinancialConnectionsSheetContract.Result.Completed
import com.stripe.android.financialconnections.FinancialConnectionsSheetContract.Result.Failed
Expand All @@ -17,10 +16,11 @@ import com.stripe.android.financialconnections.FinancialConnectionsSheetViewEffe
import com.stripe.android.financialconnections.analytics.FinancialConnectionsEventReporter
import com.stripe.android.financialconnections.di.APPLICATION_ID
import com.stripe.android.financialconnections.di.DaggerFinancialConnectionsSheetComponent
import com.stripe.android.financialconnections.domain.FetchLinkAccountSession
import com.stripe.android.financialconnections.domain.GenerateLinkAccountSessionManifest
import com.stripe.android.financialconnections.model.LinkAccountSession
import com.stripe.android.financialconnections.model.LinkAccountSessionManifest
import com.stripe.android.financialconnections.domain.FetchFinancialConnectionsSession
import com.stripe.android.financialconnections.domain.FetchFinancialConnectionsSessionForToken
import com.stripe.android.financialconnections.domain.GenerateFinancialConnectionsSessionManifest
import com.stripe.android.financialconnections.model.FinancialConnectionsSession
import com.stripe.android.financialconnections.model.FinancialConnectionsSessionManifest
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharedFlow
Expand All @@ -34,9 +34,9 @@ import javax.inject.Named
internal class FinancialConnectionsSheetViewModel @Inject constructor(
@Named(APPLICATION_ID) private val applicationId: String,
private val starterArgs: FinancialConnectionsSheetContract.Args,
private val generateLinkAccountSessionManifest: GenerateLinkAccountSessionManifest,
private val fetchLinkAccountSession: FetchLinkAccountSession,
private val fetchLinkAccountSessionForToken: FetchLinkAccountSessionForToken,
private val generateFinancialConnectionsSessionManifest: GenerateFinancialConnectionsSessionManifest,
private val fetchFinancialConnectionsSession: FetchFinancialConnectionsSession,
private val fetchFinancialConnectionsSessionForToken: FetchFinancialConnectionsSessionForToken,
private val savedStateHandle: SavedStateHandle,
private val eventReporter: FinancialConnectionsEventReporter
) : ViewModel() {
Expand All @@ -57,14 +57,14 @@ internal class FinancialConnectionsSheetViewModel @Inject constructor(
}

/**
* Fetches the [LinkAccountSessionManifest] from the Stripe API to get the hosted auth flow URL
* Fetches the [FinancialConnectionsSessionManifest] from the Stripe API to get the hosted auth flow URL
* as well as the success and cancel callback URLs to verify.
*/
private fun fetchManifest() {
viewModelScope.launch {
kotlin.runCatching {
generateLinkAccountSessionManifest(
clientSecret = starterArgs.configuration.linkAccountSessionClientSecret,
generateFinancialConnectionsSessionManifest(
clientSecret = starterArgs.configuration.financialConnectionsSessionClientSecret,
applicationId = applicationId
)
}.onFailure {
Expand All @@ -81,7 +81,7 @@ internal class FinancialConnectionsSheetViewModel @Inject constructor(
* @param manifest the manifest containing the hosted auth flow URL to launch
*
*/
private suspend fun openAuthFlow(manifest: LinkAccountSessionManifest) {
private suspend fun openAuthFlow(manifest: FinancialConnectionsSessionManifest) {
// stores manifest in state for future references.
_state.updateAndPersist {
it.copy(
Expand Down Expand Up @@ -139,16 +139,16 @@ internal class FinancialConnectionsSheetViewModel @Inject constructor(
}

/**
* For regular connections flows requesting a link account session:
* For regular connections flows requesting a session:
*
* On successfully completing the hosted auth flow and receiving the success callback intent,
* fetch the updated [LinkAccountSession] model from the API
* fetch the updated [FinancialConnectionsSession] model from the API
* and return it back as a [Completed] result.
*/
private fun fetchLinkAccountSession() {
private fun fetchFinancialConnectionsSession() {
viewModelScope.launch {
kotlin.runCatching {
fetchLinkAccountSession(starterArgs.configuration.linkAccountSessionClientSecret)
fetchFinancialConnectionsSession(starterArgs.configuration.financialConnectionsSessionClientSecret)
}.onSuccess {
val result = Completed(it)
eventReporter.onResult(starterArgs.configuration, result)
Expand All @@ -163,13 +163,15 @@ internal class FinancialConnectionsSheetViewModel @Inject constructor(
* For connections flows requesting an account [com.stripe.android.model.Token]:
*
* On successfully completing the hosted auth flow and receiving the success callback intent,
* fetch the updated [LinkAccountSession] and the generated [com.stripe.android.model.Token]
* fetch the updated [FinancialConnectionsSession] and the generated [com.stripe.android.model.Token]
* and return it back as a [Completed] result.
*/
private fun fetchLinkAccountSessionForToken() {
private fun fetchFinancialConnectionsSessionForToken() {
viewModelScope.launch {
kotlin.runCatching {
fetchLinkAccountSessionForToken(starterArgs.configuration.linkAccountSessionClientSecret)
fetchFinancialConnectionsSessionForToken(
clientSecret = starterArgs.configuration.financialConnectionsSessionClientSecret
)
}.onSuccess { (las, token) ->
val result = Completed(las, token)
eventReporter.onResult(starterArgs.configuration, result)
Expand Down Expand Up @@ -217,8 +219,8 @@ internal class FinancialConnectionsSheetViewModel @Inject constructor(
val manifest = _state.value.manifest
when (intent?.data.toString()) {
manifest?.successUrl -> when (starterArgs) {
is FinancialConnectionsSheetContract.Args.Default -> fetchLinkAccountSession()
is FinancialConnectionsSheetContract.Args.ForToken -> fetchLinkAccountSessionForToken()
is FinancialConnectionsSheetContract.Args.Default -> fetchFinancialConnectionsSession()
is FinancialConnectionsSheetContract.Args.ForToken -> fetchFinancialConnectionsSessionForToken()
}
manifest?.cancelUrl -> onUserCancel()
else -> onFatal(Exception("Error processing FinancialConnectionsSheet intent"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ internal class DefaultFinancialFinancialConnectionsEventReporter @Inject constru
fireEvent(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

File naming?

FinancialConnectionsAnalyticsEvent(
FinancialConnectionsAnalyticsEvent.Code.SheetPresented,
mapOf(PARAM_CLIENT_SECRET to configuration.linkAccountSessionClientSecret)
mapOf(PARAM_CLIENT_SECRET to configuration.financialConnectionsSessionClientSecret)
)
)
}
Expand All @@ -34,23 +34,23 @@ internal class DefaultFinancialFinancialConnectionsEventReporter @Inject constru
FinancialConnectionsAnalyticsEvent(
FinancialConnectionsAnalyticsEvent.Code.SheetClosed,
mapOf(
PARAM_CLIENT_SECRET to configuration.linkAccountSessionClientSecret,
PARAM_CLIENT_SECRET to configuration.financialConnectionsSessionClientSecret,
PARAM_SESSION_RESULT to "completed"
)
)
is FinancialConnectionsSheetContract.Result.Canceled ->
FinancialConnectionsAnalyticsEvent(
FinancialConnectionsAnalyticsEvent.Code.SheetClosed,
mapOf(
PARAM_CLIENT_SECRET to configuration.linkAccountSessionClientSecret,
PARAM_CLIENT_SECRET to configuration.financialConnectionsSessionClientSecret,
PARAM_SESSION_RESULT to "cancelled"
)
)
is FinancialConnectionsSheetContract.Result.Failed ->
FinancialConnectionsAnalyticsEvent(
FinancialConnectionsAnalyticsEvent.Code.SheetFailed,
mapOf(
PARAM_CLIENT_SECRET to configuration.linkAccountSessionClientSecret,
PARAM_CLIENT_SECRET to configuration.financialConnectionsSessionClientSecret,
PARAM_SESSION_RESULT to "failure"
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import com.stripe.android.core.networking.DefaultStripeNetworkClient
import com.stripe.android.core.networking.StripeNetworkClient
import com.stripe.android.financialconnections.analytics.DefaultFinancialFinancialConnectionsEventReporter
import com.stripe.android.financialconnections.analytics.FinancialConnectionsEventReporter
import com.stripe.android.financialconnections.repository.FinancialConnectionsApiRepository
import com.stripe.android.financialconnections.repository.FinancialConnectionsRepository
import com.stripe.android.financialconnections.repository.FinancialFinancialConnectionsApiRepository
import dagger.Module
import dagger.Provides
import java.util.Locale
Expand Down Expand Up @@ -43,7 +43,7 @@ internal object FinancialConnectionsSheetModule {
@Provides
@Singleton
fun provideConnectionsRepository(
repository: FinancialFinancialConnectionsApiRepository
repository: FinancialConnectionsApiRepository
): FinancialConnectionsRepository = repository

@Provides
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.stripe.android.financialconnections.domain

import com.stripe.android.financialconnections.FinancialConnectionsSheetViewModel
import com.stripe.android.financialconnections.model.FinancialConnectionsAccount
import com.stripe.android.financialconnections.model.FinancialConnectionsAccountList
import com.stripe.android.financialconnections.model.FinancialConnectionsSession
import com.stripe.android.financialconnections.model.GetFinancialConnectionsAcccountsParams
import com.stripe.android.financialconnections.repository.FinancialConnectionsRepository
import javax.inject.Inject

internal class FetchFinancialConnectionsSession @Inject constructor(
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No changes, just renamed the class.

private val financialConnectionsRepository: FinancialConnectionsRepository
) {

/**
* Fetches the session with all the connected accounts via pagination
*
* @param clientSecret the [FinancialConnectionsSession] client secret
*
* @return [FinancialConnectionsSession] with all connected accounts
*/
suspend operator fun invoke(clientSecret: String): FinancialConnectionsSession {
val session = financialConnectionsRepository.getFinancialConnectionsSession(clientSecret)
if (session.accounts.hasMore) {
val accounts = mutableListOf<FinancialConnectionsAccount>()
accounts.addAll(session.accounts.financialConnectionsAccounts)

var nextAccountList = financialConnectionsRepository.getFinancialConnectionsAccounts(
GetFinancialConnectionsAcccountsParams(clientSecret, accounts.last().id)
)
accounts.addAll(nextAccountList.financialConnectionsAccounts)

while (nextAccountList.hasMore && accounts.size < FinancialConnectionsSheetViewModel.MAX_ACCOUNTS) {
nextAccountList = financialConnectionsRepository.getFinancialConnectionsAccounts(
GetFinancialConnectionsAcccountsParams(clientSecret, accounts.last().id)
)
accounts.addAll(nextAccountList.financialConnectionsAccounts)
}

return FinancialConnectionsSession(
id = session.id,
clientSecret = session.clientSecret,
accounts = FinancialConnectionsAccountList(
financialConnectionsAccounts = accounts,
hasMore = nextAccountList.hasMore,
url = nextAccountList.url,
count = accounts.size,
totalCount = nextAccountList.totalCount
),
bankAccountToken = null, // Token should not be exposed on regular sessions.
livemode = session.livemode
)
}
return session
}
}
Loading