react-native-iap 8.3.0 → 8.4.0
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/.yarn/install-state.gz +0 -0
- package/ios/RNIapIos.m +1 -0
- package/ios/RNIapIos.swift +3 -1
- package/package.json +1 -1
- package/src/hooks/useIAP.d.ts +1 -0
- package/src/hooks/useIAP.js +2 -1
- package/src/hooks/withIAPContext.d.ts +1 -0
- package/src/hooks/withIAPContext.js +9 -1
- package/src/iap.d.ts +2 -1
- package/src/iap.js +13 -14
- package/src/types/index.d.ts +2 -2
package/.yarn/install-state.gz
CHANGED
|
Binary file
|
package/ios/RNIapIos.m
CHANGED
|
@@ -18,6 +18,7 @@ RCT_EXTERN_METHOD(getAvailableItems:
|
|
|
18
18
|
reject:(RCTPromiseRejectBlock)reject)
|
|
19
19
|
RCT_EXTERN_METHOD(buyProduct:
|
|
20
20
|
(NSString*)sku
|
|
21
|
+
appAccountToken:(NSString*)appAccountToken
|
|
21
22
|
andDangerouslyFinishTransactionAutomatically:(BOOL)andDangerouslyFinishTransactionAutomatically
|
|
22
23
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
23
24
|
reject:(RCTPromiseRejectBlock)reject)
|
package/ios/RNIapIos.swift
CHANGED
|
@@ -178,6 +178,7 @@ class RNIapIos: RCTEventEmitter, SKRequestDelegate, SKPaymentTransactionObserver
|
|
|
178
178
|
|
|
179
179
|
@objc public func buyProduct(
|
|
180
180
|
_ sku:String,
|
|
181
|
+
appAccountToken:String,
|
|
181
182
|
andDangerouslyFinishTransactionAutomatically: Bool,
|
|
182
183
|
resolve: @escaping RCTPromiseResolveBlock = { _ in },
|
|
183
184
|
reject: @escaping RCTPromiseRejectBlock = { _, _, _ in }
|
|
@@ -197,6 +198,7 @@ class RNIapIos: RCTEventEmitter, SKRequestDelegate, SKPaymentTransactionObserver
|
|
|
197
198
|
addPromise(forKey: prod.productIdentifier, resolve: resolve, reject: reject)
|
|
198
199
|
|
|
199
200
|
let payment = SKMutablePayment(product: prod)
|
|
201
|
+
payment.applicationUsername = appAccountToken
|
|
200
202
|
SKPaymentQueue.default().add(payment)
|
|
201
203
|
} else{
|
|
202
204
|
if hasListeners {
|
|
@@ -341,7 +343,7 @@ class RNIapIos: RCTEventEmitter, SKRequestDelegate, SKPaymentTransactionObserver
|
|
|
341
343
|
reject: @escaping RCTPromiseRejectBlock = { _, _, _ in }
|
|
342
344
|
) {
|
|
343
345
|
print("\n\n\n *** get promoted product. \n\n.")
|
|
344
|
-
resolve(promotedProduct )
|
|
346
|
+
resolve((promotedProduct != nil) ? getProductObject(promotedProduct!) : nil)
|
|
345
347
|
}
|
|
346
348
|
|
|
347
349
|
@objc public func buyPromotedProduct(
|
package/package.json
CHANGED
package/src/hooks/useIAP.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ declare type IAP_STATUS = {
|
|
|
9
9
|
availablePurchases: Purchase[];
|
|
10
10
|
currentPurchase?: Purchase;
|
|
11
11
|
currentPurchaseError?: PurchaseError;
|
|
12
|
+
initConnectionError?: Error;
|
|
12
13
|
finishTransaction: (purchase: Purchase, isConsumable?: boolean, developerPayloadAndroid?: string) => Promise<string | void>;
|
|
13
14
|
getAvailablePurchases: () => Promise<void>;
|
|
14
15
|
getPurchaseHistories: () => Promise<void>;
|
package/src/hooks/useIAP.js
CHANGED
|
@@ -39,7 +39,7 @@ import { useCallback } from 'react';
|
|
|
39
39
|
import { useIAPContext } from './withIAPContext';
|
|
40
40
|
export function useIAP() {
|
|
41
41
|
var _this = this;
|
|
42
|
-
var _a = useIAPContext(), connected = _a.connected, products = _a.products, promotedProductsIOS = _a.promotedProductsIOS, subscriptions = _a.subscriptions, purchaseHistories = _a.purchaseHistories, availablePurchases = _a.availablePurchases, currentPurchase = _a.currentPurchase, currentPurchaseError = _a.currentPurchaseError, setProducts = _a.setProducts, setSubscriptions = _a.setSubscriptions, setAvailablePurchases = _a.setAvailablePurchases, setPurchaseHistories = _a.setPurchaseHistories, setCurrentPurchase = _a.setCurrentPurchase, setCurrentPurchaseError = _a.setCurrentPurchaseError;
|
|
42
|
+
var _a = useIAPContext(), connected = _a.connected, products = _a.products, promotedProductsIOS = _a.promotedProductsIOS, subscriptions = _a.subscriptions, purchaseHistories = _a.purchaseHistories, availablePurchases = _a.availablePurchases, currentPurchase = _a.currentPurchase, currentPurchaseError = _a.currentPurchaseError, initConnectionError = _a.initConnectionError, setProducts = _a.setProducts, setSubscriptions = _a.setSubscriptions, setAvailablePurchases = _a.setAvailablePurchases, setPurchaseHistories = _a.setPurchaseHistories, setCurrentPurchase = _a.setCurrentPurchase, setCurrentPurchaseError = _a.setCurrentPurchaseError;
|
|
43
43
|
var getProducts = useCallback(function (skus) { return __awaiter(_this, void 0, void 0, function () {
|
|
44
44
|
var _a;
|
|
45
45
|
return __generator(this, function (_b) {
|
|
@@ -129,6 +129,7 @@ export function useIAP() {
|
|
|
129
129
|
availablePurchases: availablePurchases,
|
|
130
130
|
currentPurchase: currentPurchase,
|
|
131
131
|
currentPurchaseError: currentPurchaseError,
|
|
132
|
+
initConnectionError: initConnectionError,
|
|
132
133
|
finishTransaction: finishTransaction,
|
|
133
134
|
getProducts: getProducts,
|
|
134
135
|
getSubscriptions: getSubscriptions,
|
|
@@ -9,6 +9,7 @@ declare type IAPContextType = {
|
|
|
9
9
|
availablePurchases: Purchase[];
|
|
10
10
|
currentPurchase?: Purchase;
|
|
11
11
|
currentPurchaseError?: PurchaseError;
|
|
12
|
+
initConnectionError?: Error;
|
|
12
13
|
setProducts: (products: Product[]) => void;
|
|
13
14
|
setSubscriptions: (subscriptions: Subscription[]) => void;
|
|
14
15
|
setPurchaseHistories: (purchaseHistories: Purchase[]) => void;
|
|
@@ -68,6 +68,7 @@ export function withIAPContext(Component) {
|
|
|
68
68
|
var _f = useState([]), availablePurchases = _f[0], setAvailablePurchases = _f[1];
|
|
69
69
|
var _g = useState(), currentPurchase = _g[0], setCurrentPurchase = _g[1];
|
|
70
70
|
var _h = useState(), currentPurchaseError = _h[0], setCurrentPurchaseError = _h[1];
|
|
71
|
+
var _j = useState(), initConnectionError = _j[0], setInitConnectionError = _j[1];
|
|
71
72
|
var context = useMemo(function () { return ({
|
|
72
73
|
connected: connected,
|
|
73
74
|
products: products,
|
|
@@ -77,6 +78,7 @@ export function withIAPContext(Component) {
|
|
|
77
78
|
availablePurchases: availablePurchases,
|
|
78
79
|
currentPurchase: currentPurchase,
|
|
79
80
|
currentPurchaseError: currentPurchaseError,
|
|
81
|
+
initConnectionError: initConnectionError,
|
|
80
82
|
setProducts: setProducts,
|
|
81
83
|
setSubscriptions: setSubscriptions,
|
|
82
84
|
setPurchaseHistories: setPurchaseHistories,
|
|
@@ -92,6 +94,7 @@ export function withIAPContext(Component) {
|
|
|
92
94
|
availablePurchases,
|
|
93
95
|
currentPurchase,
|
|
94
96
|
currentPurchaseError,
|
|
97
|
+
initConnectionError,
|
|
95
98
|
setProducts,
|
|
96
99
|
setSubscriptions,
|
|
97
100
|
setPurchaseHistories,
|
|
@@ -100,7 +103,12 @@ export function withIAPContext(Component) {
|
|
|
100
103
|
setCurrentPurchaseError,
|
|
101
104
|
]);
|
|
102
105
|
useEffect(function () {
|
|
103
|
-
initConnection()
|
|
106
|
+
initConnection()
|
|
107
|
+
.then(function (value) {
|
|
108
|
+
setInitConnectionError(undefined);
|
|
109
|
+
setConnected(value);
|
|
110
|
+
})
|
|
111
|
+
.catch(setInitConnectionError);
|
|
104
112
|
}, []);
|
|
105
113
|
useEffect(function () {
|
|
106
114
|
if (!connected) {
|
package/src/iap.d.ts
CHANGED
|
@@ -44,12 +44,13 @@ export declare const getAvailablePurchases: () => Promise<(InAppPurchase | Subsc
|
|
|
44
44
|
/**
|
|
45
45
|
* Request a purchase for product. This will be received in `PurchaseUpdatedListener`.
|
|
46
46
|
* @param {string} sku The product's sku/ID
|
|
47
|
+
* @param {string} [appAccountToken] The purchaser's user ID
|
|
47
48
|
* @param {boolean} [andDangerouslyFinishTransactionAutomaticallyIOS] You should set this to false and call finishTransaction manually when you have delivered the purchased goods to the user. It defaults to true to provide backwards compatibility. Will default to false in version 4.0.0.
|
|
48
49
|
* @param {string} [obfuscatedAccountIdAndroid] Specifies an optional obfuscated string that is uniquely associated with the user's account in your app.
|
|
49
50
|
* @param {string} [obfuscatedProfileIdAndroid] Specifies an optional obfuscated string that is uniquely associated with the user's profile in your app.
|
|
50
51
|
* @returns {Promise<InAppPurchase>}
|
|
51
52
|
*/
|
|
52
|
-
export declare const requestPurchase: (sku: string, andDangerouslyFinishTransactionAutomaticallyIOS?: boolean, obfuscatedAccountIdAndroid?: string | undefined, obfuscatedProfileIdAndroid?: string | undefined) => Promise<InAppPurchase>;
|
|
53
|
+
export declare const requestPurchase: (sku: string, appAccountToken: string, andDangerouslyFinishTransactionAutomaticallyIOS?: boolean, obfuscatedAccountIdAndroid?: string | undefined, obfuscatedProfileIdAndroid?: string | undefined) => Promise<InAppPurchase>;
|
|
53
54
|
/**
|
|
54
55
|
* Request a purchase for product. This will be received in `PurchaseUpdatedListener`.
|
|
55
56
|
* @param {string} [sku] The product's sku/ID
|
package/src/iap.js
CHANGED
|
@@ -135,13 +135,13 @@ var fillProductsAdditionalData = function (products) { return __awaiter(void 0,
|
|
|
135
135
|
export var getProducts = function (skus) {
|
|
136
136
|
return (Platform.select({
|
|
137
137
|
ios: function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
138
|
-
var items;
|
|
139
138
|
return __generator(this, function (_a) {
|
|
140
139
|
switch (_a.label) {
|
|
141
|
-
case 0: return [4 /*yield*/, getIosModule()
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
140
|
+
case 0: return [4 /*yield*/, getIosModule()
|
|
141
|
+
.getItems(skus)
|
|
142
|
+
.filter(function (item) { return skus.includes(item.productId); })
|
|
143
|
+
.filter(function (item) { return item.type === 'iap'; })];
|
|
144
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
145
145
|
}
|
|
146
146
|
});
|
|
147
147
|
}); },
|
|
@@ -166,15 +166,13 @@ export var getProducts = function (skus) {
|
|
|
166
166
|
export var getSubscriptions = function (skus) {
|
|
167
167
|
return (Platform.select({
|
|
168
168
|
ios: function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
169
|
-
var items;
|
|
170
169
|
return __generator(this, function (_a) {
|
|
171
170
|
switch (_a.label) {
|
|
172
|
-
case 0: return [4 /*yield*/, getIosModule()
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
})];
|
|
171
|
+
case 0: return [4 /*yield*/, getIosModule()
|
|
172
|
+
.getItems(skus)
|
|
173
|
+
.filter(function (item) { return skus.includes(item.productId); })
|
|
174
|
+
.filter(function (item) { return item.type === 'subs'; })];
|
|
175
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
178
176
|
}
|
|
179
177
|
});
|
|
180
178
|
}); },
|
|
@@ -256,12 +254,13 @@ export var getAvailablePurchases = function () {
|
|
|
256
254
|
/**
|
|
257
255
|
* Request a purchase for product. This will be received in `PurchaseUpdatedListener`.
|
|
258
256
|
* @param {string} sku The product's sku/ID
|
|
257
|
+
* @param {string} [appAccountToken] The purchaser's user ID
|
|
259
258
|
* @param {boolean} [andDangerouslyFinishTransactionAutomaticallyIOS] You should set this to false and call finishTransaction manually when you have delivered the purchased goods to the user. It defaults to true to provide backwards compatibility. Will default to false in version 4.0.0.
|
|
260
259
|
* @param {string} [obfuscatedAccountIdAndroid] Specifies an optional obfuscated string that is uniquely associated with the user's account in your app.
|
|
261
260
|
* @param {string} [obfuscatedProfileIdAndroid] Specifies an optional obfuscated string that is uniquely associated with the user's profile in your app.
|
|
262
261
|
* @returns {Promise<InAppPurchase>}
|
|
263
262
|
*/
|
|
264
|
-
export var requestPurchase = function (sku, andDangerouslyFinishTransactionAutomaticallyIOS, obfuscatedAccountIdAndroid, obfuscatedProfileIdAndroid) {
|
|
263
|
+
export var requestPurchase = function (sku, appAccountToken, andDangerouslyFinishTransactionAutomaticallyIOS, obfuscatedAccountIdAndroid, obfuscatedProfileIdAndroid) {
|
|
265
264
|
if (andDangerouslyFinishTransactionAutomaticallyIOS === void 0) { andDangerouslyFinishTransactionAutomaticallyIOS = false; }
|
|
266
265
|
if (obfuscatedAccountIdAndroid === void 0) { obfuscatedAccountIdAndroid = undefined; }
|
|
267
266
|
if (obfuscatedProfileIdAndroid === void 0) { obfuscatedProfileIdAndroid = undefined; }
|
|
@@ -274,7 +273,7 @@ export var requestPurchase = function (sku, andDangerouslyFinishTransactionAutom
|
|
|
274
273
|
// eslint-disable-next-line max-len
|
|
275
274
|
'You are dangerously allowing react-native-iap to finish your transaction automatically. You should set andDangerouslyFinishTransactionAutomatically to false when calling requestPurchase and call finishTransaction manually when you have delivered the purchased goods to the user. It defaults to true to provide backwards compatibility. Will default to false in version 4.0.0.');
|
|
276
275
|
}
|
|
277
|
-
return [2 /*return*/, getIosModule().buyProduct(sku, andDangerouslyFinishTransactionAutomaticallyIOS)];
|
|
276
|
+
return [2 /*return*/, getIosModule().buyProduct(sku, appAccountToken, andDangerouslyFinishTransactionAutomaticallyIOS)];
|
|
278
277
|
});
|
|
279
278
|
}); },
|
|
280
279
|
android: function () { return __awaiter(void 0, void 0, void 0, function () {
|
package/src/types/index.d.ts
CHANGED
|
@@ -35,6 +35,8 @@ export declare enum InstallSourceAndroid {
|
|
|
35
35
|
AMAZON = 2
|
|
36
36
|
}
|
|
37
37
|
export interface ProductCommon {
|
|
38
|
+
type: 'subs' | 'sub' | 'inapp' | 'iap';
|
|
39
|
+
productId: string;
|
|
38
40
|
title: string;
|
|
39
41
|
description: string;
|
|
40
42
|
price: string;
|
|
@@ -96,11 +98,9 @@ export interface Discount {
|
|
|
96
98
|
}
|
|
97
99
|
export interface Product extends ProductCommon {
|
|
98
100
|
type: 'inapp' | 'iap';
|
|
99
|
-
productId: string;
|
|
100
101
|
}
|
|
101
102
|
export interface Subscription extends ProductCommon {
|
|
102
103
|
type: 'subs' | 'sub';
|
|
103
|
-
productId: string;
|
|
104
104
|
discounts?: Discount[];
|
|
105
105
|
introductoryPrice?: string;
|
|
106
106
|
introductoryPriceAsAmountIOS?: string;
|