Skip to content

Commit b7ae7ec

Browse files
committed
Track third party error event for CashAppPay
COAND-1009
1 parent 95a74a5 commit b7ae7ec

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

cashapppay/src/main/java/com/adyen/checkout/cashapppay/internal/ui/DefaultCashAppPayDelegate.kt

+11
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import com.adyen.checkout.components.core.PaymentMethodTypes
3434
import com.adyen.checkout.components.core.internal.PaymentComponentEvent
3535
import com.adyen.checkout.components.core.internal.PaymentObserverRepository
3636
import com.adyen.checkout.components.core.internal.analytics.AnalyticsManager
37+
import com.adyen.checkout.components.core.internal.analytics.ErrorEvent
3738
import com.adyen.checkout.components.core.internal.analytics.GenericEvents
3839
import com.adyen.checkout.components.core.internal.util.bufferedChannel
3940
import com.adyen.checkout.components.core.paymentmethod.CashAppPayPaymentMethod
@@ -280,10 +281,12 @@ constructor(
280281

281282
CashAppPayState.Declined -> {
282283
adyenLog(AdyenLogLevel.INFO) { "Cash App Pay authorization request declined" }
284+
trackSDKErrorEvent()
283285
exceptionChannel.trySend(ComponentException("Cash App Pay authorization request declined"))
284286
}
285287

286288
is CashAppPayState.CashAppPayExceptionState -> {
289+
trackSDKErrorEvent()
287290
exceptionChannel.trySend(
288291
ComponentException("Cash App Pay has encountered an error", newState.exception),
289292
)
@@ -311,6 +314,14 @@ constructor(
311314
)
312315
}
313316

317+
private fun trackSDKErrorEvent() {
318+
val event = GenericEvents.error(
319+
component = getPaymentMethodType(),
320+
event = ErrorEvent.THIRD_PARTY,
321+
)
322+
analyticsManager.trackEvent(event)
323+
}
324+
314325
override fun isConfirmationRequired(): Boolean =
315326
_viewFlow.value is ButtonComponentViewType &&
316327
componentParams.showStorePaymentField

cashapppay/src/test/java/com/adyen/checkout/cashapppay/internal/ui/DefaultCashAppPayDelegateTest.kt

+28
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import com.adyen.checkout.components.core.OrderRequest
3535
import com.adyen.checkout.components.core.PaymentComponentData
3636
import com.adyen.checkout.components.core.PaymentMethod
3737
import com.adyen.checkout.components.core.internal.PaymentObserverRepository
38+
import com.adyen.checkout.components.core.internal.analytics.ErrorEvent
3839
import com.adyen.checkout.components.core.internal.analytics.GenericEvents
3940
import com.adyen.checkout.components.core.internal.analytics.TestAnalyticsManager
4041
import com.adyen.checkout.components.core.internal.ui.model.CommonComponentParamsMapper
@@ -532,6 +533,33 @@ internal class DefaultCashAppPayDelegateTest(
532533
analyticsManager.assertLastEventNotEquals(expectedEvent)
533534
}
534535

536+
@Test
537+
fun `when state is declined, then an error is tracked`() = runTest {
538+
delegate.initialize(CoroutineScope(UnconfinedTestDispatcher()))
539+
540+
delegate.cashAppPayStateDidChange(CashAppPayState.Declined)
541+
542+
val expectedEvent = GenericEvents.error(
543+
component = TEST_PAYMENT_METHOD_TYPE,
544+
event = ErrorEvent.THIRD_PARTY
545+
)
546+
analyticsManager.assertLastEventEquals(expectedEvent)
547+
}
548+
549+
@Test
550+
fun `when state is exception, then an error is tracked`() = runTest {
551+
delegate.initialize(CoroutineScope(UnconfinedTestDispatcher()))
552+
val exception = RuntimeException("Stub!")
553+
554+
delegate.cashAppPayStateDidChange(CashAppPayState.CashAppPayExceptionState(exception))
555+
556+
val expectedEvent = GenericEvents.error(
557+
component = TEST_PAYMENT_METHOD_TYPE,
558+
event = ErrorEvent.THIRD_PARTY
559+
)
560+
analyticsManager.assertLastEventEquals(expectedEvent)
561+
}
562+
535563
@Test
536564
fun `when delegate is cleared then analytics manager is cleared`() {
537565
delegate.initialize(CoroutineScope(UnconfinedTestDispatcher()))

0 commit comments

Comments
 (0)