From c29c7544ddd639ecfdffcdc1d5db41eb10e90f46 Mon Sep 17 00:00:00 2001 From: Charly Berthet Date: Thu, 31 Oct 2024 18:28:01 +0100 Subject: [PATCH 1/2] fix: storekit2 add verificationResultIOS to getAvailablePurchases --- ios/RNIapIosSk2.swift | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/ios/RNIapIosSk2.swift b/ios/RNIapIosSk2.swift index baeaee6fd..43d45219f 100644 --- a/ios/RNIapIosSk2.swift +++ b/ios/RNIapIosSk2.swift @@ -592,10 +592,10 @@ class RNIapIosSk2iOS15: Sk2Delegate { reject: @escaping RCTPromiseRejectBlock = { _, _, _ in } ) { Task { - var purchasedItems: [Transaction] = [] + var purchasedItemsSerialized: [[String : Any?]] = [] - func addTransaction(transaction: Transaction) { - purchasedItems.append( transaction) + func addTransaction(transaction: Transaction, verification: VerificationResult) { + purchasedItemsSerialized.append(serialize(transaction, verification)) if alsoPublishToEventListener { self.sendEvent?("purchase-updated", serialize(transaction)) } @@ -606,19 +606,19 @@ class RNIapIosSk2iOS15: Sk2Delegate { } } // Iterate through all of the user's purchased products. - for await result in onlyIncludeActiveItems ? Transaction.currentEntitlements : Transaction.all { + for await verification in onlyIncludeActiveItems ? Transaction.currentEntitlements : Transaction.all { do { // Check whether the transaction is verified. If it isn’t, catch `failedVerification` error. - let transaction = try checkVerified(result) + let transaction = try checkVerified(verification) // Check the `productType` of the transaction and get the corresponding product from the store. if !onlyIncludeActiveItems { - addTransaction(transaction: transaction) + addTransaction(transaction: transaction, verification: verification) continue } switch transaction.productType { case .nonConsumable: if await productStore.getProduct(productID: transaction.productID) != nil { - addTransaction(transaction: transaction) + addTransaction(transaction: transaction, verification: verification) } case .nonRenewable: @@ -633,18 +633,18 @@ class RNIapIosSk2iOS15: Sk2Delegate { to: transaction.purchaseDate)! if currentDate < expirationDate { - addTransaction(transaction: transaction) + addTransaction(transaction: transaction, verification: verification) } } case .autoRenewable: if await productStore.getProduct(productID: transaction.productID) != nil { - addTransaction(transaction: transaction) + addTransaction(transaction: transaction, verification: verification) } case .consumable: if await productStore.getProduct(productID: transaction.productID) != nil { - addTransaction(transaction: transaction) + addTransaction(transaction: transaction, verification: verification) } default: @@ -674,7 +674,7 @@ class RNIapIosSk2iOS15: Sk2Delegate { // group, so products in the subscriptions array all belong to the same group. The statuses that // `product.subscription.status` returns apply to the entire subscription group. // subscriptionGroupStatus = try? await subscriptions.first?.subscription?.status.first?.state - resolve(purchasedItems.map({(t: Transaction) in serialize(t)})) + resolve(purchasedItemsSerialized) } } From 36634170d4f9a45c7c9e1c6312186fa7f9d497ec Mon Sep 17 00:00:00 2001 From: Charly Berthet Date: Thu, 31 Oct 2024 19:05:58 +0100 Subject: [PATCH 2/2] fix type format --- ios/RNIapIosSk2.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ios/RNIapIosSk2.swift b/ios/RNIapIosSk2.swift index 43d45219f..81845ecfc 100644 --- a/ios/RNIapIosSk2.swift +++ b/ios/RNIapIosSk2.swift @@ -592,7 +592,7 @@ class RNIapIosSk2iOS15: Sk2Delegate { reject: @escaping RCTPromiseRejectBlock = { _, _, _ in } ) { Task { - var purchasedItemsSerialized: [[String : Any?]] = [] + var purchasedItemsSerialized: [[String: Any?]] = [] func addTransaction(transaction: Transaction, verification: VerificationResult) { purchasedItemsSerialized.append(serialize(transaction, verification))