Skip to main content
Question

Determine if the purchase was subscription or consumable


Hi! I’m fairly new (started today) to using Revenue Cat so I may have missed it in the plethora of documentation. But when a user purchases an item, is there a way to tell what type was purchased?

So, for example, if I wanted to open sections of my app based on whether they subscribed or if they bought a temp access.

Would this be the correct way of implementing it:

1do {
2 let result = try await Purchases.shared.purchase(package: package)
3 self.isPurchasing = false
4 if !result.userCancelled {
5 if result.customerInfo.entitlements["lifetime"]?.isActive == true {
6 vm.isUserFullAccess = true
7 }
8 if result.customerInfo.entitlements["subscription"]?.isActive == true {
9 vm.isUserSubscribed = true
10 }
11
12 }
13} catch {
14 self.isPurchasing = false
15 print("[x] Error: \(error.localizedDescription)")
16}

Understandably, everywhere I need to check for access I use the: 

1// -- subscription access
2Purchases.shared.getCustomerInfo { customerInfo, error in
3 if customerInfo?.entitlements.all["subscriber"]?.isActive == true {
4 ...
5 }
6}
7
8
9or
10
11// -- lifetime access
12Purchases.shared.getCustomerInfo { customerInfo, error in
13 if customerInfo?.entitlements.all["lifetime"]?.isActive == true {
14 ...
15 }
16}
17
18
19or
20
21
22// -- lifetime or subscription
23Purchases.shared.getCustomerInfo { customerInfo, error in
24 if !customerInfo?.entitlements.active.isEmpty {
25 ...
26 }
27}
28

 

I’m trying to wrap my head around it and see if I can differentiate between the user types.

I’ve tagged iOS but I’m working solely on macOS - which is making testing harder than iOS it seems!

This post has been closed for comments

Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings