Skip to content

Commit

Permalink
Track error events for Google Pay
Browse files Browse the repository at this point in the history
COAND-1009
  • Loading branch information
araratthehero authored and OscarSpruit committed Dec 10, 2024
1 parent 7abe21c commit fd29e5b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -231,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 Down Expand Up @@ -275,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 Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,20 @@ 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)
Expand Down Expand Up @@ -426,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))),
)
}
}

0 comments on commit fd29e5b

Please sign in to comment.