Skip to Content
Test

Stores

Fake App Store and Google Play backends with signed payloads, for the real adapters.

Usage

import { appstore } from "@dapplelight/signet-payments/appstore"
import { googleplay } from "@dapplelight/signet-payments/googleplay"
import { fakeAppStore, fakeGooglePlay } from "@dapplelight/signet-test/stores"

const apple = fakeAppStore()
const event = await appstore(apple.config).verifyWebhook(
  apple.notification("SUBSCRIBED", "INITIAL_BUY", apple.transaction({ productId: "pro.yearly" })),
)

const play = fakeGooglePlay()
play.subscribe("tok-1", { productId: "pro.monthly" })
await googleplay(play.config).verifyWebhook(play.notification(4, "tok-1")) // 4 = PURCHASED

fakeAppStore() builds an ECDSA certificate chain and fakeGooglePlay() an RSA JWKS and service account, all inside the test process (Node or Bun). Signed payloads verify through the adapter's own code.

API

ExportWhat it does
fakeAppStore(options?)A FakeAppStore.
fakeGooglePlay(options?)A FakeGooglePlay.
AppStoreTransactionType: { transactionId, originalTransactionId, productId, ... }.
AppStoreStatusType: 1 | 2 | 3 | 4 | 5.
FakeAppStore, FakeGooglePlayTypes.
PlayStateType: SUBSCRIPTION_STATE_ACTIVE, _CANCELED, _IN_GRACE_PERIOD, _ON_HOLD, _PAUSED, _EXPIRED.

fakeAppStore(options?)

OptionTypeDefault
bundleIdstring"com.example.app"App bundle id.
now() => numberDate.nowPass clock.now.
urlstring"https://app.example.test/webhooks/appstore"URL the notification requests are addressed to.
MemberWhat it does
configSpread into appstore(...).
callsWhat the adapter asked the fake App Store Server API.
transaction(overrides?)A Sandbox transaction with defaults.
sign(payload)Sign any payload as Apple would.
serve(transaction)Answer Get Transaction Info for a hand-built transaction.
notification(type, subtype, transaction, extra?)A signed notification Request.
subscribe({ productId?, price?, periodDays?, appAccountToken? })Returns { originalTransactionId, notification }.
renew(id)DID_RENEW.
failRenewal(id, { graceDays? })With graceDays, grace period (status 4, access kept); without, billing retry (status 3).
cancelRenewal(id)Auto-renew off; access lasts to period end.
expire(id)EXPIRED.
refund(id)REFUND: revoked, status 5.
revoke(id)REVOKE: Family Sharing withdrawn, status 5.

fakeGooglePlay(options?)

OptionTypeDefault
packageNamestring"com.example.app"
now() => numberDate.nowPass clock.now.
urlstring"https://app.example.test/webhooks/googleplay"Webhook URL; also the Pub/Sub token audience.
MemberWhat it does
configSpread into googleplay(...).
callsWhat the adapter asked the fake Play API, token endpoint and JWKS.
subscribe(token, { productId?, state?, periodDays?, price?, accountId? })Record an active subscription and its first order; returns the order id.
notification(type, token)A signed Pub/Sub push (4 purchased, 2 renewed, 3 canceled).
renew(token)RENEWED.
failRenewal(token, { graceDays? })In grace period with graceDays, on hold without.
cancel(token)CANCELED: access to period end.
expire(token)EXPIRED.
refund(token, { revoke? })Voided-purchase notification; with revoke (default true) a REVOKED follows. Returns the requests in order.

Examples

Grace period after a failed renewal

import { appstore } from "@dapplelight/signet-payments/appstore"
import { DAY, fakeClock } from "@dapplelight/signet-test"
import { fakeAppStore } from "@dapplelight/signet-test/stores"

const clock = fakeClock("2026-11-01T10:00:00Z")
const store = fakeAppStore({ now: clock.now })
const gw = appstore({ ...store.config, now: clock.now })

const { originalTransactionId, notification } = store.subscribe({ productId: "pro.monthly" })
await gw.verifyWebhook(notification)

clock.advance(30 * DAY)
await gw.verifyWebhook(store.failRenewal(originalTransactionId, { graceDays: 6 }))