|
|
@@ -499,37 +499,22 @@ final class SubscriptionManager: ObservableObject {
|
|
|
}
|
|
|
|
|
|
/// Aligns local purchase flags with StoreKit history.
|
|
|
- /// - Purchases/refunds still on record → user has bought before; no free tier.
|
|
|
- /// - No transactions at all (sandbox delete) → treat as a new user with 3 free uses.
|
|
|
+ /// Purchase history is sticky: once a user has bought, they keep that status even if
|
|
|
+ /// StoreKit history is cleared (e.g. sandbox transaction delete).
|
|
|
private func syncPurchaseHistory() async {
|
|
|
- var hasRecordedPurchase = false
|
|
|
-
|
|
|
for await result in Transaction.all {
|
|
|
guard case .verified(let transaction) = result else { continue }
|
|
|
guard SubscriptionProductID.all.contains(transaction.productID) else { continue }
|
|
|
- hasRecordedPurchase = true
|
|
|
- break
|
|
|
- }
|
|
|
|
|
|
- if hasRecordedPurchase {
|
|
|
if !hasEverPurchasedPremium {
|
|
|
hasEverPurchasedPremium = true
|
|
|
UserDefaults.standard.set(true, forKey: Self.cachedHasEverPurchasedKey)
|
|
|
AIFreeUsageManager.shared.forfeitFreeUses()
|
|
|
}
|
|
|
- } else if hasEverPurchasedPremium {
|
|
|
- resetToNeverPurchasedState()
|
|
|
+ return
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private func resetToNeverPurchasedState() {
|
|
|
- hasEverPurchasedPremium = false
|
|
|
- UserDefaults.standard.set(false, forKey: Self.cachedHasEverPurchasedKey)
|
|
|
- UserDefaults.standard.removeObject(forKey: "SubscriptionManager.hadPremiumAccess")
|
|
|
- AIFreeUsageManager.shared.resetFreeUses()
|
|
|
- trialDisplayByPlan = [:]
|
|
|
- }
|
|
|
-
|
|
|
private func refreshTrialOffers() async {
|
|
|
guard isEligibleForIntroTrial else {
|
|
|
trialDisplayByPlan = [:]
|