Fixes payment when summoning

multistore
Laurent 1 year ago
parent bc75a1e9ea
commit c733a0f386
  1. 44
      PadelClub/Views/Calling/CallView.swift
  2. 24
      PadelClub/Views/Calling/SendToAllView.swift
  3. 4
      PadelClub/Views/Match/MatchDetailView.swift
  4. 2
      PadelClub/Views/Subscription/Guard.swift
  5. 62
      PadelClub/Views/Subscription/SubscriptionView.swift
  6. 6
      PadelClub/Views/User/UserCreationView.swift

@ -59,7 +59,7 @@ struct CallView: View {
@State private var contactType: ContactType? = nil
@State private var sentError: ContactManagerError? = nil
@State var cannotPayForTournament: Bool = false
@State var showSubscriptionView: Bool = false
var messageSentFailed: Binding<Bool> {
Binding {
@ -101,22 +101,23 @@ struct CallView: View {
Text(callWord + " ces \(teams.count) paires par")
}
Button {
contactType = .message(date: callDate, recipients: teams.flatMap { $0.getPhoneNumbers() }, body: finalMessage, tournamentBuild: nil)
self._payTournamentAndExecute {
self._contactByMessage()
}
} label: {
Text("sms")
.underline()
}
Text("ou")
Button {
contactType = .mail(date: callDate, recipients: tournament.umpireMail(), bccRecipients: teams.flatMap { $0.getMail() }, body: finalMessage, subject: tournament.tournamentTitle(), tournamentBuild: nil)
self._payTournamentAndExecute {
self._contactByMail()
}
} label: {
Text("mail")
.underline()
}
}
.onAppear {
self.cannotPayForTournament = Guard.main.paymentForNewTournament() == nil
}
.font(.subheadline)
.buttonStyle(.borderless)
.alert("Un problème est survenu", isPresented: messageSentFailed) {
@ -130,7 +131,6 @@ struct CallView: View {
Group {
switch contactType {
case .message(_, let recipients, let body, _):
if !self.cannotPayForTournament {
MessageComposeView(recipients: recipients, body: body) { result in
switch result {
case .cancelled:
@ -147,11 +147,7 @@ struct CallView: View {
break
}
}
} else {
SubscriptionView(isPresented: self.$cannotPayForTournament, showLackOfPlanMessage: true)
}
case .mail(_, let recipients, let bccRecipients, let body, let subject, _):
if !self.cannotPayForTournament {
MailComposeView(recipients: recipients, bccRecipients: bccRecipients, body: body, subject: subject) { result in
switch result {
case .cancelled, .saved:
@ -170,12 +166,32 @@ struct CallView: View {
break
}
}
} else {
SubscriptionView(isPresented: self.$cannotPayForTournament, showLackOfPlanMessage: true)
}
}
}
.tint(.master)
}
.sheet(isPresented: self.$showSubscriptionView, content: {
NavigationStack {
SubscriptionView(isPresented: self.$showSubscriptionView, showLackOfPlanMessage: true)
}
})
}
fileprivate func _payTournamentAndExecute(_ handler: () -> ()) {
do {
try tournament.payIfNecessary()
handler()
} catch {
self.showSubscriptionView = true
}
}
fileprivate func _contactByMessage() {
contactType = .message(date: callDate, recipients: teams.flatMap { $0.getPhoneNumbers() }, body: finalMessage, tournamentBuild: nil)
}
fileprivate func _contactByMail() {
contactType = .mail(date: callDate, recipients: tournament.umpireMail(), bccRecipients: teams.flatMap { $0.getMail() }, body: finalMessage, subject: tournament.tournamentTitle(), tournamentBuild: nil)
}
}

@ -71,11 +71,7 @@ struct SendToAllView: View {
Section {
RowButtonView("Contacter \(_totalString())") {
if contactMethod == 0 {
contactType = .message(date: nil, recipients: _teams().flatMap { $0.unsortedPlayers() }.compactMap { $0.phoneNumber }, body: addLink ? tournament.shareURL()?.absoluteString : nil, tournamentBuild: nil)
} else {
contactType = .mail(date: nil, recipients: tournament.umpireMail(), bccRecipients: _teams().flatMap { $0.unsortedPlayers() }.compactMap { $0.email }, body: addLink ? tournament.shareURL()?.absoluteString : nil, subject: tournament.tournamentTitle(), tournamentBuild: nil)
}
self._contactAndPay()
}
}
}
@ -166,6 +162,24 @@ struct SendToAllView: View {
return teams.count.formatted() + " équipe" + teams.count.pluralSuffix
}
}
fileprivate func _contactAndPay() {
do {
try tournament.payIfNecessary()
self._contact()
} catch {
self.cannotPayForTournament = true
}
}
fileprivate func _contact() {
if contactMethod == 0 {
contactType = .message(date: nil, recipients: _teams().flatMap { $0.unsortedPlayers() }.compactMap { $0.phoneNumber }, body: addLink ? tournament.shareURL()?.absoluteString : nil, tournamentBuild: nil)
} else {
contactType = .mail(date: nil, recipients: tournament.umpireMail(), bccRecipients: _teams().flatMap { $0.unsortedPlayers() }.compactMap { $0.email }, body: addLink ? tournament.shareURL()?.absoluteString : nil, subject: tournament.tournamentTitle(), tournamentBuild: nil)
}
}
}
#Preview {

@ -254,8 +254,10 @@ struct MatchDetailView: View {
}
}
} else {
NavigationStack {
SubscriptionView(isPresented: self.$showSubscriptionView, showLackOfPlanMessage: true)
}
}
case .mail(_, let recipients, let bccRecipients, let body, let subject, _):
if Guard.main.paymentForNewTournament() != nil {
MailComposeView(recipients: recipients, bccRecipients: bccRecipients, body: body, subject: subject) { result in
@ -275,10 +277,12 @@ struct MatchDetailView: View {
}
}
} else {
NavigationStack {
SubscriptionView(isPresented: self.$showSubscriptionView, showLackOfPlanMessage: true)
}
}
}
}
.tint(.master)
}
.toolbar {

@ -163,7 +163,7 @@ import LeStorage
let userTransactions = self.purchasedTransactions.filter { currentUserUUID == $0.appAccountToken }
let now = Date()
let now: Date = Date()
// print("now = \(now)")
return userTransactions.filter { transaction in
if let expirationDate = transaction.expirationDate {

@ -52,6 +52,10 @@ class SubscriptionModel: ObservableObject, StoreDelegate {
@Published var products: [Product] = []
@Published var totalPrice: String = ""
init() {
Logger.log("SubscriptionModel init ")
}
func load() {
self.isLoading = true
if self.storeManager == nil {
@ -116,9 +120,17 @@ struct SubscriptionView: View {
@State var isPurchasing: Bool = false
@State var showSuccessfulPurchaseView: Bool = false
init(isPresented: Binding<Bool>, showLackOfPlanMessage: Bool = false) {
self._isPresented = isPresented
self.showLackOfPlanMessage = showLackOfPlanMessage
Logger.log(">>> SubscriptionView init")
}
var body: some View {
Group {
VStack {
if self.showLoginView {
LoginView { _ in
self.showLoginView = false
@ -126,17 +138,14 @@ struct SubscriptionView: View {
}
} else {
List {
if self.showLackOfPlanMessage {
HStack {
Image(systemName: "exclamationmark.bubble.fill").foregroundStyle(Color.accentColor)
.font(.title)
Text("Vous ne disposez malheureusement plus d'offre pour continuer votre tournoi. Voici ce que nous proposons:")
.fontWeight(.semibold)
}
SubscriptionDetailView()
.clipShape(.rect(cornerRadius: 16.0))
.padding()
}
List {
if self.model.products.count > 0 {
Section {
@ -198,6 +207,20 @@ struct SubscriptionView: View {
}
}
} else {
if self.model.isLoading {
ProgressView()
} else {
HStack {
if let plan = Guard.main.currentPlan {
Image(systemName: plan.systemImage)
} else {
Image(systemName: "questionmark.diamond.fill")
}
Text("Il n'y a pas de produits à vous proposer")
}
}
}
}
.listStyle(.grouped)
@ -344,6 +367,27 @@ struct SubscriptionFooterView: View {
}
}
struct SubscriptionDetailView: View {
var body: some View {
HStack {
Image(systemName: "exclamationmark.bubble.fill")
//.foregroundStyle(Color.accentColor)
.font(.title)
Text("Vous ne disposez malheureusement plus d'offre pour continuer votre tournoi. Voici ce que nous proposons:")
.fontWeight(.semibold)
}
.padding()
.background(.orange)
.foregroundStyle(.black)
}
}
#Preview {
SubscriptionDetailView()
}
#Preview {
NavigationStack {
SubscriptionView(isPresented: .constant(true), showLackOfPlanMessage: false)

@ -25,6 +25,7 @@ struct UserCreationFormView: View {
@State var alertMessage: String = "" {
didSet {
self.showAlertView = true
self.isLoading = false
}
}
@ -97,7 +98,6 @@ struct UserCreationFormView: View {
} )
}
fileprivate func _selectCountry() {
guard let regionCode = Locale.current.region?.identifier, let country = Locale.current.localizedString(forRegionCode: regionCode) else {
return
@ -108,6 +108,8 @@ struct UserCreationFormView: View {
fileprivate func _create() {
self.isLoading = true
guard self.password1 == self.password2 else {
self.alertMessage = "Les mots de passe ne correspondent pas"
return
@ -133,8 +135,6 @@ struct UserCreationFormView: View {
return
}
self.isLoading = true
Task {
do {
let userCreationForm = UserCreationForm(

Loading…
Cancel
Save