Skip to content

Commit

Permalink
[SK2] Add Configuration.with(storeKitVersion:) to select the versio…
Browse files Browse the repository at this point in the history
…n of StoreKit to use (#3487)

This PR introduces a new configuration option to select the StoreKit
version to use.

It supersedes the deprecated `.with(usesStoreKit2IfAvailable: true)` and
the internal `usesStoreKit2JWS` configuration options.

Uses JWS tokens instead of SK1 receipts when in StoreKit 2 mode where
applicable.

Example usage:
```swift
Purchases.configure(
            with: .builder(withAPIKey: apiKey)
                .with(storeKitVersion: .storeKit2)
                .build()
```
  • Loading branch information
MarkVillacampa committed Feb 6, 2024
1 parent f77a9ef commit 6fbdf39
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
2 changes: 2 additions & 0 deletions RevenueCat.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@
4DBC30962B1DFA97001D33C7 /* StoreKitVersion.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DBC30952B1DFA97001D33C7 /* StoreKitVersion.swift */; };
4DBF1F362B4D572400D52354 /* LocalReceiptFetcher.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DBF1F352B4D572400D52354 /* LocalReceiptFetcher.swift */; };
4DBF1F372B4D572400D52354 /* LocalReceiptFetcher.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DBF1F352B4D572400D52354 /* LocalReceiptFetcher.swift */; };
4DBC30962B1DFA97001D33C7 /* StoreKitVersion.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DBC30952B1DFA97001D33C7 /* StoreKitVersion.swift */; };
4DC546272AD44BBE005CDB35 /* EncodedAppleReceipt.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DC546262AD44BBE005CDB35 /* EncodedAppleReceipt.swift */; };
4F0201C42A13C85500091612 /* Assertions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F0201C32A13C85500091612 /* Assertions.swift */; };
4F05876F2A5DE03F00E9A834 /* PaywallDataTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F05876E2A5DE03F00E9A834 /* PaywallDataTests.swift */; };
Expand Down Expand Up @@ -1003,6 +1004,7 @@
4D6ABB0F2AF13FBD00BB2A08 /* SK2AppTransaction.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SK2AppTransaction.swift; sourceTree = "<group>"; };
4DBC30952B1DFA97001D33C7 /* StoreKitVersion.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StoreKitVersion.swift; sourceTree = "<group>"; };
4DBF1F352B4D572400D52354 /* LocalReceiptFetcher.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LocalReceiptFetcher.swift; sourceTree = "<group>"; };
4DBC30952B1DFA97001D33C7 /* StoreKitVersion.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StoreKitVersion.swift; sourceTree = "<group>"; };
4DC546262AD44BBE005CDB35 /* EncodedAppleReceipt.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EncodedAppleReceipt.swift; sourceTree = "<group>"; };
4F0201C32A13C85500091612 /* Assertions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Assertions.swift; sourceTree = "<group>"; };
4F05876E2A5DE03F00E9A834 /* PaywallDataTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PaywallDataTests.swift; sourceTree = "<group>"; };
Expand Down
16 changes: 4 additions & 12 deletions Tests/BackendIntegrationTests/StoreKitIntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,7 @@ import XCTest

class StoreKit2IntegrationTests: StoreKit1IntegrationTests {

override class var storeKit2Setting: StoreKit2Setting { return .enabledForCompatibleDevices }

}

class StoreKit2JWSIntegrationTests: StoreKit2IntegrationTests {

override var usesStoreKit2JWS: Bool { true }
override class var storeKitVersion: StoreKitVersion { .storeKit2 }

@available(iOS 15.0, tvOS 15.0, watchOS 8.0, macOS 12.0, *)
func testObservingTransactionThrowsIfObserverModeNotEnabled() async throws {
Expand All @@ -43,9 +37,7 @@ class StoreKit2JWSIntegrationTests: StoreKit2IntegrationTests {

class StoreKit1IntegrationTests: BaseStoreKitIntegrationTests {

override class var storeKit2Setting: StoreKit2Setting {
return .disabled
}
override class var storeKitVersion: StoreKitVersion { .storeKit1 }

func testIsSandbox() throws {
try expect(self.purchases.isSandbox) == true
Expand Down Expand Up @@ -90,7 +82,7 @@ class StoreKit1IntegrationTests: BaseStoreKitIntegrationTests {

@available(iOS 15.0, tvOS 15.0, macOS 12.0, watchOS 8.0, *)
func testPurchasingSK1ProductDoesNotLeaveUnfinishedSK2Transaction() async throws {
try XCTSkipIf(Self.storeKit2Setting.usesStoreKit2IfAvailable, "Test only for SK1")
try XCTSkipIf(Self.storeKitVersion == .storeKit2, "Test only for SK1")

func verifyNoUnfinishedTransactions() async {
let unfinishedTransactions = await Transaction.unfinished.extractValues()
Expand Down Expand Up @@ -838,7 +830,7 @@ class StoreKit1IntegrationTests: BaseStoreKitIntegrationTests {
private extension BaseStoreKitIntegrationTests {

func verifyReceiptIsPresentBeforeEligibilityChecking() async throws {
if Self.storeKit2Setting == .disabled {
if Self.storeKitVersion == .storeKit1 {
// SK1 implementation relies on the receipt being loaded already.
// See `TrialOrIntroPriceEligibilityChecker.sk1CheckEligibility`
_ = try await self.purchases.restorePurchases()
Expand Down

0 comments on commit 6fbdf39

Please sign in to comment.