Skip to main content
ZeroSettle makes it easy to determine subscription status with the ZeroSettle SDK and REST API.

Getting subscription status via the SDK

The CustomerInfo 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():
// Using Swift Concurrency
do {
    let customerInfo = try await ZeroSettle.shared.customerInfo()
} catch {
    // handle error
}

// Using Completion Blocks
ZeroSettle.shared.getCustomerInfo { (customerInfo, error) in
    // access latest customerInfo
}
It’s safe to call 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 the CustomerInfo and EntitlementInfo objects. For most apps that only have one entitlement, the isActive status can be quickly checked for your entitlement ID.
if customerInfo.entitlements["your_entitlement_id"]?.isActive == true {
    // user has access to "your_entitlement_id"
}
If your app has multiple entitlements, you might also want to check if the customer has any active entitlements:
if !customerInfo.entitlements.active.isEmpty {
    // user has access to some entitlement
}
It’s important to note that 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 the restorePurchases method, even if you require all customers to create accounts.
do {
    let customerInfo = try await ZeroSettle.shared.restorePurchases()
    // access latest customerInfo
} catch {
    // handle error
}

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 call getCustomerInfo(), 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’s CustomerInfo 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.
// Option 1: using ZeroSettleDelegate:
ZeroSettle.configure(withAPIKey: <public_api_key>)
ZeroSettle.shared.delegate = self // make sure to set this after calling configure

extension AppDelegate: ZeroSettleDelegate {
    func zeroSettle(_ zeroSettle: ZeroSettle, receivedUpdated customerInfo: CustomerInfo) {
        // handle any changes to customerInfo
    }
}

// Option 2: using Swift Concurrency:
for try await customerInfo in ZeroSettle.shared.customerInfoStream {
    // handle any changes to customerInfo
}

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.
curl --request GET \
  --url https://api.zerosettle.io/v1/subscribers/app_user_id \
  --header 'Content-Type: application/json' \
  --header 'Authorization: Bearer PUBLIC_API_KEY'

Handling Refunds

ZeroSettle can handle refunds across all platforms for both subscription and non-subscription products. As soon as ZeroSettle detects a refund, the CustomerInfo will be updated to reflect the correct entitlement status - no action required on your part!