react-native-iap 12.4.0 → 12.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -20,14 +20,11 @@ import com.facebook.react.modules.core.DeviceEventManagerModule.RCTDeviceEventEm
|
|
|
20
20
|
import java.lang.NumberFormatException
|
|
21
21
|
import java.util.ArrayList
|
|
22
22
|
|
|
23
|
+
val ProductType.typeString: String
|
|
24
|
+
get() = if (this == ProductType.ENTITLED || this == ProductType.CONSUMABLE) "inapp" else "subs"
|
|
25
|
+
|
|
23
26
|
class RNIapAmazonListener(private val reactContext: ReactContext) : PurchasingListener {
|
|
24
27
|
private val skus: MutableList<Product>
|
|
25
|
-
private var availableItems: WritableNativeArray
|
|
26
|
-
private var availableItemsType: String?
|
|
27
|
-
fun getPurchaseUpdatesByType(type: String?) {
|
|
28
|
-
availableItemsType = type
|
|
29
|
-
PurchasingService.getPurchaseUpdates(true)
|
|
30
|
-
}
|
|
31
28
|
|
|
32
29
|
override fun onProductDataResponse(response: ProductDataResponse) {
|
|
33
30
|
val requestId = response.requestId.toString()
|
|
@@ -40,9 +37,7 @@ class RNIapAmazonListener(private val reactContext: ReactContext) : PurchasingLi
|
|
|
40
37
|
if (!skus.contains(product)) {
|
|
41
38
|
skus.add(product)
|
|
42
39
|
}
|
|
43
|
-
|
|
44
|
-
val productTypeString =
|
|
45
|
-
if (productType == ProductType.ENTITLED || productType == ProductType.CONSUMABLE) "inapp" else "subs"
|
|
40
|
+
|
|
46
41
|
var priceNumber: Number = 0.00
|
|
47
42
|
val priceString = product.price
|
|
48
43
|
try {
|
|
@@ -59,7 +54,7 @@ class RNIapAmazonListener(private val reactContext: ReactContext) : PurchasingLi
|
|
|
59
54
|
val coinsReward = product.coinsReward
|
|
60
55
|
item.putString("productId", product.sku)
|
|
61
56
|
item.putString("price", priceNumber.toString())
|
|
62
|
-
item.putString("type",
|
|
57
|
+
item.putString("type", product.productType.typeString)
|
|
63
58
|
item.putString("localizedPrice", priceString)
|
|
64
59
|
item.putString("title", product.title)
|
|
65
60
|
item.putString("description", product.description)
|
|
@@ -98,12 +93,9 @@ class RNIapAmazonListener(private val reactContext: ReactContext) : PurchasingLi
|
|
|
98
93
|
}
|
|
99
94
|
|
|
100
95
|
override fun onPurchaseUpdatesResponse(response: PurchaseUpdatesResponse) {
|
|
101
|
-
// Info for potential error reporting
|
|
102
|
-
val debugMessage: String?
|
|
103
|
-
var errorCode = PromiseUtils.E_UNKNOWN
|
|
104
|
-
val error = Arguments.createMap()
|
|
105
96
|
when (response.requestStatus) {
|
|
106
97
|
PurchaseUpdatesResponse.RequestStatus.SUCCESSFUL -> {
|
|
98
|
+
val availableItems = Arguments.createArray()
|
|
107
99
|
val userData = response.userData
|
|
108
100
|
var promiseItem: WritableMap? = null
|
|
109
101
|
val purchases = response.receipts
|
|
@@ -112,12 +104,7 @@ class RNIapAmazonListener(private val reactContext: ReactContext) : PurchasingLi
|
|
|
112
104
|
promiseItem = WritableNativeMap()
|
|
113
105
|
promiseItem.merge(item)
|
|
114
106
|
sendEvent(reactContext, "purchase-updated", item)
|
|
115
|
-
|
|
116
|
-
val productTypeString =
|
|
117
|
-
if (productType == ProductType.ENTITLED || productType == ProductType.CONSUMABLE) "inapp" else "subs"
|
|
118
|
-
if (productTypeString == availableItemsType) {
|
|
119
|
-
availableItems.pushMap(promiseItem)
|
|
120
|
-
}
|
|
107
|
+
availableItems.pushMap(promiseItem)
|
|
121
108
|
}
|
|
122
109
|
if (response.hasMore()) {
|
|
123
110
|
PurchasingService.getPurchaseUpdates(false)
|
|
@@ -139,13 +126,12 @@ class RNIapAmazonListener(private val reactContext: ReactContext) : PurchasingLi
|
|
|
139
126
|
RNIapAmazonModule.PROMISE_QUERY_AVAILABLE_ITEMS,
|
|
140
127
|
availableItems
|
|
141
128
|
)
|
|
142
|
-
availableItems = WritableNativeArray()
|
|
143
|
-
availableItemsType = null
|
|
144
129
|
}
|
|
145
130
|
}
|
|
146
131
|
PurchaseUpdatesResponse.RequestStatus.FAILED -> {
|
|
147
|
-
|
|
148
|
-
|
|
132
|
+
val error = Arguments.createMap()
|
|
133
|
+
val debugMessage = "An unknown or unexpected error has occured. Please try again later."
|
|
134
|
+
val errorCode = PromiseUtils.E_UNKNOWN
|
|
149
135
|
error.putInt("responseCode", 0)
|
|
150
136
|
error.putString("debugMessage", debugMessage)
|
|
151
137
|
error.putString("code", errorCode)
|
|
@@ -165,12 +151,11 @@ class RNIapAmazonListener(private val reactContext: ReactContext) : PurchasingLi
|
|
|
165
151
|
debugMessage,
|
|
166
152
|
null
|
|
167
153
|
)
|
|
168
|
-
availableItems = WritableNativeArray()
|
|
169
|
-
availableItemsType = null
|
|
170
154
|
}
|
|
171
155
|
PurchaseUpdatesResponse.RequestStatus.NOT_SUPPORTED -> {
|
|
172
|
-
|
|
173
|
-
|
|
156
|
+
val error = Arguments.createMap()
|
|
157
|
+
val debugMessage = "This feature is not available on your device."
|
|
158
|
+
val errorCode = PromiseUtils.E_SERVICE_ERROR
|
|
174
159
|
error.putInt("responseCode", 0)
|
|
175
160
|
error.putString("debugMessage", debugMessage)
|
|
176
161
|
error.putString("code", errorCode)
|
|
@@ -190,8 +175,6 @@ class RNIapAmazonListener(private val reactContext: ReactContext) : PurchasingLi
|
|
|
190
175
|
debugMessage,
|
|
191
176
|
null
|
|
192
177
|
)
|
|
193
|
-
availableItems = WritableNativeArray()
|
|
194
|
-
availableItemsType = null
|
|
195
178
|
}
|
|
196
179
|
}
|
|
197
180
|
}
|
|
@@ -207,6 +190,7 @@ class RNIapAmazonListener(private val reactContext: ReactContext) : PurchasingLi
|
|
|
207
190
|
item.putString("userJsonAmazon", userData.toJSON().toString())
|
|
208
191
|
item.putBoolean("isCanceledAmazon", receipt.isCanceled)
|
|
209
192
|
item.putString("termSku", receipt.termSku)
|
|
193
|
+
item.putString("productType", receipt.productType.typeString)
|
|
210
194
|
return item
|
|
211
195
|
}
|
|
212
196
|
|
|
@@ -224,7 +208,7 @@ class RNIapAmazonListener(private val reactContext: ReactContext) : PurchasingLi
|
|
|
224
208
|
val receipt = response.receipt
|
|
225
209
|
val userData = response.userData
|
|
226
210
|
val item = receiptToMap(userData, receipt)
|
|
227
|
-
val promiseItem: WritableMap =
|
|
211
|
+
val promiseItem: WritableMap = Arguments.createMap()
|
|
228
212
|
promiseItem.merge(item)
|
|
229
213
|
sendEvent(reactContext, "purchase-updated", item)
|
|
230
214
|
PromiseUtils
|
|
@@ -363,7 +347,5 @@ class RNIapAmazonListener(private val reactContext: ReactContext) : PurchasingLi
|
|
|
363
347
|
|
|
364
348
|
init {
|
|
365
349
|
skus = ArrayList()
|
|
366
|
-
availableItems = WritableNativeArray()
|
|
367
|
-
availableItemsType = null
|
|
368
350
|
}
|
|
369
351
|
}
|
package/ios/RNIapIosSk2.m
CHANGED
|
@@ -36,7 +36,7 @@ RCT_EXTERN_METHOD(getItems:
|
|
|
36
36
|
|
|
37
37
|
RCT_EXTERN_METHOD(getAvailableItems:
|
|
38
38
|
(BOOL)alsoPublishToEventListener
|
|
39
|
-
(BOOL)onlyIncludeActiveItems
|
|
39
|
+
onlyIncludeActiveItems:(BOOL)onlyIncludeActiveItems
|
|
40
40
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
41
41
|
reject:(RCTPromiseRejectBlock)reject)
|
|
42
42
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-iap",
|
|
3
|
-
"version": "12.4.
|
|
3
|
+
"version": "12.4.2",
|
|
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)",
|