From 5b4d406ccfd58d940c4c493894e7dceec466213b Mon Sep 17 00:00:00 2001 From: Davide De Rosa Date: Fri, 29 Jan 2021 19:06:39 +0100 Subject: [PATCH] Only drop features if refunded Retain existing providers and trusted networks in beta. --- Passepartout/App/iOS/Global/ProductManager+App.swift | 5 +++-- Passepartout/Core/Sources/Model/ProductManager.swift | 9 +++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Passepartout/App/iOS/Global/ProductManager+App.swift b/Passepartout/App/iOS/Global/ProductManager+App.swift index 364f4ecd..bbf631f8 100644 --- a/Passepartout/App/iOS/Global/ProductManager+App.swift +++ b/Passepartout/App/iOS/Global/ProductManager+App.swift @@ -41,12 +41,13 @@ extension ProductManager { public func reviewPurchases() { let service = TransientStore.shared.service reloadReceipt(andNotify: false) + let isFullVersion = (try? isEligible(forFeature: .fullVersion)) ?? false var anyRefund = false // review features and potentially revert them if they were used (Siri is handled in AppDelegate) log.debug("Checking 'Trusted networks'") - if !((try? isEligible(forFeature: .trustedNetworks)) ?? false) { + if isCancelledPurchase(.fullVersion) || (!isFullVersion && isCancelledPurchase(.trustedNetworks)) { // reset trusted networks for ALL profiles (must load first) for key in service.allProfileKeys() { @@ -76,7 +77,7 @@ extension ProductManager { guard let metadata = InfrastructureFactory.shared.metadata(forName: name) else { continue } - if !((try? isEligible(forProvider: metadata)) ?? false) { + if isCancelledPurchase(.fullVersion) || (!isFullVersion && isCancelledPurchase(metadata.product)) { service.removeProfile(ProfileKey(name)) log.debug("\tRefunded provider: \(name)") anyRefund = true diff --git a/Passepartout/Core/Sources/Model/ProductManager.swift b/Passepartout/Core/Sources/Model/ProductManager.swift index a77ef476..750512f9 100644 --- a/Passepartout/Core/Sources/Model/ProductManager.swift +++ b/Passepartout/Core/Sources/Model/ProductManager.swift @@ -65,6 +65,8 @@ public class ProductManager: NSObject { private var purchaseDates: [Product: Date] + private var cancelledPurchases: Set + private var refreshRequest: SKReceiptRefreshRequest? private var restoreCompletionHandler: ((Error?) -> Void)? @@ -75,6 +77,7 @@ public class ProductManager: NSObject { purchasedAppBuild = nil purchasedFeatures = [] purchaseDates = [:] + cancelledPurchases = [] super.init() @@ -185,6 +188,10 @@ public class ProductManager: NSObject { #endif } + public func isCancelledPurchase(_ product: Product) -> Bool { + return cancelledPurchases.contains(product) + } + public func purchaseDate(forProduct product: Product) -> Date? { return purchaseDates[product] } @@ -203,6 +210,7 @@ public class ProductManager: NSObject { purchasedAppBuild = buildNumber } purchasedFeatures.removeAll() + cancelledPurchases.removeAll() if let buildNumber = purchasedAppBuild { log.debug("Original purchased build: \(buildNumber)") @@ -222,6 +230,7 @@ public class ProductManager: NSObject { } if let cancellationDate = $0.cancellationDate { log.debug("\t\(pid) [cancelled on: \(cancellationDate)]") + cancelledPurchases.insert(product) return } if let purchaseDate = $0.originalPurchaseDate {