Skip to content

Commit

Permalink
Track redirect cancelled event
Browse files Browse the repository at this point in the history
COAND-1006
  • Loading branch information
araratthehero committed Nov 19, 2024
1 parent f11c5c8 commit cb9dcf9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit cb9dcf9

Please sign in to comment.