react-native-iap 14.3.5-rc.1 → 14.3.5
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/NitroIap.podspec +1 -1
- package/README.md +1 -1
- package/android/CMakeLists.txt +4 -0
- package/android/build.gradle +2 -2
- package/android/src/main/cpp/cpp-adapter.cpp +8 -0
- package/android/src/main/java/com/margelo/nitro/iap/HybridRnIap.kt +93 -51
- package/ios/HybridRnIap.swift +38 -30
- package/lib/module/hooks/useIAP.js +3 -5
- package/lib/module/hooks/useIAP.js.map +1 -1
- package/lib/module/index.js +54 -55
- package/lib/module/index.js.map +1 -1
- package/lib/module/types.js +1 -1
- package/lib/module/utils/type-bridge.js.map +1 -1
- package/lib/typescript/src/hooks/useIAP.d.ts +4 -4
- package/lib/typescript/src/hooks/useIAP.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +8 -7
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/specs/RnIap.nitro.d.ts +2 -1
- package/lib/typescript/src/specs/RnIap.nitro.d.ts.map +1 -1
- package/lib/typescript/src/types.d.ts +141 -146
- package/lib/typescript/src/types.d.ts.map +1 -1
- package/lib/typescript/src/utils/type-bridge.d.ts.map +1 -1
- package/nitrogen/generated/android/NitroIap+autolinking.cmake +9 -4
- package/nitrogen/generated/android/c++/JHybridRnIapSpec.cpp +32 -5
- package/nitrogen/generated/android/c++/JHybridRnIapSpec.hpp +1 -1
- package/nitrogen/generated/android/c++/JIapPlatform.hpp +59 -0
- package/nitrogen/generated/android/c++/JPurchase.cpp +26 -0
- package/nitrogen/generated/android/c++/JPurchase.hpp +80 -0
- package/nitrogen/generated/android/c++/JPurchaseAndroid.hpp +140 -0
- package/nitrogen/generated/android/c++/JPurchaseIOS.hpp +194 -0
- package/nitrogen/generated/android/c++/JPurchaseOfferIOS.hpp +61 -0
- package/nitrogen/generated/android/c++/JPurchaseState.hpp +71 -0
- package/nitrogen/generated/android/c++/JRequestPurchaseResult.hpp +89 -0
- package/nitrogen/generated/android/c++/JVariant_PurchaseAndroid_PurchaseIOS.cpp +26 -0
- package/nitrogen/generated/android/c++/JVariant_PurchaseAndroid_PurchaseIOS.hpp +80 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/HybridRnIapSpec.kt +1 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/IapPlatform.kt +21 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/Purchase.kt +42 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/PurchaseAndroid.kt +77 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/PurchaseIOS.kt +116 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/PurchaseOfferIOS.kt +35 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/PurchaseState.kt +25 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/RequestPurchaseResult.kt +32 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/Variant_PurchaseAndroid_PurchaseIOS.kt +42 -0
- package/nitrogen/generated/ios/NitroIap-Swift-Cxx-Bridge.cpp +13 -5
- package/nitrogen/generated/ios/NitroIap-Swift-Cxx-Bridge.hpp +186 -25
- package/nitrogen/generated/ios/NitroIap-Swift-Cxx-Umbrella.hpp +18 -0
- package/nitrogen/generated/ios/c++/HybridRnIapSpecSwift.hpp +20 -2
- package/nitrogen/generated/ios/swift/Func_void_RequestPurchaseResult.swift +47 -0
- package/nitrogen/generated/ios/swift/HybridRnIapSpec.swift +1 -1
- package/nitrogen/generated/ios/swift/HybridRnIapSpec_cxx.swift +7 -7
- package/nitrogen/generated/ios/swift/IapPlatform.swift +40 -0
- package/nitrogen/generated/ios/swift/Purchase.swift +18 -0
- package/nitrogen/generated/ios/swift/PurchaseAndroid.swift +399 -0
- package/nitrogen/generated/ios/swift/PurchaseIOS.swift +768 -0
- package/nitrogen/generated/ios/swift/PurchaseOfferIOS.swift +57 -0
- package/nitrogen/generated/ios/swift/PurchaseState.swift +56 -0
- package/nitrogen/generated/ios/swift/RequestPurchaseResult.swift +148 -0
- package/nitrogen/generated/ios/swift/Variant_PurchaseAndroid_PurchaseIOS.swift +18 -0
- package/nitrogen/generated/shared/c++/HybridRnIapSpec.hpp +4 -1
- package/nitrogen/generated/shared/c++/IapPlatform.hpp +76 -0
- package/nitrogen/generated/shared/c++/PurchaseAndroid.hpp +138 -0
- package/nitrogen/generated/shared/c++/PurchaseIOS.hpp +193 -0
- package/nitrogen/generated/shared/c++/PurchaseOfferIOS.hpp +75 -0
- package/nitrogen/generated/shared/c++/PurchaseState.hpp +92 -0
- package/nitrogen/generated/shared/c++/RequestPurchaseResult.hpp +78 -0
- package/package.json +5 -4
- package/plugin/build/withIAP.js +1 -1
- package/plugin/src/withIAP.ts +1 -1
- package/plugin/tsconfig.tsbuildinfo +1 -1
- package/src/hooks/useIAP.ts +13 -11
- package/src/index.ts +73 -77
- package/src/specs/RnIap.nitro.ts +4 -1
- package/src/types.ts +168 -178
- package/src/utils/type-bridge.ts +3 -1
- package/lib/index.d.ts +0 -8
- package/lib/index.js +0 -36
- package/lib/specs/RnIap.nitro.d.ts +0 -7
- package/lib/specs/RnIap.nitro.js +0 -1
package/src/index.ts
CHANGED
|
@@ -12,14 +12,17 @@ import type {
|
|
|
12
12
|
NitroReceiptValidationResultIOS,
|
|
13
13
|
NitroReceiptValidationResultAndroid,
|
|
14
14
|
} from './specs/RnIap.nitro';
|
|
15
|
-
import type {
|
|
15
|
+
import type {
|
|
16
|
+
ProductQueryType,
|
|
17
|
+
RequestPurchaseProps,
|
|
18
|
+
RequestPurchaseResult,
|
|
19
|
+
} from './types';
|
|
16
20
|
import type {
|
|
17
21
|
Product,
|
|
18
22
|
ProductRequest,
|
|
19
23
|
Purchase,
|
|
20
24
|
PurchaseAndroid,
|
|
21
25
|
PurchaseOptions,
|
|
22
|
-
PurchaseParams,
|
|
23
26
|
PurchaseError,
|
|
24
27
|
ReceiptValidationResultAndroid,
|
|
25
28
|
ReceiptValidationResultIOS,
|
|
@@ -27,6 +30,7 @@ import type {
|
|
|
27
30
|
RequestPurchaseIosProps,
|
|
28
31
|
RequestPurchasePropsByPlatforms,
|
|
29
32
|
RequestSubscriptionAndroidProps,
|
|
33
|
+
RequestSubscriptionIosProps,
|
|
30
34
|
RequestSubscriptionPropsByPlatforms,
|
|
31
35
|
SubscriptionStatusIOS,
|
|
32
36
|
} from './types';
|
|
@@ -50,38 +54,56 @@ export type {
|
|
|
50
54
|
export * from './types';
|
|
51
55
|
export * from './utils/error';
|
|
52
56
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
const PRODUCT_QUERY_TYPE_IN_APP: ProductQueryType = 'in-app';
|
|
58
|
-
const PRODUCT_QUERY_TYPE_SUBS: ProductQueryType = 'subs';
|
|
57
|
+
export type ProductTypeInput = 'inapp' | 'in-app' | 'subs';
|
|
58
|
+
|
|
59
|
+
const LEGACY_INAPP_WARNING =
|
|
60
|
+
"[react-native-iap] `type: 'inapp'` is deprecated and will be removed in v14.4.0. Use 'in-app' instead.";
|
|
59
61
|
|
|
60
62
|
function toNitroProductType(
|
|
61
|
-
type?: ProductQueryType | null,
|
|
62
|
-
):
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
63
|
+
type?: ProductTypeInput | ProductQueryType | null,
|
|
64
|
+
): 'inapp' | 'subs' {
|
|
65
|
+
if (type === 'subs') {
|
|
66
|
+
return 'subs';
|
|
67
|
+
}
|
|
68
|
+
if (type === 'inapp') {
|
|
69
|
+
console.warn(LEGACY_INAPP_WARNING);
|
|
70
|
+
return 'inapp';
|
|
71
|
+
}
|
|
72
|
+
if (type === 'all') {
|
|
73
|
+
return 'inapp';
|
|
74
|
+
}
|
|
75
|
+
return 'inapp';
|
|
66
76
|
}
|
|
67
77
|
|
|
68
78
|
function isSubscriptionQuery(type?: ProductQueryType | null): boolean {
|
|
69
|
-
return type ===
|
|
79
|
+
return type === 'subs';
|
|
70
80
|
}
|
|
71
81
|
|
|
72
82
|
function normalizeProductQueryType(
|
|
73
83
|
type?: ProductQueryType | string | null,
|
|
74
84
|
): ProductQueryType {
|
|
75
|
-
if (type ===
|
|
76
|
-
return
|
|
85
|
+
if (type === 'all' || type === 'subs' || type === 'in-app') {
|
|
86
|
+
return type;
|
|
77
87
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
88
|
+
|
|
89
|
+
if (typeof type === 'string') {
|
|
90
|
+
const normalized = type.trim().toLowerCase().replace(/_/g, '-');
|
|
91
|
+
|
|
92
|
+
if (normalized === 'all') {
|
|
93
|
+
return 'all';
|
|
94
|
+
}
|
|
95
|
+
if (normalized === 'subs') {
|
|
96
|
+
return 'subs';
|
|
97
|
+
}
|
|
98
|
+
if (normalized === 'inapp') {
|
|
99
|
+
console.warn(LEGACY_INAPP_WARNING);
|
|
100
|
+
return 'in-app';
|
|
101
|
+
}
|
|
102
|
+
if (normalized === 'in-app') {
|
|
103
|
+
return 'in-app';
|
|
104
|
+
}
|
|
83
105
|
}
|
|
84
|
-
return
|
|
106
|
+
return 'in-app';
|
|
85
107
|
}
|
|
86
108
|
|
|
87
109
|
export interface EventSubscription {
|
|
@@ -177,7 +199,7 @@ export const endConnection = async (): Promise<boolean> => {
|
|
|
177
199
|
* Fetch products from the store
|
|
178
200
|
* @param params - Product request configuration
|
|
179
201
|
* @param params.skus - Array of product SKUs to fetch
|
|
180
|
-
* @param params.type - Optional filter: '
|
|
202
|
+
* @param params.type - Optional filter: 'in-app' (default) for products, 'subs' for subscriptions, or 'all' for both.
|
|
181
203
|
* @returns Promise<Product[]> - Array of products from the store
|
|
182
204
|
*
|
|
183
205
|
* @example
|
|
@@ -191,7 +213,7 @@ export const endConnection = async (): Promise<boolean> => {
|
|
|
191
213
|
*/
|
|
192
214
|
export const fetchProducts = async ({
|
|
193
215
|
skus,
|
|
194
|
-
type =
|
|
216
|
+
type = 'in-app',
|
|
195
217
|
}: ProductRequest): Promise<Product[]> => {
|
|
196
218
|
try {
|
|
197
219
|
if (!skus || skus.length === 0) {
|
|
@@ -200,10 +222,10 @@ export const fetchProducts = async ({
|
|
|
200
222
|
|
|
201
223
|
const normalizedType = normalizeProductQueryType(type);
|
|
202
224
|
|
|
203
|
-
if (normalizedType ===
|
|
225
|
+
if (normalizedType === 'all') {
|
|
204
226
|
const [inappNitro, subsNitro] = await Promise.all([
|
|
205
|
-
IAP.instance.fetchProducts(skus,
|
|
206
|
-
IAP.instance.fetchProducts(skus,
|
|
227
|
+
IAP.instance.fetchProducts(skus, 'inapp'),
|
|
228
|
+
IAP.instance.fetchProducts(skus, 'subs'),
|
|
207
229
|
]);
|
|
208
230
|
const allNitro = [...inappNitro, ...subsNitro];
|
|
209
231
|
const validAll = allNitro.filter(validateNitroProduct);
|
|
@@ -240,7 +262,7 @@ export const fetchProducts = async ({
|
|
|
240
262
|
* Request a purchase for products or subscriptions
|
|
241
263
|
* @param params - Purchase request configuration
|
|
242
264
|
* @param params.request - Platform-specific purchase parameters
|
|
243
|
-
* @param params.type - Type of purchase: '
|
|
265
|
+
* @param params.type - Type of purchase: 'in-app' for products (default) or 'subs' for subscriptions
|
|
244
266
|
*
|
|
245
267
|
* @example
|
|
246
268
|
* ```typescript
|
|
@@ -250,7 +272,7 @@ export const fetchProducts = async ({
|
|
|
250
272
|
* ios: { sku: productId },
|
|
251
273
|
* android: { skus: [productId] }
|
|
252
274
|
* },
|
|
253
|
-
* type: '
|
|
275
|
+
* type: 'in-app'
|
|
254
276
|
* });
|
|
255
277
|
*
|
|
256
278
|
* // Subscription purchase
|
|
@@ -271,49 +293,20 @@ export const fetchProducts = async ({
|
|
|
271
293
|
* ⚠️ Important: This is an event-based operation, not promise-based.
|
|
272
294
|
* Listen for events through purchaseUpdatedListener or purchaseErrorListener.
|
|
273
295
|
* @param params - Purchase request configuration
|
|
274
|
-
* @param params.
|
|
275
|
-
* @param params.requestSubscription - Platform-specific subscription parameters (subs)
|
|
296
|
+
* @param params.request - Platform-specific request parameters
|
|
276
297
|
* @param params.type - Type of purchase (defaults to in-app)
|
|
277
298
|
*/
|
|
278
299
|
export const requestPurchase = async (
|
|
279
|
-
params:
|
|
280
|
-
): Promise<
|
|
300
|
+
params: RequestPurchaseProps,
|
|
301
|
+
): Promise<RequestPurchaseResult> => {
|
|
281
302
|
try {
|
|
282
|
-
const
|
|
283
|
-
const
|
|
284
|
-
const
|
|
285
|
-
|
|
286
|
-
const effectiveType = normalizeProductQueryType(params.type);
|
|
287
|
-
const isSubs = isSubscriptionQuery(effectiveType);
|
|
288
|
-
let request:
|
|
303
|
+
const normalizedType = normalizeProductQueryType(params.type);
|
|
304
|
+
const isSubs = isSubscriptionQuery(normalizedType);
|
|
305
|
+
const request = params.request as
|
|
289
306
|
| RequestPurchasePropsByPlatforms
|
|
290
307
|
| RequestSubscriptionPropsByPlatforms
|
|
291
308
|
| undefined;
|
|
292
309
|
|
|
293
|
-
if (isSubs) {
|
|
294
|
-
if (
|
|
295
|
-
__DEV__ &&
|
|
296
|
-
normalizedPurchaseRequest &&
|
|
297
|
-
!normalizedSubscriptionRequest
|
|
298
|
-
) {
|
|
299
|
-
console.warn(
|
|
300
|
-
'[react-native-iap] `requestPurchase` was provided for a subscription request. Did you mean to use `requestSubscription`?',
|
|
301
|
-
);
|
|
302
|
-
}
|
|
303
|
-
request = normalizedSubscriptionRequest ?? normalizedPurchaseRequest;
|
|
304
|
-
} else {
|
|
305
|
-
if (
|
|
306
|
-
__DEV__ &&
|
|
307
|
-
normalizedSubscriptionRequest &&
|
|
308
|
-
!normalizedPurchaseRequest
|
|
309
|
-
) {
|
|
310
|
-
console.warn(
|
|
311
|
-
'[react-native-iap] `requestSubscription` was provided for an in-app purchase request. Did you mean to use `requestPurchase`?',
|
|
312
|
-
);
|
|
313
|
-
}
|
|
314
|
-
request = normalizedPurchaseRequest ?? normalizedSubscriptionRequest;
|
|
315
|
-
}
|
|
316
|
-
|
|
317
310
|
if (!request) {
|
|
318
311
|
throw new Error('Missing purchase request configuration');
|
|
319
312
|
}
|
|
@@ -341,16 +334,19 @@ export const requestPurchase = async (
|
|
|
341
334
|
const unifiedRequest: any = {};
|
|
342
335
|
|
|
343
336
|
if (Platform.OS === 'ios' && request.ios) {
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
337
|
+
if (isSubs) {
|
|
338
|
+
const iosReq = request.ios as RequestSubscriptionIosProps;
|
|
339
|
+
const autoFinishSubs =
|
|
340
|
+
iosReq.andDangerouslyFinishTransactionAutomatically == null;
|
|
341
|
+
unifiedRequest.ios = {
|
|
342
|
+
...iosReq,
|
|
343
|
+
...(autoFinishSubs
|
|
344
|
+
? {andDangerouslyFinishTransactionAutomatically: true}
|
|
345
|
+
: {}),
|
|
346
|
+
} as RequestSubscriptionIosProps;
|
|
347
|
+
} else {
|
|
348
|
+
unifiedRequest.ios = request.ios as RequestPurchaseIosProps;
|
|
349
|
+
}
|
|
354
350
|
}
|
|
355
351
|
|
|
356
352
|
if (Platform.OS === 'android' && request.android) {
|
|
@@ -359,14 +355,14 @@ export const requestPurchase = async (
|
|
|
359
355
|
unifiedRequest.android = {
|
|
360
356
|
...subsRequest,
|
|
361
357
|
subscriptionOffers: subsRequest.subscriptionOffers || [],
|
|
362
|
-
} as
|
|
358
|
+
} as RequestSubscriptionAndroidProps;
|
|
363
359
|
} else {
|
|
364
|
-
unifiedRequest.android = request.android;
|
|
360
|
+
unifiedRequest.android = request.android as RequestPurchaseAndroidProps;
|
|
365
361
|
}
|
|
366
362
|
}
|
|
367
363
|
|
|
368
364
|
// Call unified method - returns void, listen for events instead
|
|
369
|
-
await IAP.instance.requestPurchase(unifiedRequest);
|
|
365
|
+
return await IAP.instance.requestPurchase(unifiedRequest);
|
|
370
366
|
} catch (error) {
|
|
371
367
|
console.error('Failed to request purchase:', error);
|
|
372
368
|
throw error;
|
package/src/specs/RnIap.nitro.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type {HybridObject} from 'react-native-nitro-modules';
|
|
2
|
+
import type {RequestPurchaseResult} from '../types';
|
|
2
3
|
|
|
3
4
|
// ╔══════════════════════════════════════════════════════════════════════════╗
|
|
4
5
|
// ║ PARAMS ║
|
|
@@ -307,7 +308,9 @@ export interface RnIap extends HybridObject<{ios: 'swift'; android: 'kotlin'}> {
|
|
|
307
308
|
* @param request - Platform-specific purchase request parameters
|
|
308
309
|
* @returns Promise<void> - Always returns void, listen for events instead
|
|
309
310
|
*/
|
|
310
|
-
requestPurchase(
|
|
311
|
+
requestPurchase(
|
|
312
|
+
request: NitroPurchaseRequest,
|
|
313
|
+
): Promise<RequestPurchaseResult>;
|
|
311
314
|
|
|
312
315
|
/**
|
|
313
316
|
* Get available purchases (unified method for both platforms)
|