Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 4 additions & 0 deletions RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
*** PLEASE FOLLOW THIS FORMAT: [<priority indicator, more stars = higher priority>] <description> [<PR URL>]

13.9
-----
- [*] Payments: Location permissions request is not shown to TTP users who grant "Allow once" permission on first foregrounding the app any more [https://github.com/woocommerce/woocommerce-ios/pull/9821]

13.8
-----
- [Internal] Orders: Bundled products (within a product bundle) are now indented, to show their relationship to the parent bundle. [https://github.com/woocommerce/woocommerce-ios/pull/9778]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import Foundation
import Yosemite
import CoreLocation

protocol CardReaderSupportDetermining {
func connectedReader() async -> CardReader?
func hasPreviousTapToPayUsage() async -> Bool
func siteSupportsLocalMobileReader() -> Bool
func deviceSupportsLocalMobileReader() async -> Bool
var locationIsAuthorized: Bool { get }
}

final class CardReaderSupportDeterminer: CardReaderSupportDetermining {
private let stores: StoresManager
private let configuration: CardPresentPaymentsConfiguration
private let siteID: Int64
private var locationManager: CLLocationManager = CLLocationManager()

init(siteID: Int64,
configuration: CardPresentPaymentsConfiguration = CardPresentConfigurationLoader().configuration,
Expand All @@ -21,6 +24,17 @@ final class CardReaderSupportDeterminer: CardReaderSupportDetermining {
self.stores = stores
}

var locationIsAuthorized: Bool {
switch locationManager.authorizationStatus {
case .notDetermined, .restricted, .denied:
return false
case .authorizedAlways, .authorizedWhenInUse:
return true
@unknown default:
return false
}
}

@MainActor
func connectedReader() async -> CardReader? {
await withCheckedContinuation { continuation in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ final class TapToPayReconnectionController {
isReconnecting = true
let supportDeterminer = supportDeterminer ?? CardReaderSupportDeterminer(siteID: siteID)
Task { @MainActor in
guard supportDeterminer.siteSupportsLocalMobileReader(),
guard supportDeterminer.locationIsAuthorized,
supportDeterminer.siteSupportsLocalMobileReader(),
await supportDeterminer.deviceSupportsLocalMobileReader(),
Copy link
Contributor

Choose a reason for hiding this comment

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

Not directly related to this PR, but TIL we can suspend the guard until the await chain has been resolved 💯

await supportDeterminer.hasPreviousTapToPayUsage(),
await supportDeterminer.connectedReader() == nil,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ import Yosemite
@testable import WooCommerce

final class MockCardReaderSupportDeterminer: CardReaderSupportDetermining {

var shouldReturnLocationIsAuthorized = false
var locationIsAuthorized: Bool {
return shouldReturnLocationIsAuthorized
}

var shouldReturnConnectedReader: CardReader? = nil
func connectedReader() async -> CardReader? {
return shouldReturnConnectedReader
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ final class TapToPayReconnectionControllerTests: XCTestCase {
func test_reconnectIfNeeded_calls_searchAndConnect_if_no_reader_connected_and_site_and_device_meet_requirements() throws {
// Given
let supportDeterminer = MockCardReaderSupportDeterminer()
supportDeterminer.shouldReturnLocationIsAuthorized = true
supportDeterminer.shouldReturnConnectedReader = nil
supportDeterminer.shouldReturnSiteSupportsLocalMobileReader = true
supportDeterminer.shouldReturnDeviceSupportsLocalMobileReader = true
Expand All @@ -69,6 +70,7 @@ final class TapToPayReconnectionControllerTests: XCTestCase {
func test_reconnectIfNeeded_creates_a_new_connection_controller_with_expected_parameters() throws {
// Given
let supportDeterminer = MockCardReaderSupportDeterminer()
supportDeterminer.shouldReturnLocationIsAuthorized = true
supportDeterminer.shouldReturnConnectedReader = nil
supportDeterminer.shouldReturnSiteSupportsLocalMobileReader = true
supportDeterminer.shouldReturnDeviceSupportsLocalMobileReader = true
Expand Down