react-native-iap 9.0.0-rc.1 → 9.0.0-rc.4
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/android/src/amazon/java/com/dooboolab/RNIap/RNIapAmazonModule.kt +0 -5
- package/android/src/play/java/com/dooboolab/RNIap/RNIapModule.kt +90 -82
- package/ios/RNIapIos.swift +30 -17
- package/lib/commonjs/iap.js +22 -7
- package/lib/commonjs/iap.js.map +1 -1
- package/lib/commonjs/types/index.js.map +1 -1
- package/lib/module/iap.js +22 -7
- package/lib/module/iap.js.map +1 -1
- package/lib/module/types/index.js.map +1 -1
- package/lib/typescript/iap.d.ts +5 -4
- package/lib/typescript/types/index.d.ts +39 -20
- package/package.json +1 -1
- package/src/iap.ts +30 -14
- package/src/types/index.ts +45 -20
|
@@ -69,12 +69,7 @@ class RNIapAmazonModule(reactContext: ReactApplicationContext) :
|
|
|
69
69
|
|
|
70
70
|
@ReactMethod
|
|
71
71
|
fun buyItemByType(
|
|
72
|
-
type: String?,
|
|
73
72
|
sku: String?,
|
|
74
|
-
purchaseToken: String?,
|
|
75
|
-
prorationMode: Int?,
|
|
76
|
-
obfuscatedAccountId: String?,
|
|
77
|
-
obfuscatedProfileId: String?,
|
|
78
73
|
promise: Promise
|
|
79
74
|
) {
|
|
80
75
|
DoobooUtils.instance.addPromiseForKey(PROMISE_BUY_ITEM, promise)
|
|
@@ -87,7 +87,7 @@ class RNIapModule(
|
|
|
87
87
|
}
|
|
88
88
|
|
|
89
89
|
@ReactMethod
|
|
90
|
-
|
|
90
|
+
fun initConnection(promise: Promise) {
|
|
91
91
|
if (googleApiAvailability.isGooglePlayServicesAvailable(reactContext)
|
|
92
92
|
!= ConnectionResult.SUCCESS
|
|
93
93
|
) {
|
|
@@ -108,13 +108,13 @@ class RNIapModule(
|
|
|
108
108
|
billingClientCache = it
|
|
109
109
|
it.startConnection(
|
|
110
110
|
object : BillingClientStateListener {
|
|
111
|
-
|
|
111
|
+
override fun onBillingSetupFinished(billingResult: BillingResult) {
|
|
112
112
|
if (!isValidResult(billingResult, promise)) return
|
|
113
113
|
|
|
114
114
|
promise.safeResolve(true)
|
|
115
115
|
}
|
|
116
116
|
|
|
117
|
-
|
|
117
|
+
override fun onBillingServiceDisconnected() {
|
|
118
118
|
Log.i(TAG, "Billing service disconnected")
|
|
119
119
|
}
|
|
120
120
|
}
|
|
@@ -123,7 +123,7 @@ class RNIapModule(
|
|
|
123
123
|
}
|
|
124
124
|
|
|
125
125
|
@ReactMethod
|
|
126
|
-
|
|
126
|
+
fun endConnection(promise: Promise) {
|
|
127
127
|
billingClientCache?.endConnection()
|
|
128
128
|
billingClientCache = null
|
|
129
129
|
promise.safeResolve(true)
|
|
@@ -160,7 +160,7 @@ class RNIapModule(
|
|
|
160
160
|
}
|
|
161
161
|
|
|
162
162
|
@ReactMethod
|
|
163
|
-
|
|
163
|
+
fun flushFailedPurchasesCachedAsPending(promise: Promise) {
|
|
164
164
|
ensureConnection(
|
|
165
165
|
promise
|
|
166
166
|
) { billingClient ->
|
|
@@ -193,15 +193,14 @@ class RNIapModule(
|
|
|
193
193
|
}
|
|
194
194
|
|
|
195
195
|
@ReactMethod
|
|
196
|
-
|
|
196
|
+
fun getItemsByType(type: String, skuArr: ReadableArray, promise: Promise) {
|
|
197
197
|
ensureConnection(
|
|
198
198
|
promise
|
|
199
199
|
) { billingClient ->
|
|
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
|
-
|
|
204
|
-
sku?.let {
|
|
203
|
+
skuArr.getString(i)?.let { sku -> // null check for older versions of RN
|
|
205
204
|
skuList.add(
|
|
206
205
|
QueryProductDetailsParams.Product.newBuilder().setProductId(sku)
|
|
207
206
|
.setProductType(type).build()
|
|
@@ -236,52 +235,53 @@ class RNIapModule(
|
|
|
236
235
|
"priceAmountMicros",
|
|
237
236
|
it.priceAmountMicros.toString()
|
|
238
237
|
)
|
|
238
|
+
item.putMap("oneTimePurchaseOfferDetails", oneTimePurchaseOfferDetails)
|
|
239
239
|
}
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
subscriptionOfferDetailsItem.offerToken
|
|
248
|
-
)
|
|
249
|
-
val offerTags = Arguments.createArray()
|
|
250
|
-
subscriptionOfferDetailsItem.offerTags.forEach { offerTag ->
|
|
251
|
-
offerTags.pushString(offerTag)
|
|
252
|
-
}
|
|
253
|
-
offerDetails.putArray("offerTags", offerTags)
|
|
254
|
-
|
|
255
|
-
val pricingPhasesList = Arguments.createArray()
|
|
256
|
-
subscriptionOfferDetailsItem.pricingPhases.pricingPhaseList.forEach { pricingPhaseItem ->
|
|
257
|
-
val pricingPhase = Arguments.createMap()
|
|
258
|
-
pricingPhase.putString(
|
|
259
|
-
"formattedPrice",
|
|
260
|
-
pricingPhaseItem.formattedPrice
|
|
261
|
-
)
|
|
262
|
-
pricingPhase.putString(
|
|
263
|
-
"priceCurrencyCode",
|
|
264
|
-
pricingPhaseItem.priceCurrencyCode
|
|
265
|
-
)
|
|
266
|
-
pricingPhase.putString("billingPeriod", pricingPhaseItem.billingPeriod)
|
|
267
|
-
pricingPhase.putInt(
|
|
268
|
-
"billingCycleCount",
|
|
269
|
-
pricingPhaseItem.billingCycleCount
|
|
240
|
+
skuDetails.subscriptionOfferDetails?.let {
|
|
241
|
+
val subscriptionOfferDetails = Arguments.createArray()
|
|
242
|
+
it.forEach { subscriptionOfferDetailsItem ->
|
|
243
|
+
val offerDetails = Arguments.createMap()
|
|
244
|
+
offerDetails.putString(
|
|
245
|
+
"offerToken",
|
|
246
|
+
subscriptionOfferDetailsItem.offerToken
|
|
270
247
|
)
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
pricingPhasesList.
|
|
248
|
+
val offerTags = Arguments.createArray()
|
|
249
|
+
subscriptionOfferDetailsItem.offerTags.forEach { offerTag ->
|
|
250
|
+
offerTags.pushString(offerTag)
|
|
251
|
+
}
|
|
252
|
+
offerDetails.putArray("offerTags", offerTags)
|
|
253
|
+
|
|
254
|
+
val pricingPhasesList = Arguments.createArray()
|
|
255
|
+
subscriptionOfferDetailsItem.pricingPhases.pricingPhaseList.forEach { pricingPhaseItem ->
|
|
256
|
+
val pricingPhase = Arguments.createMap()
|
|
257
|
+
pricingPhase.putString(
|
|
258
|
+
"formattedPrice",
|
|
259
|
+
pricingPhaseItem.formattedPrice
|
|
260
|
+
)
|
|
261
|
+
pricingPhase.putString(
|
|
262
|
+
"priceCurrencyCode",
|
|
263
|
+
pricingPhaseItem.priceCurrencyCode
|
|
264
|
+
)
|
|
265
|
+
pricingPhase.putString("billingPeriod", pricingPhaseItem.billingPeriod)
|
|
266
|
+
pricingPhase.putInt(
|
|
267
|
+
"billingCycleCount",
|
|
268
|
+
pricingPhaseItem.billingCycleCount
|
|
269
|
+
)
|
|
270
|
+
pricingPhase.putString(
|
|
271
|
+
"priceAmountMicros",
|
|
272
|
+
pricingPhaseItem.priceAmountMicros.toString()
|
|
273
|
+
)
|
|
274
|
+
pricingPhase.putInt("recurrenceMode", pricingPhaseItem.recurrenceMode)
|
|
275
|
+
|
|
276
|
+
pricingPhasesList.pushMap(pricingPhase)
|
|
277
|
+
}
|
|
278
|
+
val pricingPhases = Arguments.createMap()
|
|
279
|
+
pricingPhases.putArray("pricingPhaseList", pricingPhasesList)
|
|
280
|
+
offerDetails.putMap("pricingPhases", pricingPhases)
|
|
281
|
+
subscriptionOfferDetails.pushMap(offerDetails)
|
|
278
282
|
}
|
|
279
|
-
|
|
280
|
-
pricingPhases.putArray("pricingPhaseList", pricingPhasesList)
|
|
281
|
-
offerDetails.putMap("pricingPhases", pricingPhases)
|
|
282
|
-
subscriptionOfferDetails.pushMap(offerDetails)
|
|
283
|
+
item.putArray("subscriptionOfferDetails", subscriptionOfferDetails)
|
|
283
284
|
}
|
|
284
|
-
item.putArray("subscriptionOfferDetails", subscriptionOfferDetails)
|
|
285
285
|
items.pushMap(item)
|
|
286
286
|
}
|
|
287
287
|
promise.safeResolve(items)
|
|
@@ -319,7 +319,7 @@ class RNIapModule(
|
|
|
319
319
|
if (!isValidResult(billingResult, promise)) return@queryPurchasesAsync
|
|
320
320
|
purchases?.forEach { purchase ->
|
|
321
321
|
val item = WritableNativeMap()
|
|
322
|
-
item.putString("productId", purchase.products[0])// kept for convenience/backward-compatibility. productIds has the complete list
|
|
322
|
+
item.putString("productId", purchase.products[0]) // kept for convenience/backward-compatibility. productIds has the complete list
|
|
323
323
|
val products = Arguments.createArray()
|
|
324
324
|
purchase.products.forEach { products.pushString(it) }
|
|
325
325
|
item.putArray("productIds", products)
|
|
@@ -345,7 +345,7 @@ class RNIapModule(
|
|
|
345
345
|
item.putBoolean("autoRenewingAndroid", purchase.isAutoRenewing)
|
|
346
346
|
}
|
|
347
347
|
items.pushMap(item)
|
|
348
|
-
|
|
348
|
+
}
|
|
349
349
|
promise.safeResolve(items)
|
|
350
350
|
}
|
|
351
351
|
}
|
|
@@ -394,7 +394,8 @@ class RNIapModule(
|
|
|
394
394
|
prorationMode: Int,
|
|
395
395
|
obfuscatedAccountId: String?,
|
|
396
396
|
obfuscatedProfileId: String?,
|
|
397
|
-
|
|
397
|
+
offerTokenArr: ReadableArray, // New parameter in V5
|
|
398
|
+
isOfferPersonalized: Boolean, // New parameter in V5
|
|
398
399
|
promise: Promise
|
|
399
400
|
) {
|
|
400
401
|
val activity = currentActivity
|
|
@@ -409,36 +410,43 @@ class RNIapModule(
|
|
|
409
410
|
PROMISE_BUY_ITEM,
|
|
410
411
|
promise
|
|
411
412
|
)
|
|
413
|
+
if (type == BillingClient.ProductType.SUBS && skuArr.size() != offerTokenArr.size()) {
|
|
414
|
+
val debugMessage =
|
|
415
|
+
"The number of skus (${skuArr.size()}) must match: the number of offerTokens (${offerTokenArr.size()}) for Subscriptions"
|
|
416
|
+
val error = Arguments.createMap()
|
|
417
|
+
error.putString("debugMessage", debugMessage)
|
|
418
|
+
error.putString("code", PROMISE_BUY_ITEM)
|
|
419
|
+
error.putString("message", debugMessage)
|
|
420
|
+
sendEvent(reactContext, "purchase-error", error)
|
|
421
|
+
promise.safeReject(PROMISE_BUY_ITEM, debugMessage)
|
|
422
|
+
return@ensureConnection
|
|
423
|
+
}
|
|
412
424
|
val productParamsList =
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
val offerToken =
|
|
435
|
-
selectedSku.subscriptionOfferDetails?.get(selectedOfferIndex)?.offerToken
|
|
436
|
-
offerToken?.let { productParams = productParams.setOfferToken(offerToken) }
|
|
425
|
+
skuArr.toArrayList().map { it.toString() }.mapIndexed { index, sku ->
|
|
426
|
+
val selectedSku: ProductDetails? = skus[sku]
|
|
427
|
+
if (selectedSku == null) {
|
|
428
|
+
val debugMessage =
|
|
429
|
+
"The sku was not found. Please fetch products first by calling getItems"
|
|
430
|
+
val error = Arguments.createMap()
|
|
431
|
+
error.putString("debugMessage", debugMessage)
|
|
432
|
+
error.putString("code", PROMISE_BUY_ITEM)
|
|
433
|
+
error.putString("message", debugMessage)
|
|
434
|
+
error.putString("productId", sku)
|
|
435
|
+
sendEvent(reactContext, "purchase-error", error)
|
|
436
|
+
promise.safeReject(PROMISE_BUY_ITEM, debugMessage)
|
|
437
|
+
return@ensureConnection
|
|
438
|
+
}
|
|
439
|
+
var productDetailParams = BillingFlowParams.ProductDetailsParams.newBuilder().setProductDetails(selectedSku)
|
|
440
|
+
if (type == BillingClient.ProductType.SUBS) {
|
|
441
|
+
offerTokenArr.getString(index)?.let { offerToken -> // null check for older versions of RN
|
|
442
|
+
productDetailParams = productDetailParams.setOfferToken(offerToken)
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
productDetailParams.build()
|
|
437
446
|
}
|
|
438
|
-
productParams.build()
|
|
439
|
-
}
|
|
440
447
|
val builder = BillingFlowParams.newBuilder()
|
|
441
|
-
builder.setProductDetailsParamsList(productParamsList)
|
|
448
|
+
builder.setProductDetailsParamsList(productParamsList).setIsOfferPersonalized(isOfferPersonalized)
|
|
449
|
+
|
|
442
450
|
val subscriptionUpdateParamsBuilder = SubscriptionUpdateParams.newBuilder()
|
|
443
451
|
if (purchaseToken != null) {
|
|
444
452
|
subscriptionUpdateParamsBuilder.setOldPurchaseToken(purchaseToken)
|
|
@@ -568,7 +576,7 @@ class RNIapModule(
|
|
|
568
576
|
.getBillingResponseData(billingResult.responseCode)
|
|
569
577
|
map.putString("code", errorData[0])
|
|
570
578
|
map.putString("message", errorData[1])
|
|
571
|
-
map.putString("purchaseToken",purchaseToken)
|
|
579
|
+
map.putString("purchaseToken", purchaseToken)
|
|
572
580
|
promise.safeResolve(map)
|
|
573
581
|
}
|
|
574
582
|
}
|
|
@@ -618,7 +626,7 @@ class RNIapModule(
|
|
|
618
626
|
accountIdentifiers.obfuscatedProfileId
|
|
619
627
|
)
|
|
620
628
|
}
|
|
621
|
-
promiseItems.pushMap(item)
|
|
629
|
+
promiseItems.pushMap(item.copy())
|
|
622
630
|
sendEvent(reactContext, "purchase-updated", item)
|
|
623
631
|
}
|
|
624
632
|
DoobooUtils.instance.resolvePromisesForKey(PROMISE_BUY_ITEM, promiseItems)
|
package/ios/RNIapIos.swift
CHANGED
|
@@ -43,7 +43,8 @@ class RNIapIos: RCTEventEmitter, SKRequestDelegate, SKPaymentTransactionObserver
|
|
|
43
43
|
private var promotedPayment: SKPayment?
|
|
44
44
|
private var promotedProduct: SKProduct?
|
|
45
45
|
private var productsRequest: SKProductsRequest?
|
|
46
|
-
private var countPendingTransaction: Int
|
|
46
|
+
private var countPendingTransaction: Int = 0
|
|
47
|
+
private var hasTransactionObserver = false
|
|
47
48
|
|
|
48
49
|
override init() {
|
|
49
50
|
promisesByKey = [String: [RNIapIosPromise]]()
|
|
@@ -51,17 +52,31 @@ class RNIapIos: RCTEventEmitter, SKRequestDelegate, SKPaymentTransactionObserver
|
|
|
51
52
|
myQueue = DispatchQueue(label: "reject")
|
|
52
53
|
validProducts = [SKProduct]()
|
|
53
54
|
super.init()
|
|
54
|
-
|
|
55
|
+
addTransactionObserver()
|
|
55
56
|
}
|
|
56
57
|
|
|
57
58
|
deinit {
|
|
58
|
-
|
|
59
|
+
removeTransactionObserver()
|
|
59
60
|
}
|
|
60
61
|
|
|
61
62
|
override class func requiresMainQueueSetup() -> Bool {
|
|
62
63
|
return true
|
|
63
64
|
}
|
|
64
65
|
|
|
66
|
+
func addTransactionObserver() {
|
|
67
|
+
if !hasTransactionObserver {
|
|
68
|
+
hasTransactionObserver = true
|
|
69
|
+
SKPaymentQueue.default().add(self)
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
func removeTransactionObserver() {
|
|
74
|
+
if hasTransactionObserver {
|
|
75
|
+
hasTransactionObserver = false
|
|
76
|
+
SKPaymentQueue.default().remove(self)
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
65
80
|
func flushUnheardEvents() {
|
|
66
81
|
paymentQueue(SKPaymentQueue.default(), updatedTransactions: SKPaymentQueue.default().transactions)
|
|
67
82
|
}
|
|
@@ -136,6 +151,7 @@ class RNIapIos: RCTEventEmitter, SKRequestDelegate, SKPaymentTransactionObserver
|
|
|
136
151
|
_ resolve: @escaping RCTPromiseResolveBlock = { _ in },
|
|
137
152
|
reject: @escaping RCTPromiseRejectBlock = { _, _, _ in }
|
|
138
153
|
) {
|
|
154
|
+
addTransactionObserver()
|
|
139
155
|
let canMakePayments = SKPaymentQueue.canMakePayments()
|
|
140
156
|
resolve(NSNumber(value: canMakePayments))
|
|
141
157
|
}
|
|
@@ -143,7 +159,7 @@ class RNIapIos: RCTEventEmitter, SKRequestDelegate, SKPaymentTransactionObserver
|
|
|
143
159
|
_ resolve: @escaping RCTPromiseResolveBlock = { _ in },
|
|
144
160
|
reject: @escaping RCTPromiseRejectBlock = { _, _, _ in }
|
|
145
161
|
) {
|
|
146
|
-
|
|
162
|
+
removeTransactionObserver()
|
|
147
163
|
resolve(nil)
|
|
148
164
|
}
|
|
149
165
|
@objc public func getItems(
|
|
@@ -300,18 +316,19 @@ class RNIapIos: RCTEventEmitter, SKRequestDelegate, SKPaymentTransactionObserver
|
|
|
300
316
|
_ resolve: @escaping RCTPromiseResolveBlock = { _ in },
|
|
301
317
|
reject: @escaping RCTPromiseRejectBlock = { _, _, _ in }
|
|
302
318
|
) {
|
|
303
|
-
debugMessage("clear remaining Transactions. Call this before make a new transaction")
|
|
304
|
-
|
|
305
319
|
let pendingTrans = SKPaymentQueue.default().transactions
|
|
306
|
-
|
|
320
|
+
countPendingTransaction = pendingTrans.count
|
|
321
|
+
|
|
322
|
+
debugMessage("clear remaining Transactions (\(countPendingTransaction)). Call this before make a new transaction")
|
|
307
323
|
|
|
308
324
|
if countPendingTransaction > 0 {
|
|
309
325
|
addPromise(forKey: "cleaningTransactions", resolve: resolve, reject: reject)
|
|
310
326
|
for transaction in pendingTrans {
|
|
311
327
|
SKPaymentQueue.default().finishTransaction(transaction)
|
|
312
328
|
}
|
|
329
|
+
} else {
|
|
330
|
+
resolve(nil)
|
|
313
331
|
}
|
|
314
|
-
resolve(nil)
|
|
315
332
|
}
|
|
316
333
|
|
|
317
334
|
@objc public func clearProducts(
|
|
@@ -936,18 +953,14 @@ class RNIapIos: RCTEventEmitter, SKRequestDelegate, SKPaymentTransactionObserver
|
|
|
936
953
|
}
|
|
937
954
|
|
|
938
955
|
func paymentQueue(_ queue: SKPaymentQueue, removedTransactions transactions: [SKPaymentTransaction]) {
|
|
939
|
-
debugMessage("removedTransactions")
|
|
956
|
+
debugMessage("removedTransactions - countPendingTransactions \(countPendingTransaction)")
|
|
940
957
|
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
}
|
|
944
|
-
|
|
945
|
-
if unwrappedCount > 0 {
|
|
946
|
-
unwrappedCount -= transactions.count
|
|
958
|
+
if countPendingTransaction > 0 {
|
|
959
|
+
countPendingTransaction -= transactions.count
|
|
947
960
|
|
|
948
|
-
if
|
|
961
|
+
if countPendingTransaction <= 0 {
|
|
949
962
|
resolvePromises(forKey: "cleaningTransactions", value: nil)
|
|
950
|
-
countPendingTransaction =
|
|
963
|
+
countPendingTransaction = 0
|
|
951
964
|
}
|
|
952
965
|
}
|
|
953
966
|
}
|
package/lib/commonjs/iap.js
CHANGED
|
@@ -17,6 +17,7 @@ const {
|
|
|
17
17
|
RNIapAmazonModule
|
|
18
18
|
} = _reactNative.NativeModules;
|
|
19
19
|
const isAndroid = _reactNative.Platform.OS === 'android';
|
|
20
|
+
const isAmazon = isAndroid && !!RNIapAmazonModule;
|
|
20
21
|
const isIos = _reactNative.Platform.OS === 'ios';
|
|
21
22
|
const ANDROID_ITEM_TYPE_SUBSCRIPTION = 'subs';
|
|
22
23
|
const ANDROID_ITEM_TYPE_IAP = 'inapp';
|
|
@@ -220,6 +221,8 @@ const getAvailablePurchases = () => (_reactNative.Platform.select({
|
|
|
220
221
|
* @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.
|
|
221
222
|
* @param {string} [obfuscatedAccountIdAndroid] Specifies an optional obfuscated string that is uniquely associated with the user's account in your app.
|
|
222
223
|
* @param {string} [obfuscatedProfileIdAndroid] Specifies an optional obfuscated string that is uniquely associated with the user's profile in your app.
|
|
224
|
+
* @param {string[]} [skus] Product Ids to purchase. Note that this is only for Android. iOS only uses a single SKU. If not provided, it'll default to using [sku] for backward-compatibility
|
|
225
|
+
* @param {boolean} [isOfferPersonalized] Defaults to false, Only for Android V5
|
|
223
226
|
* @returns {Promise<InAppPurchase>}
|
|
224
227
|
*/
|
|
225
228
|
|
|
@@ -232,7 +235,11 @@ const requestPurchase = _ref => {
|
|
|
232
235
|
andDangerouslyFinishTransactionAutomaticallyIOS = false,
|
|
233
236
|
obfuscatedAccountIdAndroid,
|
|
234
237
|
obfuscatedProfileIdAndroid,
|
|
235
|
-
applicationUsername
|
|
238
|
+
applicationUsername,
|
|
239
|
+
skus,
|
|
240
|
+
// Android Billing V5
|
|
241
|
+
isOfferPersonalized = undefined // Android Billing V5
|
|
242
|
+
|
|
236
243
|
} = _ref;
|
|
237
244
|
return (_reactNative.Platform.select({
|
|
238
245
|
ios: async () => {
|
|
@@ -243,7 +250,7 @@ const requestPurchase = _ref => {
|
|
|
243
250
|
return getIosModule().buyProduct(sku, andDangerouslyFinishTransactionAutomaticallyIOS, applicationUsername);
|
|
244
251
|
},
|
|
245
252
|
android: async () => {
|
|
246
|
-
return getAndroidModule().buyItemByType(ANDROID_ITEM_TYPE_IAP, [sku], null, -1, obfuscatedAccountIdAndroid, obfuscatedProfileIdAndroid, undefined);
|
|
253
|
+
return getAndroidModule().buyItemByType(ANDROID_ITEM_TYPE_IAP, skus !== null && skus !== void 0 && skus.length ? skus : [sku], null, -1, obfuscatedAccountIdAndroid, obfuscatedProfileIdAndroid, undefined, isOfferPersonalized ?? false);
|
|
247
254
|
}
|
|
248
255
|
}) || Promise.resolve)();
|
|
249
256
|
};
|
|
@@ -256,8 +263,7 @@ const requestPurchase = _ref => {
|
|
|
256
263
|
* @param {ProrationModesAndroid} [prorationModeAndroid] UNKNOWN_SUBSCRIPTION_UPGRADE_DOWNGRADE_POLICY, IMMEDIATE_WITH_TIME_PRORATION, IMMEDIATE_AND_CHARGE_PRORATED_PRICE, IMMEDIATE_WITHOUT_PRORATION, DEFERRED
|
|
257
264
|
* @param {string} [obfuscatedAccountIdAndroid] Specifies an optional obfuscated string that is uniquely associated with the user's account in your app.
|
|
258
265
|
* @param {string} [obfuscatedProfileIdAndroid] Specifies an optional obfuscated string that is uniquely associated with the user's profile in your app.
|
|
259
|
-
* @param {
|
|
260
|
-
* @param {string[]} [skus] Skus to purchase, if more than one, otherwise it'll default to sku
|
|
266
|
+
* @param {SubscriptionOffers[]} [subscriptionOffers] Array of SubscriptionOffers. Every sku must be paired with a corresponding offerToken
|
|
261
267
|
* @returns {Promise<SubscriptionPurchase | null>} Promise resolves to null when using proratioModesAndroid=DEFERRED, and to a SubscriptionPurchase otherwise
|
|
262
268
|
*/
|
|
263
269
|
|
|
@@ -272,9 +278,9 @@ const requestSubscription = _ref2 => {
|
|
|
272
278
|
prorationModeAndroid = -1,
|
|
273
279
|
obfuscatedAccountIdAndroid,
|
|
274
280
|
obfuscatedProfileIdAndroid,
|
|
275
|
-
|
|
281
|
+
subscriptionOffers = undefined,
|
|
276
282
|
// Android Billing V5
|
|
277
|
-
|
|
283
|
+
isOfferPersonalized = undefined,
|
|
278
284
|
// Android Billing V5
|
|
279
285
|
applicationUsername
|
|
280
286
|
} = _ref2;
|
|
@@ -287,7 +293,16 @@ const requestSubscription = _ref2 => {
|
|
|
287
293
|
return getIosModule().buyProduct(sku, andDangerouslyFinishTransactionAutomaticallyIOS, applicationUsername);
|
|
288
294
|
},
|
|
289
295
|
android: async () => {
|
|
290
|
-
|
|
296
|
+
if (isAmazon) {
|
|
297
|
+
return RNIapAmazonModule.buyItemByType(sku);
|
|
298
|
+
} else {
|
|
299
|
+
if (!(subscriptionOffers !== null && subscriptionOffers !== void 0 && subscriptionOffers.length)) {
|
|
300
|
+
Promise.reject('subscriptionOffers are required for Google Play Subscriptions');
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
return RNIapModule.buyItemByType(ANDROID_ITEM_TYPE_SUBSCRIPTION, subscriptionOffers === null || subscriptionOffers === void 0 ? void 0 : subscriptionOffers.map(so => so.sku), purchaseTokenAndroid, prorationModeAndroid, obfuscatedAccountIdAndroid, obfuscatedProfileIdAndroid, subscriptionOffers === null || subscriptionOffers === void 0 ? void 0 : subscriptionOffers.map(so => so.offerToken), isOfferPersonalized ?? false);
|
|
305
|
+
}
|
|
291
306
|
}
|
|
292
307
|
}) || Promise.resolve)();
|
|
293
308
|
};
|