Skip to content

Commit

Permalink
[BANKCON-14528] Update FC SDK to accept link_mode value from the pa…
Browse files Browse the repository at this point in the history
…yment sheet (#4050)

## Summary

As part of the
[Panther](https://docs.google.com/document/d/1ErJVA3lLvNspPe3A8uYP9feK8Yvfq-Sw5aatNIvlGxk/edit#heading=h.p9ofrc4zbe1z)
project, we'll need to call a different payment method endpoint at the
end of the Financial Connections flow based on whether or not we're in a
Panther flow. To know this, we need the `link_mode` value, which is
fetched in the elements session response. This passes that value into
the FC SDK for future use!

## Motivation

Building Panther!

## Testing

Verified the correct `linkMode` value is accessed in the
`FinancialConnectionsSheet`:

<img width="1184" alt="Screenshot 2024-09-24 at 9 55 27 AM"
src="https://github.com/user-attachments/assets/5d0831a5-dbfb-4b58-836d-8a235267abde">

## Changelog

N/a
  • Loading branch information
mats-stripe authored Sep 25, 2024
1 parent 00c3032 commit 9a7afba
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 8 deletions.
8 changes: 8 additions & 0 deletions StripeCore/StripeCore.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
45DAE581F74EF7E11C64212B /* InstallMethod.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21E64986F72C7BD8B1105A95 /* InstallMethod.swift */; };
48A6CCB4008A5060C2655C5F /* XCTestCase+Stripe.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2DE48D0086BED21F9E837D0B /* XCTestCase+Stripe.swift */; };
4910B9282C3D8F3F00B030D4 /* Result+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4910B9272C3D8F3F00B030D4 /* Result+Extensions.swift */; };
492039932CA47A8600CE2072 /* ElementsSessionContext.swift in Sources */ = {isa = PBXBuildFile; fileRef = 492039922CA47A8600CE2072 /* ElementsSessionContext.swift */; };
493B33062CA3015600E3622F /* LinkMode.swift in Sources */ = {isa = PBXBuildFile; fileRef = 493B33052CA3015600E3622F /* LinkMode.swift */; };
49ECDA412CA340E100F647F0 /* AsyncTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 49ECDA402CA340E100F647F0 /* AsyncTests.swift */; };
4B2FAC57E03D8654A177C408 /* Dictionary+Stripe.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7727AEEFD2FC880BADDA1872 /* Dictionary+Stripe.swift */; };
53D46A03B77577EE21F4B166 /* StripeCodableTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1FCE36551600C3E53BEAF8F0 /* StripeCodableTest.swift */; };
Expand Down Expand Up @@ -227,6 +229,8 @@
4689F6B4384244D9FD282560 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
48A3D6592296104A1512AE92 /* fr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = fr; path = fr.lproj/Localizable.strings; sourceTree = "<group>"; };
4910B9272C3D8F3F00B030D4 /* Result+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Result+Extensions.swift"; sourceTree = "<group>"; };
492039922CA47A8600CE2072 /* ElementsSessionContext.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ElementsSessionContext.swift; sourceTree = "<group>"; };
493B33052CA3015600E3622F /* LinkMode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LinkMode.swift; sourceTree = "<group>"; };
49424775D3233411D9C2473B /* StripeCodable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StripeCodable.swift; sourceTree = "<group>"; };
49538DBF8457D96707A2DA56 /* nl */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = nl; path = nl.lproj/Localizable.strings; sourceTree = "<group>"; };
49ECDA402CA340E100F647F0 /* AsyncTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AsyncTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -447,6 +451,8 @@
6A05FB462BCF24370001D128 /* FinancialConnectionsLinkedBank.swift */,
6A05FB482BCF244A0001D128 /* InstantDebitsLinkedBank.swift */,
6A05FB4A2BCF245C0001D128 /* FinancialConnectionsEvent.swift */,
493B33052CA3015600E3622F /* LinkMode.swift */,
492039922CA47A8600CE2072 /* ElementsSessionContext.swift */,
);
path = "Connections Bindings";
sourceTree = "<group>";
Expand Down Expand Up @@ -986,6 +992,7 @@
4B2FAC57E03D8654A177C408 /* Dictionary+Stripe.swift in Sources */,
42DE35681C71A931F65E0E7D /* Enums+CustomStringConvertible.swift in Sources */,
D8FEF16798A791F5BF7EA4B2 /* NSArray+Stripe.swift in Sources */,
492039932CA47A8600CE2072 /* ElementsSessionContext.swift in Sources */,
C318A6B6CD599B06DA7CE706 /* NSBundle+Stripe_AppName.swift in Sources */,
2AA9B01C8A2D2BADC4619629 /* NSCharacterSet+StripeCore.swift in Sources */,
C5BF4B8AE85FF72EC6382EC0 /* NSError+Stripe.swift in Sources */,
Expand Down Expand Up @@ -1024,6 +1031,7 @@
DFF3092E51B6C3ED81AB1448 /* String+Localized.swift in Sources */,
6B987BDD2C9111BC00DDFDB3 /* Notification+Stripe.swift in Sources */,
89DB623A200678B4E9845AF2 /* FraudDetectionData.swift in Sources */,
493B33062CA3015600E3622F /* LinkMode.swift in Sources */,
920832EE256E377572DD41EB /* STPTelemetryClient.swift in Sources */,
3B27DDDDC91F1599BF1469BB /* UserDefaults+PaymentsCore.swift in Sources */,
B6D129B2DC90FA1F8A1F5BCB /* UIActivityIndicatorView+Stripe.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// ElementsSessionContext.swift
// StripeCore
//
// Created by Mat Schmid on 2024-09-25.
//

import Foundation

/// Contains elements session context useful for the Financial Connections SDK.
@_spi(STP) public struct ElementsSessionContext {
@_spi(STP) public let linkMode: LinkMode?

@_spi(STP) public init(linkMode: LinkMode?) {
self.linkMode = linkMode
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import UIKit
apiClient: STPAPIClient,
clientSecret: String,
returnURL: String?,
elementsSessionContext: ElementsSessionContext?,
onEvent: ((FinancialConnectionsEvent) -> Void)?,
from presentingViewController: UIViewController,
completion: @escaping (FinancialConnectionsSDKResult) -> Void
Expand Down
18 changes: 18 additions & 0 deletions StripeCore/StripeCore/Source/Connections Bindings/LinkMode.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// LinkMode.swift
// StripeCore
//
// Created by Mat Schmid on 2024-09-24.
//

import Foundation

@_spi(STP) public enum LinkMode: String {
case linkPaymentMethod = "LINK_PAYMENT_METHOD"
case passthrough = "PASSTHROUGH"
case linkCardBrand = "LINK_CARD_BRAND"

@_spi(STP) public var isPantherPayment: Bool {
self == .linkCardBrand
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class FinancialConnectionsSDKImplementation: FinancialConnectionsSDKInter
apiClient: STPAPIClient,
clientSecret: String,
returnURL: String?,
elementsSessionContext: ElementsSessionContext?,
onEvent: ((StripeCore.FinancialConnectionsEvent) -> Void)?,
from presentingViewController: UIViewController,
completion: @escaping (FinancialConnectionsSDKResult) -> Void
Expand All @@ -29,6 +30,7 @@ public class FinancialConnectionsSDKImplementation: FinancialConnectionsSDKInter
returnURL: returnURL
)
financialConnectionsSheet.apiClient = apiClient
financialConnectionsSheet.elementsSessionContext = elementsSessionContext
financialConnectionsSheet.onEvent = onEvent
// Captures self explicitly until the callback is invoked
financialConnectionsSheet.present(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ final public class FinancialConnectionsSheet {

private var wrapperViewController: ModalPresentationWrapperViewController?

// Any additional Elements context useful for the Financial Connections SDK.
@_spi(STP) public var elementsSessionContext: StripeCore.ElementsSessionContext?

// Analytics client to use for logging analytics
@_spi(STP) public let analyticsClient: STPAnalyticsClientProtocol

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,11 @@ extension PaymentMethodFormViewController {
private var usBankAccountFormElement: USBankAccountPaymentMethodElement? { form as? USBankAccountPaymentMethodElement }
private var instantDebitsFormElement: InstantDebitsPaymentMethodElement? { form as? InstantDebitsPaymentMethodElement }

private var elementsSessionContext: ElementsSessionContext? {
let linkMode = elementsSession.linkSettings?.linkMode
return ElementsSessionContext(linkMode: linkMode)
}

private var shouldOverridePrimaryButton: Bool {
if paymentMethodType == .stripe(.USBankAccount) {
if case .new = paymentOption {
Expand Down Expand Up @@ -312,6 +317,7 @@ extension PaymentMethodFormViewController {
clientSecret: paymentIntent.clientSecret,
returnURL: configuration.returnURL,
additionalParameters: additionalParameters,
elementsSessionContext: elementsSessionContext,
onEvent: nil,
params: params,
from: viewController,
Expand All @@ -322,6 +328,7 @@ extension PaymentMethodFormViewController {
clientSecret: setupIntent.clientSecret,
returnURL: configuration.returnURL,
additionalParameters: additionalParameters,
elementsSessionContext: elementsSessionContext,
onEvent: nil,
params: params,
from: viewController,
Expand All @@ -346,6 +353,7 @@ extension PaymentMethodFormViewController {
currency: currency,
onBehalfOf: intentConfig.onBehalfOf,
additionalParameters: additionalParameters,
elementsSessionContext: elementsSessionContext,
from: viewController,
financialConnectionsCompletion: financialConnectionsCompletion
)
Expand Down Expand Up @@ -402,6 +410,7 @@ extension PaymentMethodFormViewController {
clientSecret: paymentIntent.clientSecret,
returnURL: configuration.returnURL,
additionalParameters: additionalParameters,
elementsSessionContext: elementsSessionContext,
onEvent: nil,
params: params,
from: viewController,
Expand All @@ -412,6 +421,7 @@ extension PaymentMethodFormViewController {
clientSecret: setupIntent.clientSecret,
returnURL: configuration.returnURL,
additionalParameters: additionalParameters,
elementsSessionContext: elementsSessionContext,
onEvent: nil,
params: params,
from: viewController,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ extension STPElementsSession {
customerSessionData: [String: Any]? = nil,
cardBrandChoiceData: [String: Any]? = nil,
isLinkPassthroughModeEnabled: Bool? = nil,
linkMode: LinkSettings.LinkMode? = nil,
linkMode: LinkMode? = nil,
linkFundingSources: Set<LinkSettings.FundingSource> = [],
disableLinkSignup: Bool? = nil
) -> STPElementsSession {
Expand Down Expand Up @@ -88,7 +88,7 @@ extension STPElementsSession {

static func _testValue(
intent: Intent,
linkMode: LinkSettings.LinkMode? = nil,
linkMode: LinkMode? = nil,
linkFundingSources: Set<LinkSettings.FundingSource> = []
) -> STPElementsSession {
let paymentMethodTypes: [String] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

import Foundation
@_spi(STP) import StripeCore

/// For internal SDK use only
@objc(STP_Internal_LinkSettings)
Expand All @@ -21,12 +22,6 @@ import Foundation
case ephemeral
}

@_spi(STP) @frozen public enum LinkMode: String {
case linkPaymentMethod = "LINK_PAYMENT_METHOD"
case passthrough = "PASSTHROUGH"
case linkCardBrand = "LINK_CARD_BRAND"
}

@_spi(STP) public let fundingSources: Set<FundingSource>
@_spi(STP) public let popupWebviewOption: PopupWebviewOption?
@_spi(STP) public let passthroughModeEnabled: Bool?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ public class STPBankAccountCollector: NSObject {
clientSecret: String,
returnURL: String?,
additionalParameters: [String: Any] = [:],
elementsSessionContext: ElementsSessionContext?,
onEvent: ((FinancialConnectionsEvent) -> Void)?,
params: STPCollectBankAccountParams,
from viewController: UIViewController,
Expand All @@ -206,6 +207,7 @@ public class STPBankAccountCollector: NSObject {
clientSecret: clientSecret,
returnURL: returnURL,
additionalParameters: additionalParameters,
elementsSessionContext: elementsSessionContext,
onEvent: onEvent,
params: params,
from: viewController,
Expand All @@ -217,6 +219,7 @@ public class STPBankAccountCollector: NSObject {
clientSecret: String,
returnURL: String?,
additionalParameters: [String: Any] = [:],
elementsSessionContext: ElementsSessionContext? = nil,
onEvent: ((FinancialConnectionsEvent) -> Void)?,
params: STPCollectBankAccountParams,
from viewController: UIViewController,
Expand Down Expand Up @@ -254,6 +257,7 @@ public class STPBankAccountCollector: NSObject {
apiClient: self.apiClient,
clientSecret: linkAccountSession.clientSecret,
returnURL: returnURL,
elementsSessionContext: elementsSessionContext,
onEvent: onEvent,
from: viewController
) { result in
Expand Down Expand Up @@ -442,6 +446,7 @@ public class STPBankAccountCollector: NSObject {
clientSecret: String,
returnURL: String?,
additionalParameters: [String: Any] = [:],
elementsSessionContext: ElementsSessionContext? = nil,
onEvent: ((FinancialConnectionsEvent) -> Void)?,
params: STPCollectBankAccountParams,
from viewController: UIViewController,
Expand All @@ -460,6 +465,7 @@ public class STPBankAccountCollector: NSObject {
clientSecret: clientSecret,
returnURL: returnURL,
additionalParameters: additionalParameters,
elementsSessionContext: elementsSessionContext,
onEvent: onEvent,
params: params,
from: viewController,
Expand All @@ -471,6 +477,7 @@ public class STPBankAccountCollector: NSObject {
clientSecret: String,
returnURL: String?,
additionalParameters: [String: Any] = [:],
elementsSessionContext: ElementsSessionContext?,
onEvent: ((FinancialConnectionsEvent) -> Void)?,
params: STPCollectBankAccountParams,
from viewController: UIViewController,
Expand Down Expand Up @@ -507,6 +514,7 @@ public class STPBankAccountCollector: NSObject {
apiClient: self.apiClient,
clientSecret: linkAccountSession.clientSecret,
returnURL: returnURL,
elementsSessionContext: elementsSessionContext,
onEvent: onEvent,
from: viewController
) { result in
Expand Down Expand Up @@ -557,6 +565,7 @@ public class STPBankAccountCollector: NSObject {
currency: String?,
onBehalfOf: String?,
additionalParameters: [String: Any] = [:],
elementsSessionContext: ElementsSessionContext?,
from viewController: UIViewController,
financialConnectionsCompletion: @escaping (
FinancialConnectionsSDKResult?, LinkAccountSession?, NSError?
Expand Down Expand Up @@ -596,6 +605,7 @@ public class STPBankAccountCollector: NSObject {
apiClient: self.apiClient,
clientSecret: linkAccountSession.clientSecret,
returnURL: returnURL,
elementsSessionContext: elementsSessionContext,
onEvent: onEvent,
from: viewController
) { result in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ final class StubbedConnectionsSDKInterface: FinancialConnectionsSDKInterface {
apiClient: STPAPIClient,
clientSecret: String,
returnURL: String?,
elementsSessionContext: ElementsSessionContext?,
onEvent: ((FinancialConnectionsEvent) -> Void)?,
from presentingViewController: UIViewController,
completion: @escaping (FinancialConnectionsSDKResult) -> Void
Expand Down

0 comments on commit 9a7afba

Please sign in to comment.