Question

Determine if the purchase was subscription or consumable

  • 2 October 2022
  • 0 replies
  • 22 views

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:

do {
let result = try await Purchases.shared.purchase(package: package)
self.isPurchasing = false
if !result.userCancelled {
if result.customerInfo.entitlements["lifetime"]?.isActive == true {
vm.isUserFullAccess = true
}
if result.customerInfo.entitlements["subscription"]?.isActive == true {
vm.isUserSubscribed = true
}

}
} catch {
self.isPurchasing = false
print("[x] Error: \(error.localizedDescription)")
}

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

// -- subscription access
Purchases.shared.getCustomerInfo { customerInfo, error in
if customerInfo?.entitlements.all["subscriber"]?.isActive == true {
...
}
}


or

// -- lifetime access
Purchases.shared.getCustomerInfo { customerInfo, error in
if customerInfo?.entitlements.all["lifetime"]?.isActive == true {
...
}
}


or


// -- lifetime or subscription
Purchases.shared.getCustomerInfo { customerInfo, error in
if !customerInfo?.entitlements.active.isEmpty {
...
}
}

 

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!


0 replies

Be the first to reply!

Reply