Skip to content

Commit

Permalink
trim
Browse files Browse the repository at this point in the history
  • Loading branch information
toluo-stripe committed Jan 15, 2025
1 parent 87ef2c7 commit 0cfa94f
Show file tree
Hide file tree
Showing 14 changed files with 31 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import com.stripe.android.link.ui.BottomSheetContent
import com.stripe.android.link.ui.LinkContent
import com.stripe.android.paymentsheet.BuildConfig
import com.stripe.android.paymentsheet.analytics.EventReporter
import com.stripe.android.paymentsheet.viewmodels.BaseSheetViewModel
import com.stripe.android.ui.core.elements.events.LocalCardBrandDisallowedReporter
import com.stripe.android.ui.core.elements.events.LocalCardNumberCompletedEventReporter
import com.stripe.android.uicore.elements.LocalAutofillEventReporter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ import dagger.Module
import dagger.Provides
import kotlinx.coroutines.Dispatchers
import javax.inject.Named
import javax.inject.Singleton
import kotlin.coroutines.CoroutineContext

@Module
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ internal fun LinkContent(
}
}

@SuppressWarnings("LongMethod")
@Composable
private fun Screens(
navController: NavHostController,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import com.stripe.android.link.model.LinkAccount
import com.stripe.android.link.model.supportedPaymentMethodTypes
import com.stripe.android.link.ui.paymentmenthod.Factory
import com.stripe.android.model.ConsumerPaymentDetails
import com.stripe.android.paymentsheet.analytics.code
import kotlinx.coroutines.launch
import javax.inject.Inject

Expand Down Expand Up @@ -63,4 +62,4 @@ internal class CardEditViewModel @Inject constructor(
}
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ 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 @@ -23,7 +22,7 @@ internal object Factory {
fun formHelper(
configuration: LinkConfiguration,
cardAccountRangeRepositoryFactory: CardAccountRangeRepository.Factory,
selectionUpdater: (PaymentSelection?) -> Unit,
selectionUpdater: UpdateSelection,
): FormHelper {
return FormHelper.create(
cardAccountRangeRepositoryFactory = cardAccountRangeRepositoryFactory,
Expand All @@ -33,14 +32,12 @@ internal object Factory {
}

fun usBankAccountArguments(
configuration: LinkConfiguration,
paymentMethodMetadata: PaymentMethodMetadata
): USBankAccountFormArguments {
return USBankAccountFormArguments.create(
configuration = configuration,
paymentMethodMetadata = paymentMethodMetadata,
selectedPaymentMethodCode = "card",
bankFormInteractor = BankFormInteractor.create { }
bankFormInteractor = BankFormInteractor.create { }
)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,45 +1,46 @@
package com.stripe.android.link.ui.paymentmenthod

import androidx.compose.foundation.layout.Column
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.saveable.rememberSaveable
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.unit.dp
import com.stripe.android.link.ui.PrimaryButton
import com.stripe.android.link.ui.ScrollableTopLevelColumn
import com.stripe.android.paymentsheet.model.label
import com.stripe.android.paymentsheet.ui.FormElement
import com.stripe.android.paymentsheet.ui.PaymentMethodForm
import com.stripe.android.uicore.utils.collectAsState
import java.util.UUID

@Composable
internal fun PaymentMethodScreen(
viewModel: PaymentMethodViewModel
) {
val state by viewModel.state.collectAsState()
val context = LocalContext.current
val uuid = rememberSaveable { UUID.randomUUID().toString() }

Column {
FormElement(
ScrollableTopLevelColumn {
PaymentMethodForm(
uuid = uuid,
args = state.formArguments,
enabled = true,
selectedPaymentMethodCode = state.selectedPaymentMethodCode,
formElements = state.formElements,
formArguments = state.formArguments,
usBankAccountFormArguments = state.usBankAccountFormArguments,
horizontalPadding = 16.dp,
onFormFieldValuesChanged = { formValues ->
viewModel.formValuesChanged(formValues)
},
onInteractionEvent = {},
formElements = state.formElements,
)

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

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

}
onButtonClick = viewModel::onPayClicked
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,16 @@ 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 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
Expand Down Expand Up @@ -48,6 +43,8 @@ internal class PaymentMethodViewModel @Inject constructor(
)
}

fun onPayClicked() = Unit

private fun updateSelection(selection: PaymentSelection?) {
_state.update {
it.copy(
Expand Down Expand Up @@ -84,15 +81,3 @@ internal class PaymentMethodViewModel @Inject constructor(
}
}
}

internal data class State(
val selectedPaymentMethodCode: String,
val isProcessing: Boolean,
val usBankAccountFormArguments: USBankAccountFormArguments,
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 @@ -105,7 +105,6 @@ internal class USBankAccountFormArguments(
}

fun create(
configuration: LinkConfiguration,
paymentMethodMetadata: PaymentMethodMetadata,
selectedPaymentMethodCode: String,
bankFormInteractor: BankFormInteractor,
Expand All @@ -132,11 +131,11 @@ internal class USBankAccountFormArguments(
clientSecret = stripeIntent.clientSecret,
shippingDetails = null,
draftPaymentSelection = null,
onMandateTextChanged = { _, _ ->},
onMandateTextChanged = { _, _ -> },
onLinkedBankAccountChanged = bankFormInteractor::handleLinkedBankAccountChanged,
onUpdatePrimaryButtonUIState = { },
onUpdatePrimaryButtonUIState = { },
onUpdatePrimaryButtonState = {},
onError = {},
onError = { },
incentive = paymentMethodMetadata.paymentMethodIncentive,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import com.stripe.android.link.account.FakeLinkAccountManager
import com.stripe.android.link.account.LinkAccountManager
import com.stripe.android.link.model.AccountStatus
import com.stripe.android.paymentelement.confirmation.FakeConfirmationHandler
import com.stripe.android.paymentsheet.analytics.FakeEventReporter
import com.stripe.android.testing.CoroutineTestRule
import kotlinx.coroutines.test.UnconfinedTestDispatcher
import kotlinx.coroutines.test.advanceUntilIdle
Expand Down Expand Up @@ -318,7 +319,8 @@ internal class LinkActivityViewModelTest {
return LinkActivityViewModel(
linkAccountManager = linkAccountManager,
activityRetainedComponent = mock(),
confirmationHandlerFactory = { FakeConfirmationHandler() }
confirmationHandlerFactory = { FakeConfirmationHandler() },
eventReporter = FakeEventReporter()
).apply {
this.navController = navController
this.dismissWithResult = dismissWithResult
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.stripe.android.link.LinkConfiguration
import com.stripe.android.testing.PaymentIntentFactory
import org.junit.Test

class InlineSignupViewStateTest {
class InlineSignupViewPaymentMethodStateTest {

@Test
fun `Allows full prefill if showing instead of save-for-future-use for US customers`() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import kotlinx.coroutines.test.UnconfinedTestDispatcher
import kotlinx.coroutines.test.runTest
import org.junit.Test

internal class EmbeddedConfirmationStateHolderTest {
internal class EmbeddedConfirmationPaymentMethodStateHolderTest {
@Test
fun `setting state updates savedStateHandle`() = testScenario {
assertThat(savedStateHandle.get<State?>(CONFIRMATION_STATE_KEY)).isNull()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import com.stripe.android.model.PaymentMethodFixtures
import com.stripe.android.paymentsheet.model.PaymentSelection
import org.junit.Test

class PaymentOptionsStateFactoryTest {
class PaymentOptionsPaymentMethodStateFactoryTest {

@Test
fun `Returns current selection if available`() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.stripe.android.R
import com.stripe.android.model.CardBrand
import org.junit.Test

class CvcStateTest {
class CvcPaymentMethodStateTest {

@Test
fun `cvc state has correct label for non amex card`() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import org.junit.Test
import com.stripe.android.R as StripeR
import com.stripe.android.ui.core.R as StripeUiCoreR

class PaymentSheetTopBarStateFactoryTest {
class PaymentSheetTopBarPaymentMethodStateFactoryTest {

@Test
fun `navigation is close when canNavigateBack=false`() {
Expand Down

0 comments on commit 0cfa94f

Please sign in to comment.