@@ -12,7 +12,9 @@ import com.stripe.android.core.utils.UserFacingLogger
12
12
import com.stripe.android.googlepaylauncher.GooglePayEnvironment
13
13
import com.stripe.android.googlepaylauncher.GooglePayRepository
14
14
import com.stripe.android.link.LinkConfiguration
15
+ import com.stripe.android.link.LinkConfigurationCoordinator
15
16
import com.stripe.android.link.account.LinkStore
17
+ import com.stripe.android.link.attestation.LinkAttestationCheck
16
18
import com.stripe.android.link.gate.LinkGate
17
19
import com.stripe.android.link.model.AccountStatus
18
20
import com.stripe.android.link.model.LinkAppearance
@@ -150,6 +152,7 @@ internal class DefaultPaymentElementLoader @Inject constructor(
150
152
private val accountStatusProvider : LinkAccountStatusProvider ,
151
153
private val logLinkHoldbackExperiment : LogLinkHoldbackExperiment ,
152
154
private val linkStore : LinkStore ,
155
+ private val attestationCheck : LinkConfigurationCoordinator ,
153
156
private val linkGateFactory : LinkGate .Factory ,
154
157
private val externalPaymentMethodsRepository : ExternalPaymentMethodsRepository ,
155
158
private val userFacingLogger : UserFacingLogger ,
@@ -483,6 +486,11 @@ internal class DefaultPaymentElementLoader @Inject constructor(
483
486
initializationMode = initializationMode,
484
487
linkAppearance = linkAppearance
485
488
) ? : return null
489
+ // Disable link if attestation is required and fails.
490
+ if (attestationPassed(linkConfig).not ()) {
491
+ return null
492
+ }
493
+
486
494
return loadLinkState(
487
495
configuration = configuration,
488
496
linkConfiguration = linkConfig,
@@ -491,6 +499,21 @@ internal class DefaultPaymentElementLoader @Inject constructor(
491
499
)
492
500
}
493
501
502
+ private suspend fun attestationPassed (linkConfig : LinkConfiguration ): Boolean = runCatching {
503
+ val attestationResult = attestationCheck.linkAttestationCheck(linkConfig)
504
+ .invoke()
505
+ when (attestationResult) {
506
+ is LinkAttestationCheck .Result .AccountError ,
507
+ is LinkAttestationCheck .Result .AttestationFailed ,
508
+ is LinkAttestationCheck .Result .Error -> {
509
+ false
510
+ }
511
+ LinkAttestationCheck .Result .Successful -> {
512
+ true
513
+ }
514
+ }
515
+ }.getOrDefault(false )
516
+
494
517
private suspend fun loadLinkState (
495
518
configuration : CommonConfiguration ,
496
519
linkConfiguration : LinkConfiguration ,
@@ -611,8 +634,8 @@ internal class DefaultPaymentElementLoader @Inject constructor(
611
634
defaultBillingDetails = configuration.defaultBillingDetails,
612
635
allowDefaultOptIn = elementsSession.allowLinkDefaultOptIn,
613
636
googlePlacesApiKey = configuration.googlePlacesApiKey,
614
- collectMissingBillingDetailsForExistingPaymentMethods =
615
- configuration .link.collectMissingBillingDetailsForExistingPaymentMethods,
637
+ collectMissingBillingDetailsForExistingPaymentMethods = configuration
638
+ .link.collectMissingBillingDetailsForExistingPaymentMethods,
616
639
allowUserEmailEdits = configuration.link.allowUserEmailEdits,
617
640
skipWalletInFlowController = elementsSession.linkMobileSkipWalletInFlowController,
618
641
customerId = elementsSession.customer?.session?.customerId,
@@ -678,6 +701,7 @@ internal class DefaultPaymentElementLoader @Inject constructor(
678
701
customer : CustomerState ? ,
679
702
isGooglePayReady : Boolean ,
680
703
): PaymentSelection ? {
704
+ return PaymentSelection .Link ()
681
705
val isDefaultPaymentMethodEnabled = metadata.customerMetadata?.isPaymentMethodSetAsDefaultEnabled ? : false
682
706
val primaryPaymentSelection = if (isDefaultPaymentMethodEnabled) {
683
707
customer?.paymentMethods?.firstOrNull {
0 commit comments