Skip to content

Commit

Permalink
Consider attachDefaultsToPaymentMethod
Browse files Browse the repository at this point in the history
  • Loading branch information
tillh-stripe committed Oct 18, 2024
1 parent 8bbd279 commit 799f952
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -492,24 +492,33 @@ internal class USBankAccountFormViewModel @Inject internal constructor(
amount = args.formArgs.amount?.value,
currency = args.formArgs.amount?.currencyCode,
linkMode = args.linkMode,
billingAddress = ElementsSessionContext.BillingAddress(
name = name.value,
phone = phone.value?.let { phoneController.getE164PhoneNumber(it) },
address = address.value?.let {
ElementsSessionContext.BillingAddress.Address(
line1 = it.line1,
line2 = it.line2,
postalCode = it.postalCode,
city = it.city,
state = it.state,
country = it.country,
)
},
),
billingAddress = makeElementsSessionContextBillingAddress(),
),
)
}

private fun makeElementsSessionContextBillingAddress(): ElementsSessionContext.BillingAddress {
val attachDefaultsToPaymentMethod = collectionConfiguration.attachDefaultsToPaymentMethod
val name = name.value.takeIf { fieldsState.showNameField || attachDefaultsToPaymentMethod }
val phone = phone.value.takeIf { fieldsState.showPhoneField || attachDefaultsToPaymentMethod }
val address = address.value.takeIf { fieldsState.showAddressFields || attachDefaultsToPaymentMethod }

return ElementsSessionContext.BillingAddress(
name = name,
phone = phone?.let { phoneController.getE164PhoneNumber(it) },
address = address?.let {
ElementsSessionContext.BillingAddress.Address(
line1 = it.line1,
line2 = it.line2,
postalCode = it.postalCode,
city = it.city,
state = it.state,
country = it.country,
)
},
)
}

private fun createUSBankAccountConfiguration(): CollectBankAccountConfiguration.USBankAccount {
return CollectBankAccountConfiguration.USBankAccount(
name = name.value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1086,9 +1086,7 @@ class USBankAccountFormViewModelTest {
amount = 5099,
currency = "usd",
linkMode = LinkMode.LinkCardBrand,
billingAddress = ElementsSessionContext.BillingAddress(
name = "Jenny Rose",
),
billingAddress = ElementsSessionContext.BillingAddress(),
),
)
),
Expand Down

0 comments on commit 799f952

Please sign in to comment.