Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CONSUMERBANK-582] Put bank tab in correct position #4301

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading