Skip to content

Commit

Permalink
Propagate Result<T> to call-site
Browse files Browse the repository at this point in the history
  • Loading branch information
tillh-stripe committed Jan 10, 2025
1 parent 132e90a commit 7855ff4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ internal interface FinancialConnectionsConsumerSessionRepository {
suspend fun updateAvailableIncentives(
sessionId: String,
consumerSessionClientSecret: String,
): UpdateAvailableIncentives
): Result<UpdateAvailableIncentives>

companion object {
operator fun invoke(
Expand Down Expand Up @@ -247,13 +247,13 @@ private class FinancialConnectionsConsumerSessionRepositoryImpl(
override suspend fun updateAvailableIncentives(
sessionId: String,
consumerSessionClientSecret: String,
): UpdateAvailableIncentives {
): Result<UpdateAvailableIncentives> {
return consumersApiService.updateAvailableIncentives(
sessionId = sessionId,
consumerSessionClientSecret = consumerSessionClientSecret,
requestSurface = requestSurface,
requestOptions = provideApiRequestOptions(useConsumerPublishableKey = true),
).getOrThrow()
)
}

private suspend fun postConsumerSession(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
)
)
)
Expand Down

0 comments on commit 7855ff4

Please sign in to comment.