Skip to content

[SK2] Add Configuration.with(storeKitVersion:) to select the version of StoreKit to use#3487

Merged
MarkVillacampa merged 23 commits into
sk2-full-flowfrom
sk2-version-configuration
Dec 20, 2023
Merged

[SK2] Add Configuration.with(storeKitVersion:) to select the version of StoreKit to use#3487
MarkVillacampa merged 23 commits into
sk2-full-flowfrom
sk2-version-configuration

Conversation

@MarkVillacampa

@MarkVillacampa MarkVillacampa commented Dec 4, 2023

Copy link
Copy Markdown
Member

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:

Purchases.configure(
            with: .builder(withAPIKey: apiKey)
                .with(storeKitVersion: .storeKit2)
                .build()

@MarkVillacampa MarkVillacampa added the pr:feat A new feature label Dec 4, 2023
Comment thread Sources/Misc/StoreKitVersion.swift
Comment thread Sources/Misc/StoreKitVersion.swift Outdated
}

extension StoreKitVersion {
var versionString: String {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: spacing here

Comment thread Sources/Misc/StoreKitVersion.swift Outdated

extension StoreKitVersion {
var versionString: String {
if isStoreKit2EnabledAndAvailable {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Explicit self:

Suggested change
if isStoreKit2EnabledAndAvailable {
if self.isStoreKit2EnabledAndAvailable {


@testable import RevenueCat

class StoreKitVersionTests: TestCase {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<3

"X-Platform-Flavor" : "native",
"X-Platform-Version" : "Version 17.0.0 (Build 21A342)",
"X-Storefront" : "USA",
"X-StoreKit-Version" : "1",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a better header than X-StoreKit2-Enabled 👍🏻

///
/// ### Related Symbols
/// - ``StoreKitVersion``
@objc public func with(storeKitVersion version: StoreKitVersion) -> Builder {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I started doing this for #3066 but ended up removing it. I think it's a better API 👍🏻

@NachoSoto

Copy link
Copy Markdown
Contributor

Looks good in general, but I want to discuss the duplicate flag.

@NachoSoto

Copy link
Copy Markdown
Contributor

Let's print the configured SK version on SDK initialization too: https://github.com/RevenueCat/purchases-ios/blob/main/Sources/Purchasing/Purchases/Purchases.swift#L556

@MarkVillacampa MarkVillacampa force-pushed the sk2-version-configuration branch from c47b5bd to f2a0820 Compare December 13, 2023 12:28
Base automatically changed from sk2-receipt to main December 13, 2023 16:00
@MarkVillacampa MarkVillacampa force-pushed the sk2-version-configuration branch from 85b2048 to 4886d77 Compare December 13, 2023 16:19
@codecov

codecov Bot commented Dec 18, 2023

Copy link
Copy Markdown

Codecov Report

Attention: 9 lines in your changes are missing coverage. Please review.

Comparison is base (32c63cd) 85.97% compared to head (0e854bb) 85.97%.
Report is 13 commits behind head on sk2-full-flow.

Files Patch % Lines
Sources/Misc/StoreKitVersion.swift 83.87% 5 Missing ⚠️
Sources/Purchasing/Purchases/Purchases.swift 71.42% 2 Missing ⚠️
Sources/Logging/Strings/ConfigureStrings.swift 66.66% 1 Missing ⚠️
Sources/Support/DebugUI/DebugViewModel.swift 0.00% 1 Missing ⚠️
Additional details and impacted files
@@                Coverage Diff                @@
##           sk2-full-flow    #3487      +/-   ##
=================================================
- Coverage          85.97%   85.97%   -0.01%     
=================================================
  Files                240      240              
  Lines              17494    17490       -4     
=================================================
- Hits               15041    15037       -4     
  Misses              2453     2453              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


case response_verification_mode(Signing.ResponseVerificationMode)

case storekit_version(String)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This String could be anything. Better to use StoreKitVersion to make it type safe.

Comment thread Sources/Misc/StoreKitVersion.swift Outdated
case storeKit2

/// Let RevenueCat use the most appropiate version of StoreKit
case `default`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of making this a case, I think it would make more sense to define it like this:

extension StoreKitVersion {

  public static `default`: Self = .storeKit1

}

Since it's technically not a different version.

Then we don't need to consider it separately in all the logic, and to update it we only need to change it in one place.

Comment thread Sources/Misc/StoreKitVersion.swift Outdated

extension StoreKitVersion {

var versionString: String {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: putting the type of the value in the name isn't a thing anymore 😅

Maybe we can do this:

extension StoreKitVersion: CustomDebugStringConvertible {

  public var debugDescription: {
    switch self {} // Let's use a switch, so if we ever add more cases, the compiler reminds us to handle it here.
  }

}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Objc throwback 🤣

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed it to effectiveVersion instead of using the debugDescription mechanism since it does not represent the enum value, but the effective version of StoreKit that's use despite what's configured. Added a docstring comment too.

Comment thread Sources/Misc/SystemInfo.swift

@NachoSoto NachoSoto left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's agree one what to do with StoreKit2Setting

expect(self.receiptFetcher.receiptDataReceivedRefreshPolicy) == .onlyIfEmpty
}

func testPurchaseSK1PackageRetriesReceiptFetchIfEnabled() async throws {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Functionally equivalent to the removed test below, but uses SK1, since SK2 does not post receipts now.

Comment thread Sources/Misc/StoreKitVersion.swift Outdated
public extension StoreKitVersion {

/// Let RevenueCat use the most appropiate version of StoreKit
static var `default` = Self.storeKit1

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops! This is mutable , meaning you can do

StoreKitVersion.default = .storeKit2 😬
Suggested change
static var `default` = Self.storeKit1
static let `default`: Self = .storeKit1

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

omg good catch 😅

Comment thread Sources/Misc/StoreKitVersion.swift Outdated

/// Returns a string representing the effective version of StoreKit used.
/// This can be different from the configured version if StoreKit 2 is not available on the current device.
var effectiveVersion: String {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like this is doing 2 things:

  • Detecting the effective StoreKitVersion
  • Converting to String

I'd change this to

Suggested change
var effectiveVersion: String {
var effectiveVersion: StoreKitVersion {

Then maybe using my CustomDebugStringConvertible suggestion?


Simply remove this method call to let RevenueCat decide for you which StoreKit implementation to use.
""")
@available(*, deprecated, message: "Use .with(storeKitVersion:) to enable StoreKit 2")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<3


Logger.debug(Strings.configure.debug_enabled, fileName: nil)
if systemInfo.storeKit2Setting == .enabledForCompatibleDevices {
if systemInfo.storeKitVersion.isStoreKit2EnabledAndAvailable {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can remove this now that we have the generic storekit_version below?

@@ -0,0 +1,50 @@
{

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, can you remove this file?

@MarkVillacampa MarkVillacampa changed the base branch from main to sk2-full-flow December 20, 2023 10:50
@MarkVillacampa MarkVillacampa merged commit f1a70e4 into sk2-full-flow Dec 20, 2023
@MarkVillacampa MarkVillacampa deleted the sk2-version-configuration branch December 20, 2023 10:53
MarkVillacampa added a commit that referenced this pull request Dec 21, 2023
…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()
```
MarkVillacampa added a commit that referenced this pull request Jan 11, 2024
…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()
```
MarkVillacampa added a commit that referenced this pull request Jan 26, 2024
…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()
```
MarkVillacampa added a commit that referenced this pull request Feb 6, 2024
…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()
```
MarkVillacampa added a commit that referenced this pull request Feb 6, 2024
…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()
```
MarkVillacampa added a commit that referenced this pull request Feb 6, 2024
…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()
```
MarkVillacampa added a commit that referenced this pull request Feb 6, 2024
…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()
```
MarkVillacampa added a commit that referenced this pull request Feb 6, 2024
…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()
```
MarkVillacampa added a commit that referenced this pull request Feb 6, 2024
…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()
```
MarkVillacampa added a commit that referenced this pull request Feb 7, 2024
…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()
```
NachoSoto pushed a commit that referenced this pull request Feb 9, 2024
…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()
```
NachoSoto pushed a commit that referenced this pull request Feb 12, 2024
…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()
```
NachoSoto pushed a commit that referenced this pull request Feb 12, 2024
…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()
```
NachoSoto pushed a commit that referenced this pull request Feb 14, 2024
…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()
```
MarkVillacampa added a commit that referenced this pull request Feb 21, 2024
…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()
```
joshdholtz pushed a commit that referenced this pull request Feb 23, 2024
…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()
```
MarkVillacampa added a commit that referenced this pull request Mar 6, 2024
…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()
```
MarkVillacampa added a commit that referenced this pull request Mar 6, 2024
…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()
```
MarkVillacampa added a commit that referenced this pull request Apr 9, 2024
…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()
```
fire-at-will pushed a commit that referenced this pull request Apr 15, 2024
…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()
```
fire-at-will pushed a commit that referenced this pull request May 13, 2024
…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()
```
fire-at-will pushed a commit that referenced this pull request Jun 24, 2024
…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()
```
fire-at-will pushed a commit that referenced this pull request Jun 28, 2024
…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()
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants