@octane-xplat/billing 0.18.0 → 0.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -27
- package/package.json +90 -96
- package/src/billing.macos.ts +12 -11
- package/src/billing.ts +151 -94
- package/src/billing.web.ts +12 -11
- package/src/billing.windows.ts +14 -12
- package/src/types.ts +94 -51
- package/types/generated/.tsrx-typegen-manifest.json +0 -6
- package/types/generated/billing.d.ts +1 -0
- package/types/generated/types.d.ts +47 -5
- package/LICENSE +0 -21
- package/types/generated/billing.linux.d.ts +0 -1
- package/types/generated/billing.macos.d.ts +0 -2
- package/types/generated/billing.web.d.ts +0 -2
- package/types/generated/billing.windows.d.ts +0 -2
- package/types/generated/index.macos.d.ts +0 -2
- package/types/generated/index.web.d.ts +0 -2
package/README.md
CHANGED
|
@@ -1,29 +1,5 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @octane-xplat/billing
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
pnpm add @octane-xplat/billing
|
|
5
|
-
```
|
|
3
|
+
[Documentation](https://octane-xplat.goddardai.org/package-billing).
|
|
6
4
|
|
|
7
|
-
|
|
8
|
-
`@nativescript/payments`. Owns the store transaction loop; paywall UI and
|
|
9
|
-
server-side receipt validation stay in the app.
|
|
10
|
-
|
|
11
|
-
```ts
|
|
12
|
-
import { billing } from '@octane-xplat/billing'
|
|
13
|
-
|
|
14
|
-
billing.connect()
|
|
15
|
-
const unsubscribe = billing.onPurchase(async (purchases) => {
|
|
16
|
-
for (const p of purchases) {
|
|
17
|
-
await grantEntitlement(p)
|
|
18
|
-
await billing.finishTransaction(p)
|
|
19
|
-
}
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
const products = await billing.fetchProducts(['com.app.pro'], 'subs')
|
|
23
|
-
await billing.requestPurchase('com.app.pro')
|
|
24
|
-
const owned = await billing.getAvailablePurchases() // restore
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
Mirrors `expo-iap`/`react-native-iap` naming (fetchProducts, requestPurchase,
|
|
28
|
-
finishTransaction, getAvailablePurchases). Web/desktop report
|
|
29
|
-
`supported: false`.
|
|
5
|
+
[API reference](https://octane-xplat.goddardai.org/api-billing).
|
package/package.json
CHANGED
|
@@ -1,97 +1,91 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
"scripts": {
|
|
93
|
-
"typegen": "tsrx-typegen --target octane",
|
|
94
|
-
"pack:check": "tsrx-typegen --pack-check",
|
|
95
|
-
"typecheck": "node ../../scripts/typecheck.ts"
|
|
96
|
-
}
|
|
97
|
-
}
|
|
2
|
+
"name": "@octane-xplat/billing",
|
|
3
|
+
"version": "0.20.0",
|
|
4
|
+
"description": "In-app purchases and subscriptions for Octane xplat — StoreKit 2 and Play Billing via @nativescript/payments",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"android",
|
|
7
|
+
"cross-platform",
|
|
8
|
+
"nativescript",
|
|
9
|
+
"octane",
|
|
10
|
+
"xplat",
|
|
11
|
+
"iap",
|
|
12
|
+
"billing",
|
|
13
|
+
"storekit",
|
|
14
|
+
"purchases",
|
|
15
|
+
"subscriptions"
|
|
16
|
+
],
|
|
17
|
+
"homepage": "https://github.com/octane-xplat/octane-xplat/tree/main/packages/billing",
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "https://github.com/octane-xplat/octane-xplat",
|
|
22
|
+
"directory": "packages/billing"
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"src",
|
|
26
|
+
"platforms",
|
|
27
|
+
"types",
|
|
28
|
+
"!src/**/*.test.*",
|
|
29
|
+
"!src/**/*.spec.*"
|
|
30
|
+
],
|
|
31
|
+
"type": "module",
|
|
32
|
+
"exports": {
|
|
33
|
+
".": {
|
|
34
|
+
"types": "./types/generated/index.d.ts",
|
|
35
|
+
"macos": "./src/index.macos.ts",
|
|
36
|
+
"web": "./src/index.web.ts",
|
|
37
|
+
"native": "./src/index.ts",
|
|
38
|
+
"default": "./src/index.ts"
|
|
39
|
+
},
|
|
40
|
+
"./*": {
|
|
41
|
+
"types": "./types/generated/*.d.ts",
|
|
42
|
+
"default": "./src/*"
|
|
43
|
+
},
|
|
44
|
+
"./*.ts": {
|
|
45
|
+
"types": "./types/generated/*.d.ts",
|
|
46
|
+
"default": "./src/*.ts"
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
"publishConfig": {
|
|
50
|
+
"access": "public"
|
|
51
|
+
},
|
|
52
|
+
"scripts": {
|
|
53
|
+
"test": "node --test tests/*.test.mjs",
|
|
54
|
+
"typegen": "tsrx-typegen --target octane",
|
|
55
|
+
"prepack": "bun run typegen && tsrx-typegen --pack-check",
|
|
56
|
+
"pack:check": "tsrx-typegen --pack-check",
|
|
57
|
+
"typecheck": "node ../../scripts/typecheck.ts"
|
|
58
|
+
},
|
|
59
|
+
"devDependencies": {
|
|
60
|
+
"@nativescript-community/octane": "0.2.5",
|
|
61
|
+
"@nativescript/core": "9.1.3",
|
|
62
|
+
"@nativescript/types": "9.1.4",
|
|
63
|
+
"octane": "0.16.3",
|
|
64
|
+
"tsrx-typegen": "0.6.1",
|
|
65
|
+
"typescript": "7.1.0-beta",
|
|
66
|
+
"@tsrx/content-mapper": "0.1.2",
|
|
67
|
+
"typescript-classic": "npm:typescript@5.9.3"
|
|
68
|
+
},
|
|
69
|
+
"peerDependencies": {
|
|
70
|
+
"@nativescript-community/octane": ">=0.2.1 <1",
|
|
71
|
+
"@nativescript/core": ">=9.1.0 <10",
|
|
72
|
+
"octane": ">=0.6.3 <1"
|
|
73
|
+
},
|
|
74
|
+
"peerDependenciesMeta": {
|
|
75
|
+
"@nativescript-community/octane": {
|
|
76
|
+
"optional": true
|
|
77
|
+
},
|
|
78
|
+
"@nativescript/core": {
|
|
79
|
+
"optional": true
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
"nativescript": {
|
|
83
|
+
"platforms": {
|
|
84
|
+
"android": "9.1.0",
|
|
85
|
+
"ios": "9.1.0"
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
"dependencies": {
|
|
89
|
+
"@nativescript/payments": "4.0.1"
|
|
90
|
+
}
|
|
91
|
+
}
|
package/src/billing.macos.ts
CHANGED
|
@@ -4,16 +4,17 @@ import type { Billing } from './types'
|
|
|
4
4
|
|
|
5
5
|
const unsupported = () => Promise.reject(new Error('unsupported: billing is not wired on macOS'))
|
|
6
6
|
|
|
7
|
+
/** Store billing service — Play Billing / StoreKit. */
|
|
7
8
|
export const billing: Billing = {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
9
|
+
supported: false,
|
|
10
|
+
connect: () => Promise.resolve(),
|
|
11
|
+
disconnect: () => {},
|
|
12
|
+
canMakePayments: () => false,
|
|
13
|
+
fetchProducts: unsupported,
|
|
14
|
+
requestPurchase: unsupported,
|
|
15
|
+
onPurchase: () => () => {},
|
|
16
|
+
onPurchaseError: () => () => {},
|
|
17
|
+
getAvailablePurchases: unsupported,
|
|
18
|
+
finishTransaction: unsupported,
|
|
19
|
+
showManageSubscriptions: unsupported,
|
|
19
20
|
}
|
package/src/billing.ts
CHANGED
|
@@ -2,113 +2,170 @@
|
|
|
2
2
|
// Billing). One Payment client behind the flat service; purchase outcomes
|
|
3
3
|
// fan out to registered listeners.
|
|
4
4
|
import { Payment, type Product as NativeProduct, type Transaction } from '@nativescript/payments'
|
|
5
|
-
import type { Billing, Product, Purchase,
|
|
5
|
+
import type { Billing, Product, Purchase, RequestPurchaseOptions } from './types'
|
|
6
6
|
|
|
7
7
|
let client: Payment | null = null
|
|
8
|
+
let ready = false
|
|
9
|
+
const readyWaiters = new Set<() => void>()
|
|
8
10
|
const purchaseListeners = new Set<(purchases: Purchase[]) => void>()
|
|
9
11
|
const errorListeners = new Set<(error: { code: string; message: string }) => void>()
|
|
10
12
|
|
|
11
13
|
function asProduct(p: NativeProduct): Product {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
return {
|
|
15
|
+
id: p.id,
|
|
16
|
+
title: p.localizedTitle ?? p.title ?? p.name,
|
|
17
|
+
description: p.description,
|
|
18
|
+
type: p.type,
|
|
19
|
+
displayPrice: p.priceFormatted,
|
|
20
|
+
priceMicros: p.priceAmountMicros,
|
|
21
|
+
native: p,
|
|
22
|
+
}
|
|
20
23
|
}
|
|
21
24
|
|
|
22
25
|
function asPurchase(t: Transaction): Purchase {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
26
|
+
return {
|
|
27
|
+
productId: t.productId,
|
|
28
|
+
transactionId: t.orderId,
|
|
29
|
+
transactionDate: t.orderDate ?? null,
|
|
30
|
+
state: t.state,
|
|
31
|
+
type: t.type,
|
|
32
|
+
isAcknowledged: t.isAcknowledged,
|
|
33
|
+
receiptToken: t.receiptToken,
|
|
34
|
+
native: t,
|
|
35
|
+
}
|
|
33
36
|
}
|
|
34
37
|
|
|
35
38
|
function getClient(): Payment {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
39
|
+
if (!client) {
|
|
40
|
+
client = new Payment()
|
|
41
|
+
client.onReady = () => {
|
|
42
|
+
ready = true
|
|
43
|
+
for (const resolve of readyWaiters) {
|
|
44
|
+
resolve()
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
readyWaiters.clear()
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
client.onPurchaseUpdate = (purchases, error) => {
|
|
51
|
+
if (error) {
|
|
52
|
+
const out = {
|
|
53
|
+
code: (error as any)?.code ?? 'ERROR',
|
|
54
|
+
message: error.message ?? String(error),
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
for (const listener of errorListeners) {
|
|
58
|
+
listener(out)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const mapped = (purchases ?? []).map(asPurchase)
|
|
65
|
+
|
|
66
|
+
for (const listener of purchaseListeners) {
|
|
67
|
+
listener(mapped)
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return client
|
|
53
73
|
}
|
|
54
74
|
|
|
75
|
+
/** Store billing service — Play Billing / StoreKit. */
|
|
55
76
|
export const billing: Billing = {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
77
|
+
supported: Payment.isSupported(),
|
|
78
|
+
|
|
79
|
+
connect(): Promise<void> {
|
|
80
|
+
const c = getClient()
|
|
81
|
+
|
|
82
|
+
if (ready) {
|
|
83
|
+
return Promise.resolve()
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const pending = new Promise<void>((resolve) => readyWaiters.add(resolve))
|
|
87
|
+
|
|
88
|
+
c.connect()
|
|
89
|
+
return pending
|
|
90
|
+
},
|
|
91
|
+
|
|
92
|
+
disconnect(): void {
|
|
93
|
+
ready = false
|
|
94
|
+
client?.disconnect()
|
|
95
|
+
// @nativescript/payments 4.0.1 never re-fires onReady on a manually
|
|
96
|
+
// disconnected Payment (its internal flag stays set), so reconnecting
|
|
97
|
+
// needs a fresh client — a new Payment's init reconnects and re-arms
|
|
98
|
+
// the callback.
|
|
99
|
+
client = null
|
|
100
|
+
},
|
|
101
|
+
|
|
102
|
+
canMakePayments(): boolean {
|
|
103
|
+
return getClient().canMakePayments()
|
|
104
|
+
},
|
|
105
|
+
|
|
106
|
+
async fetchProducts(productIds: string[], type: 'inapp' | 'subs' = 'inapp'): Promise<Product[]> {
|
|
107
|
+
const products = await getClient().fetchProducts(productIds, type)
|
|
108
|
+
|
|
109
|
+
return (products ?? []).map(asProduct)
|
|
110
|
+
},
|
|
111
|
+
|
|
112
|
+
async requestPurchase(
|
|
113
|
+
product: Product | string,
|
|
114
|
+
options?: RequestPurchaseOptions,
|
|
115
|
+
): Promise<void> {
|
|
116
|
+
const c = getClient()
|
|
117
|
+
const { type, ...purchaseOptions } = options ?? {}
|
|
118
|
+
let native: NativeProduct | undefined
|
|
119
|
+
|
|
120
|
+
if (typeof product === 'string') {
|
|
121
|
+
const [fetched] = await c.fetchProducts([product], type ?? 'inapp')
|
|
122
|
+
|
|
123
|
+
if (!fetched) {
|
|
124
|
+
throw Object.assign(new Error(`billing.requestPurchase: product '${product}' not found`), {
|
|
125
|
+
code: 'PRODUCT_UNAVAILABLE',
|
|
126
|
+
})
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
native = fetched
|
|
130
|
+
} else {
|
|
131
|
+
native = product.native as NativeProduct | undefined
|
|
132
|
+
if (!native) {
|
|
133
|
+
throw new Error('billing.requestPurchase: product lacks its native store reference')
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
await c.purchaseProduct(native, purchaseOptions)
|
|
138
|
+
},
|
|
139
|
+
|
|
140
|
+
onPurchase(listener: (purchases: Purchase[]) => void): () => void {
|
|
141
|
+
purchaseListeners.add(listener)
|
|
142
|
+
return () => purchaseListeners.delete(listener)
|
|
143
|
+
},
|
|
144
|
+
|
|
145
|
+
onPurchaseError(listener): () => void {
|
|
146
|
+
errorListeners.add(listener)
|
|
147
|
+
return () => errorListeners.delete(listener)
|
|
148
|
+
},
|
|
149
|
+
|
|
150
|
+
async getAvailablePurchases(): Promise<Purchase[]> {
|
|
151
|
+
const transactions = await getClient().fetchPurchases()
|
|
152
|
+
|
|
153
|
+
return (transactions ?? []).map(asPurchase)
|
|
154
|
+
},
|
|
155
|
+
|
|
156
|
+
async finishTransaction(purchase: Purchase, options?: { consume?: boolean }): Promise<void> {
|
|
157
|
+
const native = purchase.native as Transaction | undefined
|
|
158
|
+
|
|
159
|
+
if (!native) {
|
|
160
|
+
throw new Error('billing.finishTransaction: purchase lacks its native transaction')
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
await native.finish(options)
|
|
164
|
+
},
|
|
165
|
+
|
|
166
|
+
async showManageSubscriptions(options?: { subscriptionGroupId?: string }): Promise<void> {
|
|
167
|
+
await getClient().showSubscriptionsManagement({
|
|
168
|
+
ios: { subscriptionGroupID: options?.subscriptionGroupId },
|
|
169
|
+
})
|
|
170
|
+
},
|
|
114
171
|
}
|
package/src/billing.web.ts
CHANGED
|
@@ -5,16 +5,17 @@ import type { Billing } from './types'
|
|
|
5
5
|
|
|
6
6
|
const unsupported = () => Promise.reject(new Error('unsupported: no store backend on web'))
|
|
7
7
|
|
|
8
|
+
/** Store billing service — Play Billing / StoreKit. */
|
|
8
9
|
export const billing: Billing = {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
10
|
+
supported: false,
|
|
11
|
+
connect: () => Promise.resolve(),
|
|
12
|
+
disconnect: () => {},
|
|
13
|
+
canMakePayments: () => false,
|
|
14
|
+
fetchProducts: unsupported,
|
|
15
|
+
requestPurchase: unsupported,
|
|
16
|
+
onPurchase: () => () => {},
|
|
17
|
+
onPurchaseError: () => () => {},
|
|
18
|
+
getAvailablePurchases: unsupported,
|
|
19
|
+
finishTransaction: unsupported,
|
|
20
|
+
showManageSubscriptions: unsupported,
|
|
20
21
|
}
|
package/src/billing.windows.ts
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
// Windows leaf — no store backend; report unsupported.
|
|
2
2
|
import type { Billing } from './types'
|
|
3
3
|
|
|
4
|
-
const unsupported = () =>
|
|
4
|
+
const unsupported = () =>
|
|
5
|
+
Promise.reject(new Error('unsupported: billing is not available on windows'))
|
|
5
6
|
|
|
7
|
+
/** Store billing service — Play Billing / StoreKit. */
|
|
6
8
|
export const billing: Billing = {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
9
|
+
supported: false,
|
|
10
|
+
connect: () => Promise.resolve(),
|
|
11
|
+
disconnect: () => {},
|
|
12
|
+
canMakePayments: () => false,
|
|
13
|
+
fetchProducts: unsupported,
|
|
14
|
+
requestPurchase: unsupported,
|
|
15
|
+
onPurchase: () => () => {},
|
|
16
|
+
onPurchaseError: () => () => {},
|
|
17
|
+
getAvailablePurchases: unsupported,
|
|
18
|
+
finishTransaction: unsupported,
|
|
19
|
+
showManageSubscriptions: unsupported,
|
|
18
20
|
}
|
package/src/types.ts
CHANGED
|
@@ -1,71 +1,114 @@
|
|
|
1
|
+
/** Store product kind: one-time 'inapp' or 'subs' subscription; 'unknown'
|
|
2
|
+
* when the store reports something else. */
|
|
1
3
|
export type ProductType = 'inapp' | 'subs' | 'unknown'
|
|
2
4
|
|
|
5
|
+
/** A store product as fetched from the app store. Prices are null until
|
|
6
|
+
* the store reports them (and priceMicros stays null on iOS). */
|
|
3
7
|
export interface Product {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
/** Store product identifier as registered in the console. */
|
|
9
|
+
id: string
|
|
10
|
+
/** Store-localized title. */
|
|
11
|
+
title: string
|
|
12
|
+
/** Store-localized description. */
|
|
13
|
+
description: string
|
|
14
|
+
/** 'inapp' or 'subs' as queried. */
|
|
15
|
+
type: ProductType
|
|
16
|
+
/** Localized price string ('$4.99') — null until the store reports it. */
|
|
17
|
+
displayPrice: string | null
|
|
18
|
+
/** Price in micros (1_000_000 = 1 unit) — null on iOS, which reports
|
|
19
|
+
* formatted price only at this API level. */
|
|
20
|
+
priceMicros: number | null
|
|
21
|
+
/** Underlying plugin product — pass the fetched Product back to
|
|
22
|
+
* requestPurchase so subscription offer details reach checkout. */
|
|
23
|
+
native?: unknown
|
|
14
24
|
}
|
|
15
25
|
|
|
26
|
+
/** Transaction lifecycle: 'pending' awaits external payment action
|
|
27
|
+
* (ask-to-buy, deferred); 'unknown' covers unmapped store states. */
|
|
16
28
|
export type PurchaseState = 'pending' | 'purchased' | 'unknown'
|
|
17
29
|
|
|
30
|
+
/** One store transaction returned by purchase updates or restore queries. */
|
|
18
31
|
export interface Purchase {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
+
/** The Product.id this transaction is for. */
|
|
33
|
+
productId: string
|
|
34
|
+
/** Play order id / StoreKit transaction id. */
|
|
35
|
+
transactionId: string
|
|
36
|
+
/** When the store recorded the transaction; null when unreported. */
|
|
37
|
+
transactionDate: Date | null
|
|
38
|
+
/** Normalized transaction state. */
|
|
39
|
+
state: PurchaseState
|
|
40
|
+
/** 'inapp' or 'subs'. */
|
|
41
|
+
type: ProductType
|
|
42
|
+
/** Play: acknowledged; StoreKit: finished. Unacknowledged consumables
|
|
43
|
+
* are re-delivered by the store until finishTransaction completes them. */
|
|
44
|
+
isAcknowledged: boolean
|
|
45
|
+
/** Receipt token for server-side verification (Play purchase token /
|
|
46
|
+
* StoreKit receipt data). */
|
|
47
|
+
receiptToken: string
|
|
48
|
+
/** Underlying plugin transaction — pass to finishTransaction internals
|
|
49
|
+
* when holding the raw reference is required. */
|
|
50
|
+
native?: unknown
|
|
32
51
|
}
|
|
33
52
|
|
|
53
|
+
/** Options for requestPurchase(); platform bags pass through to the store. */
|
|
34
54
|
export interface PurchaseOptions {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
55
|
+
/** Android obfuscated account/profile ids. */
|
|
56
|
+
accountId?: string
|
|
57
|
+
/** Play Billing overrides — obfuscated ids plus the EU personalized-price flag. */
|
|
58
|
+
android?: { accountId?: string; profileId?: string; isOfferPersonalized?: boolean }
|
|
59
|
+
/** StoreKit overrides — quantity and sandbox ask-to-buy simulation. */
|
|
60
|
+
ios?: { quantity?: number; simulatesAskToBuyInSandbox?: boolean }
|
|
39
61
|
}
|
|
40
62
|
|
|
63
|
+
/** requestPurchase() options: store options plus the product kind used to
|
|
64
|
+
* fetch an id before checkout. */
|
|
65
|
+
export interface RequestPurchaseOptions extends PurchaseOptions {
|
|
66
|
+
/** Product kind fetched when `requestPurchase` receives an id rather than
|
|
67
|
+
* a fetched Product; defaults to 'inapp'. Use 'subs' for subscriptions. */
|
|
68
|
+
type?: 'inapp' | 'subs'
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** A store-reported failure. */
|
|
41
72
|
export interface PurchaseError {
|
|
42
|
-
|
|
43
|
-
|
|
73
|
+
/** Normalized store error code (Play Billing response / StoreKit error
|
|
74
|
+
* mapped to shared spellings where possible). */
|
|
75
|
+
code: string
|
|
76
|
+
/** Human-readable store message. */
|
|
77
|
+
message: string
|
|
44
78
|
}
|
|
45
79
|
|
|
80
|
+
/** Store billing façade — Play Billing on Android, StoreKit on iOS.
|
|
81
|
+
* False `supported` on web/desktop leaves. */
|
|
46
82
|
export interface Billing {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
83
|
+
/** StoreKit/Play Billing client exists (false on web/desktop leaves). */
|
|
84
|
+
readonly supported: boolean
|
|
85
|
+
/** Connect the store client — call once at app start, before other calls.
|
|
86
|
+
* Resolves once the store reports ready; check canMakePayments() after it
|
|
87
|
+
* resolves. A call after disconnect() awaits the next readiness signal. */
|
|
88
|
+
connect(): Promise<void>
|
|
89
|
+
/** Release the store client connection. */
|
|
90
|
+
disconnect(): void
|
|
91
|
+
/** The device can make payments (parental controls off, store reachable). */
|
|
92
|
+
canMakePayments(): boolean
|
|
93
|
+
/** Fetch store metadata for console-registered product ids. */
|
|
94
|
+
fetchProducts(productIds: string[], type?: 'inapp' | 'subs'): Promise<Product[]>
|
|
95
|
+
/** Kick the OS purchase sheet. Pass the Product returned by fetchProducts —
|
|
96
|
+
* required for subscriptions, whose 'subs' fetch carries the store's offer
|
|
97
|
+
* details — or a product id, fetched internally as options.type
|
|
98
|
+
* (default 'inapp'). Outcomes arrive on onPurchase/onPurchaseError and
|
|
99
|
+
* must be completed with finishTransaction. */
|
|
100
|
+
requestPurchase(product: Product | string, options?: RequestPurchaseOptions): Promise<void>
|
|
101
|
+
/** Purchase-update listener; returns the unsubscribe function. */
|
|
102
|
+
onPurchase(listener: (purchases: Purchase[]) => void): () => void
|
|
103
|
+
/** Purchase-failure listener; returns the unsubscribe function. */
|
|
104
|
+
onPurchaseError(listener: (error: PurchaseError) => void): () => void
|
|
105
|
+
/** Owned/unconsumed purchases — the "restore" query on both stores. */
|
|
106
|
+
getAvailablePurchases(): Promise<Purchase[]>
|
|
107
|
+
/** Consume/acknowledge a completed purchase (Play: consume or
|
|
108
|
+
* acknowledge; StoreKit: finish). Options.consume = consumable flow. */
|
|
109
|
+
finishTransaction(purchase: Purchase, options?: { consume?: boolean }): Promise<void>
|
|
110
|
+
/** Native subscription management UI. */
|
|
111
|
+
showManageSubscriptions(options?: { subscriptionGroupId?: string }): Promise<void>
|
|
69
112
|
}
|
|
70
113
|
|
|
71
114
|
export declare const billing: Billing
|
|
@@ -1,24 +1,43 @@
|
|
|
1
|
+
/** Store product kind: one-time 'inapp' or 'subs' subscription; 'unknown'
|
|
2
|
+
* when the store reports something else. */
|
|
1
3
|
export type ProductType = 'inapp' | 'subs' | 'unknown';
|
|
4
|
+
/** A store product as fetched from the app store. Prices are null until
|
|
5
|
+
* the store reports them (and priceMicros stays null on iOS). */
|
|
2
6
|
export interface Product {
|
|
7
|
+
/** Store product identifier as registered in the console. */
|
|
3
8
|
id: string;
|
|
4
9
|
/** Store-localized title. */
|
|
5
10
|
title: string;
|
|
11
|
+
/** Store-localized description. */
|
|
6
12
|
description: string;
|
|
13
|
+
/** 'inapp' or 'subs' as queried. */
|
|
7
14
|
type: ProductType;
|
|
8
15
|
/** Localized price string ('$4.99') — null until the store reports it. */
|
|
9
16
|
displayPrice: string | null;
|
|
10
17
|
/** Price in micros (1_000_000 = 1 unit) — null on iOS, which reports
|
|
11
18
|
* formatted price only at this API level. */
|
|
12
19
|
priceMicros: number | null;
|
|
20
|
+
/** Underlying plugin product — pass the fetched Product back to
|
|
21
|
+
* requestPurchase so subscription offer details reach checkout. */
|
|
22
|
+
native?: unknown;
|
|
13
23
|
}
|
|
24
|
+
/** Transaction lifecycle: 'pending' awaits external payment action
|
|
25
|
+
* (ask-to-buy, deferred); 'unknown' covers unmapped store states. */
|
|
14
26
|
export type PurchaseState = 'pending' | 'purchased' | 'unknown';
|
|
27
|
+
/** One store transaction returned by purchase updates or restore queries. */
|
|
15
28
|
export interface Purchase {
|
|
29
|
+
/** The Product.id this transaction is for. */
|
|
16
30
|
productId: string;
|
|
17
31
|
/** Play order id / StoreKit transaction id. */
|
|
18
32
|
transactionId: string;
|
|
33
|
+
/** When the store recorded the transaction; null when unreported. */
|
|
19
34
|
transactionDate: Date | null;
|
|
35
|
+
/** Normalized transaction state. */
|
|
20
36
|
state: PurchaseState;
|
|
37
|
+
/** 'inapp' or 'subs'. */
|
|
21
38
|
type: ProductType;
|
|
39
|
+
/** Play: acknowledged; StoreKit: finished. Unacknowledged consumables
|
|
40
|
+
* are re-delivered by the store until finishTransaction completes them. */
|
|
22
41
|
isAcknowledged: boolean;
|
|
23
42
|
/** Receipt token for server-side verification (Play purchase token /
|
|
24
43
|
* StoreKit receipt data). */
|
|
@@ -27,38 +46,61 @@ export interface Purchase {
|
|
|
27
46
|
* when holding the raw reference is required. */
|
|
28
47
|
native?: unknown;
|
|
29
48
|
}
|
|
49
|
+
/** Options for requestPurchase(); platform bags pass through to the store. */
|
|
30
50
|
export interface PurchaseOptions {
|
|
31
51
|
/** Android obfuscated account/profile ids. */
|
|
32
52
|
accountId?: string;
|
|
53
|
+
/** Play Billing overrides — obfuscated ids plus the EU personalized-price flag. */
|
|
33
54
|
android?: {
|
|
34
55
|
accountId?: string;
|
|
35
56
|
profileId?: string;
|
|
36
57
|
isOfferPersonalized?: boolean;
|
|
37
58
|
};
|
|
59
|
+
/** StoreKit overrides — quantity and sandbox ask-to-buy simulation. */
|
|
38
60
|
ios?: {
|
|
39
61
|
quantity?: number;
|
|
40
62
|
simulatesAskToBuyInSandbox?: boolean;
|
|
41
63
|
};
|
|
42
64
|
}
|
|
65
|
+
/** requestPurchase() options: store options plus the product kind used to
|
|
66
|
+
* fetch an id before checkout. */
|
|
67
|
+
export interface RequestPurchaseOptions extends PurchaseOptions {
|
|
68
|
+
/** Product kind fetched when `requestPurchase` receives an id rather than
|
|
69
|
+
* a fetched Product; defaults to 'inapp'. Use 'subs' for subscriptions. */
|
|
70
|
+
type?: 'inapp' | 'subs';
|
|
71
|
+
}
|
|
72
|
+
/** A store-reported failure. */
|
|
43
73
|
export interface PurchaseError {
|
|
74
|
+
/** Normalized store error code (Play Billing response / StoreKit error
|
|
75
|
+
* mapped to shared spellings where possible). */
|
|
44
76
|
code: string;
|
|
77
|
+
/** Human-readable store message. */
|
|
45
78
|
message: string;
|
|
46
79
|
}
|
|
80
|
+
/** Store billing façade — Play Billing on Android, StoreKit on iOS.
|
|
81
|
+
* False `supported` on web/desktop leaves. */
|
|
47
82
|
export interface Billing {
|
|
48
83
|
/** StoreKit/Play Billing client exists (false on web/desktop leaves). */
|
|
49
84
|
readonly supported: boolean;
|
|
50
|
-
/** Connect the store client — call once at app start, before other calls.
|
|
51
|
-
|
|
85
|
+
/** Connect the store client — call once at app start, before other calls.
|
|
86
|
+
* Resolves once the store reports ready; check canMakePayments() after it
|
|
87
|
+
* resolves. A call after disconnect() awaits the next readiness signal. */
|
|
88
|
+
connect(): Promise<void>;
|
|
89
|
+
/** Release the store client connection. */
|
|
52
90
|
disconnect(): void;
|
|
53
91
|
/** The device can make payments (parental controls off, store reachable). */
|
|
54
92
|
canMakePayments(): boolean;
|
|
93
|
+
/** Fetch store metadata for console-registered product ids. */
|
|
55
94
|
fetchProducts(productIds: string[], type?: 'inapp' | 'subs'): Promise<Product[]>;
|
|
56
|
-
/** Kick the OS purchase sheet
|
|
57
|
-
*
|
|
95
|
+
/** Kick the OS purchase sheet. Pass the Product returned by fetchProducts —
|
|
96
|
+
* required for subscriptions, whose 'subs' fetch carries the store's offer
|
|
97
|
+
* details — or a product id, fetched internally as options.type
|
|
98
|
+
* (default 'inapp'). Outcomes arrive on onPurchase/onPurchaseError and
|
|
58
99
|
* must be completed with finishTransaction. */
|
|
59
|
-
requestPurchase(
|
|
100
|
+
requestPurchase(product: Product | string, options?: RequestPurchaseOptions): Promise<void>;
|
|
60
101
|
/** Purchase-update listener; returns the unsubscribe function. */
|
|
61
102
|
onPurchase(listener: (purchases: Purchase[]) => void): () => void;
|
|
103
|
+
/** Purchase-failure listener; returns the unsubscribe function. */
|
|
62
104
|
onPurchaseError(listener: (error: PurchaseError) => void): () => void;
|
|
63
105
|
/** Owned/unconsumed purchases — the "restore" query on both stores. */
|
|
64
106
|
getAvailablePurchases(): Promise<Purchase[]>;
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
The MIT License (MIT)
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 Alec Larson
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in
|
|
13
|
-
all copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
-
THE SOFTWARE.
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { billing } from './billing.web.js';
|