StoreObserver.swift (845B)
1 // 2 // StoreObserver.swift 3 // damus 4 // 5 // Created by Daniel D’Aquino on 2023-12-08. 6 // 7 8 import Foundation 9 import StoreKit 10 11 class StoreObserver: NSObject, SKPaymentTransactionObserver { 12 static let standard = StoreObserver() 13 14 var delegate: StoreObserverDelegate? 15 16 init(delegate: StoreObserverDelegate? = nil) { 17 self.delegate = delegate 18 super.init() 19 } 20 21 //Observe transaction updates. 22 func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) { 23 //Handle transaction states here. 24 Log.info("StoreObserver received a transaction update. Notifying to delegate.", for: .damus_purple) 25 26 Task { 27 try await self.delegate?.send_receipt() 28 } 29 } 30 } 31 32 protocol StoreObserverDelegate { 33 func send_receipt() async throws 34 }