Fixes in the subscription process

main
Laurent 3 years ago
parent 51057f3fcb
commit 74b1092680
  1. 12
      LeCountdown/Subscription/AppGuard.swift
  2. 1
      LeCountdown/Subscription/Store.swift
  3. 49
      LeCountdown/Subscription/StoreView.swift
  4. 2
      LeCountdown/Views/ContentView.swift
  5. 2
      LeCountdown/Views/PresetsView.swift
  6. 1
      LeCountdown/fr.lproj/Localizable.strings

@ -36,7 +36,7 @@ extension Notification.Name {
@Published private(set) var purchasedTransactions = Set<StoreKit.Transaction>()
var currentBestPlan: StoreKit.Transaction? = nil
@Published var currentBestPlan: StoreKit.Transaction? = nil
var updateListenerTask: Task<Void, Error>? = nil
@ -124,20 +124,20 @@ extension Notification.Name {
}
var isSubscriber: Bool {
return false // self.currentPlan != .none
return self.currentPlan != .none
}
var currentPlan: StorePlan {
#if DEBUG
return .yearly
#else
// #if DEBUG
// return .yearly
// #else
if let currentBestPlan = self.currentBestPlan,
let plan = StorePlan(rawValue: currentBestPlan.productID) {
return plan
}
return .none
#endif
// #endif
}
fileprivate func _updateBestPlan() {

@ -87,6 +87,7 @@ class Store: ObservableObject {
await transaction.finish()
DispatchQueue.main.asyncAfter(deadline: DispatchTime(uptimeNanoseconds: 200000), execute: {
Conductor.maestro.playSound(Sound.EX_ATSM_140_Koshi_Chimes_Aria_Tuning_Loop_Wondering_Am)
NotificationCenter.default.post(name: Notification.Name.StoreEventHappened, object: nil)
})

@ -29,15 +29,17 @@ fileprivate enum Feature: Int, Identifiable, CaseIterable {
struct StoreView: View, StoreDelegate {
@StateObject var store: Store = Store()
@StateObject private var store: Store = Store()
@State var errorMessage: String? = nil
@State private var errorMessage: String? = nil
@Binding var isPresented: Bool
var body: some View {
Group {
if !self.store.products.isEmpty {
PlanView()
PlanView(isPresented: self.$isPresented)
.environmentObject(self.store)
} else {
ProgressView()
@ -69,9 +71,11 @@ struct PlanView: View {
@EnvironmentObject var store: Store
// var productName: String
// var price: String
@State var _loadingProduct: String? = nil
@State var _purchased: Bool = false
@Binding var isPresented: Bool
var body: some View {
VStack {
@ -107,17 +111,26 @@ struct PlanView: View {
} label: {
HStack {
Spacer()
VStack {
if let plan = StorePlan(rawValue: product.id) {
Text("\(product.displayPrice) / \(plan.formattedPeriod)").font(.title3)
if product.id == self._loadingProduct {
if self._purchased {
Image(systemName: "checkmark.circle.fill")
} else {
Text("Plan not found")
ProgressView()
.progressViewStyle(.circular).tint(.white)
}
} else {
VStack {
if let plan = StorePlan(rawValue: product.id) {
Text("\(product.displayPrice) / \(plan.formattedPeriod)").font(.title3)
} else {
Text("Plan not found")
}
}
}
Spacer()
}
}.frame(height: 44.0)
}
.buttonStyle(.borderedProminent)
.fontWeight(.medium)
@ -128,7 +141,15 @@ struct PlanView: View {
fileprivate func _purchase(product: Product) {
Task {
try await store.purchase(product)
self._loadingProduct = product.id
let result = try await store.purchase(product)
switch result {
case .none:
self._loadingProduct = nil
case .some:
self._purchased = true
self.isPresented = false
}
}
}
@ -192,6 +213,6 @@ struct PlayerWrapperView: View {
struct StoreView_Previews: PreviewProvider {
static var previews: some View {
PlanView().environmentObject(Store())
PlanView(isPresented: .constant(false)).environmentObject(Store())
}
}

@ -114,7 +114,7 @@ struct ContentView<T : AbstractTimer>: View {
.presentationDetents([.height(240.0)])
})
.sheet(isPresented: self.$showSubscriptionSheet, content: {
StoreView()
StoreView(isPresented: self.$showSubscriptionSheet)
})
.toolbar {
ToolbarItem(placement: .navigationBarLeading) {

@ -113,7 +113,7 @@ struct PresetsView: View {
.environment(\.managedObjectContext, viewContext)
})
.sheet(isPresented: $isShowingSubscription, content: {
StoreView()
StoreView(isPresented: self.$isShowingSubscription)
})
.navigationTitle("Create")
}

@ -257,3 +257,4 @@
"Confirmation" = "Confirmation";
"month" = "mois";
"year" = "an";
"Get fully enchanted" = "Enchantement permanent";

Loading…
Cancel
Save