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 20, 2024
1 parent 2e1e840 commit b950651
Show file tree
Hide file tree
Showing 2 changed files with 52 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 @@ -228,16 +229,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 @@ -248,6 +252,7 @@ internal class DefaultGooglePayDelegate(
when (resultCode) {
Activity.RESULT_OK -> {
if (data == null) {
trackThirdPartyErrorEvent()
exceptionChannel.trySend(ComponentException("Result data is null"))
return
}
Expand All @@ -259,6 +264,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 @@ -269,6 +276,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 @@ -281,6 +289,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 @@ -269,6 +271,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 @@ -390,5 +417,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))),
)
}
}

0 comments on commit b950651

Please sign in to comment.