-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds Privacy Pro Feature Flags (#717)
* Privacy Pro Flags * Fix lint issues * Add isLaunchedOverride and isLaunchedOverrideStripe * Add SubscriptionFeatureAvailability * Add isLaunchedOverride flag * Fix duplicate * Make init public * Protocol made public * Override disallowed purchase for internal users * Empty options * Return empty options * Empty options * Add SubscriptionFeatureAvailabilityTests * Fix wrong flags checked for override * Swiftlint fixes --------- Co-authored-by: Michal Smaga <[email protected]>
- Loading branch information
1 parent
6d5ffe5
commit 0c73586
Showing
5 changed files
with
390 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
Sources/Subscription/SubscriptionFeatureAvailability.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// | ||
// SubscriptionFeatureAvailability.swift | ||
// | ||
// Copyright © 2024 DuckDuckGo. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
import BrowserServicesKit | ||
|
||
public protocol SubscriptionFeatureAvailability { | ||
var isFeatureAvailable: Bool { get } | ||
var isSubscriptionPurchaseAllowed: Bool { get } | ||
} | ||
|
||
public final class DefaultSubscriptionFeatureAvailability: SubscriptionFeatureAvailability { | ||
|
||
private let privacyConfigurationManager: PrivacyConfigurationManaging | ||
private let purchasePlatform: SubscriptionPurchaseEnvironment.Environment | ||
|
||
public init(privacyConfigurationManager: PrivacyConfigurationManaging, purchasePlatform: SubscriptionPurchaseEnvironment.Environment) { | ||
self.privacyConfigurationManager = privacyConfigurationManager | ||
self.purchasePlatform = purchasePlatform | ||
} | ||
|
||
public var isFeatureAvailable: Bool { | ||
isInternalUser || isSubscriptionLaunched || isSubscriptionLaunchedOverride | ||
} | ||
|
||
public var isSubscriptionPurchaseAllowed: Bool { | ||
let isPurchaseAllowed: Bool | ||
|
||
switch purchasePlatform { | ||
case .appStore: | ||
isPurchaseAllowed = privacyConfigurationManager.privacyConfig.isSubfeatureEnabled(PrivacyProSubfeature.allowPurchase) | ||
case .stripe: | ||
isPurchaseAllowed = privacyConfigurationManager.privacyConfig.isSubfeatureEnabled(PrivacyProSubfeature.allowPurchaseStripe) | ||
} | ||
|
||
return isPurchaseAllowed || isInternalUser | ||
} | ||
|
||
// MARK: - Conditions | ||
|
||
private var isInternalUser: Bool { | ||
privacyConfigurationManager.internalUserDecider.isInternalUser | ||
} | ||
|
||
private var isSubscriptionLaunched: Bool { | ||
switch purchasePlatform { | ||
case .appStore: | ||
privacyConfigurationManager.privacyConfig.isSubfeatureEnabled(PrivacyProSubfeature.isLaunched) | ||
case .stripe: | ||
privacyConfigurationManager.privacyConfig.isSubfeatureEnabled(PrivacyProSubfeature.isLaunchedStripe) | ||
} | ||
} | ||
|
||
private var isSubscriptionLaunchedOverride: Bool { | ||
switch purchasePlatform { | ||
case .appStore: | ||
privacyConfigurationManager.privacyConfig.isSubfeatureEnabled(PrivacyProSubfeature.isLaunchedOverride) | ||
case .stripe: | ||
privacyConfigurationManager.privacyConfig.isSubfeatureEnabled(PrivacyProSubfeature.isLaunchedOverrideStripe) | ||
} | ||
} | ||
} |
Oops, something went wrong.