@octane-xplat/billing 0.19.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 +2 -77
- package/package.json +5 -4
- package/src/billing.macos.ts +11 -11
- package/src/billing.ts +147 -131
- package/src/billing.web.ts +11 -11
- package/src/billing.windows.ts +12 -12
- package/src/types.ts +78 -78
- package/types/generated/.tsrx-typegen-manifest.json +0 -6
- package/types/generated/billing.linux.d.ts +0 -1
- package/types/generated/billing.macos.d.ts +0 -3
- package/types/generated/billing.web.d.ts +0 -3
- package/types/generated/billing.windows.d.ts +0 -3
- package/types/generated/index.macos.d.ts +0 -2
- package/types/generated/index.web.d.ts +0 -2
package/README.md
CHANGED
|
@@ -1,80 +1,5 @@
|
|
|
1
1
|
# @octane-xplat/billing
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
through StoreKit and Google Play Billing. Your app owns the screen, backend
|
|
5
|
-
verification and entitlement ledger. Web and desktop report `supported: false`.
|
|
6
|
-
For the complete purchase/restore path, follow [Sell and restore an in-app purchase](https://octane-xplat.goddardai.org/in-app-purchases).
|
|
3
|
+
[Documentation](https://octane-xplat.goddardai.org/package-billing).
|
|
7
4
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
Install in an existing Xplat app:
|
|
11
|
-
|
|
12
|
-
```sh
|
|
13
|
-
bun add @octane-xplat/billing
|
|
14
|
-
```
|
|
15
|
-
|
|
16
|
-
Register a non-consumable product and test account first, following the
|
|
17
|
-
[guide's store setup](https://octane-xplat.goddardai.org/in-app-purchases#register-one-product).
|
|
18
|
-
Use its exact product ID in a screen action. The result contains the store's
|
|
19
|
-
title and localized price; keep the connection for the billing owner's lifetime:
|
|
20
|
-
|
|
21
|
-
```ts
|
|
22
|
-
import { billing } from '@octane-xplat/billing'
|
|
23
|
-
|
|
24
|
-
export async function readProduct(productId: string) {
|
|
25
|
-
if (!billing.supported) return { status: 'unavailable' as const }
|
|
26
|
-
await billing.connect()
|
|
27
|
-
if (!billing.canMakePayments()) return { status: 'retry' as const }
|
|
28
|
-
const products = await billing.fetchProducts([productId], 'inapp')
|
|
29
|
-
return { status: 'loaded' as const, product: products[0] ?? null }
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export function closeBillingOwner() {
|
|
33
|
-
billing.disconnect()
|
|
34
|
-
}
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
Handle a rejected read in your screen's error state. `connect()` resolves once
|
|
38
|
-
the store reports ready, including reconnects after `disconnect()`. A `retry`
|
|
39
|
-
result after a resolved connect means the store setup failed or payments are
|
|
40
|
-
restricted; offer Reload store after checking the store account. If a loaded
|
|
41
|
-
product is absent, check its ID, app identity, availability and tester setup.
|
|
42
|
-
Release the owner when it ends; do not disconnect immediately after initiating
|
|
43
|
-
a purchase.
|
|
44
|
-
|
|
45
|
-
## Complete and restore safely
|
|
46
|
-
|
|
47
|
-
Use the [maintained controller and screen](https://octane-xplat.goddardai.org/in-app-purchases#own-the-store-connection-and-screen)
|
|
48
|
-
for listeners installed before purchase initiation, authenticated verification,
|
|
49
|
-
pending/cancelled states, duplicate events, restore and disposal. A returned
|
|
50
|
-
purchase request is not proof of payment. The backend must verify and durably
|
|
51
|
-
grant before the app finishes a purchased transaction:
|
|
52
|
-
|
|
53
|
-
```ts
|
|
54
|
-
import { billing, type Purchase } from '@octane-xplat/billing'
|
|
55
|
-
|
|
56
|
-
export async function finishVerifiedPurchase(purchase: Purchase) {
|
|
57
|
-
// Only after server verification and durable entitlement commit.
|
|
58
|
-
await billing.finishTransaction(purchase, { consume: false })
|
|
59
|
-
}
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
The purchase object must retain its native transaction reference. Query the
|
|
63
|
-
store again after restart instead of persisting this object as JSON. The guide
|
|
64
|
-
specifies the [backend contract](https://octane-xplat.goddardai.org/in-app-purchases#implement-the-backend-contract-before-buying)
|
|
65
|
-
and recovery checks; the package supplies neither a server verifier nor an
|
|
66
|
-
entitlement database.
|
|
67
|
-
|
|
68
|
-
Subscriptions initiate through the product returned by a `'subs'` fetch, which
|
|
69
|
-
carries the store's offer details into checkout:
|
|
70
|
-
|
|
71
|
-
```ts
|
|
72
|
-
const [plan] = await billing.fetchProducts(['com.example.plan.monthly'], 'subs')
|
|
73
|
-
if (plan) await billing.requestPurchase(plan)
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
On Google Play the store applies the product's first offer; choosing between
|
|
77
|
-
base plans or offers and changing an active subscription are not exposed at
|
|
78
|
-
this level. Listing a subscription does not qualify its checkout. Use the
|
|
79
|
-
guide's [support and recovery boundaries](https://octane-xplat.goddardai.org/in-app-purchases#buy-finish-and-recover)
|
|
80
|
-
before choosing consumables or subscriptions.
|
|
5
|
+
[API reference](https://octane-xplat.goddardai.org/api-billing).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@octane-xplat/billing",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.20.0",
|
|
4
4
|
"description": "In-app purchases and subscriptions for Octane xplat — StoreKit 2 and Play Billing via @nativescript/payments",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"android",
|
|
@@ -60,10 +60,11 @@
|
|
|
60
60
|
"@nativescript-community/octane": "0.2.5",
|
|
61
61
|
"@nativescript/core": "9.1.3",
|
|
62
62
|
"@nativescript/types": "9.1.4",
|
|
63
|
-
"@tsrx/typescript-plugin": "0.4.11",
|
|
64
63
|
"octane": "0.16.3",
|
|
65
|
-
"tsrx-typegen": "0.
|
|
66
|
-
"typescript": "
|
|
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"
|
|
67
68
|
},
|
|
68
69
|
"peerDependencies": {
|
|
69
70
|
"@nativescript-community/octane": ">=0.2.1 <1",
|
package/src/billing.macos.ts
CHANGED
|
@@ -6,15 +6,15 @@ const unsupported = () => Promise.reject(new Error('unsupported: billing is not
|
|
|
6
6
|
|
|
7
7
|
/** Store billing service — Play Billing / StoreKit. */
|
|
8
8
|
export const billing: Billing = {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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,
|
|
20
20
|
}
|
package/src/billing.ts
CHANGED
|
@@ -11,145 +11,161 @@ const purchaseListeners = new Set<(purchases: Purchase[]) => void>()
|
|
|
11
11
|
const errorListeners = new Set<(error: { code: string; message: string }) => void>()
|
|
12
12
|
|
|
13
13
|
function asProduct(p: NativeProduct): Product {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
+
}
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
function asPurchase(t: Transaction): Purchase {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
+
}
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
function getClient(): Payment {
|
|
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
|
-
|
|
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
|
|
68
73
|
}
|
|
69
74
|
|
|
70
75
|
/** Store billing service — Play Billing / StoreKit. */
|
|
71
76
|
export const billing: Billing = {
|
|
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
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
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
|
+
},
|
|
155
171
|
}
|
package/src/billing.web.ts
CHANGED
|
@@ -7,15 +7,15 @@ const unsupported = () => Promise.reject(new Error('unsupported: no store backen
|
|
|
7
7
|
|
|
8
8
|
/** Store billing service — Play Billing / StoreKit. */
|
|
9
9
|
export const billing: Billing = {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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,
|
|
21
21
|
}
|
package/src/billing.windows.ts
CHANGED
|
@@ -2,19 +2,19 @@
|
|
|
2
2
|
import type { Billing } from './types'
|
|
3
3
|
|
|
4
4
|
const unsupported = () =>
|
|
5
|
-
|
|
5
|
+
Promise.reject(new Error('unsupported: billing is not available on windows'))
|
|
6
6
|
|
|
7
7
|
/** Store billing service — Play Billing / StoreKit. */
|
|
8
8
|
export const billing: Billing = {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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,
|
|
20
20
|
}
|
package/src/types.ts
CHANGED
|
@@ -5,22 +5,22 @@ export type ProductType = 'inapp' | 'subs' | 'unknown'
|
|
|
5
5
|
/** A store product as fetched from the app store. Prices are null until
|
|
6
6
|
* the store reports them (and priceMicros stays null on iOS). */
|
|
7
7
|
export interface Product {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
/** Transaction lifecycle: 'pending' awaits external payment action
|
|
@@ -29,86 +29,86 @@ export type PurchaseState = 'pending' | 'purchased' | 'unknown'
|
|
|
29
29
|
|
|
30
30
|
/** One store transaction returned by purchase updates or restore queries. */
|
|
31
31
|
export interface Purchase {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
/** Options for requestPurchase(); platform bags pass through to the store. */
|
|
54
54
|
export interface PurchaseOptions {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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 }
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
/** requestPurchase() options: store options plus the product kind used to
|
|
64
64
|
* fetch an id before checkout. */
|
|
65
65
|
export interface RequestPurchaseOptions extends PurchaseOptions {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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
69
|
}
|
|
70
70
|
|
|
71
71
|
/** A store-reported failure. */
|
|
72
72
|
export interface PurchaseError {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
/** Store billing façade — Play Billing on Android, StoreKit on iOS.
|
|
81
81
|
* False `supported` on web/desktop leaves. */
|
|
82
82
|
export interface Billing {
|
|
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
|
-
|
|
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>
|
|
112
112
|
}
|
|
113
113
|
|
|
114
114
|
export declare const billing: Billing
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { billing } from './billing.web.js';
|