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

[1/2] Swift Concurrency migration - Financial Connections API client #4444

Merged
merged 7 commits into from
Jan 16, 2025
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 @@ -442,6 +442,31 @@ final class PlaygroundConfiguration {
}
}

// MARK: - Experimental

@UserDefault(
key: "FINANCIAL_CONNECTIONS_EXAMPLE_USE_ASYNC_API_CLIENT",
defaultValue: false
)
private static var useAsyncAPIClientStorage: Bool

private static let useAsyncAPIClientKey = "use_async_api_client"
var useAsyncAPIClient: Bool {
get {
if let useAsyncAPIClient = configurationStore[Self.useAsyncAPIClientKey] as? Bool {
return useAsyncAPIClient
} else {
return false
}
}
set {
// Save to configuration string
configurationStore[Self.useAsyncAPIClientKey] = newValue
// Save to user defaults
Self.useAsyncAPIClientStorage = newValue
}
}

// MARK: - Update

func updateConfigurationString(_ configurationString: String) {
Expand Down Expand Up @@ -548,6 +573,12 @@ final class PlaygroundConfiguration {
} else {
self.liveEvents = false
}

if let useAsyncAPIClient = dictionary[Self.useAsyncAPIClientKey] as? Bool {
self.useAsyncAPIClient = useAsyncAPIClient
} else {
self.useAsyncAPIClient = false
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ struct PlaygroundView: View {
.disabled(viewModel.sessionOutput[.accountIds] == nil)
.accessibility(identifier: "playground-session-output-copy-account-ids")
}

Section(header: Text("Experimental")) {
Toggle("Use async API client", isOn: viewModel.useAsyncAPIClient)
}
}

VStack {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

import Combine
import Foundation
import StripeFinancialConnections
@_spi(STP) import StripeCore
@_spi(STP) import StripeFinancialConnections
import StripePaymentSheet
import SwiftUI
import UIKit
Expand Down Expand Up @@ -212,6 +213,18 @@ final class PlaygroundViewModel: ObservableObject {
)
}

var useAsyncAPIClient: Binding<Bool> {
Binding(
get: {
self.playgroundConfiguration.useAsyncAPIClient
},
set: {
self.playgroundConfiguration.useAsyncAPIClient = $0
self.objectWillChange.send()
}
)
}

@Published var showConfigurationView = false
private(set) lazy var playgroundConfigurationViewModel: PlaygroundManageConfigurationViewModel = {
return PlaygroundManageConfigurationViewModel(
Expand Down Expand Up @@ -309,6 +322,7 @@ final class PlaygroundViewModel: ObservableObject {
useCase: self.playgroundConfiguration.useCase,
stripeAccount: self.playgroundConfiguration.merchant.stripeAccount,
setupPlaygroundResponseJSON: setupPlaygroundResponse,
useAsyncApiClient: self.playgroundConfiguration.useAsyncAPIClient,
onEvent: { event in
if self.liveEvents.wrappedValue == true {
let message = "\(event.name.rawValue); \(event.metadata.dictionary)"
Expand Down Expand Up @@ -457,6 +471,7 @@ private func PresentFinancialConnectionsSheet(
useCase: PlaygroundConfiguration.UseCase,
stripeAccount: String?,
setupPlaygroundResponseJSON: [String: String],
useAsyncApiClient: Bool,
onEvent: @escaping (FinancialConnectionsEvent) -> Void,
completionHandler: @escaping (FinancialConnectionsSheet.Result) -> Void
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import Foundation
case payment(String)
case setup(String)
case deferred(String)

@_spi(STP) public var id: String {
switch self {
case let .payment(id), let .setup(id), let .deferred(id):
Expand Down Expand Up @@ -55,7 +55,7 @@ import Foundation
@_spi(STP) public var billingAddress: BillingAddress? {
BillingAddress(from: billingDetails)
}

@_spi(STP) public var incentiveEligibilitySession: IntentID? {
guard eligibleForIncentive else {
return nil
Expand All @@ -64,13 +64,13 @@ import Foundation
}

@_spi(STP) public init(
amount: Int?,
currency: String?,
prefillDetails: PrefillDetails?,
intentId: IntentID?,
linkMode: LinkMode?,
billingDetails: BillingDetails?,
eligibleForIncentive: Bool
amount: Int? = nil,
currency: String? = nil,
prefillDetails: PrefillDetails? = nil,
intentId: IntentID? = nil,
linkMode: LinkMode? = nil,
billingDetails: BillingDetails? = nil,
eligibleForIncentive: Bool = false
) {
self.amount = amount
self.currency = currency
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
460C7685096AA6C693309647 /* FinancialConnectionsAuthSession.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5C837C27C2577391B91FF0E5 /* FinancialConnectionsAuthSession.swift */; };
465AE8A58AD2183E1E2042FE /* ConsentDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81304AD5BE5CCA10D1A866E0 /* ConsentDataSource.swift */; };
486E50E6CB90208AB98C031E /* UIImageView+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDC3AC48492FAB61E5B66D94 /* UIImageView+Extensions.swift */; };
490A37E72D2EF6B0007917CD /* FinancialConnectionsSynchronize.json in Resources */ = {isa = PBXBuildFile; fileRef = 490A37E62D2EF6B0007917CD /* FinancialConnectionsSynchronize.json */; };
490B00112C93582900B1A489 /* FinancialConnectionsAccountPickerPane.swift in Sources */ = {isa = PBXBuildFile; fileRef = 490B00102C93582900B1A489 /* FinancialConnectionsAccountPickerPane.swift */; };
492039952CA4972B00CE2072 /* FinancialConnectionsWebFlowTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 492039942CA4972B00CE2072 /* FinancialConnectionsWebFlowTests.swift */; };
492651662C24C9E7001DDBCA /* TestModeAutofillBannerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 492651652C24C9E7001DDBCA /* TestModeAutofillBannerView.swift */; };
Expand All @@ -71,6 +72,8 @@
49C9113B2C59932300589E0D /* LinkSignupFormView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 49C9113A2C59932300589E0D /* LinkSignupFormView.swift */; };
49F047532C63B430006BAD3E /* StripeSchemeAddress.swift in Sources */ = {isa = PBXBuildFile; fileRef = 49F047522C63B430006BAD3E /* StripeSchemeAddress.swift */; };
49F047552C63C2E5006BAD3E /* FinancialConnectionsPaymentDetails.swift in Sources */ = {isa = PBXBuildFile; fileRef = 49F047542C63C2E5006BAD3E /* FinancialConnectionsPaymentDetails.swift */; };
49F1B83A2D2DAE7100136303 /* FinancialConnectionsAsyncAPIClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = 49F1B8392D2DAE7100136303 /* FinancialConnectionsAsyncAPIClient.swift */; };
49F1B83E2D2EC82300136303 /* FinancialConnectionsAsyncAPIClient+Legacy.swift in Sources */ = {isa = PBXBuildFile; fileRef = 49F1B83D2D2EC82300136303 /* FinancialConnectionsAsyncAPIClient+Legacy.swift */; };
4A0D015C978BD79BBFE6CE57 /* ManualEntryDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD4C39F5F9AF440B13F51A81 /* ManualEntryDataSource.swift */; };
4A537AE0C50CAFF3889EFE28 /* UIViewController+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF7E41313B709F87B549D85F /* UIViewController+Extensions.swift */; };
4DC8EB63806434ABF4C9CC43 /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 782A419DCF59BE6AB6439D04 /* [email protected] */; };
Expand Down Expand Up @@ -318,6 +321,7 @@
452989E2D269784006EFD18C /* FinancialConnectionsPartnerAccount.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FinancialConnectionsPartnerAccount.swift; sourceTree = "<group>"; };
463549CECD379484842033E3 /* AccountPickerAccountLoadErrorView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountPickerAccountLoadErrorView.swift; sourceTree = "<group>"; };
4667E3861CDEC3A41B757714 /* FinancialConnectionsSynchronize.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FinancialConnectionsSynchronize.swift; sourceTree = "<group>"; };
490A37E62D2EF6B0007917CD /* FinancialConnectionsSynchronize.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = FinancialConnectionsSynchronize.json; sourceTree = "<group>"; };
490B00102C93582900B1A489 /* FinancialConnectionsAccountPickerPane.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FinancialConnectionsAccountPickerPane.swift; sourceTree = "<group>"; };
492039942CA4972B00CE2072 /* FinancialConnectionsWebFlowTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FinancialConnectionsWebFlowTests.swift; sourceTree = "<group>"; };
492651652C24C9E7001DDBCA /* TestModeAutofillBannerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestModeAutofillBannerView.swift; sourceTree = "<group>"; };
Expand All @@ -333,6 +337,8 @@
49C9113A2C59932300589E0D /* LinkSignupFormView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = LinkSignupFormView.swift; path = StripeFinancialConnections/Source/Native/NetworkingLinkSignupPane/LinkSignupFormView.swift; sourceTree = SOURCE_ROOT; };
49F047522C63B430006BAD3E /* StripeSchemeAddress.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StripeSchemeAddress.swift; sourceTree = "<group>"; };
49F047542C63C2E5006BAD3E /* FinancialConnectionsPaymentDetails.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FinancialConnectionsPaymentDetails.swift; sourceTree = "<group>"; };
49F1B8392D2DAE7100136303 /* FinancialConnectionsAsyncAPIClient.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FinancialConnectionsAsyncAPIClient.swift; sourceTree = "<group>"; };
49F1B83D2D2EC82300136303 /* FinancialConnectionsAsyncAPIClient+Legacy.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "FinancialConnectionsAsyncAPIClient+Legacy.swift"; sourceTree = "<group>"; };
4A7B146AA6BF44921A249DB8 /* EmptyFinancialConnectionsAPIClient.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmptyFinancialConnectionsAPIClient.swift; sourceTree = "<group>"; };
4AFBF95DAE0783010A17EB58 /* FinancialConnectionsSession_only_accounts.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = FinancialConnectionsSession_only_accounts.json; sourceTree = "<group>"; };
4BFCD9C339634B71FC8F85E9 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
Expand Down Expand Up @@ -649,6 +655,8 @@
FF54EDA6123C7E4E78D9D56B /* APIPollingHelper.swift */,
2D95E5F34BDEE0237F52DA0A /* APIVersion.swift */,
4E2EAD7059FF8358E674774A /* FinancialConnectionsAPIClient.swift */,
49F1B8392D2DAE7100136303 /* FinancialConnectionsAsyncAPIClient.swift */,
49F1B83D2D2EC82300136303 /* FinancialConnectionsAsyncAPIClient+Legacy.swift */,
);
path = "API Bindings";
sourceTree = "<group>";
Expand Down Expand Up @@ -910,6 +918,7 @@
4AFBF95DAE0783010A17EB58 /* FinancialConnectionsSession_only_accounts.json */,
1DF07A1AAD6B39033F0B86FD /* FinancialConnectionsSession_only_both_missing.json */,
AA01BC4016BF8788633CCAD9 /* FinancialConnectionsSession_only_la.json */,
490A37E62D2EF6B0007917CD /* FinancialConnectionsSynchronize.json */,
);
path = MockData;
sourceTree = "<group>";
Expand Down Expand Up @@ -1230,6 +1239,8 @@
"zh-Hant",
);
mainGroup = 7879CBA341D7E807714A831B;
packageReferences = (
);
productRefGroup = 820BF9CF057CF92872BC3C15 /* Products */;
projectDirPath = "";
projectRoot = "";
Expand All @@ -1246,6 +1257,7 @@
buildActionMask = 2147483647;
files = (
D0C1EF46A418A8F8774B7418 /* FinancialConnectionsSession_both_accounts_la.json in Resources */,
490A37E72D2EF6B0007917CD /* FinancialConnectionsSynchronize.json in Resources */,
07BFA34C5643A79E1E35A159 /* FinancialConnectionsSession_only_accounts.json in Resources */,
A156FACA60231988F247F6F4 /* FinancialConnectionsSession_only_both_missing.json in Resources */,
ACD21F21C6E42706A882A1AE /* FinancialConnectionsSession_only_la.json in Resources */,
Expand Down Expand Up @@ -1374,6 +1386,7 @@
3446145FCA3278D51A9D4B80 /* AttachLinkedPaymentAccountDataSource.swift in Sources */,
E3F62D2F9C344A1178030E8E /* AttachLinkedPaymentAccountViewController.swift in Sources */,
707C265C4179A8FEC98913FE /* ConsentBodyView.swift in Sources */,
49F1B83E2D2EC82300136303 /* FinancialConnectionsAsyncAPIClient+Legacy.swift in Sources */,
465AE8A58AD2183E1E2042FE /* ConsentDataSource.swift in Sources */,
97C528CE821C6A55D58F68A4 /* ConsentFooterView.swift in Sources */,
8927328EE28A0C94B5AB69DB /* ConsentLogoView.swift in Sources */,
Expand All @@ -1384,6 +1397,7 @@
44203505ED2F64D07632566B /* LinkAccountPickerBodyView.swift in Sources */,
6A13B9822B48BD6C00FFA327 /* AccountPickerRowView.swift in Sources */,
C55F79F4B85E1EB8730B02C6 /* LinkAccountPickerDataSource.swift in Sources */,
49F1B83A2D2DAE7100136303 /* FinancialConnectionsAsyncAPIClient.swift in Sources */,
166ACB3BF53BDB4443E276E3 /* LinkAccountPickerFooterView.swift in Sources */,
F0495231F4C70E054149C03A /* LinkAccountPickerNewAccountRowView.swift in Sources */,
72BB9389206F10DE9B18E542 /* LinkAccountPickerViewController.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,14 @@ protocol FinancialConnectionsAPI {
customSuccessPaneMessage: String?
)

var backingAPIClient: STPAPIClient { get }

var isLinkWithStripe: Bool { get set }
var consumerPublishableKey: String? { get set }
var consumerSession: ConsumerSessionData? { get set }

func completeAssertion(possibleError: Error?)

func synchronize(
clientSecret: String,
returnURL: String?
Expand Down Expand Up @@ -295,6 +303,12 @@ protocol FinancialConnectionsAPI {
paymentDetailsId: String,
billingDetails: ElementsSessionContext.BillingDetails?
) -> Future<LinkBankPaymentMethod>

func updateAvailableIncentives(
Copy link
Collaborator

Choose a reason for hiding this comment

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

🙏

consumerSessionClientSecret: String,
sessionID: String,
paymentDetailsID: String
) -> Future<AvailableIncentives>
}

extension FinancialConnectionsAPIClient: FinancialConnectionsAPI {
Expand Down
Loading
Loading