Skip to content

Commit

Permalink
Some cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
toluo-stripe committed Jan 14, 2025
1 parent 736fcf5 commit fa37860
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.stripe.android.cards.CardAccountRangeRepository
import com.stripe.android.link.LinkConfiguration
import com.stripe.android.lpmfoundations.paymentmethod.PaymentMethodMetadata
import com.stripe.android.paymentsheet.FormHelper
import com.stripe.android.paymentsheet.model.PaymentSelection
import com.stripe.android.paymentsheet.paymentdatacollection.ach.USBankAccountFormArguments
import com.stripe.android.paymentsheet.verticalmode.BankFormInteractor

Expand All @@ -21,11 +22,13 @@ internal object Factory {

fun formHelper(
configuration: LinkConfiguration,
cardAccountRangeRepositoryFactory: CardAccountRangeRepository.Factory
cardAccountRangeRepositoryFactory: CardAccountRangeRepository.Factory,
selectionUpdater: (PaymentSelection?) -> Unit,
): FormHelper {
return FormHelper.create(
cardAccountRangeRepositoryFactory = cardAccountRangeRepositoryFactory,
paymentMethodMetadata = paymentMethodMetadata(configuration)
paymentMethodMetadata = paymentMethodMetadata(configuration),
selectionUpdater = selectionUpdater
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
package com.stripe.android.link.ui.paymentmenthod

import androidx.compose.foundation.layout.Column
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.unit.dp
import com.stripe.android.link.ui.PrimaryButton
import com.stripe.android.paymentsheet.model.label
import com.stripe.android.paymentsheet.ui.FormElement
import com.stripe.android.uicore.utils.collectAsState

Expand All @@ -11,24 +16,30 @@ internal fun PaymentMethodScreen(
viewModel: PaymentMethodViewModel
) {
val state by viewModel.state.collectAsState()
val context = LocalContext.current

FormElement(
enabled = true,
selectedPaymentMethodCode = state.selectedPaymentMethodCode,
formElements = state.formElements,
formArguments = state.formArguments,
usBankAccountFormArguments = state.usBankAccountFormArguments,
horizontalPadding = 16.dp,
onFormFieldValuesChanged = { formValues ->
// interactor.handleViewAction(
// VerticalModeFormInteractor.ViewAction.FormFieldValuesChanged(formValues)
// )
},
onInteractionEvent = {
// if (!hasSentInteractionEvent) {
// interactor.handleViewAction(VerticalModeFormInteractor.ViewAction.FieldInteraction)
// hasSentInteractionEvent = true
// }
},
)
Column {
FormElement(
enabled = true,
selectedPaymentMethodCode = state.selectedPaymentMethodCode,
formElements = state.formElements,
formArguments = state.formArguments,
usBankAccountFormArguments = state.usBankAccountFormArguments,
horizontalPadding = 16.dp,
onFormFieldValuesChanged = { formValues ->
viewModel.formValuesChanged(formValues)
},
onInteractionEvent = {},
)

Text(state.paymentSelection?.label?.resolve(context) ?: "null")

PrimaryButton(
label = state.primaryButtonLabel.resolve(context),
state = state.primaryButtonState,
onButtonClick = {

}
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,24 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.viewmodel.initializer
import androidx.lifecycle.viewmodel.viewModelFactory
import com.stripe.android.core.strings.ResolvableString
import com.stripe.android.link.LinkConfiguration
import com.stripe.android.link.injection.NativeLinkComponent
import com.stripe.android.link.ui.PrimaryButtonState
import com.stripe.android.link.ui.completePaymentButtonLabel
import com.stripe.android.lpmfoundations.FormHeaderInformation
import com.stripe.android.lpmfoundations.paymentmethod.PaymentMethodMetadata
import com.stripe.android.model.PaymentMethod
import com.stripe.android.paymentsheet.DefaultFormHelper
import com.stripe.android.paymentsheet.FormHelper
import com.stripe.android.paymentsheet.forms.FormFieldValues
import com.stripe.android.paymentsheet.model.PaymentSelection
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.update
import com.stripe.android.cards.CardAccountRangeRepository
import com.stripe.android.link.LinkConfiguration
import com.stripe.android.lpmfoundations.FormHeaderInformation
import com.stripe.android.paymentsheet.paymentdatacollection.FormArguments
import com.stripe.android.paymentsheet.paymentdatacollection.ach.USBankAccountFormArguments
import com.stripe.android.uicore.elements.FormElement
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.update
import javax.inject.Inject

internal class PaymentMethodViewModel @Inject constructor(
Expand Down Expand Up @@ -95,4 +92,7 @@ internal data class State(
val formArguments: FormArguments,
val formElements: List<FormElement>,
val headerInformation: FormHeaderInformation?,
val primaryButtonState: PrimaryButtonState,
val primaryButtonLabel: ResolvableString,
val paymentSelection: PaymentSelection? = null
)
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import com.stripe.android.paymentsheet.paymentdatacollection.FormArguments
import com.stripe.android.uicore.elements.FormElement

internal interface FormHelper {

fun formElementsForCode(code: String): List<FormElement>

fun createFormArguments(
Expand Down

0 comments on commit fa37860

Please sign in to comment.