From 6d10183fbcb6097e5cacc91ef6f65fd0211d37ad Mon Sep 17 00:00:00 2001 From: Ararat Mnatsakanyan Date: Mon, 11 Nov 2024 12:42:06 +0100 Subject: [PATCH] Track third party error event for CashAppPay COAND-1009 --- .../internal/ui/DefaultCashAppPayDelegate.kt | 11 ++++++++ .../ui/DefaultCashAppPayDelegateTest.kt | 28 +++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/cashapppay/src/main/java/com/adyen/checkout/cashapppay/internal/ui/DefaultCashAppPayDelegate.kt b/cashapppay/src/main/java/com/adyen/checkout/cashapppay/internal/ui/DefaultCashAppPayDelegate.kt index 639a297589..2bee8d4808 100644 --- a/cashapppay/src/main/java/com/adyen/checkout/cashapppay/internal/ui/DefaultCashAppPayDelegate.kt +++ b/cashapppay/src/main/java/com/adyen/checkout/cashapppay/internal/ui/DefaultCashAppPayDelegate.kt @@ -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 @@ -280,10 +281,12 @@ constructor( CashAppPayState.Declined -> { adyenLog(AdyenLogLevel.INFO) { "Cash App Pay authorization request declined" } + trackSDKErrorEvent() exceptionChannel.trySend(ComponentException("Cash App Pay authorization request declined")) } is CashAppPayState.CashAppPayExceptionState -> { + trackSDKErrorEvent() exceptionChannel.trySend( ComponentException("Cash App Pay has encountered an error", newState.exception), ) @@ -311,6 +314,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 diff --git a/cashapppay/src/test/java/com/adyen/checkout/cashapppay/internal/ui/DefaultCashAppPayDelegateTest.kt b/cashapppay/src/test/java/com/adyen/checkout/cashapppay/internal/ui/DefaultCashAppPayDelegateTest.kt index f009258f17..547bffa42c 100644 --- a/cashapppay/src/test/java/com/adyen/checkout/cashapppay/internal/ui/DefaultCashAppPayDelegateTest.kt +++ b/cashapppay/src/test/java/com/adyen/checkout/cashapppay/internal/ui/DefaultCashAppPayDelegateTest.kt @@ -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 @@ -532,6 +533,33 @@ internal class DefaultCashAppPayDelegateTest( analyticsManager.assertLastEventNotEquals(expectedEvent) } + @Test + fun `when state is declined, then an error is tracked`() = runTest { + delegate.initialize(CoroutineScope(UnconfinedTestDispatcher())) + + delegate.cashAppPayStateDidChange(CashAppPayState.Declined) + + val expectedEvent = GenericEvents.error( + component = TEST_PAYMENT_METHOD_TYPE, + event = ErrorEvent.THIRD_PARTY + ) + analyticsManager.assertLastEventEquals(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()))