I had the same issue. No matter how many times I called .finish() via Transaction.updates or Product.purchase I always received the same expired transaction instead of a current one.
I was able to work around it with the following:
extension Product {
public func buy(options: Set<PurchaseOption>) async throws -> Purchasable.PurchaseResult {
await Transaction.clearUnfinishedTransactionsPrePurchase()
let result: Product.PurchaseResult = try await self.purchase(options: options)
// Check result ...
}
}
extension Transaction {
/// Fixes a bug where unfinished but expired transactions block future purchases.
static func clearUnfinishedTransactionsPrePurchase() async {
for await unfinished in Transaction.unfinished {
let unsafe = unfinished.unsafePayloadValue
guard (unsafe.expirationDate ?? .now) < .now else { continue }
switch unfinished {
case let .unverified(t, _): await t.finish()
case let .verified(t): await t.finish()
}
}
}
}
Topic:
App & System Services
SubTopic:
StoreKit
Tags: