@@ -11,26 +11,37 @@ import StoreKit
1111
1212#if canImport(PurchaseConnector)
1313import PurchaseConnector
14- @objc class TransactionFetcher : NSObject {
15- @objc static func fetchTransaction( withId transactionId: String , completion: @escaping ( AFSDKTransactionSK2 ? ) -> Void ) {
16- Task {
17- if #available( iOS 15 . 0 , * ) {
14+ @objc ( TransactionFetcher)
15+ class TransactionFetcher : NSObject , RCTBridgeModule {
16+ @objc func fetchTransaction( _ transactionId: String , callback: @escaping RCTResponseSenderBlock ) {
17+ if #available( iOS 15 . 0 , * ) {
18+ Task {
1819 do {
1920 let allTransactions = try await Transaction . all
20- if let matchingTransaction = allTransactions. first ( where: { $0. id == UInt64 ( transactionId) } ) {
21+ // Unwrap verified transactions
22+ let verifiedTransactions = allTransactions. compactMap { verificationResult -> Transaction ? in
23+ switch verificationResult {
24+ case . verified( let transaction) :
25+ return transaction
26+ case . unverified( _, _) :
27+ return nil
28+ }
29+ }
30+
31+ if let matchingTransaction = await verifiedTransactions. first ( where: { $0. id == UInt64 ( transactionId) } ) {
2132 let afTransaction = AFSDKTransactionSK2 ( transaction: matchingTransaction)
22- completion ( afTransaction)
33+ callback ( [ NSNull ( ) , afTransaction] )
2334 } else {
24- completion ( nil )
35+ callback ( [ NSNull ( ) , NSNull ( ) ] )
2536 }
2637 } catch {
2738 print ( " Error fetching transactions: \( error) " )
28- completion ( nil )
39+ callback ( [ error . localizedDescription , NSNull ( ) ] )
2940 }
30- } else {
31- print ( " StoreKit 2 is not available on this iOS version. " )
32- completion ( nil )
3341 }
42+ } else {
43+ print ( " StoreKit 2 is not available on this iOS version. " )
44+ callback ( [ " StoreKit 2 is not available on this iOS version. " , NSNull ( ) ] )
3445 }
3546 }
3647}
0 commit comments