Getting subscription status via the SDK
Theentitlements property contains all of the purchase and subscription data available about a user. This is updated whenever a purchase completes or when you call restoreEntitlements().
restoreEntitlements() frequently throughout your app. The SDK caches entitlements locally and the network request is lightweight.
Checking If A User Is Subscribed
The subscription status for a user can be determined using theEntitlement objects returned by restoreEntitlements().
For most apps with a single premium tier, check for a specific product:
Entitlements will be empty if no purchases have been made. Always handle the empty case in your UI.
Restoring Purchases
Restoring purchases allows users to recover their in-app purchases on a new device or after reinstalling the app. It is recommended that all apps have a way for users to trigger restore, even if you require accounts.syncStoreKitTransactions is enabled).
Cache
The SDK caches the user’s subscription information to reduce your app’s reliance on the network. Users who unlock entitlements will be able to access them even without an internet connection. The SDK will update the cache if it’s older than 5 minutes when you callrestoreEntitlements(), make a purchase, or restore purchases. It’s a good idea to call restoreEntitlements() any time a user accesses premium content.
Listening For Entitlement Updates
Entitlements can change from various sources: web checkout completion, StoreKit transaction updates, or subscription renewals/cancellations. Use the delegate to respond to changes:entitlements published property in SwiftUI:
Entitlement updates are triggered by SDK operations (purchases, restores). They are not pushed from the backend in real-time.
Getting subscription status via the REST API
If you need to get a user’s subscription status from outside of the ZeroSettle SDK, for example, from your own backend, you should use the REST API.Handling Refunds
ZeroSettle handles refunds for both subscription and non-subscription products. As soon as a refund is processed, the entitlements will be updated to reflect the correct status — no action required on your part. TheisActive property on the affected Entitlement will be set to false.