@@ -290,43 +290,59 @@ public final class OpenIapModule: NSObject, OpenIapModuleProtocol {
290290 public func finishTransaction( purchase: PurchaseInput , isConsumable: Bool ? ) async throws -> Void {
291291 let identifier = purchase. id
292292
293+ OpenIapLog . debug ( " 🔄 finishTransaction called with id: \( identifier) " )
294+
295+ // First check pending transactions (most common case)
293296 if let pending = await state. getPending ( id: identifier) {
297+ OpenIapLog . debug ( " ✅ Found pending transaction, finishing... " )
294298 await pending. finish ( )
295299 await state. removePending ( id: identifier)
300+ OpenIapLog . debug ( " ✅ Transaction finished successfully " )
296301 return
297302 }
298303
304+ OpenIapLog . debug ( " ⚠️ Transaction not in pending state, searching in StoreKit... " )
305+
306+ // Try to parse as numeric ID for StoreKit lookup
299307 guard let numericId = UInt64 ( identifier) else {
300- let error = makePurchaseError ( code: . purchaseError, message: " Invalid transaction identifier " )
308+ let error = makePurchaseError ( code: . purchaseError, message: " Invalid transaction identifier: \( identifier) (not found in pending and not a valid numeric ID) " )
309+ OpenIapLog . error ( " ❌ finishTransaction failed: \( error. message) " )
301310 emitPurchaseError ( error)
302311 throw error
303312 }
304313
314+ // Search in current entitlements
305315 for await result in Transaction . currentEntitlements {
306316 do {
307317 let transaction = try checkVerified ( result)
308318 if transaction. id == numericId {
319+ OpenIapLog . debug ( " ✅ Found in currentEntitlements, finishing... " )
309320 await transaction. finish ( )
321+ OpenIapLog . debug ( " ✅ Transaction finished successfully " )
310322 return
311323 }
312324 } catch {
313325 continue
314326 }
315327 }
316328
329+ // Search in unfinished transactions
317330 for await result in Transaction . unfinished {
318331 do {
319332 let transaction = try checkVerified ( result)
320333 if transaction. id == numericId {
334+ OpenIapLog . debug ( " ✅ Found in unfinished, finishing... " )
321335 await transaction. finish ( )
336+ OpenIapLog . debug ( " ✅ Transaction finished successfully " )
322337 return
323338 }
324339 } catch {
325340 continue
326341 }
327342 }
328343
329- let error = makePurchaseError ( code: . purchaseError, message: " Transaction not found " )
344+ let error = makePurchaseError ( code: . purchaseError, message: " Transaction not found: \( identifier) " )
345+ OpenIapLog . error ( " ❌ finishTransaction failed: \( error. message) " )
330346 emitPurchaseError ( error)
331347 throw error
332348 }
0 commit comments