Skip to content

Commit

Permalink
Track third party error event for Google Pay
Browse files Browse the repository at this point in the history
COAND-1009
  • Loading branch information
araratthehero committed Nov 11, 2024
1 parent 5fa28c6 commit 3ad7360
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,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.core.AdyenLogLevel
Expand Down Expand Up @@ -149,6 +150,7 @@ internal class DefaultGooglePayDelegate(
when (resultCode) {
Activity.RESULT_OK -> {
if (data == null) {
trackSDKErrorEvent()
exceptionChannel.trySend(ComponentException("Result data is null"))
return
}
Expand All @@ -157,10 +159,13 @@ internal class DefaultGooglePayDelegate(
}

Activity.RESULT_CANCELED -> {
trackSDKErrorEvent()
exceptionChannel.trySend(ComponentException("Payment canceled."))
}

AutoResolveHelper.RESULT_ERROR -> {
trackSDKErrorEvent()

val status = AutoResolveHelper.getStatusFromIntent(data)
val statusMessage: String = status?.let { ": ${it.statusMessage}" }.orEmpty()
exceptionChannel.trySend(ComponentException("GooglePay returned an error$statusMessage"))
Expand All @@ -170,6 +175,14 @@ internal class DefaultGooglePayDelegate(
}
}

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

override fun getGooglePayButtonParameters(): GooglePayButtonParameters {
val allowedPaymentMethodsList = GooglePayUtils.getAllowedPaymentMethods(componentParams)
val allowedPaymentMethods = ModelUtils.serializeOptList(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@

package com.adyen.checkout.googlepay.internal.ui

import android.app.Activity
import app.cash.turbine.test
import com.adyen.checkout.components.core.Amount
import com.adyen.checkout.components.core.CheckoutConfiguration
import com.adyen.checkout.components.core.Configuration
import com.adyen.checkout.components.core.OrderRequest
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 @@ -185,6 +187,28 @@ internal class DefaultGooglePayDelegateTest {

analyticsManager.assertIsCleared()
}

@Test
fun `when activity result is OK and data is null, then error event is tracked`() {
delegate.handleActivityResult(Activity.RESULT_OK, data = null)

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

@Test
fun `when activity result is CANCELLED, then error event is tracked`() {
delegate.handleActivityResult(Activity.RESULT_CANCELED, data = null)

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

private fun createCheckoutConfiguration(
Expand Down

0 comments on commit 3ad7360

Please sign in to comment.