Skip to content

Commit

Permalink
Uses prefill details.
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosmuvi-stripe committed Jan 28, 2025
1 parent 71cb403 commit 87d6018
Show file tree
Hide file tree
Showing 10 changed files with 221 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ internal class FinancialConnectionsSheetViewModel @Inject constructor(
if (result is Failed && result.error is FinancialConnectionsAttestationError) {
val error = result.error
integrityVerdictManager.setVerdictFailed()
switchToWebFlow(error.prefilledEmail)
switchToWebFlow(error.prefillDetails)
return
}
eventReporter.onResult(state.initialArgs.configuration, result)
Expand All @@ -562,19 +562,13 @@ internal class FinancialConnectionsSheetViewModel @Inject constructor(
/**
* On scenarios where native failed mid flow due to attestation errors, switch back to web flow.
*/
private fun switchToWebFlow(prefilledEmail: String?) {
private fun switchToWebFlow(prefillDetails: PrefillDetails?) {
viewModelScope.launch {
val sync = getOrFetchSync()
val hostedAuthUrl = HostedAuthUrlBuilder.create(
args = initialState.initialArgs,
manifest = sync.manifest,
sdkPrefillDetails = prefilledEmail?.let {
PrefillDetails(
email = it,
phone = null,
phoneCountryCode = null
)
}
sdkPrefillDetails = prefillDetails
)

if (hostedAuthUrl != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ internal class LookupAccount @Inject constructor(

suspend operator fun invoke(
email: String,
phone: String?,
phoneCountryCode: String?,
emailSource: EmailSource,
verifiedFlow: Boolean,
sessionId: String,
Expand All @@ -45,7 +47,13 @@ internal class LookupAccount @Inject constructor(
)
}
}.getOrElse { throwable ->
throw throwable.toAttestationErrorIfApplicable(prefilledEmail = email)
throw throwable.toAttestationErrorIfApplicable(
FinancialConnectionsSheet.ElementsSessionContext.PrefillDetails(
email = email,
phone = phone,
phoneCountryCode = phoneCountryCode
)
)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
package com.stripe.android.financialconnections.features.error

import com.stripe.android.core.exception.APIException
import com.stripe.android.financialconnections.FinancialConnectionsSheet.ElementsSessionContext.PrefillDetails
import com.stripe.attestation.AttestationError

internal fun Throwable.toAttestationErrorIfApplicable(prefilledEmail: String?): Throwable {
internal fun Throwable.toAttestationErrorIfApplicable(sdkPrefillDetails: PrefillDetails?): Throwable {
return when {
this is APIException && stripeError?.code == "link_failed_to_attest_request" -> FinancialConnectionsAttestationError(
errorType = AttestationError.ErrorType.BACKEND_VERDICT_FAILED,
message = stripeError?.message ?: "An unknown error occurred",
prefilledEmail = prefilledEmail,
prefillDetails = sdkPrefillDetails,
cause = this
)
this is AttestationError -> FinancialConnectionsAttestationError(
errorType = this.errorType,
message = this.message ?: "An unknown error occurred",
prefilledEmail = prefilledEmail,
prefillDetails = sdkPrefillDetails,
cause = this
)
else -> this
Expand All @@ -23,7 +24,7 @@ internal fun Throwable.toAttestationErrorIfApplicable(prefilledEmail: String?):

internal class FinancialConnectionsAttestationError(
val errorType: AttestationError.ErrorType,
val prefilledEmail: String?,
val prefillDetails: PrefillDetails?,
message: String,
cause: Throwable? = null
) : Exception(message, cause)
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ internal class NetworkingLinkLoginWarmupViewModel @AssistedInject constructor(
lookupAccount(
pane = PANE,
email = payload.email,
phone = null,
phoneCountryCode = null,
emailSource = EmailSource.CUSTOMER_OBJECT,
sessionId = payload.sessionId,
verifiedFlow = payload.verifiedFlow
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.stripe.android.financialconnections.features.networkinglinksignup

import com.stripe.android.core.Logger
import com.stripe.android.financialconnections.FinancialConnectionsSheet.ElementsSessionContext.PrefillDetails
import com.stripe.android.financialconnections.analytics.FinancialConnectionsAnalyticsEvent.AttestationEndpoint.SIGNUP
import com.stripe.android.financialconnections.analytics.FinancialConnectionsAnalyticsEvent.Click
import com.stripe.android.financialconnections.analytics.FinancialConnectionsAnalyticsTracker
Expand Down Expand Up @@ -94,7 +95,13 @@ internal class LinkSignupHandlerForInstantDebits @Inject constructor(
) {
handleError(
extraMessage = "Error creating a Link account",
error = error.toAttestationErrorIfApplicable(state.validEmail!!),
error = error.toAttestationErrorIfApplicable(
PrefillDetails(
state.validEmail!!,
state.validPhone,
state.payload()!!.phoneController.getCountryCode()
)
),
pane = LINK_LOGIN,
displayErrorScreen = true,
)
Expand Down Expand Up @@ -167,7 +174,13 @@ internal class LinkSignupHandlerForNetworking @Inject constructor(
) {
eventTracker.logError(
extraMessage = "Error saving account to Link",
error = error.toAttestationErrorIfApplicable(state.validEmail!!),
error = error.toAttestationErrorIfApplicable(
PrefillDetails(
state.validEmail!!,
state.validPhone,
state.payload()!!.phoneController.getCountryCode()
)
),
logger = logger,
pane = NETWORKING_LINK_SIGNUP_PANE,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ internal class NetworkingLinkSignupViewModel @AssistedInject constructor(
lookupAccount(
pane = pane,
email = validEmail,
phone = payload?.phoneController?.getLocalNumber(),
phoneCountryCode = payload?.phoneController?.getCountryCode(),
emailSource = if (payload?.prefilledEmail == validEmail) CUSTOMER_OBJECT else USER_ACTION,
sessionId = payload?.sessionId ?: "",
verifiedFlow = payload?.appVerificationEnabled == true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,12 @@ class NetworkingLinkLoginWarmupViewModelTest {
whenever(
lookupAccount(
email = anyOrNull(),
phone = anyOrNull(),
phoneCountryCode = anyOrNull(),
emailSource = anyOrNull(),
verifiedFlow = anyOrNull(),
sessionId = anyOrNull(),
pane = any()
pane = anyOrNull()
)
).thenReturn(
ConsumerSessionLookup(
Expand All @@ -96,7 +98,15 @@ class NetworkingLinkLoginWarmupViewModelTest {
val viewModel = buildViewModel(NetworkingLinkLoginWarmupState())
viewModel.onContinueClick()

verify(lookupAccount).invoke(any(), any(), any(), any(), any())
verify(lookupAccount).invoke(
email = anyOrNull(),
phone = anyOrNull(),
phoneCountryCode = anyOrNull(),
emailSource = anyOrNull(),
verifiedFlow = anyOrNull(),
sessionId = anyOrNull(),
pane = anyOrNull()
)
navigationManager.assertNavigatedTo(
destination = Destination.NetworkingLinkVerification,
pane = Pane.NETWORKING_LINK_LOGIN_WARMUP
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,15 @@ class LinkSignupHandlerForInstantDebitsTest {

@Test
fun `handleSignupFailure should call handleError with correct parameters`() = runTest {
val testState = NetworkingLinkSignupState(
validEmail = "[email protected]",
validPhone = "+1234567890",
isInstantDebits = true,
payload = Async.Success(validPayload)
)
val error = RuntimeException("Test Error")
handler.handleSignupFailure(error)

handler.handleSignupFailure(testState, error)

verify(handleError).invoke(
extraMessage = "Error creating a Link account",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,14 @@ class LinkSignupHandlerForNetworkingTest {
@Test
fun `handleSignupFailure should log error and navigate to Success pane`() = runTest {
val error = RuntimeException("Test Error")
val testState = NetworkingLinkSignupState(
validEmail = "[email protected]",
validPhone = "+1234567890",
isInstantDebits = true,
payload = Async.Success(validPayload)
)

handler.handleSignupFailure(error)
handler.handleSignupFailure(testState, error)

verify(eventTracker).logError(
extraMessage = "Error saving account to Link",
Expand Down
Loading

0 comments on commit 87d6018

Please sign in to comment.