Skip to content

Commit 24ac17e

Browse files
KM-17521: centralize manage subscription eligibility in SubscriptionManagementUtil
1 parent f0b1ad1 commit 24ac17e

3 files changed

Lines changed: 17 additions & 8 deletions

File tree

PIA VPN/Core/Utils/SubscriptionManagementUtil.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@ private let log = PIALogger.logger(for: SubscriptionManagementUtil.self)
2828
/// Utility for managing subscription-related functionality across UIKit and SwiftUI
2929
enum SubscriptionManagementUtil {
3030

31+
/// Whether the App Store subscription management sheet can be presented for the given account.
32+
/// `AppStore.showManageSubscriptions(in:)` is unsupported when running on Mac, and only App Store
33+
/// subscriptions can be managed in the first place.
34+
///
35+
/// - Parameter info: The account info to check the plan of.
36+
static func canManageSubscription(for info: AccountInfo) -> Bool {
37+
guard !Platform.isRunningOnMac else { return false }
38+
return info.plan == .monthly || info.plan == .yearly || info.plan == .trial
39+
}
40+
3141
/// Opens the App Store subscription management sheet using StoreKit 2.
3242
/// This method presents the native iOS subscription management interface within the app.
3343
///
@@ -36,6 +46,11 @@ enum SubscriptionManagementUtil {
3646
/// For SwiftUI, use the `@Environment(\.windowScene)` property wrapper.
3747
@MainActor
3848
static func openManageSubscription(in windowScene: UIWindowScene) async {
49+
guard !Platform.isRunningOnMac else {
50+
log.error("Subscription management is not supported when running on Mac")
51+
return
52+
}
53+
3954
do {
4055
try await AppStore.showManageSubscriptions(in: windowScene)
4156
} catch {

PIA VPN/UI/Menu/AccountViewController.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,10 +214,7 @@ final class AccountViewController: AutolayoutViewController {
214214
}
215215
styleExpirationDate()
216216

217-
let hasManageablePlan = userInfo.plan == .monthly || userInfo.plan == .yearly || userInfo.plan == .trial
218-
let canManageSubscription = hasManageablePlan && !Platform.isRunningOnMac
219-
220-
if canManageSubscription {
217+
if SubscriptionManagementUtil.canManageSubscription(for: userInfo) {
221218
labelSubscriptions.isHidden = false
222219
labelSubscriptionTopConstraint.constant = 20
223220
} else {

PIA VPN/UI/Menu/MenuViewController.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,7 @@ final class MenuViewController: AutolayoutViewController {
148148
let info = currentUser.info
149149
{
150150

151-
let hasManageablePlan = info.plan == .monthly || info.plan == .yearly || info.plan == .trial
152-
let canManageSubscription = hasManageablePlan && !Platform.isRunningOnMac
153-
154-
if canManageSubscription {
151+
if SubscriptionManagementUtil.canManageSubscription(for: info) {
155152

156153
switch info.plan {
157154
case .yearly:

0 commit comments

Comments
 (0)