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 33d92ae commit 6d10183
Show file tree
Hide file tree
Showing 2 changed files with 39 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 @@ -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),
)
Expand Down Expand Up @@ -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
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,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()))
Expand Down

0 comments on commit 6d10183

Please sign in to comment.