Skip to content

Commit

Permalink
Add error event
Browse files Browse the repository at this point in the history
  • Loading branch information
toluo-stripe committed Jan 24, 2025
1 parent 6ce4f21 commit af59a0e
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,9 @@ interface ErrorReporter : FraudDetectionErrorReporter {
LINK_WEB_FAILED_TO_PARSE_RESULT_URI(
partialEventName = "link.web.result.parsing_failed"
),
LINK_NATIVE_FAILED_TO_PREPARE_INTEGRITY_MANAGER(
partialEventName = "link.native.integrity.preparation_failed"
),
PAYMENT_SHEET_AUTHENTICATORS_NOT_FOUND(
partialEventName = "paymentsheet.authenticators.not_found"
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import com.stripe.android.link.model.AccountStatus
import com.stripe.android.link.model.LinkAccount
import com.stripe.android.link.ui.LinkAppBarState
import com.stripe.android.paymentelement.confirmation.ConfirmationHandler
import com.stripe.android.payments.core.analytics.ErrorReporter
import com.stripe.android.paymentsheet.R
import com.stripe.android.paymentsheet.analytics.EventReporter
import com.stripe.attestation.IntegrityRequestManager
Expand All @@ -37,7 +38,8 @@ internal class LinkActivityViewModel @Inject constructor(
private val linkAccountManager: LinkAccountManager,
val eventReporter: EventReporter,
private val integrityRequestManager: IntegrityRequestManager,
private val linkGate: LinkGate
private val linkGate: LinkGate,
private val errorReporter: ErrorReporter,
) : ViewModel(), DefaultLifecycleObserver {
val confirmationHandler = confirmationHandlerFactory.create(viewModelScope)
private val _linkState = MutableStateFlow(
Expand Down Expand Up @@ -135,6 +137,10 @@ internal class LinkActivityViewModel @Inject constructor(
val error = result.exceptionOrNull()
if (error != null) {
moveToWeb()
errorReporter.report(
errorEvent = ErrorReporter.UnexpectedErrorEvent.LINK_NATIVE_FAILED_TO_PREPARE_INTEGRITY_MANAGER,
stripeException = LinkEventException(error)
)
return false
}
return true
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.stripe.android.link

import com.stripe.android.core.exception.StripeException

class LinkEventException(override val cause: Throwable): StripeException(cause = cause)
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.stripe.android.link.LinkActivityViewModel
import com.stripe.android.link.account.LinkAccountManager
import com.stripe.android.link.gate.LinkGate
import com.stripe.android.paymentelement.confirmation.DefaultConfirmationHandler
import com.stripe.android.payments.core.analytics.ErrorReporter
import com.stripe.android.paymentsheet.analytics.EventReporter
import com.stripe.attestation.IntegrityRequestManager
import dagger.Module
Expand All @@ -19,15 +20,17 @@ internal object LinkViewModelModule {
linkAccountManager: LinkAccountManager,
eventReporter: EventReporter,
integrityRequestManager: IntegrityRequestManager,
linkGate: LinkGate
linkGate: LinkGate,
errorReporter: ErrorReporter
): LinkActivityViewModel {
return LinkActivityViewModel(
activityRetainedComponent = component,
confirmationHandlerFactory = defaultConfirmationHandlerFactory,
linkAccountManager = linkAccountManager,
eventReporter = eventReporter,
integrityRequestManager = integrityRequestManager,
linkGate = linkGate
linkGate = linkGate,
errorReporter = errorReporter
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ import com.stripe.android.link.injection.NativeLinkComponent
import com.stripe.android.link.model.AccountStatus
import com.stripe.android.paymentelement.confirmation.ConfirmationHandler
import com.stripe.android.paymentelement.confirmation.FakeConfirmationHandler
import com.stripe.android.payments.core.analytics.ErrorReporter
import com.stripe.android.paymentsheet.analytics.EventReporter
import com.stripe.android.paymentsheet.analytics.FakeEventReporter
import com.stripe.android.testing.CoroutineTestRule
import com.stripe.android.testing.FakeErrorReporter
import com.stripe.android.testing.FakeLogger
import com.stripe.android.utils.DummyActivityResultCaller
import com.stripe.android.utils.NullCardAccountRangeRepositoryFactory
Expand Down Expand Up @@ -314,6 +316,7 @@ internal class LinkActivityViewModelTest {
val navController = navController()
val linkGate = FakeLinkGate()
val integrityRequestManager = FakeIntegrityRequestManager()
val errorReporter = FakeErrorReporter()

integrityRequestManager.prepareResult = Result.failure(Throwable("oops"))
linkGate.setUseAttestationEndpoints(true)
Expand All @@ -322,6 +325,7 @@ internal class LinkActivityViewModelTest {
linkAccountManager = linkAccountManager,
linkGate = linkGate,
integrityRequestManager = integrityRequestManager,
errorReporter = errorReporter,
launchWeb = { config ->
launchWebConfig = config
}
Expand All @@ -341,6 +345,10 @@ internal class LinkActivityViewModelTest {
launchSingleTop = false
)
assertThat(launchWebConfig).isNotNull()
assertThat(errorReporter.getLoggedErrors())
.containsExactly(
ErrorReporter.UnexpectedErrorEvent.LINK_NATIVE_FAILED_TO_PREPARE_INTEGRITY_MANAGER.eventName
)
integrityRequestManager.ensureAllEventsConsumed()
}

Expand Down Expand Up @@ -459,6 +467,7 @@ internal class LinkActivityViewModelTest {
navController: NavHostController = navController(),
integrityRequestManager: IntegrityRequestManager = FakeIntegrityRequestManager(),
linkGate: LinkGate = FakeLinkGate(),
errorReporter: ErrorReporter = FakeErrorReporter(),
dismissWithResult: (LinkActivityResult) -> Unit = {},
launchWeb: (LinkConfiguration) -> Unit = {}
): LinkActivityViewModel {
Expand All @@ -468,7 +477,8 @@ internal class LinkActivityViewModelTest {
eventReporter = eventReporter,
confirmationHandlerFactory = { confirmationHandler },
integrityRequestManager = integrityRequestManager,
linkGate = linkGate
linkGate = linkGate,
errorReporter = errorReporter
).apply {
this.navController = navController
this.dismissWithResult = dismissWithResult
Expand Down

0 comments on commit af59a0e

Please sign in to comment.