react-native-iap 9.0.3 → 10.0.1
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/src/amazon/java/com/dooboolab/RNIap/RNIapAmazonModule.kt +2 -1
- package/android/src/play/java/com/dooboolab/RNIap/RNIapModule.kt +2 -1
- package/lib/commonjs/eventEmitter.js +54 -0
- package/lib/commonjs/eventEmitter.js.map +1 -0
- package/lib/commonjs/hooks/useIAP.js +33 -15
- package/lib/commonjs/hooks/useIAP.js.map +1 -1
- package/lib/commonjs/hooks/withIAPContext.js +9 -7
- package/lib/commonjs/hooks/withIAPContext.js.map +1 -1
- package/lib/commonjs/iap.js +131 -197
- package/lib/commonjs/iap.js.map +1 -1
- package/lib/commonjs/index.js +28 -15
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/internal/enhancedFetch.js +30 -0
- package/lib/commonjs/internal/enhancedFetch.js.map +1 -0
- package/lib/commonjs/internal/fillProductsWithAdditionalData.js +47 -0
- package/lib/commonjs/internal/fillProductsWithAdditionalData.js.map +1 -0
- package/lib/commonjs/internal/index.js +45 -0
- package/lib/commonjs/internal/index.js.map +1 -0
- package/lib/commonjs/internal/platform.js +19 -0
- package/lib/commonjs/internal/platform.js.map +1 -0
- package/lib/commonjs/purchaseError.js +47 -0
- package/lib/commonjs/purchaseError.js.map +1 -0
- package/lib/commonjs/types/index.js +1 -23
- package/lib/commonjs/types/index.js.map +1 -1
- package/lib/module/eventEmitter.js +36 -0
- package/lib/module/eventEmitter.js.map +1 -0
- package/lib/module/hooks/useIAP.js +34 -16
- package/lib/module/hooks/useIAP.js.map +1 -1
- package/lib/module/hooks/withIAPContext.js +6 -5
- package/lib/module/hooks/withIAPContext.js.map +1 -1
- package/lib/module/iap.js +123 -186
- package/lib/module/iap.js.map +1 -1
- package/lib/module/index.js +2 -2
- package/lib/module/index.js.map +1 -1
- package/lib/module/internal/enhancedFetch.js +21 -0
- package/lib/module/internal/enhancedFetch.js.map +1 -0
- package/lib/module/internal/fillProductsWithAdditionalData.js +37 -0
- package/lib/module/internal/fillProductsWithAdditionalData.js.map +1 -0
- package/lib/module/internal/index.js +4 -0
- package/lib/module/internal/index.js.map +1 -0
- package/lib/module/internal/platform.js +8 -0
- package/lib/module/internal/platform.js.map +1 -0
- package/lib/module/purchaseError.js +38 -0
- package/lib/module/purchaseError.js.map +1 -0
- package/lib/module/types/index.js +0 -21
- package/lib/module/types/index.js.map +1 -1
- package/lib/typescript/eventEmitter.d.ts +17 -0
- package/lib/typescript/hooks/useIAP.d.ts +15 -9
- package/lib/typescript/hooks/withIAPContext.d.ts +4 -3
- package/lib/typescript/iap.d.ts +80 -41
- package/lib/typescript/index.d.ts +2 -2
- package/lib/typescript/internal/enhancedFetch.d.ts +6 -0
- package/lib/typescript/internal/fillProductsWithAdditionalData.d.ts +5 -0
- package/lib/typescript/internal/index.d.ts +3 -0
- package/lib/typescript/internal/platform.d.ts +3 -0
- package/lib/typescript/purchaseError.d.ts +26 -0
- package/lib/typescript/types/index.d.ts +1 -48
- package/package.json +1 -1
- package/src/eventEmitter.ts +49 -0
- package/src/hooks/useIAP.ts +38 -35
- package/src/hooks/withIAPContext.tsx +12 -13
- package/src/iap.ts +165 -242
- package/src/index.ts +2 -4
- package/src/internal/enhancedFetch.ts +25 -0
- package/src/internal/fillProductsWithAdditionalData.ts +43 -0
- package/src/internal/index.ts +3 -0
- package/src/internal/platform.ts +7 -0
- package/src/purchaseError.ts +35 -0
- package/src/types/index.ts +1 -59
|
@@ -9,8 +9,9 @@ import com.facebook.react.bridge.ReactContextBaseJavaModule
|
|
|
9
9
|
import com.facebook.react.bridge.ReactMethod
|
|
10
10
|
import com.facebook.react.bridge.ReadableArray
|
|
11
11
|
import com.facebook.react.bridge.WritableNativeArray
|
|
12
|
+
import com.facebook.react.module.annotations.ReactModule
|
|
12
13
|
import java.util.HashSet
|
|
13
|
-
|
|
14
|
+
@ReactModule(name = RNIapAmazonModule.TAG)
|
|
14
15
|
class RNIapAmazonModule(reactContext: ReactApplicationContext) :
|
|
15
16
|
ReactContextBaseJavaModule(reactContext) {
|
|
16
17
|
var hasListener = false
|
|
@@ -30,11 +30,12 @@ import com.facebook.react.bridge.WritableArray
|
|
|
30
30
|
import com.facebook.react.bridge.WritableMap
|
|
31
31
|
import com.facebook.react.bridge.WritableNativeArray
|
|
32
32
|
import com.facebook.react.bridge.WritableNativeMap
|
|
33
|
+
import com.facebook.react.module.annotations.ReactModule
|
|
33
34
|
import com.facebook.react.modules.core.DeviceEventManagerModule.RCTDeviceEventEmitter
|
|
34
35
|
import com.google.android.gms.common.ConnectionResult
|
|
35
36
|
import com.google.android.gms.common.GoogleApiAvailability
|
|
36
37
|
import java.util.ArrayList
|
|
37
|
-
|
|
38
|
+
@ReactModule(name = RNIapModule.TAG)
|
|
38
39
|
class RNIapModule(
|
|
39
40
|
private val reactContext: ReactApplicationContext,
|
|
40
41
|
private val builder: BillingClient.Builder = BillingClient.newBuilder(reactContext).enablePendingPurchases(),
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.purchaseUpdatedListener = exports.purchaseErrorListener = exports.promotedProductListener = void 0;
|
|
7
|
+
|
|
8
|
+
var _reactNative = require("react-native");
|
|
9
|
+
|
|
10
|
+
var _iap = require("./iap");
|
|
11
|
+
|
|
12
|
+
var _internal = require("./internal");
|
|
13
|
+
|
|
14
|
+
const eventEmitter = new _reactNative.NativeEventEmitter((0, _iap.getNativeModule)());
|
|
15
|
+
/**
|
|
16
|
+
* Add IAP purchase event
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
const purchaseUpdatedListener = listener => {
|
|
20
|
+
const emitterSubscription = eventEmitter.addListener('purchase-updated', listener);
|
|
21
|
+
|
|
22
|
+
if (_internal.isAndroid) {
|
|
23
|
+
(0, _iap.getAndroidModule)().startListening();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return emitterSubscription;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Add IAP purchase error event
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
exports.purchaseUpdatedListener = purchaseUpdatedListener;
|
|
34
|
+
|
|
35
|
+
const purchaseErrorListener = listener => eventEmitter.addListener('purchase-error', listener);
|
|
36
|
+
/**
|
|
37
|
+
* Add IAP promoted subscription event
|
|
38
|
+
*
|
|
39
|
+
* @platform iOS
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
exports.purchaseErrorListener = purchaseErrorListener;
|
|
44
|
+
|
|
45
|
+
const promotedProductListener = listener => {
|
|
46
|
+
if (_internal.isIos) {
|
|
47
|
+
return new _reactNative.NativeEventEmitter((0, _iap.getIosModule)()).addListener('iap-promoted-product', listener);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return null;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
exports.promotedProductListener = promotedProductListener;
|
|
54
|
+
//# sourceMappingURL=eventEmitter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["eventEmitter","NativeEventEmitter","getNativeModule","purchaseUpdatedListener","listener","emitterSubscription","addListener","isAndroid","getAndroidModule","startListening","purchaseErrorListener","promotedProductListener","isIos","getIosModule"],"sources":["eventEmitter.ts"],"sourcesContent":["import {EmitterSubscription, NativeEventEmitter} from 'react-native';\n\nimport {getAndroidModule, getIosModule, getNativeModule} from './iap';\nimport {isAndroid, isIos} from './internal';\nimport type {PurchaseError} from './purchaseError';\nimport type {Purchase} from './types';\n\nconst eventEmitter = new NativeEventEmitter(getNativeModule());\n\n/**\n * Add IAP purchase event\n */\nexport const purchaseUpdatedListener = (\n listener: (event: Purchase) => void,\n) => {\n const emitterSubscription = eventEmitter.addListener(\n 'purchase-updated',\n listener,\n );\n\n if (isAndroid) {\n getAndroidModule().startListening();\n }\n\n return emitterSubscription;\n};\n\n/**\n * Add IAP purchase error event\n */\nexport const purchaseErrorListener = (\n listener: (error: PurchaseError) => void,\n): EmitterSubscription => eventEmitter.addListener('purchase-error', listener);\n\n/**\n * Add IAP promoted subscription event\n *\n * @platform iOS\n */\nexport const promotedProductListener = (listener: () => void) => {\n if (isIos) {\n return new NativeEventEmitter(getIosModule()).addListener(\n 'iap-promoted-product',\n listener,\n );\n }\n\n return null;\n};\n"],"mappings":";;;;;;;AAAA;;AAEA;;AACA;;AAIA,MAAMA,YAAY,GAAG,IAAIC,+BAAJ,CAAuB,IAAAC,oBAAA,GAAvB,CAArB;AAEA;AACA;AACA;;AACO,MAAMC,uBAAuB,GAClCC,QADqC,IAElC;EACH,MAAMC,mBAAmB,GAAGL,YAAY,CAACM,WAAb,CAC1B,kBAD0B,EAE1BF,QAF0B,CAA5B;;EAKA,IAAIG,mBAAJ,EAAe;IACb,IAAAC,qBAAA,IAAmBC,cAAnB;EACD;;EAED,OAAOJ,mBAAP;AACD,CAbM;AAeP;AACA;AACA;;;;;AACO,MAAMK,qBAAqB,GAChCN,QADmC,IAEXJ,YAAY,CAACM,WAAb,CAAyB,gBAAzB,EAA2CF,QAA3C,CAFnB;AAIP;AACA;AACA;AACA;AACA;;;;;AACO,MAAMO,uBAAuB,GAAIP,QAAD,IAA0B;EAC/D,IAAIQ,eAAJ,EAAW;IACT,OAAO,IAAIX,+BAAJ,CAAuB,IAAAY,iBAAA,GAAvB,EAAuCP,WAAvC,CACL,sBADK,EAELF,QAFK,CAAP;EAID;;EAED,OAAO,IAAP;AACD,CATM"}
|
|
@@ -17,7 +17,7 @@ function useIAP() {
|
|
|
17
17
|
products,
|
|
18
18
|
promotedProductsIOS,
|
|
19
19
|
subscriptions,
|
|
20
|
-
|
|
20
|
+
purchaseHistory,
|
|
21
21
|
availablePurchases,
|
|
22
22
|
currentPurchase,
|
|
23
23
|
currentPurchaseError,
|
|
@@ -25,25 +25,45 @@ function useIAP() {
|
|
|
25
25
|
setProducts,
|
|
26
26
|
setSubscriptions,
|
|
27
27
|
setAvailablePurchases,
|
|
28
|
-
|
|
28
|
+
setPurchaseHistory,
|
|
29
29
|
setCurrentPurchase,
|
|
30
30
|
setCurrentPurchaseError
|
|
31
31
|
} = (0, _withIAPContext.useIAPContext)();
|
|
32
|
-
const getProducts = (0, _react.useCallback)(async
|
|
33
|
-
|
|
32
|
+
const getProducts = (0, _react.useCallback)(async _ref => {
|
|
33
|
+
let {
|
|
34
|
+
skus
|
|
35
|
+
} = _ref;
|
|
36
|
+
setProducts(await (0, _iap.getProducts)({
|
|
37
|
+
skus
|
|
38
|
+
}));
|
|
34
39
|
}, [setProducts]);
|
|
35
|
-
const getSubscriptions = (0, _react.useCallback)(async
|
|
36
|
-
|
|
40
|
+
const getSubscriptions = (0, _react.useCallback)(async _ref2 => {
|
|
41
|
+
let {
|
|
42
|
+
skus
|
|
43
|
+
} = _ref2;
|
|
44
|
+
setSubscriptions(await (0, _iap.getSubscriptions)({
|
|
45
|
+
skus
|
|
46
|
+
}));
|
|
37
47
|
}, [setSubscriptions]);
|
|
38
48
|
const getAvailablePurchases = (0, _react.useCallback)(async () => {
|
|
39
49
|
setAvailablePurchases(await (0, _iap.getAvailablePurchases)());
|
|
40
50
|
}, [setAvailablePurchases]);
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
}, [
|
|
44
|
-
const finishTransaction = (0, _react.useCallback)(async
|
|
51
|
+
const getPurchaseHistory = (0, _react.useCallback)(async () => {
|
|
52
|
+
setPurchaseHistory(await (0, _iap.getPurchaseHistory)());
|
|
53
|
+
}, [setPurchaseHistory]);
|
|
54
|
+
const finishTransaction = (0, _react.useCallback)(async _ref3 => {
|
|
55
|
+
let {
|
|
56
|
+
purchase,
|
|
57
|
+
isConsumable,
|
|
58
|
+
developerPayloadAndroid
|
|
59
|
+
} = _ref3;
|
|
60
|
+
|
|
45
61
|
try {
|
|
46
|
-
return await (0, _iap.finishTransaction)(
|
|
62
|
+
return await (0, _iap.finishTransaction)({
|
|
63
|
+
purchase,
|
|
64
|
+
isConsumable,
|
|
65
|
+
developerPayloadAndroid
|
|
66
|
+
});
|
|
47
67
|
} catch (err) {
|
|
48
68
|
throw err;
|
|
49
69
|
} finally {
|
|
@@ -61,7 +81,7 @@ function useIAP() {
|
|
|
61
81
|
products,
|
|
62
82
|
promotedProductsIOS,
|
|
63
83
|
subscriptions,
|
|
64
|
-
|
|
84
|
+
purchaseHistory,
|
|
65
85
|
availablePurchases,
|
|
66
86
|
currentPurchase,
|
|
67
87
|
currentPurchaseError,
|
|
@@ -70,9 +90,7 @@ function useIAP() {
|
|
|
70
90
|
getProducts,
|
|
71
91
|
getSubscriptions,
|
|
72
92
|
getAvailablePurchases,
|
|
73
|
-
|
|
74
|
-
requestPurchase: _iap.requestPurchase,
|
|
75
|
-
requestSubscription: _iap.requestSubscription
|
|
93
|
+
getPurchaseHistory
|
|
76
94
|
};
|
|
77
95
|
}
|
|
78
96
|
//# sourceMappingURL=useIAP.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useIAP","connected","products","promotedProductsIOS","subscriptions","
|
|
1
|
+
{"version":3,"names":["useIAP","connected","products","promotedProductsIOS","subscriptions","purchaseHistory","availablePurchases","currentPurchase","currentPurchaseError","initConnectionError","setProducts","setSubscriptions","setAvailablePurchases","setPurchaseHistory","setCurrentPurchase","setCurrentPurchaseError","useIAPContext","getProducts","useCallback","skus","iapGetProducts","getSubscriptions","iapGetSubscriptions","getAvailablePurchases","iapGetAvailablePurchases","getPurchaseHistory","iapGetPurchaseHistory","finishTransaction","purchase","isConsumable","developerPayloadAndroid","iapFinishTransaction","err","productId","undefined"],"sources":["useIAP.ts"],"sourcesContent":["import {useCallback} from 'react';\n\nimport {\n finishTransaction as iapFinishTransaction,\n getAvailablePurchases as iapGetAvailablePurchases,\n getProducts as iapGetProducts,\n getPurchaseHistory as iapGetPurchaseHistory,\n getSubscriptions as iapGetSubscriptions,\n} from '../iap';\nimport type {PurchaseError} from '../purchaseError';\nimport type {Product, Purchase, Subscription} from '../types';\n\nimport {useIAPContext} from './withIAPContext';\n\ntype IAP_STATUS = {\n connected: boolean;\n products: Product[];\n promotedProductsIOS: Product[];\n subscriptions: Subscription[];\n purchaseHistory: Purchase[];\n availablePurchases: Purchase[];\n currentPurchase?: Purchase;\n currentPurchaseError?: PurchaseError;\n initConnectionError?: Error;\n finishTransaction: ({\n purchase,\n isConsumable,\n developerPayloadAndroid,\n }: {\n purchase: Purchase;\n isConsumable?: boolean;\n developerPayloadAndroid?: string;\n }) => Promise<string | void>;\n getAvailablePurchases: () => Promise<void>;\n getPurchaseHistory: () => Promise<void>;\n getProducts: ({skus}: {skus: string[]}) => Promise<void>;\n getSubscriptions: ({skus}: {skus: string[]}) => Promise<void>;\n};\n\nexport function useIAP(): IAP_STATUS {\n const {\n connected,\n products,\n promotedProductsIOS,\n subscriptions,\n purchaseHistory,\n availablePurchases,\n currentPurchase,\n currentPurchaseError,\n initConnectionError,\n setProducts,\n setSubscriptions,\n setAvailablePurchases,\n setPurchaseHistory,\n setCurrentPurchase,\n setCurrentPurchaseError,\n } = useIAPContext();\n\n const getProducts = useCallback(\n async ({skus}: {skus: string[]}): Promise<void> => {\n setProducts(await iapGetProducts({skus}));\n },\n [setProducts],\n );\n\n const getSubscriptions = useCallback(\n async ({skus}: {skus: string[]}): Promise<void> => {\n setSubscriptions(await iapGetSubscriptions({skus}));\n },\n [setSubscriptions],\n );\n\n const getAvailablePurchases = useCallback(async (): Promise<void> => {\n setAvailablePurchases(await iapGetAvailablePurchases());\n }, [setAvailablePurchases]);\n\n const getPurchaseHistory = useCallback(async (): Promise<void> => {\n setPurchaseHistory(await iapGetPurchaseHistory());\n }, [setPurchaseHistory]);\n\n const finishTransaction = useCallback(\n async ({\n purchase,\n isConsumable,\n developerPayloadAndroid,\n }: {\n purchase: Purchase;\n isConsumable?: boolean;\n developerPayloadAndroid?: string;\n }): Promise<string | void> => {\n try {\n return await iapFinishTransaction({\n purchase,\n isConsumable,\n developerPayloadAndroid,\n });\n } catch (err) {\n throw err;\n } finally {\n if (purchase.productId === currentPurchase?.productId) {\n setCurrentPurchase(undefined);\n }\n\n if (purchase.productId === currentPurchaseError?.productId) {\n setCurrentPurchaseError(undefined);\n }\n }\n },\n [\n currentPurchase?.productId,\n currentPurchaseError?.productId,\n setCurrentPurchase,\n setCurrentPurchaseError,\n ],\n );\n\n return {\n connected,\n products,\n promotedProductsIOS,\n subscriptions,\n purchaseHistory,\n availablePurchases,\n currentPurchase,\n currentPurchaseError,\n initConnectionError,\n finishTransaction,\n getProducts,\n getSubscriptions,\n getAvailablePurchases,\n getPurchaseHistory,\n };\n}\n"],"mappings":";;;;;;;AAAA;;AAEA;;AAUA;;AA2BO,SAASA,MAAT,GAA8B;EACnC,MAAM;IACJC,SADI;IAEJC,QAFI;IAGJC,mBAHI;IAIJC,aAJI;IAKJC,eALI;IAMJC,kBANI;IAOJC,eAPI;IAQJC,oBARI;IASJC,mBATI;IAUJC,WAVI;IAWJC,gBAXI;IAYJC,qBAZI;IAaJC,kBAbI;IAcJC,kBAdI;IAeJC;EAfI,IAgBF,IAAAC,6BAAA,GAhBJ;EAkBA,MAAMC,WAAW,GAAG,IAAAC,kBAAA,EAClB,cAAmD;IAAA,IAA5C;MAACC;IAAD,CAA4C;IACjDT,WAAW,CAAC,MAAM,IAAAU,gBAAA,EAAe;MAACD;IAAD,CAAf,CAAP,CAAX;EACD,CAHiB,EAIlB,CAACT,WAAD,CAJkB,CAApB;EAOA,MAAMW,gBAAgB,GAAG,IAAAH,kBAAA,EACvB,eAAmD;IAAA,IAA5C;MAACC;IAAD,CAA4C;IACjDR,gBAAgB,CAAC,MAAM,IAAAW,qBAAA,EAAoB;MAACH;IAAD,CAApB,CAAP,CAAhB;EACD,CAHsB,EAIvB,CAACR,gBAAD,CAJuB,CAAzB;EAOA,MAAMY,qBAAqB,GAAG,IAAAL,kBAAA,EAAY,YAA2B;IACnEN,qBAA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AAP;AAgBD"}
|
|
@@ -8,6 +8,8 @@ exports.withIAPContext = withIAPContext;
|
|
|
8
8
|
|
|
9
9
|
var _react = _interopRequireWildcard(require("react"));
|
|
10
10
|
|
|
11
|
+
var _eventEmitter = require("../eventEmitter");
|
|
12
|
+
|
|
11
13
|
var _iap = require("../iap");
|
|
12
14
|
|
|
13
15
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
@@ -33,7 +35,7 @@ function withIAPContext(Component) {
|
|
|
33
35
|
const [products, setProducts] = (0, _react.useState)([]);
|
|
34
36
|
const [promotedProductsIOS, setPromotedProductsIOS] = (0, _react.useState)([]);
|
|
35
37
|
const [subscriptions, setSubscriptions] = (0, _react.useState)([]);
|
|
36
|
-
const [
|
|
38
|
+
const [purchaseHistory, setPurchaseHistory] = (0, _react.useState)([]);
|
|
37
39
|
const [availablePurchases, setAvailablePurchases] = (0, _react.useState)([]);
|
|
38
40
|
const [currentPurchase, setCurrentPurchase] = (0, _react.useState)();
|
|
39
41
|
const [currentPurchaseError, setCurrentPurchaseError] = (0, _react.useState)();
|
|
@@ -43,18 +45,18 @@ function withIAPContext(Component) {
|
|
|
43
45
|
products,
|
|
44
46
|
subscriptions,
|
|
45
47
|
promotedProductsIOS,
|
|
46
|
-
|
|
48
|
+
purchaseHistory,
|
|
47
49
|
availablePurchases,
|
|
48
50
|
currentPurchase,
|
|
49
51
|
currentPurchaseError,
|
|
50
52
|
initConnectionError,
|
|
51
53
|
setProducts,
|
|
52
54
|
setSubscriptions,
|
|
53
|
-
|
|
55
|
+
setPurchaseHistory,
|
|
54
56
|
setAvailablePurchases,
|
|
55
57
|
setCurrentPurchase,
|
|
56
58
|
setCurrentPurchaseError
|
|
57
|
-
}), [connected, products, subscriptions, promotedProductsIOS,
|
|
59
|
+
}), [connected, products, subscriptions, promotedProductsIOS, purchaseHistory, availablePurchases, currentPurchase, currentPurchaseError, initConnectionError, setProducts, setSubscriptions, setPurchaseHistory, setAvailablePurchases, setCurrentPurchase, setCurrentPurchaseError]);
|
|
58
60
|
(0, _react.useEffect)(() => {
|
|
59
61
|
(0, _iap.initConnection)().then(value => {
|
|
60
62
|
setInitConnectionError(undefined);
|
|
@@ -66,15 +68,15 @@ function withIAPContext(Component) {
|
|
|
66
68
|
return;
|
|
67
69
|
}
|
|
68
70
|
|
|
69
|
-
const purchaseUpdateSubscription = (0,
|
|
71
|
+
const purchaseUpdateSubscription = (0, _eventEmitter.purchaseUpdatedListener)(async purchase => {
|
|
70
72
|
setCurrentPurchaseError(undefined);
|
|
71
73
|
setCurrentPurchase(purchase);
|
|
72
74
|
});
|
|
73
|
-
const purchaseErrorSubscription = (0,
|
|
75
|
+
const purchaseErrorSubscription = (0, _eventEmitter.purchaseErrorListener)(error => {
|
|
74
76
|
setCurrentPurchase(undefined);
|
|
75
77
|
setCurrentPurchaseError(error);
|
|
76
78
|
});
|
|
77
|
-
const promotedProductSubscription = (0,
|
|
79
|
+
const promotedProductSubscription = (0, _eventEmitter.promotedProductListener)(async () => {
|
|
78
80
|
const product = await (0, _iap.getPromotedProductIOS)();
|
|
79
81
|
setPromotedProductsIOS(prevProducts => [...prevProducts, ...(product ? [product] : [])]);
|
|
80
82
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["IAPContext","React","createContext","useIAPContext","ctx","useContext","Error","withIAPContext","Component","WrapperComponent","props","connected","setConnected","useState","products","setProducts","promotedProductsIOS","setPromotedProductsIOS","subscriptions","setSubscriptions","
|
|
1
|
+
{"version":3,"names":["IAPContext","React","createContext","useIAPContext","ctx","useContext","Error","withIAPContext","Component","WrapperComponent","props","connected","setConnected","useState","products","setProducts","promotedProductsIOS","setPromotedProductsIOS","subscriptions","setSubscriptions","purchaseHistory","setPurchaseHistory","availablePurchases","setAvailablePurchases","currentPurchase","setCurrentPurchase","currentPurchaseError","setCurrentPurchaseError","initConnectionError","setInitConnectionError","context","useMemo","useEffect","initConnection","then","value","undefined","catch","purchaseUpdateSubscription","purchaseUpdatedListener","purchase","purchaseErrorSubscription","purchaseErrorListener","error","promotedProductSubscription","promotedProductListener","product","getPromotedProductIOS","prevProducts","remove"],"sources":["withIAPContext.tsx"],"sourcesContent":["import React, {useContext, useEffect, useMemo, useState} from 'react';\n\nimport {\n promotedProductListener,\n purchaseErrorListener,\n purchaseUpdatedListener,\n} from '../eventEmitter';\nimport {getPromotedProductIOS, initConnection} from '../iap';\nimport type {PurchaseError} from '../purchaseError';\nimport type {\n Product,\n ProductPurchase,\n Purchase,\n Subscription,\n SubscriptionPurchase,\n} from '../types';\n\ntype IAPContextType = {\n connected: boolean;\n products: Product[];\n promotedProductsIOS: Product[];\n subscriptions: Subscription[];\n purchaseHistory: Purchase[];\n availablePurchases: Purchase[];\n currentPurchase?: Purchase;\n currentPurchaseError?: PurchaseError;\n initConnectionError?: Error;\n setProducts: (products: Product[]) => void;\n setSubscriptions: (subscriptions: Subscription[]) => void;\n setPurchaseHistory: (purchaseHistory: Purchase[]) => void;\n setAvailablePurchases: (availablePurchases: Purchase[]) => void;\n setCurrentPurchase: (currentPurchase: Purchase | undefined) => void;\n setCurrentPurchaseError: (\n currentPurchaseError: PurchaseError | undefined,\n ) => void;\n};\n\n// @ts-ignore\nconst IAPContext = React.createContext<IAPContextType>(null);\n\nexport function useIAPContext(): IAPContextType {\n const ctx = useContext(IAPContext);\n\n if (!ctx) {\n throw new Error('You need wrap your app with withIAPContext HOC');\n }\n\n return ctx;\n}\n\nexport function withIAPContext<T>(Component: React.ComponentType<T>) {\n return function WrapperComponent(props: T) {\n const [connected, setConnected] = useState(false);\n const [products, setProducts] = useState<Product[]>([]);\n\n const [promotedProductsIOS, setPromotedProductsIOS] = useState<Product[]>(\n [],\n );\n const [subscriptions, setSubscriptions] = useState<Subscription[]>([]);\n const [purchaseHistory, setPurchaseHistory] = useState<Purchase[]>([]);\n\n const [availablePurchases, setAvailablePurchases] = useState<Purchase[]>(\n [],\n );\n const [currentPurchase, setCurrentPurchase] = useState<Purchase>();\n\n const [currentPurchaseError, setCurrentPurchaseError] =\n useState<PurchaseError>();\n\n const [initConnectionError, setInitConnectionError] = useState<Error>();\n\n const context = useMemo(\n () => ({\n connected,\n products,\n subscriptions,\n promotedProductsIOS,\n purchaseHistory,\n availablePurchases,\n currentPurchase,\n currentPurchaseError,\n initConnectionError,\n setProducts,\n setSubscriptions,\n setPurchaseHistory,\n setAvailablePurchases,\n setCurrentPurchase,\n setCurrentPurchaseError,\n }),\n [\n connected,\n products,\n subscriptions,\n promotedProductsIOS,\n purchaseHistory,\n availablePurchases,\n currentPurchase,\n currentPurchaseError,\n initConnectionError,\n setProducts,\n setSubscriptions,\n setPurchaseHistory,\n setAvailablePurchases,\n setCurrentPurchase,\n setCurrentPurchaseError,\n ],\n );\n\n useEffect(() => {\n initConnection()\n .then((value) => {\n setInitConnectionError(undefined);\n setConnected(value);\n })\n .catch(setInitConnectionError);\n }, []);\n\n useEffect(() => {\n if (!connected) {\n return;\n }\n\n const purchaseUpdateSubscription = purchaseUpdatedListener(\n async (purchase: ProductPurchase | SubscriptionPurchase) => {\n setCurrentPurchaseError(undefined);\n setCurrentPurchase(purchase);\n },\n );\n\n const purchaseErrorSubscription = purchaseErrorListener(\n (error: PurchaseError) => {\n setCurrentPurchase(undefined);\n setCurrentPurchaseError(error);\n },\n );\n\n const promotedProductSubscription = promotedProductListener(async () => {\n const product = await getPromotedProductIOS();\n\n setPromotedProductsIOS((prevProducts) => [\n ...prevProducts,\n ...(product ? [product] : []),\n ]);\n });\n\n return () => {\n purchaseUpdateSubscription.remove();\n purchaseErrorSubscription.remove();\n promotedProductSubscription?.remove();\n };\n }, [connected]);\n\n return (\n <IAPContext.Provider value={context}>\n <Component {...props} />\n </IAPContext.Provider>\n );\n };\n}\n"],"mappings":";;;;;;;;AAAA;;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