Skip to content

Commit

Permalink
Fixes and testing for merchant-initiated repair flows
Browse files Browse the repository at this point in the history
  • Loading branch information
tillh-stripe committed Jan 31, 2025
1 parent e16dd1f commit 6e1a4ee
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,36 @@ final class PlaygroundConfiguration {
configurationStore[Self.phoneKey] = newValue
}
}

// MARK: - Relink Authorization

private static let customerIdKey = "customer_id"
var customerId: String {
get {
if let customerId = configurationStore[Self.customerIdKey] as? String {
return customerId
} else {
return ""
}
}
set {
configurationStore[Self.customerIdKey] = newValue
}
}

private static let relinkAuthorizationKey = "relink_authorization"
var relinkAuthorization: String {
get {
if let relinkAuthorization = configurationStore[Self.relinkAuthorizationKey] as? String {
return relinkAuthorization
} else {
return ""
}
}
set {
configurationStore[Self.relinkAuthorizationKey] = newValue
}
}

// MARK: - Permissions

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,17 @@ struct PlaygroundView: View {
.accessibility(identifier: "playground-phone")
}
}

Section(header: Text("Relink")) {
TextField("Customer", text: viewModel.customerId)
.keyboardType(.default)
.autocapitalization(.none)
.accessibility(identifier: "playground-customer-id")

TextField("Relink authorization", text: viewModel.relinkAuthorization)
.keyboardType(.default)
.accessibility(identifier: "playground-relink-authorization")
}

Section(header: Text("PERMISSIONS")) {
Toggle("Balances", isOn: viewModel.balancesPermission)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,30 @@ final class PlaygroundViewModel: ObservableObject {
}
)
}

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

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

var balancesPermission: Binding<Bool> {
Binding(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,10 @@ extension NativeFlowController {
//
// keeping this logic in `pushPane` is helpful because we want to
// reuse `skipSuccessPane` and `manualEntryMode == .custom` logic
clearNavigationStack: Bool = false
clearNavigationStack: Bool = false,
// Useful for cases where we want to prevent the current pane from being shown again,
// but not affect any previous panes.
removeCurrent: Bool = false
) {
if pane == .success && dataManager.manifest.skipSuccessPane == true {
closeAuthFlow(error: nil)
Expand All @@ -192,8 +195,11 @@ extension NativeFlowController {
nativeFlowController: self,
dataManager: dataManager
)
if clearNavigationStack, let paneViewController = paneViewController {
if clearNavigationStack, let paneViewController {
setNavigationControllerViewControllers([paneViewController], animated: animated)
} else if removeCurrent, let paneViewController {
let viewControllers = Array(navigationController.viewControllers.dropLast())
setNavigationControllerViewControllers(viewControllers + [paneViewController], animated: animated)
} else {
pushViewController(paneViewController, animated: animated)
}
Expand Down Expand Up @@ -829,6 +835,14 @@ extension NativeFlowController: PartnerAuthViewControllerDelegate {

showErrorPane(forError: error, referrerPane: .partnerAuth)
}

func partnerAuthViewController(
_ viewController: PartnerAuthViewController,
didRequestNextPane nextPane: FinancialConnectionsSessionManifest.NextPane
) {
dataManager.authSession = nil // clear any lingering auth sessions
pushPane(nextPane, animated: true, removeCurrent: true)
}
}

// MARK: - AccountPickerViewControllerDelegate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ protocol PartnerAuthViewControllerDelegate: AnyObject {
_ viewController: PartnerAuthViewController,
didReceiveError error: Error
)
func partnerAuthViewController(
_ viewController: PartnerAuthViewController,
didRequestNextPane nextPane: FinancialConnectionsSessionManifest.NextPane
)
}

final class PartnerAuthViewController: SheetViewController {
Expand Down Expand Up @@ -157,7 +161,12 @@ final class PartnerAuthViewController: SheetViewController {
},
didSelectCancel: { [weak self] in
guard let self = self else { return }
self.delegate?.partnerAuthViewControllerDidRequestToGoBack(self)

if panePresentationStyle == .fullscreen {
self.delegate?.partnerAuthViewController(self, didRequestNextPane: .institutionPicker)
} else {
self.delegate?.partnerAuthViewControllerDidRequestToGoBack(self)
}
}
)
self.prepaneViews = prepaneViews
Expand Down

0 comments on commit 6e1a4ee

Please sign in to comment.