diff --git a/StripePaymentSheet/StripePaymentSheet/Source/PaymentSheet/PaymentMethodType.swift b/StripePaymentSheet/StripePaymentSheet/Source/PaymentSheet/PaymentMethodType.swift index 441fc76b6ac..486a29d526e 100644 --- a/StripePaymentSheet/StripePaymentSheet/Source/PaymentSheet/PaymentMethodType.swift +++ b/StripePaymentSheet/StripePaymentSheet/Source/PaymentSheet/PaymentMethodType.swift @@ -459,6 +459,6 @@ extension STPPaymentMethodParams { extension PaymentElementConfiguration { var isEligibleForBankTab: Bool { billingDetailsCollectionConfiguration.email != .never || - defaultBillingDetails.email?.isEmpty == false + (defaultBillingDetails.email?.isEmpty == false && billingDetailsCollectionConfiguration.attachDefaultsToPaymentMethod) } } diff --git a/StripePaymentSheet/StripePaymentSheet/Source/PaymentSheet/USBankAccount/InstantDebitsPaymentMethodElement.swift b/StripePaymentSheet/StripePaymentSheet/Source/PaymentSheet/USBankAccount/InstantDebitsPaymentMethodElement.swift index 1c7642510f0..ffb2ed1b8a9 100644 --- a/StripePaymentSheet/StripePaymentSheet/Source/PaymentSheet/USBankAccount/InstantDebitsPaymentMethodElement.swift +++ b/StripePaymentSheet/StripePaymentSheet/Source/PaymentSheet/USBankAccount/InstantDebitsPaymentMethodElement.swift @@ -73,7 +73,8 @@ final class InstantDebitsPaymentMethodElement: ContainerElement { } var defaultName: String? { - configuration.defaultBillingDetails.name + guard configuration.billingDetailsCollectionConfiguration.attachDefaultsToPaymentMethod else { return nil } + return configuration.defaultBillingDetails.name } var email: String? { @@ -81,7 +82,8 @@ final class InstantDebitsPaymentMethodElement: ContainerElement { } var defaultEmail: String? { - configuration.defaultBillingDetails.email + guard configuration.billingDetailsCollectionConfiguration.attachDefaultsToPaymentMethod else { return nil } + return configuration.defaultBillingDetails.email } var phone: String? { @@ -89,7 +91,8 @@ final class InstantDebitsPaymentMethodElement: ContainerElement { } var defaultPhone: String? { - configuration.defaultBillingDetails.phone + guard configuration.billingDetailsCollectionConfiguration.attachDefaultsToPaymentMethod else { return nil } + return configuration.defaultBillingDetails.phone } var address: PaymentSheet.Address { @@ -104,7 +107,8 @@ final class InstantDebitsPaymentMethodElement: ContainerElement { } var defaultAddress: PaymentSheet.Address? { - configuration.defaultBillingDetails.address + guard configuration.billingDetailsCollectionConfiguration.attachDefaultsToPaymentMethod else { return nil } + return configuration.defaultBillingDetails.address } var enableCTA: Bool { diff --git a/StripePaymentSheet/StripePaymentSheetTests/PaymentSheet/PaymentSheetFormFactoryTest.swift b/StripePaymentSheet/StripePaymentSheetTests/PaymentSheet/PaymentSheetFormFactoryTest.swift index 7b133b8bf7c..6a993f4ceb2 100644 --- a/StripePaymentSheet/StripePaymentSheetTests/PaymentSheet/PaymentSheetFormFactoryTest.swift +++ b/StripePaymentSheet/StripePaymentSheetTests/PaymentSheet/PaymentSheetFormFactoryTest.swift @@ -1699,7 +1699,7 @@ class PaymentSheetFormFactoryTest: XCTestCase { XCTAssertNil(instantDebitsSection.addressElement) } - func testMakeInstantDebits_defaultValues() { + func testMakeInstantDebits_defaultValues_attachDefaultsOff() { let defaultAddress = PaymentSheet.Address( city: "San Francisco", country: "CA", @@ -1714,6 +1714,40 @@ class PaymentSheetFormFactoryTest: XCTestCase { configuration.defaultBillingDetails.email = "foo@bar.com" configuration.defaultBillingDetails.phone = "+12345678900" configuration.defaultBillingDetails.address = defaultAddress + configuration.billingDetailsCollectionConfiguration.attachDefaultsToPaymentMethod = false + + let factory = PaymentSheetFormFactory( + intent: ._testPaymentIntent(paymentMethodTypes: [.card]), + elementsSession: ._testValue(paymentMethodTypes: ["card"]), + configuration: .paymentSheet(configuration), + paymentMethod: .stripe(.card) + ) + guard let instantDebitsSection = factory.makeInstantDebits(countries: ["US"]) as? InstantDebitsPaymentMethodElement else { + return XCTFail("Expected InstantDebitsPaymentMethodElement from factory") + } + + XCTAssertNil(instantDebitsSection.defaultName) + XCTAssertNil(instantDebitsSection.defaultEmail) + XCTAssertNil(instantDebitsSection.defaultPhone) + XCTAssertNil(instantDebitsSection.defaultAddress) + } + + func testMakeInstantDebits_defaultValues_attachDefaultsOn() { + let defaultAddress = PaymentSheet.Address( + city: "San Francisco", + country: "CA", + line1: "510 Townsend St.", + line2: "Line 2", + postalCode: "94102", + state: "CA" + ) + + var configuration = PaymentSheet.Configuration() + configuration.defaultBillingDetails.name = "Foo Bar" + configuration.defaultBillingDetails.email = "foo@bar.com" + configuration.defaultBillingDetails.phone = "+12345678900" + configuration.defaultBillingDetails.address = defaultAddress + configuration.billingDetailsCollectionConfiguration.attachDefaultsToPaymentMethod = true let factory = PaymentSheetFormFactory( intent: ._testPaymentIntent(paymentMethodTypes: [.card]), diff --git a/StripePaymentSheet/StripePaymentSheetTests/PaymentSheet/PaymentSheetPaymentMethodTypeTest.swift b/StripePaymentSheet/StripePaymentSheetTests/PaymentSheet/PaymentSheetPaymentMethodTypeTest.swift index 77ab4523042..119e55ae6e6 100644 --- a/StripePaymentSheet/StripePaymentSheetTests/PaymentSheet/PaymentSheetPaymentMethodTypeTest.swift +++ b/StripePaymentSheet/StripePaymentSheetTests/PaymentSheet/PaymentSheetPaymentMethodTypeTest.swift @@ -424,6 +424,25 @@ class PaymentSheetPaymentMethodTypeTest: XCTestCase { XCTAssertEqual(types, [.stripe(.card), .linkCardBrand]) } + func testPaymentMethodTypesLinkCardBrand_noDefaults() { + let intent = Intent._testPaymentIntent(paymentMethodTypes: [.card]) + var configuration = PaymentSheet.Configuration() + configuration.billingDetailsCollectionConfiguration.email = .never + configuration.billingDetailsCollectionConfiguration.attachDefaultsToPaymentMethod = false + configuration.defaultBillingDetails.email = nil + let types = PaymentSheet.PaymentMethodType.filteredPaymentMethodTypes( + from: intent, + elementsSession: ._testValue( + intent: intent, + linkMode: .linkCardBrand, + linkFundingSources: [.card, .bankAccount] + ), + configuration: configuration + ) + // This configuration should not show the bank tab. + XCTAssertEqual(types, [.stripe(.card)]) + } + // MARK: Other func testUnknownPMTypeIsUnsupported() {