From 7855ff4865e749952284d06080ffa5444678373c Mon Sep 17 00:00:00 2001 From: Till Hellmund Date: Fri, 10 Jan 2025 15:47:05 -0500 Subject: [PATCH] Propagate `Result` to call-site --- .../domain/CreateInstantDebitsResult.kt | 15 ++++++--------- ...ancialConnectionsConsumerSessionRepository.kt | 6 +++--- .../domain/RealCreateInstantDebitsResultTest.kt | 16 +++++++++------- 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/financial-connections/src/main/java/com/stripe/android/financialconnections/domain/CreateInstantDebitsResult.kt b/financial-connections/src/main/java/com/stripe/android/financialconnections/domain/CreateInstantDebitsResult.kt index 325dd9db150..85d004c50fe 100644 --- a/financial-connections/src/main/java/com/stripe/android/financialconnections/domain/CreateInstantDebitsResult.kt +++ b/financial-connections/src/main/java/com/stripe/android/financialconnections/domain/CreateInstantDebitsResult.kt @@ -61,15 +61,12 @@ internal class RealCreateInstantDebitsResult @Inject constructor( val incentiveEligibilitySessionId = elementsSessionContext?.incentiveEligibilitySession?.id val eligibleForIncentive = if (incentiveEligibilitySessionId != null) { - runCatching { - consumerRepository.updateAvailableIncentives( - sessionId = incentiveEligibilitySessionId, - consumerSessionClientSecret = clientSecret, - ) - }.fold( - onSuccess = { it.data.isNotEmpty() }, - onFailure = { false }, - ) + consumerRepository.updateAvailableIncentives( + sessionId = incentiveEligibilitySessionId, + consumerSessionClientSecret = clientSecret, + ).map { + it.data.isNotEmpty() + }.getOrDefault(false) } else { false } diff --git a/financial-connections/src/main/java/com/stripe/android/financialconnections/repository/FinancialConnectionsConsumerSessionRepository.kt b/financial-connections/src/main/java/com/stripe/android/financialconnections/repository/FinancialConnectionsConsumerSessionRepository.kt index 53f2ec7d591..9bfeeea8e8d 100644 --- a/financial-connections/src/main/java/com/stripe/android/financialconnections/repository/FinancialConnectionsConsumerSessionRepository.kt +++ b/financial-connections/src/main/java/com/stripe/android/financialconnections/repository/FinancialConnectionsConsumerSessionRepository.kt @@ -73,7 +73,7 @@ internal interface FinancialConnectionsConsumerSessionRepository { suspend fun updateAvailableIncentives( sessionId: String, consumerSessionClientSecret: String, - ): UpdateAvailableIncentives + ): Result companion object { operator fun invoke( @@ -247,13 +247,13 @@ private class FinancialConnectionsConsumerSessionRepositoryImpl( override suspend fun updateAvailableIncentives( sessionId: String, consumerSessionClientSecret: String, - ): UpdateAvailableIncentives { + ): Result { return consumersApiService.updateAvailableIncentives( sessionId = sessionId, consumerSessionClientSecret = consumerSessionClientSecret, requestSurface = requestSurface, requestOptions = provideApiRequestOptions(useConsumerPublishableKey = true), - ).getOrThrow() + ) } private suspend fun postConsumerSession( diff --git a/financial-connections/src/test/java/com/stripe/android/financialconnections/domain/RealCreateInstantDebitsResultTest.kt b/financial-connections/src/test/java/com/stripe/android/financialconnections/domain/RealCreateInstantDebitsResultTest.kt index c7564be2517..fce3a4a818a 100644 --- a/financial-connections/src/test/java/com/stripe/android/financialconnections/domain/RealCreateInstantDebitsResultTest.kt +++ b/financial-connections/src/test/java/com/stripe/android/financialconnections/domain/RealCreateInstantDebitsResultTest.kt @@ -221,13 +221,15 @@ class RealCreateInstantDebitsResultTest { consumerSessionClientSecret = eq("clientSecret"), ) ).thenReturn( - UpdateAvailableIncentives( - data = listOf( - LinkConsumerIncentive( - incentiveParams = LinkConsumerIncentive.IncentiveParams( - paymentMethod = "link_instant_debits", - ), - incentiveDisplayText = "$5", + Result.success( + UpdateAvailableIncentives( + data = listOf( + LinkConsumerIncentive( + incentiveParams = LinkConsumerIncentive.IncentiveParams( + paymentMethod = "link_instant_debits", + ), + incentiveDisplayText = "$5", + ) ) ) )