react-native-iap 8.4.0 → 9.0.0-beta3

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.
@@ -30,7 +30,7 @@ import org.junit.Assert.assertTrue
30
30
  import org.junit.Before
31
31
  import org.junit.Test
32
32
 
33
- class RNIapModuleTest {
33
+ class RNIapModuleTestV4 {
34
34
 
35
35
  @MockK
36
36
  lateinit var context: ReactApplicationContext
@@ -44,14 +44,14 @@ class RNIapModuleTest {
44
44
  @MockK
45
45
  lateinit var availability: GoogleApiAvailability
46
46
 
47
- private lateinit var module: RNIapModule
47
+ private lateinit var module: RNIapModuleV4
48
48
 
49
49
  @Before
50
50
  fun setUp() {
51
51
  MockKAnnotations.init(this, relaxUnitFun = true)
52
52
  every { builder.setListener(any()) } returns builder
53
53
  every { builder.build() } returns billingClient
54
- module = RNIapModule(context, builder, availability)
54
+ module = RNIapModuleV4(context, builder, availability)
55
55
  }
56
56
 
57
57
  @Test
@@ -134,7 +134,7 @@ class RNIapModuleTest {
134
134
  every { billingClient.isReady } returns true
135
135
  val promise = mockk<Promise>(relaxed = true)
136
136
  val listener = slot<PurchasesResponseListener>()
137
- every { billingClient.queryPurchasesAsync(any(), capture(listener)) } answers {
137
+ every { billingClient.queryPurchasesAsync(any<String>(), capture(listener)) } answers {
138
138
  listener.captured.onQueryPurchasesResponse(BillingResult.newBuilder().build(), listOf())
139
139
  }
140
140
  module.initConnection(mockk())
@@ -150,7 +150,7 @@ class RNIapModuleTest {
150
150
  every { billingClient.isReady } returns true
151
151
  val promise = mockk<Promise>(relaxed = true)
152
152
  val listener = slot<PurchasesResponseListener>()
153
- every { billingClient.queryPurchasesAsync(any(), capture(listener)) } answers {
153
+ every { billingClient.queryPurchasesAsync(any<String>(), capture(listener)) } answers {
154
154
  listener.captured.onQueryPurchasesResponse(
155
155
  BillingResult.newBuilder().build(),
156
156
  listOf(
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:
@@ -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
- payment.applicationUsername = appAccountToken
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-iap",
3
- "version": "8.4.0",
3
+ "version": "9.0.0-beta3",
4
4
  "packageManager": "yarn@3.2.0",
5
5
  "description": "React Native In App Purchase Module.",
6
6
  "main": "index.js",
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, ProrationModesAndroid, PurchaseError, PurchaseResult, Subscription, SubscriptionPurchase } from './types';
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} [appAccountToken] The purchaser's user ID
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: string, appAccountToken: string, andDangerouslyFinishTransactionAutomaticallyIOS?: boolean, obfuscatedAccountIdAndroid?: string | undefined, obfuscatedProfileIdAndroid?: string | undefined) => Promise<InAppPurchase>;
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: string, andDangerouslyFinishTransactionAutomaticallyIOS?: boolean, purchaseTokenAndroid?: string | undefined, prorationModeAndroid?: ProrationModesAndroid, obfuscatedAccountIdAndroid?: string | undefined, obfuscatedProfileIdAndroid?: string | undefined) => Promise<SubscriptionPurchase | null>;
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
@@ -37,7 +37,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
37
37
  import * as Apple from './types/apple';
38
38
  import { Linking, NativeEventEmitter, NativeModules, Platform, } from 'react-native';
39
39
  import { IAPErrorCode, InstallSourceAndroid, PurchaseStateAndroid, } from './types';
40
- var RNIapIos = NativeModules.RNIapIos, RNIapModule = NativeModules.RNIapModule, RNIapAmazonModule = NativeModules.RNIapAmazonModule;
40
+ var RNIapIos = NativeModules.RNIapIos, RNIapModule = NativeModules.RNIapModule, RNIapModuleV4 = NativeModules.RNIapModuleV4, RNIapAmazonModule = NativeModules.RNIapAmazonModule;
41
41
  var ANDROID_ITEM_TYPE_SUBSCRIPTION = 'subs';
42
42
  var ANDROID_ITEM_TYPE_IAP = 'inapp';
43
43
  export var getInstallSourceAndroid = function () {
@@ -45,14 +45,25 @@ export var getInstallSourceAndroid = function () {
45
45
  ? InstallSourceAndroid.GOOGLE_PLAY
46
46
  : InstallSourceAndroid.AMAZON;
47
47
  };
48
+ /**
49
+ * Defaulting to V4 to minimize migration, it'll eventually be changed to default to V5
50
+ */
51
+ var androidNativeModule = RNIapModuleV4;
52
+ export var setAndroidNativeModule = function (nativeModule) {
53
+ androidNativeModule = nativeModule;
54
+ };
48
55
  var checkNativeAndroidAvailable = function () {
49
- if (!RNIapModule && !RNIapAmazonModule) {
56
+ if (!RNIapModule && !RNIapModuleV4 && !RNIapAmazonModule) {
50
57
  throw new Error(IAPErrorCode.E_IAP_NOT_AVAILABLE);
51
58
  }
52
59
  };
53
60
  var getAndroidModule = function () {
54
61
  checkNativeAndroidAvailable();
55
- return RNIapModule ? RNIapModule : RNIapAmazonModule;
62
+ return androidNativeModule
63
+ ? androidNativeModule
64
+ : RNIapModule
65
+ ? RNIapModule
66
+ : RNIapAmazonModule;
56
67
  };
57
68
  var checkNativeiOSAvailable = function () {
58
69
  if (!RNIapIos) {
@@ -64,11 +75,13 @@ var getIosModule = function () {
64
75
  return RNIapIos;
65
76
  };
66
77
  var getNativeModule = function () {
67
- return RNIapModule
68
- ? RNIapModule
69
- : RNIapAmazonModule
70
- ? RNIapAmazonModule
71
- : RNIapIos;
78
+ return androidNativeModule
79
+ ? androidNativeModule
80
+ : RNIapModule
81
+ ? RNIapModule
82
+ : RNIapAmazonModule
83
+ ? RNIapAmazonModule
84
+ : RNIapIos;
72
85
  };
73
86
  /**
74
87
  * Init module for purchase flow. Required on Android. In ios it will check whether user canMakePayment.
@@ -135,13 +148,15 @@ var fillProductsAdditionalData = function (products) { return __awaiter(void 0,
135
148
  export var getProducts = function (skus) {
136
149
  return (Platform.select({
137
150
  ios: function () { return __awaiter(void 0, void 0, void 0, function () {
151
+ var products;
138
152
  return __generator(this, function (_a) {
139
153
  switch (_a.label) {
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()];
154
+ case 0: return [4 /*yield*/, getIosModule().getItems(skus)];
155
+ case 1:
156
+ products = _a.sent();
157
+ return [2 /*return*/, products.filter(function (item) {
158
+ return skus.includes(item.productId) && item.type === 'iap';
159
+ })];
145
160
  }
146
161
  });
147
162
  }); },
@@ -166,13 +181,15 @@ export var getProducts = function (skus) {
166
181
  export var getSubscriptions = function (skus) {
167
182
  return (Platform.select({
168
183
  ios: function () { return __awaiter(void 0, void 0, void 0, function () {
184
+ var subscriptions;
169
185
  return __generator(this, function (_a) {
170
186
  switch (_a.label) {
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()];
187
+ case 0: return [4 /*yield*/, getIosModule().getItems(skus)];
188
+ case 1:
189
+ subscriptions = _a.sent();
190
+ return [2 /*return*/, subscriptions.filter(function (item) {
191
+ return skus.includes(item.productId) && item.type === 'subs';
192
+ })];
176
193
  }
177
194
  });
178
195
  }); },
@@ -254,16 +271,14 @@ export var getAvailablePurchases = function () {
254
271
  /**
255
272
  * Request a purchase for product. This will be received in `PurchaseUpdatedListener`.
256
273
  * @param {string} sku The product's sku/ID
257
- * @param {string} [appAccountToken] The purchaser's user ID
274
+ * @param {string} [applicationUsername] The purchaser's user ID
258
275
  * @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
276
  * @param {string} [obfuscatedAccountIdAndroid] Specifies an optional obfuscated string that is uniquely associated with the user's account in your app.
260
277
  * @param {string} [obfuscatedProfileIdAndroid] Specifies an optional obfuscated string that is uniquely associated with the user's profile in your app.
261
278
  * @returns {Promise<InAppPurchase>}
262
279
  */
263
- export var requestPurchase = function (sku, appAccountToken, andDangerouslyFinishTransactionAutomaticallyIOS, obfuscatedAccountIdAndroid, obfuscatedProfileIdAndroid) {
264
- if (andDangerouslyFinishTransactionAutomaticallyIOS === void 0) { andDangerouslyFinishTransactionAutomaticallyIOS = false; }
265
- if (obfuscatedAccountIdAndroid === void 0) { obfuscatedAccountIdAndroid = undefined; }
266
- if (obfuscatedProfileIdAndroid === void 0) { obfuscatedProfileIdAndroid = undefined; }
280
+ export var requestPurchase = function (_a) {
281
+ 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;
267
282
  return (Platform.select({
268
283
  ios: function () { return __awaiter(void 0, void 0, void 0, function () {
269
284
  return __generator(this, function (_a) {
@@ -273,12 +288,12 @@ export var requestPurchase = function (sku, appAccountToken, andDangerouslyFinis
273
288
  // eslint-disable-next-line max-len
274
289
  '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
290
  }
276
- return [2 /*return*/, getIosModule().buyProduct(sku, appAccountToken, andDangerouslyFinishTransactionAutomaticallyIOS)];
291
+ return [2 /*return*/, getIosModule().buyProduct(sku, andDangerouslyFinishTransactionAutomaticallyIOS, applicationUsername)];
277
292
  });
278
293
  }); },
279
294
  android: function () { return __awaiter(void 0, void 0, void 0, function () {
280
295
  return __generator(this, function (_a) {
281
- return [2 /*return*/, getAndroidModule().buyItemByType(ANDROID_ITEM_TYPE_IAP, sku, null, 0, obfuscatedAccountIdAndroid, obfuscatedProfileIdAndroid)];
296
+ return [2 /*return*/, getAndroidModule().buyItemByType(ANDROID_ITEM_TYPE_IAP, sku, null, 0, obfuscatedAccountIdAndroid, obfuscatedProfileIdAndroid, undefined)];
282
297
  });
283
298
  }); },
284
299
  }) || Promise.resolve)();
@@ -291,14 +306,11 @@ export var requestPurchase = function (sku, appAccountToken, andDangerouslyFinis
291
306
  * @param {ProrationModesAndroid} [prorationModeAndroid] UNKNOWN_SUBSCRIPTION_UPGRADE_DOWNGRADE_POLICY, IMMEDIATE_WITH_TIME_PRORATION, IMMEDIATE_AND_CHARGE_PRORATED_PRICE, IMMEDIATE_WITHOUT_PRORATION, DEFERRED
292
307
  * @param {string} [obfuscatedAccountIdAndroid] Specifies an optional obfuscated string that is uniquely associated with the user's account in your app.
293
308
  * @param {string} [obfuscatedProfileIdAndroid] Specifies an optional obfuscated string that is uniquely associated with the user's profile in your app.
309
+ * @param {string} [selectedOfferIndex] Selected Offer index from the list returned by get products
294
310
  * @returns {Promise<SubscriptionPurchase | null>} Promise resolves to null when using proratioModesAndroid=DEFERRED, and to a SubscriptionPurchase otherwise
295
311
  */
296
- export var requestSubscription = function (sku, andDangerouslyFinishTransactionAutomaticallyIOS, purchaseTokenAndroid, prorationModeAndroid, obfuscatedAccountIdAndroid, obfuscatedProfileIdAndroid) {
297
- if (andDangerouslyFinishTransactionAutomaticallyIOS === void 0) { andDangerouslyFinishTransactionAutomaticallyIOS = false; }
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; }
312
+ export var requestSubscription = function (_a) {
313
+ 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;
302
314
  return (Platform.select({
303
315
  ios: function () { return __awaiter(void 0, void 0, void 0, function () {
304
316
  return __generator(this, function (_a) {
@@ -313,7 +325,7 @@ export var requestSubscription = function (sku, andDangerouslyFinishTransactionA
313
325
  }); },
314
326
  android: function () { return __awaiter(void 0, void 0, void 0, function () {
315
327
  return __generator(this, function (_a) {
316
- return [2 /*return*/, getAndroidModule().buyItemByType(ANDROID_ITEM_TYPE_SUBSCRIPTION, sku, purchaseTokenAndroid, prorationModeAndroid, obfuscatedAccountIdAndroid, obfuscatedProfileIdAndroid)];
328
+ return [2 /*return*/, getAndroidModule().buyItemByType(ANDROID_ITEM_TYPE_SUBSCRIPTION, sku, purchaseTokenAndroid, prorationModeAndroid, obfuscatedAccountIdAndroid, obfuscatedProfileIdAndroid, selectedOfferIndex)];
317
329
  });
318
330
  }); },
319
331
  }) || Promise.resolve)();
@@ -114,4 +114,40 @@ export interface Subscription extends ProductCommon {
114
114
  introductoryPricePeriodAndroid?: string;
115
115
  subscriptionPeriodAndroid?: string;
116
116
  freeTrialPeriodAndroid?: string;
117
+ productType?: string;
118
+ name?: string;
119
+ oneTimePurchaseOfferDetails?: {
120
+ priceCurrencyCode?: string;
121
+ formattedPrice?: string;
122
+ priceAmountMicros?: string;
123
+ }[];
124
+ subscriptionOfferDetails?: {
125
+ offerToken?: string[];
126
+ pricingPhases: {
127
+ pricingPhaseList: {
128
+ formattedPrice?: string;
129
+ priceCurrencyCode?: string;
130
+ billingPeriod?: string;
131
+ billingCycleCount?: number;
132
+ priceAmountMicros?: string;
133
+ recurrenceMode?: number;
134
+ };
135
+ };
136
+ }[];
137
+ }
138
+ export interface RequestPurchase {
139
+ sku: string;
140
+ andDangerouslyFinishTransactionAutomaticallyIOS: boolean;
141
+ applicationUsername?: string;
142
+ obfuscatedAccountIdAndroid: string | undefined;
143
+ obfuscatedProfileIdAndroid: string | undefined;
144
+ }
145
+ export interface RequestSubscription {
146
+ sku: string;
147
+ andDangerouslyFinishTransactionAutomaticallyIOS: boolean;
148
+ purchaseTokenAndroid: string | undefined;
149
+ prorationModeAndroid: ProrationModesAndroid;
150
+ obfuscatedAccountIdAndroid: string | undefined;
151
+ obfuscatedProfileIdAndroid: string | undefined;
152
+ selectedOfferIndex?: number | undefined;
117
153
  }
@@ -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
- }