Allow users to buy Bubble+

This commit is contained in:
lumaa-dev 2024-09-23 18:30:20 +02:00
parent f64d85204c
commit 049e6b9666
1 changed files with 92 additions and 45 deletions

View File

@ -6,13 +6,15 @@ import RevenueCat
public struct ShopView: View {
@Environment(AppDelegate.self) private var delegate: AppDelegate
@Environment(\.dismiss) private var dismiss
@Environment(\.openURL) private var openURL: OpenURLAction
@Environment(\.dismiss) private var dismiss: DismissAction
@State private var showSub: Bool = false
@State private var purchaseError: Bool = false
@State private var hasSub: Bool = false
private var canPay: Bool {
#if targetEnvironment(simulator)
#if targetEnvironment(simulator) || !DEBUG
return true
#else
return false
@ -38,6 +40,7 @@ public struct ShopView: View {
Spacer()
if !self.hasSub {
VStack(spacing: 20) {
Button {
showSub.toggle()
@ -76,6 +79,49 @@ public struct ShopView: View {
.padding(.top, 50)
}
.padding(.vertical)
} else {
VStack {
Button {
Task {
#if !targetEnvironment(simulator)
if let windowScene = self.delegate.window?.windowScene {
print("accessing subs natively")
try? await AppStore.showManageSubscriptions(in: windowScene)
} else {
print("accessing subs via deeplink")
openURL(URL(string: "itms-apps://apps.apple.com/account/subscriptions")!)
}
#else
print("ACCESS SUBS but Simulator can't")
#endif
}
} label: {
VStack {
Text("shop.bubble-plus.owning")
.font(.title2.bold())
.foregroundStyle(Color(uiColor: UIColor.label))
Text("shop.bubble-plus.manage")
.font(.callout)
.foregroundStyle(Color.blue)
}
.padding(.vertical)
}
Button {
dismiss()
} label: {
Text("shop.bubble-plus.dismiss")
}
.buttonStyle(.borderless)
.padding(.top, 50)
}
}
}
.task {
AppDelegate.hasPlus { subscribed in
self.hasSub = subscribed
}
}
.frame(width: delegate.windowWidth)
.background(Color.appBackground)
@ -99,7 +145,7 @@ public struct ShopView: View {
feature(.drafts)
feature(.analytics)
// feature(.analytics)
feature(.contentFilter)
@ -392,6 +438,7 @@ extension ShopView {
// .environment(\.locale, Locale(identifier: "en-us"))
}
// MARK: - Entitlements
enum PlusEntitlements: String {
case monthly
case yearly