From 7e70d6a4e0fd14658c12c4b6733c940f09e45f28 Mon Sep 17 00:00:00 2001 From: NachoSoto Date: Mon, 31 Jul 2023 10:49:40 +0200 Subject: [PATCH 1/3] `Paywalls`: pre-warm intro eligibility in background thread Follow-up to #2860. Thanks to integration tests for catching this (#2123). --- Sources/Purchasing/Purchases/Purchases.swift | 23 ++++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/Sources/Purchasing/Purchases/Purchases.swift b/Sources/Purchasing/Purchases/Purchases.swift index 75e781da80..5d65df6b11 100644 --- a/Sources/Purchasing/Purchases/Purchases.swift +++ b/Sources/Purchasing/Purchases/Purchases.swift @@ -1611,19 +1611,24 @@ private extension Purchases { self.offeringsManager.updateOfferingsCache(appUserID: self.appUserID, isAppBackgrounded: isAppBackgrounded) { offerings in if let offering = offerings.value?.current, let paywall = offering.paywall { - let packageTypes = Set(paywall.config.packages) - let products: [String] = offering.availablePackages - .lazy - .filter { packageTypes.contains($0.packageType) } - .map(\.storeProduct.productIdentifier) - - Logger.debug(Strings.eligibility.warming_up_eligibility_cache(paywall)) - - self.trialOrIntroPriceEligibilityChecker.checkEligibility(productIdentifiers: products) { _ in } + self.operationDispatcher.dispatchOnWorkerThread { + self.warmUpEligibilityCache(offering: offering, paywall: paywall) + } } } } + private func warmUpEligibilityCache(offering: RevenueCat.Offering, paywall: PaywallData) { + let packageTypes = Set(paywall.config.packages) + let products: [String] = offering.availablePackages + .lazy + .filter { packageTypes.contains($0.packageType) } + .map(\.storeProduct.productIdentifier) + + Logger.debug(Strings.eligibility.warming_up_eligibility_cache(paywall)) + self.trialOrIntroPriceEligibilityChecker.checkEligibility(productIdentifiers: products) { _ in } + } + } // MARK: - Deprecations From f0a485f58521d85ffa1a937bf687add38248d4b7 Mon Sep 17 00:00:00 2001 From: NachoSoto Date: Mon, 31 Jul 2023 11:34:24 +0200 Subject: [PATCH 2/3] Fixed custom entitlement computation --- Sources/Purchasing/Purchases/Purchases.swift | 2 +- Sources/Support/FrameworkDisambiguation.swift | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Sources/Purchasing/Purchases/Purchases.swift b/Sources/Purchasing/Purchases/Purchases.swift index 5d65df6b11..47fc4c5db4 100644 --- a/Sources/Purchasing/Purchases/Purchases.swift +++ b/Sources/Purchasing/Purchases/Purchases.swift @@ -1618,7 +1618,7 @@ private extension Purchases { } } - private func warmUpEligibilityCache(offering: RevenueCat.Offering, paywall: PaywallData) { + private func warmUpEligibilityCache(offering: RCOffering, paywall: PaywallData) { let packageTypes = Set(paywall.config.packages) let products: [String] = offering.availablePackages .lazy diff --git a/Sources/Support/FrameworkDisambiguation.swift b/Sources/Support/FrameworkDisambiguation.swift index ffb9c7b706..f07da393d3 100644 --- a/Sources/Support/FrameworkDisambiguation.swift +++ b/Sources/Support/FrameworkDisambiguation.swift @@ -23,4 +23,5 @@ typealias RCRefundRequestStatus = RefundRequestStatus typealias RCErrorCode = ErrorCode +typealias RCOffering = Offering let RCDefaultLogHandler = defaultLogHandler From 9f0048ca367cf63d070e8c0c1e9ff91519cc6839 Mon Sep 17 00:00:00 2001 From: NachoSoto Date: Sun, 30 Jul 2023 11:46:09 +0200 Subject: [PATCH 3/3] `Paywalls`: updated Integration Test snapshot I added a paywall to the integration test offering so we can validate the response format with our integration tests. --- .../testCanGetOfferings.1.json | 45 ++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/Tests/BackendIntegrationTests/__Snapshots__/StoreKitIntegrationTests/testCanGetOfferings.1.json b/Tests/BackendIntegrationTests/__Snapshots__/StoreKitIntegrationTests/testCanGetOfferings.1.json index 44176be12c..8982dc36a6 100644 --- a/Tests/BackendIntegrationTests/__Snapshots__/StoreKitIntegrationTests/testCanGetOfferings.1.json +++ b/Tests/BackendIntegrationTests/__Snapshots__/StoreKitIntegrationTests/testCanGetOfferings.1.json @@ -21,7 +21,50 @@ "platform_product_identifier" : "com.revenuecat.weekly_1.99.3_day_intro" } ], - "paywall" : null + "paywall" : { + "asset_base_url" : "https://d35rwhxn1vk1te.cloudfront.net", + "config" : { + "blurred_background_image" : true, + "colors" : { + "light" : { + "accent1" : "#ec64e5", + "accent2" : "#d9d9d9", + "background" : "#ffffff", + "call_to_action_background" : "#45c186", + "call_to_action_foreground" : "#ffffff", + "text1" : "#000000" + } + }, + "default_package" : "$rc_monthly", + "display_restore_purchases" : true, + "images" : { + "background" : "300883_1690710097.jpg", + "icon" : "300883_1690710150.jpg" + }, + "packages" : [ + "$rc_monthly", + "$rc_annual" + ], + "privacy_url" : "https://revenuecat.com/privacy", + "tos_url" : "https://revenuecat.com/tos" + }, + "default_locale" : "en_US", + "localized_strings" : { + "en_US" : { + "call_to_action" : "Purchase for {{ price_per_month }} per month", + "call_to_action_with_intro_offer" : "Start your {{ intro_duration }} trial, then {{ price_per_month }} per month", + "features" : [ + + ], + "offer_details" : "{{ total_price_and_per_month }}", + "offer_details_with_intro_offer" : "{{ total_price_and_per_month }} after {{ intro_duration }} trial", + "offer_name" : "{{ period }}", + "subtitle" : "Gert access to all our educational content trusted by thousands of parents", + "title" : "Ignite your child's curiosity" + } + }, + "template_name" : "multi_package_bold" + } }, { "description" : "Coins",