react-native-iap 8.0.0-rc.3 → 8.0.0-rc.4
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/android/build.gradle +3 -3
- package/android/src/amazon/java/com/dooboolab/RNIap/RNIapPackage.kt +1 -1
- package/android/src/play/java/com/dooboolab/RNIap/RNIapPackage.kt +4 -0
- package/index.js.flow +1 -1
- package/package.json +24 -22
- package/src/hooks/useIAP.js +4 -2
- package/src/hooks/withIAPContext.js +4 -2
- package/src/iap.d.ts +1 -1
- package/src/iap.js +28 -14
package/android/build.gradle
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
|
|
2
2
|
buildscript {
|
|
3
|
-
ext.
|
|
3
|
+
ext.kotlinVersion = '1.5.30'
|
|
4
4
|
repositories {
|
|
5
5
|
google()
|
|
6
6
|
mavenCentral()
|
|
@@ -8,7 +8,7 @@ buildscript {
|
|
|
8
8
|
|
|
9
9
|
dependencies {
|
|
10
10
|
classpath 'com.android.tools.build:gradle:4.2.2'
|
|
11
|
-
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$
|
|
11
|
+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
|
|
@@ -85,5 +85,5 @@ dependencies {
|
|
|
85
85
|
implementation "androidx.browser:browser:$androidXBrowser"
|
|
86
86
|
}
|
|
87
87
|
implementation "androidx.core:core-ktx:1.6.0"
|
|
88
|
-
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$
|
|
88
|
+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion"
|
|
89
89
|
}
|
|
@@ -38,7 +38,7 @@ import com.facebook.react.uimanager.ViewManager
|
|
|
38
38
|
|
|
39
39
|
class RNIapPackage : ReactPackage {
|
|
40
40
|
|
|
41
|
-
fun createJSModules(): MutableList<Class<out JavaScriptModule>> {
|
|
41
|
+
override fun createJSModules(): MutableList<Class<out JavaScriptModule>> {
|
|
42
42
|
return mutableListOf()
|
|
43
43
|
}
|
|
44
44
|
|
|
@@ -46,6 +46,10 @@ import com.facebook.react.uimanager.ViewManager
|
|
|
46
46
|
|
|
47
47
|
class RNIapPackage : ReactPackage {
|
|
48
48
|
|
|
49
|
+
override fun createJSModules(): MutableList<Class<out JavaScriptModule>> {
|
|
50
|
+
return mutableListOf()
|
|
51
|
+
}
|
|
52
|
+
|
|
49
53
|
override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
|
|
50
54
|
return emptyList()
|
|
51
55
|
}
|
package/index.js.flow
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-iap",
|
|
3
|
-
"version": "8.0.0-rc.
|
|
3
|
+
"version": "8.0.0-rc.4",
|
|
4
4
|
"description": "React Native In App Purchase Module.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -43,31 +43,33 @@
|
|
|
43
43
|
"dooboolab-welcome": "1.3.2"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@babel/core": "7.
|
|
47
|
-
"@babel/plugin-proposal-class-properties": "7.
|
|
48
|
-
"@babel/plugin-proposal-private-methods": "7.
|
|
49
|
-
"@babel/preset-env": "7.
|
|
50
|
-
"@babel/preset-react": "7.
|
|
51
|
-
"@babel/preset-typescript": "7.
|
|
52
|
-
"@dooboo/eslint-config": "
|
|
53
|
-
"@testing-library/jest-native": "4.0.
|
|
54
|
-
"@testing-library/react-native": "
|
|
55
|
-
"@types/
|
|
56
|
-
"@types/
|
|
57
|
-
"@types/react": "
|
|
58
|
-
"@types/react-native": "0.65.1",
|
|
46
|
+
"@babel/core": "7.16.0",
|
|
47
|
+
"@babel/plugin-proposal-class-properties": "7.16.0",
|
|
48
|
+
"@babel/plugin-proposal-private-methods": "7.16.0",
|
|
49
|
+
"@babel/preset-env": "7.16.0",
|
|
50
|
+
"@babel/preset-react": "7.16.0",
|
|
51
|
+
"@babel/preset-typescript": "7.16.0",
|
|
52
|
+
"@dooboo/eslint-config": "1.2.1",
|
|
53
|
+
"@testing-library/jest-native": "4.0.4",
|
|
54
|
+
"@testing-library/react-native": "8.0.0",
|
|
55
|
+
"@types/jest": "27.0.2",
|
|
56
|
+
"@types/react": "17.0.34",
|
|
57
|
+
"@types/react-native": "0.66.4",
|
|
59
58
|
"babel-core": "7.0.0-bridge.0",
|
|
60
|
-
"babel-
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
"
|
|
65
|
-
"jest": "27.2.0",
|
|
59
|
+
"babel-jest": "27.3.1",
|
|
60
|
+
"eslint": "8.2.0",
|
|
61
|
+
"flow-bin": "0.164.0",
|
|
62
|
+
"flowgen": "1.15.0",
|
|
63
|
+
"jest": "27.3.1",
|
|
66
64
|
"metro-react-native-babel-preset": "0.66.2",
|
|
67
65
|
"monolinter": "1.0.4",
|
|
68
66
|
"prettier": "2.4.1",
|
|
69
67
|
"react-native": "0.65.1",
|
|
70
|
-
"ts-jest": "27.0.
|
|
71
|
-
"typescript": "4.4.
|
|
68
|
+
"ts-jest": "27.0.7",
|
|
69
|
+
"typescript": "4.4.4"
|
|
70
|
+
},
|
|
71
|
+
"resolutions": {
|
|
72
|
+
"@typescript-eslint/eslint-plugin": "^5.3.1",
|
|
73
|
+
"@typescript-eslint/parser": "^5.3.1"
|
|
72
74
|
}
|
|
73
75
|
}
|
package/src/hooks/useIAP.js
CHANGED
|
@@ -104,10 +104,12 @@ export function useIAP() {
|
|
|
104
104
|
err_1 = _a.sent();
|
|
105
105
|
throw err_1;
|
|
106
106
|
case 3:
|
|
107
|
-
if (purchase.productId === (currentPurchase === null || currentPurchase === void 0 ? void 0 : currentPurchase.productId))
|
|
107
|
+
if (purchase.productId === (currentPurchase === null || currentPurchase === void 0 ? void 0 : currentPurchase.productId)) {
|
|
108
108
|
setCurrentPurchase(undefined);
|
|
109
|
-
|
|
109
|
+
}
|
|
110
|
+
if (purchase.productId === (currentPurchaseError === null || currentPurchaseError === void 0 ? void 0 : currentPurchaseError.productId)) {
|
|
110
111
|
setCurrentPurchaseError(undefined);
|
|
112
|
+
}
|
|
111
113
|
return [7 /*endfinally*/];
|
|
112
114
|
case 4: return [2 /*return*/];
|
|
113
115
|
}
|
|
@@ -52,8 +52,9 @@ var IAPEmitter = new NativeEventEmitter(RNIapIos);
|
|
|
52
52
|
var IAPContext = React.createContext(null);
|
|
53
53
|
export function useIAPContext() {
|
|
54
54
|
var ctx = useContext(IAPContext);
|
|
55
|
-
if (!ctx)
|
|
55
|
+
if (!ctx) {
|
|
56
56
|
throw new Error('You need wrap your app with withIAPContext HOC');
|
|
57
|
+
}
|
|
57
58
|
return ctx;
|
|
58
59
|
}
|
|
59
60
|
export function withIAPContext(Component) {
|
|
@@ -102,8 +103,9 @@ export function withIAPContext(Component) {
|
|
|
102
103
|
initConnection().then(setConnected);
|
|
103
104
|
}, []);
|
|
104
105
|
useEffect(function () {
|
|
105
|
-
if (!connected)
|
|
106
|
+
if (!connected) {
|
|
106
107
|
return;
|
|
108
|
+
}
|
|
107
109
|
var purchaseUpdateSubscription = purchaseUpdatedListener(function (purchase) { return __awaiter(_this, void 0, void 0, function () {
|
|
108
110
|
return __generator(this, function (_a) {
|
|
109
111
|
setCurrentPurchaseError(undefined);
|
package/src/iap.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import * as Android from './types/android';
|
|
2
1
|
import * as Amazon from './types/amazon';
|
|
2
|
+
import * as Android from './types/android';
|
|
3
3
|
import * as Apple from './types/apple';
|
|
4
4
|
import { EmitterSubscription } from 'react-native';
|
|
5
5
|
import { InAppPurchase, InstallSourceAndroid, Product, ProductPurchase, ProrationModesAndroid, PurchaseError, PurchaseResult, Subscription, SubscriptionPurchase } from './types';
|
package/src/iap.js
CHANGED
|
@@ -46,16 +46,18 @@ export var getInstallSourceAndroid = function () {
|
|
|
46
46
|
: InstallSourceAndroid.AMAZON;
|
|
47
47
|
};
|
|
48
48
|
var checkNativeAndroidAvailable = function () {
|
|
49
|
-
if (!RNIapModule && !RNIapAmazonModule)
|
|
49
|
+
if (!RNIapModule && !RNIapAmazonModule) {
|
|
50
50
|
throw new Error(IAPErrorCode.E_IAP_NOT_AVAILABLE);
|
|
51
|
+
}
|
|
51
52
|
};
|
|
52
53
|
var getAndroidModule = function () {
|
|
53
54
|
checkNativeAndroidAvailable();
|
|
54
55
|
return RNIapModule ? RNIapModule : RNIapAmazonModule;
|
|
55
56
|
};
|
|
56
57
|
var checkNativeiOSAvailable = function () {
|
|
57
|
-
if (!RNIapIos)
|
|
58
|
+
if (!RNIapIos) {
|
|
58
59
|
throw new Error(IAPErrorCode.E_IAP_NOT_AVAILABLE);
|
|
60
|
+
}
|
|
59
61
|
};
|
|
60
62
|
var getIosModule = function () {
|
|
61
63
|
checkNativeiOSAvailable();
|
|
@@ -116,8 +118,9 @@ var fillProductsAdditionalData = function (products) { return __awaiter(void 0,
|
|
|
116
118
|
currency_1 = currencies[user.userMarketplaceAmazon];
|
|
117
119
|
// Add currency to products
|
|
118
120
|
products.forEach(function (product) {
|
|
119
|
-
if (currency_1)
|
|
121
|
+
if (currency_1) {
|
|
120
122
|
product.currency = currency_1;
|
|
123
|
+
}
|
|
121
124
|
});
|
|
122
125
|
_a.label = 2;
|
|
123
126
|
case 2: return [2 /*return*/, products];
|
|
@@ -265,11 +268,12 @@ export var requestPurchase = function (sku, andDangerouslyFinishTransactionAutom
|
|
|
265
268
|
return (Platform.select({
|
|
266
269
|
ios: function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
267
270
|
return __generator(this, function (_a) {
|
|
268
|
-
if (andDangerouslyFinishTransactionAutomaticallyIOS)
|
|
271
|
+
if (andDangerouslyFinishTransactionAutomaticallyIOS) {
|
|
269
272
|
// eslint-disable-next-line no-console
|
|
270
273
|
console.warn(
|
|
271
274
|
// eslint-disable-next-line max-len
|
|
272
275
|
'You are dangerously allowing react-native-iap to finish your transaction automatically. You should set andDangerouslyFinishTransactionAutomatically to false when calling requestPurchase and call finishTransaction manually when you have delivered the purchased goods to the user. It defaults to true to provide backwards compatibility. Will default to false in version 4.0.0.');
|
|
276
|
+
}
|
|
273
277
|
return [2 /*return*/, getIosModule().buyProduct(sku, andDangerouslyFinishTransactionAutomaticallyIOS)];
|
|
274
278
|
});
|
|
275
279
|
}); },
|
|
@@ -299,11 +303,12 @@ export var requestSubscription = function (sku, andDangerouslyFinishTransactionA
|
|
|
299
303
|
return (Platform.select({
|
|
300
304
|
ios: function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
301
305
|
return __generator(this, function (_a) {
|
|
302
|
-
if (andDangerouslyFinishTransactionAutomaticallyIOS)
|
|
306
|
+
if (andDangerouslyFinishTransactionAutomaticallyIOS) {
|
|
303
307
|
// eslint-disable-next-line no-console
|
|
304
308
|
console.warn(
|
|
305
309
|
// eslint-disable-next-line max-len
|
|
306
310
|
'You are dangerously allowing react-native-iap to finish your transaction automatically. You should set andDangerouslyFinishTransactionAutomatically to false when calling requestPurchase and call finishTransaction manually when you have delivered the purchased goods to the user. It defaults to true to provide backwards compatibility. Will default to false in version 4.0.0.');
|
|
311
|
+
}
|
|
307
312
|
return [2 /*return*/, getIosModule().buyProduct(sku, andDangerouslyFinishTransactionAutomaticallyIOS)];
|
|
308
313
|
});
|
|
309
314
|
}); },
|
|
@@ -343,17 +348,22 @@ export var finishTransaction = function (purchase, isConsumable, developerPayloa
|
|
|
343
348
|
}); },
|
|
344
349
|
android: function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
345
350
|
return __generator(this, function (_a) {
|
|
346
|
-
if (purchase)
|
|
347
|
-
if (isConsumable)
|
|
351
|
+
if (purchase) {
|
|
352
|
+
if (isConsumable) {
|
|
348
353
|
return [2 /*return*/, getAndroidModule().consumeProduct(purchase.purchaseToken, developerPayloadAndroid)];
|
|
354
|
+
}
|
|
349
355
|
else if (purchase.userIdAmazon ||
|
|
350
356
|
(!purchase.isAcknowledgedAndroid &&
|
|
351
|
-
purchase.purchaseStateAndroid === PurchaseStateAndroid.PURCHASED))
|
|
357
|
+
purchase.purchaseStateAndroid === PurchaseStateAndroid.PURCHASED)) {
|
|
352
358
|
return [2 /*return*/, getAndroidModule().acknowledgePurchase(purchase.purchaseToken, developerPayloadAndroid)];
|
|
353
|
-
|
|
359
|
+
}
|
|
360
|
+
else {
|
|
354
361
|
throw new Error('purchase is not suitable to be purchased');
|
|
355
|
-
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
else {
|
|
356
365
|
throw new Error('purchase is not assigned');
|
|
366
|
+
}
|
|
357
367
|
return [2 /*return*/];
|
|
358
368
|
});
|
|
359
369
|
}); },
|
|
@@ -424,10 +434,11 @@ var fetchJsonOrThrow = function (url, receiptBody) { return __awaiter(void 0, vo
|
|
|
424
434
|
})];
|
|
425
435
|
case 1:
|
|
426
436
|
response = _a.sent();
|
|
427
|
-
if (!response.ok)
|
|
437
|
+
if (!response.ok) {
|
|
428
438
|
throw Object.assign(new Error(response.statusText), {
|
|
429
439
|
statusCode: response.status,
|
|
430
440
|
});
|
|
441
|
+
}
|
|
431
442
|
return [2 /*return*/, response.json()];
|
|
432
443
|
}
|
|
433
444
|
});
|
|
@@ -518,10 +529,11 @@ export var validateReceiptAndroid = function (packageName, productId, productTok
|
|
|
518
529
|
})];
|
|
519
530
|
case 1:
|
|
520
531
|
response = _a.sent();
|
|
521
|
-
if (!response.ok)
|
|
532
|
+
if (!response.ok) {
|
|
522
533
|
throw Object.assign(new Error(response.statusText), {
|
|
523
534
|
statusCode: response.status,
|
|
524
535
|
});
|
|
536
|
+
}
|
|
525
537
|
return [2 /*return*/, response.json()];
|
|
526
538
|
}
|
|
527
539
|
});
|
|
@@ -553,10 +565,11 @@ export var validateReceiptAmazon = function (developerSecret, userId, receiptId,
|
|
|
553
565
|
})];
|
|
554
566
|
case 1:
|
|
555
567
|
response = _a.sent();
|
|
556
|
-
if (!response.ok)
|
|
568
|
+
if (!response.ok) {
|
|
557
569
|
throw Object.assign(new Error(response.statusText), {
|
|
558
570
|
statusCode: response.status,
|
|
559
571
|
});
|
|
572
|
+
}
|
|
560
573
|
return [2 /*return*/, response.json()];
|
|
561
574
|
}
|
|
562
575
|
});
|
|
@@ -569,8 +582,9 @@ export var validateReceiptAmazon = function (developerSecret, userId, receiptId,
|
|
|
569
582
|
export var purchaseUpdatedListener = function (listener) {
|
|
570
583
|
var myModuleEvt = new NativeEventEmitter(getNativeModule());
|
|
571
584
|
var emitterSubscription = myModuleEvt.addListener('purchase-updated', listener);
|
|
572
|
-
if (Platform.OS === 'android')
|
|
585
|
+
if (Platform.OS === 'android') {
|
|
573
586
|
getAndroidModule().startListening();
|
|
587
|
+
}
|
|
574
588
|
return emitterSubscription;
|
|
575
589
|
};
|
|
576
590
|
/**
|