Skip to content

Commit

Permalink
Fix billing details fields bug & add flow controller tests for Bacs.
Browse files Browse the repository at this point in the history
  • Loading branch information
samer-stripe committed Nov 30, 2023
1 parent c3a734a commit 0212a8f
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -473,9 +473,9 @@ class LpmRepository constructor(
formSpec = LayoutSpec(sharedDataSpec.fields)
)
PaymentMethod.Type.BacsDebit.code -> {
val localFields = listOf(
val localFields = listOfNotNull(
ContactInformationSpec(
collectPhone = false,
collectPhone = billingDetailsCollectionConfiguration.collectPhone,
nameLabel = R.string.stripe_bacs_full_name
),
BacsDebitBankAccountSpec(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,20 @@ internal class TestBacs : BasePlaygroundTest() {
)
}

@Test
fun testBacsWhenConfirmedInCustomFlow() {
testDriver.confirmCustomAndBuy(
testParameters = createTestParameters(AuthorizeAction.Bacs.Confirm)
)
}

@Test
fun testBacsWhenCancelledInCustomFlow() {
testDriver.confirmCustomAndBuy(
testParameters = createTestParameters(AuthorizeAction.Bacs.ModifyDetails)
)
}

private fun createTestParameters(
bacsAuthAction: AuthorizeAction.Bacs
): TestParameters {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,11 @@ internal class FormViewModel @Inject internal constructor(
lpmRepository.fromCode(formArguments.paymentMethodCode)
).formSpec.items

// Cards are a special case and already contain specs based on the configuration.
if (formArguments.paymentMethodCode != PaymentMethod.Type.Card.code) {
// Cards & Bacs debit are a special case and already contain specs based on the configuration.
if (
formArguments.paymentMethodCode != PaymentMethod.Type.Card.code &&
formArguments.paymentMethodCode != PaymentMethod.Type.BacsDebit.code
) {
specs = specsForConfiguration(
configuration = formArguments.billingDetailsCollectionConfiguration,
placeholderOverrideList = formArguments.requiredFields,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import com.stripe.android.ui.core.elements.CardDetailsSectionElement
import com.stripe.android.ui.core.elements.CountrySpec
import com.stripe.android.ui.core.elements.EmailElement
import com.stripe.android.ui.core.elements.EmailSpec
import com.stripe.android.ui.core.elements.EmptyFormElement
import com.stripe.android.ui.core.elements.IbanSpec
import com.stripe.android.ui.core.elements.LayoutSpec
import com.stripe.android.ui.core.elements.MandateTextSpec
Expand Down Expand Up @@ -861,6 +862,30 @@ internal class FormViewModelTest {
}
}

@Test
fun `Test Bacs with billing configuration does not billing field placeholders`() = runTest {
val formViewModel = createViewModel(
COMPOSE_FRAGMENT_ARGS.copy(
paymentMethodCode = PaymentMethod.Type.BacsDebit.code,
billingDetailsCollectionConfiguration = PaymentSheet.BillingDetailsCollectionConfiguration(
name = PaymentSheet.BillingDetailsCollectionConfiguration.CollectionMode.Always,
email = PaymentSheet.BillingDetailsCollectionConfiguration.CollectionMode.Always,
phone = PaymentSheet.BillingDetailsCollectionConfiguration.CollectionMode.Always,
)
),
createLpmRepositorySupportedPaymentMethod(
PaymentMethod.Type.BacsDebit,
LayoutSpec.create(),
),
)

formViewModel.elementsFlow.test {
assertThat(awaitItem()).containsExactly(EmptyFormElement())

awaitComplete()
}
}

private suspend fun getSectionFieldTextControllerWithLabel(
formViewModel: FormViewModel,
@StringRes label: Int
Expand Down

0 comments on commit 0212a8f

Please sign in to comment.