react-native-iap 14.3.2-rc.1 → 14.3.2-rc.3
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/lib/commonjs/index.js +36 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/specs/RnIap.nitro.js +6 -0
- package/lib/commonjs/specs/RnIap.nitro.js.map +1 -0
- package/lib/commonjs/types.js +118 -0
- package/lib/commonjs/types.js.map +1 -0
- package/lib/module/index.js +51 -49
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/plugin/src/withIAP.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/package.json +2 -1
- package/plugin/build/withIAP.js +68 -1
- package/plugin/src/withIAP.ts +80 -3
- package/src/index.ts +64 -61
- package/lib/index.d.ts +0 -8
- package/lib/index.js +0 -36
- package/lib/specs/RnIap.nitro.d.ts +0 -7
- package/lib/specs/RnIap.nitro.js +0 -1
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _exportNames = {};
|
|
7
|
+
exports.default = void 0;
|
|
8
|
+
var _reactNativeNitroModules = require("react-native-nitro-modules");
|
|
9
|
+
var _RnIap = require("./specs/RnIap.nitro");
|
|
10
|
+
Object.keys(_RnIap).forEach(function (key) {
|
|
11
|
+
if (key === "default" || key === "__esModule") return;
|
|
12
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
13
|
+
if (key in exports && exports[key] === _RnIap[key]) return;
|
|
14
|
+
Object.defineProperty(exports, key, {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: function () {
|
|
17
|
+
return _RnIap[key];
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
var _types = require("./types");
|
|
22
|
+
Object.keys(_types).forEach(function (key) {
|
|
23
|
+
if (key === "default" || key === "__esModule") return;
|
|
24
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
25
|
+
if (key in exports && exports[key] === _types[key]) return;
|
|
26
|
+
Object.defineProperty(exports, key, {
|
|
27
|
+
enumerable: true,
|
|
28
|
+
get: function () {
|
|
29
|
+
return _types[key];
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
// Create and export the RnIap HybridObject directly
|
|
34
|
+
const RnIap = _reactNativeNitroModules.NitroModules.createHybridObject('RnIap');
|
|
35
|
+
var _default = exports.default = RnIap;
|
|
36
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_reactNativeNitroModules","require","_RnIap","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_types","RnIap","NitroModules","createHybridObject","_default","default"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;;;;;;AAAA,IAAAA,wBAAA,GAAAC,OAAA;AAGA,IAAAC,MAAA,GAAAD,OAAA;AAAAE,MAAA,CAAAC,IAAA,CAAAF,MAAA,EAAAG,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAJ,MAAA,CAAAI,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAZ,MAAA,CAAAI,GAAA;IAAA;EAAA;AAAA;AACA,IAAAS,MAAA,GAAAd,OAAA;AAAAE,MAAA,CAAAC,IAAA,CAAAW,MAAA,EAAAV,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAS,MAAA,CAAAT,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAC,MAAA,CAAAT,GAAA;IAAA;EAAA;AAAA;AAEA;AACA,MAAMU,KAAK,GAAGC,qCAAY,CAACC,kBAAkB,CAAY,OAAO,CAAC;AAAA,IAAAC,QAAA,GAAAR,OAAA,CAAAS,OAAA,GAElDJ,KAAK","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sourceRoot":"../../../src","sources":["specs/RnIap.nitro.ts"],"mappings":"","ignoreList":[]}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.PurchaseAndroidState = exports.ErrorCode = void 0;
|
|
7
|
+
// ============================================================================
|
|
8
|
+
// CORE TYPES
|
|
9
|
+
// ============================================================================
|
|
10
|
+
// ============================================================================
|
|
11
|
+
// COMMON TYPES (Base types shared across all platforms)
|
|
12
|
+
// ============================================================================
|
|
13
|
+
/**
|
|
14
|
+
* Base product information shared across all platforms
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Base purchase information shared across all platforms
|
|
18
|
+
* Represents both consumables, non-consumables, and subscriptions
|
|
19
|
+
*/
|
|
20
|
+
// ============================================================================
|
|
21
|
+
// PLATFORM TYPES
|
|
22
|
+
// ============================================================================
|
|
23
|
+
// ============================================================================
|
|
24
|
+
// IOS TYPES
|
|
25
|
+
// ============================================================================
|
|
26
|
+
// ============================================================================
|
|
27
|
+
// ANDROID TYPES
|
|
28
|
+
// ============================================================================
|
|
29
|
+
let PurchaseAndroidState = exports.PurchaseAndroidState = /*#__PURE__*/function (PurchaseAndroidState) {
|
|
30
|
+
PurchaseAndroidState[PurchaseAndroidState["UNSPECIFIED_STATE"] = 0] = "UNSPECIFIED_STATE";
|
|
31
|
+
PurchaseAndroidState[PurchaseAndroidState["PURCHASED"] = 1] = "PURCHASED";
|
|
32
|
+
PurchaseAndroidState[PurchaseAndroidState["PENDING"] = 2] = "PENDING";
|
|
33
|
+
return PurchaseAndroidState;
|
|
34
|
+
}({}); // ============================================================================
|
|
35
|
+
// TYPE ALIASES
|
|
36
|
+
// ============================================================================
|
|
37
|
+
// Legacy naming for backward compatibility
|
|
38
|
+
// Legacy naming for backward compatibility
|
|
39
|
+
// ============================================================================
|
|
40
|
+
// UNION TYPES
|
|
41
|
+
// ============================================================================
|
|
42
|
+
// Product Union Types
|
|
43
|
+
// Purchase Union Types
|
|
44
|
+
/**
|
|
45
|
+
* Regular product purchase (consumable or non-consumable)
|
|
46
|
+
* Both types appear in getAvailablePurchases until finishTransaction is called
|
|
47
|
+
*/
|
|
48
|
+
/**
|
|
49
|
+
* Active subscription purchase
|
|
50
|
+
* Appears in getAvailablePurchases while subscription is active
|
|
51
|
+
*/
|
|
52
|
+
/**
|
|
53
|
+
* Combined purchase type that includes all purchase types
|
|
54
|
+
* Used as return type for getAvailablePurchases
|
|
55
|
+
*/
|
|
56
|
+
// ============================================================================
|
|
57
|
+
// REQUEST TYPES
|
|
58
|
+
// ============================================================================
|
|
59
|
+
// iOS-specific purchase request parameters
|
|
60
|
+
// Android-specific purchase request parameters
|
|
61
|
+
// Android-specific subscription request parameters
|
|
62
|
+
// Platform-specific request structures
|
|
63
|
+
// Modern request types (v2.7.0+)
|
|
64
|
+
// ============================================================================
|
|
65
|
+
// ERROR TYPES
|
|
66
|
+
// ============================================================================
|
|
67
|
+
let ErrorCode = exports.ErrorCode = /*#__PURE__*/function (ErrorCode) {
|
|
68
|
+
ErrorCode["E_UNKNOWN"] = "E_UNKNOWN";
|
|
69
|
+
ErrorCode["E_USER_CANCELLED"] = "E_USER_CANCELLED";
|
|
70
|
+
ErrorCode["E_USER_ERROR"] = "E_USER_ERROR";
|
|
71
|
+
ErrorCode["E_ITEM_UNAVAILABLE"] = "E_ITEM_UNAVAILABLE";
|
|
72
|
+
ErrorCode["E_REMOTE_ERROR"] = "E_REMOTE_ERROR";
|
|
73
|
+
ErrorCode["E_NETWORK_ERROR"] = "E_NETWORK_ERROR";
|
|
74
|
+
ErrorCode["E_SERVICE_ERROR"] = "E_SERVICE_ERROR";
|
|
75
|
+
ErrorCode["E_RECEIPT_FAILED"] = "E_RECEIPT_FAILED";
|
|
76
|
+
ErrorCode["E_RECEIPT_FINISHED_FAILED"] = "E_RECEIPT_FINISHED_FAILED";
|
|
77
|
+
ErrorCode["E_NOT_PREPARED"] = "E_NOT_PREPARED";
|
|
78
|
+
ErrorCode["E_NOT_ENDED"] = "E_NOT_ENDED";
|
|
79
|
+
ErrorCode["E_ALREADY_OWNED"] = "E_ALREADY_OWNED";
|
|
80
|
+
ErrorCode["E_DEVELOPER_ERROR"] = "E_DEVELOPER_ERROR";
|
|
81
|
+
ErrorCode["E_BILLING_RESPONSE_JSON_PARSE_ERROR"] = "E_BILLING_RESPONSE_JSON_PARSE_ERROR";
|
|
82
|
+
ErrorCode["E_DEFERRED_PAYMENT"] = "E_DEFERRED_PAYMENT";
|
|
83
|
+
ErrorCode["E_INTERRUPTED"] = "E_INTERRUPTED";
|
|
84
|
+
ErrorCode["E_IAP_NOT_AVAILABLE"] = "E_IAP_NOT_AVAILABLE";
|
|
85
|
+
ErrorCode["E_PURCHASE_ERROR"] = "E_PURCHASE_ERROR";
|
|
86
|
+
ErrorCode["E_SYNC_ERROR"] = "E_SYNC_ERROR";
|
|
87
|
+
ErrorCode["E_TRANSACTION_VALIDATION_FAILED"] = "E_TRANSACTION_VALIDATION_FAILED";
|
|
88
|
+
ErrorCode["E_ACTIVITY_UNAVAILABLE"] = "E_ACTIVITY_UNAVAILABLE";
|
|
89
|
+
ErrorCode["E_ALREADY_PREPARED"] = "E_ALREADY_PREPARED";
|
|
90
|
+
ErrorCode["E_PENDING"] = "E_PENDING";
|
|
91
|
+
ErrorCode["E_CONNECTION_CLOSED"] = "E_CONNECTION_CLOSED";
|
|
92
|
+
return ErrorCode;
|
|
93
|
+
}({}); // Additional iOS types
|
|
94
|
+
// ============================================================================
|
|
95
|
+
// METHOD OPTIONS TYPES
|
|
96
|
+
// ============================================================================
|
|
97
|
+
/**
|
|
98
|
+
* Options for getAvailablePurchases and getPurchaseHistories methods
|
|
99
|
+
*/
|
|
100
|
+
/**
|
|
101
|
+
* Parameters for finishTransaction method
|
|
102
|
+
*/
|
|
103
|
+
// ============================================================================
|
|
104
|
+
// IAP CONTEXT INTERFACE
|
|
105
|
+
// ============================================================================
|
|
106
|
+
/**
|
|
107
|
+
* Main IAP context interface providing all in-app purchase functionality
|
|
108
|
+
*/
|
|
109
|
+
/**
|
|
110
|
+
* Purchase error type
|
|
111
|
+
*/
|
|
112
|
+
/**
|
|
113
|
+
* Validation options for receipt validation
|
|
114
|
+
*/
|
|
115
|
+
/**
|
|
116
|
+
* Validation result from receipt validation
|
|
117
|
+
*/
|
|
118
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["PurchaseAndroidState","exports","ErrorCode"],"sourceRoot":"../../src","sources":["types.ts"],"mappings":";;;;;;AAAA;AACA;AACA;AAQA;AACA;AACA;AAEA;AACA;AACA;AAwBA;AACA;AACA;AACA;AAwBA;AACA;AACA;AAKA;AACA;AACA;AAyGA;AACA;AACA;AAAA,IAsDYA,oBAAoB,GAAAC,OAAA,CAAAD,oBAAA,0BAApBA,oBAAoB;EAApBA,oBAAoB,CAApBA,oBAAoB;EAApBA,oBAAoB,CAApBA,oBAAoB;EAApBA,oBAAoB,CAApBA,oBAAoB;EAAA,OAApBA,oBAAoB;AAAA,OAuBhC;AACA;AACA;AAEA;AAIA;AAIA;AACA;AACA;AAEA;AASA;AACA;AACA;AACA;AACA;AAKA;AACA;AACA;AACA;AAKA;AACA;AACA;AACA;AAKA;AACA;AACA;AAEA;AASA;AAQA;AAWA;AAWA;AAIA;AACA;AACA;AAAA,IAEYE,SAAS,GAAAD,OAAA,CAAAC,SAAA,0BAATA,SAAS;EAATA,SAAS;EAATA,SAAS;EAATA,SAAS;EAATA,SAAS;EAATA,SAAS;EAATA,SAAS;EAATA,SAAS;EAATA,SAAS;EAATA,SAAS;EAATA,SAAS;EAATA,SAAS;EAATA,SAAS;EAATA,SAAS;EAATA,SAAS;EAATA,SAAS;EAATA,SAAS;EAATA,SAAS;EAATA,SAAS;EAATA,SAAS;EAATA,SAAS;EAATA,SAAS;EAATA,SAAS;EAATA,SAAS;EAATA,SAAS;EAAA,OAATA,SAAS;AAAA,OAuCrB;AAyBA;AACA;AACA;AAEA;AACA;AACA;AAQA;AACA;AACA;AAeA;AACA;AACA;AAEA;AACA;AACA;AAkFA;AACA;AACA;AAUA;AACA;AACA;AAmBA;AACA;AACA","ignoreList":[]}
|
package/lib/module/index.js
CHANGED
|
@@ -39,18 +39,20 @@ export const restorePurchases = async (options = {
|
|
|
39
39
|
// Development utilities removed - use type bridge functions directly if needed
|
|
40
40
|
|
|
41
41
|
// Create the RnIap HybridObject instance lazily to avoid early JSI crashes
|
|
42
|
-
let
|
|
43
|
-
const
|
|
44
|
-
|
|
42
|
+
let iapRef = null;
|
|
43
|
+
const IAP = {
|
|
44
|
+
get instance() {
|
|
45
|
+
if (iapRef) return iapRef;
|
|
45
46
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
47
|
+
// Guard against accessing Nitro before it's installed into the JS runtime
|
|
48
|
+
const hasNitroDispatcher = typeof globalThis !== 'undefined' && globalThis?.__nitro?.dispatcher != null;
|
|
49
|
+
const isJestEnvironment = typeof globalThis.jest !== 'undefined' || typeof process !== 'undefined' && !!process.env && process.env.JEST_WORKER_ID != null;
|
|
50
|
+
if (!hasNitroDispatcher && !isJestEnvironment) {
|
|
51
|
+
throw new Error('Nitro runtime not installed yet. Ensure react-native-nitro-modules is initialized before calling IAP.');
|
|
52
|
+
}
|
|
53
|
+
iapRef = NitroModules.createHybridObject('RnIap');
|
|
54
|
+
return iapRef;
|
|
51
55
|
}
|
|
52
|
-
iap = NitroModules.createHybridObject('RnIap');
|
|
53
|
-
return iap;
|
|
54
56
|
};
|
|
55
57
|
|
|
56
58
|
/**
|
|
@@ -58,7 +60,7 @@ const getIap = () => {
|
|
|
58
60
|
*/
|
|
59
61
|
export const initConnection = async () => {
|
|
60
62
|
try {
|
|
61
|
-
return await
|
|
63
|
+
return await IAP.instance.initConnection();
|
|
62
64
|
} catch (error) {
|
|
63
65
|
console.error('Failed to initialize IAP connection:', error);
|
|
64
66
|
throw error;
|
|
@@ -71,8 +73,8 @@ export const initConnection = async () => {
|
|
|
71
73
|
export const endConnection = async () => {
|
|
72
74
|
try {
|
|
73
75
|
// If never initialized, treat as ended
|
|
74
|
-
if (!
|
|
75
|
-
return await
|
|
76
|
+
if (!iapRef) return true;
|
|
77
|
+
return await IAP.instance.endConnection();
|
|
76
78
|
} catch (error) {
|
|
77
79
|
console.error('Failed to end IAP connection:', error);
|
|
78
80
|
throw error;
|
|
@@ -104,7 +106,7 @@ export const fetchProducts = async ({
|
|
|
104
106
|
throw new Error('No SKUs provided');
|
|
105
107
|
}
|
|
106
108
|
if (type === 'all') {
|
|
107
|
-
const [inappNitro, subsNitro] = await Promise.all([
|
|
109
|
+
const [inappNitro, subsNitro] = await Promise.all([IAP.instance.fetchProducts(skus, 'inapp'), IAP.instance.fetchProducts(skus, 'subs')]);
|
|
108
110
|
const allNitro = [...inappNitro, ...subsNitro];
|
|
109
111
|
const validAll = allNitro.filter(validateNitroProduct);
|
|
110
112
|
if (validAll.length !== allNitro.length) {
|
|
@@ -112,7 +114,7 @@ export const fetchProducts = async ({
|
|
|
112
114
|
}
|
|
113
115
|
return validAll.map(convertNitroProductToProduct);
|
|
114
116
|
}
|
|
115
|
-
const nitroProducts = await
|
|
117
|
+
const nitroProducts = await IAP.instance.fetchProducts(skus, type);
|
|
116
118
|
|
|
117
119
|
// Validate and convert NitroProducts to TypeScript Products
|
|
118
120
|
const validProducts = nitroProducts.filter(validateNitroProduct);
|
|
@@ -211,7 +213,7 @@ export const requestPurchase = async ({
|
|
|
211
213
|
}
|
|
212
214
|
|
|
213
215
|
// Call unified method - returns void, listen for events instead
|
|
214
|
-
await
|
|
216
|
+
await IAP.instance.requestPurchase(unifiedRequest);
|
|
215
217
|
} catch (error) {
|
|
216
218
|
console.error('Failed to request purchase:', error);
|
|
217
219
|
throw error;
|
|
@@ -248,12 +250,12 @@ export const getAvailablePurchases = async ({
|
|
|
248
250
|
};
|
|
249
251
|
} else if (Platform.OS === 'android') {
|
|
250
252
|
// For Android, we need to call twice for inapp and subs
|
|
251
|
-
const inappNitroPurchases = await
|
|
253
|
+
const inappNitroPurchases = await IAP.instance.getAvailablePurchases({
|
|
252
254
|
android: {
|
|
253
255
|
type: 'inapp'
|
|
254
256
|
}
|
|
255
257
|
});
|
|
256
|
-
const subsNitroPurchases = await
|
|
258
|
+
const subsNitroPurchases = await IAP.instance.getAvailablePurchases({
|
|
257
259
|
android: {
|
|
258
260
|
type: 'subs'
|
|
259
261
|
}
|
|
@@ -269,7 +271,7 @@ export const getAvailablePurchases = async ({
|
|
|
269
271
|
} else {
|
|
270
272
|
throw new Error('Unsupported platform');
|
|
271
273
|
}
|
|
272
|
-
const nitroPurchases = await
|
|
274
|
+
const nitroPurchases = await IAP.instance.getAvailablePurchases(options);
|
|
273
275
|
|
|
274
276
|
// Validate and convert NitroPurchases to TypeScript Purchases
|
|
275
277
|
const validPurchases = nitroPurchases.filter(validateNitroPurchase);
|
|
@@ -324,7 +326,7 @@ export const finishTransaction = async ({
|
|
|
324
326
|
} else {
|
|
325
327
|
throw new Error('Unsupported platform');
|
|
326
328
|
}
|
|
327
|
-
const result = await
|
|
329
|
+
const result = await IAP.instance.finishTransaction(params);
|
|
328
330
|
|
|
329
331
|
// Handle variant return type
|
|
330
332
|
if (typeof result === 'boolean') {
|
|
@@ -362,7 +364,7 @@ export const acknowledgePurchaseAndroid = async purchaseToken => {
|
|
|
362
364
|
if (Platform.OS !== 'android') {
|
|
363
365
|
throw new Error('acknowledgePurchaseAndroid is only available on Android');
|
|
364
366
|
}
|
|
365
|
-
const result = await
|
|
367
|
+
const result = await IAP.instance.finishTransaction({
|
|
366
368
|
android: {
|
|
367
369
|
purchaseToken,
|
|
368
370
|
isConsumable: false
|
|
@@ -400,7 +402,7 @@ export const consumePurchaseAndroid = async purchaseToken => {
|
|
|
400
402
|
if (Platform.OS !== 'android') {
|
|
401
403
|
throw new Error('consumePurchaseAndroid is only available on Android');
|
|
402
404
|
}
|
|
403
|
-
const result = await
|
|
405
|
+
const result = await IAP.instance.finishTransaction({
|
|
404
406
|
android: {
|
|
405
407
|
purchaseToken,
|
|
406
408
|
isConsumable: true
|
|
@@ -466,7 +468,7 @@ export const purchaseUpdatedListener = listener => {
|
|
|
466
468
|
listenerMap.set(listener, wrappedListener);
|
|
467
469
|
let attached = false;
|
|
468
470
|
try {
|
|
469
|
-
|
|
471
|
+
IAP.instance.addPurchaseUpdatedListener(wrappedListener);
|
|
470
472
|
attached = true;
|
|
471
473
|
} catch (e) {
|
|
472
474
|
const msg = String(e ?? '');
|
|
@@ -482,7 +484,7 @@ export const purchaseUpdatedListener = listener => {
|
|
|
482
484
|
if (wrapped) {
|
|
483
485
|
if (attached) {
|
|
484
486
|
try {
|
|
485
|
-
|
|
487
|
+
IAP.instance.removePurchaseUpdatedListener(wrapped);
|
|
486
488
|
} catch {}
|
|
487
489
|
}
|
|
488
490
|
listenerMap.delete(listener);
|
|
@@ -523,7 +525,7 @@ export const purchaseErrorListener = listener => {
|
|
|
523
525
|
listenerMap.set(listener, listener);
|
|
524
526
|
let attached = false;
|
|
525
527
|
try {
|
|
526
|
-
|
|
528
|
+
IAP.instance.addPurchaseErrorListener(listener);
|
|
527
529
|
attached = true;
|
|
528
530
|
} catch (e) {
|
|
529
531
|
const msg = String(e ?? '');
|
|
@@ -537,7 +539,7 @@ export const purchaseErrorListener = listener => {
|
|
|
537
539
|
remove: () => {
|
|
538
540
|
if (attached) {
|
|
539
541
|
try {
|
|
540
|
-
|
|
542
|
+
IAP.instance.removePurchaseErrorListener(listener);
|
|
541
543
|
} catch {}
|
|
542
544
|
}
|
|
543
545
|
listenerMap.delete(listener);
|
|
@@ -587,7 +589,7 @@ export const promotedProductListenerIOS = listener => {
|
|
|
587
589
|
listenerMap.set(listener, wrappedListener);
|
|
588
590
|
let attached = false;
|
|
589
591
|
try {
|
|
590
|
-
|
|
592
|
+
IAP.instance.addPromotedProductListenerIOS(wrappedListener);
|
|
591
593
|
attached = true;
|
|
592
594
|
} catch (e) {
|
|
593
595
|
const msg = String(e ?? '');
|
|
@@ -603,7 +605,7 @@ export const promotedProductListenerIOS = listener => {
|
|
|
603
605
|
if (wrapped) {
|
|
604
606
|
if (attached) {
|
|
605
607
|
try {
|
|
606
|
-
|
|
608
|
+
IAP.instance.removePromotedProductListenerIOS(wrapped);
|
|
607
609
|
} catch {}
|
|
608
610
|
}
|
|
609
611
|
listenerMap.delete(listener);
|
|
@@ -628,7 +630,7 @@ export const validateReceipt = async (sku, androidOptions) => {
|
|
|
628
630
|
sku,
|
|
629
631
|
androidOptions
|
|
630
632
|
};
|
|
631
|
-
const nitroResult = await
|
|
633
|
+
const nitroResult = await IAP.instance.validateReceipt(params);
|
|
632
634
|
|
|
633
635
|
// Convert Nitro result to public API result
|
|
634
636
|
if (Platform.OS === 'ios') {
|
|
@@ -682,7 +684,7 @@ export const syncIOS = async () => {
|
|
|
682
684
|
throw new Error('syncIOS is only available on iOS');
|
|
683
685
|
}
|
|
684
686
|
try {
|
|
685
|
-
return await
|
|
687
|
+
return await IAP.instance.syncIOS();
|
|
686
688
|
} catch (error) {
|
|
687
689
|
console.error('[syncIOS] Failed:', error);
|
|
688
690
|
const errorJson = parseErrorStringToJsonObj(error);
|
|
@@ -700,7 +702,7 @@ export const requestPromotedProductIOS = async () => {
|
|
|
700
702
|
return null;
|
|
701
703
|
}
|
|
702
704
|
try {
|
|
703
|
-
const nitroProduct = await
|
|
705
|
+
const nitroProduct = await IAP.instance.requestPromotedProductIOS();
|
|
704
706
|
if (nitroProduct) {
|
|
705
707
|
return convertNitroProductToProduct(nitroProduct);
|
|
706
708
|
}
|
|
@@ -722,7 +724,7 @@ export const presentCodeRedemptionSheetIOS = async () => {
|
|
|
722
724
|
return false;
|
|
723
725
|
}
|
|
724
726
|
try {
|
|
725
|
-
return await
|
|
727
|
+
return await IAP.instance.presentCodeRedemptionSheetIOS();
|
|
726
728
|
} catch (error) {
|
|
727
729
|
console.error('[presentCodeRedemptionSheetIOS] Failed:', error);
|
|
728
730
|
const errorJson = parseErrorStringToJsonObj(error);
|
|
@@ -740,7 +742,7 @@ export const buyPromotedProductIOS = async () => {
|
|
|
740
742
|
throw new Error('buyPromotedProductIOS is only available on iOS');
|
|
741
743
|
}
|
|
742
744
|
try {
|
|
743
|
-
await
|
|
745
|
+
await IAP.instance.buyPromotedProductIOS();
|
|
744
746
|
} catch (error) {
|
|
745
747
|
console.error('[buyPromotedProductIOS] Failed:', error);
|
|
746
748
|
const errorJson = parseErrorStringToJsonObj(error);
|
|
@@ -758,7 +760,7 @@ export const clearTransactionIOS = async () => {
|
|
|
758
760
|
return;
|
|
759
761
|
}
|
|
760
762
|
try {
|
|
761
|
-
await
|
|
763
|
+
await IAP.instance.clearTransactionIOS();
|
|
762
764
|
} catch (error) {
|
|
763
765
|
console.error('[clearTransactionIOS] Failed:', error);
|
|
764
766
|
const errorJson = parseErrorStringToJsonObj(error);
|
|
@@ -777,7 +779,7 @@ export const beginRefundRequestIOS = async sku => {
|
|
|
777
779
|
return null;
|
|
778
780
|
}
|
|
779
781
|
try {
|
|
780
|
-
return await
|
|
782
|
+
return await IAP.instance.beginRefundRequestIOS(sku);
|
|
781
783
|
} catch (error) {
|
|
782
784
|
console.error('[beginRefundRequestIOS] Failed:', error);
|
|
783
785
|
const errorJson = parseErrorStringToJsonObj(error);
|
|
@@ -797,7 +799,7 @@ export const subscriptionStatusIOS = async sku => {
|
|
|
797
799
|
throw new Error('subscriptionStatusIOS is only available on iOS');
|
|
798
800
|
}
|
|
799
801
|
try {
|
|
800
|
-
const statuses = await
|
|
802
|
+
const statuses = await IAP.instance.subscriptionStatusIOS(sku);
|
|
801
803
|
if (!statuses || !Array.isArray(statuses)) return [];
|
|
802
804
|
return statuses.map(s => convertNitroSubscriptionStatusToSubscriptionStatusIOS(s));
|
|
803
805
|
} catch (error) {
|
|
@@ -818,7 +820,7 @@ export const currentEntitlementIOS = async sku => {
|
|
|
818
820
|
return null;
|
|
819
821
|
}
|
|
820
822
|
try {
|
|
821
|
-
const nitroPurchase = await
|
|
823
|
+
const nitroPurchase = await IAP.instance.currentEntitlementIOS(sku);
|
|
822
824
|
if (nitroPurchase) {
|
|
823
825
|
return convertNitroPurchaseToPurchase(nitroPurchase);
|
|
824
826
|
}
|
|
@@ -841,7 +843,7 @@ export const latestTransactionIOS = async sku => {
|
|
|
841
843
|
return null;
|
|
842
844
|
}
|
|
843
845
|
try {
|
|
844
|
-
const nitroPurchase = await
|
|
846
|
+
const nitroPurchase = await IAP.instance.latestTransactionIOS(sku);
|
|
845
847
|
if (nitroPurchase) {
|
|
846
848
|
return convertNitroPurchaseToPurchase(nitroPurchase);
|
|
847
849
|
}
|
|
@@ -863,7 +865,7 @@ export const getPendingTransactionsIOS = async () => {
|
|
|
863
865
|
return [];
|
|
864
866
|
}
|
|
865
867
|
try {
|
|
866
|
-
const nitroPurchases = await
|
|
868
|
+
const nitroPurchases = await IAP.instance.getPendingTransactionsIOS();
|
|
867
869
|
return nitroPurchases.map(convertNitroPurchaseToPurchase);
|
|
868
870
|
} catch (error) {
|
|
869
871
|
console.error('[getPendingTransactionsIOS] Failed:', error);
|
|
@@ -882,7 +884,7 @@ export const showManageSubscriptionsIOS = async () => {
|
|
|
882
884
|
return [];
|
|
883
885
|
}
|
|
884
886
|
try {
|
|
885
|
-
const nitroPurchases = await
|
|
887
|
+
const nitroPurchases = await IAP.instance.showManageSubscriptionsIOS();
|
|
886
888
|
return nitroPurchases.map(convertNitroPurchaseToPurchase);
|
|
887
889
|
} catch (error) {
|
|
888
890
|
console.error('[showManageSubscriptionsIOS] Failed:', error);
|
|
@@ -902,7 +904,7 @@ export const isEligibleForIntroOfferIOS = async groupID => {
|
|
|
902
904
|
return false;
|
|
903
905
|
}
|
|
904
906
|
try {
|
|
905
|
-
return await
|
|
907
|
+
return await IAP.instance.isEligibleForIntroOfferIOS(groupID);
|
|
906
908
|
} catch (error) {
|
|
907
909
|
console.error('[isEligibleForIntroOfferIOS] Failed:', error);
|
|
908
910
|
const errorJson = parseErrorStringToJsonObj(error);
|
|
@@ -920,7 +922,7 @@ export const getReceiptDataIOS = async () => {
|
|
|
920
922
|
throw new Error('getReceiptDataIOS is only available on iOS');
|
|
921
923
|
}
|
|
922
924
|
try {
|
|
923
|
-
return await
|
|
925
|
+
return await IAP.instance.getReceiptDataIOS();
|
|
924
926
|
} catch (error) {
|
|
925
927
|
console.error('[getReceiptDataIOS] Failed:', error);
|
|
926
928
|
const errorJson = parseErrorStringToJsonObj(error);
|
|
@@ -939,7 +941,7 @@ export const isTransactionVerifiedIOS = async sku => {
|
|
|
939
941
|
return false;
|
|
940
942
|
}
|
|
941
943
|
try {
|
|
942
|
-
return await
|
|
944
|
+
return await IAP.instance.isTransactionVerifiedIOS(sku);
|
|
943
945
|
} catch (error) {
|
|
944
946
|
console.error('[isTransactionVerifiedIOS] Failed:', error);
|
|
945
947
|
const errorJson = parseErrorStringToJsonObj(error);
|
|
@@ -958,7 +960,7 @@ export const getTransactionJwsIOS = async sku => {
|
|
|
958
960
|
return null;
|
|
959
961
|
}
|
|
960
962
|
try {
|
|
961
|
-
return await
|
|
963
|
+
return await IAP.instance.getTransactionJwsIOS(sku);
|
|
962
964
|
} catch (error) {
|
|
963
965
|
console.error('[getTransactionJwsIOS] Failed:', error);
|
|
964
966
|
const errorJson = parseErrorStringToJsonObj(error);
|
|
@@ -983,7 +985,7 @@ export const getStorefrontIOS = async () => {
|
|
|
983
985
|
}
|
|
984
986
|
try {
|
|
985
987
|
// Call the native method to get storefront
|
|
986
|
-
const storefront = await
|
|
988
|
+
const storefront = await IAP.instance.getStorefrontIOS();
|
|
987
989
|
return storefront;
|
|
988
990
|
} catch (error) {
|
|
989
991
|
console.error('Failed to get storefront:', error);
|
|
@@ -1001,7 +1003,7 @@ export const getStorefront = async () => {
|
|
|
1001
1003
|
if (Platform.OS === 'android') {
|
|
1002
1004
|
try {
|
|
1003
1005
|
// Optional since older builds may not have the method
|
|
1004
|
-
const result = await
|
|
1006
|
+
const result = await IAP.instance.getStorefrontAndroid?.();
|
|
1005
1007
|
return result ?? '';
|
|
1006
1008
|
} catch {
|
|
1007
1009
|
return '';
|
|
@@ -1016,7 +1018,7 @@ export const getStorefront = async () => {
|
|
|
1016
1018
|
*/
|
|
1017
1019
|
export const deepLinkToSubscriptions = async (options = {}) => {
|
|
1018
1020
|
if (Platform.OS === 'android') {
|
|
1019
|
-
await
|
|
1021
|
+
await IAP.instance.deepLinkToSubscriptionsAndroid?.({
|
|
1020
1022
|
skuAndroid: options.skuAndroid,
|
|
1021
1023
|
packageNameAndroid: options.packageNameAndroid
|
|
1022
1024
|
});
|
|
@@ -1025,7 +1027,7 @@ export const deepLinkToSubscriptions = async (options = {}) => {
|
|
|
1025
1027
|
// iOS: Use manage subscriptions sheet (ignore returned purchases for deeplink parity)
|
|
1026
1028
|
if (Platform.OS === 'ios') {
|
|
1027
1029
|
try {
|
|
1028
|
-
await
|
|
1030
|
+
await IAP.instance.showManageSubscriptionsIOS();
|
|
1029
1031
|
} catch {
|
|
1030
1032
|
// no-op
|
|
1031
1033
|
}
|
|
@@ -1059,7 +1061,7 @@ export const getAppTransactionIOS = async () => {
|
|
|
1059
1061
|
}
|
|
1060
1062
|
try {
|
|
1061
1063
|
// Call the native method to get app transaction
|
|
1062
|
-
const appTransaction = await
|
|
1064
|
+
const appTransaction = await IAP.instance.getAppTransactionIOS();
|
|
1063
1065
|
return appTransaction;
|
|
1064
1066
|
} catch (error) {
|
|
1065
1067
|
console.error('Failed to get app transaction:', error);
|