Skip to content

About

Microsoft Store in-app purchase bindings (Windows.Services.Store) for Perry

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

@perryts/microsoft-store

Microsoft Store in-app purchase bindings (Windows.Services.Store) for Perry. The Windows counterpart of @perryts/storekit (Apple) and @perryts/play-billing (Android), with the same shape: native calls that resolve with JSON strings.

Platforms

Target Implementation
Windows 10 (2004) / 11, x64 Native: Rust over Windows.Services.Store (windows-rs). Needs an MSIX: see below
Everything else Stub: js_ms_store_available() is 0 and every call resolves with a "not available" payload

Building needs only a Rust toolchain (MSVC target on Windows). No Windows SDK headers, no C++ and no .NET: the WinRT projections come from windows-rs, and the app links WindowsApp.lib, which every MSVC install has.

Package identity

The Store answers only an app with package identity: an MSIX installed from the Store, or one installed locally whose identity (Name and Publisher) is the one Partner Center reserved for the app. A plain .exe has none, so js_ms_store_available() returns 0 and an app should treat that build as having no store. To test purchases before release:

  1. Reserve the app in Partner Center and create its add-ons. Each add-on's Product ID is what you pass to these calls. Use the same ID as on the App Store and Google Play, and the calling code can share one product table.
  2. Publish the app at least once. Hiding it from search with "Make this product available but not discoverable" or "Private audience" is enough. Install it from the Store on the test PC. That gives the PC a license for the app.
  3. Build an MSIX with the Store's identity (Package/Identity/Name and Publisher from Product identity), signed with a test certificate whose subject is that Publisher, and install it over the Store copy. Purchases then go through the real Store with your Microsoft account. Test accounts can be refunded in Partner Center.

Installation

npm install @perryts/microsoft-store

and allow the native library in the app's package.json:

"perry": { "allow": { "nativeLibrary": ["@perryts/microsoft-store"] } }

ABI: perry-ffi v0.5 (perry.nativeLibrary.abiVersion), pinned to the same Perry release as @perryts/storekit.

Quick start

import {
  js_ms_store_available, js_ms_store_start_listener, js_ms_store_license_changes,
  js_ms_store_load_products, js_ms_store_purchase, js_ms_store_query_purchases,
} from "@perryts/microsoft-store";

if (js_ms_store_available() === 1) {
  js_ms_store_start_listener();

  // products by Partner Center Product ID (or Store ID); "" lists every add-on
  const products = JSON.parse(await js_ms_store_load_products("com.example.full"));
  console.log(products[0]?.displayPrice);          // "$6.99"

  // the Store's purchase dialog, parented to the app's window
  const r = JSON.parse(await js_ms_store_purchase("com.example.full"));
  if (r.success) { /* Succeeded or AlreadyPurchased */ }
  else if (r.cancelled) { /* closed the dialog */ }

  // what the account owns (durables and subscriptions), available offline
  const owned = JSON.parse(await js_ms_store_query_purchases())
    .some((l: { productId: string; isActive: boolean }) => l.productId === "com.example.full" && l.isActive);

  // purchases made elsewhere, refunds, a parent's approval: poll the counter
  let seen = js_ms_store_license_changes();
  setInterval(() => {
    if (js_ms_store_license_changes() !== seen) { seen = js_ms_store_license_changes(); /* query again */ }
  }, 1000);
}

API

Function Resolves with
js_ms_store_available(): number 1 with package identity, else 0 (synchronous)
js_ms_store_start_listener(): void Subscribes to OfflineLicensesChanged (idempotent)
js_ms_store_license_changes(): number License changes seen so far (synchronous)
js_ms_store_load_products(ids) Product[]: id, storeId, title, description, displayPrice, productKind, isOwned
js_ms_store_purchase(id) {success, productId, storeId, status}; on failure cancelled or error
js_ms_store_query_purchases() License[]: productId, storeId, skuStoreId, isActive, expiresAt (Unix ms)
js_ms_store_customer_ids(collectionsTicket, purchaseTicket, publisherUserId) {collectionsId, purchaseId}: Store ID keys for your service (collections and purchase/recurrence REST APIs), bound to publisherUserId and valid 90 days. Your service mints the two Azure AD tickets (audiences https://onestore.microsoft.com/b2b/keys/create/collections and .../purchase)

Failures resolve with {"success": false, "error": "0x803F6107 …"} and never reject. The error names the HRESULT. 0x803F6107 usually means the installed package's identity isn't the Store's.

There is no restore: licenses follow the Microsoft account, so querying purchases is the restore. Consumables (StoreContext.ReportConsumableFulfillmentAsync) are not wrapped yet.

How it works

Each call runs on a Perry worker thread in the multithreaded apartment and blocks there on the WinRT operation. The JSON answer becomes a JS string on the main thread (resolve_with). A desktop app has to give StoreContext a window (IInitializeWithWindow) for the purchase dialog. The package picks it itself: the foreground window if it belongs to the process, otherwise the process's first visible top-level window.

License

MIT

About

Microsoft Store in-app purchase bindings (Windows.Services.Store) for Perry

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages