From 3b8c2209b4f914e0f83e49adf8aec7e404e40c9c Mon Sep 17 00:00:00 2001 From: Laurent Date: Wed, 1 May 2024 18:04:02 +0200 Subject: [PATCH] WIP for subscriptions --- PadelClub/Data/Tournament.swift | 1 + PadelClub/Views/Match/MatchDetailView.swift | 8 ++++++-- PadelClub/Views/Subscription/Guard.swift | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/PadelClub/Data/Tournament.swift b/PadelClub/Data/Tournament.swift index 89dd04e..08d535a 100644 --- a/PadelClub/Data/Tournament.swift +++ b/PadelClub/Data/Tournament.swift @@ -1228,6 +1228,7 @@ class Tournament : ModelObject, Storable { if self.currentPayment != nil { return } if let payment = Guard.main.paymentForNewTournament() { self.setPayment(payment) + try DataStore.shared.tournaments.addOrUpdate(instance: self) return } throw PaymentError.cantPayTournament diff --git a/PadelClub/Views/Match/MatchDetailView.swift b/PadelClub/Views/Match/MatchDetailView.swift index 5a5340a..a392a05 100644 --- a/PadelClub/Views/Match/MatchDetailView.swift +++ b/PadelClub/Views/Match/MatchDetailView.swift @@ -139,8 +139,12 @@ struct MatchDetailView: View { Section { RowButtonView("Saisir les résultats", systemImage: "list.clipboard") { do { -// try self.tournament.payIfNecessary() - scoreType = .edition + if let tournament = self.match.currentTournament() { + try tournament.payIfNecessary() + scoreType = .edition + } else { + self.showSubscriptionView = true + } } catch { self.showSubscriptionView = true } diff --git a/PadelClub/Views/Subscription/Guard.swift b/PadelClub/Views/Subscription/Guard.swift index 5f76d42..b838727 100644 --- a/PadelClub/Views/Subscription/Guard.swift +++ b/PadelClub/Views/Subscription/Guard.swift @@ -125,7 +125,7 @@ import LeStorage var currentPlan: StoreItem? { #if DEBUG - return .monthlyUnlimited + return nil #else if let currentBestPlan = self.currentBestPlan, let plan = StorePlan(rawValue: currentBestPlan.productID) { return plan