Skip to content

Commit

Permalink
[BANKCON-14528] Update mobile FC SDKs to accept link_mode value from …
Browse files Browse the repository at this point in the history
…the payment sheet
  • Loading branch information
mats-stripe committed Sep 24, 2024
1 parent 75bdab9 commit 10f874d
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 6 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 */; };
493B33062CA3015600E3622F /* LinkMode.swift in Sources */ = {isa = PBXBuildFile; fileRef = 493B33052CA3015600E3622F /* LinkMode.swift */; };
4955688F2CA1FB8D00518AFD /* ElementsContext.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4955688E2CA1FB8D00518AFD /* ElementsContext.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 */; };
552DA7969984C443617DBC3E /* STPMultipartFormDataPart.swift in Sources */ = {isa = PBXBuildFile; fileRef = E1C72BA9C44FF60A0E7BEF76 /* STPMultipartFormDataPart.swift */; };
Expand Down Expand Up @@ -226,8 +228,10 @@
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>"; };
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>"; };
4955688E2CA1FB8D00518AFD /* ElementsContext.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ElementsContext.swift; sourceTree = "<group>"; };
4A8030BF88608CA86E295F18 /* Enums+CustomStringConvertible.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Enums+CustomStringConvertible.swift"; sourceTree = "<group>"; };
4C51E3FA5EE3587BB7BBC634 /* STPError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = STPError.swift; sourceTree = "<group>"; };
4EC3BCEEECB3E1485B18F0C4 /* FinancialConnectionsSDKInterface.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FinancialConnectionsSDKInterface.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -444,6 +448,8 @@
6A05FB462BCF24370001D128 /* FinancialConnectionsLinkedBank.swift */,
6A05FB482BCF244A0001D128 /* InstantDebitsLinkedBank.swift */,
6A05FB4A2BCF245C0001D128 /* FinancialConnectionsEvent.swift */,
4955688E2CA1FB8D00518AFD /* ElementsContext.swift */,
493B33052CA3015600E3622F /* LinkMode.swift */,
);
path = "Connections Bindings";
sourceTree = "<group>";
Expand Down Expand Up @@ -1004,6 +1010,7 @@
096274D0729AA8849FAD103C /* PaymentsSDKVariant.swift in Sources */,
DA5A05459309B9B77ACDD736 /* STPDeviceUtils.swift in Sources */,
4910B9282C3D8F3F00B030D4 /* Result+Extensions.swift in Sources */,
4955688F2CA1FB8D00518AFD /* ElementsContext.swift in Sources */,
83790210FFC2DD764C042C8E /* STPDispatchFunctions.swift in Sources */,
72DA29CA8A750E8B00DBF3D4 /* STPError.swift in Sources */,
F628BBE9FDA9D3A217ACA753 /* STPNumericStringValidator.swift in Sources */,
Expand All @@ -1020,6 +1027,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,16 @@
//
// ElementsContext.swift
// StripeCore
//
// Created by Mat Schmid on 2024-09-23.
//

import Foundation

@_spi(STP) public struct ElementsContext {
@_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?,
elementsContext: ElementsContext?,
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?,
elementsContext: ElementsContext?,
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.elementsContext = elementsContext
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 elementsContext: ElementsContext?

// 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 elementsContext: ElementsContext? {
let linkMode = elementsSession.linkSettings?.linkMode
return ElementsContext(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,
elementsContext: elementsContext,
onEvent: nil,
params: params,
from: viewController,
Expand All @@ -322,6 +328,7 @@ extension PaymentMethodFormViewController {
clientSecret: setupIntent.clientSecret,
returnURL: configuration.returnURL,
additionalParameters: additionalParameters,
elementsContext: elementsContext,
onEvent: nil,
params: params,
from: viewController,
Expand All @@ -346,6 +353,7 @@ extension PaymentMethodFormViewController {
currency: currency,
onBehalfOf: intentConfig.onBehalfOf,
additionalParameters: additionalParameters,
elementsContext: elementsContext,
from: viewController,
financialConnectionsCompletion: financialConnectionsCompletion
)
Expand Down Expand Up @@ -402,6 +410,7 @@ extension PaymentMethodFormViewController {
clientSecret: paymentIntent.clientSecret,
returnURL: configuration.returnURL,
additionalParameters: additionalParameters,
elementsContext: elementsContext,
onEvent: nil,
params: params,
from: viewController,
Expand All @@ -412,6 +421,7 @@ extension PaymentMethodFormViewController {
clientSecret: setupIntent.clientSecret,
returnURL: configuration.returnURL,
additionalParameters: additionalParameters,
elementsContext: elementsContext,
onEvent: nil,
params: params,
from: viewController,
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] = [:],
elementsContext: ElementsContext?,
onEvent: ((FinancialConnectionsEvent) -> Void)?,
params: STPCollectBankAccountParams,
from viewController: UIViewController,
Expand All @@ -206,6 +207,7 @@ public class STPBankAccountCollector: NSObject {
clientSecret: clientSecret,
returnURL: returnURL,
additionalParameters: additionalParameters,
elementsContext: elementsContext,
onEvent: onEvent,
params: params,
from: viewController,
Expand All @@ -217,6 +219,7 @@ public class STPBankAccountCollector: NSObject {
clientSecret: String,
returnURL: String?,
additionalParameters: [String: Any] = [:],
elementsContext: ElementsContext? = 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,
elementsContext: elementsContext,
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] = [:],
elementsContext: ElementsContext? = 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,
elementsContext: elementsContext,
onEvent: onEvent,
params: params,
from: viewController,
Expand All @@ -471,6 +477,7 @@ public class STPBankAccountCollector: NSObject {
clientSecret: String,
returnURL: String?,
additionalParameters: [String: Any] = [:],
elementsContext: ElementsContext?,
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,
elementsContext: elementsContext,
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] = [:],
elementsContext: ElementsContext?,
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,
elementsContext: elementsContext,
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?,
elementsContext: ElementsContext?,
onEvent: ((FinancialConnectionsEvent) -> Void)?,
from presentingViewController: UIViewController,
completion: @escaping (FinancialConnectionsSDKResult) -> Void
Expand Down

0 comments on commit 10f874d

Please sign in to comment.