-
Notifications
You must be signed in to change notification settings - Fork 1k
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
[Connect] Fix API inconsistent naming + Add Dashboard-only support for Account Management component #4036
Merged
mludowise-stripe
merged 6 commits into
master
from
mludowise/MXMOBILE-2503_dashboard_components
Oct 2, 2024
Merged
[Connect] Fix API inconsistent naming + Add Dashboard-only support for Account Management component #4036
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7f9f13c
AccountManagement
mludowise-stripe 119ecb2
Add collection options
mludowise-stripe 48cacdb
Fix API discrepency
mludowise-stripe 06dbbd1
AccountManagementViewControllerTests
mludowise-stripe 62516e2
fix comment
mludowise-stripe 94fd831
Fix comment
mludowise-stripe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
StripeConnect/StripeConnect/Source/Components/AccountManagementViewController.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// | ||
// AccountManagementViewController.swift | ||
// StripeConnect | ||
// | ||
// Created by Mel Ludowise on 9/21/24. | ||
// | ||
|
||
import UIKit | ||
|
||
/** | ||
Show details of a given payment and allow users to manage disputes and perform refunds. | ||
*/ | ||
@_spi(DashboardOnly) | ||
@available(iOS 15, *) | ||
public class AccountManagementViewController: UIViewController { | ||
|
||
struct Props: Encodable { | ||
let collectionOptions: AccountCollectionOptions | ||
|
||
enum CodingKeys: String, CodingKey { | ||
case collectionOptions = "setCollectionOptions" | ||
} | ||
} | ||
|
||
let webView: ConnectComponentWebView | ||
|
||
public weak var delegate: AccountManagementViewControllerDelegate? | ||
|
||
init(componentManager: EmbeddedComponentManager, | ||
collectionOptions: AccountCollectionOptions) { | ||
webView = ConnectComponentWebView( | ||
componentManager: componentManager, | ||
componentType: .accountManagement | ||
) { | ||
Props(collectionOptions: collectionOptions) | ||
} | ||
super.init(nibName: nil, bundle: nil) | ||
|
||
webView.addMessageHandler(OnLoadErrorMessageHandler { [weak self] value in | ||
guard let self else { return } | ||
self.delegate?.accountManagement(self, didFailLoadWithError: value.error.connectEmbedError) | ||
}) | ||
|
||
// TODO(MXMOBILE-2796): Send collection options to web view | ||
|
||
webView.presentPopup = { [weak self] vc in | ||
self?.present(vc, animated: true) | ||
} | ||
} | ||
|
||
required init?(coder: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
|
||
public override func loadView() { | ||
view = webView | ||
} | ||
} | ||
|
||
@_spi(DashboardOnly) | ||
@available(iOS 15, *) | ||
public protocol AccountManagementViewControllerDelegate: AnyObject { | ||
/** | ||
Triggered when an error occurs loading the account management component | ||
- Parameters: | ||
- accountManagement: The account management component that errored when loading | ||
- error: The error that occurred when loading the component | ||
*/ | ||
func accountManagement(_ accountManagement: AccountManagementViewController, | ||
didFailLoadWithError error: Error) | ||
} | ||
|
||
@available(iOS 15, *) | ||
public extension AccountManagementViewControllerDelegate { | ||
// Default implementation to make optional | ||
func accountManagement(_ accountManagement: AccountManagementViewController, | ||
didFailLoadWithError error: Error) { } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -101,6 +101,13 @@ public class EmbeddedComponentManager { | |
.init(componentManager: self) | ||
} | ||
|
||
@_spi(DashboardOnly) | ||
public func createAccountManagementViewController( | ||
collectionOptions: AccountCollectionOptions = .init()) -> AccountManagementViewController { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure yet whether we plan to set account collection options or whether this does anything for Dashboard, but putting it in for now so we can test it |
||
.init(componentManager: self, | ||
collectionOptions: collectionOptions) | ||
} | ||
|
||
/// Used to keep reference of all web views associated with this component manager. | ||
/// - Parameters: | ||
/// - webView: The web view associated with this component manager | ||
|
75 changes: 75 additions & 0 deletions
75
StripeConnect/StripeConnectTests/Components/AccountManagementViewControllerTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// | ||
// AccountManagementViewControllerTests.swift | ||
// StripeConnectTests | ||
// | ||
// Created by Mel Ludowise on 9/25/24. | ||
// | ||
|
||
import SafariServices | ||
@_spi(PrivateBetaConnect) @_spi(DashboardOnly) @testable import StripeConnect | ||
@_spi(STP) import StripeCore | ||
import WebKit | ||
import XCTest | ||
|
||
class AccountManagementViewControllerTests: XCTestCase { | ||
let componentManager = EmbeddedComponentManager(fetchClientSecret: { | ||
return nil | ||
}) | ||
|
||
override func setUp() { | ||
super.setUp() | ||
STPAPIClient.shared.publishableKey = "pk_test" | ||
componentManager.shouldLoadContent = false | ||
} | ||
|
||
@MainActor | ||
func testDelegate() async throws { | ||
let vc = componentManager.createAccountManagementViewController() | ||
|
||
let expectationDidFail = XCTestExpectation(description: "didFail called") | ||
let delegate = AccountManagementViewControllerDelegatePassThrough { onboardingVC, error in | ||
XCTAssertEqual(vc, onboardingVC) | ||
XCTAssertEqual((error as? EmbeddedComponentError)?.type, .rateLimitError) | ||
XCTAssertEqual((error as? EmbeddedComponentError)?.description, "Error message") | ||
expectationDidFail.fulfill() | ||
} | ||
|
||
vc.delegate = delegate | ||
try await vc.webView.evaluateOnLoadError(type: "rate_limit_error", message: "Error message") | ||
await fulfillment(of: [expectationDidFail], timeout: TestHelpers.defaultTimeout) | ||
} | ||
|
||
@MainActor | ||
func testFetchInitComponentProps() async throws { | ||
let vc = componentManager.createAccountManagementViewController( | ||
collectionOptions: { | ||
var collectionOptions = AccountCollectionOptions() | ||
collectionOptions.fields = .eventuallyDue | ||
collectionOptions.futureRequirements = .include | ||
return collectionOptions | ||
}() | ||
) | ||
|
||
try await vc.webView.evaluateMessageWithReply(name: "fetchInitComponentProps", | ||
json: "{}", | ||
expectedResponse: """ | ||
{"setCollectionOptions":{"fields":"eventually_due","futureRequirements":"include"}} | ||
""") | ||
} | ||
|
||
} | ||
|
||
private class AccountManagementViewControllerDelegatePassThrough: AccountManagementViewControllerDelegate { | ||
|
||
var didFailLoad: ((_ accountManagement: AccountManagementViewController, _ error: Error) -> Void)? | ||
|
||
init(didFailLoad: ((AccountManagementViewController, Error) -> Void)? = nil) { | ||
self.didFailLoad = didFailLoad | ||
} | ||
|
||
func accountManagement(_ accountManagement: AccountManagementViewController, | ||
didFailLoadWithError error: Error) | ||
{ | ||
didFailLoad?(accountManagement, error) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We had intended to make this consistent with the AccountOnboarding delegate style, but it slipped past API review. Paper trail of API approval:
https://docs.google.com/document/d/195BaU6k2J-2CAs9anNE6e4OlZO34N-e2HTYc6pacpTw/edit?pli=1#bookmark=id.dk457iw2wtca