Skip to content

Commit

Permalink
Sends supports_app_verification to syncrhonize when Integrity available
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosmuvi-stripe committed Dec 23, 2024
1 parent dae2c69 commit ecc939b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,11 @@ internal class FinancialConnectionsSheetViewModel @Inject constructor(
private fun fetchManifest() {
viewModelScope.launch {
kotlin.runCatching {
prepareStandardRequestManager()
getOrFetchSync(refetchCondition = Always)
val attestationInitialized = prepareStandardRequestManager()
getOrFetchSync(
refetchCondition = Always,
attestationInitialized = attestationInitialized
)
}.onFailure {
finishWithResult(stateFlow.value, Failed(it))
}.onSuccess {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ internal class GetOrFetchSync @Inject constructor(
) {

suspend operator fun invoke(
refetchCondition: RefetchCondition = RefetchCondition.None
refetchCondition: RefetchCondition = RefetchCondition.None,
attestationInitialized: Boolean? = null
): SynchronizeSessionResponse {
return repository.getOrSynchronizeFinancialConnectionsSession(
clientSecret = configuration.financialConnectionsSessionClientSecret,
applicationId = applicationId,
reFetchCondition = refetchCondition::shouldReFetch,
attestationInitialized = attestationInitialized
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ internal interface FinancialConnectionsManifestRepository {
suspend fun getOrSynchronizeFinancialConnectionsSession(
clientSecret: String,
applicationId: String,
attestationInitialized: Boolean?,
reFetchCondition: (SynchronizeSessionResponse) -> Boolean
): SynchronizeSessionResponse

Expand Down Expand Up @@ -206,15 +207,17 @@ private class FinancialConnectionsManifestRepositoryImpl(
override suspend fun getOrSynchronizeFinancialConnectionsSession(
clientSecret: String,
applicationId: String,
attestationInitialized: Boolean?,
reFetchCondition: (SynchronizeSessionResponse) -> Boolean
): SynchronizeSessionResponse = mutex.withLock {
val cachedSync = cachedSynchronizeSessionResponse?.takeUnless(reFetchCondition)
return cachedSync ?: synchronize(applicationId, clientSecret)
return cachedSync ?: synchronize(applicationId, clientSecret, attestationInitialized)
}

private suspend fun synchronize(
applicationId: String,
clientSecret: String,
attestationInitialized: Boolean?,
): SynchronizeSessionResponse = requestExecutor.execute(
apiRequestFactory.createPost(
url = synchronizeSessionUrl,
Expand All @@ -228,6 +231,8 @@ private class FinancialConnectionsManifestRepositoryImpl(
"forced_authflow_version" to "v3",
PARAMS_FULLSCREEN to true,
PARAMS_HIDE_CLOSE_BUTTON to true,
PARAMS_SUPPORT_APP_VERIFICATION to attestationInitialized,
PARAMS_VERIFY_APP_ID to applicationId.takeIf { attestationInitialized == true },
NetworkConstants.PARAMS_APPLICATION_ID to applicationId
),
NetworkConstants.PARAMS_CLIENT_SECRET to clientSecret
Expand Down Expand Up @@ -523,6 +528,8 @@ private class FinancialConnectionsManifestRepositoryImpl(
companion object {
internal const val PARAMS_FULLSCREEN = "fullscreen"
internal const val PARAMS_HIDE_CLOSE_BUTTON = "hide_close_button"
internal const val PARAMS_SUPPORT_APP_VERIFICATION = "supports_app_verification"
internal const val PARAMS_VERIFY_APP_ID = "verified_app_id"

internal const val synchronizeSessionUrl: String =
"${ApiRequest.API_HOST}/v1/financial_connections/sessions/synchronize"
Expand Down

0 comments on commit ecc939b

Please sign in to comment.