From 3fb521a584df8837a09377447978af4f02c1b016 Mon Sep 17 00:00:00 2001 From: Davide De Rosa Date: Thu, 11 Jan 2024 17:52:05 +0100 Subject: [PATCH] Split Apple TV purchase (#467) Full version features were listed when purchasing the Apple TV feature, and this was very misleading. --- Passepartout/App/Views/AddProviderView.swift | 2 +- .../App/Views/PaywallView+Purchase.swift | 6 ++- Passepartout/App/Views/PaywallView.swift | 6 +-- .../Managers/ProductManager.swift | 49 ++++++++++--------- .../ProductManagerTests.swift | 4 +- 5 files changed, 36 insertions(+), 31 deletions(-) diff --git a/Passepartout/App/Views/AddProviderView.swift b/Passepartout/App/Views/AddProviderView.swift index f6cccfa3..4104b2a6 100644 --- a/Passepartout/App/Views/AddProviderView.swift +++ b/Passepartout/App/Views/AddProviderView.swift @@ -60,7 +60,7 @@ struct AddProviderView: View { themeCloseItem(isPresented: bindings.$isPresented) }.sheet(isPresented: $viewModel.isPaywallPresented) { NavigationView { - PaywallView(isPresented: $viewModel.isPaywallPresented) + PaywallView(isPresented: $viewModel.isPaywallPresented, feature: .allProviders) }.themeGlobal() }.navigationTitle(L10n.AddProfile.Shared.title) .themeSecondaryView() diff --git a/Passepartout/App/Views/PaywallView+Purchase.swift b/Passepartout/App/Views/PaywallView+Purchase.swift index 9593e19c..3f6ec78c 100644 --- a/Passepartout/App/Views/PaywallView+Purchase.swift +++ b/Passepartout/App/Views/PaywallView+Purchase.swift @@ -54,8 +54,10 @@ extension PaywallView { var body: some View { List { - skFullVersion.map { - fullFeaturesSection(withHeader: $0.localizedTitle) + if feature != .appleTV { + skFullVersion.map { + fullFeaturesSection(withHeader: $0.localizedTitle) + } } purchaseSection .disabled(purchaseState != nil) diff --git a/Passepartout/App/Views/PaywallView.swift b/Passepartout/App/Views/PaywallView.swift index cd65bc5c..662e87f2 100644 --- a/Passepartout/App/Views/PaywallView.swift +++ b/Passepartout/App/Views/PaywallView.swift @@ -31,9 +31,9 @@ struct PaywallView: View { @Binding private var isPresented: Bool - private let feature: LocalProduct? + private let feature: LocalProduct - init(modalType: Binding, feature: LocalProduct? = nil) { + init(modalType: Binding, feature: LocalProduct) { let isPresented = Binding { modalType.wrappedValue != nil } set: { @@ -44,7 +44,7 @@ struct PaywallView: View { self.init(isPresented: isPresented, feature: feature) } - init(isPresented: Binding, feature: LocalProduct? = nil) { + init(isPresented: Binding, feature: LocalProduct) { productManager = .shared _isPresented = isPresented self.feature = feature diff --git a/PassepartoutLibrary/Sources/PassepartoutFrontend/Managers/ProductManager.swift b/PassepartoutLibrary/Sources/PassepartoutFrontend/Managers/ProductManager.swift index c660730c..cc23577c 100644 --- a/PassepartoutLibrary/Sources/PassepartoutFrontend/Managers/ProductManager.swift +++ b/PassepartoutLibrary/Sources/PassepartoutFrontend/Managers/ProductManager.swift @@ -301,32 +301,35 @@ extension ProductManager { // purchased platform -> may only purchase other platform public func purchasableProducts(withFeature feature: LocalProduct?) -> [LocalProduct] { - var products: [LocalProduct] = { - if hasPurchased(.fullVersion) { + + // separate purchase + guard feature != .appleTV else { + if hasPurchased(.appleTV) { return [] } -#if targetEnvironment(macCatalyst) - if hasPurchased(.fullVersion_macOS) { - return [] - } - if hasPurchased(.fullVersion_iOS) { - return [.fullVersion_macOS] - } - return [.fullVersion, .fullVersion_macOS] -#else - if hasPurchased(.fullVersion_iOS) { - return [] - } - if hasPurchased(.fullVersion_macOS) { - return [.fullVersion_iOS] - } - return [.fullVersion, .fullVersion_iOS] -#endif - }() - if feature == .appleTV && !hasPurchased(.appleTV) { - products.append(.appleTV) + return [.appleTV] } - return products + + if hasPurchased(.fullVersion) { + return [] + } +#if targetEnvironment(macCatalyst) + if hasPurchased(.fullVersion_macOS) { + return [] + } + if hasPurchased(.fullVersion_iOS) { + return [.fullVersion_macOS] + } + return [.fullVersion, .fullVersion_macOS] +#else + if hasPurchased(.fullVersion_iOS) { + return [] + } + if hasPurchased(.fullVersion_macOS) { + return [.fullVersion_iOS] + } + return [.fullVersion, .fullVersion_iOS] +#endif } } diff --git a/PassepartoutLibrary/Tests/PassepartoutFrontendTests/ProductManagerTests.swift b/PassepartoutLibrary/Tests/PassepartoutFrontendTests/ProductManagerTests.swift index ecd5413e..4081b5eb 100644 --- a/PassepartoutLibrary/Tests/PassepartoutFrontendTests/ProductManagerTests.swift +++ b/PassepartoutLibrary/Tests/PassepartoutFrontendTests/ProductManagerTests.swift @@ -223,7 +223,7 @@ final class ProductManagerTests: XCTestCase { reader.setReceipt(withBuild: 1500, products: []) let sut = ProductManager(inApp: inApp, receiptReader: reader, buildProducts: noBuildProducts) - XCTAssertTrue(sut.purchasableProducts(withFeature: .appleTV).contains(.appleTV)) + XCTAssertEqual(sut.purchasableProducts(withFeature: .appleTV), [.appleTV]) } func test_givenAppleTV_whenDidPurchase_thenCannotPurchase() { @@ -231,6 +231,6 @@ final class ProductManagerTests: XCTestCase { reader.setReceipt(withBuild: 1500, products: [.appleTV]) let sut = ProductManager(inApp: inApp, receiptReader: reader, buildProducts: noBuildProducts) - XCTAssertFalse(sut.purchasableProducts(withFeature: .appleTV).contains(.appleTV)) + XCTAssertEqual(sut.purchasableProducts(withFeature: .appleTV), []) } }