Skip to content

Commit

Permalink
support redeeming win-back offers with streamlined purchasing disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
fire-at-will authored Nov 8, 2024
1 parent a58ab4c commit f638ae7
Show file tree
Hide file tree
Showing 12 changed files with 695 additions and 22 deletions.
21 changes: 21 additions & 0 deletions RevenueCat.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1003,6 +1003,10 @@
F5FCD3EA27DA0D0B003BDC04 /* PriceFormatterProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = F5FCD3E927DA0D0B003BDC04 /* PriceFormatterProvider.swift */; };
F5FCD3FC27DA2034003BDC04 /* PriceFormatterProviderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F5FCD3FB27DA2034003BDC04 /* PriceFormatterProviderTests.swift */; };
FD18ED4E2837F89200C5AA4F /* StoreKitWorkaroundsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD18ED4D2837F89200C5AA4F /* StoreKitWorkaroundsTests.swift */; };
FD20467F2CB82F2000166727 /* StoreKit2PurchaseIntentListener.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD20467E2CB82F1700166727 /* StoreKit2PurchaseIntentListener.swift */; };
FD2046812CB8333A00166727 /* StoreKit2PurchaseIntentListenerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD2046802CB8333200166727 /* StoreKit2PurchaseIntentListenerTests.swift */; };
FD2046832CB833CD00166727 /* MockStoreKit2PurchaseIntentListenerDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD2046822CB833CD00166727 /* MockStoreKit2PurchaseIntentListenerDelegate.swift */; };
FD2046842CB833CD00166727 /* MockStoreKit2PurchaseIntentListenerDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD2046822CB833CD00166727 /* MockStoreKit2PurchaseIntentListenerDelegate.swift */; };
FD2E6C9F2C480FF000CB4BD7 /* OHHTTPStubs in Frameworks */ = {isa = PBXBuildFile; productRef = FD2E6C9E2C480FF000CB4BD7 /* OHHTTPStubs */; };
FD2E6CA12C48100900CB4BD7 /* OHHTTPStubsSwift in Frameworks */ = {isa = PBXBuildFile; productRef = FD2E6CA02C48100900CB4BD7 /* OHHTTPStubsSwift */; };
FD43D2FC2C41864000077235 /* TimeInterval+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD43D2FA2C4185B700077235 /* TimeInterval+Extensions.swift */; };
Expand All @@ -1014,6 +1018,8 @@
FDAADFD32BE2B99900BD1659 /* MockStoreKit2ObserverModePurchaseDetector.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDAADFD22BE2B99900BD1659 /* MockStoreKit2ObserverModePurchaseDetector.swift */; };
FDAADFD42BE2B99900BD1659 /* MockStoreKit2ObserverModePurchaseDetector.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDAADFD22BE2B99900BD1659 /* MockStoreKit2ObserverModePurchaseDetector.swift */; };
FDAADFD72BE2C67700BD1659 /* StoreKit2ObserverModePurchaseDetectorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDAADFD52BE2C67700BD1659 /* StoreKit2ObserverModePurchaseDetectorTests.swift */; };
FDC892D12CCAD0EE000AEB9F /* MockStoreKit2PurchaseIntentListener.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDC892D02CCAD0EE000AEB9F /* MockStoreKit2PurchaseIntentListener.swift */; };
FDC892D22CCAD0EE000AEB9F /* MockStoreKit2PurchaseIntentListener.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDC892D02CCAD0EE000AEB9F /* MockStoreKit2PurchaseIntentListener.swift */; };
FDAC7B532CD3D67600DFC0D9 /* WinBackOfferEligibilityCalculatorType.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDAC7B522CD3D67600DFC0D9 /* WinBackOfferEligibilityCalculatorType.swift */; };
FDAC7B552CD3D7A500DFC0D9 /* WinBackOfferEligibilityCalculator.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDAC7B542CD3D7A200DFC0D9 /* WinBackOfferEligibilityCalculator.swift */; };
FDAC7B572CD3FD8500DFC0D9 /* MockWinBackOfferEligibilityCalculator.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDAC7B562CD3FD8500DFC0D9 /* MockWinBackOfferEligibilityCalculator.swift */; };
Expand Down Expand Up @@ -2205,12 +2211,16 @@
F5FCD3E927DA0D0B003BDC04 /* PriceFormatterProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PriceFormatterProvider.swift; sourceTree = "<group>"; };
F5FCD3FB27DA2034003BDC04 /* PriceFormatterProviderTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PriceFormatterProviderTests.swift; sourceTree = "<group>"; };
FD18ED4D2837F89200C5AA4F /* StoreKitWorkaroundsTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StoreKitWorkaroundsTests.swift; sourceTree = "<group>"; };
FD20467E2CB82F1700166727 /* StoreKit2PurchaseIntentListener.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StoreKit2PurchaseIntentListener.swift; sourceTree = "<group>"; };
FD2046802CB8333200166727 /* StoreKit2PurchaseIntentListenerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StoreKit2PurchaseIntentListenerTests.swift; sourceTree = "<group>"; };
FD2046822CB833CD00166727 /* MockStoreKit2PurchaseIntentListenerDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockStoreKit2PurchaseIntentListenerDelegate.swift; sourceTree = "<group>"; };
FD43D2FA2C4185B700077235 /* TimeInterval+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "TimeInterval+Extensions.swift"; sourceTree = "<group>"; };
FD43D2FD2C41867600077235 /* TimeInterval+ExtensionsTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "TimeInterval+ExtensionsTests.swift"; sourceTree = "<group>"; };
FDAADFCA2BE2A5BF00BD1659 /* MockAllTransactionsProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockAllTransactionsProvider.swift; sourceTree = "<group>"; };
FDAADFCE2BE2B84500BD1659 /* StoreKit2ObserverModePurchaseDetector.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StoreKit2ObserverModePurchaseDetector.swift; sourceTree = "<group>"; };
FDAADFD22BE2B99900BD1659 /* MockStoreKit2ObserverModePurchaseDetector.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockStoreKit2ObserverModePurchaseDetector.swift; sourceTree = "<group>"; };
FDAADFD52BE2C67700BD1659 /* StoreKit2ObserverModePurchaseDetectorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StoreKit2ObserverModePurchaseDetectorTests.swift; sourceTree = "<group>"; };
FDC892D02CCAD0EE000AEB9F /* MockStoreKit2PurchaseIntentListener.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockStoreKit2PurchaseIntentListener.swift; sourceTree = "<group>"; };
FDAC7B522CD3D67600DFC0D9 /* WinBackOfferEligibilityCalculatorType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WinBackOfferEligibilityCalculatorType.swift; sourceTree = "<group>"; };
FDAC7B542CD3D7A200DFC0D9 /* WinBackOfferEligibilityCalculator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WinBackOfferEligibilityCalculator.swift; sourceTree = "<group>"; };
FDAC7B562CD3FD8500DFC0D9 /* MockWinBackOfferEligibilityCalculator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockWinBackOfferEligibilityCalculator.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2335,6 +2345,7 @@
4D6ABB0B2AF13F9400BB2A08 /* StoreKit2Receipt.swift */,
2D294E5B26DECFD500B8FE4F /* StoreKit2TransactionListener.swift */,
4F7DBFBC2A1E986C00A2F511 /* StoreKit2TransactionFetcher.swift */,
FD20467E2CB82F1700166727 /* StoreKit2PurchaseIntentListener.swift */,
);
path = StoreKit2;
sourceTree = "<group>";
Expand Down Expand Up @@ -3175,6 +3186,7 @@
5793397128E77A6E00C1232C /* MockPaymentQueue.swift */,
4F54DF3E2A1D8C7500FD72BF /* MockStoreKit2TransactionFetcher.swift */,
575A8EE42922C9F300936709 /* MockStoreKit2TransactionListenerDelegate.swift */,
FD2046822CB833CD00166727 /* MockStoreKit2PurchaseIntentListenerDelegate.swift */,
57FFD2502922DBED00A9A878 /* MockStoreTransaction.swift */,
578DAA492948EF4F001700FD /* TestClock.swift */,
5791FBD1299184EF00F1FEDA /* MockAsyncSequence.swift */,
Expand All @@ -3186,6 +3198,7 @@
35316DA82BD14BFD00E4A970 /* MockDiagnosticsSynchronizer.swift */,
FDAADFCA2BE2A5BF00BD1659 /* MockAllTransactionsProvider.swift */,
FDAADFD22BE2B99900BD1659 /* MockStoreKit2ObserverModePurchaseDetector.swift */,
FDC892D02CCAD0EE000AEB9F /* MockStoreKit2PurchaseIntentListener.swift */,
FDAC7B562CD3FD8500DFC0D9 /* MockWinBackOfferEligibilityCalculator.swift */,
);
path = Mocks;
Expand Down Expand Up @@ -3793,6 +3806,7 @@
isa = PBXGroup;
children = (
57C381B62791E593009E3940 /* StoreKit2TransactionListenerTests.swift */,
FD2046802CB8333200166727 /* StoreKit2PurchaseIntentListenerTests.swift */,
F516BD322828FDD90083480B /* StoreKit2StorefrontListenerTests.swift */,
57E6194F28D291DC0093170C /* StoreKit2CachingProductsManagerTests.swift */,
4FD291BD2A1E9A2E0098D1B9 /* StoreKit2TransactionFetcherTests.swift */,
Expand Down Expand Up @@ -5420,6 +5434,7 @@
3543914226F911F300E669DF /* MockSK1Product.swift in Sources */,
57FFD2522922DBED00A9A878 /* MockStoreTransaction.swift in Sources */,
3543913826F90FE100E669DF /* MockIntroEligibilityCalculator.swift in Sources */,
FD2046842CB833CD00166727 /* MockStoreKit2PurchaseIntentListenerDelegate.swift in Sources */,
3543914126F911CC00E669DF /* MockDeviceCache.swift in Sources */,
3543913C26F9101600E669DF /* MockOperationDispatcher.swift in Sources */,
4FA4C9752A16D49E007D2803 /* MockOfflineEntitlementsManager.swift in Sources */,
Expand All @@ -5441,6 +5456,7 @@
2D90F8CC26FD2BA1009B9142 /* StoreKitConfigTestCase.swift in Sources */,
2D90F8BC26FD20C2009B9142 /* MockReceiptParser.swift in Sources */,
57488C8329CB91D20000EE7E /* CustomerInfoOfflineEntitlementsStoreKitTest.swift in Sources */,
FD2046812CB8333A00166727 /* StoreKit2PurchaseIntentListenerTests.swift in Sources */,
57DE80812807529F008D6C6F /* MockStorefront.swift in Sources */,
57544C29285FA95E004E54D5 /* MockAttributeSyncing.swift in Sources */,
57057FF928B0048900995F21 /* TestLogHandler.swift in Sources */,
Expand Down Expand Up @@ -5493,6 +5509,7 @@
B359DDF027EAA2B4003ABA54 /* MockDateProvider.swift in Sources */,
57C381E3279627B7009E3940 /* MockStoreProductDiscount.swift in Sources */,
576C8AB927D2996C0058FA6E /* CurrentTestCaseTracker.swift in Sources */,
FDC892D12CCAD0EE000AEB9F /* MockStoreKit2PurchaseIntentListener.swift in Sources */,
B3BE0264275942D500915B4C /* AvailabilityChecks.swift in Sources */,
4D322E3C2B7E7E250004AF53 /* PurchasesOrchestratorCommonTests.swift in Sources */,
2D90F8B326FD2082009B9142 /* MockProductsManager.swift in Sources */,
Expand Down Expand Up @@ -5817,6 +5834,8 @@
5766C622282DAA700067D886 /* GetIntroEligibilityResponse.swift in Sources */,
35E840CC270FB70D00899AE2 /* ManageSubscriptionsHelper.swift in Sources */,
6E38843A0CAFD551013D0A3F /* StoreProduct.swift in Sources */,
4FE6FEE52AA940B800780B45 /* PaywallStoredEvent.swift in Sources */,
FD20467F2CB82F2000166727 /* StoreKit2PurchaseIntentListener.swift in Sources */,
4FE6FEE52AA940B800780B45 /* StoredEvent.swift in Sources */,
B34605BD279A6E380031CA74 /* CallbackCacheStatus.swift in Sources */,
42F1DF385E3C1F9903A07FBF /* ProductsFetcherSK1.swift in Sources */,
Expand Down Expand Up @@ -5929,6 +5948,7 @@
5733D01128D00354008638D8 /* PromotionalOfferTests.swift in Sources */,
57544C28285FA94B004E54D5 /* MockAttributeSyncing.swift in Sources */,
4F34AEEC2A5DCCBA00F4BCB0 /* VerificationResultTests.swift in Sources */,
FD2046832CB833CD00166727 /* MockStoreKit2PurchaseIntentListenerDelegate.swift in Sources */,
35AAEB4C2BBC39D100A12548 /* DiagnosticsFileHandlerTests.swift in Sources */,
57DE80802807529F008D6C6F /* MockStorefront.swift in Sources */,
5759B464296E1A4B002472D5 /* MockBundle.swift in Sources */,
Expand Down Expand Up @@ -6032,6 +6052,7 @@
574A2F4F282D7B9E00150D40 /* PostOfferDecodingTests.swift in Sources */,
2DDF41CE24F6F4C3005BC22D /* InAppPurchaseBuilderTests.swift in Sources */,
573A10DB2800AF4700F976E5 /* PurchaseErrorTests.swift in Sources */,
FDC892D22CCAD0EE000AEB9F /* MockStoreKit2PurchaseIntentListener.swift in Sources */,
35C05DC82BC8510000109308 /* DiagnosticsTrackerTests.swift in Sources */,
35C272A12BC4084C005A0CE8 /* MockDiagnosticsTracker.swift in Sources */,
2C7F0AD62B8EEF7B00381179 /* RateLimiterRests.swift in Sources */,
Expand Down
10 changes: 10 additions & 0 deletions Sources/Logging/Strings/StoreKitStrings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ enum StoreKitStrings {

case sk2_purchasing_added_promotional_offer_option(String)

case sk2_purchasing_added_winback_offer_option(String)

case sk2_purchasing_added_uuid_option(UUID)

case sk2_unknown_product_type(String)
Expand All @@ -61,6 +63,8 @@ enum StoreKitStrings {

case sk2_observing_transaction_updates

case sk2_observing_purchase_intents

case sk2_unknown_environment(String)

case sk2_error_encoding_receipt(Error)
Expand Down Expand Up @@ -126,6 +130,9 @@ extension StoreKitStrings: LogMessage {
case let .sk2_purchasing_added_promotional_offer_option(discountIdentifier):
return "Adding Product.PurchaseOption for discount '\(discountIdentifier)'"

case let .sk2_purchasing_added_winback_offer_option(winBackOfferID):
return "Adding Product.PurchaseOption for win-back offer with ID '\(winBackOfferID)'"

case let .sk2_purchasing_added_uuid_option(uuid):
return "Adding Product.PurchaseOption for .appAccountToken '\(uuid)'"

Expand Down Expand Up @@ -170,6 +177,9 @@ extension StoreKitStrings: LogMessage {
case .sk2_observing_transaction_updates:
return "Observing StoreKit.Transaction.updates"

case .sk2_observing_purchase_intents:
return "Observing StoreKit.PurchaseIntent.intents"

case let .sk2_unknown_environment(environment):
return "Unrecognized StoreKit Environment: \(environment)"

Expand Down
6 changes: 6 additions & 0 deletions Sources/Purchasing/Purchases/Purchases.swift
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,12 @@ public typealias StartPurchaseBlock = (@escaping PurchaseCompletedBlock) -> Void

Logger.verbose(Strings.configure.purchases_init(self, paymentQueueWrapper))

#if os(iOS) || targetEnvironment(macCatalyst) || os(macOS)
if #available(iOS 16.4, macOS 14.4, *), systemInfo.storeKitVersion.isStoreKit2EnabledAndAvailable {
purchasesOrchestrator.setSK2PurchaseIntentListener(StoreKit2PurchaseIntentListener())
}
#endif

self.purchasesOrchestrator.delegate = self

// Don't update caches in the background to potentially avoid apps being launched through a notification
Expand Down
Loading

0 comments on commit f638ae7

Please sign in to comment.