-
Notifications
You must be signed in to change notification settings - Fork 645
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
[Refactor] Merge the post verification logic between verification panes. #8653
Draft
carlosmuvi-stripe
wants to merge
10
commits into
master
Choose a base branch
from
carlosmuvi/BANKCON-11254/android-support-for-networking-a-manually-entered
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
4cffe74
[skip ci] Start PR
carlosmuvi-stripe 63a60ad
Unify verification logic.
carlosmuvi-stripe d802569
Updates tests.
carlosmuvi-stripe cd9ff0a
Updates API.
carlosmuvi-stripe 9adc0cb
Adds more tests.
carlosmuvi-stripe a6c41b7
Ensures accounts are attached.
carlosmuvi-stripe 36c4f8f
Merge remote-tracking branch 'refs/remotes/origin/master' into carlos…
carlosmuvi-stripe 807098a
Style fixes.
carlosmuvi-stripe b7bf0e0
Test fixes.
carlosmuvi-stripe d0f31dd
Style fixes.
carlosmuvi-stripe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 117 additions & 0 deletions
117
...ions/src/main/java/com/stripe/android/financialconnections/domain/CompleteVerification.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
package com.stripe.android.financialconnections.domain | ||
|
||
import com.stripe.android.core.Logger | ||
import com.stripe.android.financialconnections.analytics.FinancialConnectionsAnalyticsEvent.VerificationError | ||
import com.stripe.android.financialconnections.analytics.FinancialConnectionsAnalyticsEvent.VerificationError.Error.MarkLinkVerifiedError | ||
import com.stripe.android.financialconnections.analytics.FinancialConnectionsAnalyticsEvent.VerificationSuccess | ||
import com.stripe.android.financialconnections.analytics.FinancialConnectionsAnalyticsTracker | ||
import com.stripe.android.financialconnections.analytics.logError | ||
import com.stripe.android.financialconnections.features.common.isDataFlow | ||
import com.stripe.android.financialconnections.model.FinancialConnectionsSessionManifest.Pane | ||
import com.stripe.android.financialconnections.model.PaymentAccountParams | ||
import com.stripe.android.financialconnections.navigation.Destination | ||
import com.stripe.android.financialconnections.navigation.Destination.Success | ||
import com.stripe.android.financialconnections.navigation.NavigationManager | ||
import com.stripe.android.financialconnections.navigation.destination | ||
import com.stripe.android.financialconnections.repository.AttachedPaymentAccountRepository | ||
import javax.inject.Inject | ||
|
||
internal class CompleteVerification @Inject constructor( | ||
private val cachedAccounts: GetCachedAccounts, | ||
private val saveAccountToLink: SaveAccountToLink, | ||
private val getOrFetchSync: GetOrFetchSync, | ||
private val analyticsTracker: FinancialConnectionsAnalyticsTracker, | ||
private val navigationManager: NavigationManager, | ||
private val logger: Logger, | ||
private val handleError: HandleError, | ||
private val markLinkVerified: MarkLinkVerified, | ||
private val attachedPaymentAccountRepository: AttachedPaymentAccountRepository, | ||
) { | ||
suspend operator fun invoke( | ||
pane: Pane, | ||
consumerSessionClientSecret: String, | ||
) { | ||
val manifest = getOrFetchSync().manifest | ||
val accounts = cachedAccounts() | ||
if (accounts.isNotEmpty()) { | ||
// If there are accounts to share (ie. user linked accounts first and then logged in) then save those | ||
// when we have already connected accounts, we first saveToNetworkAndLink and then markLinkVerified | ||
saveToNetworkAndLinkRequest( | ||
accounts = accounts, | ||
consumerSessionClientSecret = consumerSessionClientSecret, | ||
isDataFlow = manifest.isDataFlow, | ||
pane = pane | ||
) | ||
} else if (attachedPaymentAccountRepository.get()?.attachedPaymentAccount is PaymentAccountParams.BankAccount) { | ||
// we come here if the user has already attached their bank account and has then logged in | ||
// to an existing Link account. now we want network that bank account | ||
// we do not need to pass anything here since the bank account is already attached | ||
// and the backend pulls it from the LAS | ||
saveToNetworkAndLinkRequest( | ||
accounts = null, | ||
consumerSessionClientSecret = consumerSessionClientSecret, | ||
isDataFlow = manifest.isDataFlow, | ||
pane = pane | ||
) | ||
} else { | ||
// if the user is verifying at the beginning of the flow and hasn't connected accounts yet, | ||
// we just markLinkVerified and move onto returning user account picker. | ||
runCatching { markLinkVerified() }.fold( | ||
// TODO(carlosmuvi): once `/link_verified` is updated to return correct next_pane we should consume that | ||
onSuccess = { | ||
analyticsTracker.track(VerificationSuccess(pane)) | ||
navigationManager.tryNavigateTo(Destination.LinkAccountPicker(referrer = pane)) | ||
}, | ||
onFailure = { | ||
val nextPaneOnFailure = manifest.initialInstitution | ||
?.let { Pane.PARTNER_AUTH } | ||
?: Pane.INSTITUTION_PICKER | ||
analyticsTracker.logError( | ||
extraMessage = "Error confirming verification or marking link as verified", | ||
error = it, | ||
logger = logger, | ||
pane = pane | ||
) | ||
analyticsTracker.track(VerificationError(pane, MarkLinkVerifiedError)) | ||
navigationManager.tryNavigateTo(nextPaneOnFailure.destination(referrer = pane)) | ||
} | ||
) | ||
} | ||
} | ||
|
||
private suspend fun saveToNetworkAndLinkRequest( | ||
accounts: List<CachedPartnerAccount>?, | ||
consumerSessionClientSecret: String, | ||
isDataFlow: Boolean, | ||
pane: Pane | ||
) { | ||
runCatching { | ||
saveAccountToLink.existing( | ||
consumerSessionClientSecret = consumerSessionClientSecret, | ||
selectedAccounts = accounts, | ||
shouldPollAccountNumbers = isDataFlow | ||
) | ||
}.onSuccess { | ||
analyticsTracker.track(VerificationSuccess(pane)) | ||
}.onFailure { | ||
logger.error("Error saving account to Link", it) | ||
analyticsTracker.track(VerificationError(pane, VerificationError.Error.SaveToLinkError)) | ||
} | ||
|
||
runCatching { markLinkVerified() } | ||
.onSuccess { | ||
// navigate to success regardless of save result. | ||
// the save use case takes care of updating the success screen message (that will be a failure in case | ||
// of something going wrong) | ||
navigationManager.tryNavigateTo(Success(referrer = pane)) | ||
}.onFailure { | ||
// mimicking behavior from v2 where if this request fails we use default error handling | ||
handleError( | ||
extraMessage = "Error marking link as verified", | ||
error = it, | ||
pane = pane, | ||
displayErrorScreen = true | ||
) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ import com.stripe.android.financialconnections.model.FinancialConnectionsInstitu | |
import com.stripe.android.financialconnections.model.LinkAccountSessionPaymentAccount | ||
import com.stripe.android.financialconnections.model.PaymentAccountParams | ||
import com.stripe.android.financialconnections.model.SynchronizeSessionResponse | ||
import com.stripe.android.financialconnections.repository.AttachedPaymentAccountRepository | ||
import com.stripe.android.financialconnections.repository.FinancialConnectionsAccountsRepository | ||
import com.stripe.android.financialconnections.utils.PollTimingOptions | ||
import com.stripe.android.financialconnections.utils.retryOnException | ||
|
@@ -17,6 +18,7 @@ import kotlin.time.Duration.Companion.seconds | |
|
||
internal class PollAttachPaymentAccount @Inject constructor( | ||
private val repository: FinancialConnectionsAccountsRepository, | ||
private val attachedPaymentAccountRepository: AttachedPaymentAccountRepository, | ||
private val configuration: FinancialConnectionsSheet.Configuration | ||
) { | ||
|
||
|
@@ -35,11 +37,13 @@ internal class PollAttachPaymentAccount @Inject constructor( | |
retryCondition = { exception -> exception.shouldRetry } | ||
) { | ||
try { | ||
repository.postLinkAccountSessionPaymentAccount( | ||
repository.postAttachPaymentAccountToLinkAccountSession( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. renamed this api request to be more precise. |
||
clientSecret = configuration.financialConnectionsSessionClientSecret, | ||
paymentAccount = params, | ||
consumerSessionClientSecret = consumerSessionClientSecret | ||
) | ||
).also { | ||
attachedPaymentAccountRepository.set(params) | ||
} | ||
} catch (e: StripeException) { | ||
throw e.toDomainException( | ||
activeInstitution, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
equivalent web code: https://git.corp.stripe.com/stripe-internal/stripe-js-v3/blob/02e07063/src/linkedAccounts/inner/components/panes/v3/LinkVerificationPane/index.tsx#L177
Note this is just merging the logic across verification panes into a usecase. No new code here besides checking if an account of type
bank_account
has been previously attached.