From 3859ba3a0d5bf9be6f3ce1068f176c7f8f260f71 Mon Sep 17 00:00:00 2001 From: Mat Schmid Date: Mon, 25 Nov 2024 11:20:08 -0500 Subject: [PATCH] Fallback to third position --- .../Source/PaymentSheet/PaymentMethodType.swift | 7 +++++-- .../PaymentSheet/PaymentSheetPaymentMethodTypeTest.swift | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/StripePaymentSheet/StripePaymentSheet/Source/PaymentSheet/PaymentMethodType.swift b/StripePaymentSheet/StripePaymentSheet/Source/PaymentSheet/PaymentMethodType.swift index b62fbe87313..c1d4a0d4790 100644 --- a/StripePaymentSheet/StripePaymentSheet/Source/PaymentSheet/PaymentMethodType.swift +++ b/StripePaymentSheet/StripePaymentSheet/Source/PaymentSheet/PaymentMethodType.swift @@ -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) } diff --git a/StripePaymentSheet/StripePaymentSheetTests/PaymentSheet/PaymentSheetPaymentMethodTypeTest.swift b/StripePaymentSheet/StripePaymentSheetTests/PaymentSheet/PaymentSheetPaymentMethodTypeTest.swift index c32ed218c03..925adeb450a 100644 --- a/StripePaymentSheet/StripePaymentSheetTests/PaymentSheet/PaymentSheetPaymentMethodTypeTest.swift +++ b/StripePaymentSheet/StripePaymentSheetTests/PaymentSheet/PaymentSheetPaymentMethodTypeTest.swift @@ -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() {