Skip to content

[Feature] In-app purchases and subscriptions: StoreKit 2 and Google Play Billing #353

Closed

Description

@houko

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 appAccountToken on StoreKit 2, and obfuscatedAccountId plus a chosen offer's offerToken and basePlanId on 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.
  • OnPurchaseUpdate delivers purchases that complete outside a Purchase call, kept for the first handler after launch as OnNotificationPress keeps its press.
  • Finish(purchase) covers StoreKit's finish() 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, the driver items and events, an Access capability in core/access.go and 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

  1. houko commented on Nov 16, 2026

    @houko
    CollaboratorAuthor

    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.updates and Transaction.currentEntitlements are Swift structs and async sequences with no Objective-C surface, so the purego/objc path internal/platform/apple uses 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 deprecated verifyReceipt. 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 in cmd/nsgo, compiled the same way only when nsgo.yaml asks for purchases. It exposes @_cdecl C 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:billing is an AAR with its own manifest entries (com.android.vending.BILLING, a proxy activity). As docs/architecture/remote-push.md:27 says for FCM, a standalone app's APK is assembled from the committed classes.dex and the runtime's fixed manifest, so nothing can add it. This looks like the same call as remote push's open decision 2, generalized: does nsgo build package prebuilt, optional adapters committed beside classes.dex (one for FCM, one for Billing), with their manifest fragments merged when nsgo.yaml enables them? Or do Google-library features stay with -embed hosts? 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 or purchaseToken) for server verification; OnPurchaseUpdate, kept for the first handler after launch; Finish; CurrentEntitlements; ManageSubscriptions. The account token is a UUID on StoreKit 2 and obfuscatedAccountId on 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.

  2. added a commit that references this issue on Nov 16, 2026
    7f2273b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    AndroidcoreenhancementiOSmacOS

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions