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

Create empty manage PMs screen #8523

Merged
merged 11 commits into from
May 23, 2024
7 changes: 7 additions & 0 deletions paymentsheet/api/paymentsheet.api
Original file line number Diff line number Diff line change
Expand Up @@ -1920,6 +1920,13 @@ public final class com/stripe/android/paymentsheet/ui/ComposableSingletons$EditP
public final fun getLambda-2$paymentsheet_release ()Lkotlin/jvm/functions/Function2;
}

public final class com/stripe/android/paymentsheet/ui/ComposableSingletons$PaymentMethodVerticalLayoutUIKt {
public static final field INSTANCE Lcom/stripe/android/paymentsheet/ui/ComposableSingletons$PaymentMethodVerticalLayoutUIKt;
public static field lambda-1 Lkotlin/jvm/functions/Function3;
public fun <init> ()V
public final fun getLambda-1$paymentsheet_release ()Lkotlin/jvm/functions/Function3;
}

public final class com/stripe/android/paymentsheet/ui/ComposableSingletons$PaymentSheetScreenKt {
public static final field INSTANCE Lcom/stripe/android/paymentsheet/ui/ComposableSingletons$PaymentSheetScreenKt;
public static field lambda-1 Lkotlin/jvm/functions/Function4;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.stripe.android.paymentsheet.navigation

import androidx.compose.foundation.layout.padding
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
Expand All @@ -14,7 +15,7 @@ import com.stripe.android.paymentsheet.ui.AddPaymentMethod
import com.stripe.android.paymentsheet.ui.EditPaymentMethod
import com.stripe.android.paymentsheet.ui.FormElement
import com.stripe.android.paymentsheet.ui.ModifiableEditPaymentMethodViewInteractor
import com.stripe.android.paymentsheet.ui.NewPaymentMethodVerticalLayoutUI
import com.stripe.android.paymentsheet.ui.PaymentMethodVerticalLayoutUI
import com.stripe.android.paymentsheet.ui.SavedPaymentMethodTabLayoutUI
import com.stripe.android.paymentsheet.ui.SavedPaymentMethodsTopContentPadding
import com.stripe.android.paymentsheet.viewmodels.BaseSheetViewModel
Expand All @@ -32,6 +33,7 @@ internal val PaymentSheetScreen.topContentPadding: Dp
is PaymentSheetScreen.Form,
is PaymentSheetScreen.AddFirstPaymentMethod,
is PaymentSheetScreen.AddAnotherPaymentMethod,
is PaymentSheetScreen.ManageSavedPaymentMethods,
is PaymentSheetScreen.EditPaymentMethod -> {
0.dp
}
Expand Down Expand Up @@ -64,7 +66,7 @@ internal sealed interface PaymentSheetScreen {
}
}

object SelectSavedPaymentMethods : PaymentSheetScreen {
data object SelectSavedPaymentMethods : PaymentSheetScreen {

override val showsBuyButton: Boolean = true
override val showsContinueButton: Boolean = false
Expand Down Expand Up @@ -172,10 +174,11 @@ internal sealed interface PaymentSheetScreen {

val isProcessing by viewModel.processing.collectAsStateSafely()

NewPaymentMethodVerticalLayoutUI(
PaymentMethodVerticalLayoutUI(
paymentMethods = supportedPaymentMethods,
selectedIndex = -1,
isEnabled = !isProcessing,
onViewMorePaymentMethods = { viewModel.transitionTo(ManageSavedPaymentMethods) },
onItemSelectedListener = { viewModel.transitionTo(Form(it.code)) },
imageLoader = imageLoader,
modifier = Modifier.padding(horizontal = 20.dp)
Expand Down Expand Up @@ -222,6 +225,19 @@ internal sealed interface PaymentSheetScreen {
)
}
}

data object ManageSavedPaymentMethods : PaymentSheetScreen {
override val showsBuyButton: Boolean = false
override val showsContinueButton: Boolean = false
override val canNavigateBack: Boolean = true

override fun showsWalletsHeader(isCompleteFlow: Boolean): Boolean = false

@Composable
override fun Content(viewModel: BaseSheetViewModel, modifier: Modifier) {
Text("Manage your saved PMs here")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In a follow up, I will make this a column of SavedPaymentMethodRowButtons

}
}
}

@Composable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,55 +16,69 @@ internal class HeaderTextFactory(
types: List<PaymentMethodCode>,
): Int? {
return if (isCompleteFlow) {
when (screen) {
is PaymentSheetScreen.SelectSavedPaymentMethods -> {
if (isWalletEnabled) {
null
} else {
R.string.stripe_paymentsheet_select_payment_method
}
}
is PaymentSheetScreen.AddFirstPaymentMethod, PaymentSheetScreen.VerticalMode -> {
R.string.stripe_paymentsheet_add_payment_method_title.takeUnless {
isWalletEnabled
}
}
is PaymentSheetScreen.EditPaymentMethod -> {
StripeR.string.stripe_title_update_card
}
is PaymentSheetScreen.Loading,
is PaymentSheetScreen.AddAnotherPaymentMethod,
is PaymentSheetScreen.Form,
null -> {
null
}
}
createForCompleteFlow(screen, isWalletEnabled)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ran into a linter issue about this function being too complex, so separated some of it out

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only actually new thing in this file is the PaymentSheetScreen.ManageSavedPaymentMethods branch

} else {
when (screen) {
is PaymentSheetScreen.Loading, is PaymentSheetScreen.Form -> {
null
}
is PaymentSheetScreen.SelectSavedPaymentMethods -> {
R.string.stripe_paymentsheet_select_payment_method
}
is PaymentSheetScreen.AddFirstPaymentMethod,
is PaymentSheetScreen.AddAnotherPaymentMethod,
is PaymentSheetScreen.VerticalMode -> {
val title = if (types.singleOrNull() == PaymentMethod.Type.Card.code) {
StripeR.string.stripe_title_add_a_card
} else {
R.string.stripe_paymentsheet_choose_payment_method
}
createForFlowController(screen, types, isWalletEnabled)
}
}

private fun createForCompleteFlow(
screen: PaymentSheetScreen?,
isWalletEnabled: Boolean
) = when (screen) {
is PaymentSheetScreen.SelectSavedPaymentMethods -> {
if (isWalletEnabled) {
null
} else {
R.string.stripe_paymentsheet_select_payment_method
}
}
is PaymentSheetScreen.AddFirstPaymentMethod, PaymentSheetScreen.VerticalMode -> {
R.string.stripe_paymentsheet_add_payment_method_title.takeUnless {
isWalletEnabled
}
}
is PaymentSheetScreen.EditPaymentMethod -> {
StripeR.string.stripe_title_update_card
}
is PaymentSheetScreen.ManageSavedPaymentMethods -> {
R.string.stripe_paymentsheet_select_payment_method
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a test for this (if it's the final variant).

I've been skipping tests for all the stuff I've added, since it isn't done yet.

}
is PaymentSheetScreen.Loading,
is PaymentSheetScreen.AddAnotherPaymentMethod,
is PaymentSheetScreen.Form,
null -> {
null
}
}

title.takeUnless { isWalletEnabled }
}
is PaymentSheetScreen.EditPaymentMethod -> {
StripeR.string.stripe_title_update_card
}
null -> {
null
}
private fun createForFlowController(
screen: PaymentSheetScreen?,
types: List<PaymentMethodCode>,
isWalletEnabled: Boolean
) = when (screen) {
is PaymentSheetScreen.Loading, is PaymentSheetScreen.Form -> {
null
}
is PaymentSheetScreen.SelectSavedPaymentMethods, is PaymentSheetScreen.ManageSavedPaymentMethods -> {
R.string.stripe_paymentsheet_select_payment_method
}
is PaymentSheetScreen.AddFirstPaymentMethod,
is PaymentSheetScreen.AddAnotherPaymentMethod,
is PaymentSheetScreen.VerticalMode -> {
val title = if (types.singleOrNull() == PaymentMethod.Type.Card.code) {
StripeR.string.stripe_title_add_a_card
} else {
R.string.stripe_paymentsheet_choose_payment_method
}

title.takeUnless { isWalletEnabled }
}
is PaymentSheetScreen.EditPaymentMethod -> {
StripeR.string.stripe_title_update_card
}
null -> {
null
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.stripe.android.paymentsheet.ui

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.material.Text
import androidx.compose.material.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.stripe.android.lpmfoundations.luxe.SupportedPaymentMethod
import com.stripe.android.uicore.image.StripeImageLoader

@Composable
internal fun PaymentMethodVerticalLayoutUI(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created this new layout for the list of both saved PMs + new PMs (using the existing NewPaymentMethodVerticalLayoutUI). Once there is a saved PM displayed in this layout, it will have a "View more" button and clicking that button should call the onViewMorePaymentMethods function that is included here

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we will probably keep doing this for a while. I'm hoping to refactor some stuff in this realm too. But I'm on board with this as iterative progress!

paymentMethods: List<SupportedPaymentMethod>,
selectedIndex: Int,
isEnabled: Boolean,
onViewMorePaymentMethods: () -> Unit,
onItemSelectedListener: (SupportedPaymentMethod) -> Unit,
imageLoader: StripeImageLoader,
modifier: Modifier = Modifier,
) {
Column(modifier = modifier, verticalArrangement = Arrangement.spacedBy(12.dp)) {
TextButton(onClick = { onViewMorePaymentMethods() }) {
Text(text = "Go to manage screen")
}

NewPaymentMethodVerticalLayoutUI(
paymentMethods = paymentMethods,
selectedIndex = selectedIndex,
isEnabled = isEnabled,
onItemSelectedListener = onItemSelectedListener,
imageLoader = imageLoader
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ internal abstract class BaseSheetViewModel(
previouslyShownForm = null
previouslyInteractedForm = null
}
is PaymentSheetScreen.Form -> {
is PaymentSheetScreen.Form, is PaymentSheetScreen.ManageSavedPaymentMethods -> {
}
}
}
Expand Down Expand Up @@ -362,7 +362,10 @@ internal abstract class BaseSheetViewModel(

private fun reportPaymentSheetShown(currentScreen: PaymentSheetScreen) {
when (currentScreen) {
is PaymentSheetScreen.Loading, is PaymentSheetScreen.EditPaymentMethod, is PaymentSheetScreen.Form -> {
is PaymentSheetScreen.Loading,
is PaymentSheetScreen.EditPaymentMethod,
is PaymentSheetScreen.Form,
is PaymentSheetScreen.ManageSavedPaymentMethods -> {
// Nothing to do here
}
is PaymentSheetScreen.SelectSavedPaymentMethods -> {
Expand Down
Loading