Skip to content

Commit 78267b2

Browse files
committed
8314 Use checkDeviceSupport to show reader choice
Previously the logic for when we show the `Tap to Pay on iPhone` or `Bluetooth reader` screen was in the preflight controller, using Apple’s API’s. Stripe’s support is more restricted than Apple’s, and has been exposed via the CardPresentPaymentsStore. This commit updates the PreflightController to use the exposed Stripe check.
1 parent 469f8a6 commit 78267b2

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

WooCommerce/Classes/ViewRelated/CardPresentPayments/CardPresentPaymentPreflightController.swift

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ final class CardPresentPaymentPreflightController {
8282
analyticsTracker: analyticsTracker)
8383
}
8484

85-
func start() {
85+
@MainActor
86+
func start() async {
8687
configureBackend()
8788
observeConnectedReaders()
8889
// If we're already connected to a reader, return it
@@ -94,7 +95,7 @@ final class CardPresentPaymentPreflightController {
9495
// TODO: Run onboarding if needed
9596

9697
// Ask for a Reader type if supported by device/in country
97-
guard localMobileReaderSupported(),
98+
guard await localMobileReaderSupported(),
9899
configuration.supportedReaders.contains(.appleBuiltIn)
99100
else {
100101
// Attempt to find a bluetooth reader and connect
@@ -120,16 +121,16 @@ final class CardPresentPaymentPreflightController {
120121
}))
121122
}
122123

123-
private func localMobileReaderSupported() -> Bool {
124-
#if targetEnvironment(simulator)
125-
return true
126-
#else
127-
if #available(iOS 15.4, *) {
128-
return PaymentCardReader.isSupported
129-
} else {
130-
return false
124+
@MainActor
125+
private func localMobileReaderSupported() async -> Bool {
126+
await withCheckedContinuation { continuation in
127+
let action = CardPresentPaymentAction.checkDeviceSupport(siteID: siteID,
128+
cardReaderType: .appleBuiltIn,
129+
discoveryMethod: .localMobile) { result in
130+
continuation.resume(returning: result)
131+
}
132+
stores.dispatch(action)
131133
}
132-
#endif
133134
}
134135

135136
private func handleConnectionResult(_ result: Result<CardReaderConnectionResult, Error>) {

WooCommerce/Classes/ViewRelated/Orders/Collect Payments/CollectOrderPaymentUseCase.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,9 @@ final class CollectOrderPaymentUseCase: NSObject, CollectOrderPaymentProtocol {
178178
}
179179
.store(in: &cancellables)
180180

181-
preflightController?.start()
181+
Task {
182+
await preflightController?.start()
183+
}
182184
}
183185
}
184186

0 commit comments

Comments
 (0)