-
Notifications
You must be signed in to change notification settings - Fork 664
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Abstract Link Attestation Check (#10103)
- Loading branch information
1 parent
129c556
commit 257b869
Showing
13 changed files
with
338 additions
and
315 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
...entsheet/src/main/java/com/stripe/android/link/attestation/DefaultLinkAttestationCheck.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package com.stripe.android.link.attestation | ||
|
||
import com.stripe.android.core.exception.StripeException | ||
import com.stripe.android.link.LinkConfiguration | ||
import com.stripe.android.link.account.LinkAccountManager | ||
import com.stripe.android.link.account.LinkAuth | ||
import com.stripe.android.link.account.LinkAuthResult | ||
import com.stripe.android.link.gate.LinkGate | ||
import com.stripe.android.model.EmailSource | ||
import com.stripe.android.payments.core.analytics.ErrorReporter | ||
import com.stripe.attestation.IntegrityRequestManager | ||
import javax.inject.Inject | ||
|
||
internal class DefaultLinkAttestationCheck @Inject constructor( | ||
private val linkGate: LinkGate, | ||
private val linkAuth: LinkAuth, | ||
private val integrityRequestManager: IntegrityRequestManager, | ||
private val linkAccountManager: LinkAccountManager, | ||
private val linkConfiguration: LinkConfiguration, | ||
private val errorReporter: ErrorReporter | ||
) : LinkAttestationCheck { | ||
override suspend fun invoke(): LinkAttestationCheck.Result { | ||
if (linkGate.useAttestationEndpoints.not()) return LinkAttestationCheck.Result.Successful | ||
val result = integrityRequestManager.prepare() | ||
|
||
return result.fold( | ||
onSuccess = { | ||
val email = linkAccountManager.linkAccount.value?.email | ||
?: linkConfiguration.customerInfo.email | ||
if (email == null) return@fold LinkAttestationCheck.Result.Successful | ||
val lookupResult = linkAuth.lookUp( | ||
email = email, | ||
emailSource = EmailSource.CUSTOMER_OBJECT, | ||
startSession = false | ||
) | ||
when (lookupResult) { | ||
is LinkAuthResult.AttestationFailed -> { | ||
LinkAttestationCheck.Result.AttestationFailed(lookupResult.error) | ||
} | ||
is LinkAuthResult.Error -> { | ||
LinkAttestationCheck.Result.Error(lookupResult.error) | ||
} | ||
is LinkAuthResult.AccountError -> { | ||
LinkAttestationCheck.Result.AccountError(lookupResult.error) | ||
} | ||
LinkAuthResult.NoLinkAccountFound, | ||
is LinkAuthResult.Success -> { | ||
LinkAttestationCheck.Result.Successful | ||
} | ||
} | ||
}, | ||
onFailure = { error -> | ||
errorReporter.report( | ||
errorEvent = ErrorReporter.ExpectedErrorEvent.LINK_NATIVE_FAILED_TO_PREPARE_INTEGRITY_MANAGER, | ||
stripeException = StripeException.create(error) | ||
) | ||
LinkAttestationCheck.Result.AttestationFailed(error) | ||
} | ||
) | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
paymentsheet/src/main/java/com/stripe/android/link/attestation/LinkAttestationCheck.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.stripe.android.link.attestation | ||
|
||
internal interface LinkAttestationCheck { | ||
suspend fun invoke(): Result | ||
|
||
sealed interface Result { | ||
data object Successful : Result | ||
data class AttestationFailed(val error: Throwable) : Result | ||
data class AccountError(val error: Throwable) : Result | ||
data class Error(val error: Throwable) : Result | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
paymentsheet/src/main/java/com/stripe/android/link/injection/ApplicationIdModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.stripe.android.link.injection | ||
|
||
import android.app.Application | ||
import dagger.Module | ||
import dagger.Provides | ||
import javax.inject.Named | ||
|
||
@Module | ||
internal object ApplicationIdModule { | ||
@Provides | ||
@Named(APPLICATION_ID) | ||
fun provideApplicationId( | ||
application: Application | ||
): String { | ||
return application.packageName | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...entsheet/src/main/java/com/stripe/android/link/injection/IntegrityRequestManagerModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.stripe.android.link.injection | ||
|
||
import android.app.Application | ||
import com.stripe.android.BuildConfig | ||
import com.stripe.android.core.Logger | ||
import com.stripe.attestation.IntegrityRequestManager | ||
import com.stripe.attestation.IntegrityStandardRequestManager | ||
import com.stripe.attestation.RealStandardIntegrityManagerFactory | ||
import dagger.Module | ||
import dagger.Provides | ||
|
||
@Module | ||
internal object IntegrityRequestManagerModule { | ||
@Provides | ||
fun providesIntegrityStandardRequestManager( | ||
context: Application | ||
): IntegrityRequestManager = IntegrityStandardRequestManager( | ||
cloudProjectNumber = 577365562050, // stripe-payments-sdk-prod | ||
logError = { message, error -> | ||
Logger.getInstance(BuildConfig.DEBUG).error(message, error) | ||
}, | ||
factory = RealStandardIntegrityManagerFactory(context) | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.