diff --git a/Swiftgram/SGPayWall/Sources/SGPayWall.swift b/Swiftgram/SGPayWall/Sources/SGPayWall.swift index 10ba8506a4..39f0ed9eb7 100644 --- a/Swiftgram/SGPayWall/Sources/SGPayWall.swift +++ b/Swiftgram/SGPayWall/Sources/SGPayWall.swift @@ -13,7 +13,7 @@ import TelegramUIPreferences @available(iOS 13.0, *) -public func sgPayWallController(statusSignal: Signal, replacementController: ViewController, presentationData: PresentationData? = nil, SGIAPManager: SGIAPManager, openUrl: @escaping (String) -> Void, paymentsEnabled: Bool) -> ViewController { +public func sgPayWallController(statusSignal: Signal, replacementController: ViewController, presentationData: PresentationData? = nil, SGIAPManager: SGIAPManager, openUrl: @escaping (String) -> Void, paymentsEnabled: Bool, canBuyInBeta: Bool, openAppStorePage: @escaping () -> Void) -> ViewController { // let theme = presentationData?.theme ?? (UITraitCollection.current.userInterfaceStyle == .dark ? defaultDarkColorPresentationTheme : defaultPresentationTheme) let theme = defaultDarkColorPresentationTheme let strings = presentationData?.strings ?? defaultPresentationStrings @@ -30,7 +30,7 @@ public func sgPayWallController(statusSignal: Signal, replacemen let swiftUIView = SGSwiftUIView( legacyController: legacyController, content: { - SGPayWallView(wrapperController: legacyController, replacementController: replacementController, SGIAP: SGIAPManager, statusSignal: statusSignal, openUrl: openUrl, paymentsEnabled: paymentsEnabled) + SGPayWallView(wrapperController: legacyController, replacementController: replacementController, SGIAP: SGIAPManager, statusSignal: statusSignal, openUrl: openUrl, openAppStorePage: openAppStorePage, paymentsEnabled: paymentsEnabled, canBuyInBeta: canBuyInBeta) } ) let controller = UIHostingController(rootView: swiftUIView, ignoreSafeArea: true) @@ -106,7 +106,9 @@ struct SGPayWallView: View { let SGIAP: SGIAPManager let statusSignal: Signal let openUrl: (String) -> Void + let openAppStorePage: () -> Void let paymentsEnabled: Bool + let canBuyInBeta: Bool private enum PayWallState: Equatable { case ready // ready to buy @@ -405,6 +407,8 @@ struct SGPayWallView: View { } else if let product = product { if !SGIAP.canMakePayments || paymentsEnabled == false { return "PayWall.Button.PaymentsUnavailable".i18n(lang) + } else if Bundle.main.appStoreReceiptURL?.lastPathComponent == "sandboxReceipt" && !canBuyInBeta { + return "PayWall.Button.BuyInAppStore".i18n(lang) } else { return "PayWall.Button.Subscribe".i18n(lang, args: product.price) } @@ -430,9 +434,13 @@ struct SGPayWallView: View { if currentStatus > 1 { wrapperController?.replace(with: replacementController) } else { - guard let product = product else { return } - state = .purchasing - SGIAP.buyProduct(product.skProduct) + if Bundle.main.appStoreReceiptURL?.lastPathComponent == "sandboxReceipt" && !canBuyInBeta { + openAppStorePage() + } else { + guard let product = product else { return } + state = .purchasing + SGIAP.buyProduct(product.skProduct) + } } } diff --git a/Swiftgram/SGStrings/Strings/en.lproj/SGLocalizable.strings b/Swiftgram/SGStrings/Strings/en.lproj/SGLocalizable.strings index 71b6667691..15f39e7a8d 100644 --- a/Swiftgram/SGStrings/Strings/en.lproj/SGLocalizable.strings +++ b/Swiftgram/SGStrings/Strings/en.lproj/SGLocalizable.strings @@ -227,6 +227,7 @@ "PayWall.Button.Restoring" = "Restoring Purchases..."; "PayWall.Button.Validating" = "Validating Purchase..."; "PayWall.Button.PaymentsUnavailable" = "Payments unavailable"; +"PayWall.Button.BuyInAppStore" = "Subscribe in App Store version"; "PayWall.Button.Subscribe" = "Subscribe for %@ / month"; "PayWall.Button.ContactingAppStore" = "Contacting App Store..."; diff --git a/Swiftgram/SGStrings/Strings/ru.lproj/SGLocalizable.strings b/Swiftgram/SGStrings/Strings/ru.lproj/SGLocalizable.strings index 8cbbf41ba4..41542f6436 100644 --- a/Swiftgram/SGStrings/Strings/ru.lproj/SGLocalizable.strings +++ b/Swiftgram/SGStrings/Strings/ru.lproj/SGLocalizable.strings @@ -194,10 +194,10 @@ "PayWall.Text" = "Заряжен Pro функциями"; "PayWall.SessionBackup.Title" = "Бэкап Аккаунтов"; -"PayWall.SessionBackup.Notice" = "Вход в аккаунты без кодов, даже после переустановки. Безопасное хранение в Keychain на устройстве."; +"PayWall.SessionBackup.Notice" = "Вход в аккаунты без кода, даже после переустановки. Безопасное хранение в Keychain на устройстве."; "PayWall.MessageFilter.Title" = "Фильтр сообщений"; -"PayWall.MessageFilter.Notice" = "Уменьшает видимость надоедливых сообщений со СПАМом или рекламой"; +"PayWall.MessageFilter.Notice" = "Уменьшает видимость надоедливых сообщений со СПАМом или рекламой."; "PayWall.Notifications.Title" = "Отключение @тэгов и ответов"; "PayWall.Notifications.Notice" = "Скрывает или приглушает неважные уведомления."; @@ -227,6 +227,7 @@ "PayWall.Button.Restoring" = "Восстановление покупок..."; "PayWall.Button.Validating" = "Проверка покупки..."; "PayWall.Button.PaymentsUnavailable" = "Платежи недоступны"; +"PayWall.Button.BuyInAppStore" = "Подписаться в App Store версии"; "PayWall.Button.Subscribe" = "Подписаться за %@ / месяц"; "PayWall.Button.ContactingAppStore" = "Подключение к App Store..."; diff --git a/Swiftgram/SGWebSettingsScheme/Sources/File.swift b/Swiftgram/SGWebSettingsScheme/Sources/File.swift index 5f61cf945c..f0bcd7fb0f 100644 --- a/Swiftgram/SGWebSettingsScheme/Sources/File.swift +++ b/Swiftgram/SGWebSettingsScheme/Sources/File.swift @@ -5,7 +5,7 @@ public struct SGWebSettings: Codable, Equatable { public let user: SGUserSettings public static var defaultValue: SGWebSettings { - return SGWebSettings(global: SGGlobalSettings(ytPip: true, qrLogin: true, storiesAvailable: false, canViewMessages: true, canEditSettings: false, canShowTelescope: false, announcementsData: nil, regdateFormat: "full", botMonkeys: [], forceReasons: [], unforceReasons: [], paymentsEnabled: true, duckyAppIconAvailable: true, canGrant: false), user: SGUserSettings(contentReasons: [], canSendTelescope: false)) + return SGWebSettings(global: SGGlobalSettings(ytPip: true, qrLogin: true, storiesAvailable: false, canViewMessages: true, canEditSettings: false, canShowTelescope: false, announcementsData: nil, regdateFormat: "full", botMonkeys: [], forceReasons: [], unforceReasons: [], paymentsEnabled: true, duckyAppIconAvailable: true, canGrant: false), user: SGUserSettings(contentReasons: [], canSendTelescope: false, canBuyInBeta: true)) } } @@ -37,6 +37,7 @@ public struct SGBotMonkeys: Codable, Equatable { public struct SGUserSettings: Codable, Equatable { public let contentReasons: [String] public let canSendTelescope: Bool + public let canBuyInBeta: Bool } diff --git a/submodules/TelegramUI/Sources/SharedAccountContext.swift b/submodules/TelegramUI/Sources/SharedAccountContext.swift index 7c6fd1f117..8378530671 100644 --- a/submodules/TelegramUI/Sources/SharedAccountContext.swift +++ b/submodules/TelegramUI/Sources/SharedAccountContext.swift @@ -3624,7 +3624,8 @@ extension SharedAccountContextImpl { } let proController = self.makeSGProController(context: context) - let payWallController = sgPayWallController(statusSignal: statusSignal, replacementController: proController, presentationData: self.currentPresentationData.with { $0 }, SGIAPManager: sgIAP, openUrl: self.applicationBindings.openUrl, paymentsEnabled: context.currentAppConfiguration.with { $0 }.sgWebSettings.global.paymentsEnabled) + let sgWebSettings = context.currentAppConfiguration.with { $0 }.sgWebSettings + let payWallController = sgPayWallController(statusSignal: statusSignal, replacementController: proController, presentationData: self.currentPresentationData.with { $0 }, SGIAPManager: sgIAP, openUrl: self.applicationBindings.openUrl, paymentsEnabled: sgWebSettings.global.paymentsEnabled, canBuyInBeta: sgWebSettings.user.canBuyInBeta, openAppStorePage: self.applicationBindings.openAppStorePage) return payWallController }