Skip to content

Commit

Permalink
Track third party error event for CashAppPay
Browse files Browse the repository at this point in the history
COAND-1009
  • Loading branch information
araratthehero committed Nov 11, 2024
1 parent c24aa4d commit 5fa28c6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import com.adyen.checkout.components.core.PaymentMethodTypes
import com.adyen.checkout.components.core.internal.PaymentComponentEvent
import com.adyen.checkout.components.core.internal.PaymentObserverRepository
import com.adyen.checkout.components.core.internal.analytics.AnalyticsManager
import com.adyen.checkout.components.core.internal.analytics.ErrorEvent
import com.adyen.checkout.components.core.internal.analytics.GenericEvents
import com.adyen.checkout.components.core.internal.util.bufferedChannel
import com.adyen.checkout.components.core.paymentmethod.CashAppPayPaymentMethod
Expand Down Expand Up @@ -284,6 +285,7 @@ constructor(
}

is CashAppPayState.CashAppPayExceptionState -> {
trackSDKErrorEvent()
exceptionChannel.trySend(
ComponentException("Cash App Pay has encountered an error", newState.exception),
)
Expand Down Expand Up @@ -311,6 +313,14 @@ constructor(
)
}

private fun trackSDKErrorEvent() {
val event = GenericEvents.error(
component = getPaymentMethodType(),
event = ErrorEvent.THIRD_PARTY,
)
analyticsManager.trackEvent(event)
}

override fun isConfirmationRequired(): Boolean =
_viewFlow.value is ButtonComponentViewType &&
componentParams.showStorePaymentField
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import com.adyen.checkout.components.core.OrderRequest
import com.adyen.checkout.components.core.PaymentComponentData
import com.adyen.checkout.components.core.PaymentMethod
import com.adyen.checkout.components.core.internal.PaymentObserverRepository
import com.adyen.checkout.components.core.internal.analytics.ErrorEvent
import com.adyen.checkout.components.core.internal.analytics.GenericEvents
import com.adyen.checkout.components.core.internal.analytics.TestAnalyticsManager
import com.adyen.checkout.components.core.internal.ui.model.CommonComponentParamsMapper
Expand Down Expand Up @@ -532,6 +533,20 @@ internal class DefaultCashAppPayDelegateTest(
analyticsManager.assertLastEventNotEquals(expectedEvent)
}

@Test
fun `when state is exception, then an error is tracked`() = runTest {
delegate.initialize(CoroutineScope(UnconfinedTestDispatcher()))
val exception = RuntimeException("Stub!")

delegate.cashAppPayStateDidChange(CashAppPayState.CashAppPayExceptionState(exception))

val expectedEvent = GenericEvents.error(
component = TEST_PAYMENT_METHOD_TYPE,
event = ErrorEvent.THIRD_PARTY
)
analyticsManager.assertLastEventEquals(expectedEvent)
}

@Test
fun `when delegate is cleared then analytics manager is cleared`() {
delegate.initialize(CoroutineScope(UnconfinedTestDispatcher()))
Expand Down

0 comments on commit 5fa28c6

Please sign in to comment.