Getting subscription status via the SDK
TheCustomerInfo object contains all of the purchase and subscription data available about a customer.
This object is updated whenever a purchase or restore occurs and periodically throughout the lifecycle of your app. The latest information can always be retrieved by calling getCustomerInfo():
getCustomerInfo() frequently throughout your app. Since the SDK updates and caches the latest CustomerInfo when the app becomes active, the completion block won’t need to make a network request in most cases.
Checking If A User Is Subscribed
The subscription status for a user can easily be determined with theCustomerInfo and EntitlementInfo objects.
For most apps that only have one entitlement, the isActive status can be quickly checked for your entitlement ID.
CustomerInfo will be empty if no purchases have been made and no transactions have been synced. This means that entitlements may not exist in CustomerInfo even if they have been set up in the ZeroSettle dashboard.
Restoring Purchases
Restoring purchases is a mechanism by which your user can restore their in-app purchases, reactivating any content that had previously been purchased from the same store account. It is recommended that all apps have some way for users to trigger therestorePurchases method, even if you require all customers to create accounts.
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, but only if you callgetCustomerInfo(), make a purchase, or restore purchases, so it’s a good idea to call getCustomerInfo() any time a user accesses premium content.
Listening For CustomerInfo Updates
Since ZeroSettle SDK works seamlessly on any platform, a user’sCustomerInfo may change from a variety of sources. You can respond to any changes in CustomerInfo by conforming to an optional delegate method, zeroSettle:receivedUpdated:. This will fire whenever we receive a change in CustomerInfo on the current device and you should expect it to be called at launch and throughout the life of the app.
CustomerInfo updates are not pushed to your app from the ZeroSettle backend, updates can only happen from an outbound network request to ZeroSettle.
Depending on your app, it may be sufficient to ignore the delegate and simply handle changes to customer information the next time your app is launched. Or throughout your app as you request new CustomerInfo objects.
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 can handle refunds across all platforms for both subscription and non-subscription products. As soon as ZeroSettle detects a refund, theCustomerInfo will be updated to reflect the correct entitlement status - no action required on your part!
