Skip to content

Commit f15876a

Browse files
committed
Wrap site assessment behind ciab FF
1 parent d284cfc commit f15876a

File tree

4 files changed

+43
-26
lines changed

4 files changed

+43
-26
lines changed

Modules/Sources/Experiments/DefaultFeatureFlagService.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ public struct DefaultFeatureFlagService: FeatureFlagService {
9898
return buildConfig == .localDeveloper || buildConfig == .alpha
9999
case .ciabBookings:
100100
return buildConfig == .localDeveloper || buildConfig == .alpha
101+
case .ciab:
102+
return buildConfig == .localDeveloper || buildConfig == .alpha
101103
case .pointOfSaleSurveys:
102104
return true
103105
case .pointOfSaleCatalogAPI:

Modules/Sources/Experiments/FeatureFlag.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,11 @@ public enum FeatureFlag: Int {
204204
///
205205
case ciabBookings
206206

207+
/// Represents CIAB environment availability overall
208+
/// Has same underlying logic as `ciabBookings` flag.
209+
///
210+
case ciab
211+
207212
/// Enables surveys for potential and current POS merchants
208213
///
209214
case pointOfSaleSurveys

Modules/Sources/Yosemite/Stores/OrderCardPresentPaymentEligibilityStore.swift

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import enum WooFoundation.SeverityLevel
88
///
99
public final class OrderCardPresentPaymentEligibilityStore: Store {
1010
private let currentSite: () -> Site?
11+
private let isCIABEnvironmentSupported: () -> Bool
1112
private let crashLogger: CrashLogger
1213
private lazy var siteCIABEligibilityChecker: CIABEligibilityCheckerProtocol = CIABEligibilityChecker(
1314
currentSite: currentSite
@@ -18,9 +19,11 @@ public final class OrderCardPresentPaymentEligibilityStore: Store {
1819
storageManager: StorageManagerType,
1920
network: Network,
2021
crashLogger: CrashLogger,
22+
isCIABEnvironmentSupported: @escaping () -> Bool,
2123
currentSite: @escaping () -> Site?
2224
) {
2325
self.currentSite = currentSite
26+
self.isCIABEnvironmentSupported = isCIABEnvironmentSupported
2427
self.crashLogger = crashLogger
2528
super.init(
2629
dispatcher: dispatcher,
@@ -60,37 +63,41 @@ private extension OrderCardPresentPaymentEligibilityStore {
6063
cardPresentPaymentsConfiguration: CardPresentPaymentsConfiguration,
6164
onCompletion: (Result<Bool, Error>) -> Void) {
6265
let storage = storageManager.viewStorage
63-
let storageSite = storage.loadSite(siteID: siteID)?.toReadOnly()
64-
65-
let site: Site?
66-
if let storageSite {
67-
site = storageSite
68-
} else {
69-
/// Non - fatal fallback to `currentSite` when a storage site is missing
70-
site = currentSite()
71-
72-
logFailedStorageSiteRead(
73-
siteID: siteID,
74-
currentSiteFallbackValue: site
75-
)
76-
}
7766

78-
guard let site else {
79-
logFailedDefaultSiteRead(siteID: siteID)
67+
/// The following checks are only relevant if CIAB is rolled out.
68+
if isCIABEnvironmentSupported() {
69+
let storageSite = storage.loadSite(siteID: siteID)?.toReadOnly()
70+
71+
let site: Site?
72+
if let storageSite {
73+
site = storageSite
74+
} else {
75+
/// Non - fatal fallback to `currentSite` when a storage site is missing
76+
site = currentSite()
8077

81-
return onCompletion(
82-
.failure(
83-
OrderIsEligibleForCardPresentPaymentError.failedToObtainSite
78+
logFailedStorageSiteRead(
79+
siteID: siteID,
80+
currentSiteFallbackValue: site
8481
)
85-
)
86-
}
82+
}
83+
84+
guard let site else {
85+
logFailedDefaultSiteRead(siteID: siteID)
86+
87+
return onCompletion(
88+
.failure(
89+
OrderIsEligibleForCardPresentPaymentError.failedToObtainSite
90+
)
91+
)
92+
}
8793

88-
guard siteCIABEligibilityChecker.isFeatureSupported(.cardReader, for: site) else {
89-
return onCompletion(
90-
.failure(
91-
OrderIsEligibleForCardPresentPaymentError.cardReaderPaymentOptionIsNotSupportedForCIABSites
94+
guard siteCIABEligibilityChecker.isFeatureSupported(.cardReader, for: site) else {
95+
return onCompletion(
96+
.failure(
97+
OrderIsEligibleForCardPresentPaymentError.cardReaderPaymentOptionIsNotSupportedForCIABSites
98+
)
9299
)
93-
)
100+
}
94101
}
95102

96103
guard let order = storage.loadOrder(siteID: siteID, orderID: orderID)?.toReadOnly() else {

WooCommerce/Classes/Yosemite/AuthenticatedState.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ class AuthenticatedState: StoresManagerState {
8787
storageManager: storageManager,
8888
network: network,
8989
crashLogger: ServiceLocator.crashLogging,
90+
isCIABEnvironmentSupported: {
91+
ServiceLocator.featureFlagService.isFeatureFlagEnabled(.ciab)
92+
},
9093
currentSite: {
9194
ServiceLocator.stores.sessionManager.defaultSite
9295
}

0 commit comments

Comments
 (0)