Fall back sandbox receipt to release receipt (#337)

Could be a way to enable paid features in TestFlight builds for those
who originally bought them from the App Store.
This commit is contained in:
Davide De Rosa 2023-07-24 23:32:05 +02:00 committed by GitHub
parent 65d6e30469
commit bae843363c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 35 additions and 17 deletions

View File

@ -222,11 +222,7 @@ final class ProductManager: NSObject, ObservableObject {
} }
func reloadReceipt(andNotify: Bool = true) { func reloadReceipt(andNotify: Bool = true) {
guard let url = Bundle.main.appStoreReceiptURL else { guard let receipt else {
pp_log.warning("No App Store receipt found!")
return
}
guard let receipt = Receipt(contentsOfURL: url) else {
pp_log.error("Could not parse App Store receipt!") pp_log.error("Could not parse App Store receipt!")
return return
} }
@ -281,8 +277,40 @@ extension ProductManager: SKPaymentTransactionObserver {
} }
} }
extension ProductManager { private extension ProductManager {
private func detectRefunds(_ refunds: Set<LocalProduct>) { var isMac: Bool {
#if targetEnvironment(macCatalyst)
true
#else
false
#endif
}
var receipt: Receipt? {
guard let url = Bundle.main.appStoreReceiptURL else {
pp_log.warning("No App Store receipt found!")
return nil
}
let receipt = Receipt(contentsOfURL: url)
// in TestFlight, attempt fallback to existing release receipt
if Bundle.main.isTestFlight {
guard let receipt else {
let releaseUrl = url.deletingLastPathComponent().appendingPathComponent("receipt")
guard releaseUrl != url else {
assertionFailure("How can release URL be equal to sandbox URL in TestFlight?")
return nil
}
pp_log.warning("Sandbox receipt not found, falling back to Release receipt")
return Receipt(contentsOfURL: releaseUrl)
}
return receipt
}
return receipt
}
func detectRefunds(_ refunds: Set<LocalProduct>) {
let isEligibleForFullVersion = isFullVersion() let isEligibleForFullVersion = isFullVersion()
let hasCancelledFullVersion: Bool let hasCancelledFullVersion: Bool
let hasCancelledTrustedNetworks: Bool let hasCancelledTrustedNetworks: Bool
@ -305,13 +333,3 @@ extension ProductManager {
} }
} }
} }
extension ProductManager {
private var isMac: Bool {
#if targetEnvironment(macCatalyst)
true
#else
false
#endif
}
}