feat: parse OwnershipType.assigned (#8064)

* parse OwnershipType.assigned

* Update PurchaseOwnershipTypeTests.swift

* lint

* Update baseline swiftinterface files (#8065)

* remove unnecessary availability requirements

* add parsing test

---------

Co-authored-by: RevenueCat Git Bot <72824662+RCGitBot@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
authored and GitHub committed 2026-10-21 11:29:25 -05:00
1 parent e98186b2d4
commit d66667d98e
19 files changed
+76 -15

No files matched your search

@@ -61,6 +61,7 @@ private extension PurchaseOwnershipType {
switch self {
case .purchased: return "PURCHASED"
case .familyShared: return "FAMILY_SHARED"
case .assigned: return "ASSIGNED"
case .unknown: return nil
}
}
+2
View File
@@ -56,6 +56,8 @@ import Foundation
/// How the Customer received access to this subscription:
/// - ``PurchaseOwnershipType/purchased``: The customer bought the subscription.
/// - ``PurchaseOwnershipType/familyShared``: The Customer has access to the product via their family.
/// - ``PurchaseOwnershipType/assigned``: The Customer has been assigned access to this product
/// through an organization.
@objc public let ownershipType: PurchaseOwnershipType
/// Type of the current subscription period:
@@ -252,6 +252,7 @@ private extension PurchaseOwnershipType {
switch self {
case .purchased: return "PURCHASED"
case .familyShared: return "FAMILY_SHARED"
case .assigned: return "ASSIGNED"
case .unknown: return nil
}
}
@@ -62,7 +62,7 @@ extension PurchasedSK2Product {
expiresDate: transaction.expirationDate,
store: .appStore,
isSandbox: sandboxEnvironmentDetector.isSandbox,
ownershipType: transaction.ownershipType.type,
ownershipType: PurchaseOwnershipType.from(storeKitOwnershipType: transaction.ownershipType),
productPlanIdentifier: self.productPlanIdentifier
)
self.entitlement = .init(
@@ -96,20 +96,6 @@ private extension StoreKit.Transaction.OfferType {
}
@available(iOS 15.0, tvOS 15.0, watchOS 8.0, macOS 12.0, *)
private extension StoreKit.Transaction.OwnershipType {
var type: PurchaseOwnershipType {
switch self {
case .familyShared:
return .familyShared
default:
return .purchased
}
}
}
@available(iOS 15.0, tvOS 15.0, watchOS 8.0, macOS 12.0, *)
private extension PurchasedSK2Product {
static func productPlanIdentifier(from transaction: StoreKit.Transaction) -> String? {
@@ -13,6 +13,7 @@
//
import Foundation
import StoreKit
/// The types used to describe whether a transaction was purchased by the user,
/// or is available to them through Family Sharing.
@@ -32,6 +33,11 @@ import Foundation
*/
case unknown = 2
/**
The user has access to the purchase through an organization.
*/
case assigned = 3
}
extension PurchaseOwnershipType: CaseIterable {}
@@ -42,3 +48,21 @@ extension PurchaseOwnershipType: DefaultValueProvider {
static let defaultValue: Self = .purchased
}
internal extension PurchaseOwnershipType {
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
static func from(storeKitOwnershipType: StoreKit.Transaction.OwnershipType) -> PurchaseOwnershipType {
switch storeKitOwnershipType {
case .familyShared:
return .familyShared
#if compiler(>=6.4)
case .assigned:
return .assigned
#endif
default:
return .purchased
}
}
}
@@ -56,6 +56,7 @@ func checkPurchasesEnums() {
switch oType! {
case .purchased,
.familyShared,
.assigned,
.unknown:
print(oType!)
@unknown default:
@@ -284,6 +284,7 @@ NSURL *url;
switch(o) {
case RCPurchaseOwnershipTypePurchased:
case RCPurchaseOwnershipTypeFamilyShared:
case RCPurchaseOwnershipTypeAssigned:
case RCPurchaseOwnershipTypeUnknown:
NSLog(@"%ld", (long)o);
}
@@ -65,6 +65,7 @@ func checkPurchasesEnums() {
switch oType! {
case .purchased,
.familyShared,
.assigned,
.unknown:
print(oType!)
@unknown default:
@@ -647,6 +647,24 @@ class EntitlementInfosTests: TestCase {
expect(entitlement.ownershipType) == .unknown
}
func testParseAssignedOwnershipTypeInEntitlementInfoAndSubscriptionInfo() throws {
stubResponse(entitlements: [
"pro_cat": [
"expires_date": "2200-07-26T23:50:40Z",
"product_identifier": "monthly_freetrial",
"purchase_date": "2019-07-26T23:45:40Z"
]
],
subscriptions: mockSubscriptions(ownershipType: "ASSIGNED"))
let customerInfo = try CustomerInfo(data: response)
let entitlement = try XCTUnwrap(customerInfo.entitlements.active["pro_cat"])
let subscription = try XCTUnwrap(customerInfo.subscriptionsByProductIdentifier["monthly_freetrial"])
expect(entitlement.ownershipType) == .assigned
expect(subscription.ownershipType) == .assigned
}
func testParseOwnershipTypeDefaultsToPurchasedIfMissing() throws {
let mockEntitlements = [
"pro_cat": [
@@ -13,6 +13,7 @@
import Nimble
@testable import RevenueCat
import StoreKit
import XCTest
class PurchaseOwnershipTypeTests: TestCase {
@@ -32,3 +33,19 @@ class PurchaseOwnershipTypeTests: TestCase {
}
}
// MARK: - From StoreKit OwnershipType
extension PurchaseOwnershipTypeTests {
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
func testFromStoreKitOwnershipType() throws {
try AvailabilityChecks.iOS15APIAvailableOrSkipTest()
expect(PurchaseOwnershipType.from(storeKitOwnershipType: .purchased)) == .purchased
expect(PurchaseOwnershipType.from(storeKitOwnershipType: .familyShared)) == .familyShared
#if compiler(>=6.4)
expect(PurchaseOwnershipType.from(storeKitOwnershipType: .assigned)) == .assigned
#endif
}
}
@@ -2265,6 +2265,7 @@ extension RevenueCat.PackageType : Swift.Codable {
case purchased = 0
case familyShared = 1
case unknown = 2
case assigned = 3
public init?(rawValue: Swift.Int)
public typealias RawValue = Swift.Int
public var rawValue: Swift.Int {
+1
View File
@@ -2265,6 +2265,7 @@ extension RevenueCat.PackageType : Swift.Codable {
case purchased = 0
case familyShared = 1
case unknown = 2
case assigned = 3
public init?(rawValue: Swift.Int)
public typealias RawValue = Swift.Int
public var rawValue: Swift.Int {
+1
View File
@@ -2232,6 +2232,7 @@ extension RevenueCat.PackageType : Swift.Codable {
case purchased = 0
case familyShared = 1
case unknown = 2
case assigned = 3
public init?(rawValue: Swift.Int)
public typealias RawValue = Swift.Int
public var rawValue: Swift.Int {
@@ -2232,6 +2232,7 @@ extension RevenueCat.PackageType : Swift.Codable {
case purchased = 0
case familyShared = 1
case unknown = 2
case assigned = 3
public init?(rawValue: Swift.Int)
public typealias RawValue = Swift.Int
public var rawValue: Swift.Int {
+1
View File
@@ -2232,6 +2232,7 @@ extension RevenueCat.PackageType : Swift.Codable {
case purchased = 0
case familyShared = 1
case unknown = 2
case assigned = 3
public init?(rawValue: Swift.Int)
public typealias RawValue = Swift.Int
public var rawValue: Swift.Int {
@@ -2265,6 +2265,7 @@ extension RevenueCat.PackageType : Swift.Codable {
case purchased = 0
case familyShared = 1
case unknown = 2
case assigned = 3
public init?(rawValue: Swift.Int)
public typealias RawValue = Swift.Int
public var rawValue: Swift.Int {
@@ -2265,6 +2265,7 @@ extension RevenueCat.PackageType : Swift.Codable {
case purchased = 0
case familyShared = 1
case unknown = 2
case assigned = 3
public init?(rawValue: Swift.Int)
public typealias RawValue = Swift.Int
public var rawValue: Swift.Int {
@@ -2233,6 +2233,7 @@ extension RevenueCat.PackageType : Swift.Codable {
case purchased = 0
case familyShared = 1
case unknown = 2
case assigned = 3
public init?(rawValue: Swift.Int)
public typealias RawValue = Swift.Int
public var rawValue: Swift.Int {
@@ -2233,6 +2233,7 @@ extension RevenueCat.PackageType : Swift.Codable {
case purchased = 0
case familyShared = 1
case unknown = 2
case assigned = 3
public init?(rawValue: Swift.Int)
public typealias RawValue = Swift.Int
public var rawValue: Swift.Int {