Skip to content

Commit

Permalink
Fallback to third position
Browse files Browse the repository at this point in the history
  • Loading branch information
mats-stripe committed Nov 25, 2024
1 parent 5bd154e commit 3859ba3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,13 @@ extension PaymentSheet {
configuration.isEligibleForBankTab
}

// Places the payment method type at either the index for `link`, or in the third / last position.
func insertAtBankTabPosition(paymentMethodType: PaymentMethodType) {
let bankTabPosition = elementsSession.orderedPaymentMethodTypes.firstIndex(of: .link)
if let bankTabPosition, recommendedPaymentMethodTypes.indices.contains(bankTabPosition) {
recommendedPaymentMethodTypes.insert(paymentMethodType, at: bankTabPosition)
let fallbackPosition = 2
let bankTabIndex = bankTabPosition ?? fallbackPosition
if recommendedPaymentMethodTypes.indices.contains(bankTabIndex) {
recommendedPaymentMethodTypes.insert(paymentMethodType, at: bankTabIndex)
} else {
recommendedPaymentMethodTypes.append(paymentMethodType)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ class PaymentSheetPaymentMethodTypeTest: XCTestCase {
),
configuration: configuration
)
XCTAssertEqual(types, [.stripe(.cashApp), .stripe(.amazonPay), .stripe(.card), .stripe(.klarna), .linkCardBrand])
XCTAssertEqual(types, [.stripe(.cashApp), .stripe(.amazonPay), .linkCardBrand, .stripe(.card), .stripe(.klarna)])
}

func testPaymentMethodTypesLinkCardBrand_noDefaults() {
Expand Down

0 comments on commit 3859ba3

Please sign in to comment.