react-native-iap 9.0.0-beta → 9.0.0-beta2
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/android/src/play/java/com/dooboolab/RNIap/RNIapModule.kt +1 -1
- package/android/src/play/java/com/dooboolab/RNIap/RNIapModuleV4.kt +1 -1
- package/ios/RNIapIos.m +1 -0
- package/ios/RNIapIos.swift +6 -8
- package/package.json +1 -1
- package/src/iap.d.ts +6 -4
- package/src/iap.js +10 -16
- package/src/types/index.d.ts +16 -0
- package/ios/RNIapQueue.swift +0 -36
package/.yarn/install-state.gz
CHANGED
|
Binary file
|
|
@@ -200,7 +200,7 @@ class RNIapModule(
|
|
|
200
200
|
val skuList = ArrayList<QueryProductDetailsParams.Product>()
|
|
201
201
|
for (i in 0 until skuArr.size()) {
|
|
202
202
|
if (skuArr.getType(i) == ReadableType.String) {
|
|
203
|
-
val sku = skuArr.getString(i)
|
|
203
|
+
val sku: String = skuArr.getString(i)
|
|
204
204
|
skuList.add(
|
|
205
205
|
QueryProductDetailsParams.Product.newBuilder().setProductId(sku)
|
|
206
206
|
.setProductType(type).build()
|
|
@@ -196,7 +196,7 @@ class RNIapModuleV4(
|
|
|
196
196
|
val skuList = ArrayList<String>()
|
|
197
197
|
for (i in 0 until skuArr.size()) {
|
|
198
198
|
if (skuArr.getType(i) == ReadableType.String) {
|
|
199
|
-
val sku = skuArr.getString(i)
|
|
199
|
+
val sku: String = skuArr.getString(i)
|
|
200
200
|
skuList.add(sku)
|
|
201
201
|
}
|
|
202
202
|
}
|
package/ios/RNIapIos.m
CHANGED
|
@@ -20,6 +20,7 @@ RCT_EXTERN_METHOD(buyProduct:
|
|
|
20
20
|
(NSString*)sku
|
|
21
21
|
appAccountToken:(NSString*)appAccountToken
|
|
22
22
|
andDangerouslyFinishTransactionAutomatically:(BOOL)andDangerouslyFinishTransactionAutomatically
|
|
23
|
+
applicationUsername:(NSString)applicationUsername
|
|
23
24
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
24
25
|
reject:(RCTPromiseRejectBlock)reject)
|
|
25
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
|
}
|
|
@@ -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,8 +2,9 @@ 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
|
+
export declare const setAndroidNativeModule: (nativeModule: any) => void;
|
|
7
8
|
/**
|
|
8
9
|
* Init module for purchase flow. Required on Android. In ios it will check whether user canMakePayment.
|
|
9
10
|
* @returns {Promise<boolean>}
|
|
@@ -44,13 +45,13 @@ export declare const getAvailablePurchases: () => Promise<(InAppPurchase | Subsc
|
|
|
44
45
|
/**
|
|
45
46
|
* Request a purchase for product. This will be received in `PurchaseUpdatedListener`.
|
|
46
47
|
* @param {string} sku The product's sku/ID
|
|
47
|
-
* @param {string} [
|
|
48
|
+
* @param {string} [applicationUsername] The purchaser's user ID
|
|
48
49
|
* @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
50
|
* @param {string} [obfuscatedAccountIdAndroid] Specifies an optional obfuscated string that is uniquely associated with the user's account in your app.
|
|
50
51
|
* @param {string} [obfuscatedProfileIdAndroid] Specifies an optional obfuscated string that is uniquely associated with the user's profile in your app.
|
|
51
52
|
* @returns {Promise<InAppPurchase>}
|
|
52
53
|
*/
|
|
53
|
-
export declare const requestPurchase: (sku
|
|
54
|
+
export declare const requestPurchase: ({ sku, andDangerouslyFinishTransactionAutomaticallyIOS, applicationUsername, obfuscatedAccountIdAndroid, obfuscatedProfileIdAndroid, }: RequestPurchase) => Promise<InAppPurchase>;
|
|
54
55
|
/**
|
|
55
56
|
* Request a purchase for product. This will be received in `PurchaseUpdatedListener`.
|
|
56
57
|
* @param {string} [sku] The product's sku/ID
|
|
@@ -59,9 +60,10 @@ export declare const requestPurchase: (sku: string, appAccountToken: string, and
|
|
|
59
60
|
* @param {ProrationModesAndroid} [prorationModeAndroid] UNKNOWN_SUBSCRIPTION_UPGRADE_DOWNGRADE_POLICY, IMMEDIATE_WITH_TIME_PRORATION, IMMEDIATE_AND_CHARGE_PRORATED_PRICE, IMMEDIATE_WITHOUT_PRORATION, DEFERRED
|
|
60
61
|
* @param {string} [obfuscatedAccountIdAndroid] Specifies an optional obfuscated string that is uniquely associated with the user's account in your app.
|
|
61
62
|
* @param {string} [obfuscatedProfileIdAndroid] Specifies an optional obfuscated string that is uniquely associated with the user's profile in your app.
|
|
63
|
+
* @param {string} [selectedOfferIndex] Selected Offer index from the list returned by get products
|
|
62
64
|
* @returns {Promise<SubscriptionPurchase | null>} Promise resolves to null when using proratioModesAndroid=DEFERRED, and to a SubscriptionPurchase otherwise
|
|
63
65
|
*/
|
|
64
|
-
export declare const requestSubscription: (sku
|
|
66
|
+
export declare const requestSubscription: ({ sku, andDangerouslyFinishTransactionAutomaticallyIOS, purchaseTokenAndroid, prorationModeAndroid, obfuscatedAccountIdAndroid, obfuscatedProfileIdAndroid, selectedOfferIndex, }: RequestSubscription) => Promise<SubscriptionPurchase | null>;
|
|
65
67
|
/**
|
|
66
68
|
* Request a purchase for product. This will be received in `PurchaseUpdatedListener`.
|
|
67
69
|
* @param {string} sku The product's sku/ID
|
package/src/iap.js
CHANGED
|
@@ -49,7 +49,7 @@ export var getInstallSourceAndroid = function () {
|
|
|
49
49
|
* Defaulting to V4 to minimize migration, it'll eventually be changed to default to V5
|
|
50
50
|
*/
|
|
51
51
|
var androidNativeModule = RNIapModuleV4;
|
|
52
|
-
var setAndroidNativeModule = function (nativeModule) {
|
|
52
|
+
export var setAndroidNativeModule = function (nativeModule) {
|
|
53
53
|
androidNativeModule = nativeModule;
|
|
54
54
|
};
|
|
55
55
|
var checkNativeAndroidAvailable = function () {
|
|
@@ -267,17 +267,14 @@ export var getAvailablePurchases = function () {
|
|
|
267
267
|
/**
|
|
268
268
|
* Request a purchase for product. This will be received in `PurchaseUpdatedListener`.
|
|
269
269
|
* @param {string} sku The product's sku/ID
|
|
270
|
-
* @param {string} [
|
|
270
|
+
* @param {string} [applicationUsername] The purchaser's user ID
|
|
271
271
|
* @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.
|
|
272
272
|
* @param {string} [obfuscatedAccountIdAndroid] Specifies an optional obfuscated string that is uniquely associated with the user's account in your app.
|
|
273
273
|
* @param {string} [obfuscatedProfileIdAndroid] Specifies an optional obfuscated string that is uniquely associated with the user's profile in your app.
|
|
274
274
|
* @returns {Promise<InAppPurchase>}
|
|
275
275
|
*/
|
|
276
|
-
export var requestPurchase = function (
|
|
277
|
-
|
|
278
|
-
if (obfuscatedAccountIdAndroid === void 0) { obfuscatedAccountIdAndroid = undefined; }
|
|
279
|
-
if (obfuscatedProfileIdAndroid === void 0) { obfuscatedProfileIdAndroid = undefined; }
|
|
280
|
-
if (selectedOfferIndex === void 0) { selectedOfferIndex = undefined; }
|
|
276
|
+
export var requestPurchase = function (_a) {
|
|
277
|
+
var sku = _a.sku, _b = _a.andDangerouslyFinishTransactionAutomaticallyIOS, andDangerouslyFinishTransactionAutomaticallyIOS = _b === void 0 ? false : _b, applicationUsername = _a.applicationUsername, _c = _a.obfuscatedAccountIdAndroid, obfuscatedAccountIdAndroid = _c === void 0 ? undefined : _c, _d = _a.obfuscatedProfileIdAndroid, obfuscatedProfileIdAndroid = _d === void 0 ? undefined : _d;
|
|
281
278
|
return (Platform.select({
|
|
282
279
|
ios: function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
283
280
|
return __generator(this, function (_a) {
|
|
@@ -287,12 +284,12 @@ export var requestPurchase = function (sku, appAccountToken, andDangerouslyFinis
|
|
|
287
284
|
// eslint-disable-next-line max-len
|
|
288
285
|
'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.');
|
|
289
286
|
}
|
|
290
|
-
return [2 /*return*/, getIosModule().buyProduct(sku,
|
|
287
|
+
return [2 /*return*/, getIosModule().buyProduct(sku, andDangerouslyFinishTransactionAutomaticallyIOS, applicationUsername)];
|
|
291
288
|
});
|
|
292
289
|
}); },
|
|
293
290
|
android: function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
294
291
|
return __generator(this, function (_a) {
|
|
295
|
-
return [2 /*return*/, getAndroidModule().buyItemByType(ANDROID_ITEM_TYPE_IAP, sku, null, 0, obfuscatedAccountIdAndroid, obfuscatedProfileIdAndroid,
|
|
292
|
+
return [2 /*return*/, getAndroidModule().buyItemByType(ANDROID_ITEM_TYPE_IAP, sku, null, 0, obfuscatedAccountIdAndroid, obfuscatedProfileIdAndroid, undefined)];
|
|
296
293
|
});
|
|
297
294
|
}); },
|
|
298
295
|
}) || Promise.resolve)();
|
|
@@ -305,14 +302,11 @@ export var requestPurchase = function (sku, appAccountToken, andDangerouslyFinis
|
|
|
305
302
|
* @param {ProrationModesAndroid} [prorationModeAndroid] UNKNOWN_SUBSCRIPTION_UPGRADE_DOWNGRADE_POLICY, IMMEDIATE_WITH_TIME_PRORATION, IMMEDIATE_AND_CHARGE_PRORATED_PRICE, IMMEDIATE_WITHOUT_PRORATION, DEFERRED
|
|
306
303
|
* @param {string} [obfuscatedAccountIdAndroid] Specifies an optional obfuscated string that is uniquely associated with the user's account in your app.
|
|
307
304
|
* @param {string} [obfuscatedProfileIdAndroid] Specifies an optional obfuscated string that is uniquely associated with the user's profile in your app.
|
|
305
|
+
* @param {string} [selectedOfferIndex] Selected Offer index from the list returned by get products
|
|
308
306
|
* @returns {Promise<SubscriptionPurchase | null>} Promise resolves to null when using proratioModesAndroid=DEFERRED, and to a SubscriptionPurchase otherwise
|
|
309
307
|
*/
|
|
310
|
-
export var requestSubscription = function (
|
|
311
|
-
|
|
312
|
-
if (purchaseTokenAndroid === void 0) { purchaseTokenAndroid = undefined; }
|
|
313
|
-
if (prorationModeAndroid === void 0) { prorationModeAndroid = -1; }
|
|
314
|
-
if (obfuscatedAccountIdAndroid === void 0) { obfuscatedAccountIdAndroid = undefined; }
|
|
315
|
-
if (obfuscatedProfileIdAndroid === void 0) { obfuscatedProfileIdAndroid = undefined; }
|
|
308
|
+
export var requestSubscription = function (_a) {
|
|
309
|
+
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.selectedOfferIndex, selectedOfferIndex = _g === void 0 ? undefined : _g;
|
|
316
310
|
return (Platform.select({
|
|
317
311
|
ios: function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
318
312
|
return __generator(this, function (_a) {
|
|
@@ -327,7 +321,7 @@ export var requestSubscription = function (sku, andDangerouslyFinishTransactionA
|
|
|
327
321
|
}); },
|
|
328
322
|
android: function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
329
323
|
return __generator(this, function (_a) {
|
|
330
|
-
return [2 /*return*/, getAndroidModule().buyItemByType(ANDROID_ITEM_TYPE_SUBSCRIPTION, sku, purchaseTokenAndroid, prorationModeAndroid, obfuscatedAccountIdAndroid, obfuscatedProfileIdAndroid)];
|
|
324
|
+
return [2 /*return*/, getAndroidModule().buyItemByType(ANDROID_ITEM_TYPE_SUBSCRIPTION, sku, purchaseTokenAndroid, prorationModeAndroid, obfuscatedAccountIdAndroid, obfuscatedProfileIdAndroid, selectedOfferIndex)];
|
|
331
325
|
});
|
|
332
326
|
}); },
|
|
333
327
|
}) || Promise.resolve)();
|
package/src/types/index.d.ts
CHANGED
|
@@ -137,3 +137,19 @@ export interface Subscription extends ProductCommon {
|
|
|
137
137
|
subscriptionPeriodAndroid?: string;
|
|
138
138
|
freeTrialPeriodAndroid?: string;
|
|
139
139
|
}
|
|
140
|
+
export interface RequestPurchase {
|
|
141
|
+
sku: string;
|
|
142
|
+
andDangerouslyFinishTransactionAutomaticallyIOS: boolean;
|
|
143
|
+
applicationUsername?: string;
|
|
144
|
+
obfuscatedAccountIdAndroid: string | undefined;
|
|
145
|
+
obfuscatedProfileIdAndroid: string | undefined;
|
|
146
|
+
}
|
|
147
|
+
export interface RequestSubscription {
|
|
148
|
+
sku: string;
|
|
149
|
+
andDangerouslyFinishTransactionAutomaticallyIOS: boolean;
|
|
150
|
+
purchaseTokenAndroid: string | undefined;
|
|
151
|
+
prorationModeAndroid: ProrationModesAndroid;
|
|
152
|
+
obfuscatedAccountIdAndroid: string | undefined;
|
|
153
|
+
obfuscatedProfileIdAndroid: string | undefined;
|
|
154
|
+
selectedOfferIndex?: number | undefined;
|
|
155
|
+
}
|
package/ios/RNIapQueue.swift
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// RNIapQueue.swift
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
// Created by Andres Aguilar on 9/8/21.
|
|
6
|
-
//
|
|
7
|
-
|
|
8
|
-
import Foundation
|
|
9
|
-
import StoreKit
|
|
10
|
-
|
|
11
|
-
// Temporarily stores payment information since it is sent by the OS before RN instantiates the RNModule
|
|
12
|
-
@objc(RNIapQueue)
|
|
13
|
-
public class RNIapQueue: NSObject, SKPaymentTransactionObserver {
|
|
14
|
-
public func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {
|
|
15
|
-
//No-op
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
@objc
|
|
19
|
-
public static let shared = RNIapQueue()
|
|
20
|
-
|
|
21
|
-
var queue: SKPaymentQueue? = nil;
|
|
22
|
-
var payment: SKPayment? = nil;
|
|
23
|
-
var product: SKProduct? = nil;
|
|
24
|
-
|
|
25
|
-
private override init(){}
|
|
26
|
-
|
|
27
|
-
// Sent when a user initiates an IAP buy from the App Store
|
|
28
|
-
@available(iOS 11.0, *)
|
|
29
|
-
func paymentQueue(_ queue: SKPaymentQueue, shouldAddStorePayment payment: SKPayment, for product: SKProduct) -> Bool{
|
|
30
|
-
RNIapQueue.shared.queue = queue
|
|
31
|
-
RNIapQueue.shared.payment = payment
|
|
32
|
-
RNIapQueue.shared.product = product
|
|
33
|
-
return false
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
}
|