Repository navigation
Description
Context
A phone app built with NSGo cannot sell anything through the stores. At 7eba948 nothing in the tree calls StoreKit (Product, Transaction, SKPaymentQueue) or Google Play Billing (BillingClient), and docs/roadmap.md has no row for purchases.
On iOS this could be added the way the other Apple services are, in internal/platform/apple. On Android, a standalone app has no Gradle build of its own. nsgo build assembles the APK from the committed classes.dex and the runtime's fixed manifest, so a library like com.android.billingclient cannot be added. docs/architecture/remote-push.md:27 describes the same boundary for FCM ("nothing can add an adapter there until the tool packages a tested one"). Today only an -embed host can add it, and that means writing its own Kotlin or Swift purchase layer behind the host channel (docs/architecture/embedding.md).
Why it matters
Most paid phone apps sell subscriptions or unlocks, and both App Store and Play require digital goods to go through their billing. Without this an app either cannot move to NSGo, or has to keep a native host for purchases alone. A dictionary app moving its React Native build (expo-iap) to NSGo uses every one of these calls:
- Fetching products and their localized prices. Prices come from the store and must never be hard-coded.
- Starting a purchase of a subscription with an account token, so the server can tie the transaction to the user. That is
appAccountTokenon StoreKit 2, andobfuscatedAccountIdplus a chosen offer'sofferTokenandbasePlanIdon Play. - Listening for purchase updates and errors, including those that arrive at launch (renewals, Ask to Buy, pending purchases).
- Sending the signed transaction (StoreKit 2 JWS, Play
purchaseToken) to the app's server for verification, then finishing or acknowledging it. - Restoring purchases or listing current entitlements.
- Opening the platform's subscription management page.
Proposal
A purchases service in core (or a package of its own, like microphone):
Products(ids)returns the localized title, display price and subscription offers.Purchase(product, offer, accountToken)answers purchased, pending, cancelled or failed. A purchase carries the platform's signed payload and an opaque ID.OnPurchaseUpdatedelivers purchases that complete outside aPurchasecall, kept for the first handler after launch asOnNotificationPresskeeps its press.Finish(purchase)covers StoreKit'sfinish()and Play's acknowledge or consume.CurrentEntitlements()/ restore.ManageSubscriptions().- iOS and macOS: StoreKit 2.
- Android: Play Billing, which needs the same decision remote push needs for FCM: how a standalone app gets a Google library and its manifest entries.
- Unavailable on the other targets.
Acceptance
core: the requests and their answers, thedriveritems and events, anAccesscapability incore/access.goand its TSX check.- iOS: a sandbox purchase of a subscription and a consumable on a device, with the StoreKit configuration file working in the simulator.
- Android: a license-tester purchase on a device through an internal test track. That also covers a store upload, which the roadmap's "Store packages accepted" row tracks.
nsgotest: a model that fakes products, purchases, pending and failed answers, and updates at launch.- Docs:
docs/architecture/services.md,docs/public/*/services.md,docs/roadmap.md.
Activity
houko commentedon Nov 16, 2026
Design notes before any code, since two parts of this need a maintainer decision.
iOS and macOS: StoreKit 2 is Swift-only.
Product,Transaction,Product.purchase(options:)with.appAccountToken(_:),Transaction.updatesandTransaction.currentEntitlementsare Swift structs and async sequences with no Objective-C surface, so the purego/objc pathinternal/platform/appleuses cannot reach them. The fallback, StoreKit 1 (SKPaymentQueue,SKProductsRequest), still works, but it is deprecated since iOS 18 and gives no JWS transactions, so a server would have to keep using the deprecatedverifyReceipt. The tool already compiles Swift with Xcode's swiftc, for widgets (cmd/nsgo/widgets.go) and the watchOS host (cmd/nsgo/watchos.go). Proposal: a small Swift shim incmd/nsgo, compiled the same way only whennsgo.yamlasks for purchases. It exposes@_cdeclC functions (fetch products, purchase with an account token, finish, current entitlements, an updates callback) that the Apple backend calls, passing JSON across. Apps that do not use purchases link none of it, as what an app links wants.Android: Play Billing is a Google library, the same boundary as FCM.
com.android.billingclient:billingis an AAR with its own manifest entries (com.android.vending.BILLING, a proxy activity). Asdocs/architecture/remote-push.md:27says for FCM, a standalone app's APK is assembled from the committedclasses.dexand the runtime's fixed manifest, so nothing can add it. This looks like the same call as remote push's open decision 2, generalized: doesnsgo buildpackage prebuilt, optional adapters committed besideclasses.dex(one for FCM, one for Billing), with their manifest fragments merged whennsgo.yamlenables them? Or do Google-library features stay with-embedhosts? The library's license (Android Software Development Kit License, not Apache-2.0) may also decide whether a prebuilt copy can be committed here. That needs checking before the first option is chosen. Until it is decided, Android could answer purchases unavailable in standalone apps and route them to the host through the host channel in embedded ones.API shape, from an app now using
expo-iap:Products(ids);Purchase(product, offer, accountToken)answering purchased / pending / cancelled / failed, with the platform's signed payload (JWS orpurchaseToken) for server verification;OnPurchaseUpdate, kept for the first handler after launch;Finish;CurrentEntitlements;ManageSubscriptions. The account token is a UUID on StoreKit 2 andobfuscatedAccountIdon Play, so the API should take a UUID-shaped string and document the mapping.If the Swift-shim approach for Apple is acceptable, the Apple half can land first behind
Env.CanPurchase, with Android following whichever way decision 2 goes.feat(core): in-app purchases through StoreKit 2