react-native-iap 11.0.0-rc.5 → 11.0.0-rc.7
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/ios/RNIapIos.swift +11 -4
- package/ios/RNIapIosSk2.m +13 -0
- package/ios/RNIapIosSk2.swift +374 -29
- package/lib/commonjs/internal/platform.js +8 -8
- package/lib/commonjs/internal/platform.js.map +1 -1
- package/lib/commonjs/modules/iosSk2.js.map +1 -1
- package/lib/module/internal/platform.js +6 -6
- package/lib/module/internal/platform.js.map +1 -1
- package/lib/module/modules/iosSk2.js.map +1 -1
- package/lib/typescript/internal/platform.d.ts +1 -1
- package/lib/typescript/modules/iosSk2.d.ts +1 -0
- package/package.json +1 -1
- package/src/internal/platform.ts +8 -7
- package/src/modules/iosSk2.ts +1 -0
package/ios/RNIapIos.swift
CHANGED
|
@@ -651,6 +651,12 @@ class RNIapIos: RCTEventEmitter, SKRequestDelegate, SKPaymentTransactionObserver
|
|
|
651
651
|
if numOfUnits != 0 {
|
|
652
652
|
itemType = "subs"
|
|
653
653
|
}
|
|
654
|
+
// More reliable way of determining a subs on newer iOS versions
|
|
655
|
+
if #available(iOS 12.0, *) {
|
|
656
|
+
if product.subscriptionGroupIdentifier != nil {
|
|
657
|
+
itemType = "subs"
|
|
658
|
+
}
|
|
659
|
+
}
|
|
654
660
|
|
|
655
661
|
// subscriptionPeriod = product.subscriptionPeriod ? [product.subscriptionPeriod stringValue] : @"";
|
|
656
662
|
// introductoryPrice = product.introductoryPrice != nil ? [NSString stringWithFormat:@"%@", product.introductoryPrice] : @"";
|
|
@@ -750,10 +756,11 @@ class RNIapIos: RCTEventEmitter, SKRequestDelegate, SKPaymentTransactionObserver
|
|
|
750
756
|
for discount in product.discounts {
|
|
751
757
|
let formatter = NumberFormatter()
|
|
752
758
|
formatter.numberStyle = .currency
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
759
|
+
// This causes a crash on certain versions of iOS.
|
|
760
|
+
// let priceLocale: Locale? = discount.priceLocale
|
|
761
|
+
// if let priceLocale = priceLocale {
|
|
762
|
+
// formatter.locale = priceLocale
|
|
763
|
+
// }
|
|
757
764
|
localizedPrice = formatter.string(from: discount.price)
|
|
758
765
|
var numberOfPeriods: String?
|
|
759
766
|
|
package/ios/RNIapIosSk2.m
CHANGED
|
@@ -2,8 +2,21 @@
|
|
|
2
2
|
|
|
3
3
|
#import <React/RCTBridgeModule.h>
|
|
4
4
|
#ifdef __IPHONE_15_0
|
|
5
|
+
|
|
6
|
+
// From: https://stackoverflow.com/a/5337804/570612
|
|
7
|
+
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
|
|
8
|
+
|
|
9
|
+
|
|
5
10
|
@interface RCT_EXTERN_MODULE (RNIapIosSk2, NSObject)
|
|
6
11
|
|
|
12
|
+
RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(isAvailable){
|
|
13
|
+
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"15.0")) {
|
|
14
|
+
return [NSNumber numberWithInt:1];
|
|
15
|
+
}else{
|
|
16
|
+
return [NSNumber numberWithInt:0];
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
7
20
|
RCT_EXTERN_METHOD(disable:
|
|
8
21
|
(RCTPromiseResolveBlock)resolve
|
|
9
22
|
reject:(RCTPromiseRejectBlock)reject)
|
package/ios/RNIapIosSk2.swift
CHANGED
|
@@ -2,18 +2,378 @@ import Foundation
|
|
|
2
2
|
import React
|
|
3
3
|
import StoreKit
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
protocol Sk2Delegate {
|
|
6
|
+
func disable(
|
|
7
|
+
_ resolve: @escaping RCTPromiseResolveBlock,
|
|
8
|
+
reject: @escaping RCTPromiseRejectBlock
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
func initConnection(
|
|
12
|
+
_ resolve: @escaping RCTPromiseResolveBlock ,
|
|
13
|
+
reject: @escaping RCTPromiseRejectBlock
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
func endConnection(
|
|
17
|
+
_ resolve: @escaping RCTPromiseResolveBlock,
|
|
18
|
+
reject: @escaping RCTPromiseRejectBlock
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
func getItems(
|
|
22
|
+
_ skus: [String],
|
|
23
|
+
resolve: @escaping RCTPromiseResolveBlock,
|
|
24
|
+
reject: @escaping RCTPromiseRejectBlock
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
func getAvailableItems(
|
|
28
|
+
_ alsoPublishToEventListener: Bool,
|
|
29
|
+
resolve: @escaping RCTPromiseResolveBlock,
|
|
30
|
+
reject: @escaping RCTPromiseRejectBlock
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
func buyProduct(
|
|
34
|
+
_ sku: String,
|
|
35
|
+
andDangerouslyFinishTransactionAutomatically: Bool,
|
|
36
|
+
appAccountToken: String?,
|
|
37
|
+
quantity: Int,
|
|
38
|
+
withOffer: [String: String],
|
|
39
|
+
resolve: @escaping RCTPromiseResolveBlock,
|
|
40
|
+
reject: @escaping RCTPromiseRejectBlock
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
func isEligibleForIntroOffer(
|
|
44
|
+
_ groupID: String,
|
|
45
|
+
resolve: @escaping RCTPromiseResolveBlock ,
|
|
46
|
+
reject: @escaping RCTPromiseRejectBlock
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
func subscriptionStatus(
|
|
50
|
+
_ sku: String,
|
|
51
|
+
resolve: @escaping RCTPromiseResolveBlock,
|
|
52
|
+
reject: @escaping RCTPromiseRejectBlock
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
func currentEntitlement(
|
|
56
|
+
_ sku: String,
|
|
57
|
+
resolve: @escaping RCTPromiseResolveBlock,
|
|
58
|
+
reject: @escaping RCTPromiseRejectBlock
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
func latestTransaction(
|
|
62
|
+
_ sku: String,
|
|
63
|
+
resolve: @escaping RCTPromiseResolveBlock,
|
|
64
|
+
reject: @escaping RCTPromiseRejectBlock
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
func finishTransaction(
|
|
68
|
+
_ transactionIdentifier: String,
|
|
69
|
+
resolve: @escaping RCTPromiseResolveBlock ,
|
|
70
|
+
reject: @escaping RCTPromiseRejectBlock
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
func pendingTransactions (
|
|
74
|
+
_ resolve: @escaping RCTPromiseResolveBlock,
|
|
75
|
+
reject: @escaping RCTPromiseRejectBlock
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
func sync(
|
|
79
|
+
_ resolve: @escaping RCTPromiseResolveBlock,
|
|
80
|
+
reject: @escaping RCTPromiseRejectBlock
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
func presentCodeRedemptionSheet(
|
|
84
|
+
_ resolve: @escaping RCTPromiseResolveBlock,
|
|
85
|
+
reject: @escaping RCTPromiseRejectBlock
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
func startObserving()
|
|
89
|
+
func stopObserving()
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
class DummySk2: Sk2Delegate {
|
|
93
|
+
let errorCode = IapErrors.E_DEVELOPER_ERROR.rawValue
|
|
94
|
+
let errorMessage = "Method only available on iOS 15 and up"
|
|
95
|
+
|
|
96
|
+
func disable(
|
|
97
|
+
_ resolve: @escaping RCTPromiseResolveBlock,
|
|
98
|
+
reject: @escaping RCTPromiseRejectBlock
|
|
99
|
+
) {
|
|
100
|
+
reject(errorCode, errorMessage, nil)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
func initConnection(
|
|
104
|
+
_ resolve: @escaping RCTPromiseResolveBlock ,
|
|
105
|
+
reject: @escaping RCTPromiseRejectBlock
|
|
106
|
+
) {
|
|
107
|
+
reject(errorCode, errorMessage, nil)
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
func endConnection(
|
|
111
|
+
_ resolve: @escaping RCTPromiseResolveBlock,
|
|
112
|
+
reject: @escaping RCTPromiseRejectBlock
|
|
113
|
+
) {
|
|
114
|
+
reject(errorCode, errorMessage, nil)
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
func getItems(
|
|
118
|
+
_ skus: [String],
|
|
119
|
+
resolve: @escaping RCTPromiseResolveBlock,
|
|
120
|
+
reject: @escaping RCTPromiseRejectBlock
|
|
121
|
+
) {
|
|
122
|
+
reject(errorCode, errorMessage, nil)
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
func getAvailableItems(
|
|
126
|
+
_ alsoPublishToEventListener: Bool,
|
|
127
|
+
resolve: @escaping RCTPromiseResolveBlock,
|
|
128
|
+
reject: @escaping RCTPromiseRejectBlock
|
|
129
|
+
) {
|
|
130
|
+
reject(errorCode, errorMessage, nil)
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
func buyProduct(
|
|
134
|
+
_ sku: String,
|
|
135
|
+
andDangerouslyFinishTransactionAutomatically: Bool,
|
|
136
|
+
appAccountToken: String?,
|
|
137
|
+
quantity: Int,
|
|
138
|
+
withOffer: [String: String],
|
|
139
|
+
resolve: @escaping RCTPromiseResolveBlock,
|
|
140
|
+
reject: @escaping RCTPromiseRejectBlock
|
|
141
|
+
) {
|
|
142
|
+
reject(errorCode, errorMessage, nil)
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
func isEligibleForIntroOffer(
|
|
146
|
+
_ groupID: String,
|
|
147
|
+
resolve: @escaping RCTPromiseResolveBlock ,
|
|
148
|
+
reject: @escaping RCTPromiseRejectBlock
|
|
149
|
+
) {
|
|
150
|
+
reject(errorCode, errorMessage, nil)
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
func subscriptionStatus(
|
|
154
|
+
_ sku: String,
|
|
155
|
+
resolve: @escaping RCTPromiseResolveBlock,
|
|
156
|
+
reject: @escaping RCTPromiseRejectBlock
|
|
157
|
+
) {
|
|
158
|
+
reject(errorCode, errorMessage, nil)
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
func currentEntitlement(
|
|
162
|
+
_ sku: String,
|
|
163
|
+
resolve: @escaping RCTPromiseResolveBlock,
|
|
164
|
+
reject: @escaping RCTPromiseRejectBlock
|
|
165
|
+
) {
|
|
166
|
+
reject(errorCode, errorMessage, nil)
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
func latestTransaction(
|
|
170
|
+
_ sku: String,
|
|
171
|
+
resolve: @escaping RCTPromiseResolveBlock,
|
|
172
|
+
reject: @escaping RCTPromiseRejectBlock
|
|
173
|
+
) {
|
|
174
|
+
reject(errorCode, errorMessage, nil)
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
func finishTransaction(
|
|
178
|
+
_ transactionIdentifier: String,
|
|
179
|
+
resolve: @escaping RCTPromiseResolveBlock ,
|
|
180
|
+
reject: @escaping RCTPromiseRejectBlock
|
|
181
|
+
) {
|
|
182
|
+
reject(errorCode, errorMessage, nil)
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
func pendingTransactions (
|
|
186
|
+
_ resolve: @escaping RCTPromiseResolveBlock,
|
|
187
|
+
reject: @escaping RCTPromiseRejectBlock
|
|
188
|
+
) {
|
|
189
|
+
reject(errorCode, errorMessage, nil)
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
func sync(
|
|
193
|
+
_ resolve: @escaping RCTPromiseResolveBlock,
|
|
194
|
+
reject: @escaping RCTPromiseRejectBlock
|
|
195
|
+
) {
|
|
196
|
+
reject(errorCode, errorMessage, nil)
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
func presentCodeRedemptionSheet(
|
|
200
|
+
_ resolve: @escaping RCTPromiseResolveBlock,
|
|
201
|
+
reject: @escaping RCTPromiseRejectBlock
|
|
202
|
+
) {
|
|
203
|
+
reject(errorCode, errorMessage, nil)
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
func startObserving() {
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
func stopObserving() {
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
6
213
|
@objc(RNIapIosSk2)
|
|
7
|
-
class RNIapIosSk2: RCTEventEmitter {
|
|
214
|
+
class RNIapIosSk2: RCTEventEmitter, Sk2Delegate {
|
|
215
|
+
private var delegate: Sk2Delegate = DummySk2()
|
|
216
|
+
|
|
217
|
+
override init() {
|
|
218
|
+
super.init()
|
|
219
|
+
if #available(iOS 15.0, *) {
|
|
220
|
+
delegate = RNIapIosSk2iOS15(sendEvent: self.sendEvent)
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
@objc public func disable(
|
|
225
|
+
_ resolve: @escaping RCTPromiseResolveBlock = { _ in },
|
|
226
|
+
reject: @escaping RCTPromiseRejectBlock = { _, _, _ in }
|
|
227
|
+
) {
|
|
228
|
+
delegate.disable(resolve, reject: reject)
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
override class func requiresMainQueueSetup() -> Bool {
|
|
232
|
+
return true
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
override func startObserving() {
|
|
236
|
+
delegate.startObserving()
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
override func stopObserving() {
|
|
240
|
+
delegate.stopObserving()
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
override func addListener(_ eventName: String?) {
|
|
244
|
+
super.addListener(eventName)
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
"iap-transaction-updated" is unique to Sk2.
|
|
249
|
+
"iap-promoted-product" is only avaiable on Sk1
|
|
250
|
+
"purchase-updated", "purchase-error" are for backward compatibility
|
|
251
|
+
*/
|
|
252
|
+
override func supportedEvents() -> [String]? {
|
|
253
|
+
return [ "purchase-updated", "purchase-error", "iap-transaction-updated"]
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
@objc public func initConnection(
|
|
257
|
+
_ resolve: @escaping RCTPromiseResolveBlock = { _ in },
|
|
258
|
+
reject: @escaping RCTPromiseRejectBlock = { _, _, _ in }
|
|
259
|
+
) {
|
|
260
|
+
delegate.initConnection(resolve, reject: reject)
|
|
261
|
+
}
|
|
262
|
+
@objc public func endConnection(
|
|
263
|
+
_ resolve: @escaping RCTPromiseResolveBlock = { _ in },
|
|
264
|
+
reject: @escaping RCTPromiseRejectBlock = { _, _, _ in }
|
|
265
|
+
) {
|
|
266
|
+
delegate.endConnection(resolve, reject: reject)
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
@objc public func getItems(
|
|
270
|
+
_ skus: [String],
|
|
271
|
+
resolve: @escaping RCTPromiseResolveBlock = { _ in },
|
|
272
|
+
reject: @escaping RCTPromiseRejectBlock = { _, _, _ in }
|
|
273
|
+
) {
|
|
274
|
+
delegate.getItems(skus, resolve: resolve, reject: reject)
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
@objc public func getAvailableItems(
|
|
278
|
+
_ alsoPublishToEventListener: Bool,
|
|
279
|
+
resolve: @escaping RCTPromiseResolveBlock = { _ in },
|
|
280
|
+
reject: @escaping RCTPromiseRejectBlock = { _, _, _ in }
|
|
281
|
+
) {
|
|
282
|
+
delegate.getAvailableItems(alsoPublishToEventListener, resolve: resolve, reject: reject)
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
@objc public func buyProduct(
|
|
286
|
+
_ sku: String,
|
|
287
|
+
andDangerouslyFinishTransactionAutomatically: Bool,
|
|
288
|
+
appAccountToken: String?,
|
|
289
|
+
quantity: Int,
|
|
290
|
+
withOffer: [String: String],
|
|
291
|
+
resolve: @escaping RCTPromiseResolveBlock = { _ in },
|
|
292
|
+
reject: @escaping RCTPromiseRejectBlock = { _, _, _ in }
|
|
293
|
+
) {
|
|
294
|
+
delegate.buyProduct(
|
|
295
|
+
sku,
|
|
296
|
+
andDangerouslyFinishTransactionAutomatically: andDangerouslyFinishTransactionAutomatically,
|
|
297
|
+
appAccountToken: appAccountToken,
|
|
298
|
+
quantity: quantity,
|
|
299
|
+
withOffer: withOffer,
|
|
300
|
+
resolve: resolve,
|
|
301
|
+
reject: reject)
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
@objc public func isEligibleForIntroOffer(
|
|
305
|
+
_ groupID: String,
|
|
306
|
+
resolve: @escaping RCTPromiseResolveBlock = { _ in },
|
|
307
|
+
reject: @escaping RCTPromiseRejectBlock = { _, _, _ in }
|
|
308
|
+
) {
|
|
309
|
+
delegate.isEligibleForIntroOffer(groupID, resolve: resolve, reject: reject)
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
@objc public func subscriptionStatus(
|
|
313
|
+
_ sku: String,
|
|
314
|
+
resolve: @escaping RCTPromiseResolveBlock = { _ in },
|
|
315
|
+
reject: @escaping RCTPromiseRejectBlock = { _, _, _ in }
|
|
316
|
+
) {
|
|
317
|
+
delegate.subscriptionStatus(sku, resolve: resolve, reject: reject)
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
@objc public func currentEntitlement(
|
|
321
|
+
_ sku: String,
|
|
322
|
+
resolve: @escaping RCTPromiseResolveBlock = { _ in },
|
|
323
|
+
reject: @escaping RCTPromiseRejectBlock = { _, _, _ in }
|
|
324
|
+
) {
|
|
325
|
+
delegate.currentEntitlement(sku, resolve: resolve, reject: reject)
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
@objc public func latestTransaction(
|
|
329
|
+
_ sku: String,
|
|
330
|
+
resolve: @escaping RCTPromiseResolveBlock = { _ in },
|
|
331
|
+
reject: @escaping RCTPromiseRejectBlock = { _, _, _ in }
|
|
332
|
+
) {
|
|
333
|
+
delegate.latestTransaction(sku, resolve: resolve, reject: reject)
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
@objc public func finishTransaction(
|
|
337
|
+
_ transactionIdentifier: String,
|
|
338
|
+
resolve: @escaping RCTPromiseResolveBlock = { _ in },
|
|
339
|
+
reject: @escaping RCTPromiseRejectBlock = { _, _, _ in }
|
|
340
|
+
) {
|
|
341
|
+
delegate.finishTransaction(transactionIdentifier, resolve: resolve, reject: reject)
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
@objc public func pendingTransactions (
|
|
345
|
+
_ resolve: @escaping RCTPromiseResolveBlock = { _ in },
|
|
346
|
+
reject: @escaping RCTPromiseRejectBlock = { _, _, _ in }
|
|
347
|
+
) {
|
|
348
|
+
delegate.pendingTransactions(resolve, reject: reject)
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
@objc public func sync(
|
|
352
|
+
_ resolve: @escaping RCTPromiseResolveBlock = { _ in},
|
|
353
|
+
reject: @escaping RCTPromiseRejectBlock = {_, _, _ in}
|
|
354
|
+
) {
|
|
355
|
+
delegate.sync(resolve, reject: reject)
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
@objc public func presentCodeRedemptionSheet(
|
|
359
|
+
_ resolve: @escaping RCTPromiseResolveBlock = { _ in },
|
|
360
|
+
reject: @escaping RCTPromiseRejectBlock = { _, _, _ in }
|
|
361
|
+
) {
|
|
362
|
+
delegate.presentCodeRedemptionSheet(resolve, reject: reject)
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
@available(iOS 15.0, *)
|
|
367
|
+
class RNIapIosSk2iOS15: Sk2Delegate {
|
|
8
368
|
private var hasListeners = false
|
|
9
369
|
private var products: [String: Product]
|
|
10
370
|
private var transactions: [String: Transaction]
|
|
11
371
|
private var updateListenerTask: Task<Void, Error>?
|
|
12
|
-
|
|
13
|
-
|
|
372
|
+
fileprivate var sendEvent: ((String?, Any?) -> Void)?
|
|
373
|
+
init(sendEvent: ((String?, Any?) -> Void)? ) {
|
|
374
|
+
self.sendEvent = sendEvent
|
|
14
375
|
products = [String: Product]()
|
|
15
376
|
transactions = [String: Transaction]()
|
|
16
|
-
super.init()
|
|
17
377
|
addTransactionObserver()
|
|
18
378
|
}
|
|
19
379
|
|
|
@@ -29,9 +389,6 @@ class RNIapIosSk2: RCTEventEmitter {
|
|
|
29
389
|
resolve(nil)
|
|
30
390
|
}
|
|
31
391
|
|
|
32
|
-
override class func requiresMainQueueSetup() -> Bool {
|
|
33
|
-
return true
|
|
34
|
-
}
|
|
35
392
|
func addTransactionObserver() {
|
|
36
393
|
if updateListenerTask == nil {
|
|
37
394
|
updateListenerTask = listenForTransactions()
|
|
@@ -59,8 +416,8 @@ class RNIapIosSk2: RCTEventEmitter {
|
|
|
59
416
|
// await self.updateCustomerProductStatus()
|
|
60
417
|
|
|
61
418
|
if self.hasListeners {
|
|
62
|
-
self.sendEvent(
|
|
63
|
-
self.sendEvent(
|
|
419
|
+
self.sendEvent?("purchase-updated", serialize(transaction))
|
|
420
|
+
self.sendEvent?("iap-transaction-updated", ["transaction": serialize(transaction)])
|
|
64
421
|
}
|
|
65
422
|
// Always finish a transaction.
|
|
66
423
|
// await transaction.finish()
|
|
@@ -77,33 +434,21 @@ class RNIapIosSk2: RCTEventEmitter {
|
|
|
77
434
|
"message": error.localizedDescription
|
|
78
435
|
]
|
|
79
436
|
|
|
80
|
-
self.sendEvent(
|
|
81
|
-
self.sendEvent(
|
|
437
|
+
self.sendEvent?("purchase-error", err)
|
|
438
|
+
self.sendEvent?("iap-transaction-updated", ["error": err])
|
|
82
439
|
}
|
|
83
440
|
}
|
|
84
441
|
}
|
|
85
442
|
}
|
|
86
443
|
}
|
|
87
444
|
|
|
88
|
-
|
|
445
|
+
func startObserving() {
|
|
89
446
|
hasListeners = true
|
|
90
447
|
}
|
|
91
448
|
|
|
92
|
-
|
|
449
|
+
func stopObserving() {
|
|
93
450
|
hasListeners = false
|
|
94
451
|
}
|
|
95
|
-
override func addListener(_ eventName: String?) {
|
|
96
|
-
super.addListener(eventName)
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
"iap-transaction-updated" is unique to Sk2.
|
|
101
|
-
"iap-promoted-product" is only avaiable on Sk1
|
|
102
|
-
"purchase-updated", "purchase-error" are for backward compatibility
|
|
103
|
-
*/
|
|
104
|
-
override func supportedEvents() -> [String]? {
|
|
105
|
-
return [ "purchase-updated", "purchase-error", "iap-transaction-updated"]
|
|
106
|
-
}
|
|
107
452
|
|
|
108
453
|
@objc public func initConnection(
|
|
109
454
|
_ resolve: @escaping RCTPromiseResolveBlock = { _ in },
|
|
@@ -154,12 +499,12 @@ class RNIapIosSk2: RCTEventEmitter {
|
|
|
154
499
|
func addPurchase(transaction: Transaction, product: Product) {
|
|
155
500
|
purchasedItems.append( transaction)
|
|
156
501
|
if alsoPublishToEventListener {
|
|
157
|
-
sendEvent(
|
|
502
|
+
self.sendEvent?("purchase-update", serialize(transaction))
|
|
158
503
|
}
|
|
159
504
|
}
|
|
160
505
|
func addError( error: Error, errorDict: [String: String]) {
|
|
161
506
|
if alsoPublishToEventListener {
|
|
162
|
-
sendEvent(
|
|
507
|
+
self.sendEvent?("purchase-error", errorDict)
|
|
163
508
|
}
|
|
164
509
|
}
|
|
165
510
|
// Iterate through all of the user's purchased products.
|
|
@@ -277,7 +622,7 @@ class RNIapIosSk2: RCTEventEmitter {
|
|
|
277
622
|
resolve(nil)
|
|
278
623
|
} else {
|
|
279
624
|
self.addTransaction(transaction)
|
|
280
|
-
sendEvent(
|
|
625
|
+
self.sendEvent?("purchase-updated", serialize(transaction))
|
|
281
626
|
resolve(serialize(transaction))
|
|
282
627
|
}
|
|
283
628
|
return
|
|
@@ -51,13 +51,13 @@ const getNativeModule = () => {
|
|
|
51
51
|
exports.getNativeModule = getNativeModule;
|
|
52
52
|
let iosNativeModule = RNIapIos;
|
|
53
53
|
|
|
54
|
-
const
|
|
54
|
+
const isStorekit2Avaiable = () => (RNIapIosSk2 === null || RNIapIosSk2 === void 0 ? void 0 : RNIapIosSk2.isAvailable()) === 1;
|
|
55
55
|
|
|
56
|
-
exports.
|
|
56
|
+
exports.isStorekit2Avaiable = isStorekit2Avaiable;
|
|
57
57
|
|
|
58
|
-
const
|
|
58
|
+
const isIosStorekit2 = () => !!iosNativeModule && iosNativeModule === RNIapIosSk2 && isStorekit2Avaiable();
|
|
59
59
|
|
|
60
|
-
exports.
|
|
60
|
+
exports.isIosStorekit2 = isIosStorekit2;
|
|
61
61
|
|
|
62
62
|
const setIosNativeModule = nativeModule => {
|
|
63
63
|
iosNativeModule = nativeModule;
|
|
@@ -68,7 +68,7 @@ exports.setIosNativeModule = setIosNativeModule;
|
|
|
68
68
|
const storekit2Mode = () => {
|
|
69
69
|
iosNativeModule = RNIapIosSk2;
|
|
70
70
|
|
|
71
|
-
if (
|
|
71
|
+
if (isStorekit2Avaiable()) {
|
|
72
72
|
RNIapIos.disable();
|
|
73
73
|
return true;
|
|
74
74
|
}
|
|
@@ -82,7 +82,7 @@ exports.storekit2Mode = storekit2Mode;
|
|
|
82
82
|
const storekit1Mode = () => {
|
|
83
83
|
iosNativeModule = RNIapIos;
|
|
84
84
|
|
|
85
|
-
if (
|
|
85
|
+
if (isStorekit2Avaiable()) {
|
|
86
86
|
RNIapIosSk2.disable();
|
|
87
87
|
return true;
|
|
88
88
|
}
|
|
@@ -93,7 +93,7 @@ const storekit1Mode = () => {
|
|
|
93
93
|
exports.storekit1Mode = storekit1Mode;
|
|
94
94
|
|
|
95
95
|
const storekitHybridMode = () => {
|
|
96
|
-
if (
|
|
96
|
+
if (isStorekit2Avaiable()) {
|
|
97
97
|
iosNativeModule = RNIapIosSk2;
|
|
98
98
|
console.info('Using Storekit 2');
|
|
99
99
|
return true;
|
|
@@ -107,7 +107,7 @@ const storekitHybridMode = () => {
|
|
|
107
107
|
exports.storekitHybridMode = storekitHybridMode;
|
|
108
108
|
|
|
109
109
|
const checkNativeIOSAvailable = () => {
|
|
110
|
-
if (!RNIapIos && !
|
|
110
|
+
if (!RNIapIos && !isStorekit2Avaiable()) {
|
|
111
111
|
throw new Error('IAP_NOT_AVAILABLE');
|
|
112
112
|
}
|
|
113
113
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["RNIapIos","RNIapIosSk2","RNIapModule","RNIapAmazonModule","NativeModules","isIos","Platform","OS","isAndroid","isAmazon","androidNativeModule","setAndroidNativeModule","nativeModule","checkNativeAndroidAvailable","Error","getAndroidModule","getNativeModule","getIosModule","iosNativeModule","
|
|
1
|
+
{"version":3,"names":["RNIapIos","RNIapIosSk2","RNIapModule","RNIapAmazonModule","NativeModules","isIos","Platform","OS","isAndroid","isAmazon","androidNativeModule","setAndroidNativeModule","nativeModule","checkNativeAndroidAvailable","Error","getAndroidModule","getNativeModule","getIosModule","iosNativeModule","isStorekit2Avaiable","isAvailable","isIosStorekit2","setIosNativeModule","storekit2Mode","disable","console","warn","storekit1Mode","storekitHybridMode","info","checkNativeIOSAvailable"],"sources":["platform.ts"],"sourcesContent":["import {NativeModules, Platform} from 'react-native';\n\nconst {RNIapIos, RNIapIosSk2, RNIapModule, RNIapAmazonModule} = NativeModules;\n\nexport const isIos = Platform.OS === 'ios';\nexport const isAndroid = Platform.OS === 'android';\nexport const isAmazon = isAndroid && !!RNIapAmazonModule;\n\n// Android\n\nlet androidNativeModule = RNIapModule;\n\nexport const setAndroidNativeModule = (\n nativeModule: typeof RNIapModule,\n): void => {\n androidNativeModule = nativeModule;\n};\n\nexport const checkNativeAndroidAvailable = (): void => {\n if (!RNIapModule && !RNIapAmazonModule) {\n throw new Error('IAP_NOT_AVAILABLE');\n }\n};\n\nexport const getAndroidModule = ():\n | typeof RNIapModule\n | typeof RNIapAmazonModule => {\n checkNativeAndroidAvailable();\n\n return androidNativeModule\n ? androidNativeModule\n : RNIapModule\n ? RNIapModule\n : RNIapAmazonModule;\n};\n\nexport const getNativeModule = ():\n | typeof RNIapModule\n | typeof RNIapAmazonModule\n | typeof RNIapIos\n | typeof RNIapIosSk2 => {\n return isAndroid ? getAndroidModule() : getIosModule();\n};\n\n// iOS\n\nlet iosNativeModule: typeof RNIapIos | typeof RNIapIosSk2 = RNIapIos;\n\nexport const isStorekit2Avaiable = (): boolean =>\n RNIapIosSk2?.isAvailable() === 1;\n\nexport const isIosStorekit2 = () =>\n !!iosNativeModule && iosNativeModule === RNIapIosSk2 && isStorekit2Avaiable();\n\nexport const setIosNativeModule = (\n nativeModule: typeof RNIapIos | typeof RNIapIosSk2,\n): void => {\n iosNativeModule = nativeModule;\n};\n\nexport const storekit2Mode = () => {\n iosNativeModule = RNIapIosSk2;\n if (isStorekit2Avaiable()) {\n RNIapIos.disable();\n return true;\n }\n console.warn('Storekit 2 is not available on this device');\n\n return false;\n};\n\nexport const storekit1Mode = () => {\n iosNativeModule = RNIapIos;\n if (isStorekit2Avaiable()) {\n RNIapIosSk2.disable();\n return true;\n }\n return false;\n};\n\nexport const storekitHybridMode = () => {\n if (isStorekit2Avaiable()) {\n iosNativeModule = RNIapIosSk2;\n console.info('Using Storekit 2');\n return true;\n } else {\n iosNativeModule = RNIapIos;\n console.info('Using Storekit 1');\n return true;\n }\n};\n\nconst checkNativeIOSAvailable = (): void => {\n if (!RNIapIos && !isStorekit2Avaiable()) {\n throw new Error('IAP_NOT_AVAILABLE');\n }\n};\n\nexport const getIosModule = (): typeof RNIapIos | typeof RNIapIosSk2 => {\n checkNativeIOSAvailable();\n\n return iosNativeModule\n ? iosNativeModule\n : RNIapIosSk2\n ? RNIapIosSk2\n : RNIapIos;\n};\n"],"mappings":";;;;;;;AAAA;;AAEA,MAAM;EAACA,QAAD;EAAWC,WAAX;EAAwBC,WAAxB;EAAqCC;AAArC,IAA0DC,0BAAhE;AAEO,MAAMC,KAAK,GAAGC,qBAAA,CAASC,EAAT,KAAgB,KAA9B;;AACA,MAAMC,SAAS,GAAGF,qBAAA,CAASC,EAAT,KAAgB,SAAlC;;AACA,MAAME,QAAQ,GAAGD,SAAS,IAAI,CAAC,CAACL,iBAAhC,C,CAEP;;;AAEA,IAAIO,mBAAmB,GAAGR,WAA1B;;AAEO,MAAMS,sBAAsB,GACjCC,YADoC,IAE3B;EACTF,mBAAmB,GAAGE,YAAtB;AACD,CAJM;;;;AAMA,MAAMC,2BAA2B,GAAG,MAAY;EACrD,IAAI,CAACX,WAAD,IAAgB,CAACC,iBAArB,EAAwC;IACtC,MAAM,IAAIW,KAAJ,CAAU,mBAAV,CAAN;EACD;AACF,CAJM;;;;AAMA,MAAMC,gBAAgB,GAAG,MAEA;EAC9BF,2BAA2B;EAE3B,OAAOH,mBAAmB,GACtBA,mBADsB,GAEtBR,WAAW,GACXA,WADW,GAEXC,iBAJJ;AAKD,CAVM;;;;AAYA,MAAMa,eAAe,GAAG,MAIL;EACxB,OAAOR,SAAS,GAAGO,gBAAgB,EAAnB,GAAwBE,YAAY,EAApD;AACD,CANM,C,CAQP;;;;AAEA,IAAIC,eAAqD,GAAGlB,QAA5D;;AAEO,MAAMmB,mBAAmB,GAAG,MACjC,CAAAlB,WAAW,SAAX,IAAAA,WAAW,WAAX,YAAAA,WAAW,CAAEmB,WAAb,QAA+B,CAD1B;;;;AAGA,MAAMC,cAAc,GAAG,MAC5B,CAAC,CAACH,eAAF,IAAqBA,eAAe,KAAKjB,WAAzC,IAAwDkB,mBAAmB,EADtE;;;;AAGA,MAAMG,kBAAkB,GAC7BV,YADgC,IAEvB;EACTM,eAAe,GAAGN,YAAlB;AACD,CAJM;;;;AAMA,MAAMW,aAAa,GAAG,MAAM;EACjCL,eAAe,GAAGjB,WAAlB;;EACA,IAAIkB,mBAAmB,EAAvB,EAA2B;IACzBnB,QAAQ,CAACwB,OAAT;IACA,OAAO,IAAP;EACD;;EACDC,OAAO,CAACC,IAAR,CAAa,4CAAb;EAEA,OAAO,KAAP;AACD,CATM;;;;AAWA,MAAMC,aAAa,GAAG,MAAM;EACjCT,eAAe,GAAGlB,QAAlB;;EACA,IAAImB,mBAAmB,EAAvB,EAA2B;IACzBlB,WAAW,CAACuB,OAAZ;IACA,OAAO,IAAP;EACD;;EACD,OAAO,KAAP;AACD,CAPM;;;;AASA,MAAMI,kBAAkB,GAAG,MAAM;EACtC,IAAIT,mBAAmB,EAAvB,EAA2B;IACzBD,eAAe,GAAGjB,WAAlB;IACAwB,OAAO,CAACI,IAAR,CAAa,kBAAb;IACA,OAAO,IAAP;EACD,CAJD,MAIO;IACLX,eAAe,GAAGlB,QAAlB;IACAyB,OAAO,CAACI,IAAR,CAAa,kBAAb;IACA,OAAO,IAAP;EACD;AACF,CAVM;;;;AAYP,MAAMC,uBAAuB,GAAG,MAAY;EAC1C,IAAI,CAAC9B,QAAD,IAAa,CAACmB,mBAAmB,EAArC,EAAyC;IACvC,MAAM,IAAIL,KAAJ,CAAU,mBAAV,CAAN;EACD;AACF,CAJD;;AAMO,MAAMG,YAAY,GAAG,MAA4C;EACtEa,uBAAuB;EAEvB,OAAOZ,eAAe,GAClBA,eADkB,GAElBjB,WAAW,GACXA,WADW,GAEXD,QAJJ;AAKD,CARM"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["RNIapIosSk2","NativeModules","sync","isEligibleForIntroOffer","groupID","subscriptionStatus","sku","currentEntitlement","latestTransaction"],"sources":["iosSk2.ts"],"sourcesContent":["import {NativeModules} from 'react-native';\n\nimport type {Product, ProductPurchase, Purchase, Sku} from '../types';\nimport type {\n PaymentDiscountSk2,\n ProductSk2,\n ProductStatus,\n TransactionSk2,\n} from '../types/appleSk2';\n\nimport type {NativeModuleProps} from './common';\nconst {RNIapIosSk2} = NativeModules;\n\ntype getItems = (skus: Sku[]) => Promise<ProductSk2[]>;\n\ntype getAvailableItems = (\n alsoPublishToEventListener?: boolean,\n) => Promise<TransactionSk2[]>;\n\nexport type BuyProduct = (\n sku: Sku,\n andDangerouslyFinishTransactionAutomaticallyIOS: boolean,\n applicationUsername: string | undefined,\n quantity: number,\n withOffer: Record<keyof PaymentDiscountSk2, string> | undefined,\n) => Promise<Purchase>;\n\ntype clearTransaction = () => Promise<void>;\ntype clearProducts = () => Promise<void>;\ntype promotedProduct = () => Promise<Product | null>;\ntype buyPromotedProduct = () => Promise<void>;\ntype requestReceipt = (refresh: boolean) => Promise<string>;\n\ntype finishTransaction = (transactionIdentifier: string) => Promise<boolean>;\n\ntype getPendingTransactions = () => Promise<ProductPurchase[]>;\ntype presentCodeRedemptionSheet = () => Promise<null>;\n\nexport interface IosModulePropsSk2 extends NativeModuleProps {\n latestTransaction(sku: string): Promise<TransactionSk2>;\n currentEntitlement(sku: string): Promise<TransactionSk2>;\n subscriptionStatus(sku: string): Promise<ProductStatus[]>;\n isEligibleForIntroOffer(groupID: string): Promise<Boolean>;\n sync(): Promise<null>;\n getItems: getItems;\n getAvailableItems: getAvailableItems;\n buyProduct: BuyProduct;\n clearTransaction: clearTransaction;\n clearProducts: clearProducts;\n promotedProduct: promotedProduct;\n buyPromotedProduct: buyPromotedProduct;\n requestReceipt: requestReceipt;\n finishTransaction: finishTransaction;\n getPendingTransactions: getPendingTransactions;\n presentCodeRedemptionSheet: presentCodeRedemptionSheet;\n disable: () => Promise<null>;\n}\n\n/**\n * Sync state with Appstore (iOS only)\n * https://developer.apple.com/documentation/storekit/appstore/3791906-sync\n */\nexport const sync = (): Promise<null> => RNIapIosSk2.sync();\n\n/**\n *\n */\nexport const isEligibleForIntroOffer = (groupID: string): Promise<Boolean> =>\n RNIapIosSk2.isEligibleForIntroOffer(groupID);\n\n/**\n *\n */\n\nexport const subscriptionStatus = (sku: string): Promise<ProductStatus[]> =>\n RNIapIosSk2.subscriptionStatus(sku);\n\n/**\n *\n */\nexport const currentEntitlement = (sku: string): Promise<TransactionSk2> =>\n RNIapIosSk2.currentEntitlement(sku);\n\n/**\n *\n */\nexport const latestTransaction = (sku: string): Promise<TransactionSk2> =>\n RNIapIosSk2.latestTransaction(sku);\n"],"mappings":";;;;;;;AAAA;;AAWA,MAAM;EAACA;AAAD,IAAgBC,0BAAtB;;
|
|
1
|
+
{"version":3,"names":["RNIapIosSk2","NativeModules","sync","isEligibleForIntroOffer","groupID","subscriptionStatus","sku","currentEntitlement","latestTransaction"],"sources":["iosSk2.ts"],"sourcesContent":["import {NativeModules} from 'react-native';\n\nimport type {Product, ProductPurchase, Purchase, Sku} from '../types';\nimport type {\n PaymentDiscountSk2,\n ProductSk2,\n ProductStatus,\n TransactionSk2,\n} from '../types/appleSk2';\n\nimport type {NativeModuleProps} from './common';\nconst {RNIapIosSk2} = NativeModules;\n\ntype getItems = (skus: Sku[]) => Promise<ProductSk2[]>;\n\ntype getAvailableItems = (\n alsoPublishToEventListener?: boolean,\n) => Promise<TransactionSk2[]>;\n\nexport type BuyProduct = (\n sku: Sku,\n andDangerouslyFinishTransactionAutomaticallyIOS: boolean,\n applicationUsername: string | undefined,\n quantity: number,\n withOffer: Record<keyof PaymentDiscountSk2, string> | undefined,\n) => Promise<Purchase>;\n\ntype clearTransaction = () => Promise<void>;\ntype clearProducts = () => Promise<void>;\ntype promotedProduct = () => Promise<Product | null>;\ntype buyPromotedProduct = () => Promise<void>;\ntype requestReceipt = (refresh: boolean) => Promise<string>;\n\ntype finishTransaction = (transactionIdentifier: string) => Promise<boolean>;\n\ntype getPendingTransactions = () => Promise<ProductPurchase[]>;\ntype presentCodeRedemptionSheet = () => Promise<null>;\n\nexport interface IosModulePropsSk2 extends NativeModuleProps {\n isAvailable(): number;\n latestTransaction(sku: string): Promise<TransactionSk2>;\n currentEntitlement(sku: string): Promise<TransactionSk2>;\n subscriptionStatus(sku: string): Promise<ProductStatus[]>;\n isEligibleForIntroOffer(groupID: string): Promise<Boolean>;\n sync(): Promise<null>;\n getItems: getItems;\n getAvailableItems: getAvailableItems;\n buyProduct: BuyProduct;\n clearTransaction: clearTransaction;\n clearProducts: clearProducts;\n promotedProduct: promotedProduct;\n buyPromotedProduct: buyPromotedProduct;\n requestReceipt: requestReceipt;\n finishTransaction: finishTransaction;\n getPendingTransactions: getPendingTransactions;\n presentCodeRedemptionSheet: presentCodeRedemptionSheet;\n disable: () => Promise<null>;\n}\n\n/**\n * Sync state with Appstore (iOS only)\n * https://developer.apple.com/documentation/storekit/appstore/3791906-sync\n */\nexport const sync = (): Promise<null> => RNIapIosSk2.sync();\n\n/**\n *\n */\nexport const isEligibleForIntroOffer = (groupID: string): Promise<Boolean> =>\n RNIapIosSk2.isEligibleForIntroOffer(groupID);\n\n/**\n *\n */\n\nexport const subscriptionStatus = (sku: string): Promise<ProductStatus[]> =>\n RNIapIosSk2.subscriptionStatus(sku);\n\n/**\n *\n */\nexport const currentEntitlement = (sku: string): Promise<TransactionSk2> =>\n RNIapIosSk2.currentEntitlement(sku);\n\n/**\n *\n */\nexport const latestTransaction = (sku: string): Promise<TransactionSk2> =>\n RNIapIosSk2.latestTransaction(sku);\n"],"mappings":";;;;;;;AAAA;;AAWA,MAAM;EAACA;AAAD,IAAgBC,0BAAtB;;AAgDA;AACA;AACA;AACA;AACO,MAAMC,IAAI,GAAG,MAAqBF,WAAW,CAACE,IAAZ,EAAlC;AAEP;AACA;AACA;;;;;AACO,MAAMC,uBAAuB,GAAIC,OAAD,IACrCJ,WAAW,CAACG,uBAAZ,CAAoCC,OAApC,CADK;AAGP;AACA;AACA;;;;;AAEO,MAAMC,kBAAkB,GAAIC,GAAD,IAChCN,WAAW,CAACK,kBAAZ,CAA+BC,GAA/B,CADK;AAGP;AACA;AACA;;;;;AACO,MAAMC,kBAAkB,GAAID,GAAD,IAChCN,WAAW,CAACO,kBAAZ,CAA+BD,GAA/B,CADK;AAGP;AACA;AACA;;;;;AACO,MAAME,iBAAiB,GAAIF,GAAD,IAC/BN,WAAW,CAACQ,iBAAZ,CAA8BF,GAA9B,CADK"}
|
|
@@ -27,15 +27,15 @@ export const getNativeModule = () => {
|
|
|
27
27
|
}; // iOS
|
|
28
28
|
|
|
29
29
|
let iosNativeModule = RNIapIos;
|
|
30
|
-
export const
|
|
31
|
-
export const
|
|
30
|
+
export const isStorekit2Avaiable = () => (RNIapIosSk2 === null || RNIapIosSk2 === void 0 ? void 0 : RNIapIosSk2.isAvailable()) === 1;
|
|
31
|
+
export const isIosStorekit2 = () => !!iosNativeModule && iosNativeModule === RNIapIosSk2 && isStorekit2Avaiable();
|
|
32
32
|
export const setIosNativeModule = nativeModule => {
|
|
33
33
|
iosNativeModule = nativeModule;
|
|
34
34
|
};
|
|
35
35
|
export const storekit2Mode = () => {
|
|
36
36
|
iosNativeModule = RNIapIosSk2;
|
|
37
37
|
|
|
38
|
-
if (
|
|
38
|
+
if (isStorekit2Avaiable()) {
|
|
39
39
|
RNIapIos.disable();
|
|
40
40
|
return true;
|
|
41
41
|
}
|
|
@@ -46,7 +46,7 @@ export const storekit2Mode = () => {
|
|
|
46
46
|
export const storekit1Mode = () => {
|
|
47
47
|
iosNativeModule = RNIapIos;
|
|
48
48
|
|
|
49
|
-
if (
|
|
49
|
+
if (isStorekit2Avaiable()) {
|
|
50
50
|
RNIapIosSk2.disable();
|
|
51
51
|
return true;
|
|
52
52
|
}
|
|
@@ -54,7 +54,7 @@ export const storekit1Mode = () => {
|
|
|
54
54
|
return false;
|
|
55
55
|
};
|
|
56
56
|
export const storekitHybridMode = () => {
|
|
57
|
-
if (
|
|
57
|
+
if (isStorekit2Avaiable()) {
|
|
58
58
|
iosNativeModule = RNIapIosSk2;
|
|
59
59
|
console.info('Using Storekit 2');
|
|
60
60
|
return true;
|
|
@@ -66,7 +66,7 @@ export const storekitHybridMode = () => {
|
|
|
66
66
|
};
|
|
67
67
|
|
|
68
68
|
const checkNativeIOSAvailable = () => {
|
|
69
|
-
if (!RNIapIos && !
|
|
69
|
+
if (!RNIapIos && !isStorekit2Avaiable()) {
|
|
70
70
|
throw new Error('IAP_NOT_AVAILABLE');
|
|
71
71
|
}
|
|
72
72
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["NativeModules","Platform","RNIapIos","RNIapIosSk2","RNIapModule","RNIapAmazonModule","isIos","OS","isAndroid","isAmazon","androidNativeModule","setAndroidNativeModule","nativeModule","checkNativeAndroidAvailable","Error","getAndroidModule","getNativeModule","getIosModule","iosNativeModule","
|
|
1
|
+
{"version":3,"names":["NativeModules","Platform","RNIapIos","RNIapIosSk2","RNIapModule","RNIapAmazonModule","isIos","OS","isAndroid","isAmazon","androidNativeModule","setAndroidNativeModule","nativeModule","checkNativeAndroidAvailable","Error","getAndroidModule","getNativeModule","getIosModule","iosNativeModule","isStorekit2Avaiable","isAvailable","isIosStorekit2","setIosNativeModule","storekit2Mode","disable","console","warn","storekit1Mode","storekitHybridMode","info","checkNativeIOSAvailable"],"sources":["platform.ts"],"sourcesContent":["import {NativeModules, Platform} from 'react-native';\n\nconst {RNIapIos, RNIapIosSk2, RNIapModule, RNIapAmazonModule} = NativeModules;\n\nexport const isIos = Platform.OS === 'ios';\nexport const isAndroid = Platform.OS === 'android';\nexport const isAmazon = isAndroid && !!RNIapAmazonModule;\n\n// Android\n\nlet androidNativeModule = RNIapModule;\n\nexport const setAndroidNativeModule = (\n nativeModule: typeof RNIapModule,\n): void => {\n androidNativeModule = nativeModule;\n};\n\nexport const checkNativeAndroidAvailable = (): void => {\n if (!RNIapModule && !RNIapAmazonModule) {\n throw new Error('IAP_NOT_AVAILABLE');\n }\n};\n\nexport const getAndroidModule = ():\n | typeof RNIapModule\n | typeof RNIapAmazonModule => {\n checkNativeAndroidAvailable();\n\n return androidNativeModule\n ? androidNativeModule\n : RNIapModule\n ? RNIapModule\n : RNIapAmazonModule;\n};\n\nexport const getNativeModule = ():\n | typeof RNIapModule\n | typeof RNIapAmazonModule\n | typeof RNIapIos\n | typeof RNIapIosSk2 => {\n return isAndroid ? getAndroidModule() : getIosModule();\n};\n\n// iOS\n\nlet iosNativeModule: typeof RNIapIos | typeof RNIapIosSk2 = RNIapIos;\n\nexport const isStorekit2Avaiable = (): boolean =>\n RNIapIosSk2?.isAvailable() === 1;\n\nexport const isIosStorekit2 = () =>\n !!iosNativeModule && iosNativeModule === RNIapIosSk2 && isStorekit2Avaiable();\n\nexport const setIosNativeModule = (\n nativeModule: typeof RNIapIos | typeof RNIapIosSk2,\n): void => {\n iosNativeModule = nativeModule;\n};\n\nexport const storekit2Mode = () => {\n iosNativeModule = RNIapIosSk2;\n if (isStorekit2Avaiable()) {\n RNIapIos.disable();\n return true;\n }\n console.warn('Storekit 2 is not available on this device');\n\n return false;\n};\n\nexport const storekit1Mode = () => {\n iosNativeModule = RNIapIos;\n if (isStorekit2Avaiable()) {\n RNIapIosSk2.disable();\n return true;\n }\n return false;\n};\n\nexport const storekitHybridMode = () => {\n if (isStorekit2Avaiable()) {\n iosNativeModule = RNIapIosSk2;\n console.info('Using Storekit 2');\n return true;\n } else {\n iosNativeModule = RNIapIos;\n console.info('Using Storekit 1');\n return true;\n }\n};\n\nconst checkNativeIOSAvailable = (): void => {\n if (!RNIapIos && !isStorekit2Avaiable()) {\n throw new Error('IAP_NOT_AVAILABLE');\n }\n};\n\nexport const getIosModule = (): typeof RNIapIos | typeof RNIapIosSk2 => {\n checkNativeIOSAvailable();\n\n return iosNativeModule\n ? iosNativeModule\n : RNIapIosSk2\n ? RNIapIosSk2\n : RNIapIos;\n};\n"],"mappings":"AAAA,SAAQA,aAAR,EAAuBC,QAAvB,QAAsC,cAAtC;AAEA,MAAM;EAACC,QAAD;EAAWC,WAAX;EAAwBC,WAAxB;EAAqCC;AAArC,IAA0DL,aAAhE;AAEA,OAAO,MAAMM,KAAK,GAAGL,QAAQ,CAACM,EAAT,KAAgB,KAA9B;AACP,OAAO,MAAMC,SAAS,GAAGP,QAAQ,CAACM,EAAT,KAAgB,SAAlC;AACP,OAAO,MAAME,QAAQ,GAAGD,SAAS,IAAI,CAAC,CAACH,iBAAhC,C,CAEP;;AAEA,IAAIK,mBAAmB,GAAGN,WAA1B;AAEA,OAAO,MAAMO,sBAAsB,GACjCC,YADoC,IAE3B;EACTF,mBAAmB,GAAGE,YAAtB;AACD,CAJM;AAMP,OAAO,MAAMC,2BAA2B,GAAG,MAAY;EACrD,IAAI,CAACT,WAAD,IAAgB,CAACC,iBAArB,EAAwC;IACtC,MAAM,IAAIS,KAAJ,CAAU,mBAAV,CAAN;EACD;AACF,CAJM;AAMP,OAAO,MAAMC,gBAAgB,GAAG,MAEA;EAC9BF,2BAA2B;EAE3B,OAAOH,mBAAmB,GACtBA,mBADsB,GAEtBN,WAAW,GACXA,WADW,GAEXC,iBAJJ;AAKD,CAVM;AAYP,OAAO,MAAMW,eAAe,GAAG,MAIL;EACxB,OAAOR,SAAS,GAAGO,gBAAgB,EAAnB,GAAwBE,YAAY,EAApD;AACD,CANM,C,CAQP;;AAEA,IAAIC,eAAqD,GAAGhB,QAA5D;AAEA,OAAO,MAAMiB,mBAAmB,GAAG,MACjC,CAAAhB,WAAW,SAAX,IAAAA,WAAW,WAAX,YAAAA,WAAW,CAAEiB,WAAb,QAA+B,CAD1B;AAGP,OAAO,MAAMC,cAAc,GAAG,MAC5B,CAAC,CAACH,eAAF,IAAqBA,eAAe,KAAKf,WAAzC,IAAwDgB,mBAAmB,EADtE;AAGP,OAAO,MAAMG,kBAAkB,GAC7BV,YADgC,IAEvB;EACTM,eAAe,GAAGN,YAAlB;AACD,CAJM;AAMP,OAAO,MAAMW,aAAa,GAAG,MAAM;EACjCL,eAAe,GAAGf,WAAlB;;EACA,IAAIgB,mBAAmB,EAAvB,EAA2B;IACzBjB,QAAQ,CAACsB,OAAT;IACA,OAAO,IAAP;EACD;;EACDC,OAAO,CAACC,IAAR,CAAa,4CAAb;EAEA,OAAO,KAAP;AACD,CATM;AAWP,OAAO,MAAMC,aAAa,GAAG,MAAM;EACjCT,eAAe,GAAGhB,QAAlB;;EACA,IAAIiB,mBAAmB,EAAvB,EAA2B;IACzBhB,WAAW,CAACqB,OAAZ;IACA,OAAO,IAAP;EACD;;EACD,OAAO,KAAP;AACD,CAPM;AASP,OAAO,MAAMI,kBAAkB,GAAG,MAAM;EACtC,IAAIT,mBAAmB,EAAvB,EAA2B;IACzBD,eAAe,GAAGf,WAAlB;IACAsB,OAAO,CAACI,IAAR,CAAa,kBAAb;IACA,OAAO,IAAP;EACD,CAJD,MAIO;IACLX,eAAe,GAAGhB,QAAlB;IACAuB,OAAO,CAACI,IAAR,CAAa,kBAAb;IACA,OAAO,IAAP;EACD;AACF,CAVM;;AAYP,MAAMC,uBAAuB,GAAG,MAAY;EAC1C,IAAI,CAAC5B,QAAD,IAAa,CAACiB,mBAAmB,EAArC,EAAyC;IACvC,MAAM,IAAIL,KAAJ,CAAU,mBAAV,CAAN;EACD;AACF,CAJD;;AAMA,OAAO,MAAMG,YAAY,GAAG,MAA4C;EACtEa,uBAAuB;EAEvB,OAAOZ,eAAe,GAClBA,eADkB,GAElBf,WAAW,GACXA,WADW,GAEXD,QAJJ;AAKD,CARM"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["NativeModules","RNIapIosSk2","sync","isEligibleForIntroOffer","groupID","subscriptionStatus","sku","currentEntitlement","latestTransaction"],"sources":["iosSk2.ts"],"sourcesContent":["import {NativeModules} from 'react-native';\n\nimport type {Product, ProductPurchase, Purchase, Sku} from '../types';\nimport type {\n PaymentDiscountSk2,\n ProductSk2,\n ProductStatus,\n TransactionSk2,\n} from '../types/appleSk2';\n\nimport type {NativeModuleProps} from './common';\nconst {RNIapIosSk2} = NativeModules;\n\ntype getItems = (skus: Sku[]) => Promise<ProductSk2[]>;\n\ntype getAvailableItems = (\n alsoPublishToEventListener?: boolean,\n) => Promise<TransactionSk2[]>;\n\nexport type BuyProduct = (\n sku: Sku,\n andDangerouslyFinishTransactionAutomaticallyIOS: boolean,\n applicationUsername: string | undefined,\n quantity: number,\n withOffer: Record<keyof PaymentDiscountSk2, string> | undefined,\n) => Promise<Purchase>;\n\ntype clearTransaction = () => Promise<void>;\ntype clearProducts = () => Promise<void>;\ntype promotedProduct = () => Promise<Product | null>;\ntype buyPromotedProduct = () => Promise<void>;\ntype requestReceipt = (refresh: boolean) => Promise<string>;\n\ntype finishTransaction = (transactionIdentifier: string) => Promise<boolean>;\n\ntype getPendingTransactions = () => Promise<ProductPurchase[]>;\ntype presentCodeRedemptionSheet = () => Promise<null>;\n\nexport interface IosModulePropsSk2 extends NativeModuleProps {\n latestTransaction(sku: string): Promise<TransactionSk2>;\n currentEntitlement(sku: string): Promise<TransactionSk2>;\n subscriptionStatus(sku: string): Promise<ProductStatus[]>;\n isEligibleForIntroOffer(groupID: string): Promise<Boolean>;\n sync(): Promise<null>;\n getItems: getItems;\n getAvailableItems: getAvailableItems;\n buyProduct: BuyProduct;\n clearTransaction: clearTransaction;\n clearProducts: clearProducts;\n promotedProduct: promotedProduct;\n buyPromotedProduct: buyPromotedProduct;\n requestReceipt: requestReceipt;\n finishTransaction: finishTransaction;\n getPendingTransactions: getPendingTransactions;\n presentCodeRedemptionSheet: presentCodeRedemptionSheet;\n disable: () => Promise<null>;\n}\n\n/**\n * Sync state with Appstore (iOS only)\n * https://developer.apple.com/documentation/storekit/appstore/3791906-sync\n */\nexport const sync = (): Promise<null> => RNIapIosSk2.sync();\n\n/**\n *\n */\nexport const isEligibleForIntroOffer = (groupID: string): Promise<Boolean> =>\n RNIapIosSk2.isEligibleForIntroOffer(groupID);\n\n/**\n *\n */\n\nexport const subscriptionStatus = (sku: string): Promise<ProductStatus[]> =>\n RNIapIosSk2.subscriptionStatus(sku);\n\n/**\n *\n */\nexport const currentEntitlement = (sku: string): Promise<TransactionSk2> =>\n RNIapIosSk2.currentEntitlement(sku);\n\n/**\n *\n */\nexport const latestTransaction = (sku: string): Promise<TransactionSk2> =>\n RNIapIosSk2.latestTransaction(sku);\n"],"mappings":"AAAA,SAAQA,aAAR,QAA4B,cAA5B;AAWA,MAAM;EAACC;AAAD,IAAgBD,aAAtB;;
|
|
1
|
+
{"version":3,"names":["NativeModules","RNIapIosSk2","sync","isEligibleForIntroOffer","groupID","subscriptionStatus","sku","currentEntitlement","latestTransaction"],"sources":["iosSk2.ts"],"sourcesContent":["import {NativeModules} from 'react-native';\n\nimport type {Product, ProductPurchase, Purchase, Sku} from '../types';\nimport type {\n PaymentDiscountSk2,\n ProductSk2,\n ProductStatus,\n TransactionSk2,\n} from '../types/appleSk2';\n\nimport type {NativeModuleProps} from './common';\nconst {RNIapIosSk2} = NativeModules;\n\ntype getItems = (skus: Sku[]) => Promise<ProductSk2[]>;\n\ntype getAvailableItems = (\n alsoPublishToEventListener?: boolean,\n) => Promise<TransactionSk2[]>;\n\nexport type BuyProduct = (\n sku: Sku,\n andDangerouslyFinishTransactionAutomaticallyIOS: boolean,\n applicationUsername: string | undefined,\n quantity: number,\n withOffer: Record<keyof PaymentDiscountSk2, string> | undefined,\n) => Promise<Purchase>;\n\ntype clearTransaction = () => Promise<void>;\ntype clearProducts = () => Promise<void>;\ntype promotedProduct = () => Promise<Product | null>;\ntype buyPromotedProduct = () => Promise<void>;\ntype requestReceipt = (refresh: boolean) => Promise<string>;\n\ntype finishTransaction = (transactionIdentifier: string) => Promise<boolean>;\n\ntype getPendingTransactions = () => Promise<ProductPurchase[]>;\ntype presentCodeRedemptionSheet = () => Promise<null>;\n\nexport interface IosModulePropsSk2 extends NativeModuleProps {\n isAvailable(): number;\n latestTransaction(sku: string): Promise<TransactionSk2>;\n currentEntitlement(sku: string): Promise<TransactionSk2>;\n subscriptionStatus(sku: string): Promise<ProductStatus[]>;\n isEligibleForIntroOffer(groupID: string): Promise<Boolean>;\n sync(): Promise<null>;\n getItems: getItems;\n getAvailableItems: getAvailableItems;\n buyProduct: BuyProduct;\n clearTransaction: clearTransaction;\n clearProducts: clearProducts;\n promotedProduct: promotedProduct;\n buyPromotedProduct: buyPromotedProduct;\n requestReceipt: requestReceipt;\n finishTransaction: finishTransaction;\n getPendingTransactions: getPendingTransactions;\n presentCodeRedemptionSheet: presentCodeRedemptionSheet;\n disable: () => Promise<null>;\n}\n\n/**\n * Sync state with Appstore (iOS only)\n * https://developer.apple.com/documentation/storekit/appstore/3791906-sync\n */\nexport const sync = (): Promise<null> => RNIapIosSk2.sync();\n\n/**\n *\n */\nexport const isEligibleForIntroOffer = (groupID: string): Promise<Boolean> =>\n RNIapIosSk2.isEligibleForIntroOffer(groupID);\n\n/**\n *\n */\n\nexport const subscriptionStatus = (sku: string): Promise<ProductStatus[]> =>\n RNIapIosSk2.subscriptionStatus(sku);\n\n/**\n *\n */\nexport const currentEntitlement = (sku: string): Promise<TransactionSk2> =>\n RNIapIosSk2.currentEntitlement(sku);\n\n/**\n *\n */\nexport const latestTransaction = (sku: string): Promise<TransactionSk2> =>\n RNIapIosSk2.latestTransaction(sku);\n"],"mappings":"AAAA,SAAQA,aAAR,QAA4B,cAA5B;AAWA,MAAM;EAACC;AAAD,IAAgBD,aAAtB;;AAgDA;AACA;AACA;AACA;AACA,OAAO,MAAME,IAAI,GAAG,MAAqBD,WAAW,CAACC,IAAZ,EAAlC;AAEP;AACA;AACA;;AACA,OAAO,MAAMC,uBAAuB,GAAIC,OAAD,IACrCH,WAAW,CAACE,uBAAZ,CAAoCC,OAApC,CADK;AAGP;AACA;AACA;;AAEA,OAAO,MAAMC,kBAAkB,GAAIC,GAAD,IAChCL,WAAW,CAACI,kBAAZ,CAA+BC,GAA/B,CADK;AAGP;AACA;AACA;;AACA,OAAO,MAAMC,kBAAkB,GAAID,GAAD,IAChCL,WAAW,CAACM,kBAAZ,CAA+BD,GAA/B,CADK;AAGP;AACA;AACA;;AACA,OAAO,MAAME,iBAAiB,GAAIF,GAAD,IAC/BL,WAAW,CAACO,iBAAZ,CAA8BF,GAA9B,CADK"}
|
|
@@ -5,8 +5,8 @@ export declare const setAndroidNativeModule: (nativeModule: import("..").Android
|
|
|
5
5
|
export declare const checkNativeAndroidAvailable: () => void;
|
|
6
6
|
export declare const getAndroidModule: () => import("..").AmazonModuleProps | import("..").AndroidModuleProps;
|
|
7
7
|
export declare const getNativeModule: () => import("..").AmazonModuleProps | import("..").IosModuleProps | import("../modules/iosSk2").IosModulePropsSk2 | import("..").AndroidModuleProps;
|
|
8
|
-
export declare const isIosStorekit2: () => boolean;
|
|
9
8
|
export declare const isStorekit2Avaiable: () => boolean;
|
|
9
|
+
export declare const isIosStorekit2: () => boolean;
|
|
10
10
|
export declare const setIosNativeModule: (nativeModule: import("..").IosModuleProps | import("../modules/iosSk2").IosModulePropsSk2) => void;
|
|
11
11
|
export declare const storekit2Mode: () => boolean;
|
|
12
12
|
export declare const storekit1Mode: () => boolean;
|
|
@@ -13,6 +13,7 @@ declare type finishTransaction = (transactionIdentifier: string) => Promise<bool
|
|
|
13
13
|
declare type getPendingTransactions = () => Promise<ProductPurchase[]>;
|
|
14
14
|
declare type presentCodeRedemptionSheet = () => Promise<null>;
|
|
15
15
|
export interface IosModulePropsSk2 extends NativeModuleProps {
|
|
16
|
+
isAvailable(): number;
|
|
16
17
|
latestTransaction(sku: string): Promise<TransactionSk2>;
|
|
17
18
|
currentEntitlement(sku: string): Promise<TransactionSk2>;
|
|
18
19
|
subscriptionStatus(sku: string): Promise<ProductStatus[]>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-iap",
|
|
3
|
-
"version": "11.0.0-rc.
|
|
3
|
+
"version": "11.0.0-rc.7",
|
|
4
4
|
"description": "React Native In App Purchase Module.",
|
|
5
5
|
"repository": "https://github.com/dooboolab/react-native-iap",
|
|
6
6
|
"author": "dooboolab <support@dooboolab.com> (https://github.com/dooboolab)",
|
package/src/internal/platform.ts
CHANGED
|
@@ -46,10 +46,11 @@ export const getNativeModule = ():
|
|
|
46
46
|
|
|
47
47
|
let iosNativeModule: typeof RNIapIos | typeof RNIapIosSk2 = RNIapIos;
|
|
48
48
|
|
|
49
|
-
export const
|
|
50
|
-
|
|
49
|
+
export const isStorekit2Avaiable = (): boolean =>
|
|
50
|
+
RNIapIosSk2?.isAvailable() === 1;
|
|
51
51
|
|
|
52
|
-
export const
|
|
52
|
+
export const isIosStorekit2 = () =>
|
|
53
|
+
!!iosNativeModule && iosNativeModule === RNIapIosSk2 && isStorekit2Avaiable();
|
|
53
54
|
|
|
54
55
|
export const setIosNativeModule = (
|
|
55
56
|
nativeModule: typeof RNIapIos | typeof RNIapIosSk2,
|
|
@@ -59,7 +60,7 @@ export const setIosNativeModule = (
|
|
|
59
60
|
|
|
60
61
|
export const storekit2Mode = () => {
|
|
61
62
|
iosNativeModule = RNIapIosSk2;
|
|
62
|
-
if (
|
|
63
|
+
if (isStorekit2Avaiable()) {
|
|
63
64
|
RNIapIos.disable();
|
|
64
65
|
return true;
|
|
65
66
|
}
|
|
@@ -70,7 +71,7 @@ export const storekit2Mode = () => {
|
|
|
70
71
|
|
|
71
72
|
export const storekit1Mode = () => {
|
|
72
73
|
iosNativeModule = RNIapIos;
|
|
73
|
-
if (
|
|
74
|
+
if (isStorekit2Avaiable()) {
|
|
74
75
|
RNIapIosSk2.disable();
|
|
75
76
|
return true;
|
|
76
77
|
}
|
|
@@ -78,7 +79,7 @@ export const storekit1Mode = () => {
|
|
|
78
79
|
};
|
|
79
80
|
|
|
80
81
|
export const storekitHybridMode = () => {
|
|
81
|
-
if (
|
|
82
|
+
if (isStorekit2Avaiable()) {
|
|
82
83
|
iosNativeModule = RNIapIosSk2;
|
|
83
84
|
console.info('Using Storekit 2');
|
|
84
85
|
return true;
|
|
@@ -90,7 +91,7 @@ export const storekitHybridMode = () => {
|
|
|
90
91
|
};
|
|
91
92
|
|
|
92
93
|
const checkNativeIOSAvailable = (): void => {
|
|
93
|
-
if (!RNIapIos && !
|
|
94
|
+
if (!RNIapIos && !isStorekit2Avaiable()) {
|
|
94
95
|
throw new Error('IAP_NOT_AVAILABLE');
|
|
95
96
|
}
|
|
96
97
|
};
|
package/src/modules/iosSk2.ts
CHANGED
|
@@ -37,6 +37,7 @@ type getPendingTransactions = () => Promise<ProductPurchase[]>;
|
|
|
37
37
|
type presentCodeRedemptionSheet = () => Promise<null>;
|
|
38
38
|
|
|
39
39
|
export interface IosModulePropsSk2 extends NativeModuleProps {
|
|
40
|
+
isAvailable(): number;
|
|
40
41
|
latestTransaction(sku: string): Promise<TransactionSk2>;
|
|
41
42
|
currentEntitlement(sku: string): Promise<TransactionSk2>;
|
|
42
43
|
subscriptionStatus(sku: string): Promise<ProductStatus[]>;
|