Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Analytics - Track third party error events - Google pay #1900

Draft
wants to merge 1 commit into
base: feature/google-pay
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -230,16 +231,19 @@ internal class DefaultGooglePayDelegate(
AutoResolveHelper.RESULT_ERROR -> {
val statusMessage: String = paymentDataTaskResult.status.statusMessage?.let { ": $it" }.orEmpty()
adyenLog(AdyenLogLevel.ERROR) { "GooglePay encountered an error$statusMessage" }
trackThirdPartyErrorEvent()
exceptionChannel.trySend(ComponentException("GooglePay encountered an error$statusMessage"))
}

CommonStatusCodes.INTERNAL_ERROR -> {
adyenLog(AdyenLogLevel.ERROR) { "GooglePay encountered an internal error" }
trackThirdPartyErrorEvent()
exceptionChannel.trySend(ComponentException("GooglePay encountered an internal error"))
}

else -> {
adyenLog(AdyenLogLevel.ERROR) { "GooglePay encountered an unexpected error, statusCode: $statusCode" }
trackThirdPartyErrorEvent()
exceptionChannel.trySend(ComponentException("GooglePay encountered an unexpected error"))
}
}
Expand All @@ -250,6 +254,7 @@ internal class DefaultGooglePayDelegate(
when (resultCode) {
Activity.RESULT_OK -> {
if (data == null) {
trackThirdPartyErrorEvent()
exceptionChannel.trySend(ComponentException("Result data is null"))
return
}
Expand All @@ -261,6 +266,8 @@ internal class DefaultGooglePayDelegate(
}

AutoResolveHelper.RESULT_ERROR -> {
trackThirdPartyErrorEvent()

val status = AutoResolveHelper.getStatusFromIntent(data)
val statusMessage: String = status?.let { ": ${it.statusMessage}" }.orEmpty()
exceptionChannel.trySend(ComponentException("GooglePay returned an error$statusMessage"))
Expand All @@ -271,6 +278,7 @@ internal class DefaultGooglePayDelegate(
private fun initiatePayment(paymentData: PaymentData?) {
if (paymentData == null) {
adyenLog(AdyenLogLevel.ERROR) { "Payment data is null" }
trackThirdPartyErrorEvent()
exceptionChannel.trySend(ComponentException("GooglePay encountered an unexpected error"))
return
}
Expand All @@ -283,6 +291,14 @@ internal class DefaultGooglePayDelegate(
submitHandler.onSubmit(_componentStateFlow.value)
}

private fun trackThirdPartyErrorEvent() {
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,6 +8,7 @@

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
Expand All @@ -16,6 +17,7 @@ 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 @@ -287,6 +289,31 @@ internal class DefaultGooglePayDelegateTest(

analyticsManager.assertIsCleared()
}

@ParameterizedTest
@MethodSource("com.adyen.checkout.googlepay.internal.ui.DefaultGooglePayDelegateTest#paymentResultErrorSource")
fun `when handling payment result is error, then error event is tracked`(
result: ApiTaskResult<PaymentData>
) {
delegate.handlePaymentResult(result)

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

@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)
}
}

@ParameterizedTest
Expand Down Expand Up @@ -413,5 +440,14 @@ internal class DefaultGooglePayDelegateTest(
arguments(true, false, false, GooglePayUnavailableException()),
arguments(true, true, true, null),
)

@JvmStatic
fun paymentResultErrorSource() = listOf(
// result
arguments(ApiTaskResult(null, Status.RESULT_SUCCESS)),
arguments(ApiTaskResult(null, Status.RESULT_INTERNAL_ERROR)),
arguments(ApiTaskResult(null, Status.RESULT_INTERRUPTED)),
arguments(ApiTaskResult(null, Status(AutoResolveHelper.RESULT_ERROR))),
)
}
}