Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve payment selection for guests #5480

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Inject whether Link is enabled for testability
  • Loading branch information
tillh-stripe committed Sep 9, 2022
commit f2c4ec4a39318d0ac23feb9e1f8a5d9e8c499fb4
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ const val CUSTOMER_NAME = "customerName"
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
const val SHIPPING_VALUES = "shippingValues"

/**
* Identifies whether Link is enabled.
*/
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
const val LINK_ENABLED = "linkEnabled"

/**
* Identifies the Stripe Intent being processed by Link.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.stripe.android.core.injection.IOContext
import com.stripe.android.googlepaylauncher.GooglePayEnvironment
import com.stripe.android.googlepaylauncher.GooglePayRepository
import com.stripe.android.link.LinkPaymentLauncher
import com.stripe.android.link.injection.LINK_ENABLED
import com.stripe.android.model.PaymentMethod
import com.stripe.android.model.StripeIntent
import com.stripe.android.paymentsheet.PaymentSheet
Expand All @@ -23,6 +24,7 @@ import com.stripe.android.ui.core.forms.resources.ResourceRepository
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.withContext
import javax.inject.Inject
import javax.inject.Named
import javax.inject.Singleton
import kotlin.coroutines.CoroutineContext

Expand All @@ -38,7 +40,8 @@ internal class DefaultFlowControllerInitializer @Inject constructor(
private val lpmResourceRepository: ResourceRepository<LpmRepository>,
private val logger: Logger,
val eventReporter: EventReporter,
@IOContext private val workContext: CoroutineContext
@IOContext private val workContext: CoroutineContext,
@Named(LINK_ENABLED) private val isLinkEnabled: Boolean
) : FlowControllerInitializer {

override suspend fun init(
Expand All @@ -50,7 +53,7 @@ internal class DefaultFlowControllerInitializer @Inject constructor(
retrieveStripeIntent(clientSecret)
}.fold(
onSuccess = { stripeIntent ->
val isLinkReady = LinkPaymentLauncher.LINK_ENABLED &&
val isLinkReady = isLinkEnabled &&
stripeIntent.paymentMethodTypes.contains(PaymentMethod.Type.Link.code)

create(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import android.content.Context
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.ViewModelStoreOwner
import com.stripe.android.core.injection.IOContext
import com.stripe.android.link.LinkPaymentLauncher
import com.stripe.android.link.injection.LINK_ENABLED
import com.stripe.android.payments.core.injection.PRODUCT_USAGE
import com.stripe.android.paymentsheet.DefaultPrefsRepository
import com.stripe.android.paymentsheet.PaymentSheet
Expand Down Expand Up @@ -70,6 +72,11 @@ internal abstract class FlowControllerModule {
@Named(PRODUCT_USAGE)
fun provideProductUsageTokens() = setOf("PaymentSheet.FlowController")

@Provides
@Singleton
@Named(LINK_ENABLED)
fun provideLinkEnabled() = LinkPaymentLauncher.LINK_ENABLED

@Provides
@Singleton
fun provideViewModel(viewModelStoreOwner: ViewModelStoreOwner): FlowControllerViewModel =
Expand Down