Skip to content

[Migrate simple payments] Fix card reader payment methods from Menu > Payments > Collect Payment #12801

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

Merged
merged 4 commits into from
May 23, 2024
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
1 change: 1 addition & 0 deletions RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

18.8
-----
- [*] Menu > Payments > Collect Payment: fix the the "card reader" & "Tap To Pay" payment methods where it was no-op before. [https://github.com/woocommerce/woocommerce-ios/pull/12801]
- [internal] Optimize API calls sent for Dashboard screen. [https://github.com/woocommerce/woocommerce-ios/pull/12775]


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,10 @@ struct InPersonPaymentsMenu: View {
}
.navigationDestination(isPresented: $viewModel.presentPaymentMethods) {
if let paymentMethodsViewModel = viewModel.paymentMethodsViewModel {
PaymentMethodsView(dismiss: {
PaymentMethodsWrapperHosted(viewModel: paymentMethodsViewModel,
dismiss: {
viewModel.dismissPaymentCollection()
}, viewModel: paymentMethodsViewModel)
})
} else {
EmptyView()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import SwiftUI

/// A pure wrapper UIKit hosting controller of `PaymentMethodsView` to provide `PaymentMethodsView`'s `rootViewController` in order
/// for card reader payment methods to work, as a pure SwiftUI flow doesn't have a `UIViewController` to pass around.
/// To use it in SwiftUI, `PaymentMethodsWrapperHosted` is the wrapper's SwiftUI version.
final class PaymentMethodsWrapperHostingController: UIHostingController<PaymentMethodsView> {
init(dismiss: @escaping () -> Void,
viewModel: PaymentMethodsViewModel) {
super.init(rootView: PaymentMethodsView(dismiss: dismiss, viewModel: viewModel))
}

required dynamic init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

override func viewDidLoad() {
super.viewDidLoad()

// Needed to present IPP collect amount alerts, which are displayed in UIKit view controllers.
rootView.rootViewController = self
}
}

// MARK: - SwiftUI compatibility
struct PaymentMethodsWrapperHosted: UIViewControllerRepresentable {
let viewModel: PaymentMethodsViewModel
let dismiss: () -> Void

func makeUIViewController(context: Context) -> some UIViewController {
PaymentMethodsWrapperHostingController(dismiss: dismiss, viewModel: viewModel)
}

func updateUIViewController(_ uiViewController: UIViewControllerType, context: Context) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ struct PaymentMethodsView: View {
}
.background(FullScreenCoverClearBackgroundView())
}
.onAppear {
guard rootViewController != nil else {
return viewModel.logNoRootViewControllerError()
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,17 @@ final class PaymentMethodsViewModel: ObservableObject {
trackFlowCanceled()
}

/// Logs an error when `PaymentMethodsView.rootViewController` is missing.
func logNoRootViewControllerError() {
let logProperties: [String: Any] = ["flow": flow.rawValue]
ServiceLocator.crashLogging.logMessage(
"Missing `rootViewController` in `PaymentMethodsView` can result in a broken IPP experience",
properties: logProperties,
level: .error
)
assertionFailure("Missing `rootViewController` in `PaymentMethodsView` can result in a broken IPP experience in flow: \(flow.rawValue)")
}

/// Defines if the swipe-to-dismiss gesture on the payment flow should be enabled
///
var shouldEnableSwipeToDismiss: Bool {
Expand Down
4 changes: 4 additions & 0 deletions WooCommerce/WooCommerce.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@
025678052575EA1B009D7E6C /* ProductDetailsCellViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 025678042575EA1B009D7E6C /* ProductDetailsCellViewModelTests.swift */; };
025678C125773236009D7E6C /* Collection+ShippingLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 025678C025773236009D7E6C /* Collection+ShippingLabel.swift */; };
025678C725773399009D7E6C /* Collection+ShippingLabelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 025678C625773399009D7E6C /* Collection+ShippingLabelTests.swift */; };
02577A7F2BFC4BB300B63FE6 /* PaymentMethodsWrapperHostingController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02577A7E2BFC4BB300B63FE6 /* PaymentMethodsWrapperHostingController.swift */; };
0258B4D82B1590A3008FEA07 /* ConfigurableBundleNoticeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0258B4D72B1590A3008FEA07 /* ConfigurableBundleNoticeView.swift */; };
0258B4DA2B159A0F008FEA07 /* Publisher+WithPrevious.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0258B4D92B159A0F008FEA07 /* Publisher+WithPrevious.swift */; };
0258B66D2518778300EB5CF2 /* ProductFormViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0258B66C2518778300EB5CF2 /* ProductFormViewModelTests.swift */; };
Expand Down Expand Up @@ -3009,6 +3010,7 @@
025678042575EA1B009D7E6C /* ProductDetailsCellViewModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProductDetailsCellViewModelTests.swift; sourceTree = "<group>"; };
025678C025773236009D7E6C /* Collection+ShippingLabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Collection+ShippingLabel.swift"; sourceTree = "<group>"; };
025678C625773399009D7E6C /* Collection+ShippingLabelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Collection+ShippingLabelTests.swift"; sourceTree = "<group>"; };
02577A7E2BFC4BB300B63FE6 /* PaymentMethodsWrapperHostingController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PaymentMethodsWrapperHostingController.swift; sourceTree = "<group>"; };
0258B4D72B1590A3008FEA07 /* ConfigurableBundleNoticeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConfigurableBundleNoticeView.swift; sourceTree = "<group>"; };
0258B4D92B159A0F008FEA07 /* Publisher+WithPrevious.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Publisher+WithPrevious.swift"; sourceTree = "<group>"; };
0258B66C2518778300EB5CF2 /* ProductFormViewModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProductFormViewModelTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -7233,6 +7235,7 @@
20D5CB502AFCF856009A39C3 /* PaymentsRow.swift */,
20D5CB522AFCF8E7009A39C3 /* PaymentsToggleRow.swift */,
0240737F2BBAAF7400C00441 /* SimplePaymentsMigrationView.swift */,
02577A7E2BFC4BB300B63FE6 /* PaymentMethodsWrapperHostingController.swift */,
);
path = "Payments Menu";
sourceTree = "<group>";
Expand Down Expand Up @@ -14513,6 +14516,7 @@
CE263DE8206ACE3E0015A693 /* MainTabBarController.swift in Sources */,
20A3AFE32B10EF860033AF2D /* CardReaderSettingsFlowPresentingView.swift in Sources */,
CE14452E2188C11700A991D8 /* ZendeskManager.swift in Sources */,
02577A7F2BFC4BB300B63FE6 /* PaymentMethodsWrapperHostingController.swift in Sources */,
02BA53432A380D7D0069224D /* ProductDescriptionAICoordinator.swift in Sources */,
FE28F7122684CA29004465C7 /* RoleErrorViewController.swift in Sources */,
B5BE75DB213F1D1E00909A14 /* OverlayMessageView.swift in Sources */,
Expand Down