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

[BANKCON-14524] Allow pay by bank when linkCardBrand criteria is met & dedupe instant debits #4021

Merged
merged 2 commits into from
Sep 25, 2024
Merged
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 @@ -196,7 +196,7 @@ class PaymentSheetStandardUITests: PaymentSheetUITestCase {
// `mc_load_succeeded` event `selected_lpm` should be "apple_pay", the default payment method.
XCTAssertEqual(analyticsLog[2][string: "selected_lpm"], "apple_pay")
app.buttons["+ Add"].waitForExistenceAndTap()
XCTAssertTrue(app.staticTexts["Add a card"].waitForExistence(timeout: 2))
XCTAssertTrue(app.staticTexts["Card information"].waitForExistence(timeout: 2))
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to update this UI test. With Panther enabled there's a second payment method available in this scenario now, and so the Add a card text was no longer shown. Here's the changes to this screen with Panther:

Before (without Panther) Now (with Panther)
Simulator Screenshot - iPhone 15 - 2024-09-25 at 11 28 33 Simulator Screenshot - iPhone 15 - 2024-09-25 at 11 28 03


// Should fire the `mc_form_shown` event w/ `selected_lpm` = card
XCTAssertEqual(analyticsLog.last?[string: "event"], "mc_form_shown")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,29 @@ extension PaymentSheet {
// External Payment Methods
+ elementsSession.externalPaymentMethods.map { PaymentMethodType.external($0) }

if
elementsSession.orderedPaymentMethodTypes.contains(.link),
!elementsSession.orderedPaymentMethodTypes.contains(.USBankAccount),
!intent.isDeferredIntent,
// We should manually add Instant Debits as a payment method when:
// - Link is an available payment method.
// - US Bank Account is *not* an available payment method.
// - Not a deferred intent flow.
// - Link Funding Sources contains Bank Account.
var eligibleForInstantDebits: Bool {
elementsSession.orderedPaymentMethodTypes.contains(.link) &&
!elementsSession.orderedPaymentMethodTypes.contains(.USBankAccount) &&
!intent.isDeferredIntent &&
elementsSession.linkFundingSources?.contains(.bankAccount) == true
{
}
Comment on lines +173 to +178
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this need to be a var instead of a let?

and out of curiosity/learning how does this compile?

I would have expected it to be something like:

            let eligibleForInstantDebits: Bool = {
                return elementsSession.orderedPaymentMethodTypes.contains(.link) &&
                !elementsSession.orderedPaymentMethodTypes.contains(.USBankAccount) &&
                !intent.isDeferredIntent &&
                elementsSession.linkFundingSources?.contains(.bankAccount) == true
            }()

I get the inferred return as they are no longer necessary.

But what are all the other pieces?

it almost looks like an in-line computed property but the declaration is inside of a function 🤔 so I am not immediately sure the step-by-step execution for it to compile into a boolean

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried in Xcode and I guess it can't be a let because it is a computed property

Is there a name for computed properties inside of functions, and is this new or old? 🤔


// We should manually add Link Card Brand as a payment method when:
// - Link Funding Sources contains Bank Account.
// - US Bank Account is *not* an available payment method.
// - Link Card Brand is the Link Mode
var eligibleForLinkCardBrand: Bool {
elementsSession.linkFundingSources?.contains(.bankAccount) == true &&
!elementsSession.orderedPaymentMethodTypes.contains(.USBankAccount) &&
elementsSession.linkSettings?.linkMode == .linkCardBrand
}

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

if let merchantPaymentMethodOrder = configuration.paymentMethodOrder?.map({ $0.lowercased() }) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,8 @@ class PaymentSheetPaymentMethodTypeTest: XCTestCase {
XCTAssertEqual(elementsSession.orderedPaymentMethodTypes, [.klarna, .card])
}

// MARK: - Payment Method Types

func testPaymentIntentFilteredPaymentMethodTypes() {
let intent = Intent._testPaymentIntent(paymentMethodTypes: [.card, .klarna, .przelewy24])
var configuration = PaymentSheet.Configuration()
Expand Down Expand Up @@ -407,6 +409,23 @@ class PaymentSheetPaymentMethodTypeTest: XCTestCase {
XCTAssertEqual(types, [.stripe(.card)])
}

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

// MARK: Other

func testUnknownPMTypeIsUnsupported() {
let setupIntent = STPFixtures.makeSetupIntent(paymentMethodTypes: [.unknown])
let paymentMethod = STPPaymentMethod.type(from: "luxe_bucks")
Expand Down Expand Up @@ -518,7 +537,7 @@ extension STPFixtures {
captureMethod: String = "automatic",
confirmationMethod: String = "automatic",
shippingProvided: Bool = false,
paymentMethodJson: [String:Any]? = nil
paymentMethodJson: [String: Any]? = nil
) -> STPPaymentIntent {
var json = STPTestUtils.jsonNamed(STPTestJSONPaymentIntent)!
if let setupFutureUsage = setupFutureUsage {
Expand All @@ -539,7 +558,7 @@ extension STPFixtures {
}
if let paymentMethodJson = paymentMethodJson {
json["payment_method"] = paymentMethodJson

}
if let paymentMethodOptions = paymentMethodOptions {
json["payment_method_options"] = paymentMethodOptions.dictionaryValue
Expand All @@ -550,7 +569,7 @@ extension STPFixtures {
static func makeSetupIntent(
paymentMethodTypes: [STPPaymentMethodType] = [.card],
usage: String = "off_session",
paymentMethodJson: [String:Any]? = nil
paymentMethodJson: [String: Any]? = nil
) -> STPSetupIntent {
var json = STPTestUtils.jsonNamed(STPTestJSONSetupIntent)!
json["usage"] = usage
Expand All @@ -559,7 +578,7 @@ extension STPFixtures {
}
if let paymentMethodJson = paymentMethodJson {
json["payment_method"] = paymentMethodJson

}
return STPSetupIntent.decodedObject(fromAPIResponse: json)!
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ extension STPElementsSession {
customerSessionData: [String: Any]? = nil,
cardBrandChoiceData: [String: Any]? = nil,
isLinkPassthroughModeEnabled: Bool? = nil,
linkMode: LinkSettings.LinkMode? = nil,
linkFundingSources: Set<LinkSettings.FundingSource> = [],
disableLinkSignup: Bool? = nil
) -> STPElementsSession {
var json = STPTestUtils.jsonNamed("ElementsSession")!
Expand Down Expand Up @@ -70,6 +72,12 @@ extension STPElementsSession {
json[jsonDict: "link_settings"]!["link_passthrough_mode_enabled"] = isLinkPassthroughModeEnabled
}

if let linkMode {
json[jsonDict: "link_settings"]!["link_mode"] = linkMode.rawValue
}

json[jsonDict: "link_settings"]!["link_funding_sources"] = linkFundingSources.map(\.rawValue)

if let disableLinkSignup {
json[jsonDict: "link_settings"]!["link_mobile_disable_signup"] = disableLinkSignup
}
Expand All @@ -78,7 +86,11 @@ extension STPElementsSession {
return elementsSession
}

static func _testValue(intent: Intent) -> STPElementsSession {
static func _testValue(
intent: Intent,
linkMode: LinkSettings.LinkMode? = nil,
linkFundingSources: Set<LinkSettings.FundingSource> = []
) -> STPElementsSession {
let paymentMethodTypes: [String] = {
switch intent {
case .paymentIntent(let paymentIntent):
Expand All @@ -89,7 +101,11 @@ extension STPElementsSession {
return intentConfig.paymentMethodTypes ?? []
}
}()
return STPElementsSession._testValue(paymentMethodTypes: paymentMethodTypes)
return STPElementsSession._testValue(
paymentMethodTypes: paymentMethodTypes,
linkMode: linkMode,
linkFundingSources: linkFundingSources
)
}
}

Expand Down
Loading