SDK reference
Horse Android SDK (preview)
The Horse Android SDK brings the same API to Google Play, the Kotlin way. An app sold on both stores keeps one Horse app, shared by its customers, entitlements, offerings and remote config.
The source is on GitHub: HorseRevenue/horsekit-android. It uses Kotlin, coroutines and Google Play Billing Library 9, and needs minSdk 24.
#Install
Once it's released, the SDK comes from Maven Central:
dependencies {
implementation("app.horserevenue:horsekit:1.0.0")
}Until then, ./gradlew :horsekit:publishToMavenLocal in the repository builds the same artifact into ~/.m2, and mavenLocal() in your repositories picks it up.
#Use
// Application.onCreate:
Horse.configure(this, HorseConfiguration(apiKey = "pk_…", appUserId = currentUserId)) // null → anonymous
// A paywall, from a coroutine:
val offerings = Horse.shared.offerings()
val result = Horse.shared.purchase(activity, offerings.current!!.monthly!!)
if (!result.userCancelled) close()
// Access:
if (Horse.shared.isEntitled("pro")) unlock()
Horse.shared.customerInfoFlow.collect { info -> render(info?.isEntitled("pro") == true) }
// Remote config:
val headline = Horse.shared.remoteConfig.string("paywall_headline")#How it maps to Google Play
- Products. A subscription is one product per base plan, written
subscriptionId:basePlanId(premium:monthly). A one-time product is its product id. Entitlements attach exactly as on iPhone. - Offerings. Each package names its Play product next to its App Store one. A package with only one store's product shows only on that store's devices.
- Which offer is bought.
purchasebuys the package's default option: the longest free trial Play still offers this person, then the cheapest intro price, then the base plan. Pass aSubscriptionOptionfromstoreProduct.subscriptionOptionsto choose another. Tag an offerhorse-ignore-offerin Play Console to keep it from being picked by default. - Upgrades and downgrades.
purchase(activity, pkg, oldPurchaseToken = current.purchaseToken)replaces that subscription now, with the unused time credited. - Restore.
restorePurchases(), behind a Restore button. As on iPhone, a fresh install starts locked (RestorePolicy.ON_RESTORE).RestorePolicy.AUTOMATICclaims at launch instead. - Pending payments. A purchase Play holds, such as cash or a slow card, throws
HorseException.PurchasePending. It reaches Horse by itself once it's paid. - Acknowledgement. Horse acknowledges each purchase once it has stored it. If Horse can't be reached for two days, the device acknowledges it itself, because Google refunds a purchase nobody acknowledged within three days.
Sign-in (logIn, logOut), paywall conversion (paywallShown, paywallClosed), analytics (track, screen) and access codes (redeem) work as on iPhone.
#Notifications
Google's real-time developer notifications play the part of Apple's App Store Server Notifications. The app's SDK & settings tab shows the Pub/Sub topic to paste into Play Console → Monetize with Play → Monetization setup. Until it's set, renewals and cancellations reach Horse only when the app opens.