horse revenue Docs

Guides

Customers and accounts

Every install is a customer. It's anonymous until your app signs the person in, and its page in the dashboard shows everything they bought, every renewal and what they have access to now.

#Is this person entitled?

Horse.shared.isEntitled("pro")                     // synchronous, from the cache, any thread

let info = try await Horse.shared.customerInfo()   // fetched when the cache is over 5 minutes old
info.isEntitled("pro")
info.entitlements["pro"]?.expirationDate
info.entitlements["pro"]?.willRenew

Use isEntitled rather than reading entitlements.active yourself. It also respects access blocked from the dashboard, and an expiry that passed while the app was open.

To follow changes, use customerInfoStream, the @Published customerInfo property, or Horse.customerInfoDidChangeNotification. See checking access.

#Anonymous and signed-in customers

Without accounts, each install is an anonymous customer, and that's fine. When your app has sign-in, pass your own user id:

// At launch, if someone is already signed in:
Horse.configure(apiKey: "pk_…", appUserID: currentUser?.id, baseURL: horseURL)

// When someone signs in:
try await Horse.shared.logIn(user.id)    // merges the anonymous customer into this one
try await Horse.shared.syncPurchases()   // and claims what this Apple Account bought

// When they sign out:
try await Horse.shared.logOut()          // back to a fresh anonymous id

Purchases stay with the signed-in customer on the server. After logOut, StoreKit still knows the device's purchases, so restorePurchases() brings them back.

#Attributes

Facts about the customer, shown on their page and sent to your integrations. Keys starting with $ are reserved.

await Horse.shared.setEmail("ana@example.com")
await Horse.shared.setDisplayName("Ana")
await Horse.shared.setAttributes(["plan_source": "onboarding", "old_key": nil])   // nil removes it

#In the dashboard

The Customers tab finds anyone by app user id, alias, original transaction id, appAccountToken, email or access code. A customer's page shows their subscriptions with every renewal, refund and billing problem, their entitlements, attributes, attribution, the experiments they're in and their history. From there, people with the right role can:

  • Grant an entitlement for some days or for life, for a customer you're making amends with or a tester.
  • Refresh from the store, if something looks out of date.
  • Block an entitlement for testing: the app locks on its next refresh, and the purchase stays on file.
  • Merge two customers that turn out to be the same person.

Every action is recorded in the customer's history, with who did it and why.