|
|
|
|
@ -124,12 +124,9 @@ import Combine |
|
|
|
|
if transaction.revocationDate == nil { |
|
|
|
|
// If the App Store has not revoked the transaction, add it to the list of `purchasedIdentifiers`. |
|
|
|
|
purchasedTransactions.insert(transaction) |
|
|
|
|
|
|
|
|
|
// try self._addPurchaseIfPossible(transaction: transaction) |
|
|
|
|
} else { |
|
|
|
|
// If the App Store has revoked this transaction, remove it from the list of `purchasedIdentifiers`. |
|
|
|
|
purchasedTransactions.remove(transaction) |
|
|
|
|
// try self._updatePurchaseIfPossible(transaction: transaction) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
try self._updatePurchase(transaction: transaction) |
|
|
|
|
@ -155,24 +152,6 @@ import Combine |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// fileprivate func _addPurchaseIfPossible(transaction: StoreKit.Transaction) throws { |
|
|
|
|
// |
|
|
|
|
// let purchases = DataStore.shared.purchases |
|
|
|
|
// |
|
|
|
|
// if self._purchaseByTransactionId(transaction.originalID) == nil { |
|
|
|
|
// let purchase: Purchase = try transaction.purchase() |
|
|
|
|
// try purchases.addOrUpdate(instance: purchase) |
|
|
|
|
// } |
|
|
|
|
// } |
|
|
|
|
// |
|
|
|
|
// fileprivate func _updatePurchaseIfPossible(transaction: StoreKit.Transaction) throws { |
|
|
|
|
// let purchases = DataStore.shared.purchases |
|
|
|
|
// if let existing: Purchase = self._purchaseByTransactionId(transaction.originalID) { |
|
|
|
|
// existing.revocationDate = transaction.revocationDate |
|
|
|
|
// try purchases.addOrUpdate(instance: existing) |
|
|
|
|
// } |
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
fileprivate func _purchaseByTransactionId(_ transactionId: UInt64) -> Purchase? { |
|
|
|
|
let purchases = DataStore.shared.purchases |
|
|
|
|
return purchases.first(where: { $0.id == transactionId }) |
|
|
|
|
@ -212,11 +191,11 @@ import Combine |
|
|
|
|
|
|
|
|
|
public func userFilteredPurchases() -> [StoreKit.Transaction] { |
|
|
|
|
// Logger.log("self.purchasedTransactions = \(self.purchasedTransactions.count)") |
|
|
|
|
guard let userId = StoreCenter.main.userId, let currentUserUUID: UUID = UUID(uuidString: userId) else { |
|
|
|
|
guard let userId = StoreCenter.main.userId else { |
|
|
|
|
return [] |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
let userTransactions = self.purchasedTransactions.filter { currentUserUUID == $0.appAccountToken || $0.appAccountToken == nil } |
|
|
|
|
let userTransactions = self.purchasedTransactions.filter { userId == $0.appAccountToken?.uuidString || $0.appAccountToken == nil } |
|
|
|
|
|
|
|
|
|
let now: Date = Date() |
|
|
|
|
// print("now = \(now)") |
|
|
|
|
@ -334,6 +313,7 @@ public struct PurchaseRow: Identifiable { |
|
|
|
|
fileprivate extension StoreKit.Transaction { |
|
|
|
|
|
|
|
|
|
func purchase() throws -> Purchase { |
|
|
|
|
|
|
|
|
|
guard let userId = StoreCenter.main.userId else { |
|
|
|
|
throw StoreError.missingUserId |
|
|
|
|
} |
|
|
|
|
|