Skip to content

Commit 1e2bcd2

Browse files
Use Nil as Default Value for Link Supported Payment Methods (#6349)
## Summary Modifies the default value of `supportedPaymentMethodTypes` ## Motivation In #5309, we introduced parametric filtering of supported payment methods. We used a default value of `allCases`, which works for our current feature set. However, in #6342, we'll want to remove the `intersection` on these filtered payment methods if none are provided to allow for unknown PMs to be included in the list. In this PR, we'll keep the same intersection functionality of all cases, but modify the piping of these values to use `nil` instead of `allCases` as the default value. In #6342, we [remove the allCases intersection](https://github.com/stripe/stripe-ios/pull/6342/changes#diff-7d5339851903df687dc841f3deb388ba566a2f0b319c57c38671cb529b80e7a4R119) entirely if `nil` filtered payment methods are passed in. ## Demos | Test Harness | MPE | | ------------- | ------------- | | <video src="https://github.com/user-attachments/assets/3a09ccb5-59c1-4cfb-aa7f-273776a8e6f8" /> | <video src="https://github.com/user-attachments/assets/8f798fe5-ecc1-4ee9-9d7a-ba532421d354" /> |
1 parent ddb0172 commit 1e2bcd2

5 files changed

Lines changed: 25 additions & 12 deletions

File tree

StripePaymentSheet/StripePaymentSheet/Source/Internal/Link/Controllers/PayWithLinkViewController.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ final class PayWithLinkViewController: BottomSheetViewController {
8888
let launchedFromFlowController: Bool
8989
let initiallySelectedPaymentDetailsID: String?
9090
let callToAction: ConfirmButton.CallToActionType
91-
let supportedPaymentMethodTypes: [LinkPaymentMethodType]
91+
let supportedPaymentMethodTypes: [LinkPaymentMethodType]?
9292
var lastAddedPaymentDetails: ConsumerPaymentDetails?
9393
var analyticsHelper: PaymentSheetAnalyticsHelper
9494
let linkAppearance: LinkAppearance?
@@ -115,7 +115,8 @@ final class PayWithLinkViewController: BottomSheetViewController {
115115
/// Returns [.card] as fallback if no types are supported after filtering.
116116
func getSupportedPaymentDetailsTypes(linkAccount: PaymentSheetLinkAccount) -> Set<ConsumerPaymentDetails.DetailsType> {
117117
let allSupportedPaymentDetailsTypes = linkAccount.supportedPaymentDetailsTypes(for: elementsSession)
118-
let filteredSupportedPaymentDetailsTypes = allSupportedPaymentDetailsTypes.intersection(supportedPaymentMethodTypes.detailsTypes)
118+
let supportedPaymentDetailsTypes = supportedPaymentMethodTypes?.detailsTypes ?? Set(ConsumerPaymentDetails.DetailsType.allCases)
119+
let filteredSupportedPaymentDetailsTypes = allSupportedPaymentDetailsTypes.intersection(supportedPaymentDetailsTypes)
119120

120121
if !filteredSupportedPaymentDetailsTypes.isEmpty {
121122
return filteredSupportedPaymentDetailsTypes
@@ -136,7 +137,7 @@ final class PayWithLinkViewController: BottomSheetViewController {
136137
/// - launchedFromFlowController: Whether the flow was opened from `FlowController`.
137138
/// - initiallySelectedPaymentDetailsID: The ID of an initially selected payment method. This is set when opened instead of FlowController.
138139
/// - callToAction: A custom CTA to display on the confirm button. If `nil`, will display `intent`'s default CTA.
139-
/// - supportedPaymentMethodTypes: The payment method types to support in the Link sheet. Defaults to all available types.
140+
/// - supportedPaymentMethodTypes: The payment method types to support in the Link sheet. If `nil`, all available types are supported.
140141
/// - analyticsHelper: An instance of `AnalyticsHelper` to use for logging.
141142
/// - linkAppearance: Optional appearance overrides for Link UI.
142143
/// - linkConfiguration: Configuration for Link behavior and content.
@@ -150,7 +151,7 @@ final class PayWithLinkViewController: BottomSheetViewController {
150151
launchedFromFlowController: Bool = false,
151152
initiallySelectedPaymentDetailsID: String?,
152153
callToAction: ConfirmButton.CallToActionType?,
153-
supportedPaymentMethodTypes: [LinkPaymentMethodType] = LinkPaymentMethodType.allCases,
154+
supportedPaymentMethodTypes: [LinkPaymentMethodType]? = nil,
154155
analyticsHelper: PaymentSheetAnalyticsHelper,
155156
linkAppearance: LinkAppearance? = nil,
156157
linkConfiguration: LinkConfiguration? = nil
@@ -211,7 +212,7 @@ final class PayWithLinkViewController: BottomSheetViewController {
211212
initiallySelectedPaymentDetailsID: String? = nil,
212213
callToAction: ConfirmButton.CallToActionType? = nil,
213214
analyticsHelper: PaymentSheetAnalyticsHelper,
214-
supportedPaymentMethodTypes: [LinkPaymentMethodType] = LinkPaymentMethodType.allCases,
215+
supportedPaymentMethodTypes: [LinkPaymentMethodType]? = nil,
215216
linkAppearance: LinkAppearance? = nil,
216217
linkConfiguration: LinkConfiguration? = nil
217218
) {

StripePaymentSheet/StripePaymentSheet/Source/PaymentSheet/Link/LinkController.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -360,13 +360,13 @@ import UIKit
360360
///
361361
/// - Parameter presentingViewController: The view controller from which to present the Link sheet.
362362
/// - Parameter email: The email address to pre-fill in the Link sheet. If `nil`, the email field will be empty.
363-
/// - Parameter supportedPaymentMethodTypes: The payment method types to support in the Link sheet. Defaults to all available types.
363+
/// - Parameter supportedPaymentMethodTypes: The payment method types to support in the Link sheet. If `nil`, all available types are supported.
364364
/// - Parameter collectName: Whether or not we should collect the user's name and attach it to the billing details.
365365
/// - Parameter completion: A closure that is called when the user has selected a payment method or canceled the sheet. If the user selects a payment method, the `paymentMethodPreview` will be updated accordingly.
366366
@_spi(STP) public func collectPaymentMethod(
367367
from presentingViewController: UIViewController,
368368
with email: String?,
369-
supportedPaymentMethodTypes: [LinkPaymentMethodType] = LinkPaymentMethodType.allCases,
369+
supportedPaymentMethodTypes: [LinkPaymentMethodType]? = nil,
370370
collectName: Bool = false,
371371
completion: @escaping () -> Void
372372
) {
@@ -1021,13 +1021,13 @@ extension LinkController: LinkFullConsentViewControllerDelegate {
10211021
///
10221022
/// - Parameter presentingViewController: The view controller from which to present the Link sheet.
10231023
/// - Parameter email: The email address to pre-fill in the Link sheet. If `nil`, the email field will be empty.
1024-
/// - Parameter supportedPaymentMethodTypes: The payment method types to support in the Link sheet. Defaults to all available types.
1024+
/// - Parameter supportedPaymentMethodTypes: The payment method types to support in the Link sheet. If `nil`, all available types are supported.
10251025
/// - Parameter collectName: Whether or not we should collect the user's name and attach it to the billing details.
10261026
/// - Returns: A `PaymentMethodDisplayData` if the user selected a payment method, or `nil` otherwise.
10271027
func collectPaymentMethod(
10281028
from presentingViewController: UIViewController,
10291029
with email: String?,
1030-
supportedPaymentMethodTypes: [LinkPaymentMethodType] = LinkPaymentMethodType.allCases,
1030+
supportedPaymentMethodTypes: [LinkPaymentMethodType]? = nil,
10311031
collectName: Bool = false
10321032
) async -> LinkController.PaymentMethodPreview? {
10331033
return await withCheckedContinuation { continuation in

StripePaymentSheet/StripePaymentSheet/Source/PaymentSheet/Link/LinkFlowControllerHelpers.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ extension UIViewController {
2525
intent: Intent,
2626
elementsSession: STPElementsSession,
2727
analyticsHelper: PaymentSheetAnalyticsHelper,
28-
supportedPaymentMethodTypes: [LinkPaymentMethodType] = LinkPaymentMethodType.allCases,
28+
supportedPaymentMethodTypes: [LinkPaymentMethodType]? = nil,
2929
linkAppearance: LinkAppearance? = nil,
3030
linkConfiguration: LinkConfiguration? = nil,
3131
shouldShowSecondaryCta: Bool = true,

StripePaymentSheet/StripePaymentSheet/Source/PaymentSheet/Link/PayWithNativeLinkController.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ final class PayWithNativeLinkController {
5454
let configuration: PaymentElementConfiguration
5555
let logPayment: Bool
5656
let analyticsHelper: PaymentSheetAnalyticsHelper
57-
let supportedPaymentMethodTypes: [LinkPaymentMethodType]
57+
let supportedPaymentMethodTypes: [LinkPaymentMethodType]?
5858

5959
private let linkAppearance: LinkAppearance?
6060
private let linkConfiguration: LinkConfiguration?
@@ -67,7 +67,7 @@ final class PayWithNativeLinkController {
6767
configuration: PaymentElementConfiguration,
6868
logPayment: Bool = true,
6969
analyticsHelper: PaymentSheetAnalyticsHelper,
70-
supportedPaymentMethodTypes: [LinkPaymentMethodType] = LinkPaymentMethodType.allCases,
70+
supportedPaymentMethodTypes: [LinkPaymentMethodType]? = nil,
7171
linkAppearance: LinkAppearance? = nil,
7272
linkConfiguration: LinkConfiguration? = nil,
7373
confirmationChallenge: ConfirmationChallenge? = nil

StripePaymentSheet/StripePaymentSheetTests/PaymentSheet/Link/PayWithLinkViewController-WalletViewModelTests.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,16 @@ class PayWithLinkViewController_WalletViewModelTests: XCTestCase {
180180
)
181181
}
182182

183+
func test_supportedPaymentMethodTypes_whenFilterIsNil_usesAllCasesAtIntersection() throws {
184+
let sut = try makeSUT(
185+
supportedPaymentDetailsTypes: [.bankAccount],
186+
supportedPaymentMethodTypes: nil,
187+
linkFundingSources: ["BANK_ACCOUNT"]
188+
)
189+
190+
XCTAssertEqual(sut.supportedPaymentMethodTypes, [.bankAccount])
191+
}
192+
183193
func test_cardBrandFiltering_passThroughEnabled() throws {
184194
let sut = try makeSUT(supportedPaymentDetailsTypes: [.card],
185195
linkFundingSources: ["CARD"],
@@ -368,6 +378,7 @@ extension PayWithLinkViewController_WalletViewModelTests {
368378
func makeSUT(
369379
paymentMethods: [ConsumerPaymentDetails] = LinkStubs.paymentMethods(),
370380
supportedPaymentDetailsTypes: Set<ConsumerPaymentDetails.DetailsType> = [.card, .bankAccount],
381+
supportedPaymentMethodTypes: [LinkPaymentMethodType]? = nil,
371382
linkFundingSources: [String] = ["CARD"],
372383
cardBrandAcceptance: PaymentSheet.CardBrandAcceptance = .all,
373384
allowedCardFundingTypes: PaymentSheet.CardFundingType = .all,
@@ -415,6 +426,7 @@ extension PayWithLinkViewController_WalletViewModelTests {
415426
shouldShowSecondaryCta: shouldShowSecondaryCta,
416427
initiallySelectedPaymentDetailsID: nil,
417428
callToAction: nil,
429+
supportedPaymentMethodTypes: supportedPaymentMethodTypes,
418430
analyticsHelper: ._testValue()
419431
),
420432
paymentMethods: paymentMethods

0 commit comments

Comments
 (0)