@rocapine/react-native-onboarding 1.70.0 → 1.71.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/dist/products/adapters/expoIap.d.ts.map +1 -1
- package/dist/products/adapters/expoIap.js +118 -11
- package/dist/products/adapters/expoIap.js.map +1 -1
- package/dist/steps/common.types.d.ts +2 -0
- package/dist/steps/common.types.d.ts.map +1 -1
- package/dist/steps/common.types.js +1 -0
- package/dist/steps/common.types.js.map +1 -1
- package/package.json +1 -1
- package/src/products/adapters/__tests__/expoIap.test.ts +210 -0
- package/src/products/adapters/expoIap.ts +121 -5
- package/src/steps/common.types.ts +3 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"expoIap.d.ts","sourceRoot":"","sources":["../../../src/products/adapters/expoIap.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAA8C,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"expoIap.d.ts","sourceRoot":"","sources":["../../../src/products/adapters/expoIap.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAA8C,MAAM,UAAU,CAAC;AA8D5F,sEAAsE;AACtE,eAAO,MAAM,sBAAsB,GAAI,MAAK,GAAS,KAAG,eAgJvD,CAAC"}
|
|
@@ -23,6 +23,40 @@ const toPeriod = (iso) => {
|
|
|
23
23
|
// expo-iap surfaces a user cancellation as a code rather than a typed error.
|
|
24
24
|
const isCancellation = (e) => (e === null || e === void 0 ? void 0 : e.code) === "E_USER_CANCELLED" || (e === null || e === void 0 ? void 0 : e.code) === "USER_CANCELED" || (e === null || e === void 0 ? void 0 : e.userCancelled) === true;
|
|
25
25
|
const idFor = (ref) => react_native_1.Platform.OS === "ios" ? ref.ios : ref.android;
|
|
26
|
+
const ISO_UNIT = { day: "D", week: "W", month: "M", year: "Y" };
|
|
27
|
+
/**
|
|
28
|
+
* The store's billing period as an ISO-8601 duration.
|
|
29
|
+
*
|
|
30
|
+
* Load-bearing far beyond the `period` field: `deriveProductFields` computes
|
|
31
|
+
* `pricePerDay` / `pricePerWeek` / `pricePerMonth` / `pricePerYear` and
|
|
32
|
+
* `savingsPct` from `periodIso` alone. A null here does not degrade those — it
|
|
33
|
+
* removes them, so `{{product.yearly.pricePerWeek}}` renders EMPTY (an unknown
|
|
34
|
+
* variable interpolates to nothing, not to a literal) and a per-week-framed
|
|
35
|
+
* paywall silently loses its headline number.
|
|
36
|
+
*
|
|
37
|
+
* expo-iap has never exposed one ready-made, and the shape has moved:
|
|
38
|
+
* - ≤4.x published `subscriptionPeriodISO` / `subscriptionPeriod` on the product
|
|
39
|
+
* - 5.x publishes the iOS period SPLIT in two (`subscriptionPeriodUnitIOS`,
|
|
40
|
+
* `subscriptionPeriodNumberIOS`) and the Android one buried in the first
|
|
41
|
+
* pricing phase of the first subscription offer
|
|
42
|
+
* All three are read, newest-shape-last so an older peer keeps working.
|
|
43
|
+
*/
|
|
44
|
+
const periodIsoFrom = (s) => {
|
|
45
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
46
|
+
const direct = (_a = s === null || s === void 0 ? void 0 : s.subscriptionPeriodISO) !== null && _a !== void 0 ? _a : s === null || s === void 0 ? void 0 : s.subscriptionPeriod;
|
|
47
|
+
if (typeof direct === "string" && direct)
|
|
48
|
+
return direct;
|
|
49
|
+
const unit = ISO_UNIT[String((_b = s === null || s === void 0 ? void 0 : s.subscriptionPeriodUnitIOS) !== null && _b !== void 0 ? _b : "").toLowerCase()];
|
|
50
|
+
if (unit) {
|
|
51
|
+
// `subscriptionPeriodNumberIOS` is typed as a STRING by expo-iap. Default to
|
|
52
|
+
// 1 rather than 0: StoreKit omits the count for a single-unit period, and
|
|
53
|
+
// "P0M" would make every derived price divide by zero.
|
|
54
|
+
const n = Number((_c = s === null || s === void 0 ? void 0 : s.subscriptionPeriodNumberIOS) !== null && _c !== void 0 ? _c : 1);
|
|
55
|
+
return `P${Number.isFinite(n) && n > 0 ? n : 1}${unit}`;
|
|
56
|
+
}
|
|
57
|
+
const androidPeriod = (_h = (_g = (_f = (_e = (_d = s === null || s === void 0 ? void 0 : s.subscriptionOffers) === null || _d === void 0 ? void 0 : _d[0]) === null || _e === void 0 ? void 0 : _e.pricingPhasesAndroid) === null || _f === void 0 ? void 0 : _f.pricingPhaseList) === null || _g === void 0 ? void 0 : _g[0]) === null || _h === void 0 ? void 0 : _h.billingPeriod;
|
|
58
|
+
return typeof androidPeriod === "string" && androidPeriod ? androidPeriod : null;
|
|
59
|
+
};
|
|
26
60
|
/** Direct StoreKit / Play Billing provider, no vendor in the path. */
|
|
27
61
|
const expoIapProductProvider = (Iap = IAP) => {
|
|
28
62
|
const required = () => {
|
|
@@ -31,32 +65,67 @@ const expoIapProductProvider = (Iap = IAP) => {
|
|
|
31
65
|
}
|
|
32
66
|
return Iap;
|
|
33
67
|
};
|
|
68
|
+
// Every expo-iap query fails until the store connection is open, and nothing
|
|
69
|
+
// opens it implicitly — `useIAP` does it for hook consumers, but this adapter
|
|
70
|
+
// is not a hook. Cached so concurrent getProducts/purchase/restore calls share
|
|
71
|
+
// one connect, and CLEARED on failure so a later call retries rather than
|
|
72
|
+
// replaying a rejected promise forever (a first call during airplane mode
|
|
73
|
+
// would otherwise poison the provider for the whole session).
|
|
74
|
+
let connecting = null;
|
|
75
|
+
const connect = async () => {
|
|
76
|
+
const M = required();
|
|
77
|
+
if (typeof M.initConnection !== "function")
|
|
78
|
+
return; // older peer: implicit connection
|
|
79
|
+
if (!connecting) {
|
|
80
|
+
connecting = Promise.resolve(M.initConnection()).catch((e) => {
|
|
81
|
+
connecting = null;
|
|
82
|
+
throw e;
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
await connecting;
|
|
86
|
+
};
|
|
87
|
+
// The raw store product per resolved productId, captured during getProducts.
|
|
88
|
+
// `purchase()` needs expo-iap's own `type` discriminator ("in-app" | "subs")
|
|
89
|
+
// and the full Purchase to finish, neither of which survives the trip through
|
|
90
|
+
// `ResolvedProduct`. Same pattern as stripeLink's `linkByKey`.
|
|
91
|
+
const rawById = new Map();
|
|
34
92
|
return {
|
|
35
93
|
async getProducts(refs) {
|
|
36
|
-
var _a, _b, _c, _d, _e, _f, _g, _h
|
|
94
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
37
95
|
const M = required();
|
|
38
96
|
const wanted = refs.map((r) => ({ ref: r, id: idFor(r) })).filter((x) => !!x.id);
|
|
39
97
|
if (wanted.length === 0)
|
|
40
98
|
return [];
|
|
99
|
+
await connect();
|
|
41
100
|
const skus = wanted.map((w) => w.id);
|
|
42
|
-
|
|
43
|
-
|
|
101
|
+
// 5.x renamed `getProducts(skus)` to `fetchProducts({ skus, type })` — an
|
|
102
|
+
// object arg, not a positional array. Calling the old name on 5.x throws
|
|
103
|
+
// "M.getProducts is not a function", so probe rather than assume; `"all"`
|
|
104
|
+
// because a paywall mixes subscriptions and one-off lifetime products.
|
|
105
|
+
const store = typeof M.fetchProducts === "function"
|
|
106
|
+
? await M.fetchProducts({ skus, type: "all" })
|
|
107
|
+
: await M.getProducts(skus);
|
|
108
|
+
const list = Array.isArray(store) ? store : [];
|
|
109
|
+
const byId = new Map(list.map((s) => { var _a; return [(_a = s.id) !== null && _a !== void 0 ? _a : s.productId, s]; }));
|
|
110
|
+
rawById.clear();
|
|
44
111
|
const out = [];
|
|
45
112
|
for (const { ref, id } of wanted) {
|
|
46
113
|
const s = byId.get(id);
|
|
47
114
|
if (!s)
|
|
48
115
|
continue;
|
|
49
|
-
const
|
|
116
|
+
const productId = (_a = s.id) !== null && _a !== void 0 ? _a : s.productId;
|
|
117
|
+
rawById.set(productId, s);
|
|
118
|
+
const iso = periodIsoFrom(s);
|
|
50
119
|
const { period, count } = toPeriod(iso);
|
|
51
120
|
out.push({
|
|
52
121
|
key: ref.key,
|
|
53
|
-
productId
|
|
122
|
+
productId,
|
|
54
123
|
store: react_native_1.Platform.OS === "ios" ? "app_store" : "play_store",
|
|
55
|
-
title: (
|
|
56
|
-
description: (
|
|
57
|
-
price: (
|
|
58
|
-
priceAmount: Number((
|
|
59
|
-
currencyCode: (
|
|
124
|
+
title: (_b = s.title) !== null && _b !== void 0 ? _b : "",
|
|
125
|
+
description: (_c = s.description) !== null && _c !== void 0 ? _c : "",
|
|
126
|
+
price: (_e = (_d = s.displayPrice) !== null && _d !== void 0 ? _d : s.localizedPrice) !== null && _e !== void 0 ? _e : "",
|
|
127
|
+
priceAmount: Number((_f = s.price) !== null && _f !== void 0 ? _f : 0),
|
|
128
|
+
currencyCode: (_h = (_g = s.currency) !== null && _g !== void 0 ? _g : s.currencyCode) !== null && _h !== void 0 ? _h : "",
|
|
60
129
|
period,
|
|
61
130
|
periodCount: count,
|
|
62
131
|
periodIso: iso,
|
|
@@ -65,9 +134,46 @@ const expoIapProductProvider = (Iap = IAP) => {
|
|
|
65
134
|
return out;
|
|
66
135
|
},
|
|
67
136
|
async purchase(product) {
|
|
137
|
+
var _a;
|
|
68
138
|
const M = required();
|
|
69
139
|
try {
|
|
70
|
-
await
|
|
140
|
+
await connect();
|
|
141
|
+
const raw = rawById.get(product.productId);
|
|
142
|
+
// A non-null period means a subscription even when the raw product is
|
|
143
|
+
// missing (a host that hydrated the runtime from elsewhere).
|
|
144
|
+
const isSubs = ((_a = raw === null || raw === void 0 ? void 0 : raw.type) !== null && _a !== void 0 ? _a : (product.period ? "subs" : "in-app")) === "subs";
|
|
145
|
+
const sku = product.productId;
|
|
146
|
+
// 5.x wants `{ request: { ios, android }, type }`. The old flat
|
|
147
|
+
// `{ request: { sku } }` reaches neither platform branch, so StoreKit is
|
|
148
|
+
// handed an undefined sku. `type` is required to tell a subscription
|
|
149
|
+
// from a one-off — Play rejects the wrong one outright.
|
|
150
|
+
const args = typeof M.fetchProducts === "function"
|
|
151
|
+
? {
|
|
152
|
+
request: { ios: { sku }, android: { skus: [sku] } },
|
|
153
|
+
type: isSubs ? "subs" : "in-app",
|
|
154
|
+
}
|
|
155
|
+
: { request: { sku } };
|
|
156
|
+
const result = await M.requestPurchase(args);
|
|
157
|
+
// `requestPurchase` resolves `Purchase | Purchase[] | null`. `null` is
|
|
158
|
+
// the normal 5.x outcome: the transaction is delivered to
|
|
159
|
+
// `purchaseUpdatedListener` instead, so at this point nothing is
|
|
160
|
+
// confirmed. Reporting "purchased" there would grant access for a
|
|
161
|
+
// purchase that may still fail — hence "pending", which is exactly the
|
|
162
|
+
// outcome `PurchaseButtonAction.onPending` exists to handle.
|
|
163
|
+
const purchase = Array.isArray(result) ? result[0] : result;
|
|
164
|
+
if (!purchase)
|
|
165
|
+
return { status: "pending" };
|
|
166
|
+
// Unfinished transactions are re-delivered by StoreKit on every launch
|
|
167
|
+
// until finished. Best-effort: a failure here does not un-buy anything,
|
|
168
|
+
// so it must not turn a completed purchase into an error.
|
|
169
|
+
if (typeof M.finishTransaction === "function") {
|
|
170
|
+
try {
|
|
171
|
+
await M.finishTransaction({ purchase, isConsumable: false });
|
|
172
|
+
}
|
|
173
|
+
catch (_b) {
|
|
174
|
+
// ignore — reported as purchased, will be re-delivered and finished later
|
|
175
|
+
}
|
|
176
|
+
}
|
|
71
177
|
return { status: "purchased", productKey: product.key };
|
|
72
178
|
}
|
|
73
179
|
catch (e) {
|
|
@@ -79,6 +185,7 @@ const expoIapProductProvider = (Iap = IAP) => {
|
|
|
79
185
|
async restore() {
|
|
80
186
|
const M = required();
|
|
81
187
|
try {
|
|
188
|
+
await connect();
|
|
82
189
|
const purchases = await M.getAvailablePurchases();
|
|
83
190
|
const ids = (purchases !== null && purchases !== void 0 ? purchases : []).map((p) => { var _a; return (_a = p.id) !== null && _a !== void 0 ? _a : p.productId; }).filter(Boolean);
|
|
84
191
|
return ids.length > 0
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"expoIap.js","sourceRoot":"","sources":["../../../src/products/adapters/expoIap.ts"],"names":[],"mappings":";;;AAAA,+CAAwC;AAGxC,gFAAgF;AAChF,IAAI,GAAQ,CAAC;AACb,IA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AAC;QAED,KAAK,CAAC,OAAO;YACX,MAAM,CAAC,GAAG,QAAQ,EAAE,CAAC;YACrB,IAAI,CAAC;gBACH,MAAM,OAAO,EAAE,CAAC;gBAChB,MAAM,SAAS,GAAG,MAAM,CAAC,CAAC,qBAAqB,EAAE,CAAC;gBAClD,MAAM,GAAG,GAAa,CAAC,SAAS,aAAT,SAAS,cAAT,SAAS,GAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAM,EAAE,EAAE,WAAC,OAAA,MAAA,CAAC,CAAC,EAAE,mCAAI,CAAC,CAAC,SAAS,CAAA,EAAA,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;gBAC7F,OAAO,GAAG,CAAC,MAAM,GAAG,CAAC;oBACnB,CAAC,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,YAAY,EAAE,GAAG,EAAE;oBAC3C,CAAC,CAAC,EAAE,MAAM,EAAE,oBAAoB,EAAE,CAAC;YACvC,CAAC;YAAC,OAAO,CAAC,EAAE,CAAC;gBACX,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;YACnF,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC,CAAC;AAhJW,QAAA,sBAAsB,0BAgJjC"}
|
|
@@ -95,6 +95,8 @@ export type PurchaseButtonAction = {
|
|
|
95
95
|
onSuccess?: ButtonAction[];
|
|
96
96
|
onCancel?: ButtonAction[];
|
|
97
97
|
onError?: ButtonAction[];
|
|
98
|
+
/** Runs on `"pending"` — unconfirmed, not paid. A Stripe Payment Link always resolves this. */
|
|
99
|
+
onPending?: ButtonAction[];
|
|
98
100
|
};
|
|
99
101
|
export type RestoreButtonAction = {
|
|
100
102
|
type: "restore";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"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ports.ButtonActionSchema).optional(),
|
|
66
66
|
onCancel: zod_1.z.array(exports.ButtonActionSchema).optional(),
|
|
67
67
|
onError: zod_1.z.array(exports.ButtonActionSchema).optional(),
|
|
68
|
+
onPending: zod_1.z.array(exports.ButtonActionSchema).optional(),
|
|
68
69
|
}));
|
|
69
70
|
exports.RestoreButtonActionSchema = zod_1.z.lazy(() => zod_1.z.object({
|
|
70
71
|
type: zod_1.z.literal("restore"),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.types.js","sourceRoot":"","sources":["../../src/steps/common.types.ts"],"names":[],"mappings":";;;AAAA,6BAAwB;AAEX,QAAA,mBAAmB,GAAG,OAAC,CAAC,MAAM,CAAC,OAAC,CAAC,MAAM,EAAE,EAAE,OAAC,CAAC,GAAG,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC;AAE9D,QAAA,iBAAiB,GAAG,OAAC,CAAC,KAAK,CAAC;IACvC,OAAC,CAAC,MAAM,CAAC;QACP,IAAI,EAAE,OAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,OAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,OAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,OAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QAC7F,WAAW,EAAE,OAAC,CAAC,MAAM,EAAE;KACxB,CAAC;IACF,OAAC,CAAC,MAAM,CAAC;QACP,IAAI,EAAE,OAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,OAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,OAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,OAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QAC7F,GAAG,EAAE,OAAC,CAAC,MAAM,EAAE;KAChB,CAAC;CACH,CAAC,CAA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ClC,aAAa,EAAE,2BAAmB;IAClC,mBAAmB,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,UAAU,CAAC;IAC9D,aAAa,EAAE,2BAAmB,CAAC,QAAQ,EAAE;IAC7C,QAAQ,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,OAAO,EAAE;IAC9B,QAAQ,EAAE,sBAAc;CACzB,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rocapine/react-native-onboarding",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.71.0",
|
|
4
4
|
"description": "Headless React Native SDK for Rocapine Onboarding Studio - Data fetching, state management, and hooks",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from "vitest";
|
|
2
|
+
|
|
3
|
+
// The adapter imports `Platform` from react-native, whose entry point is Flow
|
|
4
|
+
// and cannot be parsed by vitest's transformer. Same one-line stub every other
|
|
5
|
+
// react-native-touching test in this package uses.
|
|
6
|
+
vi.mock("react-native", () => ({ Platform: { OS: "ios" } }));
|
|
7
|
+
|
|
8
|
+
import { expoIapProductProvider } from "../expoIap";
|
|
9
|
+
import type { ProductRef } from "../../types";
|
|
10
|
+
|
|
11
|
+
// The adapter resolves ids by platform and vitest runs the iOS branch of the
|
|
12
|
+
// `react-native` Platform shim, so every ref here carries `ios`.
|
|
13
|
+
const YEARLY: ProductRef = { key: "yearly", ios: "pro_yearly" };
|
|
14
|
+
const LIFETIME: ProductRef = { key: "lifetime", ios: "pro_lifetime" };
|
|
15
|
+
|
|
16
|
+
// A subscription as expo-iap 5.x actually reports it: the period is SPLIT into
|
|
17
|
+
// a unit and a stringly count, and there is no `subscriptionPeriodISO` at all.
|
|
18
|
+
const iap5Yearly = {
|
|
19
|
+
id: "pro_yearly",
|
|
20
|
+
type: "subs",
|
|
21
|
+
title: "Pro Yearly",
|
|
22
|
+
description: "Best value",
|
|
23
|
+
displayPrice: "$59.99",
|
|
24
|
+
price: 59.99,
|
|
25
|
+
currency: "USD",
|
|
26
|
+
subscriptionPeriodUnitIOS: "year",
|
|
27
|
+
subscriptionPeriodNumberIOS: "1",
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const iap5Lifetime = {
|
|
31
|
+
id: "pro_lifetime",
|
|
32
|
+
type: "in-app",
|
|
33
|
+
title: "Lifetime",
|
|
34
|
+
description: "One time",
|
|
35
|
+
displayPrice: "$119.99",
|
|
36
|
+
price: 119.99,
|
|
37
|
+
currency: "USD",
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const mock5 = (over: Record<string, any> = {}) => ({
|
|
41
|
+
initConnection: vi.fn().mockResolvedValue(true),
|
|
42
|
+
fetchProducts: vi.fn().mockResolvedValue([iap5Yearly, iap5Lifetime]),
|
|
43
|
+
requestPurchase: vi.fn().mockResolvedValue(null),
|
|
44
|
+
finishTransaction: vi.fn().mockResolvedValue(undefined),
|
|
45
|
+
getAvailablePurchases: vi.fn().mockResolvedValue([]),
|
|
46
|
+
...over,
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
describe("expoIapProductProvider — expo-iap 5.x API", () => {
|
|
50
|
+
it("calls fetchProducts, not the removed getProducts", async () => {
|
|
51
|
+
// 5.x deleted `getProducts`; calling it threw "M.getProducts is not a
|
|
52
|
+
// function" and every product silently failed to resolve. A mock with NO
|
|
53
|
+
// getProducts is what pins that.
|
|
54
|
+
const M = mock5();
|
|
55
|
+
const products = await expoIapProductProvider(M).getProducts([YEARLY, LIFETIME]);
|
|
56
|
+
expect(M.fetchProducts).toHaveBeenCalledWith({ skus: ["pro_yearly", "pro_lifetime"], type: "all" });
|
|
57
|
+
expect(products.map((p) => p.key)).toEqual(["yearly", "lifetime"]);
|
|
58
|
+
expect(products[0].price).toBe("$59.99");
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it("opens the store connection before querying, exactly once", async () => {
|
|
62
|
+
const M = mock5();
|
|
63
|
+
const provider = expoIapProductProvider(M);
|
|
64
|
+
await provider.getProducts([YEARLY]);
|
|
65
|
+
await provider.getProducts([YEARLY]);
|
|
66
|
+
await provider.restore();
|
|
67
|
+
expect(M.initConnection).toHaveBeenCalledTimes(1);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it("retries the connection after a failed one instead of replaying the rejection", async () => {
|
|
71
|
+
// A first call while offline must not poison the provider for the session.
|
|
72
|
+
const initConnection = vi
|
|
73
|
+
.fn()
|
|
74
|
+
.mockRejectedValueOnce(new Error("offline"))
|
|
75
|
+
.mockResolvedValue(true);
|
|
76
|
+
const M = mock5({ initConnection });
|
|
77
|
+
const provider = expoIapProductProvider(M);
|
|
78
|
+
await expect(provider.getProducts([YEARLY])).rejects.toThrow("offline");
|
|
79
|
+
await expect(provider.getProducts([YEARLY])).resolves.toHaveLength(1);
|
|
80
|
+
expect(initConnection).toHaveBeenCalledTimes(2);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it("derives periodIso from the split iOS fields", async () => {
|
|
84
|
+
// The whole point: `periodIso` feeds deriveProductFields, so a null here
|
|
85
|
+
// removes pricePerWeek/pricePerMonth/savingsPct rather than degrading them.
|
|
86
|
+
const [yearly, lifetime] = await expoIapProductProvider(mock5()).getProducts([YEARLY, LIFETIME]);
|
|
87
|
+
expect(yearly.periodIso).toBe("P1Y");
|
|
88
|
+
expect(yearly.period).toBe("year");
|
|
89
|
+
expect(yearly.periodCount).toBe(1);
|
|
90
|
+
// A one-off product has no period at all — not "P1Y" by accident.
|
|
91
|
+
expect(lifetime.periodIso).toBeNull();
|
|
92
|
+
expect(lifetime.period).toBeNull();
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it("defaults a missing period count to 1, never 0", async () => {
|
|
96
|
+
// StoreKit omits the count for a single-unit period. "P0M" would make every
|
|
97
|
+
// derived per-unit price divide by zero.
|
|
98
|
+
const M = mock5({
|
|
99
|
+
fetchProducts: vi.fn().mockResolvedValue([
|
|
100
|
+
{ ...iap5Yearly, subscriptionPeriodUnitIOS: "month", subscriptionPeriodNumberIOS: undefined },
|
|
101
|
+
]),
|
|
102
|
+
});
|
|
103
|
+
const [p] = await expoIapProductProvider(M).getProducts([YEARLY]);
|
|
104
|
+
expect(p.periodIso).toBe("P1M");
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it("reads the Android billing period out of the first pricing phase", async () => {
|
|
108
|
+
const M = mock5({
|
|
109
|
+
fetchProducts: vi.fn().mockResolvedValue([
|
|
110
|
+
{
|
|
111
|
+
id: "pro_yearly",
|
|
112
|
+
type: "subs",
|
|
113
|
+
displayPrice: "$59.99",
|
|
114
|
+
price: 59.99,
|
|
115
|
+
currency: "USD",
|
|
116
|
+
subscriptionOffers: [
|
|
117
|
+
{ pricingPhasesAndroid: { pricingPhaseList: [{ billingPeriod: "P1Y" }] } },
|
|
118
|
+
],
|
|
119
|
+
},
|
|
120
|
+
]),
|
|
121
|
+
});
|
|
122
|
+
const [p] = await expoIapProductProvider(M).getProducts([YEARLY]);
|
|
123
|
+
expect(p.periodIso).toBe("P1Y");
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it("still honours a pre-5.x product that publishes the ISO period directly", async () => {
|
|
127
|
+
const M = mock5({
|
|
128
|
+
fetchProducts: vi
|
|
129
|
+
.fn()
|
|
130
|
+
.mockResolvedValue([{ ...iap5Yearly, subscriptionPeriodISO: "P6M", subscriptionPeriodUnitIOS: "year" }]),
|
|
131
|
+
});
|
|
132
|
+
const [p] = await expoIapProductProvider(M).getProducts([YEARLY]);
|
|
133
|
+
expect(p.periodIso).toBe("P6M");
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it("falls back to the legacy getProducts when fetchProducts is absent", async () => {
|
|
137
|
+
// A host pinned to expo-iap ≤4 must keep working.
|
|
138
|
+
const getProducts = vi.fn().mockResolvedValue([{ ...iap5Yearly, subscriptionPeriodISO: "P1Y" }]);
|
|
139
|
+
const M = { getProducts, requestPurchase: vi.fn(), getAvailablePurchases: vi.fn() };
|
|
140
|
+
const [p] = await expoIapProductProvider(M).getProducts([YEARLY]);
|
|
141
|
+
expect(getProducts).toHaveBeenCalledWith(["pro_yearly"]);
|
|
142
|
+
expect(p.periodIso).toBe("P1Y");
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
describe("expoIapProductProvider — purchase", () => {
|
|
147
|
+
const resolved = async (M: any) => (await expoIapProductProvider(M).getProducts([YEARLY]))[0];
|
|
148
|
+
|
|
149
|
+
it("sends the per-platform request shape with the subscription type", async () => {
|
|
150
|
+
// The old flat `{ request: { sku } }` reached neither platform branch, so
|
|
151
|
+
// StoreKit received an undefined sku.
|
|
152
|
+
const M = mock5({ requestPurchase: vi.fn().mockResolvedValue({ id: "tx" }) });
|
|
153
|
+
const provider = expoIapProductProvider(M);
|
|
154
|
+
const product = (await provider.getProducts([YEARLY]))[0];
|
|
155
|
+
await provider.purchase(product);
|
|
156
|
+
expect(M.requestPurchase).toHaveBeenCalledWith({
|
|
157
|
+
request: { ios: { sku: "pro_yearly" }, android: { skus: ["pro_yearly"] } },
|
|
158
|
+
type: "subs",
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
it("sends type in-app for a one-off product", async () => {
|
|
163
|
+
const M = mock5({ requestPurchase: vi.fn().mockResolvedValue({ id: "tx" }) });
|
|
164
|
+
const provider = expoIapProductProvider(M);
|
|
165
|
+
const product = (await provider.getProducts([LIFETIME]))[0];
|
|
166
|
+
await provider.purchase(product);
|
|
167
|
+
expect(M.requestPurchase.mock.calls[0][0].type).toBe("in-app");
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it("resolves pending — not purchased — when requestPurchase resolves null", async () => {
|
|
171
|
+
// The normal 5.x outcome: the transaction arrives via purchaseUpdatedListener,
|
|
172
|
+
// so nothing is confirmed yet. Reporting "purchased" granted access for a
|
|
173
|
+
// purchase that may still fail.
|
|
174
|
+
const M = mock5({ requestPurchase: vi.fn().mockResolvedValue(null) });
|
|
175
|
+
const provider = expoIapProductProvider(M);
|
|
176
|
+
const product = (await provider.getProducts([YEARLY]))[0];
|
|
177
|
+
expect(await provider.purchase(product)).toEqual({ status: "pending" });
|
|
178
|
+
expect(M.finishTransaction).not.toHaveBeenCalled();
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
it("finishes the transaction when one comes back", async () => {
|
|
182
|
+
// Unfinished transactions are re-delivered by StoreKit on every launch.
|
|
183
|
+
const purchase = { id: "tx-1" };
|
|
184
|
+
const M = mock5({ requestPurchase: vi.fn().mockResolvedValue(purchase) });
|
|
185
|
+
const provider = expoIapProductProvider(M);
|
|
186
|
+
const product = (await provider.getProducts([YEARLY]))[0];
|
|
187
|
+
expect(await provider.purchase(product)).toEqual({ status: "purchased", productKey: "yearly" });
|
|
188
|
+
expect(M.finishTransaction).toHaveBeenCalledWith({ purchase, isConsumable: false });
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
it("still reports purchased when finishing throws", async () => {
|
|
192
|
+
// A finish failure does not un-buy anything; it must not become an error.
|
|
193
|
+
const M = mock5({
|
|
194
|
+
requestPurchase: vi.fn().mockResolvedValue({ id: "tx-1" }),
|
|
195
|
+
finishTransaction: vi.fn().mockRejectedValue(new Error("finish failed")),
|
|
196
|
+
});
|
|
197
|
+
const provider = expoIapProductProvider(M);
|
|
198
|
+
const product = (await provider.getProducts([YEARLY]))[0];
|
|
199
|
+
expect(await provider.purchase(product)).toEqual({ status: "purchased", productKey: "yearly" });
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
it("maps a user cancellation to cancelled, not error", async () => {
|
|
203
|
+
const M = mock5({
|
|
204
|
+
requestPurchase: vi.fn().mockRejectedValue({ code: "E_USER_CANCELLED" }),
|
|
205
|
+
});
|
|
206
|
+
const provider = expoIapProductProvider(M);
|
|
207
|
+
const product = (await provider.getProducts([YEARLY]))[0];
|
|
208
|
+
expect(await provider.purchase(product)).toEqual({ status: "cancelled" });
|
|
209
|
+
});
|
|
210
|
+
});
|
|
@@ -24,6 +24,43 @@ const isCancellation = (e: any): boolean =>
|
|
|
24
24
|
const idFor = (ref: ProductRef): string | undefined =>
|
|
25
25
|
Platform.OS === "ios" ? ref.ios : ref.android;
|
|
26
26
|
|
|
27
|
+
const ISO_UNIT: Record<string, string> = { day: "D", week: "W", month: "M", year: "Y" };
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The store's billing period as an ISO-8601 duration.
|
|
31
|
+
*
|
|
32
|
+
* Load-bearing far beyond the `period` field: `deriveProductFields` computes
|
|
33
|
+
* `pricePerDay` / `pricePerWeek` / `pricePerMonth` / `pricePerYear` and
|
|
34
|
+
* `savingsPct` from `periodIso` alone. A null here does not degrade those — it
|
|
35
|
+
* removes them, so `{{product.yearly.pricePerWeek}}` renders EMPTY (an unknown
|
|
36
|
+
* variable interpolates to nothing, not to a literal) and a per-week-framed
|
|
37
|
+
* paywall silently loses its headline number.
|
|
38
|
+
*
|
|
39
|
+
* expo-iap has never exposed one ready-made, and the shape has moved:
|
|
40
|
+
* - ≤4.x published `subscriptionPeriodISO` / `subscriptionPeriod` on the product
|
|
41
|
+
* - 5.x publishes the iOS period SPLIT in two (`subscriptionPeriodUnitIOS`,
|
|
42
|
+
* `subscriptionPeriodNumberIOS`) and the Android one buried in the first
|
|
43
|
+
* pricing phase of the first subscription offer
|
|
44
|
+
* All three are read, newest-shape-last so an older peer keeps working.
|
|
45
|
+
*/
|
|
46
|
+
const periodIsoFrom = (s: any): string | null => {
|
|
47
|
+
const direct = s?.subscriptionPeriodISO ?? s?.subscriptionPeriod;
|
|
48
|
+
if (typeof direct === "string" && direct) return direct;
|
|
49
|
+
|
|
50
|
+
const unit = ISO_UNIT[String(s?.subscriptionPeriodUnitIOS ?? "").toLowerCase()];
|
|
51
|
+
if (unit) {
|
|
52
|
+
// `subscriptionPeriodNumberIOS` is typed as a STRING by expo-iap. Default to
|
|
53
|
+
// 1 rather than 0: StoreKit omits the count for a single-unit period, and
|
|
54
|
+
// "P0M" would make every derived price divide by zero.
|
|
55
|
+
const n = Number(s?.subscriptionPeriodNumberIOS ?? 1);
|
|
56
|
+
return `P${Number.isFinite(n) && n > 0 ? n : 1}${unit}`;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const androidPeriod =
|
|
60
|
+
s?.subscriptionOffers?.[0]?.pricingPhasesAndroid?.pricingPhaseList?.[0]?.billingPeriod;
|
|
61
|
+
return typeof androidPeriod === "string" && androidPeriod ? androidPeriod : null;
|
|
62
|
+
};
|
|
63
|
+
|
|
27
64
|
/** Direct StoreKit / Play Billing provider, no vendor in the path. */
|
|
28
65
|
export const expoIapProductProvider = (Iap: any = IAP): ProductProvider => {
|
|
29
66
|
const required = () => {
|
|
@@ -35,23 +72,62 @@ export const expoIapProductProvider = (Iap: any = IAP): ProductProvider => {
|
|
|
35
72
|
return Iap;
|
|
36
73
|
};
|
|
37
74
|
|
|
75
|
+
// Every expo-iap query fails until the store connection is open, and nothing
|
|
76
|
+
// opens it implicitly — `useIAP` does it for hook consumers, but this adapter
|
|
77
|
+
// is not a hook. Cached so concurrent getProducts/purchase/restore calls share
|
|
78
|
+
// one connect, and CLEARED on failure so a later call retries rather than
|
|
79
|
+
// replaying a rejected promise forever (a first call during airplane mode
|
|
80
|
+
// would otherwise poison the provider for the whole session).
|
|
81
|
+
let connecting: Promise<unknown> | null = null;
|
|
82
|
+
const connect = async () => {
|
|
83
|
+
const M = required();
|
|
84
|
+
if (typeof M.initConnection !== "function") return; // older peer: implicit connection
|
|
85
|
+
if (!connecting) {
|
|
86
|
+
connecting = Promise.resolve(M.initConnection()).catch((e: unknown) => {
|
|
87
|
+
connecting = null;
|
|
88
|
+
throw e;
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
await connecting;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
// The raw store product per resolved productId, captured during getProducts.
|
|
95
|
+
// `purchase()` needs expo-iap's own `type` discriminator ("in-app" | "subs")
|
|
96
|
+
// and the full Purchase to finish, neither of which survives the trip through
|
|
97
|
+
// `ResolvedProduct`. Same pattern as stripeLink's `linkByKey`.
|
|
98
|
+
const rawById = new Map<string, any>();
|
|
99
|
+
|
|
38
100
|
return {
|
|
39
101
|
async getProducts(refs: ProductRef[]): Promise<ResolvedProduct[]> {
|
|
40
102
|
const M = required();
|
|
41
103
|
const wanted = refs.map((r) => ({ ref: r, id: idFor(r) })).filter((x) => !!x.id);
|
|
42
104
|
if (wanted.length === 0) return [];
|
|
105
|
+
await connect();
|
|
43
106
|
const skus = wanted.map((w) => w.id as string);
|
|
44
|
-
|
|
45
|
-
|
|
107
|
+
|
|
108
|
+
// 5.x renamed `getProducts(skus)` to `fetchProducts({ skus, type })` — an
|
|
109
|
+
// object arg, not a positional array. Calling the old name on 5.x throws
|
|
110
|
+
// "M.getProducts is not a function", so probe rather than assume; `"all"`
|
|
111
|
+
// because a paywall mixes subscriptions and one-off lifetime products.
|
|
112
|
+
const store =
|
|
113
|
+
typeof M.fetchProducts === "function"
|
|
114
|
+
? await M.fetchProducts({ skus, type: "all" })
|
|
115
|
+
: await M.getProducts(skus);
|
|
116
|
+
|
|
117
|
+
const list: any[] = Array.isArray(store) ? store : [];
|
|
118
|
+
const byId = new Map<string, any>(list.map((s: any) => [s.id ?? s.productId, s]));
|
|
119
|
+
rawById.clear();
|
|
46
120
|
const out: ResolvedProduct[] = [];
|
|
47
121
|
for (const { ref, id } of wanted) {
|
|
48
122
|
const s = byId.get(id as string);
|
|
49
123
|
if (!s) continue;
|
|
50
|
-
const
|
|
124
|
+
const productId = s.id ?? s.productId;
|
|
125
|
+
rawById.set(productId, s);
|
|
126
|
+
const iso = periodIsoFrom(s);
|
|
51
127
|
const { period, count } = toPeriod(iso);
|
|
52
128
|
out.push({
|
|
53
129
|
key: ref.key,
|
|
54
|
-
productId
|
|
130
|
+
productId,
|
|
55
131
|
store: Platform.OS === "ios" ? "app_store" : "play_store",
|
|
56
132
|
title: s.title ?? "",
|
|
57
133
|
description: s.description ?? "",
|
|
@@ -69,7 +145,46 @@ export const expoIapProductProvider = (Iap: any = IAP): ProductProvider => {
|
|
|
69
145
|
async purchase(product) {
|
|
70
146
|
const M = required();
|
|
71
147
|
try {
|
|
72
|
-
await
|
|
148
|
+
await connect();
|
|
149
|
+
const raw = rawById.get(product.productId);
|
|
150
|
+
// A non-null period means a subscription even when the raw product is
|
|
151
|
+
// missing (a host that hydrated the runtime from elsewhere).
|
|
152
|
+
const isSubs = (raw?.type ?? (product.period ? "subs" : "in-app")) === "subs";
|
|
153
|
+
const sku = product.productId;
|
|
154
|
+
|
|
155
|
+
// 5.x wants `{ request: { ios, android }, type }`. The old flat
|
|
156
|
+
// `{ request: { sku } }` reaches neither platform branch, so StoreKit is
|
|
157
|
+
// handed an undefined sku. `type` is required to tell a subscription
|
|
158
|
+
// from a one-off — Play rejects the wrong one outright.
|
|
159
|
+
const args =
|
|
160
|
+
typeof M.fetchProducts === "function"
|
|
161
|
+
? {
|
|
162
|
+
request: { ios: { sku }, android: { skus: [sku] } },
|
|
163
|
+
type: isSubs ? "subs" : "in-app",
|
|
164
|
+
}
|
|
165
|
+
: { request: { sku } };
|
|
166
|
+
|
|
167
|
+
const result = await M.requestPurchase(args as any);
|
|
168
|
+
|
|
169
|
+
// `requestPurchase` resolves `Purchase | Purchase[] | null`. `null` is
|
|
170
|
+
// the normal 5.x outcome: the transaction is delivered to
|
|
171
|
+
// `purchaseUpdatedListener` instead, so at this point nothing is
|
|
172
|
+
// confirmed. Reporting "purchased" there would grant access for a
|
|
173
|
+
// purchase that may still fail — hence "pending", which is exactly the
|
|
174
|
+
// outcome `PurchaseButtonAction.onPending` exists to handle.
|
|
175
|
+
const purchase = Array.isArray(result) ? result[0] : result;
|
|
176
|
+
if (!purchase) return { status: "pending" };
|
|
177
|
+
|
|
178
|
+
// Unfinished transactions are re-delivered by StoreKit on every launch
|
|
179
|
+
// until finished. Best-effort: a failure here does not un-buy anything,
|
|
180
|
+
// so it must not turn a completed purchase into an error.
|
|
181
|
+
if (typeof M.finishTransaction === "function") {
|
|
182
|
+
try {
|
|
183
|
+
await M.finishTransaction({ purchase, isConsumable: false });
|
|
184
|
+
} catch {
|
|
185
|
+
// ignore — reported as purchased, will be re-delivered and finished later
|
|
186
|
+
}
|
|
187
|
+
}
|
|
73
188
|
return { status: "purchased", productKey: product.key };
|
|
74
189
|
} catch (e: any) {
|
|
75
190
|
if (isCancellation(e)) return { status: "cancelled" };
|
|
@@ -80,6 +195,7 @@ export const expoIapProductProvider = (Iap: any = IAP): ProductProvider => {
|
|
|
80
195
|
async restore() {
|
|
81
196
|
const M = required();
|
|
82
197
|
try {
|
|
198
|
+
await connect();
|
|
83
199
|
const purchases = await M.getAvailablePurchases();
|
|
84
200
|
const ids: string[] = (purchases ?? []).map((p: any) => p.id ?? p.productId).filter(Boolean);
|
|
85
201
|
return ids.length > 0
|
|
@@ -112,6 +112,8 @@ export type PurchaseButtonAction = {
|
|
|
112
112
|
onSuccess?: ButtonAction[];
|
|
113
113
|
onCancel?: ButtonAction[];
|
|
114
114
|
onError?: ButtonAction[];
|
|
115
|
+
/** Runs on `"pending"` — unconfirmed, not paid. A Stripe Payment Link always resolves this. */
|
|
116
|
+
onPending?: ButtonAction[];
|
|
115
117
|
};
|
|
116
118
|
|
|
117
119
|
export type RestoreButtonAction = {
|
|
@@ -162,6 +164,7 @@ export const PurchaseButtonActionSchema: z.ZodType<PurchaseButtonAction> = z.laz
|
|
|
162
164
|
onSuccess: z.array(ButtonActionSchema).optional(),
|
|
163
165
|
onCancel: z.array(ButtonActionSchema).optional(),
|
|
164
166
|
onError: z.array(ButtonActionSchema).optional(),
|
|
167
|
+
onPending: z.array(ButtonActionSchema).optional(),
|
|
165
168
|
})
|
|
166
169
|
);
|
|
167
170
|
|