Skip to content

Commit

Permalink
[CONSUMERBANK-582] Put bank tab in correct position
Browse files Browse the repository at this point in the history
  • Loading branch information
mats-stripe committed Nov 25, 2024
1 parent 3f81185 commit c9fc2cd
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -191,14 +191,23 @@ extension PaymentSheet {
configuration.isEligibleForBankTab
}

func insertAtBankTabPosition(paymentMethodType: PaymentMethodType) {
let bankTabPosition = elementsSession.orderedPaymentMethodTypes.firstIndex(of: .link)
if let bankTabPosition, recommendedPaymentMethodTypes.indices.contains(bankTabPosition) {
recommendedPaymentMethodTypes.insert(paymentMethodType, at: bankTabPosition)
} else {
recommendedPaymentMethodTypes.append(paymentMethodType)
}
}

if eligibleForInstantDebits {
let availabilityStatus = configurationSatisfiesRequirements(
requirements: [.financialConnectionsSDK],
configuration: configuration,
intent: intent
)
if availabilityStatus == .supported {
recommendedPaymentMethodTypes.append(.instantDebits)
insertAtBankTabPosition(paymentMethodType: .instantDebits)
}
// Else if here so we don't show both Instant Debits and Link Card Brand together.
} else if eligibleForLinkCardBrand {
Expand All @@ -208,7 +217,7 @@ extension PaymentSheet {
intent: intent
)
if availabilityStatus == .supported {
recommendedPaymentMethodTypes.append(.linkCardBrand)
insertAtBankTabPosition(paymentMethodType: .linkCardBrand)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,36 @@ class PaymentSheetPaymentMethodTypeTest: XCTestCase {
XCTAssertEqual(types, [.stripe(.card)])
}

func testPaymentMethodTypesInstantDebits() {
let intent = Intent._testPaymentIntent(paymentMethodTypes: [.link])
let configuration = PaymentSheet.Configuration()
let types = PaymentSheet.PaymentMethodType.filteredPaymentMethodTypes(
from: intent,
elementsSession: ._testValue(
intent: intent,
linkMode: .linkCardBrand,
linkFundingSources: [.card, .bankAccount]
),
configuration: configuration
)
XCTAssertEqual(types, [.instantDebits])
}

func testPaymentMethodTypesInstantDebitsWithOrderedPaymentMethodTypes() {
let intent = Intent._testPaymentIntent(paymentMethodTypes: [.card, .cashApp, .amazonPay, .link, .klarna])
var configuration = PaymentSheet.Configuration()
configuration.returnURL = "http://return-to-url"
let types = PaymentSheet.PaymentMethodType.filteredPaymentMethodTypes(
from: intent,
elementsSession: ._testValue(
intent: intent,
linkFundingSources: [.bankAccount]
),
configuration: configuration
)
XCTAssertEqual(types, [.stripe(.card), .stripe(.cashApp), .stripe(.amazonPay), .instantDebits, .stripe(.klarna)])
}

func testPaymentMethodTypesLinkCardBrand() {
let intent = Intent._testPaymentIntent(paymentMethodTypes: [.card])
let configuration = PaymentSheet.Configuration()
Expand All @@ -424,6 +454,22 @@ class PaymentSheetPaymentMethodTypeTest: XCTestCase {
XCTAssertEqual(types, [.stripe(.card), .linkCardBrand])
}

func testPaymentMethodTypesLinkCardBrandWithOrderedPaymentMethodTypes() {
let intent = Intent._testPaymentIntent(paymentMethodTypes: [.cashApp, .amazonPay, .card, .klarna])
var configuration = PaymentSheet.Configuration()
configuration.returnURL = "http://return-to-url"
let types = PaymentSheet.PaymentMethodType.filteredPaymentMethodTypes(
from: intent,
elementsSession: ._testValue(
intent: intent,
linkMode: .linkCardBrand,
linkFundingSources: [.card, .bankAccount]
),
configuration: configuration
)
XCTAssertEqual(types, [.stripe(.cashApp), .stripe(.amazonPay), .stripe(.card), .stripe(.klarna), .linkCardBrand])
}

func testPaymentMethodTypesLinkCardBrand_noDefaults() {
let intent = Intent._testPaymentIntent(paymentMethodTypes: [.card])
var configuration = PaymentSheet.Configuration()
Expand Down

0 comments on commit c9fc2cd

Please sign in to comment.