@octane-xplat/billing 0.0.0-stage → 0.18.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/LICENSE +21 -0
- package/README.md +28 -2
- package/package.json +94 -3
- package/src/billing.linux.ts +2 -0
- package/src/billing.macos.ts +19 -0
- package/src/billing.ts +114 -0
- package/src/billing.web.ts +20 -0
- package/src/billing.windows.ts +18 -0
- package/src/index.macos.ts +2 -0
- package/src/index.ts +2 -0
- package/src/index.web.ts +2 -0
- package/src/types.ts +71 -0
- package/types/generated/.tsrx-typegen-manifest.json +14 -0
- package/types/generated/billing.d.ts +2 -0
- package/types/generated/billing.linux.d.ts +1 -0
- package/types/generated/billing.macos.d.ts +2 -0
- package/types/generated/billing.web.d.ts +2 -0
- package/types/generated/billing.windows.d.ts +2 -0
- package/types/generated/index.d.ts +2 -0
- package/types/generated/index.macos.d.ts +2 -0
- package/types/generated/index.web.d.ts +2 -0
- package/types/generated/types.d.ts +75 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
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.
|
package/README.md
CHANGED
|
@@ -1,3 +1,29 @@
|
|
|
1
|
-
#
|
|
1
|
+
# `@octane-xplat/billing`
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
```sh
|
|
4
|
+
pnpm add @octane-xplat/billing
|
|
5
|
+
```
|
|
6
|
+
|
|
7
|
+
In-app purchases and subscriptions — StoreKit 2 and Play Billing through
|
|
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`.
|
package/package.json
CHANGED
|
@@ -1,6 +1,97 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@octane-xplat/billing",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.18.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
|
+
"macos": {
|
|
35
|
+
"types": "./types/generated/index.macos.d.ts",
|
|
36
|
+
"default": "./src/index.macos.ts"
|
|
37
|
+
},
|
|
38
|
+
"web": {
|
|
39
|
+
"types": "./types/generated/index.web.d.ts",
|
|
40
|
+
"default": "./src/index.web.ts"
|
|
41
|
+
},
|
|
42
|
+
"native": {
|
|
43
|
+
"types": "./types/generated/index.d.ts",
|
|
44
|
+
"default": "./src/index.ts"
|
|
45
|
+
},
|
|
46
|
+
"types": "./types/generated/index.d.ts",
|
|
47
|
+
"default": "./src/index.ts"
|
|
48
|
+
},
|
|
49
|
+
"./*": {
|
|
50
|
+
"types": "./types/generated/*.d.ts",
|
|
51
|
+
"default": "./src/*"
|
|
52
|
+
},
|
|
53
|
+
"./*.ts": {
|
|
54
|
+
"types": "./types/generated/*.d.ts",
|
|
55
|
+
"default": "./src/*.ts"
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
"publishConfig": {
|
|
59
|
+
"access": "public"
|
|
60
|
+
},
|
|
61
|
+
"devDependencies": {
|
|
62
|
+
"@nativescript-community/octane": "0.2.5",
|
|
63
|
+
"@nativescript/core": "9.1.3",
|
|
64
|
+
"@nativescript/types": "9.1.4",
|
|
65
|
+
"@tsrx/typescript-plugin": "0.4.11",
|
|
66
|
+
"octane": "0.14.0",
|
|
67
|
+
"tsrx-typegen": "0.4.0",
|
|
68
|
+
"typescript": "5.9.3"
|
|
69
|
+
},
|
|
70
|
+
"peerDependencies": {
|
|
71
|
+
"@nativescript-community/octane": ">=0.2.1 <1",
|
|
72
|
+
"@nativescript/core": ">=9.1.0 <10",
|
|
73
|
+
"octane": ">=0.6.3 <1"
|
|
74
|
+
},
|
|
75
|
+
"peerDependenciesMeta": {
|
|
76
|
+
"@nativescript-community/octane": {
|
|
77
|
+
"optional": true
|
|
78
|
+
},
|
|
79
|
+
"@nativescript/core": {
|
|
80
|
+
"optional": true
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
"nativescript": {
|
|
84
|
+
"platforms": {
|
|
85
|
+
"android": "9.1.0",
|
|
86
|
+
"ios": "9.1.0"
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
"dependencies": {
|
|
90
|
+
"@nativescript/payments": "4.0.1"
|
|
91
|
+
},
|
|
92
|
+
"scripts": {
|
|
93
|
+
"typegen": "tsrx-typegen --target octane",
|
|
94
|
+
"pack:check": "tsrx-typegen --pack-check",
|
|
95
|
+
"typecheck": "node ../../scripts/typecheck.ts"
|
|
96
|
+
}
|
|
6
97
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Billing — macOS leaf. StoreKit is bridgeable through the AppKit host but
|
|
2
|
+
// not wired; report unsupported.
|
|
3
|
+
import type { Billing } from './types'
|
|
4
|
+
|
|
5
|
+
const unsupported = () => Promise.reject(new Error('unsupported: billing is not wired on macOS'))
|
|
6
|
+
|
|
7
|
+
export const billing: Billing = {
|
|
8
|
+
supported: false,
|
|
9
|
+
connect: () => {},
|
|
10
|
+
disconnect: () => {},
|
|
11
|
+
canMakePayments: () => false,
|
|
12
|
+
fetchProducts: unsupported,
|
|
13
|
+
requestPurchase: unsupported,
|
|
14
|
+
onPurchase: () => () => {},
|
|
15
|
+
onPurchaseError: () => () => {},
|
|
16
|
+
getAvailablePurchases: unsupported,
|
|
17
|
+
finishTransaction: unsupported,
|
|
18
|
+
showManageSubscriptions: unsupported,
|
|
19
|
+
}
|
package/src/billing.ts
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
// Billing — native leaf over @nativescript/payments (StoreKit 2 + Play
|
|
2
|
+
// Billing). One Payment client behind the flat service; purchase outcomes
|
|
3
|
+
// fan out to registered listeners.
|
|
4
|
+
import { Payment, type Product as NativeProduct, type Transaction } from '@nativescript/payments'
|
|
5
|
+
import type { Billing, Product, Purchase, PurchaseOptions } from './types'
|
|
6
|
+
|
|
7
|
+
let client: Payment | null = null
|
|
8
|
+
const purchaseListeners = new Set<(purchases: Purchase[]) => void>()
|
|
9
|
+
const errorListeners = new Set<(error: { code: string; message: string }) => void>()
|
|
10
|
+
|
|
11
|
+
function asProduct(p: NativeProduct): Product {
|
|
12
|
+
return {
|
|
13
|
+
id: p.id,
|
|
14
|
+
title: p.localizedTitle ?? p.title ?? p.name,
|
|
15
|
+
description: p.description,
|
|
16
|
+
type: p.type,
|
|
17
|
+
displayPrice: p.priceFormatted,
|
|
18
|
+
priceMicros: p.priceAmountMicros,
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function asPurchase(t: Transaction): Purchase {
|
|
23
|
+
return {
|
|
24
|
+
productId: t.productId,
|
|
25
|
+
transactionId: t.orderId,
|
|
26
|
+
transactionDate: t.orderDate ?? null,
|
|
27
|
+
state: t.state,
|
|
28
|
+
type: t.type,
|
|
29
|
+
isAcknowledged: t.isAcknowledged,
|
|
30
|
+
receiptToken: t.receiptToken,
|
|
31
|
+
native: t,
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function getClient(): Payment {
|
|
36
|
+
if (!client) {
|
|
37
|
+
client = new Payment()
|
|
38
|
+
client.onPurchaseUpdate = (purchases, error) => {
|
|
39
|
+
if (error) {
|
|
40
|
+
const out = { code: (error as any)?.code ?? 'ERROR', message: error.message ?? String(error) }
|
|
41
|
+
for (const listener of errorListeners) {
|
|
42
|
+
listener(out)
|
|
43
|
+
}
|
|
44
|
+
return
|
|
45
|
+
}
|
|
46
|
+
const mapped = (purchases ?? []).map(asPurchase)
|
|
47
|
+
for (const listener of purchaseListeners) {
|
|
48
|
+
listener(mapped)
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return client
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export const billing: Billing = {
|
|
56
|
+
supported: Payment.isSupported(),
|
|
57
|
+
|
|
58
|
+
connect(): void {
|
|
59
|
+
getClient().connect()
|
|
60
|
+
},
|
|
61
|
+
|
|
62
|
+
disconnect(): void {
|
|
63
|
+
client?.disconnect()
|
|
64
|
+
},
|
|
65
|
+
|
|
66
|
+
canMakePayments(): boolean {
|
|
67
|
+
return getClient().canMakePayments()
|
|
68
|
+
},
|
|
69
|
+
|
|
70
|
+
async fetchProducts(productIds: string[], type: 'inapp' | 'subs' = 'inapp'): Promise<Product[]> {
|
|
71
|
+
const products = await getClient().fetchProducts(productIds, type)
|
|
72
|
+
return (products ?? []).map(asProduct)
|
|
73
|
+
},
|
|
74
|
+
|
|
75
|
+
async requestPurchase(productId: string, options?: PurchaseOptions): Promise<void> {
|
|
76
|
+
const c = getClient()
|
|
77
|
+
const [product] = await c.fetchProducts([productId], 'inapp')
|
|
78
|
+
if (!product) {
|
|
79
|
+
throw Object.assign(new Error(`billing.requestPurchase: product '${productId}' not found`), {
|
|
80
|
+
code: 'PRODUCT_UNAVAILABLE',
|
|
81
|
+
})
|
|
82
|
+
}
|
|
83
|
+
await c.purchaseProduct(product, options as any)
|
|
84
|
+
},
|
|
85
|
+
|
|
86
|
+
onPurchase(listener: (purchases: Purchase[]) => void): () => void {
|
|
87
|
+
purchaseListeners.add(listener)
|
|
88
|
+
return () => purchaseListeners.delete(listener)
|
|
89
|
+
},
|
|
90
|
+
|
|
91
|
+
onPurchaseError(listener): () => void {
|
|
92
|
+
errorListeners.add(listener)
|
|
93
|
+
return () => errorListeners.delete(listener)
|
|
94
|
+
},
|
|
95
|
+
|
|
96
|
+
async getAvailablePurchases(): Promise<Purchase[]> {
|
|
97
|
+
const transactions = await getClient().fetchPurchases()
|
|
98
|
+
return (transactions ?? []).map(asPurchase)
|
|
99
|
+
},
|
|
100
|
+
|
|
101
|
+
async finishTransaction(purchase: Purchase, options?: { consume?: boolean }): Promise<void> {
|
|
102
|
+
const native = purchase.native as Transaction | undefined
|
|
103
|
+
if (!native) {
|
|
104
|
+
throw new Error('billing.finishTransaction: purchase lacks its native transaction')
|
|
105
|
+
}
|
|
106
|
+
await native.finish(options)
|
|
107
|
+
},
|
|
108
|
+
|
|
109
|
+
async showManageSubscriptions(options?: { subscriptionGroupId?: string }): Promise<void> {
|
|
110
|
+
await getClient().showSubscriptionsManagement({
|
|
111
|
+
ios: { subscriptionGroupID: options?.subscriptionGroupId },
|
|
112
|
+
})
|
|
113
|
+
},
|
|
114
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// Billing — web leaf. No web store backend exists yet (a delegated-checkout
|
|
2
|
+
// seam like RevenueCat Web Billing is a possible future). supported: false;
|
|
3
|
+
// calls throw rather than silently doing nothing.
|
|
4
|
+
import type { Billing } from './types'
|
|
5
|
+
|
|
6
|
+
const unsupported = () => Promise.reject(new Error('unsupported: no store backend on web'))
|
|
7
|
+
|
|
8
|
+
export const billing: Billing = {
|
|
9
|
+
supported: false,
|
|
10
|
+
connect: () => {},
|
|
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
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// Windows leaf — no store backend; report unsupported.
|
|
2
|
+
import type { Billing } from './types'
|
|
3
|
+
|
|
4
|
+
const unsupported = () => Promise.reject(new Error('unsupported: billing is not available on windows'))
|
|
5
|
+
|
|
6
|
+
export const billing: Billing = {
|
|
7
|
+
supported: false,
|
|
8
|
+
connect: () => {},
|
|
9
|
+
disconnect: () => {},
|
|
10
|
+
canMakePayments: () => false,
|
|
11
|
+
fetchProducts: unsupported,
|
|
12
|
+
requestPurchase: unsupported,
|
|
13
|
+
onPurchase: () => () => {},
|
|
14
|
+
onPurchaseError: () => () => {},
|
|
15
|
+
getAvailablePurchases: unsupported,
|
|
16
|
+
finishTransaction: unsupported,
|
|
17
|
+
showManageSubscriptions: unsupported,
|
|
18
|
+
}
|
package/src/index.ts
ADDED
package/src/index.web.ts
ADDED
package/src/types.ts
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
export type ProductType = 'inapp' | 'subs' | 'unknown'
|
|
2
|
+
|
|
3
|
+
export interface Product {
|
|
4
|
+
id: string
|
|
5
|
+
/** Store-localized title. */
|
|
6
|
+
title: string
|
|
7
|
+
description: string
|
|
8
|
+
type: ProductType
|
|
9
|
+
/** Localized price string ('$4.99') — null until the store reports it. */
|
|
10
|
+
displayPrice: string | null
|
|
11
|
+
/** Price in micros (1_000_000 = 1 unit) — null on iOS, which reports
|
|
12
|
+
* formatted price only at this API level. */
|
|
13
|
+
priceMicros: number | null
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export type PurchaseState = 'pending' | 'purchased' | 'unknown'
|
|
17
|
+
|
|
18
|
+
export interface Purchase {
|
|
19
|
+
productId: string
|
|
20
|
+
/** Play order id / StoreKit transaction id. */
|
|
21
|
+
transactionId: string
|
|
22
|
+
transactionDate: Date | null
|
|
23
|
+
state: PurchaseState
|
|
24
|
+
type: ProductType
|
|
25
|
+
isAcknowledged: boolean
|
|
26
|
+
/** Receipt token for server-side verification (Play purchase token /
|
|
27
|
+
* StoreKit receipt data). */
|
|
28
|
+
receiptToken: string
|
|
29
|
+
/** Underlying plugin transaction — pass to finishTransaction internals
|
|
30
|
+
* when holding the raw reference is required. */
|
|
31
|
+
native?: unknown
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface PurchaseOptions {
|
|
35
|
+
/** Android obfuscated account/profile ids. */
|
|
36
|
+
accountId?: string
|
|
37
|
+
android?: { accountId?: string; profileId?: string; isOfferPersonalized?: boolean }
|
|
38
|
+
ios?: { quantity?: number; simulatesAskToBuyInSandbox?: boolean }
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface PurchaseError {
|
|
42
|
+
code: string
|
|
43
|
+
message: string
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface Billing {
|
|
47
|
+
/** StoreKit/Play Billing client exists (false on web/desktop leaves). */
|
|
48
|
+
readonly supported: boolean
|
|
49
|
+
/** Connect the store client — call once at app start, before other calls. */
|
|
50
|
+
connect(): void
|
|
51
|
+
disconnect(): void
|
|
52
|
+
/** The device can make payments (parental controls off, store reachable). */
|
|
53
|
+
canMakePayments(): boolean
|
|
54
|
+
fetchProducts(productIds: string[], type?: 'inapp' | 'subs'): Promise<Product[]>
|
|
55
|
+
/** Kick the OS purchase sheet for `productId` — the product is fetched
|
|
56
|
+
* internally first. Outcomes arrive on onPurchase/onPurchaseError and
|
|
57
|
+
* must be completed with finishTransaction. */
|
|
58
|
+
requestPurchase(productId: string, options?: PurchaseOptions): Promise<void>
|
|
59
|
+
/** Purchase-update listener; returns the unsubscribe function. */
|
|
60
|
+
onPurchase(listener: (purchases: Purchase[]) => void): () => void
|
|
61
|
+
onPurchaseError(listener: (error: PurchaseError) => void): () => void
|
|
62
|
+
/** Owned/unconsumed purchases — the "restore" query on both stores. */
|
|
63
|
+
getAvailablePurchases(): Promise<Purchase[]>
|
|
64
|
+
/** Consume/acknowledge a completed purchase (Play: consume or
|
|
65
|
+
* acknowledge; StoreKit: finish). Options.consume = consumable flow. */
|
|
66
|
+
finishTransaction(purchase: Purchase, options?: { consume?: boolean }): Promise<void>
|
|
67
|
+
/** Native subscription management UI. */
|
|
68
|
+
showManageSubscriptions(options?: { subscriptionGroupId?: string }): Promise<void>
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export declare const billing: Billing
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { billing } from './billing.web.js';
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
export type ProductType = 'inapp' | 'subs' | 'unknown';
|
|
2
|
+
export interface Product {
|
|
3
|
+
id: string;
|
|
4
|
+
/** Store-localized title. */
|
|
5
|
+
title: string;
|
|
6
|
+
description: string;
|
|
7
|
+
type: ProductType;
|
|
8
|
+
/** Localized price string ('$4.99') — null until the store reports it. */
|
|
9
|
+
displayPrice: string | null;
|
|
10
|
+
/** Price in micros (1_000_000 = 1 unit) — null on iOS, which reports
|
|
11
|
+
* formatted price only at this API level. */
|
|
12
|
+
priceMicros: number | null;
|
|
13
|
+
}
|
|
14
|
+
export type PurchaseState = 'pending' | 'purchased' | 'unknown';
|
|
15
|
+
export interface Purchase {
|
|
16
|
+
productId: string;
|
|
17
|
+
/** Play order id / StoreKit transaction id. */
|
|
18
|
+
transactionId: string;
|
|
19
|
+
transactionDate: Date | null;
|
|
20
|
+
state: PurchaseState;
|
|
21
|
+
type: ProductType;
|
|
22
|
+
isAcknowledged: boolean;
|
|
23
|
+
/** Receipt token for server-side verification (Play purchase token /
|
|
24
|
+
* StoreKit receipt data). */
|
|
25
|
+
receiptToken: string;
|
|
26
|
+
/** Underlying plugin transaction — pass to finishTransaction internals
|
|
27
|
+
* when holding the raw reference is required. */
|
|
28
|
+
native?: unknown;
|
|
29
|
+
}
|
|
30
|
+
export interface PurchaseOptions {
|
|
31
|
+
/** Android obfuscated account/profile ids. */
|
|
32
|
+
accountId?: string;
|
|
33
|
+
android?: {
|
|
34
|
+
accountId?: string;
|
|
35
|
+
profileId?: string;
|
|
36
|
+
isOfferPersonalized?: boolean;
|
|
37
|
+
};
|
|
38
|
+
ios?: {
|
|
39
|
+
quantity?: number;
|
|
40
|
+
simulatesAskToBuyInSandbox?: boolean;
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
export interface PurchaseError {
|
|
44
|
+
code: string;
|
|
45
|
+
message: string;
|
|
46
|
+
}
|
|
47
|
+
export interface Billing {
|
|
48
|
+
/** StoreKit/Play Billing client exists (false on web/desktop leaves). */
|
|
49
|
+
readonly supported: boolean;
|
|
50
|
+
/** Connect the store client — call once at app start, before other calls. */
|
|
51
|
+
connect(): void;
|
|
52
|
+
disconnect(): void;
|
|
53
|
+
/** The device can make payments (parental controls off, store reachable). */
|
|
54
|
+
canMakePayments(): boolean;
|
|
55
|
+
fetchProducts(productIds: string[], type?: 'inapp' | 'subs'): Promise<Product[]>;
|
|
56
|
+
/** Kick the OS purchase sheet for `productId` — the product is fetched
|
|
57
|
+
* internally first. Outcomes arrive on onPurchase/onPurchaseError and
|
|
58
|
+
* must be completed with finishTransaction. */
|
|
59
|
+
requestPurchase(productId: string, options?: PurchaseOptions): Promise<void>;
|
|
60
|
+
/** Purchase-update listener; returns the unsubscribe function. */
|
|
61
|
+
onPurchase(listener: (purchases: Purchase[]) => void): () => void;
|
|
62
|
+
onPurchaseError(listener: (error: PurchaseError) => void): () => void;
|
|
63
|
+
/** Owned/unconsumed purchases — the "restore" query on both stores. */
|
|
64
|
+
getAvailablePurchases(): Promise<Purchase[]>;
|
|
65
|
+
/** Consume/acknowledge a completed purchase (Play: consume or
|
|
66
|
+
* acknowledge; StoreKit: finish). Options.consume = consumable flow. */
|
|
67
|
+
finishTransaction(purchase: Purchase, options?: {
|
|
68
|
+
consume?: boolean;
|
|
69
|
+
}): Promise<void>;
|
|
70
|
+
/** Native subscription management UI. */
|
|
71
|
+
showManageSubscriptions(options?: {
|
|
72
|
+
subscriptionGroupId?: string;
|
|
73
|
+
}): Promise<void>;
|
|
74
|
+
}
|
|
75
|
+
export declare const billing: Billing;
|