From 7fb1111832dc5ddc9da787e5f27b4b65040288aa Mon Sep 17 00:00:00 2001 From: NachoSoto Date: Mon, 12 Jun 2023 16:00:31 -0700 Subject: [PATCH] `PurchasesOrchestrator`: also get `Storefront` from SK1 Looks like `Storefront.current` is usually `nil` during tests. After #2612, it's important than renewals posted from SK1 and SK2 end up with equivalent cache keys. This will be ensured by a test in #2590, which breaks unless we do this. Example cache keys between SK1 and SK2: ``` PostReceiptDataOperation $RCAnonymousID:9d38b05059d442b082f915011041bbcb-true-77c15e6fad291c0ff9bf8a4efdfa21eca7cdd74e7a0a4a1bdcf320e8ddcfc2d5\n-com.revenuecat.monthly_4.99.no_intro-0.99-USD-USA--1-0-7096FF06-P1M---1-com.revenuecat.monthly_4.99.1_free_week\n--true\n-[\"$attConsentStatus\": [SubscriberAttribute] key: $attConsentStatus value: notDetermined setTime: 2023-06-12 22:31:56 +0000] PostReceiptDataOperation $RCAnonymousID:9d38b05059d442b082f915011041bbcb-true-77c15e6fad291c0ff9bf8a4efdfa21eca7cdd74e7a0a4a1bdcf320e8ddcfc2d5\n-com.revenuecat.monthly_4.99.no_intro-0.99-USD---1-0-7096FF06-P1M---1-com.revenuecat.monthly_4.99.1_free_week\n--true\n-["$attConsentStatus": [SubscriberAttribute] key: $attConsentStatus value: notDetermined setTime: 2023-06-12 22:31:56 +0000] ``` Notice `USA` is missing on the SK2 posted product. --- Sources/Purchasing/Purchases/PurchasesOrchestrator.swift | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Sources/Purchasing/Purchases/PurchasesOrchestrator.swift b/Sources/Purchasing/Purchases/PurchasesOrchestrator.swift index 6aaab10908..a7309cc97e 100644 --- a/Sources/Purchasing/Purchases/PurchasesOrchestrator.swift +++ b/Sources/Purchasing/Purchases/PurchasesOrchestrator.swift @@ -824,7 +824,7 @@ extension PurchasesOrchestrator: StoreKit2TransactionListenerDelegate { _ listener: StoreKit2TransactionListener, updatedTransaction transaction: StoreTransactionType ) async throws { - let storefront = await transaction.storefrontOrCurrent + let storefront = await self.storefront(from: transaction) _ = try await Async.call { completed in self.transactionPoster.handlePurchasedTransaction( @@ -845,6 +845,12 @@ extension PurchasesOrchestrator: StoreKit2TransactionListenerDelegate { } } + private func storefront(from transaction: StoreTransactionType) async -> StorefrontType? { + return await transaction.storefrontOrCurrent + // If we couldn't determine storefront from SK2, try SK1: + ?? self.paymentQueueWrapper.sk1Wrapper?.currentStorefront + } + } @available(iOS 15.0, tvOS 15.0, macOS 12.0, watchOS 8.0, *)