1
This commit is contained in:
@@ -52,7 +52,7 @@ final class KBStoreKitBridge: NSObject, StoreKitDelegate {
|
||||
do {
|
||||
try await self.manager.purchase(productId: productId)
|
||||
|
||||
if let payload = await Self.latestJWSPayload(for: productId) {
|
||||
if let payload = await self.fetchPayload(for: productId) {
|
||||
self.verifySignedPayload(payload, completion: completion)
|
||||
} else {
|
||||
await MainActor.run {
|
||||
@@ -115,10 +115,24 @@ final class KBStoreKitBridge: NSObject, StoreKitDelegate {
|
||||
}
|
||||
}
|
||||
|
||||
private static func latestJWSPayload(for productId: String) async -> String? {
|
||||
guard let result = await Transaction.latest(for: productId) else { return nil }
|
||||
if case .verified = result {
|
||||
return result.jwsRepresentation
|
||||
@MainActor
|
||||
private func fetchPayload(for productId: String) async -> String? {
|
||||
if let payload = manager.consumeRecentPayload(for: productId) {
|
||||
return payload
|
||||
}
|
||||
return await Self.latestJWSPayload(for: productId, retryCount: 3)
|
||||
}
|
||||
|
||||
private static func latestJWSPayload(for productId: String, retryCount: Int = 1) async -> String? {
|
||||
var attempts = 0
|
||||
while attempts < retryCount {
|
||||
if let result = await Transaction.latest(for: productId), case .verified = result {
|
||||
return result.jwsRepresentation
|
||||
}
|
||||
attempts += 1
|
||||
if attempts < retryCount {
|
||||
try? await Task.sleep(nanoseconds: 300_000_000) // 0.3s
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user