Skip to content

Commit

Permalink
Add rest of arguments to USBankAccountFormArguments (#7248)
Browse files Browse the repository at this point in the history
  • Loading branch information
jameswoo-stripe authored Sep 2, 2023
1 parent 7f5b7ac commit 1923b12
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 14 deletions.
2 changes: 1 addition & 1 deletion paymentsheet/detekt-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<ID>LongMethod:PaymentOptionFactory.kt$PaymentOptionFactory$fun create(selection: PaymentSelection): PaymentOption</ID>
<ID>LongMethod:PaymentSheetConfigurationKtx.kt$internal fun PaymentSheet.Appearance.parseAppearance()</ID>
<ID>LongMethod:PaymentSheetLoader.kt$DefaultPaymentSheetLoader$private suspend fun create( elementsSession: ElementsSession, config: PaymentSheet.Configuration?, isGooglePayReady: Boolean, ): PaymentSheetState.Full</ID>
<ID>LongMethod:USBankAccountForm.kt$@Composable internal fun USBankAccountForm( formArgs: FormArguments, usBankAccountFormArgs: USBankAccountFormArguments, sheetViewModel: BaseSheetViewModel, isProcessing: Boolean, modifier: Modifier = Modifier, )</ID>
<ID>LongMethod:USBankAccountForm.kt$@Composable internal fun USBankAccountForm( formArgs: FormArguments, usBankAccountFormArgs: USBankAccountFormArguments, isProcessing: Boolean, modifier: Modifier = Modifier, )</ID>
<ID>LongMethod:USBankAccountForm.kt$@Composable private fun AccountDetailsForm( formArgs: FormArguments, isProcessing: Boolean, bankName: String?, last4: String?, saveForFutureUseElement: SaveForFutureUseElement, onRemoveAccount: () -> Unit, )</ID>
<ID>MagicNumber:AutocompleteScreen.kt$0.07f</ID>
<ID>MagicNumber:BaseSheetActivity.kt$BaseSheetActivity$30</ID>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,11 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.unit.dp
import androidx.lifecycle.viewmodel.compose.viewModel
import com.stripe.android.model.PaymentIntent
import com.stripe.android.paymentsheet.PaymentSheet.BillingDetailsCollectionConfiguration.AddressCollectionMode
import com.stripe.android.paymentsheet.PaymentSheet.BillingDetailsCollectionConfiguration.CollectionMode
import com.stripe.android.paymentsheet.PaymentSheetViewModel
import com.stripe.android.paymentsheet.R
import com.stripe.android.paymentsheet.model.PaymentSelection.New
import com.stripe.android.paymentsheet.paymentdatacollection.FormArguments
import com.stripe.android.paymentsheet.viewmodels.BaseSheetViewModel
import com.stripe.android.ui.core.elements.SaveForFutureUseElement
import com.stripe.android.ui.core.elements.SaveForFutureUseElementUI
import com.stripe.android.ui.core.elements.SimpleDialogElementUI
Expand All @@ -56,22 +53,20 @@ import com.stripe.android.ui.core.R as PaymentsUiCoreR
internal fun USBankAccountForm(
formArgs: FormArguments,
usBankAccountFormArgs: USBankAccountFormArguments,
sheetViewModel: BaseSheetViewModel,
isProcessing: Boolean,
modifier: Modifier = Modifier,
) {
val viewModel = viewModel<USBankAccountFormViewModel>(
factory = USBankAccountFormViewModel.Factory {
val stripeIntent = sheetViewModel.stripeIntent.value
USBankAccountFormViewModel.Args(
formArgs = formArgs,
isCompleteFlow = sheetViewModel is PaymentSheetViewModel,
isPaymentFlow = stripeIntent is PaymentIntent,
stripeIntentId = stripeIntent?.id,
clientSecret = stripeIntent?.clientSecret,
isCompleteFlow = usBankAccountFormArgs.isCompleteFlow,
isPaymentFlow = usBankAccountFormArgs.isPaymentFlow,
stripeIntentId = usBankAccountFormArgs.stripeIntentId,
clientSecret = usBankAccountFormArgs.clientSecret,
onBehalfOf = usBankAccountFormArgs.onBehalfOf,
savedPaymentMethod = sheetViewModel.newPaymentSelection as? New.USBankAccount,
shippingDetails = sheetViewModel.config?.shippingDetails,
savedPaymentMethod = usBankAccountFormArgs.draftPaymentSelection as? New.USBankAccount,
shippingDetails = usBankAccountFormArgs.shippingDetails,
)
},
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
package com.stripe.android.paymentsheet.paymentdatacollection.ach

import com.stripe.android.paymentsheet.addresselement.AddressDetails
import com.stripe.android.paymentsheet.model.PaymentSelection
import com.stripe.android.paymentsheet.ui.PrimaryButton

/**
* [USBankAccountFormArguments] provides the arguments required to render the [USBankAccountForm].
*
* @param onBehalfOf the connected account of the business of record to attach this US bank account.
* @param isCompleteFlow whether or not the USBankAccount is being presented in [PaymentSheet]
* @param isCompleteFlow whether or not the USBankAccount is being presented in [PaymentSheet].
* @param isPaymentFlow whether or not the USBankAccount is being used for payment.
* @param stripeIntentId the [StripeIntent] id.
* @param clientSecret the client secret.
* @param shippingDetails the shipping details for this transaction.
* @param draftPaymentSelection the draft payment information before the customer has confirmed it.
* @param onMandateTextChanged emitted when the mandate text has been updated, this updated text
* should be displayed to the user.
* @param onHandleUSBankAccount emitted when the payment selection has been updated. The
Expand All @@ -22,6 +28,11 @@ import com.stripe.android.paymentsheet.ui.PrimaryButton
internal class USBankAccountFormArguments(
val onBehalfOf: String?,
val isCompleteFlow: Boolean,
val isPaymentFlow: Boolean,
val stripeIntentId: String?,
val clientSecret: String?,
val shippingDetails: AddressDetails?,
val draftPaymentSelection: PaymentSelection?,
val onMandateTextChanged: (String?) -> Unit,
val onHandleUSBankAccount: (PaymentSelection.New.USBankAccount) -> Unit,
val onUpdatePrimaryButtonUIState: ((PrimaryButton.UIState?) -> (PrimaryButton.UIState?)) -> Unit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ internal fun AddPaymentMethod(
showCheckboxFlow.emit(arguments.showCheckbox)
}

val stripeIntent = sheetViewModel.stripeIntent.collectAsState()
val paymentSelection by sheetViewModel.selection.collectAsState()
val linkInlineSelection by linkHandler.linkInlineSelection.collectAsState()
var linkSignupState by remember {
Expand Down Expand Up @@ -119,6 +120,11 @@ internal fun AddPaymentMethod(
usBankAccountFormArguments = USBankAccountFormArguments(
onBehalfOf = onBehalfOf,
isCompleteFlow = sheetViewModel is PaymentSheetViewModel,
isPaymentFlow = initializationMode is PaymentSheet.InitializationMode.PaymentIntent,
stripeIntentId = stripeIntent.value?.id,
clientSecret = stripeIntent.value?.clientSecret,
shippingDetails = sheetViewModel.config?.shippingDetails,
draftPaymentSelection = sheetViewModel.newPaymentSelection,
onMandateTextChanged = sheetViewModel::updateBelowButtonText,
onHandleUSBankAccount = sheetViewModel::handleConfirmUSBankAccount,
onUpdatePrimaryButtonUIState = sheetViewModel::updateCustomPrimaryButtonUiState,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ internal fun PaymentElement(
USBankAccountForm(
formArgs = formArguments,
usBankAccountFormArgs = usBankAccountFormArguments,
sheetViewModel = sheetViewModel,
isProcessing = primaryButtonState.value?.isProcessing == true,
modifier = Modifier.padding(horizontal = horizontalPadding),
)
Expand Down

0 comments on commit 1923b12

Please sign in to comment.