Skip to content

Commit 68bbc4c

Browse files
authored
Merge pull request #9821 from woocommerce/issue/9773-prevent-ttp-reconnection-if-no-location-permission
[Mobile Payments] Prevent TTP reconnection if no location authorisation
2 parents 9e36966 + 1175919 commit 68bbc4c

File tree

5 files changed

+25
-2
lines changed

5 files changed

+25
-2
lines changed

RELEASE-NOTES.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
13.9
44
-----
5-
5+
- [*] 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]
66

77
13.8
88
-----

WooCommerce/Classes/ViewRelated/Dashboard/Settings/In-Person Payments/CardReaderSupportDeterminer.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
import Foundation
22
import Yosemite
3+
import CoreLocation
34

45
protocol CardReaderSupportDetermining {
56
func connectedReader() async -> CardReader?
67
func hasPreviousTapToPayUsage() async -> Bool
78
func siteSupportsLocalMobileReader() -> Bool
89
func deviceSupportsLocalMobileReader() async -> Bool
10+
var locationIsAuthorized: Bool { get }
911
}
1012

1113
final class CardReaderSupportDeterminer: CardReaderSupportDetermining {
1214
private let stores: StoresManager
1315
private let configuration: CardPresentPaymentsConfiguration
1416
private let siteID: Int64
17+
private var locationManager: CLLocationManager = CLLocationManager()
1518

1619
init(siteID: Int64,
1720
configuration: CardPresentPaymentsConfiguration = CardPresentConfigurationLoader().configuration,
@@ -21,6 +24,17 @@ final class CardReaderSupportDeterminer: CardReaderSupportDetermining {
2124
self.stores = stores
2225
}
2326

27+
var locationIsAuthorized: Bool {
28+
switch locationManager.authorizationStatus {
29+
case .notDetermined, .restricted, .denied:
30+
return false
31+
case .authorizedAlways, .authorizedWhenInUse:
32+
return true
33+
@unknown default:
34+
return false
35+
}
36+
}
37+
2438
@MainActor
2539
func connectedReader() async -> CardReader? {
2640
await withCheckedContinuation { continuation in

WooCommerce/Classes/ViewRelated/Dashboard/Settings/In-Person Payments/TapToPayReconnectionController.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ final class TapToPayReconnectionController {
7070
isReconnecting = true
7171
let supportDeterminer = supportDeterminer ?? CardReaderSupportDeterminer(siteID: siteID)
7272
Task { @MainActor in
73-
guard supportDeterminer.siteSupportsLocalMobileReader(),
73+
guard supportDeterminer.locationIsAuthorized,
74+
supportDeterminer.siteSupportsLocalMobileReader(),
7475
await supportDeterminer.deviceSupportsLocalMobileReader(),
7576
await supportDeterminer.hasPreviousTapToPayUsage(),
7677
await supportDeterminer.connectedReader() == nil,

WooCommerce/WooCommerceTests/Mocks/MockCardReaderSupportDeterminer.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ import Yosemite
33
@testable import WooCommerce
44

55
final class MockCardReaderSupportDeterminer: CardReaderSupportDetermining {
6+
7+
var shouldReturnLocationIsAuthorized = false
8+
var locationIsAuthorized: Bool {
9+
return shouldReturnLocationIsAuthorized
10+
}
11+
612
var shouldReturnConnectedReader: CardReader? = nil
713
func connectedReader() async -> CardReader? {
814
return shouldReturnConnectedReader

WooCommerce/WooCommerceTests/ViewRelated/Dashboard/Settings/In-Person Payments/TapToPayReconnectionControllerTests.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ final class TapToPayReconnectionControllerTests: XCTestCase {
4848
func test_reconnectIfNeeded_calls_searchAndConnect_if_no_reader_connected_and_site_and_device_meet_requirements() throws {
4949
// Given
5050
let supportDeterminer = MockCardReaderSupportDeterminer()
51+
supportDeterminer.shouldReturnLocationIsAuthorized = true
5152
supportDeterminer.shouldReturnConnectedReader = nil
5253
supportDeterminer.shouldReturnSiteSupportsLocalMobileReader = true
5354
supportDeterminer.shouldReturnDeviceSupportsLocalMobileReader = true
@@ -69,6 +70,7 @@ final class TapToPayReconnectionControllerTests: XCTestCase {
6970
func test_reconnectIfNeeded_creates_a_new_connection_controller_with_expected_parameters() throws {
7071
// Given
7172
let supportDeterminer = MockCardReaderSupportDeterminer()
73+
supportDeterminer.shouldReturnLocationIsAuthorized = true
7274
supportDeterminer.shouldReturnConnectedReader = nil
7375
supportDeterminer.shouldReturnSiteSupportsLocalMobileReader = true
7476
supportDeterminer.shouldReturnDeviceSupportsLocalMobileReader = true

0 commit comments

Comments
 (0)