react-native-iap 8.3.0 → 8.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -2
- package/ios/RNIapIos.m +2 -0
- package/ios/RNIapIos.swift +7 -7
- package/package.json +1 -2
- 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 -9
- package/src/types/index.d.ts +10 -2
- package/.yarn/install-state.gz +0 -0
- package/.yarn/releases/yarn-3.2.0.cjs +0 -785
- package/.yarnrc.yml +0 -3
- package/ios/RNIapQueue.swift +0 -36
package/README.md
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
# 
|
|
2
2
|
|
|
3
3
|
[](https://npmjs.org/package/react-native-iap)
|
|
4
|
-
|
|
4
|
+
[](https://npmjs.org/package/react-native-iap)
|
|
5
|
+
|
|
5
6
|
[](https://npmjs.org/package/react-native-iap)
|
|
6
7
|
[](https://github.com/dooboolab/react-native-iap/actions/workflows/ci.yml)
|
|
7
8
|
[](https://github.com/dooboolab/react-native-iap/actions/workflows/deploy-document.yml)
|
|
@@ -20,7 +21,11 @@ Published in [website](https://react-native-iap.dooboolab.com).
|
|
|
20
21
|
|
|
21
22
|
## Announcement
|
|
22
23
|
|
|
23
|
-
-
|
|
24
|
+
- Version `9.0.0` is currently in release candidate. The module migrates android sdk to [play billing library v5](https://qonversion.io/blog/google-play-billing-library-5-0) and iOS sdk to [storekit2](https://developer.apple.com/videos/play/wwdc2021/10114). Our core maintainer [andresesfm](https://github.com/andresesfm) is working hard on this. Please [fund the project](https://opencollective.com/react-native-iap) if you wish to support his effort. The fund goes to maintainers. To try the earlier version please use the `next` package.
|
|
25
|
+
|
|
26
|
+
```
|
|
27
|
+
yarn add react-native-iap@next
|
|
28
|
+
```
|
|
24
29
|
|
|
25
30
|
- Version `8.0.0` has finally landed in Jan 28th. Since this is early release, please use it with caution 🚧. We recommend user to use `>=8.0.0` with react-native `>=0.65.1`. The `next` package is no longer updated until we organize the roadmap for `9.0.0`.
|
|
26
31
|
|
package/ios/RNIapIos.m
CHANGED
|
@@ -18,7 +18,9 @@ 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
|
|
23
|
+
applicationUsername:(NSString)applicationUsername
|
|
22
24
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
23
25
|
reject:(RCTPromiseRejectBlock)reject)
|
|
24
26
|
RCT_EXTERN_METHOD(buyProductWithOffer:
|
package/ios/RNIapIos.swift
CHANGED
|
@@ -47,6 +47,7 @@ class RNIapIos: RCTEventEmitter, SKRequestDelegate, SKPaymentTransactionObserver
|
|
|
47
47
|
myQueue = DispatchQueue(label: "reject")
|
|
48
48
|
validProducts = [SKProduct]()
|
|
49
49
|
super.init()
|
|
50
|
+
SKPaymentQueue.default().add(self)
|
|
50
51
|
}
|
|
51
52
|
|
|
52
53
|
deinit {
|
|
@@ -132,12 +133,6 @@ class RNIapIos: RCTEventEmitter, SKRequestDelegate, SKPaymentTransactionObserver
|
|
|
132
133
|
_ resolve: @escaping RCTPromiseResolveBlock = { _ in },
|
|
133
134
|
reject: @escaping RCTPromiseRejectBlock = { _, _, _ in }
|
|
134
135
|
) {
|
|
135
|
-
SKPaymentQueue.default().remove(RNIapQueue.shared)
|
|
136
|
-
if let queue = RNIapQueue.shared.queue, let payment = RNIapQueue.shared.payment, let product = RNIapQueue.shared.product {
|
|
137
|
-
let val = paymentQueue(queue, shouldAddStorePayment: payment,for: product)
|
|
138
|
-
print("Promoted product response \(val)")
|
|
139
|
-
}
|
|
140
|
-
SKPaymentQueue.default().add(self)
|
|
141
136
|
let canMakePayments = SKPaymentQueue.canMakePayments()
|
|
142
137
|
resolve(NSNumber(value: canMakePayments))
|
|
143
138
|
}
|
|
@@ -179,6 +174,7 @@ class RNIapIos: RCTEventEmitter, SKRequestDelegate, SKPaymentTransactionObserver
|
|
|
179
174
|
@objc public func buyProduct(
|
|
180
175
|
_ sku:String,
|
|
181
176
|
andDangerouslyFinishTransactionAutomatically: Bool,
|
|
177
|
+
applicationUsername:String?,
|
|
182
178
|
resolve: @escaping RCTPromiseResolveBlock = { _ in },
|
|
183
179
|
reject: @escaping RCTPromiseRejectBlock = { _, _, _ in }
|
|
184
180
|
) {
|
|
@@ -197,6 +193,10 @@ class RNIapIos: RCTEventEmitter, SKRequestDelegate, SKPaymentTransactionObserver
|
|
|
197
193
|
addPromise(forKey: prod.productIdentifier, resolve: resolve, reject: reject)
|
|
198
194
|
|
|
199
195
|
let payment = SKMutablePayment(product: prod)
|
|
196
|
+
|
|
197
|
+
if (applicationUsername != nil) {
|
|
198
|
+
payment.applicationUsername = applicationUsername
|
|
199
|
+
}
|
|
200
200
|
SKPaymentQueue.default().add(payment)
|
|
201
201
|
} else{
|
|
202
202
|
if hasListeners {
|
|
@@ -341,7 +341,7 @@ class RNIapIos: RCTEventEmitter, SKRequestDelegate, SKPaymentTransactionObserver
|
|
|
341
341
|
reject: @escaping RCTPromiseRejectBlock = { _, _, _ in }
|
|
342
342
|
) {
|
|
343
343
|
print("\n\n\n *** get promoted product. \n\n.")
|
|
344
|
-
resolve(promotedProduct )
|
|
344
|
+
resolve((promotedProduct != nil) ? getProductObject(promotedProduct!) : nil)
|
|
345
345
|
}
|
|
346
346
|
|
|
347
347
|
@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} [applicationUsername] 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, applicationUsername?: 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,15 @@ 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
|
|
138
|
+
var products;
|
|
139
139
|
return __generator(this, function (_a) {
|
|
140
140
|
switch (_a.label) {
|
|
141
141
|
case 0: return [4 /*yield*/, getIosModule().getItems(skus)];
|
|
142
142
|
case 1:
|
|
143
|
-
|
|
144
|
-
return [2 /*return*/,
|
|
143
|
+
products = _a.sent();
|
|
144
|
+
return [2 /*return*/, products.filter(function (item) {
|
|
145
|
+
return skus.includes(item.productId) && item.type === 'iap';
|
|
146
|
+
})];
|
|
145
147
|
}
|
|
146
148
|
});
|
|
147
149
|
}); },
|
|
@@ -166,14 +168,14 @@ export var getProducts = function (skus) {
|
|
|
166
168
|
export var getSubscriptions = function (skus) {
|
|
167
169
|
return (Platform.select({
|
|
168
170
|
ios: function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
169
|
-
var
|
|
171
|
+
var subscriptions;
|
|
170
172
|
return __generator(this, function (_a) {
|
|
171
173
|
switch (_a.label) {
|
|
172
174
|
case 0: return [4 /*yield*/, getIosModule().getItems(skus)];
|
|
173
175
|
case 1:
|
|
174
|
-
|
|
175
|
-
return [2 /*return*/,
|
|
176
|
-
return skus.includes(item.productId);
|
|
176
|
+
subscriptions = _a.sent();
|
|
177
|
+
return [2 /*return*/, subscriptions.filter(function (item) {
|
|
178
|
+
return skus.includes(item.productId) && item.type === 'subs';
|
|
177
179
|
})];
|
|
178
180
|
}
|
|
179
181
|
});
|
|
@@ -256,15 +258,17 @@ export var getAvailablePurchases = function () {
|
|
|
256
258
|
/**
|
|
257
259
|
* Request a purchase for product. This will be received in `PurchaseUpdatedListener`.
|
|
258
260
|
* @param {string} sku The product's sku/ID
|
|
261
|
+
* @param {string} [applicationUsername] The purchaser's user ID
|
|
259
262
|
* @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
263
|
* @param {string} [obfuscatedAccountIdAndroid] Specifies an optional obfuscated string that is uniquely associated with the user's account in your app.
|
|
261
264
|
* @param {string} [obfuscatedProfileIdAndroid] Specifies an optional obfuscated string that is uniquely associated with the user's profile in your app.
|
|
262
265
|
* @returns {Promise<InAppPurchase>}
|
|
263
266
|
*/
|
|
264
|
-
export var requestPurchase = function (sku, andDangerouslyFinishTransactionAutomaticallyIOS, obfuscatedAccountIdAndroid, obfuscatedProfileIdAndroid) {
|
|
267
|
+
export var requestPurchase = function (sku, appAccountToken, andDangerouslyFinishTransactionAutomaticallyIOS, obfuscatedAccountIdAndroid, obfuscatedProfileIdAndroid, applicationUsername) {
|
|
265
268
|
if (andDangerouslyFinishTransactionAutomaticallyIOS === void 0) { andDangerouslyFinishTransactionAutomaticallyIOS = false; }
|
|
266
269
|
if (obfuscatedAccountIdAndroid === void 0) { obfuscatedAccountIdAndroid = undefined; }
|
|
267
270
|
if (obfuscatedProfileIdAndroid === void 0) { obfuscatedProfileIdAndroid = undefined; }
|
|
271
|
+
if (applicationUsername === void 0) { applicationUsername = undefined; }
|
|
268
272
|
return (Platform.select({
|
|
269
273
|
ios: function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
270
274
|
return __generator(this, function (_a) {
|
|
@@ -274,7 +278,7 @@ export var requestPurchase = function (sku, andDangerouslyFinishTransactionAutom
|
|
|
274
278
|
// eslint-disable-next-line max-len
|
|
275
279
|
'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
280
|
}
|
|
277
|
-
return [2 /*return*/, getIosModule().buyProduct(sku, andDangerouslyFinishTransactionAutomaticallyIOS)];
|
|
281
|
+
return [2 /*return*/, getIosModule().buyProduct(sku, andDangerouslyFinishTransactionAutomaticallyIOS, applicationUsername)];
|
|
278
282
|
});
|
|
279
283
|
}); },
|
|
280
284
|
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;
|
|
@@ -115,3 +115,11 @@ export interface Subscription extends ProductCommon {
|
|
|
115
115
|
subscriptionPeriodAndroid?: string;
|
|
116
116
|
freeTrialPeriodAndroid?: string;
|
|
117
117
|
}
|
|
118
|
+
export interface RequestPurchase {
|
|
119
|
+
sku: string;
|
|
120
|
+
andDangerouslyFinishTransactionAutomaticallyIOS: boolean;
|
|
121
|
+
applicationUsername?: string;
|
|
122
|
+
obfuscatedAccountIdAndroid: string | undefined;
|
|
123
|
+
obfuscatedProfileIdAndroid: string | undefined;
|
|
124
|
+
selectedOfferIndex: number;
|
|
125
|
+
}
|
package/.yarn/install-state.gz
DELETED
|
Binary file
|