expo-iap 2.7.5-rc.1 → 2.7.6
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/.copilot-instructions.md +26 -8
- package/CHANGELOG.md +33 -2
- package/CONTRIBUTING.md +26 -3
- package/build/ExpoIap.types.d.ts.map +1 -1
- package/build/ExpoIap.types.js.map +1 -1
- package/build/index.d.ts +1 -1
- package/build/index.d.ts.map +1 -1
- package/build/index.js +5 -4
- package/build/index.js.map +1 -1
- package/build/modules/android.d.ts.map +1 -1
- package/build/modules/android.js.map +1 -1
- package/build/modules/ios.d.ts.map +1 -1
- package/build/modules/ios.js.map +1 -1
- package/build/useIap.d.ts +6 -2
- package/build/useIap.d.ts.map +1 -1
- package/build/useIap.js +13 -8
- package/build/useIap.js.map +1 -1
- package/package.json +1 -1
- package/plugin/tsconfig.tsbuildinfo +1 -1
- package/src/ExpoIap.types.ts +17 -8
- package/src/index.ts +34 -36
- package/src/modules/android.ts +2 -4
- package/src/modules/ios.ts +87 -47
- package/src/useIap.ts +21 -15
package/src/useIap.ts
CHANGED
|
@@ -10,11 +10,9 @@ import {
|
|
|
10
10
|
purchaseErrorListener,
|
|
11
11
|
purchaseUpdatedListener,
|
|
12
12
|
promotedProductListenerIOS,
|
|
13
|
-
getProducts,
|
|
14
13
|
getAvailablePurchases,
|
|
15
14
|
getPurchaseHistories,
|
|
16
15
|
finishTransaction as finishTransactionInternal,
|
|
17
|
-
getSubscriptions,
|
|
18
16
|
requestPurchase as requestPurchaseInternal,
|
|
19
17
|
requestProducts,
|
|
20
18
|
} from './';
|
|
@@ -42,6 +40,8 @@ import {
|
|
|
42
40
|
type UseIap = {
|
|
43
41
|
connected: boolean;
|
|
44
42
|
products: Product[];
|
|
43
|
+
promotedProductsIOS: ProductPurchase[];
|
|
44
|
+
promotedProductIdIOS?: string;
|
|
45
45
|
subscriptions: SubscriptionProduct[];
|
|
46
46
|
purchaseHistories: ProductPurchase[];
|
|
47
47
|
availablePurchases: ProductPurchase[];
|
|
@@ -59,12 +59,14 @@ type UseIap = {
|
|
|
59
59
|
}) => Promise<PurchaseResult | boolean>;
|
|
60
60
|
getAvailablePurchases: (skus: string[]) => Promise<void>;
|
|
61
61
|
getPurchaseHistories: (skus: string[]) => Promise<void>;
|
|
62
|
-
getProducts: (skus: string[]) => Promise<void>;
|
|
63
|
-
getSubscriptions: (skus: string[]) => Promise<void>;
|
|
64
62
|
requestProducts: (params: {
|
|
65
63
|
skus: string[];
|
|
66
64
|
type?: 'inapp' | 'subs';
|
|
67
65
|
}) => Promise<void>;
|
|
66
|
+
/** @deprecated Use requestProducts({ skus, type: 'inapp' }) instead. This method will be removed in version 3.0.0. */
|
|
67
|
+
getProducts: (skus: string[]) => Promise<void>;
|
|
68
|
+
/** @deprecated Use requestProducts({ skus, type: 'subs' }) instead. This method will be removed in version 3.0.0. */
|
|
69
|
+
getSubscriptions: (skus: string[]) => Promise<void>;
|
|
68
70
|
requestPurchase: (params: {
|
|
69
71
|
request: RequestPurchaseProps | RequestSubscriptionProps;
|
|
70
72
|
type?: 'inapp' | 'subs';
|
|
@@ -96,6 +98,7 @@ export interface UseIAPOptions {
|
|
|
96
98
|
export function useIAP(options?: UseIAPOptions): UseIap {
|
|
97
99
|
const [connected, setConnected] = useState<boolean>(false);
|
|
98
100
|
const [products, setProducts] = useState<Product[]>([]);
|
|
101
|
+
const [promotedProductsIOS] = useState<ProductPurchase[]>([]);
|
|
99
102
|
const [subscriptions, setSubscriptions] = useState<SubscriptionProduct[]>([]);
|
|
100
103
|
const [purchaseHistories, setPurchaseHistories] = useState<ProductPurchase[]>(
|
|
101
104
|
[],
|
|
@@ -107,6 +110,7 @@ export function useIAP(options?: UseIAPOptions): UseIap {
|
|
|
107
110
|
const [promotedProductIOS, setPromotedProductIOS] = useState<Product>();
|
|
108
111
|
const [currentPurchaseError, setCurrentPurchaseError] =
|
|
109
112
|
useState<PurchaseError>();
|
|
113
|
+
const [promotedProductIdIOS] = useState<string>();
|
|
110
114
|
|
|
111
115
|
const optionsRef = useRef<UseIAPOptions | undefined>(options);
|
|
112
116
|
|
|
@@ -139,6 +143,7 @@ export function useIAP(options?: UseIAPOptions): UseIap {
|
|
|
139
143
|
purchaseUpdate?: EventSubscription;
|
|
140
144
|
purchaseError?: EventSubscription;
|
|
141
145
|
promotedProductsIos?: EventSubscription;
|
|
146
|
+
promotedProductIOS?: EventSubscription;
|
|
142
147
|
}>({});
|
|
143
148
|
|
|
144
149
|
const subscriptionsRefState = useRef<SubscriptionProduct[]>([]);
|
|
@@ -158,11 +163,11 @@ export function useIAP(options?: UseIAPOptions): UseIap {
|
|
|
158
163
|
const getProductsInternal = useCallback(
|
|
159
164
|
async (skus: string[]): Promise<void> => {
|
|
160
165
|
try {
|
|
161
|
-
const result = await
|
|
166
|
+
const result = await requestProducts({skus, type: 'inapp'});
|
|
162
167
|
setProducts((prevProducts) =>
|
|
163
168
|
mergeWithDuplicateCheck(
|
|
164
169
|
prevProducts,
|
|
165
|
-
result,
|
|
170
|
+
result as Product[],
|
|
166
171
|
(product) => product.id,
|
|
167
172
|
),
|
|
168
173
|
);
|
|
@@ -176,11 +181,11 @@ export function useIAP(options?: UseIAPOptions): UseIap {
|
|
|
176
181
|
const getSubscriptionsInternal = useCallback(
|
|
177
182
|
async (skus: string[]): Promise<void> => {
|
|
178
183
|
try {
|
|
179
|
-
const result = await
|
|
184
|
+
const result = await requestProducts({skus, type: 'subs'});
|
|
180
185
|
setSubscriptions((prevSubscriptions) =>
|
|
181
186
|
mergeWithDuplicateCheck(
|
|
182
187
|
prevSubscriptions,
|
|
183
|
-
result,
|
|
188
|
+
result as SubscriptionProduct[],
|
|
184
189
|
(subscription) => subscription.id,
|
|
185
190
|
),
|
|
186
191
|
);
|
|
@@ -392,7 +397,7 @@ export function useIAP(options?: UseIAPOptions): UseIap {
|
|
|
392
397
|
});
|
|
393
398
|
}
|
|
394
399
|
}
|
|
395
|
-
}, [refreshSubscriptionStatus]);
|
|
400
|
+
}, [refreshSubscriptionStatus, mergeWithDuplicateCheck]);
|
|
396
401
|
|
|
397
402
|
useEffect(() => {
|
|
398
403
|
initIapWithSubscriptions();
|
|
@@ -402,6 +407,7 @@ export function useIAP(options?: UseIAPOptions): UseIap {
|
|
|
402
407
|
currentSubscriptions.purchaseUpdate?.remove();
|
|
403
408
|
currentSubscriptions.purchaseError?.remove();
|
|
404
409
|
currentSubscriptions.promotedProductsIos?.remove();
|
|
410
|
+
currentSubscriptions.promotedProductIOS?.remove();
|
|
405
411
|
endConnection();
|
|
406
412
|
setConnected(false);
|
|
407
413
|
};
|
|
@@ -410,6 +416,8 @@ export function useIAP(options?: UseIAPOptions): UseIap {
|
|
|
410
416
|
return {
|
|
411
417
|
connected,
|
|
412
418
|
products,
|
|
419
|
+
promotedProductsIOS,
|
|
420
|
+
promotedProductIdIOS,
|
|
413
421
|
subscriptions,
|
|
414
422
|
purchaseHistories,
|
|
415
423
|
finishTransaction,
|
|
@@ -421,15 +429,13 @@ export function useIAP(options?: UseIAPOptions): UseIap {
|
|
|
421
429
|
clearCurrentPurchaseError,
|
|
422
430
|
getAvailablePurchases: getAvailablePurchasesInternal,
|
|
423
431
|
getPurchaseHistories: getPurchaseHistoriesInternal,
|
|
424
|
-
getProducts: getProductsInternal,
|
|
425
|
-
getSubscriptions: getSubscriptionsInternal,
|
|
426
432
|
requestProducts: requestProductsInternal,
|
|
427
433
|
requestPurchase: requestPurchaseWithReset,
|
|
428
434
|
validateReceipt,
|
|
429
435
|
restorePurchases,
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
436
|
+
getProducts: getProductsInternal,
|
|
437
|
+
getSubscriptions: getSubscriptionsInternal,
|
|
438
|
+
getPromotedProductIOS,
|
|
439
|
+
buyPromotedProductIOS,
|
|
434
440
|
};
|
|
435
441
|
}
|