react-native-iap 11.0.0-beta.1 → 11.0.0-rc.2
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/README.md +0 -1
- package/ios/IapSerializationUtils.swift +30 -0
- package/ios/RNIapIosSk2.m +5 -0
- package/ios/RNIapIosSk2.swift +63 -49
- package/lib/commonjs/eventEmitter.js +4 -4
- package/lib/commonjs/eventEmitter.js.map +1 -1
- package/lib/commonjs/hooks/withIAPContext.js +1 -1
- package/lib/commonjs/hooks/withIAPContext.js.map +1 -1
- package/lib/commonjs/iap.js +50 -297
- package/lib/commonjs/iap.js.map +1 -1
- package/lib/commonjs/internal/platform.js +75 -2
- package/lib/commonjs/internal/platform.js.map +1 -1
- package/lib/commonjs/modules/amazon.js +28 -1
- package/lib/commonjs/modules/amazon.js.map +1 -1
- package/lib/commonjs/modules/android.js +73 -1
- package/lib/commonjs/modules/android.js.map +1 -1
- package/lib/commonjs/modules/ios.js +126 -0
- package/lib/commonjs/modules/ios.js.map +1 -1
- package/lib/commonjs/modules/iosSk2.js +47 -0
- package/lib/commonjs/modules/iosSk2.js.map +1 -1
- package/lib/commonjs/types/appleSk2.js.map +1 -1
- package/lib/module/eventEmitter.js +2 -2
- package/lib/module/eventEmitter.js.map +1 -1
- package/lib/module/hooks/withIAPContext.js +2 -2
- package/lib/module/hooks/withIAPContext.js.map +1 -1
- package/lib/module/iap.js +8 -223
- package/lib/module/iap.js.map +1 -1
- package/lib/module/internal/platform.js +48 -1
- package/lib/module/internal/platform.js.map +1 -1
- package/lib/module/modules/amazon.js +23 -0
- package/lib/module/modules/amazon.js.map +1 -1
- package/lib/module/modules/android.js +59 -1
- package/lib/module/modules/android.js.map +1 -1
- package/lib/module/modules/ios.js +102 -1
- package/lib/module/modules/ios.js.map +1 -1
- package/lib/module/modules/iosSk2.js +30 -1
- package/lib/module/modules/iosSk2.js.map +1 -1
- package/lib/module/types/appleSk2.js.map +1 -1
- package/lib/typescript/iap.d.ts +7 -120
- package/lib/typescript/internal/platform.d.ts +9 -0
- package/lib/typescript/modules/amazon.d.ts +17 -0
- package/lib/typescript/modules/android.d.ts +38 -1
- package/lib/typescript/modules/ios.d.ts +56 -0
- package/lib/typescript/modules/iosSk2.d.ts +27 -1
- package/lib/typescript/types/appleSk2.d.ts +4 -0
- package/package.json +1 -1
- package/src/eventEmitter.ts +4 -3
- package/src/hooks/withIAPContext.tsx +2 -2
- package/src/iap.ts +20 -297
- package/src/internal/platform.ts +78 -1
- package/src/modules/amazon.ts +29 -1
- package/src/modules/android.ts +83 -2
- package/src/modules/ios.ts +121 -0
- package/src/modules/iosSk2.ts +45 -1
- package/src/types/appleSk2.ts +12 -0
|
@@ -3,17 +3,90 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.isIos = exports.isAndroid = exports.isAmazon = void 0;
|
|
6
|
+
exports.setIosNativeModule = exports.setAndroidNativeModule = exports.isStorekit2Avaiable = exports.isIosStorekit2 = exports.isIos = exports.isAndroid = exports.isAmazon = exports.getNativeModule = exports.getIosModule = exports.getAndroidModule = exports.enableStorekit2 = exports.checkNativeAndroidAvailable = void 0;
|
|
7
7
|
|
|
8
8
|
var _reactNative = require("react-native");
|
|
9
9
|
|
|
10
10
|
const {
|
|
11
|
+
RNIapIos,
|
|
12
|
+
RNIapIosSk2,
|
|
13
|
+
RNIapModule,
|
|
11
14
|
RNIapAmazonModule
|
|
12
15
|
} = _reactNative.NativeModules;
|
|
13
16
|
const isIos = _reactNative.Platform.OS === 'ios';
|
|
14
17
|
exports.isIos = isIos;
|
|
15
18
|
const isAndroid = _reactNative.Platform.OS === 'android';
|
|
16
19
|
exports.isAndroid = isAndroid;
|
|
17
|
-
const isAmazon = isAndroid && !!RNIapAmazonModule;
|
|
20
|
+
const isAmazon = isAndroid && !!RNIapAmazonModule; // Android
|
|
21
|
+
|
|
18
22
|
exports.isAmazon = isAmazon;
|
|
23
|
+
let androidNativeModule = RNIapModule;
|
|
24
|
+
|
|
25
|
+
const setAndroidNativeModule = nativeModule => {
|
|
26
|
+
androidNativeModule = nativeModule;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
exports.setAndroidNativeModule = setAndroidNativeModule;
|
|
30
|
+
|
|
31
|
+
const checkNativeAndroidAvailable = () => {
|
|
32
|
+
if (!RNIapModule && !RNIapAmazonModule) {
|
|
33
|
+
throw new Error('IAP_NOT_AVAILABLE');
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
exports.checkNativeAndroidAvailable = checkNativeAndroidAvailable;
|
|
38
|
+
|
|
39
|
+
const getAndroidModule = () => {
|
|
40
|
+
checkNativeAndroidAvailable();
|
|
41
|
+
return androidNativeModule ? androidNativeModule : RNIapModule ? RNIapModule : RNIapAmazonModule;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
exports.getAndroidModule = getAndroidModule;
|
|
45
|
+
|
|
46
|
+
const getNativeModule = () => {
|
|
47
|
+
return isAndroid ? getAndroidModule() : getIosModule();
|
|
48
|
+
}; // iOS
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
exports.getNativeModule = getNativeModule;
|
|
52
|
+
let iosNativeModule = RNIapIos;
|
|
53
|
+
|
|
54
|
+
const isIosStorekit2 = () => !!iosNativeModule && iosNativeModule === RNIapIosSk2;
|
|
55
|
+
|
|
56
|
+
exports.isIosStorekit2 = isIosStorekit2;
|
|
57
|
+
|
|
58
|
+
const isStorekit2Avaiable = () => !!RNIapIosSk2;
|
|
59
|
+
|
|
60
|
+
exports.isStorekit2Avaiable = isStorekit2Avaiable;
|
|
61
|
+
|
|
62
|
+
const setIosNativeModule = nativeModule => {
|
|
63
|
+
iosNativeModule = nativeModule;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
exports.setIosNativeModule = setIosNativeModule;
|
|
67
|
+
|
|
68
|
+
const enableStorekit2 = () => {
|
|
69
|
+
if (RNIapIosSk2) {
|
|
70
|
+
iosNativeModule = RNIapIosSk2;
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
console.warn('Storekit 2 is not available on this device');
|
|
75
|
+
return false;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
exports.enableStorekit2 = enableStorekit2;
|
|
79
|
+
|
|
80
|
+
const checkNativeIOSAvailable = () => {
|
|
81
|
+
if (!RNIapIos && !RNIapIosSk2) {
|
|
82
|
+
throw new Error('IAP_NOT_AVAILABLE');
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const getIosModule = () => {
|
|
87
|
+
checkNativeIOSAvailable();
|
|
88
|
+
return iosNativeModule ? iosNativeModule : RNIapIosSk2 ? RNIapIosSk2 : RNIapIos;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
exports.getIosModule = getIosModule;
|
|
19
92
|
//# sourceMappingURL=platform.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["RNIapAmazonModule","NativeModules","isIos","Platform","OS","isAndroid","isAmazon"],"sources":["platform.ts"],"sourcesContent":["import {NativeModules, Platform} from 'react-native';\n\nconst {RNIapAmazonModule} = NativeModules;\n\nexport const isIos = Platform.OS === 'ios';\nexport const isAndroid = Platform.OS === 'android';\nexport const isAmazon = isAndroid && !!RNIapAmazonModule;\n"],"mappings":";;;;;;;AAAA;;AAEA,MAAM;EAACA;
|
|
1
|
+
{"version":3,"names":["RNIapIos","RNIapIosSk2","RNIapModule","RNIapAmazonModule","NativeModules","isIos","Platform","OS","isAndroid","isAmazon","androidNativeModule","setAndroidNativeModule","nativeModule","checkNativeAndroidAvailable","Error","getAndroidModule","getNativeModule","getIosModule","iosNativeModule","isIosStorekit2","isStorekit2Avaiable","setIosNativeModule","enableStorekit2","console","warn","checkNativeIOSAvailable"],"sources":["platform.ts"],"sourcesContent":["import {NativeModules, Platform} from 'react-native';\n\nconst {RNIapIos, RNIapIosSk2, RNIapModule, RNIapAmazonModule} = NativeModules;\n\nexport const isIos = Platform.OS === 'ios';\nexport const isAndroid = Platform.OS === 'android';\nexport const isAmazon = isAndroid && !!RNIapAmazonModule;\n\n// Android\n\nlet androidNativeModule = RNIapModule;\n\nexport const setAndroidNativeModule = (\n nativeModule: typeof RNIapModule,\n): void => {\n androidNativeModule = nativeModule;\n};\n\nexport const checkNativeAndroidAvailable = (): void => {\n if (!RNIapModule && !RNIapAmazonModule) {\n throw new Error('IAP_NOT_AVAILABLE');\n }\n};\n\nexport const getAndroidModule = ():\n | typeof RNIapModule\n | typeof RNIapAmazonModule => {\n checkNativeAndroidAvailable();\n\n return androidNativeModule\n ? androidNativeModule\n : RNIapModule\n ? RNIapModule\n : RNIapAmazonModule;\n};\n\nexport const getNativeModule = ():\n | typeof RNIapModule\n | typeof RNIapAmazonModule\n | typeof RNIapIos\n | typeof RNIapIosSk2 => {\n return isAndroid ? getAndroidModule() : getIosModule();\n};\n\n// iOS\n\nlet iosNativeModule: typeof RNIapIos | typeof RNIapIosSk2 = RNIapIos;\n\nexport const isIosStorekit2 = () =>\n !!iosNativeModule && iosNativeModule === RNIapIosSk2;\n\nexport const isStorekit2Avaiable = (): boolean => !!RNIapIosSk2;\n\nexport const setIosNativeModule = (\n nativeModule: typeof RNIapIos | typeof RNIapIosSk2,\n): void => {\n iosNativeModule = nativeModule;\n};\n\nexport const enableStorekit2 = () => {\n if (RNIapIosSk2) {\n iosNativeModule = RNIapIosSk2;\n return true;\n }\n console.warn('Storekit 2 is not available on this device');\n\n return false;\n};\n\nconst checkNativeIOSAvailable = (): void => {\n if (!RNIapIos && !RNIapIosSk2) {\n throw new Error('IAP_NOT_AVAILABLE');\n }\n};\n\nexport const getIosModule = (): typeof RNIapIos | typeof RNIapIosSk2 => {\n checkNativeIOSAvailable();\n\n return iosNativeModule\n ? iosNativeModule\n : RNIapIosSk2\n ? RNIapIosSk2\n : RNIapIos;\n};\n"],"mappings":";;;;;;;AAAA;;AAEA,MAAM;EA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CARM;;;;AAUP,MAAMC,uBAAuB,GAAG,MAAY;EAC1C,IAAI,CAACzB,QAAD,IAAa,CAACC,WAAlB,EAA+B;IAC7B,MAAM,IAAIa,KAAJ,CAAU,mBAAV,CAAN;EACD;AACF,CAJD;;AAMO,MAAMG,YAAY,GAAG,MAA4C;EACtEQ,uBAAuB;EAEvB,OAAOP,eAAe,GAClBA,eADkB,GAElBjB,WAAW,GACXA,WADW,GAEXD,QAJJ;AAKD,CARM"}
|
|
@@ -3,10 +3,37 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.AmazonModule = void 0;
|
|
6
|
+
exports.validateReceiptAmazon = exports.AmazonModule = void 0;
|
|
7
7
|
|
|
8
8
|
var _reactNative = require("react-native");
|
|
9
9
|
|
|
10
|
+
var _internal = require("../internal");
|
|
11
|
+
|
|
10
12
|
const AmazonModule = _reactNative.NativeModules.RNIapAmazonModule;
|
|
13
|
+
/**
|
|
14
|
+
* Validate receipt for Amazon. NOTE: This method is here for debugging purposes only. Including
|
|
15
|
+
* your developer secret in the binary you ship to users is potentially dangerous.
|
|
16
|
+
* Use server side validation instead for your production builds
|
|
17
|
+
* @param {string} developerSecret: from the Amazon developer console.
|
|
18
|
+
* @param {string} userId who purchased the item.
|
|
19
|
+
* @param {string} receiptId long obfuscated string returned when purchasing the item
|
|
20
|
+
* @param {boolean} useSandbox Defaults to true, use sandbox environment or production.
|
|
21
|
+
* @returns {Promise<object>}
|
|
22
|
+
*/
|
|
23
|
+
|
|
11
24
|
exports.AmazonModule = AmazonModule;
|
|
25
|
+
|
|
26
|
+
const validateReceiptAmazon = async _ref => {
|
|
27
|
+
let {
|
|
28
|
+
developerSecret,
|
|
29
|
+
userId,
|
|
30
|
+
receiptId,
|
|
31
|
+
useSandbox = true
|
|
32
|
+
} = _ref;
|
|
33
|
+
const sandBoxUrl = useSandbox ? 'sandbox/' : '';
|
|
34
|
+
const url = `https://appstore-sdk.amazon.com/${sandBoxUrl}version/1.0/verifyReceiptId/developer/${developerSecret}/user/${userId}/receiptId/${receiptId}`;
|
|
35
|
+
return await (0, _internal.enhancedFetch)(url);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
exports.validateReceiptAmazon = validateReceiptAmazon;
|
|
12
39
|
//# sourceMappingURL=amazon.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["AmazonModule","NativeModules","RNIapAmazonModule"],"sources":["amazon.ts"],"sourcesContent":["import {NativeModules} from 'react-native';\n\nimport type {Product, Purchase, Sku} from '../types';\nimport type {UserDataAmazon} from '../types/amazon';\n\nimport type {NativeModuleProps} from './common';\n
|
|
1
|
+
{"version":3,"names":["AmazonModule","NativeModules","RNIapAmazonModule","validateReceiptAmazon","developerSecret","userId","receiptId","useSandbox","sandBoxUrl","url","enhancedFetch"],"sources":["amazon.ts"],"sourcesContent":["import {NativeModules} from 'react-native';\n\nimport {enhancedFetch} from '../internal';\nimport type {Product, Purchase, Sku} from '../types';\nimport type {UserDataAmazon} from '../types/amazon';\nimport type * as Amazon from '../types/amazon';\n\nimport type {NativeModuleProps} from './common';\n// ----------\n\ntype GetUser = () => Promise<UserDataAmazon>;\ntype FlushFailedPurchasesCachedAsPending = () => Promise<boolean>;\ntype GetItemsByType = (type: string, skus: Sku[]) => Promise<Product[]>;\ntype GetAvailableItems = () => Promise<Purchase[]>;\ntype BuyItemByType = (sku: Sku) => Promise<Purchase>;\n\ntype AcknowledgePurchase = (\n purchaseToken: string,\n developerPayloadAndroid?: string,\n) => Promise<boolean>;\n\ntype ConsumeProduct = (\n purchaseToken: string,\n developerPayloadAndroid?: string,\n) => Promise<boolean>;\n\ntype StartListening = () => Promise<void>;\n\nexport interface AmazonModuleProps extends NativeModuleProps {\n getUser: GetUser;\n flushFailedPurchasesCachedAsPending: FlushFailedPurchasesCachedAsPending;\n getItemsByType: GetItemsByType;\n getAvailableItems: GetAvailableItems;\n buyItemByType: BuyItemByType;\n acknowledgePurchase: AcknowledgePurchase;\n consumeProduct: ConsumeProduct;\n startListening: StartListening;\n}\n\nexport const AmazonModule =\n NativeModules.RNIapAmazonModule as AmazonModuleProps;\n\n/**\n * Validate receipt for Amazon. NOTE: This method is here for debugging purposes only. Including\n * your developer secret in the binary you ship to users is potentially dangerous.\n * Use server side validation instead for your production builds\n * @param {string} developerSecret: from the Amazon developer console.\n * @param {string} userId who purchased the item.\n * @param {string} receiptId long obfuscated string returned when purchasing the item\n * @param {boolean} useSandbox Defaults to true, use sandbox environment or production.\n * @returns {Promise<object>}\n */\nexport const validateReceiptAmazon = async ({\n developerSecret,\n userId,\n receiptId,\n useSandbox = true,\n}: {\n developerSecret: string;\n userId: string;\n receiptId: string;\n useSandbox: boolean;\n}): Promise<Amazon.ReceiptType> => {\n const sandBoxUrl = useSandbox ? 'sandbox/' : '';\n const url = `https://appstore-sdk.amazon.com/${sandBoxUrl}version/1.0/verifyReceiptId/developer/${developerSecret}/user/${userId}/receiptId/${receiptId}`;\n\n return await enhancedFetch<Amazon.ReceiptType>(url);\n};\n"],"mappings":";;;;;;;AAAA;;AAEA;;AAqCO,MAAMA,YAAY,GACvBC,0BAAA,CAAcC,iBADT;AAGP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;AACO,MAAMC,qBAAqB,GAAG,cAUF;EAAA,IAVS;IAC1CC,eAD0C;IAE1CC,MAF0C;IAG1CC,SAH0C;IAI1CC,UAAU,GAAG;EAJ6B,CAUT;EACjC,MAAMC,UAAU,GAAGD,UAAU,GAAG,UAAH,GAAgB,EAA7C;EACA,MAAME,GAAG,GAAI,mCAAkCD,UAAW,yCAAwCJ,eAAgB,SAAQC,MAAO,cAAaC,SAAU,EAAxJ;EAEA,OAAO,MAAM,IAAAI,uBAAA,EAAkCD,GAAlC,CAAb;AACD,CAfM"}
|
|
@@ -3,10 +3,82 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.AndroidModule = void 0;
|
|
6
|
+
exports.validateReceiptAndroid = exports.getInstallSourceAndroid = exports.deepLinkToSubscriptionsAndroid = exports.acknowledgePurchaseAndroid = exports.AndroidModule = void 0;
|
|
7
7
|
|
|
8
8
|
var _reactNative = require("react-native");
|
|
9
9
|
|
|
10
|
+
var _internal = require("../internal");
|
|
11
|
+
|
|
12
|
+
var _types = require("../types");
|
|
13
|
+
|
|
14
|
+
const {
|
|
15
|
+
RNIapModule
|
|
16
|
+
} = _reactNative.NativeModules;
|
|
10
17
|
const AndroidModule = _reactNative.NativeModules.RNIapModule;
|
|
11
18
|
exports.AndroidModule = AndroidModule;
|
|
19
|
+
|
|
20
|
+
const getInstallSourceAndroid = () => {
|
|
21
|
+
return RNIapModule ? _types.InstallSourceAndroid.GOOGLE_PLAY : _types.InstallSourceAndroid.AMAZON;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Deep link to subscriptions screen on Android. No-op on iOS.
|
|
25
|
+
* @param {string} sku The product's SKU (on Android)
|
|
26
|
+
* @returns {Promise<void>}
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
exports.getInstallSourceAndroid = getInstallSourceAndroid;
|
|
31
|
+
|
|
32
|
+
const deepLinkToSubscriptionsAndroid = async _ref => {
|
|
33
|
+
let {
|
|
34
|
+
sku
|
|
35
|
+
} = _ref;
|
|
36
|
+
(0, _internal.checkNativeAndroidAvailable)();
|
|
37
|
+
return _reactNative.Linking.openURL(`https://play.google.com/store/account/subscriptions?package=${await RNIapModule.getPackageName()}&sku=${sku}`);
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Validate receipt for Android. NOTE: This method is here for debugging purposes only. Including
|
|
41
|
+
* your access token in the binary you ship to users is potentially dangerous.
|
|
42
|
+
* Use server side validation instead for your production builds
|
|
43
|
+
* @param {string} packageName package name of your app.
|
|
44
|
+
* @param {string} productId product id for your in app product.
|
|
45
|
+
* @param {string} productToken token for your purchase.
|
|
46
|
+
* @param {string} accessToken accessToken from googleApis.
|
|
47
|
+
* @param {boolean} isSub whether this is subscription or inapp. `true` for subscription.
|
|
48
|
+
* @returns {Promise<object>}
|
|
49
|
+
*/
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
exports.deepLinkToSubscriptionsAndroid = deepLinkToSubscriptionsAndroid;
|
|
53
|
+
|
|
54
|
+
const validateReceiptAndroid = async _ref2 => {
|
|
55
|
+
let {
|
|
56
|
+
packageName,
|
|
57
|
+
productId,
|
|
58
|
+
productToken,
|
|
59
|
+
accessToken,
|
|
60
|
+
isSub
|
|
61
|
+
} = _ref2;
|
|
62
|
+
const type = isSub ? 'subscriptions' : 'products';
|
|
63
|
+
const url = 'https://androidpublisher.googleapis.com/androidpublisher/v3/applications' + `/${packageName}/purchases/${type}/${productId}` + `/tokens/${productToken}?access_token=${accessToken}`;
|
|
64
|
+
return await (0, _internal.enhancedFetch)(url);
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* Acknowledge a product (on Android.) No-op on iOS.
|
|
68
|
+
* @param {string} token The product's token (on Android)
|
|
69
|
+
* @returns {Promise<PurchaseResult | void>}
|
|
70
|
+
*/
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
exports.validateReceiptAndroid = validateReceiptAndroid;
|
|
74
|
+
|
|
75
|
+
const acknowledgePurchaseAndroid = _ref3 => {
|
|
76
|
+
let {
|
|
77
|
+
token,
|
|
78
|
+
developerPayload
|
|
79
|
+
} = _ref3;
|
|
80
|
+
return (0, _internal.getAndroidModule)().acknowledgePurchase(token, developerPayload);
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
exports.acknowledgePurchaseAndroid = acknowledgePurchaseAndroid;
|
|
12
84
|
//# sourceMappingURL=android.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["RNIapModule","NativeModules","AndroidModule","getInstallSourceAndroid","InstallSourceAndroid","GOOGLE_PLAY","AMAZON","deepLinkToSubscriptionsAndroid","sku","checkNativeAndroidAvailable","Linking","openURL","getPackageName","validateReceiptAndroid","packageName","productId","productToken","accessToken","isSub","type","url","enhancedFetch","acknowledgePurchaseAndroid","token","developerPayload","getAndroidModule","acknowledgePurchase"],"sources":["android.ts"],"sourcesContent":["import {Linking, NativeModules} from 'react-native';\n\nimport {\n checkNativeAndroidAvailable,\n enhancedFetch,\n getAndroidModule,\n} from '../internal';\nimport {\n InstallSourceAndroid,\n Product,\n ProductType,\n ProrationModesAndroid,\n Purchase,\n PurchaseResult,\n Sku,\n} from '../types';\nimport type * as Android from '../types/android';\n\nimport type {NativeModuleProps} from './common';\n\nconst {RNIapModule} = NativeModules;\n\ntype FlushFailedPurchasesCachedAsPending = () => Promise<boolean>;\n\ntype GetItemsByType = <T = Product>(\n type: ProductType,\n skus: Sku[],\n) => Promise<T[]>;\n\ntype GetAvailableItemsByType = <T = Purchase>(\n type: ProductType,\n) => Promise<T[]>;\n\ntype GetPurchaseHistoryByType = <T = Purchase>(\n type: ProductType,\n) => Promise<T[]>;\n\nexport type BuyItemByType = (\n type: string,\n skus: Sku[],\n purchaseToken: string | undefined,\n prorationMode: ProrationModesAndroid,\n obfuscatedAccountId: string | undefined,\n obfuscatedProfileId: string | undefined,\n subscriptionOffers: string[],\n isOfferPersonalized: boolean,\n) => Promise<Purchase>;\n\ntype AcknowledgePurchase = (\n purchaseToken: string,\n developerPayloadAndroid?: string,\n) => Promise<PurchaseResult | boolean>;\n\ntype ConsumeProduct = (\n purchaseToken: string,\n developerPayloadAndroid?: string,\n) => Promise<PurchaseResult | boolean>;\n\ntype StartListening = () => Promise<void>;\ntype GetPackageName = () => Promise<string>;\n\nexport interface AndroidModuleProps extends NativeModuleProps {\n flushFailedPurchasesCachedAsPending: FlushFailedPurchasesCachedAsPending;\n getItemsByType: GetItemsByType;\n getAvailableItemsByType: GetAvailableItemsByType;\n getPurchaseHistoryByType: GetPurchaseHistoryByType;\n buyItemByType: BuyItemByType;\n acknowledgePurchase: AcknowledgePurchase;\n consumeProduct: ConsumeProduct;\n startListening: StartListening;\n getPackageName: GetPackageName;\n}\n\nexport const AndroidModule = NativeModules.RNIapModule as AndroidModuleProps;\n\nexport const getInstallSourceAndroid = (): InstallSourceAndroid => {\n return RNIapModule\n ? InstallSourceAndroid.GOOGLE_PLAY\n : InstallSourceAndroid.AMAZON;\n};\n\n/**\n * Deep link to subscriptions screen on Android. No-op on iOS.\n * @param {string} sku The product's SKU (on Android)\n * @returns {Promise<void>}\n */\nexport const deepLinkToSubscriptionsAndroid = async ({\n sku,\n}: {\n sku: Sku;\n}): Promise<void> => {\n checkNativeAndroidAvailable();\n\n return Linking.openURL(\n `https://play.google.com/store/account/subscriptions?package=${await RNIapModule.getPackageName()}&sku=${sku}`,\n );\n};\n\n/**\n * Validate receipt for Android. NOTE: This method is here for debugging purposes only. Including\n * your access token in the binary you ship to users is potentially dangerous.\n * Use server side validation instead for your production builds\n * @param {string} packageName package name of your app.\n * @param {string} productId product id for your in app product.\n * @param {string} productToken token for your purchase.\n * @param {string} accessToken accessToken from googleApis.\n * @param {boolean} isSub whether this is subscription or inapp. `true` for subscription.\n * @returns {Promise<object>}\n */\nexport const validateReceiptAndroid = async ({\n packageName,\n productId,\n productToken,\n accessToken,\n isSub,\n}: {\n packageName: string;\n productId: string;\n productToken: string;\n accessToken: string;\n isSub?: boolean;\n}): Promise<Android.ReceiptType> => {\n const type = isSub ? 'subscriptions' : 'products';\n\n const url =\n 'https://androidpublisher.googleapis.com/androidpublisher/v3/applications' +\n `/${packageName}/purchases/${type}/${productId}` +\n `/tokens/${productToken}?access_token=${accessToken}`;\n\n return await enhancedFetch<Android.ReceiptType>(url);\n};\n\n/**\n * Acknowledge a product (on Android.) No-op on iOS.\n * @param {string} token The product's token (on Android)\n * @returns {Promise<PurchaseResult | void>}\n */\nexport const acknowledgePurchaseAndroid = ({\n token,\n developerPayload,\n}: {\n token: string;\n developerPayload?: string;\n}): Promise<PurchaseResult | boolean | void> => {\n return getAndroidModule().acknowledgePurchase(token, developerPayload);\n};\n"],"mappings":";;;;;;;AAAA;;AAEA;;AAKA;;AAaA,MAAM;EAACA;AAAD,IAAgBC,0BAAtB;AAqDO,MAAMC,aAAa,GAAGD,0BAAA,CAAcD,WAApC;;;AAEA,MAAMG,uBAAuB,GAAG,MAA4B;EACjE,OAAOH,WAAW,GACdI,2BAAA,CAAqBC,WADP,GAEdD,2BAAA,CAAqBE,MAFzB;AAGD,CAJM;AAMP;AACA;AACA;AACA;AACA;;;;;AACO,MAAMC,8BAA8B,GAAG,cAIzB;EAAA,IAJgC;IACnDC;EADmD,CAIhC;EACnB,IAAAC,qCAAA;EAEA,OAAOC,oBAAA,CAAQC,OAAR,CACJ,+DAA8D,MAAMX,WAAW,CAACY,cAAZ,EAA6B,QAAOJ,GAAI,EADxG,CAAP;AAGD,CAVM;AAYP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;AACO,MAAMK,sBAAsB,GAAG,eAYF;EAAA,IAZS;IAC3CC,WAD2C;IAE3CC,SAF2C;IAG3CC,YAH2C;IAI3CC,WAJ2C;IAK3CC;EAL2C,CAYT;EAClC,MAAMC,IAAI,GAAGD,KAAK,GAAG,eAAH,GAAqB,UAAvC;EAEA,MAAME,GAAG,GACP,6EACC,IAAGN,WAAY,cAAaK,IAAK,IAAGJ,SAAU,EAD/C,GAEC,WAAUC,YAAa,iBAAgBC,WAAY,EAHtD;EAKA,OAAO,MAAM,IAAAI,uBAAA,EAAmCD,GAAnC,CAAb;AACD,CArBM;AAuBP;AACA;AACA;AACA;AACA;;;;;AACO,MAAME,0BAA0B,GAAG,SAMM;EAAA,IANL;IACzCC,KADyC;IAEzCC;EAFyC,CAMK;EAC9C,OAAO,IAAAC,0BAAA,IAAmBC,mBAAnB,CAAuCH,KAAvC,EAA8CC,gBAA9C,CAAP;AACD,CARM"}
|
|
@@ -3,4 +3,130 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.validateReceiptIos = exports.presentCodeRedemptionSheetIOS = exports.getReceiptIOS = exports.getPromotedProductIOS = exports.getPendingPurchasesIOS = exports.clearTransactionIOS = exports.clearProductsIOS = exports.buyPromotedProductIOS = void 0;
|
|
7
|
+
|
|
8
|
+
var _internal = require("../internal");
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Get the current receipt base64 encoded in IOS.
|
|
12
|
+
* @param {forceRefresh?:boolean}
|
|
13
|
+
* @returns {Promise<ProductPurchase[]>}
|
|
14
|
+
*/
|
|
15
|
+
const getPendingPurchasesIOS = async () => (0, _internal.getIosModule)().getPendingTransactions();
|
|
16
|
+
/**
|
|
17
|
+
* Get the current receipt base64 encoded in IOS.
|
|
18
|
+
* @param {forceRefresh?:boolean}
|
|
19
|
+
* @returns {Promise<string>}
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
exports.getPendingPurchasesIOS = getPendingPurchasesIOS;
|
|
24
|
+
|
|
25
|
+
const getReceiptIOS = async _ref => {
|
|
26
|
+
let {
|
|
27
|
+
forceRefresh
|
|
28
|
+
} = _ref;
|
|
29
|
+
return (0, _internal.getIosModule)().requestReceipt(forceRefresh ?? false);
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Launches a modal to register the redeem offer code in IOS.
|
|
33
|
+
* @returns {Promise<null>}
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
exports.getReceiptIOS = getReceiptIOS;
|
|
38
|
+
|
|
39
|
+
const presentCodeRedemptionSheetIOS = async () => (0, _internal.getIosModule)().presentCodeRedemptionSheet();
|
|
40
|
+
/**
|
|
41
|
+
* Should Add Store Payment (iOS only)
|
|
42
|
+
* Indicates the the App Store purchase should continue from the app instead of the App Store.
|
|
43
|
+
* @returns {Promise<Product | null>} promoted product
|
|
44
|
+
*/
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
exports.presentCodeRedemptionSheetIOS = presentCodeRedemptionSheetIOS;
|
|
48
|
+
|
|
49
|
+
const getPromotedProductIOS = () => {
|
|
50
|
+
if (!(0, _internal.isIosStorekit2)()) {
|
|
51
|
+
return (0, _internal.getIosModule)().promotedProduct();
|
|
52
|
+
} else {
|
|
53
|
+
return Promise.reject('Only available on SK1');
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Buy the currently selected promoted product (iOS only)
|
|
58
|
+
* Initiates the payment process for a promoted product. Should only be called in response to the `iap-promoted-product` event.
|
|
59
|
+
* @returns {Promise<void>}
|
|
60
|
+
*/
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
exports.getPromotedProductIOS = getPromotedProductIOS;
|
|
64
|
+
|
|
65
|
+
const buyPromotedProductIOS = () => (0, _internal.getIosModule)().buyPromotedProduct();
|
|
66
|
+
|
|
67
|
+
exports.buyPromotedProductIOS = buyPromotedProductIOS;
|
|
68
|
+
const TEST_RECEIPT = 21007;
|
|
69
|
+
|
|
70
|
+
const requestAgnosticReceiptValidationIos = async receiptBody => {
|
|
71
|
+
const response = await (0, _internal.enhancedFetch)('https://buy.itunes.apple.com/verifyReceipt', {
|
|
72
|
+
method: 'POST',
|
|
73
|
+
body: receiptBody
|
|
74
|
+
}); // Best practice is to check for test receipt and check sandbox instead
|
|
75
|
+
// https://developer.apple.com/documentation/appstorereceipts/verifyreceipt
|
|
76
|
+
|
|
77
|
+
if (response && response.status === TEST_RECEIPT) {
|
|
78
|
+
const testResponse = await (0, _internal.enhancedFetch)('https://sandbox.itunes.apple.com/verifyReceipt', {
|
|
79
|
+
method: 'POST',
|
|
80
|
+
body: receiptBody
|
|
81
|
+
});
|
|
82
|
+
return testResponse;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return response;
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* Validate receipt for iOS.
|
|
89
|
+
* @param {object} receiptBody the receipt body to send to apple server.
|
|
90
|
+
* @param {boolean} isTest whether this is in test environment which is sandbox.
|
|
91
|
+
* @returns {Promise<Apple.ReceiptValidationResponse | false>}
|
|
92
|
+
*/
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
const validateReceiptIos = async _ref2 => {
|
|
96
|
+
let {
|
|
97
|
+
receiptBody,
|
|
98
|
+
isTest
|
|
99
|
+
} = _ref2;
|
|
100
|
+
|
|
101
|
+
if (isTest == null) {
|
|
102
|
+
return await requestAgnosticReceiptValidationIos(receiptBody);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const url = isTest ? 'https://sandbox.itunes.apple.com/verifyReceipt' : 'https://buy.itunes.apple.com/verifyReceipt';
|
|
106
|
+
return await (0, _internal.enhancedFetch)(url);
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
* Clear Transaction (iOS only)
|
|
110
|
+
* Finish remaining transactions. Related to issue #257 and #801
|
|
111
|
+
* link : https://github.com/dooboolab/react-native-iap/issues/257
|
|
112
|
+
* https://github.com/dooboolab/react-native-iap/issues/801
|
|
113
|
+
* @returns {Promise<void>}
|
|
114
|
+
*/
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
exports.validateReceiptIos = validateReceiptIos;
|
|
118
|
+
|
|
119
|
+
const clearTransactionIOS = () => (0, _internal.getIosModule)().clearTransaction();
|
|
120
|
+
/**
|
|
121
|
+
* Clear valid Products (iOS only)
|
|
122
|
+
* Remove all products which are validated by Apple server.
|
|
123
|
+
* @returns {void}
|
|
124
|
+
*/
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
exports.clearTransactionIOS = clearTransactionIOS;
|
|
128
|
+
|
|
129
|
+
const clearProductsIOS = () => (0, _internal.getIosModule)().clearProducts();
|
|
130
|
+
|
|
131
|
+
exports.clearProductsIOS = clearProductsIOS;
|
|
6
132
|
//# sourceMappingURL=ios.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["ios.ts"],"sourcesContent":["import type {\n Product,\n ProductPurchase,\n Purchase,\n Sku,\n Subscription,\n} from '../types';\nimport type {PaymentDiscount} from '../types/apple';\n\nimport type {NativeModuleProps} from './common';\n\ntype getItems = (skus: Sku[]) => Promise<Product[] | Subscription[]>;\n\ntype getAvailableItems = () => Promise<Purchase[]>;\n\nexport type BuyProduct = (\n sku: Sku,\n andDangerouslyFinishTransactionAutomaticallyIOS: boolean,\n applicationUsername: string | undefined,\n quantity: number,\n withOffer: PaymentDiscount | undefined,\n) => Promise<Purchase>;\n\ntype clearTransaction = () => Promise<void>;\ntype clearProducts = () => Promise<void>;\ntype promotedProduct = () => Promise<Product | null>;\ntype buyPromotedProduct = () => Promise<void>;\ntype requestReceipt = (refresh: boolean) => Promise<string>;\n\ntype finishTransaction = (transactionIdentifier: string) => Promise<boolean>;\n\ntype getPendingTransactions = () => Promise<ProductPurchase[]>;\ntype presentCodeRedemptionSheet = () => Promise<null>;\n\nexport interface IosModuleProps extends NativeModuleProps {\n getItems: getItems;\n getAvailableItems: getAvailableItems;\n buyProduct: BuyProduct;\n clearTransaction: clearTransaction;\n clearProducts: clearProducts;\n promotedProduct: promotedProduct;\n buyPromotedProduct: buyPromotedProduct;\n requestReceipt: requestReceipt;\n finishTransaction: finishTransaction;\n getPendingTransactions: getPendingTransactions;\n presentCodeRedemptionSheet: presentCodeRedemptionSheet;\n}\n"],"mappings":""}
|
|
1
|
+
{"version":3,"names":["getPendingPurchasesIOS","getIosModule","getPendingTransactions","getReceiptIOS","forceRefresh","requestReceipt","presentCodeRedemptionSheetIOS","presentCodeRedemptionSheet","getPromotedProductIOS","isIosStorekit2","promotedProduct","Promise","reject","buyPromotedProductIOS","buyPromotedProduct","TEST_RECEIPT","requestAgnosticReceiptValidationIos","receiptBody","response","enhancedFetch","method","body","status","testResponse","validateReceiptIos","isTest","url","clearTransactionIOS","clearTransaction","clearProductsIOS","clearProducts"],"sources":["ios.ts"],"sourcesContent":["import type {ResponseBody as ReceiptValidationResponse} from '@jeremybarbet/apple-api-types';\n\nimport {enhancedFetch, getIosModule, isIosStorekit2} from '../internal';\nimport type {\n Product,\n ProductPurchase,\n Purchase,\n Sku,\n Subscription,\n} from '../types';\nimport type {PaymentDiscount} from '../types/apple';\n\nimport type {NativeModuleProps} from './common';\n\ntype getItems = (skus: Sku[]) => Promise<Product[] | Subscription[]>;\n\ntype getAvailableItems = () => Promise<Purchase[]>;\n\nexport type BuyProduct = (\n sku: Sku,\n andDangerouslyFinishTransactionAutomaticallyIOS: boolean,\n applicationUsername: string | undefined,\n quantity: number,\n withOffer: PaymentDiscount | undefined,\n) => Promise<Purchase>;\n\ntype clearTransaction = () => Promise<void>;\ntype clearProducts = () => Promise<void>;\ntype promotedProduct = () => Promise<Product | null>;\ntype buyPromotedProduct = () => Promise<void>;\ntype requestReceipt = (refresh: boolean) => Promise<string>;\n\ntype finishTransaction = (transactionIdentifier: string) => Promise<boolean>;\n\ntype getPendingTransactions = () => Promise<ProductPurchase[]>;\ntype presentCodeRedemptionSheet = () => Promise<null>;\n\nexport interface IosModuleProps extends NativeModuleProps {\n getItems: getItems;\n getAvailableItems: getAvailableItems;\n buyProduct: BuyProduct;\n clearTransaction: clearTransaction;\n clearProducts: clearProducts;\n promotedProduct: promotedProduct;\n buyPromotedProduct: buyPromotedProduct;\n requestReceipt: requestReceipt;\n finishTransaction: finishTransaction;\n getPendingTransactions: getPendingTransactions;\n presentCodeRedemptionSheet: presentCodeRedemptionSheet;\n}\n\n/**\n * Get the current receipt base64 encoded in IOS.\n * @param {forceRefresh?:boolean}\n * @returns {Promise<ProductPurchase[]>}\n */\nexport const getPendingPurchasesIOS = async (): Promise<ProductPurchase[]> =>\n getIosModule().getPendingTransactions();\n\n/**\n * Get the current receipt base64 encoded in IOS.\n * @param {forceRefresh?:boolean}\n * @returns {Promise<string>}\n */\nexport const getReceiptIOS = async ({\n forceRefresh,\n}: {\n forceRefresh?: boolean;\n}): Promise<string> => getIosModule().requestReceipt(forceRefresh ?? false);\n\n/**\n * Launches a modal to register the redeem offer code in IOS.\n * @returns {Promise<null>}\n */\nexport const presentCodeRedemptionSheetIOS = async (): Promise<null> =>\n getIosModule().presentCodeRedemptionSheet();\n\n/**\n * Should Add Store Payment (iOS only)\n * Indicates the the App Store purchase should continue from the app instead of the App Store.\n * @returns {Promise<Product | null>} promoted product\n */\nexport const getPromotedProductIOS = (): Promise<Product | null> => {\n if (!isIosStorekit2()) {\n return getIosModule().promotedProduct();\n } else {\n return Promise.reject('Only available on SK1');\n }\n};\n\n/**\n * Buy the currently selected promoted product (iOS only)\n * Initiates the payment process for a promoted product. Should only be called in response to the `iap-promoted-product` event.\n * @returns {Promise<void>}\n */\nexport const buyPromotedProductIOS = (): Promise<void> =>\n getIosModule().buyPromotedProduct();\n\nconst TEST_RECEIPT = 21007;\nconst requestAgnosticReceiptValidationIos = async (\n receiptBody: Record<string, unknown>,\n): Promise<ReceiptValidationResponse | false> => {\n const response = await enhancedFetch<ReceiptValidationResponse>(\n 'https://buy.itunes.apple.com/verifyReceipt',\n {\n method: 'POST',\n body: receiptBody,\n },\n );\n\n // Best practice is to check for test receipt and check sandbox instead\n // https://developer.apple.com/documentation/appstorereceipts/verifyreceipt\n if (response && response.status === TEST_RECEIPT) {\n const testResponse = await enhancedFetch<ReceiptValidationResponse>(\n 'https://sandbox.itunes.apple.com/verifyReceipt',\n {\n method: 'POST',\n body: receiptBody,\n },\n );\n\n return testResponse;\n }\n\n return response;\n};\n\n/**\n * Validate receipt for iOS.\n * @param {object} receiptBody the receipt body to send to apple server.\n * @param {boolean} isTest whether this is in test environment which is sandbox.\n * @returns {Promise<Apple.ReceiptValidationResponse | false>}\n */\nexport const validateReceiptIos = async ({\n receiptBody,\n isTest,\n}: {\n receiptBody: Record<string, unknown>;\n isTest?: boolean;\n}): Promise<ReceiptValidationResponse | false> => {\n if (isTest == null) {\n return await requestAgnosticReceiptValidationIos(receiptBody);\n }\n\n const url = isTest\n ? 'https://sandbox.itunes.apple.com/verifyReceipt'\n : 'https://buy.itunes.apple.com/verifyReceipt';\n\n return await enhancedFetch<ReceiptValidationResponse>(url);\n};\n\n/**\n * Clear Transaction (iOS only)\n * Finish remaining transactions. Related to issue #257 and #801\n * link : https://github.com/dooboolab/react-native-iap/issues/257\n * https://github.com/dooboolab/react-native-iap/issues/801\n * @returns {Promise<void>}\n */\nexport const clearTransactionIOS = (): Promise<void> =>\n getIosModule().clearTransaction();\n\n/**\n * Clear valid Products (iOS only)\n * Remove all products which are validated by Apple server.\n * @returns {void}\n */\nexport const clearProductsIOS = (): Promise<void> =>\n getIosModule().clearProducts();\n"],"mappings":";;;;;;;AAEA;;AAiDA;AACA;AACA;AACA;AACA;AACO,MAAMA,sBAAsB,GAAG,YACpC,IAAAC,sBAAA,IAAeC,sBAAf,EADK;AAGP;AACA;AACA;AACA;AACA;;;;;AACO,MAAMC,aAAa,GAAG;EAAA,IAAO;IAClCC;EADkC,CAAP;EAAA,OAIN,IAAAH,sBAAA,IAAeI,cAAf,CAA8BD,YAAY,IAAI,KAA9C,CAJM;AAAA,CAAtB;AAMP;AACA;AACA;AACA;;;;;AACO,MAAME,6BAA6B,GAAG,YAC3C,IAAAL,sBAAA,IAAeM,0BAAf,EADK;AAGP;AACA;AACA;AACA;AACA;;;;;AACO,MAAMC,qBAAqB,GAAG,MAA+B;EAClE,IAAI,CAAC,IAAAC,wBAAA,GAAL,EAAuB;IACrB,OAAO,IAAAR,sBAAA,IAAeS,eAAf,EAAP;EACD,CAFD,MAEO;IACL,OAAOC,OAAO,CAACC,MAAR,CAAe,uBAAf,CAAP;EACD;AACF,CANM;AAQP;AACA;AACA;AACA;AACA;;;;;AACO,MAAMC,qBAAqB,GAAG,MACnC,IAAAZ,sBAAA,IAAea,kBAAf,EADK;;;AAGP,MAAMC,YAAY,GAAG,KAArB;;AACA,MAAMC,mCAAmC,GAAG,MAC1CC,WAD0C,IAEK;EAC/C,MAAMC,QAAQ,GAAG,MAAM,IAAAC,uBAAA,EACrB,4CADqB,EAErB;IACEC,MAAM,EAAE,MADV;IAEEC,IAAI,EAAEJ;EAFR,CAFqB,CAAvB,CAD+C,CAS/C;EACA;;EACA,IAAIC,QAAQ,IAAIA,QAAQ,CAACI,MAAT,KAAoBP,YAApC,EAAkD;IAChD,MAAMQ,YAAY,GAAG,MAAM,IAAAJ,uBAAA,EACzB,gDADyB,EAEzB;MACEC,MAAM,EAAE,MADV;MAEEC,IAAI,EAAEJ;IAFR,CAFyB,CAA3B;IAQA,OAAOM,YAAP;EACD;;EAED,OAAOL,QAAP;AACD,CA1BD;AA4BA;AACA;AACA;AACA;AACA;AACA;;;AACO,MAAMM,kBAAkB,GAAG,eAMgB;EAAA,IANT;IACvCP,WADuC;IAEvCQ;EAFuC,CAMS;;EAChD,IAAIA,MAAM,IAAI,IAAd,EAAoB;IAClB,OAAO,MAAMT,mCAAmC,CAACC,WAAD,CAAhD;EACD;;EAED,MAAMS,GAAG,GAAGD,MAAM,GACd,gDADc,GAEd,4CAFJ;EAIA,OAAO,MAAM,IAAAN,uBAAA,EAAyCO,GAAzC,CAAb;AACD,CAhBM;AAkBP;AACA;AACA;AACA;AACA;AACA;AACA;;;;;AACO,MAAMC,mBAAmB,GAAG,MACjC,IAAA1B,sBAAA,IAAe2B,gBAAf,EADK;AAGP;AACA;AACA;AACA;AACA;;;;;AACO,MAAMC,gBAAgB,GAAG,MAC9B,IAAA5B,sBAAA,IAAe6B,aAAf,EADK"}
|
|
@@ -3,4 +3,51 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.sync = exports.subscriptionStatus = exports.latestTransaction = exports.isEligibleForIntroOffer = exports.currentEntitlement = void 0;
|
|
7
|
+
|
|
8
|
+
var _reactNative = require("react-native");
|
|
9
|
+
|
|
10
|
+
const {
|
|
11
|
+
RNIapIosSk2
|
|
12
|
+
} = _reactNative.NativeModules;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Sync state with Appstore (iOS only)
|
|
16
|
+
* https://developer.apple.com/documentation/storekit/appstore/3791906-sync
|
|
17
|
+
*/
|
|
18
|
+
const sync = () => RNIapIosSk2.sync();
|
|
19
|
+
/**
|
|
20
|
+
*
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
exports.sync = sync;
|
|
25
|
+
|
|
26
|
+
const isEligibleForIntroOffer = groupID => RNIapIosSk2.isEligibleForIntroOffer(groupID);
|
|
27
|
+
/**
|
|
28
|
+
*
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
exports.isEligibleForIntroOffer = isEligibleForIntroOffer;
|
|
33
|
+
|
|
34
|
+
const subscriptionStatus = sku => RNIapIosSk2.subscriptionStatus(sku);
|
|
35
|
+
/**
|
|
36
|
+
*
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
exports.subscriptionStatus = subscriptionStatus;
|
|
41
|
+
|
|
42
|
+
const currentEntitlement = sku => RNIapIosSk2.currentEntitlement(sku);
|
|
43
|
+
/**
|
|
44
|
+
*
|
|
45
|
+
*/
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
exports.currentEntitlement = currentEntitlement;
|
|
49
|
+
|
|
50
|
+
const latestTransaction = sku => RNIapIosSk2.latestTransaction(sku);
|
|
51
|
+
|
|
52
|
+
exports.latestTransaction = latestTransaction;
|
|
6
53
|
//# sourceMappingURL=iosSk2.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["iosSk2.ts"],"sourcesContent":["import type {Product, ProductPurchase, Purchase, Sku} from '../types';\nimport type {PaymentDiscountSk2
|
|
1
|
+
{"version":3,"names":["RNIapIosSk2","NativeModules","sync","isEligibleForIntroOffer","groupID","subscriptionStatus","sku","currentEntitlement","latestTransaction"],"sources":["iosSk2.ts"],"sourcesContent":["import {NativeModules} from 'react-native';\n\nimport type {Product, ProductPurchase, Purchase, Sku} from '../types';\nimport type {\n PaymentDiscountSk2,\n ProductSk2,\n ProductStatus,\n TransactionSk2,\n} from '../types/appleSk2';\n\nimport type {NativeModuleProps} from './common';\nconst {RNIapIosSk2} = NativeModules;\n\ntype getItems = (skus: Sku[]) => Promise<ProductSk2[]>;\n\ntype getAvailableItems = () => Promise<Purchase[]>;\n\nexport type BuyProduct = (\n sku: Sku,\n andDangerouslyFinishTransactionAutomaticallyIOS: boolean,\n applicationUsername: string | undefined,\n quantity: number,\n withOffer: PaymentDiscountSk2 | undefined,\n) => Promise<Purchase>;\n\ntype clearTransaction = () => Promise<void>;\ntype clearProducts = () => Promise<void>;\ntype promotedProduct = () => Promise<Product | null>;\ntype buyPromotedProduct = () => Promise<void>;\ntype requestReceipt = (refresh: boolean) => Promise<string>;\n\ntype finishTransaction = (transactionIdentifier: string) => Promise<boolean>;\n\ntype getPendingTransactions = () => Promise<ProductPurchase[]>;\ntype presentCodeRedemptionSheet = () => Promise<null>;\n\nexport interface IosModulePropsSk2 extends NativeModuleProps {\n latestTransaction(sku: string): Promise<TransactionSk2>;\n currentEntitlement(sku: string): Promise<TransactionSk2>;\n subscriptionStatus(sku: string): Promise<ProductStatus[]>;\n isEligibleForIntroOffer(groupID: string): Promise<Boolean>;\n sync(): Promise<null>;\n getItems: getItems;\n getAvailableItems: getAvailableItems;\n buyProduct: BuyProduct;\n clearTransaction: clearTransaction;\n clearProducts: clearProducts;\n promotedProduct: promotedProduct;\n buyPromotedProduct: buyPromotedProduct;\n requestReceipt: requestReceipt;\n finishTransaction: finishTransaction;\n getPendingTransactions: getPendingTransactions;\n presentCodeRedemptionSheet: presentCodeRedemptionSheet;\n}\n\n/**\n * Sync state with Appstore (iOS only)\n * https://developer.apple.com/documentation/storekit/appstore/3791906-sync\n */\nexport const sync = (): Promise<null> => RNIapIosSk2.sync();\n\n/**\n *\n */\nexport const isEligibleForIntroOffer = (groupID: string): Promise<Boolean> =>\n RNIapIosSk2.isEligibleForIntroOffer(groupID);\n\n/**\n *\n */\n\nexport const subscriptionStatus = (sku: string): Promise<ProductStatus[]> =>\n RNIapIosSk2.subscriptionStatus(sku);\n\n/**\n *\n */\nexport const currentEntitlement = (sku: string): Promise<TransactionSk2> =>\n RNIapIosSk2.currentEntitlement(sku);\n\n/**\n *\n */\nexport const latestTransaction = (sku: string): Promise<TransactionSk2> =>\n RNIapIosSk2.latestTransaction(sku);\n"],"mappings":";;;;;;;AAAA;;AAWA,MAAM;EAACA;AAAD,IAAgBC,0BAAtB;;AA4CA;AACA;AACA;AACA;AACO,MAAMC,IAAI,GAAG,MAAqBF,WAAW,CAACE,IAAZ,EAAlC;AAEP;AACA;AACA;;;;;AACO,MAAMC,uBAAuB,GAAIC,OAAD,IACrCJ,WAAW,CAACG,uBAAZ,CAAoCC,OAApC,CADK;AAGP;AACA;AACA;;;;;AAEO,MAAMC,kBAAkB,GAAIC,GAAD,IAChCN,WAAW,CAACK,kBAAZ,CAA+BC,GAA/B,CADK;AAGP;AACA;AACA;;;;;AACO,MAAMC,kBAAkB,GAAID,GAAD,IAChCN,WAAW,CAACO,kBAAZ,CAA+BD,GAA/B,CADK;AAGP;AACA;AACA;;;;;AACO,MAAME,iBAAiB,GAAIF,GAAD,IAC/BN,WAAW,CAACQ,iBAAZ,CAA8BF,GAA9B,CADK"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["productSk2Map","id","description","displayName","price","displayPrice","prod","title","productId","String","type","localizedPrice","currency","subscriptionSk2Map","transactionSk2Map","originalPurchaseDate","productID","purchaseDate","purchasedQuantity","purchase","transactionId","transactionDate","transactionReceipt","purchaseToken","quantityIOS","originalTransactionDateIOS","originalTransactionIdentifierIOS","offerSk2Map","offer","undefined","offerID","identifier","keyID","keyIdentifier","nonce","signature","timestamp"],"sources":["appleSk2.ts"],"sourcesContent":["import type {ProductIOS, Purchase, SubscriptionIOS} from '.';\nimport type * as Apple from './apple';\nexport type ProductSk2 = {\n description: string;\n displayName: string;\n displayPrice: string;\n id: number;\n isFamilyShareable: boolean;\n jsonRepresentation: string;\n price: number;\n subscription: any; //TODO\n type: 'autoRenewable' | 'consumable' | 'nonConsumable' | 'nonRenewable';\n};\nexport const productSk2Map = ({\n id,\n description,\n displayName,\n price,\n displayPrice,\n}: ProductSk2): ProductIOS => {\n const prod: ProductIOS = {\n title: displayName,\n productId: String(id),\n description,\n type: 'iap',\n price: String(price),\n localizedPrice: displayPrice,\n currency: '', //TODO: Not avaiable on new API, use localizedPrice instead?\n };\n return prod;\n};\n\nexport const subscriptionSk2Map = ({\n id,\n description,\n displayName,\n price,\n displayPrice,\n}: ProductSk2): SubscriptionIOS => {\n const prod: SubscriptionIOS = {\n title: displayName,\n productId: String(id),\n description,\n type: 'subs',\n price: String(price),\n localizedPrice: displayPrice,\n currency: '', //TODO: Not avaiable on new API, use localizedPrice instead?\n };\n return prod;\n};\n\nexport type TransactionSk2 = {\n appAccountToken: string;\n appBundleID: string;\n debugDescription: string;\n deviceVerification: string;\n deviceVerificationNonce: string;\n expirationDate: number;\n id: number;\n isUpgraded: boolean;\n jsonRepresentation: string;\n offerID: string;\n offerType: string;\n originalID: string;\n originalPurchaseDate: number;\n ownershipType: string;\n productID: string;\n productType: string;\n purchaseDate: number;\n purchasedQuantity: number;\n revocationDate: number;\n revocationReason: string;\n signedDate: number;\n subscriptionGroupID: number;\n webOrderLineItemID: number;\n};\nexport const transactionSk2Map = ({\n id,\n originalPurchaseDate,\n productID,\n purchaseDate,\n purchasedQuantity,\n}: TransactionSk2): Purchase => {\n const purchase: Purchase = {\n productId: productID,\n transactionId: String(id),\n transactionDate: purchaseDate, //??\n transactionReceipt: '', // Not available\n purchaseToken: '', //Not avaiable\n quantityIOS: purchasedQuantity,\n originalTransactionDateIOS: String(originalPurchaseDate),\n originalTransactionIdentifierIOS: String(id), // ??\n };\n return purchase;\n};\n\n/**\n * Payment discount interface @see https://developer.apple.com/documentation/storekit/skpaymentdiscount?language=objc\n */\nexport interface PaymentDiscountSk2 {\n /**\n * A string used to uniquely identify a discount offer for a product.\n */\n offerID: string;\n\n /**\n * A string that identifies the key used to generate the signature.\n */\n keyID: string;\n\n /**\n * A universally unique ID (UUID) value that you define.\n */\n nonce: string;\n\n /**\n * A UTF-8 string representing the properties of a specific discount offer, cryptographically signed.\n */\n signature: string;\n\n /**\n * The date and time of the signature's creation in milliseconds, formatted in Unix epoch time.\n */\n timestamp: number;\n}\n\nexport const offerSk2Map = (\n offer: Apple.PaymentDiscount | undefined,\n): PaymentDiscountSk2 | undefined => {\n if (!offer) {\n return undefined;\n }\n return {\n offerID: offer.identifier,\n keyID: offer.keyIdentifier,\n nonce: offer.nonce,\n signature: offer.signature,\n timestamp: offer.timestamp,\n };\n};\n"],"mappings":";;;;;;;AAaO,MAAMA,aAAa,GAAG,QAMC;EAAA,IANA;IAC5BC,EAD4B;IAE5BC,WAF4B;IAG5BC,WAH4B;IAI5BC,KAJ4B;IAK5BC;EAL4B,CAMA;EAC5B,MAAMC,IAAgB,GAAG;IACvBC,KAAK,EAAEJ,WADgB;IAEvBK,SAAS,EAAEC,MAAM,CAACR,EAAD,CAFM;IAGvBC,WAHuB;IAIvBQ,IAAI,EAAE,KAJiB;IAKvBN,KAAK,EAAEK,MAAM,CAACL,KAAD,CALU;IAMvBO,cAAc,EAAEN,YANO;IAOvBO,QAAQ,EAAE,EAPa,CAOT;;EAPS,CAAzB;EASA,OAAON,IAAP;AACD,CAjBM;;;;AAmBA,MAAMO,kBAAkB,GAAG,SAMC;EAAA,IANA;IACjCZ,EADiC;IAEjCC,WAFiC;IAGjCC,WAHiC;IAIjCC,KAJiC;IAKjCC;EALiC,CAMA;EACjC,MAAMC,IAAqB,GAAG;IAC5BC,KAAK,EAAEJ,WADqB;IAE5BK,SAAS,EAAEC,MAAM,CAACR,EAAD,CAFW;IAG5BC,WAH4B;IAI5BQ,IAAI,EAAE,MAJsB;IAK5BN,KAAK,EAAEK,MAAM,CAACL,KAAD,CALe;IAM5BO,cAAc,EAAEN,YANY;IAO5BO,QAAQ,EAAE,EAPkB,CAOd;;EAPc,CAA9B;EASA,OAAON,IAAP;AACD,CAjBM;;;;
|
|
1
|
+
{"version":3,"names":["productSk2Map","id","description","displayName","price","displayPrice","prod","title","productId","String","type","localizedPrice","currency","subscriptionSk2Map","transactionSk2Map","originalPurchaseDate","productID","purchaseDate","purchasedQuantity","purchase","transactionId","transactionDate","transactionReceipt","purchaseToken","quantityIOS","originalTransactionDateIOS","originalTransactionIdentifierIOS","offerSk2Map","offer","undefined","offerID","identifier","keyID","keyIdentifier","nonce","signature","timestamp"],"sources":["appleSk2.ts"],"sourcesContent":["import type {ProductIOS, Purchase, SubscriptionIOS} from '.';\nimport type * as Apple from './apple';\nexport type ProductSk2 = {\n description: string;\n displayName: string;\n displayPrice: string;\n id: number;\n isFamilyShareable: boolean;\n jsonRepresentation: string;\n price: number;\n subscription: any; //TODO\n type: 'autoRenewable' | 'consumable' | 'nonConsumable' | 'nonRenewable';\n};\nexport const productSk2Map = ({\n id,\n description,\n displayName,\n price,\n displayPrice,\n}: ProductSk2): ProductIOS => {\n const prod: ProductIOS = {\n title: displayName,\n productId: String(id),\n description,\n type: 'iap',\n price: String(price),\n localizedPrice: displayPrice,\n currency: '', //TODO: Not avaiable on new API, use localizedPrice instead?\n };\n return prod;\n};\n\nexport const subscriptionSk2Map = ({\n id,\n description,\n displayName,\n price,\n displayPrice,\n}: ProductSk2): SubscriptionIOS => {\n const prod: SubscriptionIOS = {\n title: displayName,\n productId: String(id),\n description,\n type: 'subs',\n price: String(price),\n localizedPrice: displayPrice,\n currency: '', //TODO: Not avaiable on new API, use localizedPrice instead?\n };\n return prod;\n};\n\nexport type TransactionSk2 = {\n appAccountToken: string;\n appBundleID: string;\n debugDescription: string;\n deviceVerification: string;\n deviceVerificationNonce: string;\n expirationDate: number;\n id: number;\n isUpgraded: boolean;\n jsonRepresentation: string;\n offerID: string;\n offerType: string;\n originalID: string;\n originalPurchaseDate: number;\n ownershipType: string;\n productID: string;\n productType: string;\n purchaseDate: number;\n purchasedQuantity: number;\n revocationDate: number;\n revocationReason: string;\n signedDate: number;\n subscriptionGroupID: number;\n webOrderLineItemID: number;\n};\n\nexport type SubscriptionStatus =\n | 'expired'\n | 'inBillingRetryPeriod'\n | 'inGracePeriod'\n | 'revoked'\n | 'subscribed';\n\nexport type ProductStatus = {\n state: SubscriptionStatus;\n};\n\nexport const transactionSk2Map = ({\n id,\n originalPurchaseDate,\n productID,\n purchaseDate,\n purchasedQuantity,\n}: TransactionSk2): Purchase => {\n const purchase: Purchase = {\n productId: productID,\n transactionId: String(id),\n transactionDate: purchaseDate, //??\n transactionReceipt: '', // Not available\n purchaseToken: '', //Not avaiable\n quantityIOS: purchasedQuantity,\n originalTransactionDateIOS: String(originalPurchaseDate),\n originalTransactionIdentifierIOS: String(id), // ??\n };\n return purchase;\n};\n\n/**\n * Payment discount interface @see https://developer.apple.com/documentation/storekit/skpaymentdiscount?language=objc\n */\nexport interface PaymentDiscountSk2 {\n /**\n * A string used to uniquely identify a discount offer for a product.\n */\n offerID: string;\n\n /**\n * A string that identifies the key used to generate the signature.\n */\n keyID: string;\n\n /**\n * A universally unique ID (UUID) value that you define.\n */\n nonce: string;\n\n /**\n * A UTF-8 string representing the properties of a specific discount offer, cryptographically signed.\n */\n signature: string;\n\n /**\n * The date and time of the signature's creation in milliseconds, formatted in Unix epoch time.\n */\n timestamp: number;\n}\n\nexport const offerSk2Map = (\n offer: Apple.PaymentDiscount | undefined,\n): PaymentDiscountSk2 | undefined => {\n if (!offer) {\n return undefined;\n }\n return {\n offerID: offer.identifier,\n keyID: offer.keyIdentifier,\n nonce: offer.nonce,\n signature: offer.signature,\n timestamp: offer.timestamp,\n };\n};\n"],"mappings":";;;;;;;AAaO,MAAMA,aAAa,GAAG,QAMC;EAAA,IANA;IAC5BC,EAD4B;IAE5BC,WAF4B;IAG5BC,WAH4B;IAI5BC,KAJ4B;IAK5BC;EAL4B,CAMA;EAC5B,MAAMC,IAAgB,GAAG;IACvBC,KAAK,EAAEJ,WADgB;IAEvBK,SAA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,IAAI,CAACA,KAAL,EAAY;IACV,OAAOC,SAAP;EACD;;EACD,OAAO;IACLC,OAAO,EAAEF,KAAK,CAACG,UADV;IAELC,KAAK,EAAEJ,KAAK,CAACK,aAFR;IAGLC,KAAK,EAAEN,KAAK,CAACM,KAHR;IAILC,SAAS,EAAEP,KAAK,CAACO,SAJZ;IAKLC,SAAS,EAAER,KAAK,CAACQ;EALZ,CAAP;AAOD,CAbM"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { NativeEventEmitter } from 'react-native';
|
|
2
2
|
import { transactionSk2Map } from './types/appleSk2';
|
|
3
|
-
import {
|
|
4
|
-
import { isAndroid, isIos } from './internal';
|
|
3
|
+
import { isIosStorekit2 } from './iap';
|
|
4
|
+
import { getAndroidModule, getIosModule, getNativeModule, isAndroid, isIos } from './internal';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Add IAP purchase event
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["NativeEventEmitter","transactionSk2Map","getAndroidModule","getIosModule","getNativeModule","
|
|
1
|
+
{"version":3,"names":["NativeEventEmitter","transactionSk2Map","isIosStorekit2","getAndroidModule","getIosModule","getNativeModule","isAndroid","isIos","purchaseUpdatedListener","listener","eventEmitter","proxyListener","event","emitterSubscription","addListener","startListening","purchaseErrorListener","promotedProductListener"],"sources":["eventEmitter.ts"],"sourcesContent":["import {EmitterSubscription, NativeEventEmitter} from 'react-native';\n\nimport {transactionSk2Map} from './types/appleSk2';\nimport {isIosStorekit2} from './iap';\nimport {\n getAndroidModule,\n getIosModule,\n getNativeModule,\n isAndroid,\n isIos,\n} from './internal';\nimport type {PurchaseError} from './purchaseError';\nimport type {Purchase} from './types';\n\n/**\n * Add IAP purchase event\n */\nexport const purchaseUpdatedListener = (\n listener: (event: Purchase) => void,\n) => {\n const eventEmitter = new NativeEventEmitter(getNativeModule());\n const proxyListener = isIosStorekit2()\n ? (event: Purchase) => {\n listener(transactionSk2Map(event as any));\n }\n : listener;\n const emitterSubscription = eventEmitter.addListener(\n 'purchase-updated',\n proxyListener,\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 => {\n const eventEmitter = new NativeEventEmitter(getNativeModule());\n return eventEmitter.addListener('purchase-error', listener);\n};\n\n/**\n * Add IAP promoted subscription event\n *\n * @platform iOS\n */\nexport const promotedProductListener = (listener: () => void) => {\n if (isIos) {\n const eventEmitter = new NativeEventEmitter(getIosModule());\n return eventEmitter.addListener('iap-promoted-product', listener);\n }\n\n return null;\n};\n"],"mappings":"AAAA,SAA6BA,kBAA7B,QAAsD,cAAtD;AAEA,SAAQC,iBAAR,QAAgC,kBAAhC;AACA,SAAQC,cAAR,QAA6B,OAA7B;AACA,SACEC,gBADF,EAEEC,YAFF,EAGEC,eAHF,EAIEC,SAJF,EAKEC,KALF,QAMO,YANP;;AAUA;AACA;AACA;AACA,OAAO,MAAMC,uBAAuB,GAClCC,QADqC,IAElC;EACH,MAAMC,YAAY,GAAG,IAAIV,kBAAJ,CAAuBK,eAAe,EAAtC,CAArB;EACA,MAAMM,aAAa,GAAGT,cAAc,KAC/BU,KAAD,IAAqB;IACnBH,QAAQ,CAACR,iBAAiB,CAACW,KAAD,CAAlB,CAAR;EACD,CAH+B,GAIhCH,QAJJ;EAKA,MAAMI,mBAAmB,GAAGH,YAAY,CAACI,WAAb,CAC1B,kBAD0B,EAE1BH,aAF0B,CAA5B;;EAKA,IAAIL,SAAJ,EAAe;IACbH,gBAAgB,GAAGY,cAAnB;EACD;;EAED,OAAOF,mBAAP;AACD,CAnBM;AAqBP;AACA;AACA;;AACA,OAAO,MAAMG,qBAAqB,GAChCP,QADmC,IAEX;EACxB,MAAMC,YAAY,GAAG,IAAIV,kBAAJ,CAAuBK,eAAe,EAAtC,CAArB;EACA,OAAOK,YAAY,CAACI,WAAb,CAAyB,gBAAzB,EAA2CL,QAA3C,CAAP;AACD,CALM;AAOP;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMQ,uBAAuB,GAAIR,QAAD,IAA0B;EAC/D,IAAIF,KAAJ,EAAW;IACT,MAAMG,YAAY,GAAG,IAAIV,kBAAJ,CAAuBI,YAAY,EAAnC,CAArB;IACA,OAAOM,YAAY,CAACI,WAAb,CAAyB,sBAAzB,EAAiDL,QAAjD,CAAP;EACD;;EAED,OAAO,IAAP;AACD,CAPM"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React, { useContext, useEffect, useMemo, useState } from 'react';
|
|
2
2
|
import { promotedProductListener, purchaseErrorListener, purchaseUpdatedListener } from '../eventEmitter';
|
|
3
|
-
import {
|
|
3
|
+
import { IapIos, initConnection } from '../iap';
|
|
4
4
|
// @ts-ignore
|
|
5
5
|
const IAPContext = /*#__PURE__*/React.createContext(null);
|
|
6
6
|
export function useIAPContext() {
|
|
@@ -60,7 +60,7 @@ export function withIAPContext(Component) {
|
|
|
60
60
|
setCurrentPurchaseError(error);
|
|
61
61
|
});
|
|
62
62
|
const promotedProductSubscription = promotedProductListener(async () => {
|
|
63
|
-
const product = await getPromotedProductIOS();
|
|
63
|
+
const product = await IapIos.getPromotedProductIOS();
|
|
64
64
|
setPromotedProductsIOS(prevProducts => [...prevProducts, ...(product ? [product] : [])]);
|
|
65
65
|
});
|
|
66
66
|
return () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","useContext","useEffect","useMemo","useState","promotedProductListener","purchaseErrorListener","purchaseUpdatedListener","
|
|
1
|
+
{"version":3,"names":["React","useContext","useEffect","useMemo","useState","promotedProductListener","purchaseErrorListener","purchaseUpdatedListener","IapIos","initConnection","IAPContext","createContext","useIAPContext","ctx","Error","withIAPContext","Component","WrapperComponent","props","connected","setConnected","products","setProducts","promotedProductsIOS","setPromotedProductsIOS","subscriptions","setSubscriptions","purchaseHistory","setPurchaseHistory","availablePurchases","setAvailablePurchases","currentPurchase","setCurrentPurchase","currentPurchaseError","setCurrentPurchaseError","initConnectionError","setInitConnectionError","context","then","value","undefined","catch","purchaseUpdateSubscription","purchase","purchaseErrorSubscription","error","promotedProductSubscription","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 {IapIos, 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 IapIos.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,OAAOA,KAAP,IAAeC,UAAf,EAA2BC,SAA3B,EAAsCC,OAAtC,EAA+CC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