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

Add link to card form in vertical mode. #8527

Merged
merged 2 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.lifecycle.viewmodel.compose.viewModel
import com.stripe.android.link.LinkConfiguration
import com.stripe.android.link.LinkConfigurationCoordinator
import com.stripe.android.link.R
import com.stripe.android.link.theme.DefaultLinkTheme
Expand All @@ -66,7 +65,7 @@ internal const val ProgressIndicatorTestTag = "CircularProgressIndicator"
fun LinkInlineSignup(
linkConfigurationCoordinator: LinkConfigurationCoordinator,
enabled: Boolean,
onStateChanged: (LinkConfiguration, InlineSignupViewState) -> Unit,
onStateChanged: (InlineSignupViewState) -> Unit,
modifier: Modifier = Modifier
) {
linkConfigurationCoordinator.component?.let { component ->
Expand All @@ -78,7 +77,7 @@ fun LinkInlineSignup(
val errorMessage by viewModel.errorMessage.collectAsState()

LaunchedEffect(viewState) {
onStateChanged(component.configuration, viewState)
onStateChanged(viewState)
}

val focusManager = LocalFocusManager.current
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.lifecycle.viewmodel.compose.viewModel
import com.stripe.android.link.LinkConfiguration
import com.stripe.android.link.LinkConfigurationCoordinator
import com.stripe.android.link.R
import com.stripe.android.link.theme.DefaultLinkTheme
Expand All @@ -60,7 +59,7 @@ import kotlinx.coroutines.job
fun LinkOptionalInlineSignup(
linkConfigurationCoordinator: LinkConfigurationCoordinator,
enabled: Boolean,
onStateChanged: (LinkConfiguration, InlineSignupViewState) -> Unit,
onStateChanged: (InlineSignupViewState) -> Unit,
modifier: Modifier = Modifier
) {
linkConfigurationCoordinator.component?.let { component ->
Expand All @@ -72,7 +71,7 @@ fun LinkOptionalInlineSignup(
val errorMessage by viewModel.errorMessage.collectAsState()

LaunchedEffect(viewState) {
onStateChanged(component.configuration, viewState)
onStateChanged(viewState)
}

val focusManager = LocalFocusManager.current
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ internal fun AddPaymentMethod(
onItemSelectedListener = {
viewActionHandler(CustomerSheetViewAction.OnAddPaymentMethodItemChanged(it))
},
onLinkSignupStateChanged = { _, _ -> },
onLinkSignupStateChanged = { _ -> },
formArguments = viewState.formArguments,
usBankAccountFormArguments = viewState.usBankAccountFormArguments,
onFormFieldValuesChanged = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,24 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.dimensionResource
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import com.stripe.android.common.ui.BottomSheetLoadingIndicator
import com.stripe.android.model.PaymentMethod
import com.stripe.android.paymentsheet.R
import com.stripe.android.paymentsheet.paymentdatacollection.ach.USBankAccountFormArguments
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.LinkElement
import com.stripe.android.paymentsheet.ui.ModifiableEditPaymentMethodViewInteractor
import com.stripe.android.paymentsheet.ui.NewPaymentMethodVerticalLayoutUI
import com.stripe.android.paymentsheet.ui.SavedPaymentMethodTabLayoutUI
import com.stripe.android.paymentsheet.ui.SavedPaymentMethodsTopContentPadding
import com.stripe.android.paymentsheet.viewmodels.BaseSheetViewModel
import com.stripe.android.uicore.image.StripeImageLoader
import com.stripe.android.uicore.utils.collectAsStateSafely
import java.io.Closeable

internal val PaymentSheetScreen.topContentPadding: Dp
Expand Down Expand Up @@ -206,20 +211,37 @@ internal sealed interface PaymentSheetScreen {
}
val isProcessing by viewModel.processing.collectAsState()

val horizontalPadding = dimensionResource(
id = R.dimen.stripe_paymentsheet_outer_spacing_horizontal
)

FormElement(
enabled = !isProcessing,
selectedPaymentMethodCode = selectedPaymentMethodCode,
formElements = formElements,
formArguments = formArguments,
usBankAccountFormArguments = usBankAccountFormArguments,
horizontalPadding = 20.dp,
horizontalPadding = horizontalPadding,
onFormFieldValuesChanged = { formValues ->
viewModel.onFormFieldValuesChanged(formValues, selectedPaymentMethodCode)
},
onInteractionEvent = {
viewModel.reportFieldInteraction(selectedPaymentMethodCode)
},
)

val linkSignupMode by viewModel.linkSignupMode.collectAsStateSafely()
val linkInlineSignupMode = remember(linkSignupMode, selectedPaymentMethodCode) {
linkSignupMode.takeIf { selectedPaymentMethodCode == PaymentMethod.Type.Card.code }
}

LinkElement(
linkConfigurationCoordinator = viewModel.linkConfigurationCoordinator,
linkSignupMode = linkInlineSignupMode,
enabled = !isProcessing,
horizontalPadding = horizontalPadding,
onLinkSignupStateChanged = viewModel::onLinkSignUpStateUpdated,
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,7 @@ internal fun AddPaymentMethod(
sheetViewModel.reportPaymentMethodTypeSelected(selectedLpm.code)
}
},
onLinkSignupStateChanged = { _, inlineSignupViewState ->
sheetViewModel.onLinkSignUpStateUpdated(inlineSignupViewState)
},
onLinkSignupStateChanged = sheetViewModel::onLinkSignUpStateUpdated,
formArguments = arguments,
usBankAccountFormArguments = usBankAccountFormArguments,
onFormFieldValuesChanged = { formValues ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.dimensionResource
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import com.stripe.android.link.LinkConfiguration
import com.stripe.android.link.LinkConfigurationCoordinator
import com.stripe.android.link.ui.inline.InlineSignupViewState
import com.stripe.android.link.ui.inline.LinkInlineSignup
Expand Down Expand Up @@ -44,7 +43,7 @@ internal fun PaymentElement(
linkSignupMode: LinkSignupMode?,
linkConfigurationCoordinator: LinkConfigurationCoordinator?,
onItemSelectedListener: (SupportedPaymentMethod) -> Unit,
onLinkSignupStateChanged: (LinkConfiguration, InlineSignupViewState) -> Unit,
onLinkSignupStateChanged: (InlineSignupViewState) -> Unit,
formArguments: FormArguments,
usBankAccountFormArguments: USBankAccountFormArguments,
onFormFieldValuesChanged: (FormFieldValues?) -> Unit,
Expand Down Expand Up @@ -153,12 +152,12 @@ internal fun FormElement(
}

@Composable
private fun LinkElement(
internal fun LinkElement(
linkConfigurationCoordinator: LinkConfigurationCoordinator?,
linkSignupMode: LinkSignupMode?,
enabled: Boolean,
horizontalPadding: Dp,
onLinkSignupStateChanged: (LinkConfiguration, InlineSignupViewState) -> Unit,
onLinkSignupStateChanged: (InlineSignupViewState) -> Unit,
) {
if (linkConfigurationCoordinator != null && linkSignupMode != null) {
when (linkSignupMode) {
Expand Down
Loading