react-native-iap 14.3.4 → 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 +4 -4
- package/lib/module/hooks/useIAP.js.map +1 -1
- package/lib/module/index.js +54 -53
- package/lib/module/index.js.map +1 -1
- package/lib/module/types.js +1 -59
- package/lib/module/types.js.map +1 -1
- package/lib/module/utils/type-bridge.js +44 -33
- 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 +159 -204
- 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/src/hooks/useIAP.ts +14 -8
- package/src/index.ts +73 -74
- package/src/specs/RnIap.nitro.ts +4 -1
- package/src/types.ts +183 -216
- package/src/utils/type-bridge.ts +55 -43
package/src/utils/type-bridge.ts
CHANGED
|
@@ -10,8 +10,8 @@ import type {
|
|
|
10
10
|
NitroPurchase,
|
|
11
11
|
NitroSubscriptionStatus,
|
|
12
12
|
} from '../specs/RnIap.nitro';
|
|
13
|
-
import {
|
|
14
|
-
|
|
13
|
+
import type {
|
|
14
|
+
IapPlatform,
|
|
15
15
|
PaymentModeIOS,
|
|
16
16
|
ProductType,
|
|
17
17
|
ProductTypeIOS,
|
|
@@ -25,51 +25,63 @@ import type {
|
|
|
25
25
|
SubscriptionStatusIOS,
|
|
26
26
|
} from '../types';
|
|
27
27
|
|
|
28
|
-
const PLATFORM_IOS = 'ios';
|
|
29
|
-
const
|
|
30
|
-
const
|
|
31
|
-
const
|
|
32
|
-
const
|
|
33
|
-
const
|
|
34
|
-
const
|
|
28
|
+
const PLATFORM_IOS: IapPlatform = 'ios';
|
|
29
|
+
const PLATFORM_ANDROID: IapPlatform = 'android';
|
|
30
|
+
const PRODUCT_TYPE_SUBS: ProductType = 'subs';
|
|
31
|
+
const PRODUCT_TYPE_IN_APP: ProductType = 'in-app';
|
|
32
|
+
const PURCHASE_STATE_DEFERRED: PurchaseState = 'deferred';
|
|
33
|
+
const PURCHASE_STATE_FAILED: PurchaseState = 'failed';
|
|
34
|
+
const PURCHASE_STATE_PENDING: PurchaseState = 'pending';
|
|
35
|
+
const PURCHASE_STATE_PURCHASED: PurchaseState = 'purchased';
|
|
36
|
+
const PURCHASE_STATE_RESTORED: PurchaseState = 'restored';
|
|
37
|
+
const PURCHASE_STATE_UNKNOWN: PurchaseState = 'unknown';
|
|
38
|
+
const PAYMENT_MODE_EMPTY: PaymentModeIOS = 'empty';
|
|
39
|
+
const PAYMENT_MODE_FREE_TRIAL: PaymentModeIOS = 'free-trial';
|
|
40
|
+
const PAYMENT_MODE_PAY_AS_YOU_GO: PaymentModeIOS = 'pay-as-you-go';
|
|
41
|
+
const PAYMENT_MODE_PAY_UP_FRONT: PaymentModeIOS = 'pay-up-front';
|
|
42
|
+
const SUBSCRIPTION_PERIOD_DAY: SubscriptionPeriodIOS = 'day';
|
|
43
|
+
const SUBSCRIPTION_PERIOD_WEEK: SubscriptionPeriodIOS = 'week';
|
|
44
|
+
const SUBSCRIPTION_PERIOD_MONTH: SubscriptionPeriodIOS = 'month';
|
|
45
|
+
const SUBSCRIPTION_PERIOD_YEAR: SubscriptionPeriodIOS = 'year';
|
|
46
|
+
const SUBSCRIPTION_PERIOD_EMPTY: SubscriptionPeriodIOS = 'empty';
|
|
35
47
|
const DEFAULT_JSON_REPR = '{}';
|
|
36
48
|
|
|
37
49
|
type Nullable<T> = T | null | undefined;
|
|
38
50
|
|
|
39
51
|
function normalizePlatform(value?: Nullable<string>): IapPlatform {
|
|
40
52
|
return value?.toLowerCase() === PLATFORM_IOS
|
|
41
|
-
?
|
|
42
|
-
:
|
|
53
|
+
? PLATFORM_IOS
|
|
54
|
+
: PLATFORM_ANDROID;
|
|
43
55
|
}
|
|
44
56
|
|
|
45
57
|
function normalizeProductType(value?: Nullable<string>): ProductType {
|
|
46
58
|
return value?.toLowerCase() === PRODUCT_TYPE_SUBS
|
|
47
|
-
?
|
|
48
|
-
:
|
|
59
|
+
? PRODUCT_TYPE_SUBS
|
|
60
|
+
: PRODUCT_TYPE_IN_APP;
|
|
49
61
|
}
|
|
50
62
|
|
|
51
63
|
function normalizeProductTypeIOS(value?: Nullable<string>): ProductTypeIOS {
|
|
52
64
|
switch ((value ?? '').toLowerCase()) {
|
|
53
65
|
case 'consumable':
|
|
54
|
-
return
|
|
66
|
+
return 'consumable';
|
|
55
67
|
case 'nonconsumable':
|
|
56
68
|
case 'non_consumable':
|
|
57
69
|
case 'non-consumable':
|
|
58
|
-
return
|
|
70
|
+
return 'non-consumable';
|
|
59
71
|
case 'autorenewablesubscription':
|
|
60
72
|
case 'auto_renewable_subscription':
|
|
61
73
|
case 'autorenewable':
|
|
62
|
-
return
|
|
74
|
+
return 'auto-renewable-subscription';
|
|
63
75
|
case 'nonrenewingsubscription':
|
|
64
76
|
case 'non_renewing_subscription':
|
|
65
|
-
return
|
|
77
|
+
return 'non-renewing-subscription';
|
|
66
78
|
default:
|
|
67
79
|
if (value) {
|
|
68
80
|
console.warn(
|
|
69
81
|
`[react-native-iap] Unknown iOS product type "${value}", defaulting to NonConsumable.`,
|
|
70
82
|
);
|
|
71
83
|
}
|
|
72
|
-
return
|
|
84
|
+
return 'non-consumable';
|
|
73
85
|
}
|
|
74
86
|
}
|
|
75
87
|
|
|
@@ -77,15 +89,15 @@ function normalizePaymentMode(value?: Nullable<string>): PaymentModeIOS | null {
|
|
|
77
89
|
switch ((value ?? '').toUpperCase()) {
|
|
78
90
|
case 'FREE_TRIAL':
|
|
79
91
|
case 'FREETRIAL':
|
|
80
|
-
return
|
|
92
|
+
return PAYMENT_MODE_FREE_TRIAL;
|
|
81
93
|
case 'PAY_AS_YOU_GO':
|
|
82
94
|
case 'PAYASYOUGO':
|
|
83
|
-
return
|
|
95
|
+
return PAYMENT_MODE_PAY_AS_YOU_GO;
|
|
84
96
|
case 'PAY_UP_FRONT':
|
|
85
97
|
case 'PAYUPFRONT':
|
|
86
|
-
return
|
|
98
|
+
return PAYMENT_MODE_PAY_UP_FRONT;
|
|
87
99
|
default:
|
|
88
|
-
return
|
|
100
|
+
return PAYMENT_MODE_EMPTY;
|
|
89
101
|
}
|
|
90
102
|
}
|
|
91
103
|
|
|
@@ -94,15 +106,15 @@ function normalizeSubscriptionPeriod(
|
|
|
94
106
|
): SubscriptionPeriodIOS | null {
|
|
95
107
|
switch ((value ?? '').toUpperCase()) {
|
|
96
108
|
case 'DAY':
|
|
97
|
-
return
|
|
109
|
+
return SUBSCRIPTION_PERIOD_DAY;
|
|
98
110
|
case 'WEEK':
|
|
99
|
-
return
|
|
111
|
+
return SUBSCRIPTION_PERIOD_WEEK;
|
|
100
112
|
case 'MONTH':
|
|
101
|
-
return
|
|
113
|
+
return SUBSCRIPTION_PERIOD_MONTH;
|
|
102
114
|
case 'YEAR':
|
|
103
|
-
return
|
|
115
|
+
return SUBSCRIPTION_PERIOD_YEAR;
|
|
104
116
|
default:
|
|
105
|
-
return
|
|
117
|
+
return SUBSCRIPTION_PERIOD_EMPTY;
|
|
106
118
|
}
|
|
107
119
|
}
|
|
108
120
|
|
|
@@ -110,32 +122,32 @@ function normalizePurchaseState(state: unknown): PurchaseState {
|
|
|
110
122
|
if (typeof state === 'string') {
|
|
111
123
|
switch (state.toLowerCase()) {
|
|
112
124
|
case PURCHASE_STATE_PURCHASED:
|
|
113
|
-
return
|
|
125
|
+
return PURCHASE_STATE_PURCHASED;
|
|
114
126
|
case PURCHASE_STATE_PENDING:
|
|
115
|
-
return
|
|
127
|
+
return PURCHASE_STATE_PENDING;
|
|
116
128
|
case PURCHASE_STATE_FAILED:
|
|
117
|
-
return
|
|
129
|
+
return PURCHASE_STATE_FAILED;
|
|
118
130
|
case PURCHASE_STATE_RESTORED:
|
|
119
|
-
return
|
|
131
|
+
return PURCHASE_STATE_RESTORED;
|
|
120
132
|
case PURCHASE_STATE_DEFERRED:
|
|
121
|
-
return
|
|
133
|
+
return PURCHASE_STATE_DEFERRED;
|
|
122
134
|
default:
|
|
123
|
-
return
|
|
135
|
+
return PURCHASE_STATE_UNKNOWN;
|
|
124
136
|
}
|
|
125
137
|
}
|
|
126
138
|
|
|
127
139
|
if (typeof state === 'number') {
|
|
128
140
|
switch (state) {
|
|
129
141
|
case 1:
|
|
130
|
-
return
|
|
142
|
+
return PURCHASE_STATE_PURCHASED;
|
|
131
143
|
case 2:
|
|
132
|
-
return
|
|
144
|
+
return PURCHASE_STATE_PENDING;
|
|
133
145
|
default:
|
|
134
|
-
return
|
|
146
|
+
return PURCHASE_STATE_UNKNOWN;
|
|
135
147
|
}
|
|
136
148
|
}
|
|
137
149
|
|
|
138
|
-
return
|
|
150
|
+
return PURCHASE_STATE_UNKNOWN;
|
|
139
151
|
}
|
|
140
152
|
|
|
141
153
|
function toNullableString(value: unknown): string | null {
|
|
@@ -192,7 +204,7 @@ export function convertNitroProductToProduct(
|
|
|
192
204
|
platform,
|
|
193
205
|
};
|
|
194
206
|
|
|
195
|
-
if (platform ===
|
|
207
|
+
if (platform === PLATFORM_IOS) {
|
|
196
208
|
const iosProduct: any = {
|
|
197
209
|
...base,
|
|
198
210
|
displayNameIOS: nitroProduct.displayName ?? nitroProduct.title,
|
|
@@ -241,7 +253,7 @@ export function convertNitroProductToProduct(
|
|
|
241
253
|
),
|
|
242
254
|
};
|
|
243
255
|
|
|
244
|
-
if (type ===
|
|
256
|
+
if (type === PRODUCT_TYPE_SUBS) {
|
|
245
257
|
if (!Array.isArray(androidProduct.subscriptionOfferDetailsAndroid)) {
|
|
246
258
|
androidProduct.subscriptionOfferDetailsAndroid = [];
|
|
247
259
|
}
|
|
@@ -256,7 +268,7 @@ export function convertNitroProductToProduct(
|
|
|
256
268
|
export function convertProductToProductSubscription(
|
|
257
269
|
product: Product,
|
|
258
270
|
): ProductSubscription {
|
|
259
|
-
if (product.type !==
|
|
271
|
+
if (product.type !== PRODUCT_TYPE_SUBS) {
|
|
260
272
|
console.warn(
|
|
261
273
|
'Converting non-subscription product to ProductSubscription:',
|
|
262
274
|
product.id,
|
|
@@ -265,7 +277,7 @@ export function convertProductToProductSubscription(
|
|
|
265
277
|
|
|
266
278
|
const output: any = {...(product as any)};
|
|
267
279
|
|
|
268
|
-
if (output.platform ===
|
|
280
|
+
if (output.platform === PLATFORM_ANDROID) {
|
|
269
281
|
if (!Array.isArray(output.subscriptionOfferDetailsAndroid)) {
|
|
270
282
|
output.subscriptionOfferDetailsAndroid = [];
|
|
271
283
|
}
|
|
@@ -296,7 +308,7 @@ export function convertNitroPurchaseToPurchase(
|
|
|
296
308
|
};
|
|
297
309
|
|
|
298
310
|
if (
|
|
299
|
-
purchase.purchaseState ===
|
|
311
|
+
purchase.purchaseState === PURCHASE_STATE_UNKNOWN &&
|
|
300
312
|
nitroPurchase.purchaseStateAndroid != null
|
|
301
313
|
) {
|
|
302
314
|
purchase.purchaseState = normalizePurchaseState(
|
|
@@ -304,7 +316,7 @@ export function convertNitroPurchaseToPurchase(
|
|
|
304
316
|
);
|
|
305
317
|
}
|
|
306
318
|
|
|
307
|
-
if (platform ===
|
|
319
|
+
if (platform === PLATFORM_IOS) {
|
|
308
320
|
const iosPurchase: any = purchase;
|
|
309
321
|
iosPurchase.quantityIOS = toNullableNumber(nitroPurchase.quantityIOS);
|
|
310
322
|
iosPurchase.originalTransactionDateIOS = toNullableNumber(
|