diff --git a/redirect/src/main/java/com/adyen/checkout/redirect/internal/ui/DefaultRedirectDelegate.kt b/redirect/src/main/java/com/adyen/checkout/redirect/internal/ui/DefaultRedirectDelegate.kt index 227fc4cb85..061b4b2ef0 100644 --- a/redirect/src/main/java/com/adyen/checkout/redirect/internal/ui/DefaultRedirectDelegate.kt +++ b/redirect/src/main/java/com/adyen/checkout/redirect/internal/ui/DefaultRedirectDelegate.kt @@ -28,6 +28,7 @@ import com.adyen.checkout.components.core.internal.analytics.GenericEvents import com.adyen.checkout.components.core.internal.ui.model.GenericComponentParams import com.adyen.checkout.components.core.internal.util.bufferedChannel import com.adyen.checkout.core.AdyenLogLevel +import com.adyen.checkout.core.exception.CancellationException import com.adyen.checkout.core.exception.CheckoutException import com.adyen.checkout.core.exception.ComponentException import com.adyen.checkout.core.exception.HttpException @@ -200,6 +201,14 @@ constructor( } override fun onError(e: CheckoutException) { + if (e is CancellationException) { + val event = GenericEvents.error( + component = action?.paymentMethodType.orEmpty(), + event = ErrorEvent.REDIRECT_CANCELLED + ) + analyticsManager?.trackEvent(event) + } + emitError(e) } diff --git a/redirect/src/test/java/com/adyen/checkout/redirect/internal/ui/DefaultRedirectDelegateTest.kt b/redirect/src/test/java/com/adyen/checkout/redirect/internal/ui/DefaultRedirectDelegateTest.kt index 8643e3c165..d57fa4bede 100644 --- a/redirect/src/test/java/com/adyen/checkout/redirect/internal/ui/DefaultRedirectDelegateTest.kt +++ b/redirect/src/test/java/com/adyen/checkout/redirect/internal/ui/DefaultRedirectDelegateTest.kt @@ -23,6 +23,7 @@ import com.adyen.checkout.components.core.internal.analytics.TestAnalyticsManage import com.adyen.checkout.components.core.internal.ui.model.CommonComponentParamsMapper import com.adyen.checkout.components.core.internal.ui.model.GenericComponentParamsMapper import com.adyen.checkout.core.Environment +import com.adyen.checkout.core.exception.CancellationException import com.adyen.checkout.core.exception.ComponentException import com.adyen.checkout.core.exception.HttpException import com.adyen.checkout.core.exception.ModelSerializationException @@ -236,6 +237,24 @@ internal class DefaultRedirectDelegateTest( ) analyticsManager.assertLastEventEquals(expectedEvent) } + + @Test + fun `when redirect is cancelled with CancellationException, then an event is tracked`() = runTest { + val action = RedirectAction( + paymentMethodType = TEST_PAYMENT_METHOD_TYPE, + type = TEST_ACTION_TYPE, + ) + delegate.handleAction(action, Activity()) + + val exception = CancellationException("Redirect flow cancelled.") + delegate.onError(exception) + + val expectedEvent = GenericEvents.error( + component = TEST_PAYMENT_METHOD_TYPE, + event = ErrorEvent.REDIRECT_CANCELLED, + ) + analyticsManager.assertLastEventEquals(expectedEvent) + } } @Test