Skip to content

Commit 794b199

Browse files
committed
Hide IAP debug behind experimental feature toggle
1 parent acec42a commit 794b199

File tree

9 files changed

+59
-5
lines changed

9 files changed

+59
-5
lines changed

Networking/Networking/Model/Copiable/Models+Copiable.generated.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ extension CouponReport {
170170
}
171171

172172
extension Customer {
173-
func copy(
173+
public func copy(
174174
customerID: CopiableProp<Int64> = .copy,
175175
email: CopiableProp<String> = .copy,
176176
firstName: NullableCopiableProp<String> = .copy,

Storage/Storage/Model/Copiable/Models+Copiable.generated.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ extension GeneralAppSettings {
2626
isViewAddOnsSwitchEnabled: CopiableProp<Bool> = .copy,
2727
isProductSKUInputScannerSwitchEnabled: CopiableProp<Bool> = .copy,
2828
isCouponManagementSwitchEnabled: CopiableProp<Bool> = .copy,
29+
isInAppPurchasesSwitchEnabled: CopiableProp<Bool> = .copy,
2930
knownCardReaders: CopiableProp<[String]> = .copy,
3031
lastEligibilityErrorInfo: NullableCopiableProp<EligibilityErrorInfo> = .copy,
3132
lastJetpackBenefitsBannerDismissedTime: NullableCopiableProp<Date> = .copy,
@@ -36,6 +37,7 @@ extension GeneralAppSettings {
3637
let isViewAddOnsSwitchEnabled = isViewAddOnsSwitchEnabled ?? self.isViewAddOnsSwitchEnabled
3738
let isProductSKUInputScannerSwitchEnabled = isProductSKUInputScannerSwitchEnabled ?? self.isProductSKUInputScannerSwitchEnabled
3839
let isCouponManagementSwitchEnabled = isCouponManagementSwitchEnabled ?? self.isCouponManagementSwitchEnabled
40+
let isInAppPurchasesSwitchEnabled = isInAppPurchasesSwitchEnabled ?? self.isInAppPurchasesSwitchEnabled
3941
let knownCardReaders = knownCardReaders ?? self.knownCardReaders
4042
let lastEligibilityErrorInfo = lastEligibilityErrorInfo ?? self.lastEligibilityErrorInfo
4143
let lastJetpackBenefitsBannerDismissedTime = lastJetpackBenefitsBannerDismissedTime ?? self.lastJetpackBenefitsBannerDismissedTime
@@ -47,6 +49,7 @@ extension GeneralAppSettings {
4749
isViewAddOnsSwitchEnabled: isViewAddOnsSwitchEnabled,
4850
isProductSKUInputScannerSwitchEnabled: isProductSKUInputScannerSwitchEnabled,
4951
isCouponManagementSwitchEnabled: isCouponManagementSwitchEnabled,
52+
isInAppPurchasesSwitchEnabled: isInAppPurchasesSwitchEnabled,
5053
knownCardReaders: knownCardReaders,
5154
lastEligibilityErrorInfo: lastEligibilityErrorInfo,
5255
lastJetpackBenefitsBannerDismissedTime: lastJetpackBenefitsBannerDismissedTime,

Storage/Storage/Model/GeneralAppSettings.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ public struct GeneralAppSettings: Codable, Equatable, GeneratedCopiable {
3232
///
3333
public var isCouponManagementSwitchEnabled: Bool
3434

35+
/// The state for the In-app Purchases feature switch.
36+
///
37+
public var isInAppPurchasesSwitchEnabled: Bool
38+
3539
/// A list (possibly empty) of known card reader IDs - i.e. IDs of card readers that should be reconnected to automatically
3640
/// e.g. ["CHB204909005931"]
3741
///
@@ -53,6 +57,7 @@ public struct GeneralAppSettings: Codable, Equatable, GeneratedCopiable {
5357
isViewAddOnsSwitchEnabled: Bool,
5458
isProductSKUInputScannerSwitchEnabled: Bool,
5559
isCouponManagementSwitchEnabled: Bool,
60+
isInAppPurchasesSwitchEnabled: Bool,
5661
knownCardReaders: [String],
5762
lastEligibilityErrorInfo: EligibilityErrorInfo? = nil,
5863
lastJetpackBenefitsBannerDismissedTime: Date? = nil,
@@ -66,6 +71,7 @@ public struct GeneralAppSettings: Codable, Equatable, GeneratedCopiable {
6671
self.lastEligibilityErrorInfo = lastEligibilityErrorInfo
6772
self.lastJetpackBenefitsBannerDismissedTime = lastJetpackBenefitsBannerDismissedTime
6873
self.featureAnnouncementCampaignSettings = featureAnnouncementCampaignSettings
74+
self.isInAppPurchasesSwitchEnabled = isInAppPurchasesSwitchEnabled
6975
}
7076

7177
public static var `default`: Self {
@@ -74,6 +80,7 @@ public struct GeneralAppSettings: Codable, Equatable, GeneratedCopiable {
7480
isViewAddOnsSwitchEnabled: false,
7581
isProductSKUInputScannerSwitchEnabled: false,
7682
isCouponManagementSwitchEnabled: false,
83+
isInAppPurchasesSwitchEnabled: false,
7784
knownCardReaders: [],
7885
lastEligibilityErrorInfo: nil,
7986
featureAnnouncementCampaignSettings: [:])
@@ -102,6 +109,7 @@ public struct GeneralAppSettings: Codable, Equatable, GeneratedCopiable {
102109
isViewAddOnsSwitchEnabled: isViewAddOnsSwitchEnabled,
103110
isProductSKUInputScannerSwitchEnabled: isProductSKUInputScannerSwitchEnabled,
104111
isCouponManagementSwitchEnabled: isCouponManagementSwitchEnabled,
112+
isInAppPurchasesSwitchEnabled: isInAppPurchasesSwitchEnabled,
105113
knownCardReaders: knownCardReaders,
106114
lastEligibilityErrorInfo: lastEligibilityErrorInfo,
107115
featureAnnouncementCampaignSettings: featureAnnouncementCampaignSettings
@@ -121,6 +129,7 @@ public struct GeneralAppSettings: Codable, Equatable, GeneratedCopiable {
121129
isViewAddOnsSwitchEnabled: isViewAddOnsSwitchEnabled,
122130
isProductSKUInputScannerSwitchEnabled: isProductSKUInputScannerSwitchEnabled,
123131
isCouponManagementSwitchEnabled: isCouponManagementSwitchEnabled,
132+
isInAppPurchasesSwitchEnabled: isInAppPurchasesSwitchEnabled,
124133
knownCardReaders: knownCardReaders,
125134
lastEligibilityErrorInfo: lastEligibilityErrorInfo,
126135
featureAnnouncementCampaignSettings: updatedSettings
@@ -140,6 +149,7 @@ extension GeneralAppSettings {
140149
self.isViewAddOnsSwitchEnabled = try container.decodeIfPresent(Bool.self, forKey: .isViewAddOnsSwitchEnabled) ?? false
141150
self.isProductSKUInputScannerSwitchEnabled = try container.decodeIfPresent(Bool.self, forKey: .isProductSKUInputScannerSwitchEnabled) ?? false
142151
self.isCouponManagementSwitchEnabled = try container.decodeIfPresent(Bool.self, forKey: .isCouponManagementSwitchEnabled) ?? false
152+
self.isInAppPurchasesSwitchEnabled = try container.decodeIfPresent(Bool.self, forKey: .isInAppPurchasesSwitchEnabled) ?? false
143153
self.knownCardReaders = try container.decodeIfPresent([String].self, forKey: .knownCardReaders) ?? []
144154
self.lastEligibilityErrorInfo = try container.decodeIfPresent(EligibilityErrorInfo.self, forKey: .lastEligibilityErrorInfo)
145155
self.lastJetpackBenefitsBannerDismissedTime = try container.decodeIfPresent(Date.self, forKey: .lastJetpackBenefitsBannerDismissedTime)

Storage/StorageTests/Model/AppSettings/GeneralAppSettingsTests.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ final class GeneralAppSettingsTests: XCTestCase {
6666
isViewAddOnsSwitchEnabled: true,
6767
isProductSKUInputScannerSwitchEnabled: true,
6868
isCouponManagementSwitchEnabled: true,
69+
isInAppPurchasesSwitchEnabled: false,
6970
knownCardReaders: readers,
7071
lastEligibilityErrorInfo: eligibilityInfo,
7172
lastJetpackBenefitsBannerDismissedTime: jetpackBannerDismissedDate,
@@ -101,6 +102,7 @@ private extension GeneralAppSettingsTests {
101102
isViewAddOnsSwitchEnabled: Bool = false,
102103
isProductSKUInputScannerSwitchEnabled: Bool = false,
103104
isCouponManagementSwitchEnabled: Bool = false,
105+
isInAppPurchasesSwitchEnabled: Bool = false,
104106
knownCardReaders: [String] = [],
105107
lastEligibilityErrorInfo: EligibilityErrorInfo? = nil,
106108
lastJetpackBenefitsBannerDismissedTime: Date? = nil,
@@ -111,6 +113,7 @@ private extension GeneralAppSettingsTests {
111113
isViewAddOnsSwitchEnabled: isViewAddOnsSwitchEnabled,
112114
isProductSKUInputScannerSwitchEnabled: isProductSKUInputScannerSwitchEnabled,
113115
isCouponManagementSwitchEnabled: isCouponManagementSwitchEnabled,
116+
isInAppPurchasesSwitchEnabled: isInAppPurchasesSwitchEnabled,
114117
knownCardReaders: knownCardReaders,
115118
lastEligibilityErrorInfo: lastEligibilityErrorInfo,
116119
lastJetpackBenefitsBannerDismissedTime: lastJetpackBenefitsBannerDismissedTime,

WooCommerce/Classes/Model/BetaFeature.swift

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ enum BetaFeature: String, CaseIterable {
44
case viewAddOns
55
case productSKUScanner
66
case couponManagement
7+
case inAppPurchases
78
}
89

910
extension BetaFeature {
@@ -15,6 +16,8 @@ extension BetaFeature {
1516
return Localization.productSKUScannerTitle
1617
case .couponManagement:
1718
return Localization.couponManagementTitle
19+
case .inAppPurchases:
20+
return Localization.inAppPurchasesManagementTitle
1821
}
1922
}
2023

@@ -26,6 +29,8 @@ extension BetaFeature {
2629
return Localization.productSKUScannerDescription
2730
case .couponManagement:
2831
return Localization.couponManagementDescription
32+
case .inAppPurchases:
33+
return Localization.inAppPurchasesManagementDescription
2934
}
3035
}
3136

@@ -37,6 +42,8 @@ extension BetaFeature {
3742
return \.isProductSKUInputScannerSwitchEnabled
3843
case .couponManagement:
3944
return \.isCouponManagementSwitchEnabled
45+
case .inAppPurchases:
46+
return \.isInAppPurchasesSwitchEnabled
4047
}
4148
}
4249

@@ -51,6 +58,19 @@ extension BetaFeature {
5158
}
5259
}
5360

61+
var isAvailable: Bool {
62+
switch self {
63+
case .inAppPurchases:
64+
return ServiceLocator.featureFlagService.isFeatureFlagEnabled(.inAppPurchases)
65+
default:
66+
return true
67+
}
68+
}
69+
70+
static var availableFeatures: [Self] {
71+
allCases.filter(\.isAvailable)
72+
}
73+
5474
func analyticsProperties(toggleState enabled: Bool) -> [String: WooAnalyticsEventPropertyType] {
5575
var properties = ["state": enabled ? "on" : "off"]
5676
if analyticsStat == .settingsBetaFeatureToggled {
@@ -62,7 +82,10 @@ extension BetaFeature {
6282

6383
extension GeneralAppSettingsStorage {
6484
func betaFeatureEnabled(_ feature: BetaFeature) -> Bool {
65-
value(for: feature.settingsKey)
85+
guard feature.isAvailable else {
86+
return false
87+
}
88+
return value(for: feature.settingsKey)
6689
}
6790

6891
func betaFeatureEnabledBinding(_ feature: BetaFeature) -> Binding<Bool> {
@@ -109,5 +132,12 @@ private extension BetaFeature {
109132
static let couponManagementDescription = NSLocalizedString(
110133
"Test out managing coupons as we get ready to launch",
111134
comment: "Cell description on beta features screen to enable coupon management")
135+
136+
static let inAppPurchasesManagementTitle = NSLocalizedString(
137+
"In-app purchases",
138+
comment: "Cell title on beta features screen to enable in-app purchases")
139+
static let inAppPurchasesManagementDescription = NSLocalizedString(
140+
"Test out in-app purchases as we get ready to launch",
141+
comment: "Cell description on beta features screen to enable in-app purchases")
112142
}
113143
}

WooCommerce/Classes/ViewRelated/Dashboard/Settings/Beta features/BetaFeaturesConfiguration.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ struct BetaFeaturesConfiguration: View {
1717

1818
var body: some View {
1919
List {
20-
ForEach(BetaFeature.allCases) { feature in
20+
ForEach(BetaFeature.availableFeatures) { feature in
2121
Section(footer: Text(feature.description)) {
2222
TitleAndToggleRow(title: feature.title, isOn: appSettings.betaFeatureEnabledBinding(feature))
2323
}

WooCommerce/Classes/ViewRelated/Hub Menu/HubMenuViewModel.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import SwiftUI
44
import Combine
55
import Experiments
66
import Yosemite
7+
import Storage
78

89
extension NSNotification.Name {
910
/// Posted whenever the hub menu view did appear.
@@ -54,6 +55,7 @@ final class HubMenuViewModel: ObservableObject {
5455

5556
private let stores: StoresManager
5657
private let featureFlagService: FeatureFlagService
58+
private let generalAppSettings: GeneralAppSettingsStorage
5759

5860
private var productReviewFromNoteParcel: ProductReviewFromNoteParcel?
5961

@@ -64,11 +66,13 @@ final class HubMenuViewModel: ObservableObject {
6466
init(siteID: Int64,
6567
navigationController: UINavigationController? = nil,
6668
featureFlagService: FeatureFlagService = ServiceLocator.featureFlagService,
67-
stores: StoresManager = ServiceLocator.stores) {
69+
stores: StoresManager = ServiceLocator.stores,
70+
generalAppSettings: GeneralAppSettingsStorage = ServiceLocator.generalAppSettings) {
6871
self.siteID = siteID
6972
self.navigationController = navigationController
7073
self.stores = stores
7174
self.featureFlagService = featureFlagService
75+
self.generalAppSettings = generalAppSettings
7276
observeSiteForUIUpdates()
7377
}
7478

@@ -80,7 +84,7 @@ final class HubMenuViewModel: ObservableObject {
8084
///
8185
func setupMenuElements() {
8286
menuElements = [Payments(), WoocommerceAdmin(), ViewStore(), Reviews()]
83-
if ServiceLocator.featureFlagService.isFeatureFlagEnabled(.inAppPurchases) {
87+
if generalAppSettings.betaFeatureEnabled(.inAppPurchases) {
8488
menuElements.append(InAppPurchases())
8589
}
8690

Yosemite/YosemiteTests/Stores/AppSettings/InAppFeedbackCardVisibilityUseCaseTests.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ final class InAppFeedbackCardVisibilityUseCaseTests: XCTestCase {
161161
feedbacks: [:], isViewAddOnsSwitchEnabled: false,
162162
isProductSKUInputScannerSwitchEnabled: false,
163163
isCouponManagementSwitchEnabled: false,
164+
isInAppPurchasesSwitchEnabled: false,
164165
knownCardReaders: [],
165166
featureAnnouncementCampaignSettings: [:])
166167
let useCase = InAppFeedbackCardVisibilityUseCase(settings: settings, feedbackType: .ordersCreation)
@@ -228,6 +229,7 @@ private extension InAppFeedbackCardVisibilityUseCaseTests {
228229
isViewAddOnsSwitchEnabled: false,
229230
isProductSKUInputScannerSwitchEnabled: false,
230231
isCouponManagementSwitchEnabled: false,
232+
isInAppPurchasesSwitchEnabled: false,
231233
knownCardReaders: [],
232234
featureAnnouncementCampaignSettings: [:]
233235
)

Yosemite/YosemiteTests/Stores/AppSettingsStoreTests.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,6 +1006,7 @@ private extension AppSettingsStoreTests {
10061006
isViewAddOnsSwitchEnabled: false,
10071007
isProductSKUInputScannerSwitchEnabled: false,
10081008
isCouponManagementSwitchEnabled: false,
1009+
isInAppPurchasesSwitchEnabled: false,
10091010
knownCardReaders: [],
10101011
featureAnnouncementCampaignSettings: [:]
10111012
)
@@ -1019,6 +1020,7 @@ private extension AppSettingsStoreTests {
10191020
isViewAddOnsSwitchEnabled: false,
10201021
isProductSKUInputScannerSwitchEnabled: false,
10211022
isCouponManagementSwitchEnabled: false,
1023+
isInAppPurchasesSwitchEnabled: false,
10221024
knownCardReaders: [],
10231025
featureAnnouncementCampaignSettings: featureAnnouncementCampaignSettings
10241026
)

0 commit comments

Comments
 (0)