react-native-iap 8.4.0 → 8.5.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 +7 -2
- package/ios/RNIapIos.m +1 -1
- package/ios/RNIapIos.swift +6 -8
- package/package.json +1 -2
- package/src/iap.d.ts +5 -4
- package/src/iap.js +22 -23
- package/src/types/index.d.ts +12 -0
- 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,8 +18,8 @@ RCT_EXTERN_METHOD(getAvailableItems:
|
|
|
18
18
|
reject:(RCTPromiseRejectBlock)reject)
|
|
19
19
|
RCT_EXTERN_METHOD(buyProduct:
|
|
20
20
|
(NSString*)sku
|
|
21
|
-
appAccountToken:(NSString*)appAccountToken
|
|
22
21
|
andDangerouslyFinishTransactionAutomatically:(BOOL)andDangerouslyFinishTransactionAutomatically
|
|
22
|
+
applicationUsername:(NSString*)applicationUsername
|
|
23
23
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
24
24
|
reject:(RCTPromiseRejectBlock)reject)
|
|
25
25
|
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
|
}
|
|
@@ -178,8 +173,8 @@ class RNIapIos: RCTEventEmitter, SKRequestDelegate, SKPaymentTransactionObserver
|
|
|
178
173
|
|
|
179
174
|
@objc public func buyProduct(
|
|
180
175
|
_ sku:String,
|
|
181
|
-
appAccountToken:String,
|
|
182
176
|
andDangerouslyFinishTransactionAutomatically: Bool,
|
|
177
|
+
applicationUsername:String?,
|
|
183
178
|
resolve: @escaping RCTPromiseResolveBlock = { _ in },
|
|
184
179
|
reject: @escaping RCTPromiseRejectBlock = { _, _, _ in }
|
|
185
180
|
) {
|
|
@@ -198,7 +193,10 @@ class RNIapIos: RCTEventEmitter, SKRequestDelegate, SKPaymentTransactionObserver
|
|
|
198
193
|
addPromise(forKey: prod.productIdentifier, resolve: resolve, reject: reject)
|
|
199
194
|
|
|
200
195
|
let payment = SKMutablePayment(product: prod)
|
|
201
|
-
|
|
196
|
+
|
|
197
|
+
if (applicationUsername != nil) {
|
|
198
|
+
payment.applicationUsername = applicationUsername
|
|
199
|
+
}
|
|
202
200
|
SKPaymentQueue.default().add(payment)
|
|
203
201
|
} else{
|
|
204
202
|
if hasListeners {
|
package/package.json
CHANGED
package/src/iap.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import * as Amazon from './types/amazon';
|
|
|
2
2
|
import * as Android from './types/android';
|
|
3
3
|
import * as Apple from './types/apple';
|
|
4
4
|
import { EmitterSubscription } from 'react-native';
|
|
5
|
-
import { InAppPurchase, InstallSourceAndroid, Product, ProductPurchase,
|
|
5
|
+
import { InAppPurchase, InstallSourceAndroid, Product, ProductPurchase, PurchaseError, PurchaseResult, RequestPurchase, RequestSubscription, Subscription, SubscriptionPurchase } from './types';
|
|
6
6
|
export declare const getInstallSourceAndroid: () => InstallSourceAndroid;
|
|
7
7
|
/**
|
|
8
8
|
* Init module for purchase flow. Required on Android. In ios it will check whether user canMakePayment.
|
|
@@ -44,16 +44,17 @@ 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} [
|
|
47
|
+
* @param {string} [applicationUsername] The purchaser's user ID
|
|
48
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.
|
|
49
49
|
* @param {string} [obfuscatedAccountIdAndroid] Specifies an optional obfuscated string that is uniquely associated with the user's account in your app.
|
|
50
50
|
* @param {string} [obfuscatedProfileIdAndroid] Specifies an optional obfuscated string that is uniquely associated with the user's profile in your app.
|
|
51
51
|
* @returns {Promise<InAppPurchase>}
|
|
52
52
|
*/
|
|
53
|
-
export declare const requestPurchase: (sku
|
|
53
|
+
export declare const requestPurchase: ({ sku, andDangerouslyFinishTransactionAutomaticallyIOS, obfuscatedAccountIdAndroid, obfuscatedProfileIdAndroid, applicationUsername, }: RequestPurchase) => Promise<InAppPurchase>;
|
|
54
54
|
/**
|
|
55
55
|
* Request a purchase for product. This will be received in `PurchaseUpdatedListener`.
|
|
56
56
|
* @param {string} [sku] The product's sku/ID
|
|
57
|
+
* @param {string} [applicationUsername] The purchaser's user ID
|
|
57
58
|
* @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.
|
|
58
59
|
* @param {string} [purchaseTokenAndroid] purchaseToken that the user is upgrading or downgrading from (Android).
|
|
59
60
|
* @param {ProrationModesAndroid} [prorationModeAndroid] UNKNOWN_SUBSCRIPTION_UPGRADE_DOWNGRADE_POLICY, IMMEDIATE_WITH_TIME_PRORATION, IMMEDIATE_AND_CHARGE_PRORATED_PRICE, IMMEDIATE_WITHOUT_PRORATION, DEFERRED
|
|
@@ -61,7 +62,7 @@ export declare const requestPurchase: (sku: string, appAccountToken: string, and
|
|
|
61
62
|
* @param {string} [obfuscatedProfileIdAndroid] Specifies an optional obfuscated string that is uniquely associated with the user's profile in your app.
|
|
62
63
|
* @returns {Promise<SubscriptionPurchase | null>} Promise resolves to null when using proratioModesAndroid=DEFERRED, and to a SubscriptionPurchase otherwise
|
|
63
64
|
*/
|
|
64
|
-
export declare const requestSubscription: (sku
|
|
65
|
+
export declare const requestSubscription: ({ sku, andDangerouslyFinishTransactionAutomaticallyIOS, purchaseTokenAndroid, prorationModeAndroid, obfuscatedAccountIdAndroid, obfuscatedProfileIdAndroid, applicationUsername, }: RequestSubscription) => Promise<SubscriptionPurchase | null>;
|
|
65
66
|
/**
|
|
66
67
|
* Request a purchase for product. This will be received in `PurchaseUpdatedListener`.
|
|
67
68
|
* @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 products;
|
|
138
139
|
return __generator(this, function (_a) {
|
|
139
140
|
switch (_a.label) {
|
|
140
|
-
case 0: return [4 /*yield*/, getIosModule()
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
141
|
+
case 0: return [4 /*yield*/, getIosModule().getItems(skus)];
|
|
142
|
+
case 1:
|
|
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,13 +168,15 @@ 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 () {
|
|
171
|
+
var subscriptions;
|
|
169
172
|
return __generator(this, function (_a) {
|
|
170
173
|
switch (_a.label) {
|
|
171
|
-
case 0: return [4 /*yield*/, getIosModule()
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
174
|
+
case 0: return [4 /*yield*/, getIosModule().getItems(skus)];
|
|
175
|
+
case 1:
|
|
176
|
+
subscriptions = _a.sent();
|
|
177
|
+
return [2 /*return*/, subscriptions.filter(function (item) {
|
|
178
|
+
return skus.includes(item.productId) && item.type === 'subs';
|
|
179
|
+
})];
|
|
176
180
|
}
|
|
177
181
|
});
|
|
178
182
|
}); },
|
|
@@ -254,16 +258,14 @@ export var getAvailablePurchases = function () {
|
|
|
254
258
|
/**
|
|
255
259
|
* Request a purchase for product. This will be received in `PurchaseUpdatedListener`.
|
|
256
260
|
* @param {string} sku The product's sku/ID
|
|
257
|
-
* @param {string} [
|
|
261
|
+
* @param {string} [applicationUsername] The purchaser's user ID
|
|
258
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.
|
|
259
263
|
* @param {string} [obfuscatedAccountIdAndroid] Specifies an optional obfuscated string that is uniquely associated with the user's account in your app.
|
|
260
264
|
* @param {string} [obfuscatedProfileIdAndroid] Specifies an optional obfuscated string that is uniquely associated with the user's profile in your app.
|
|
261
265
|
* @returns {Promise<InAppPurchase>}
|
|
262
266
|
*/
|
|
263
|
-
export var requestPurchase = function (
|
|
264
|
-
|
|
265
|
-
if (obfuscatedAccountIdAndroid === void 0) { obfuscatedAccountIdAndroid = undefined; }
|
|
266
|
-
if (obfuscatedProfileIdAndroid === void 0) { obfuscatedProfileIdAndroid = undefined; }
|
|
267
|
+
export var requestPurchase = function (_a) {
|
|
268
|
+
var sku = _a.sku, _b = _a.andDangerouslyFinishTransactionAutomaticallyIOS, andDangerouslyFinishTransactionAutomaticallyIOS = _b === void 0 ? false : _b, _c = _a.obfuscatedAccountIdAndroid, obfuscatedAccountIdAndroid = _c === void 0 ? undefined : _c, _d = _a.obfuscatedProfileIdAndroid, obfuscatedProfileIdAndroid = _d === void 0 ? undefined : _d, _e = _a.applicationUsername, applicationUsername = _e === void 0 ? undefined : _e;
|
|
267
269
|
return (Platform.select({
|
|
268
270
|
ios: function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
269
271
|
return __generator(this, function (_a) {
|
|
@@ -273,7 +275,7 @@ export var requestPurchase = function (sku, appAccountToken, andDangerouslyFinis
|
|
|
273
275
|
// eslint-disable-next-line max-len
|
|
274
276
|
'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.');
|
|
275
277
|
}
|
|
276
|
-
return [2 /*return*/, getIosModule().buyProduct(sku,
|
|
278
|
+
return [2 /*return*/, getIosModule().buyProduct(sku, andDangerouslyFinishTransactionAutomaticallyIOS, applicationUsername)];
|
|
277
279
|
});
|
|
278
280
|
}); },
|
|
279
281
|
android: function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
@@ -286,6 +288,7 @@ export var requestPurchase = function (sku, appAccountToken, andDangerouslyFinis
|
|
|
286
288
|
/**
|
|
287
289
|
* Request a purchase for product. This will be received in `PurchaseUpdatedListener`.
|
|
288
290
|
* @param {string} [sku] The product's sku/ID
|
|
291
|
+
* @param {string} [applicationUsername] The purchaser's user ID
|
|
289
292
|
* @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.
|
|
290
293
|
* @param {string} [purchaseTokenAndroid] purchaseToken that the user is upgrading or downgrading from (Android).
|
|
291
294
|
* @param {ProrationModesAndroid} [prorationModeAndroid] UNKNOWN_SUBSCRIPTION_UPGRADE_DOWNGRADE_POLICY, IMMEDIATE_WITH_TIME_PRORATION, IMMEDIATE_AND_CHARGE_PRORATED_PRICE, IMMEDIATE_WITHOUT_PRORATION, DEFERRED
|
|
@@ -293,12 +296,8 @@ export var requestPurchase = function (sku, appAccountToken, andDangerouslyFinis
|
|
|
293
296
|
* @param {string} [obfuscatedProfileIdAndroid] Specifies an optional obfuscated string that is uniquely associated with the user's profile in your app.
|
|
294
297
|
* @returns {Promise<SubscriptionPurchase | null>} Promise resolves to null when using proratioModesAndroid=DEFERRED, and to a SubscriptionPurchase otherwise
|
|
295
298
|
*/
|
|
296
|
-
export var requestSubscription = function (
|
|
297
|
-
|
|
298
|
-
if (purchaseTokenAndroid === void 0) { purchaseTokenAndroid = undefined; }
|
|
299
|
-
if (prorationModeAndroid === void 0) { prorationModeAndroid = -1; }
|
|
300
|
-
if (obfuscatedAccountIdAndroid === void 0) { obfuscatedAccountIdAndroid = undefined; }
|
|
301
|
-
if (obfuscatedProfileIdAndroid === void 0) { obfuscatedProfileIdAndroid = undefined; }
|
|
299
|
+
export var requestSubscription = function (_a) {
|
|
300
|
+
var sku = _a.sku, _b = _a.andDangerouslyFinishTransactionAutomaticallyIOS, andDangerouslyFinishTransactionAutomaticallyIOS = _b === void 0 ? false : _b, _c = _a.purchaseTokenAndroid, purchaseTokenAndroid = _c === void 0 ? undefined : _c, _d = _a.prorationModeAndroid, prorationModeAndroid = _d === void 0 ? -1 : _d, _e = _a.obfuscatedAccountIdAndroid, obfuscatedAccountIdAndroid = _e === void 0 ? undefined : _e, _f = _a.obfuscatedProfileIdAndroid, obfuscatedProfileIdAndroid = _f === void 0 ? undefined : _f, _g = _a.applicationUsername, applicationUsername = _g === void 0 ? undefined : _g;
|
|
302
301
|
return (Platform.select({
|
|
303
302
|
ios: function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
304
303
|
return __generator(this, function (_a) {
|
|
@@ -308,7 +307,7 @@ export var requestSubscription = function (sku, andDangerouslyFinishTransactionA
|
|
|
308
307
|
// eslint-disable-next-line max-len
|
|
309
308
|
'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.');
|
|
310
309
|
}
|
|
311
|
-
return [2 /*return*/, getIosModule().buyProduct(sku, andDangerouslyFinishTransactionAutomaticallyIOS)];
|
|
310
|
+
return [2 /*return*/, getIosModule().buyProduct(sku, andDangerouslyFinishTransactionAutomaticallyIOS, applicationUsername)];
|
|
312
311
|
});
|
|
313
312
|
}); },
|
|
314
313
|
android: function () { return __awaiter(void 0, void 0, void 0, function () {
|
package/src/types/index.d.ts
CHANGED
|
@@ -115,3 +115,15 @@ 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
|
+
}
|
|
126
|
+
export interface RequestSubscription extends RequestPurchase {
|
|
127
|
+
purchaseTokenAndroid: string | undefined;
|
|
128
|
+
prorationModeAndroid: ProrationModesAndroid;
|
|
129
|
+
}
|
package/.yarn/install-state.gz
DELETED
|
Binary file
|