react-native-iap 12.1.2 → 12.3.0
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/RNIap.podspec +1 -2
- package/android/src/amazon/java/com/dooboolab/RNIap/RNIapAmazonListener.kt +32 -33
- package/android/src/amazon/java/com/dooboolab/RNIap/RNIapAmazonModule.kt +20 -21
- package/android/src/main/java/com/dooboolab/RNIap/PromiseUtils.kt +54 -0
- package/android/src/main/java/com/dooboolab/RNIap/PromiseUtlis.kt +1 -1
- package/android/src/play/java/com/dooboolab/RNIap/PlayUtils.kt +49 -34
- package/android/src/play/java/com/dooboolab/RNIap/RNIapModule.kt +24 -30
- package/ios/IapSerializationUtils.swift +11 -0
- package/ios/RNIapIosSk2.m +8 -0
- package/ios/RNIapIosSk2.swift +96 -2
- package/lib/commonjs/modules/iosSk2.js +9 -1
- package/lib/commonjs/modules/iosSk2.js.map +1 -1
- package/lib/commonjs/types/appleSk2.js.map +1 -1
- package/lib/module/modules/iosSk2.js +5 -0
- package/lib/module/modules/iosSk2.js.map +1 -1
- package/lib/module/types/appleSk2.js.map +1 -1
- package/lib/typescript/modules/iosSk2.d.ts +8 -1
- package/lib/typescript/types/appleSk2.d.ts +1 -0
- package/package.json +1 -1
- package/src/modules/iosSk2.ts +10 -0
- package/src/types/appleSk2.ts +2 -0
- package/android/src/main/java/com/dooboolab/RNIap/DoobooUtils.kt +0 -188
package/RNIap.podspec
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
require "json"
|
|
2
2
|
|
|
3
3
|
package = JSON.parse(File.read(File.join(__dir__, "package.json")))
|
|
4
|
-
folly_version = '2021.06.28.00-v2'
|
|
5
4
|
folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32'
|
|
6
5
|
|
|
7
6
|
Pod::Spec.new do |s|
|
|
@@ -30,7 +29,7 @@ Pod::Spec.new do |s|
|
|
|
30
29
|
}
|
|
31
30
|
|
|
32
31
|
s.dependency "React-Codegen"
|
|
33
|
-
s.dependency "RCT-Folly"
|
|
32
|
+
s.dependency "RCT-Folly"
|
|
34
33
|
s.dependency "RCTRequired"
|
|
35
34
|
s.dependency "RCTTypeSafety"
|
|
36
35
|
s.dependency "ReactCommon/turbomodule/core"
|
|
@@ -21,7 +21,6 @@ import java.lang.NumberFormatException
|
|
|
21
21
|
import java.util.ArrayList
|
|
22
22
|
|
|
23
23
|
class RNIapAmazonListener(private val reactContext: ReactContext) : PurchasingListener {
|
|
24
|
-
val TAG = "RNIapAmazonListener"
|
|
25
24
|
private val skus: MutableList<Product>
|
|
26
25
|
private var availableItems: WritableNativeArray
|
|
27
26
|
private var availableItemsType: String?
|
|
@@ -47,7 +46,7 @@ class RNIapAmazonListener(private val reactContext: ReactContext) : PurchasingLi
|
|
|
47
46
|
var priceNumber: Number = 0.00
|
|
48
47
|
val priceString = product.price
|
|
49
48
|
try {
|
|
50
|
-
if (priceString?.isNotEmpty()== true) {
|
|
49
|
+
if (priceString?.isNotEmpty() == true) {
|
|
51
50
|
priceNumber = priceString.replace("[^\\d.,]+".toRegex(), "").toDouble()
|
|
52
51
|
}
|
|
53
52
|
} catch (e: NumberFormatException) {
|
|
@@ -73,14 +72,14 @@ class RNIapAmazonListener(private val reactContext: ReactContext) : PurchasingLi
|
|
|
73
72
|
}
|
|
74
73
|
items.pushMap(item)
|
|
75
74
|
}
|
|
76
|
-
|
|
75
|
+
PromiseUtils
|
|
77
76
|
.resolvePromisesForKey(
|
|
78
77
|
RNIapAmazonModule.PROMISE_GET_PRODUCT_DATA,
|
|
79
78
|
items
|
|
80
79
|
)
|
|
81
80
|
}
|
|
82
81
|
ProductDataResponse.RequestStatus.FAILED ->
|
|
83
|
-
|
|
82
|
+
PromiseUtils
|
|
84
83
|
.rejectPromisesForKey(
|
|
85
84
|
RNIapAmazonModule.PROMISE_GET_PRODUCT_DATA,
|
|
86
85
|
E_PRODUCT_DATA_RESPONSE_FAILED,
|
|
@@ -88,7 +87,7 @@ class RNIapAmazonListener(private val reactContext: ReactContext) : PurchasingLi
|
|
|
88
87
|
null
|
|
89
88
|
)
|
|
90
89
|
ProductDataResponse.RequestStatus.NOT_SUPPORTED ->
|
|
91
|
-
|
|
90
|
+
PromiseUtils
|
|
92
91
|
.rejectPromisesForKey(
|
|
93
92
|
RNIapAmazonModule.PROMISE_GET_PRODUCT_DATA,
|
|
94
93
|
E_PRODUCT_DATA_RESPONSE_NOT_SUPPORTED,
|
|
@@ -100,8 +99,8 @@ class RNIapAmazonListener(private val reactContext: ReactContext) : PurchasingLi
|
|
|
100
99
|
|
|
101
100
|
override fun onPurchaseUpdatesResponse(response: PurchaseUpdatesResponse) {
|
|
102
101
|
// Info for potential error reporting
|
|
103
|
-
|
|
104
|
-
var errorCode =
|
|
102
|
+
val debugMessage: String?
|
|
103
|
+
var errorCode = PromiseUtils.E_UNKNOWN
|
|
105
104
|
val error = Arguments.createMap()
|
|
106
105
|
when (response.requestStatus) {
|
|
107
106
|
PurchaseUpdatesResponse.RequestStatus.SUCCESSFUL -> {
|
|
@@ -124,18 +123,18 @@ class RNIapAmazonListener(private val reactContext: ReactContext) : PurchasingLi
|
|
|
124
123
|
PurchasingService.getPurchaseUpdates(false)
|
|
125
124
|
} else {
|
|
126
125
|
if (purchases.size > 0 && promiseItem != null) {
|
|
127
|
-
|
|
126
|
+
PromiseUtils
|
|
128
127
|
.resolvePromisesForKey(
|
|
129
128
|
RNIapAmazonModule.PROMISE_BUY_ITEM,
|
|
130
129
|
promiseItem
|
|
131
130
|
)
|
|
132
131
|
}
|
|
133
|
-
|
|
132
|
+
PromiseUtils
|
|
134
133
|
.resolvePromisesForKey(
|
|
135
134
|
RNIapAmazonModule.PROMISE_QUERY_PURCHASES,
|
|
136
135
|
true
|
|
137
136
|
)
|
|
138
|
-
|
|
137
|
+
PromiseUtils
|
|
139
138
|
.resolvePromisesForKey(
|
|
140
139
|
RNIapAmazonModule.PROMISE_QUERY_AVAILABLE_ITEMS,
|
|
141
140
|
availableItems
|
|
@@ -146,20 +145,20 @@ class RNIapAmazonListener(private val reactContext: ReactContext) : PurchasingLi
|
|
|
146
145
|
}
|
|
147
146
|
PurchaseUpdatesResponse.RequestStatus.FAILED -> {
|
|
148
147
|
debugMessage = "An unknown or unexpected error has occured. Please try again later."
|
|
149
|
-
errorCode =
|
|
148
|
+
errorCode = PromiseUtils.E_UNKNOWN
|
|
150
149
|
error.putInt("responseCode", 0)
|
|
151
150
|
error.putString("debugMessage", debugMessage)
|
|
152
151
|
error.putString("code", errorCode)
|
|
153
152
|
error.putString("message", debugMessage)
|
|
154
153
|
sendEvent(reactContext, "purchase-error", error)
|
|
155
|
-
|
|
154
|
+
PromiseUtils
|
|
156
155
|
.rejectPromisesForKey(
|
|
157
156
|
RNIapAmazonModule.PROMISE_QUERY_PURCHASES,
|
|
158
157
|
errorCode,
|
|
159
158
|
debugMessage,
|
|
160
159
|
null
|
|
161
160
|
)
|
|
162
|
-
|
|
161
|
+
PromiseUtils
|
|
163
162
|
.rejectPromisesForKey(
|
|
164
163
|
RNIapAmazonModule.PROMISE_QUERY_AVAILABLE_ITEMS,
|
|
165
164
|
errorCode,
|
|
@@ -171,20 +170,20 @@ class RNIapAmazonListener(private val reactContext: ReactContext) : PurchasingLi
|
|
|
171
170
|
}
|
|
172
171
|
PurchaseUpdatesResponse.RequestStatus.NOT_SUPPORTED -> {
|
|
173
172
|
debugMessage = "This feature is not available on your device."
|
|
174
|
-
errorCode =
|
|
173
|
+
errorCode = PromiseUtils.E_SERVICE_ERROR
|
|
175
174
|
error.putInt("responseCode", 0)
|
|
176
175
|
error.putString("debugMessage", debugMessage)
|
|
177
176
|
error.putString("code", errorCode)
|
|
178
177
|
error.putString("message", debugMessage)
|
|
179
178
|
sendEvent(reactContext, "purchase-error", error)
|
|
180
|
-
|
|
179
|
+
PromiseUtils
|
|
181
180
|
.rejectPromisesForKey(
|
|
182
181
|
RNIapAmazonModule.PROMISE_QUERY_PURCHASES,
|
|
183
182
|
errorCode,
|
|
184
183
|
debugMessage,
|
|
185
184
|
null
|
|
186
185
|
)
|
|
187
|
-
|
|
186
|
+
PromiseUtils
|
|
188
187
|
.rejectPromisesForKey(
|
|
189
188
|
RNIapAmazonModule.PROMISE_QUERY_AVAILABLE_ITEMS,
|
|
190
189
|
errorCode,
|
|
@@ -207,7 +206,7 @@ class RNIapAmazonListener(private val reactContext: ReactContext) : PurchasingLi
|
|
|
207
206
|
item.putString("userMarketplaceAmazon", userData.marketplace)
|
|
208
207
|
item.putString("userJsonAmazon", userData.toJSON().toString())
|
|
209
208
|
item.putBoolean("isCanceledAmazon", receipt.isCanceled)
|
|
210
|
-
item.putString("termSku",receipt.termSku)
|
|
209
|
+
item.putString("termSku", receipt.termSku)
|
|
211
210
|
return item
|
|
212
211
|
}
|
|
213
212
|
|
|
@@ -217,8 +216,8 @@ class RNIapAmazonListener(private val reactContext: ReactContext) : PurchasingLi
|
|
|
217
216
|
val status = response.requestStatus
|
|
218
217
|
|
|
219
218
|
// Info for potential error reporting
|
|
220
|
-
|
|
221
|
-
var errorCode =
|
|
219
|
+
val debugMessage: String?
|
|
220
|
+
var errorCode = PromiseUtils.E_UNKNOWN
|
|
222
221
|
val error = Arguments.createMap()
|
|
223
222
|
when (status) {
|
|
224
223
|
PurchaseResponse.RequestStatus.SUCCESSFUL -> {
|
|
@@ -228,7 +227,7 @@ class RNIapAmazonListener(private val reactContext: ReactContext) : PurchasingLi
|
|
|
228
227
|
val promiseItem: WritableMap = WritableNativeMap()
|
|
229
228
|
promiseItem.merge(item)
|
|
230
229
|
sendEvent(reactContext, "purchase-updated", item)
|
|
231
|
-
|
|
230
|
+
PromiseUtils
|
|
232
231
|
.resolvePromisesForKey(
|
|
233
232
|
RNIapAmazonModule.PROMISE_BUY_ITEM,
|
|
234
233
|
promiseItem
|
|
@@ -236,13 +235,13 @@ class RNIapAmazonListener(private val reactContext: ReactContext) : PurchasingLi
|
|
|
236
235
|
}
|
|
237
236
|
PurchaseResponse.RequestStatus.ALREADY_PURCHASED -> {
|
|
238
237
|
debugMessage = "You already own this item."
|
|
239
|
-
errorCode =
|
|
238
|
+
errorCode = PromiseUtils.E_ALREADY_OWNED
|
|
240
239
|
error.putInt("responseCode", 0)
|
|
241
240
|
error.putString("debugMessage", debugMessage)
|
|
242
241
|
error.putString("code", errorCode)
|
|
243
242
|
error.putString("message", debugMessage)
|
|
244
243
|
sendEvent(reactContext, "purchase-error", error)
|
|
245
|
-
|
|
244
|
+
PromiseUtils
|
|
246
245
|
.rejectPromisesForKey(
|
|
247
246
|
RNIapAmazonModule.PROMISE_BUY_ITEM,
|
|
248
247
|
errorCode,
|
|
@@ -253,13 +252,13 @@ class RNIapAmazonListener(private val reactContext: ReactContext) : PurchasingLi
|
|
|
253
252
|
PurchaseResponse.RequestStatus.FAILED -> {
|
|
254
253
|
debugMessage =
|
|
255
254
|
"An unknown or unexpected error has occurred. Please try again later."
|
|
256
|
-
errorCode =
|
|
255
|
+
errorCode = PromiseUtils.E_UNKNOWN
|
|
257
256
|
error.putInt("responseCode", 0)
|
|
258
257
|
error.putString("debugMessage", debugMessage)
|
|
259
258
|
error.putString("code", errorCode)
|
|
260
259
|
error.putString("message", debugMessage)
|
|
261
260
|
sendEvent(reactContext, "purchase-error", error)
|
|
262
|
-
|
|
261
|
+
PromiseUtils
|
|
263
262
|
.rejectPromisesForKey(
|
|
264
263
|
RNIapAmazonModule.PROMISE_BUY_ITEM,
|
|
265
264
|
errorCode,
|
|
@@ -269,13 +268,13 @@ class RNIapAmazonListener(private val reactContext: ReactContext) : PurchasingLi
|
|
|
269
268
|
}
|
|
270
269
|
PurchaseResponse.RequestStatus.INVALID_SKU -> {
|
|
271
270
|
debugMessage = "That item is unavailable."
|
|
272
|
-
errorCode =
|
|
271
|
+
errorCode = PromiseUtils.E_ITEM_UNAVAILABLE
|
|
273
272
|
error.putInt("responseCode", 0)
|
|
274
273
|
error.putString("debugMessage", debugMessage)
|
|
275
274
|
error.putString("code", errorCode)
|
|
276
275
|
error.putString("message", debugMessage)
|
|
277
276
|
sendEvent(reactContext, "purchase-error", error)
|
|
278
|
-
|
|
277
|
+
PromiseUtils
|
|
279
278
|
.rejectPromisesForKey(
|
|
280
279
|
RNIapAmazonModule.PROMISE_BUY_ITEM,
|
|
281
280
|
errorCode,
|
|
@@ -285,13 +284,13 @@ class RNIapAmazonListener(private val reactContext: ReactContext) : PurchasingLi
|
|
|
285
284
|
}
|
|
286
285
|
PurchaseResponse.RequestStatus.NOT_SUPPORTED -> {
|
|
287
286
|
debugMessage = "This feature is not available on your device."
|
|
288
|
-
errorCode =
|
|
287
|
+
errorCode = PromiseUtils.E_SERVICE_ERROR
|
|
289
288
|
error.putInt("responseCode", 0)
|
|
290
289
|
error.putString("debugMessage", debugMessage)
|
|
291
290
|
error.putString("code", errorCode)
|
|
292
291
|
error.putString("message", debugMessage)
|
|
293
292
|
sendEvent(reactContext, "purchase-error", error)
|
|
294
|
-
|
|
293
|
+
PromiseUtils
|
|
295
294
|
.rejectPromisesForKey(
|
|
296
295
|
RNIapAmazonModule.PROMISE_BUY_ITEM,
|
|
297
296
|
errorCode,
|
|
@@ -310,11 +309,11 @@ class RNIapAmazonListener(private val reactContext: ReactContext) : PurchasingLi
|
|
|
310
309
|
item.putString("userIdAmazon", userData.userId)
|
|
311
310
|
item.putString("userMarketplaceAmazon", userData.marketplace)
|
|
312
311
|
item.putString("userJsonAmazon", userData.toJSON().toString())
|
|
313
|
-
|
|
312
|
+
PromiseUtils
|
|
314
313
|
.resolvePromisesForKey(RNIapAmazonModule.PROMISE_GET_USER_DATA, item)
|
|
315
314
|
}
|
|
316
315
|
UserDataResponse.RequestStatus.NOT_SUPPORTED ->
|
|
317
|
-
|
|
316
|
+
PromiseUtils
|
|
318
317
|
.rejectPromisesForKey(
|
|
319
318
|
RNIapAmazonModule.PROMISE_GET_USER_DATA,
|
|
320
319
|
E_USER_DATA_RESPONSE_NOT_SUPPORTED,
|
|
@@ -322,7 +321,7 @@ class RNIapAmazonListener(private val reactContext: ReactContext) : PurchasingLi
|
|
|
322
321
|
null
|
|
323
322
|
)
|
|
324
323
|
UserDataResponse.RequestStatus.FAILED ->
|
|
325
|
-
|
|
324
|
+
PromiseUtils
|
|
326
325
|
.rejectPromisesForKey(
|
|
327
326
|
RNIapAmazonModule.PROMISE_GET_USER_DATA,
|
|
328
327
|
E_USER_DATA_RESPONSE_FAILED,
|
|
@@ -331,9 +330,8 @@ class RNIapAmazonListener(private val reactContext: ReactContext) : PurchasingLi
|
|
|
331
330
|
)
|
|
332
331
|
}
|
|
333
332
|
}
|
|
334
|
-
fun clear(){
|
|
333
|
+
fun clear() {
|
|
335
334
|
skus.clear()
|
|
336
|
-
|
|
337
335
|
}
|
|
338
336
|
|
|
339
337
|
private fun sendEvent(
|
|
@@ -360,6 +358,7 @@ class RNIapAmazonListener(private val reactContext: ReactContext) : PurchasingLi
|
|
|
360
358
|
private const val E_PURCHASE_RESPONSE_INVALID_SKU = "E_PURCHASE_RESPONSE_INVALID_SKU"
|
|
361
359
|
private const val E_USER_DATA_RESPONSE_FAILED = "E_USER_DATA_RESPONSE_FAILED"
|
|
362
360
|
private const val E_USER_DATA_RESPONSE_NOT_SUPPORTED = "E_USER_DATA_RESPONSE_NOT_SUPPORTED"
|
|
361
|
+
const val TAG = "RNIapAmazonListener"
|
|
363
362
|
}
|
|
364
363
|
|
|
365
364
|
init {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
package com.dooboolab.RNIap
|
|
2
2
|
|
|
3
3
|
import android.util.Log
|
|
4
|
-
import com.amazon.device.drm.LicensingListener
|
|
5
4
|
import com.amazon.device.drm.LicensingService
|
|
6
5
|
import com.amazon.device.drm.model.LicenseResponse
|
|
7
6
|
import com.amazon.device.iap.PurchasingService
|
|
@@ -15,7 +14,6 @@ import com.facebook.react.bridge.ReadableArray
|
|
|
15
14
|
import com.facebook.react.bridge.UiThreadUtil
|
|
16
15
|
import com.facebook.react.module.annotations.ReactModule
|
|
17
16
|
|
|
18
|
-
|
|
19
17
|
@ReactModule(name = RNIapAmazonModule.TAG)
|
|
20
18
|
class RNIapAmazonModule(reactContext: ReactApplicationContext) :
|
|
21
19
|
ReactContextBaseJavaModule(reactContext) {
|
|
@@ -32,25 +30,26 @@ class RNIapAmazonModule(reactContext: ReactApplicationContext) :
|
|
|
32
30
|
this.amazonListener = amazonListener
|
|
33
31
|
UiThreadUtil.runOnUiThread {
|
|
34
32
|
try {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}catch (e:Exception){
|
|
33
|
+
PurchasingService.registerListener(context.applicationContext, amazonListener)
|
|
34
|
+
hasListener = true
|
|
35
|
+
// Prefetch user and purchases as per Amazon SDK documentation:
|
|
36
|
+
PurchasingService.getUserData()
|
|
37
|
+
PurchasingService.getPurchaseUpdates(false)
|
|
38
|
+
promise.safeResolve(true)
|
|
39
|
+
} catch (e: Exception) {
|
|
43
40
|
promise.safeReject("Error initializing Amazon appstore sdk", e)
|
|
44
41
|
}
|
|
45
42
|
}
|
|
46
43
|
}
|
|
47
44
|
|
|
48
45
|
@ReactMethod
|
|
49
|
-
fun verifyLicense(promise: Promise){
|
|
46
|
+
fun verifyLicense(promise: Promise) {
|
|
50
47
|
try {
|
|
51
48
|
LicensingService.verifyLicense(reactApplicationContext) { licenseResponse ->
|
|
52
|
-
when (
|
|
53
|
-
|
|
49
|
+
when (
|
|
50
|
+
val status: LicenseResponse.RequestStatus =
|
|
51
|
+
licenseResponse.requestStatus
|
|
52
|
+
) {
|
|
54
53
|
LicenseResponse.RequestStatus.LICENSED -> {
|
|
55
54
|
Log.d(TAG, "LicenseResponse status: $status")
|
|
56
55
|
promise.resolve("LICENSED")
|
|
@@ -77,14 +76,14 @@ class RNIapAmazonModule(reactContext: ReactApplicationContext) :
|
|
|
77
76
|
}
|
|
78
77
|
}
|
|
79
78
|
}
|
|
80
|
-
}catch (exception: Exception){
|
|
81
|
-
promise.reject("Error while attempting to check for License",exception)
|
|
79
|
+
} catch (exception: Exception) {
|
|
80
|
+
promise.reject("Error while attempting to check for License", exception)
|
|
82
81
|
}
|
|
83
82
|
}
|
|
84
83
|
|
|
85
84
|
@ReactMethod
|
|
86
85
|
fun endConnection(promise: Promise) {
|
|
87
|
-
|
|
86
|
+
PromiseUtils.rejectAllPendingPromises()
|
|
88
87
|
amazonListener?.clear()
|
|
89
88
|
hasListener = false
|
|
90
89
|
promise.resolve(true)
|
|
@@ -93,7 +92,7 @@ class RNIapAmazonModule(reactContext: ReactApplicationContext) :
|
|
|
93
92
|
@ReactMethod
|
|
94
93
|
fun getUser(promise: Promise) {
|
|
95
94
|
val requestId = PurchasingService.getUserData()
|
|
96
|
-
|
|
95
|
+
PromiseUtils.addPromiseForKey(PROMISE_GET_USER_DATA, promise)
|
|
97
96
|
}
|
|
98
97
|
|
|
99
98
|
@ReactMethod
|
|
@@ -114,13 +113,13 @@ class RNIapAmazonModule(reactContext: ReactApplicationContext) :
|
|
|
114
113
|
}
|
|
115
114
|
ii++
|
|
116
115
|
}
|
|
117
|
-
|
|
116
|
+
PromiseUtils.addPromiseForKey(PROMISE_GET_PRODUCT_DATA, promise)
|
|
118
117
|
val requestId = PurchasingService.getProductData(productSkus)
|
|
119
118
|
}
|
|
120
119
|
|
|
121
120
|
@ReactMethod
|
|
122
121
|
fun getAvailableItems(promise: Promise) {
|
|
123
|
-
|
|
122
|
+
PromiseUtils.addPromiseForKey(PROMISE_QUERY_AVAILABLE_ITEMS, promise)
|
|
124
123
|
PurchasingService.getPurchaseUpdates(true)
|
|
125
124
|
}
|
|
126
125
|
|
|
@@ -129,7 +128,7 @@ class RNIapAmazonModule(reactContext: ReactApplicationContext) :
|
|
|
129
128
|
sku: String?,
|
|
130
129
|
promise: Promise
|
|
131
130
|
) {
|
|
132
|
-
|
|
131
|
+
PromiseUtils.addPromiseForKey(PROMISE_BUY_ITEM, promise)
|
|
133
132
|
val requestId = PurchasingService.purchase(sku)
|
|
134
133
|
}
|
|
135
134
|
|
|
@@ -154,7 +153,7 @@ class RNIapAmazonModule(reactContext: ReactApplicationContext) :
|
|
|
154
153
|
}
|
|
155
154
|
|
|
156
155
|
private fun sendUnconsumedPurchases(promise: Promise) {
|
|
157
|
-
|
|
156
|
+
PromiseUtils.addPromiseForKey(PROMISE_QUERY_PURCHASES, promise)
|
|
158
157
|
PurchasingService.getPurchaseUpdates(false)
|
|
159
158
|
}
|
|
160
159
|
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
package com.dooboolab.RNIap
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.bridge.Promise
|
|
4
|
+
import java.lang.Exception
|
|
5
|
+
import java.util.HashMap
|
|
6
|
+
|
|
7
|
+
object PromiseUtils {
|
|
8
|
+
private val promises = HashMap<String, MutableList<Promise>>()
|
|
9
|
+
fun addPromiseForKey(key: String, promise: Promise) {
|
|
10
|
+
promises.getOrPut(key) { mutableListOf() }.add(promise)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
fun resolvePromisesForKey(key: String, value: Any?) {
|
|
14
|
+
promises[key]?.forEach { promise ->
|
|
15
|
+
promise.safeResolve(value)
|
|
16
|
+
}
|
|
17
|
+
promises.remove(key)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
fun rejectAllPendingPromises() {
|
|
21
|
+
promises.flatMap { it.value }.forEach { promise ->
|
|
22
|
+
promise.safeReject(E_CONNECTION_CLOSED, "Connection has been closed", null)
|
|
23
|
+
}
|
|
24
|
+
promises.clear()
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
fun rejectPromisesForKey(
|
|
28
|
+
key: String,
|
|
29
|
+
code: String?,
|
|
30
|
+
message: String?,
|
|
31
|
+
err: Exception?
|
|
32
|
+
) {
|
|
33
|
+
promises[key]?.forEach { promise ->
|
|
34
|
+
promise.safeReject(code, message, err)
|
|
35
|
+
}
|
|
36
|
+
promises.remove(key)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
private const val TAG = "PromiseUtils"
|
|
40
|
+
const val E_UNKNOWN = "E_UNKNOWN"
|
|
41
|
+
const val E_NOT_PREPARED = "E_NOT_PREPARED"
|
|
42
|
+
const val E_ALREADY_PREPARED = "E_ALREADY_PREPARED"
|
|
43
|
+
const val E_NOT_ENDED = "E_NOT_ENDED"
|
|
44
|
+
const val E_USER_CANCELLED = "E_USER_CANCELLED"
|
|
45
|
+
const val E_ITEM_UNAVAILABLE = "E_ITEM_UNAVAILABLE"
|
|
46
|
+
const val E_NETWORK_ERROR = "E_NETWORK_ERROR"
|
|
47
|
+
const val E_SERVICE_ERROR = "E_SERVICE_ERROR"
|
|
48
|
+
const val E_ALREADY_OWNED = "E_ALREADY_OWNED"
|
|
49
|
+
const val E_REMOTE_ERROR = "E_REMOTE_ERROR"
|
|
50
|
+
const val E_USER_ERROR = "E_USER_ERROR"
|
|
51
|
+
const val E_DEVELOPER_ERROR = "E_DEVELOPER_ERROR"
|
|
52
|
+
const val E_BILLING_RESPONSE_JSON_PARSE_ERROR = "E_BILLING_RESPONSE_JSON_PARSE_ERROR"
|
|
53
|
+
const val E_CONNECTION_CLOSED = "E_CONNECTION_CLOSED"
|
|
54
|
+
}
|
|
@@ -4,60 +4,81 @@ import android.util.Log
|
|
|
4
4
|
import com.android.billingclient.api.BillingClient
|
|
5
5
|
import com.facebook.react.bridge.Promise
|
|
6
6
|
|
|
7
|
-
class
|
|
7
|
+
data class BillingResponse(val code: String, val message: String)
|
|
8
|
+
|
|
9
|
+
object PlayUtils {
|
|
8
10
|
fun rejectPromiseWithBillingError(promise: Promise, responseCode: Int) {
|
|
9
11
|
val errorData = getBillingResponseData(responseCode)
|
|
10
|
-
promise.safeReject(errorData
|
|
12
|
+
promise.safeReject(errorData.code, errorData.message)
|
|
11
13
|
}
|
|
12
14
|
|
|
13
|
-
fun getBillingResponseData(responseCode: Int):
|
|
14
|
-
val errorData =
|
|
15
|
-
when (responseCode) {
|
|
15
|
+
fun getBillingResponseData(responseCode: Int): BillingResponse {
|
|
16
|
+
val errorData = when (responseCode) {
|
|
16
17
|
BillingClient.BillingResponseCode.FEATURE_NOT_SUPPORTED -> {
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
BillingResponse(
|
|
19
|
+
PromiseUtils.E_SERVICE_ERROR,
|
|
20
|
+
"This feature is not available on your device."
|
|
21
|
+
)
|
|
19
22
|
}
|
|
20
23
|
BillingClient.BillingResponseCode.SERVICE_DISCONNECTED -> {
|
|
21
|
-
|
|
22
|
-
|
|
24
|
+
BillingResponse(
|
|
25
|
+
PromiseUtils.E_NETWORK_ERROR,
|
|
26
|
+
"The service is disconnected (check your internet connection.)"
|
|
27
|
+
)
|
|
23
28
|
}
|
|
24
29
|
BillingClient.BillingResponseCode.OK -> {
|
|
25
|
-
|
|
26
|
-
|
|
30
|
+
BillingResponse(
|
|
31
|
+
"OK",
|
|
32
|
+
""
|
|
33
|
+
)
|
|
27
34
|
}
|
|
28
35
|
BillingClient.BillingResponseCode.USER_CANCELED -> {
|
|
29
|
-
|
|
30
|
-
|
|
36
|
+
BillingResponse(
|
|
37
|
+
PromiseUtils.E_USER_CANCELLED,
|
|
38
|
+
"Payment is Cancelled."
|
|
39
|
+
)
|
|
31
40
|
}
|
|
32
41
|
BillingClient.BillingResponseCode.SERVICE_UNAVAILABLE -> {
|
|
33
|
-
|
|
34
|
-
|
|
42
|
+
BillingResponse(
|
|
43
|
+
PromiseUtils.E_SERVICE_ERROR,
|
|
35
44
|
"The service is unreachable. This may be your internet connection, or the Play Store may be down."
|
|
45
|
+
)
|
|
36
46
|
}
|
|
37
47
|
BillingClient.BillingResponseCode.BILLING_UNAVAILABLE -> {
|
|
38
|
-
|
|
39
|
-
|
|
48
|
+
BillingResponse(
|
|
49
|
+
PromiseUtils.E_SERVICE_ERROR,
|
|
40
50
|
"Billing is unavailable. This may be a problem with your device, or the Play Store may be down."
|
|
51
|
+
)
|
|
41
52
|
}
|
|
42
53
|
BillingClient.BillingResponseCode.ITEM_UNAVAILABLE -> {
|
|
43
|
-
|
|
44
|
-
|
|
54
|
+
BillingResponse(
|
|
55
|
+
PromiseUtils.E_ITEM_UNAVAILABLE,
|
|
56
|
+
"That item is unavailable."
|
|
57
|
+
)
|
|
45
58
|
}
|
|
46
59
|
BillingClient.BillingResponseCode.DEVELOPER_ERROR -> {
|
|
47
|
-
|
|
48
|
-
|
|
60
|
+
BillingResponse(
|
|
61
|
+
PromiseUtils.E_DEVELOPER_ERROR,
|
|
62
|
+
"Google is indicating that we have some issue connecting to payment."
|
|
63
|
+
)
|
|
49
64
|
}
|
|
50
65
|
BillingClient.BillingResponseCode.ERROR -> {
|
|
51
|
-
|
|
52
|
-
|
|
66
|
+
BillingResponse(
|
|
67
|
+
PromiseUtils.E_UNKNOWN,
|
|
68
|
+
"An unknown or unexpected error has occurred. Please try again later."
|
|
69
|
+
)
|
|
53
70
|
}
|
|
54
71
|
BillingClient.BillingResponseCode.ITEM_ALREADY_OWNED -> {
|
|
55
|
-
|
|
56
|
-
|
|
72
|
+
BillingResponse(
|
|
73
|
+
PromiseUtils.E_ALREADY_OWNED,
|
|
74
|
+
"You already own this item."
|
|
75
|
+
)
|
|
57
76
|
}
|
|
58
77
|
else -> {
|
|
59
|
-
|
|
60
|
-
|
|
78
|
+
BillingResponse(
|
|
79
|
+
PromiseUtils.E_UNKNOWN,
|
|
80
|
+
"Purchase failed with code: $responseCode"
|
|
81
|
+
)
|
|
61
82
|
}
|
|
62
83
|
}
|
|
63
84
|
Log.e(TAG, "Error Code : $responseCode")
|
|
@@ -66,12 +87,6 @@ class PlayUtils {
|
|
|
66
87
|
|
|
67
88
|
fun rejectPromisesWithBillingError(key: String, responseCode: Int) {
|
|
68
89
|
val errorData = getBillingResponseData(responseCode)
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
companion object {
|
|
73
|
-
private const val TAG = "PlayUtils"
|
|
74
|
-
const val E_PLAY_SERVICES_UNAVAILABLE = "E_PLAY_SERVICES_UNAVAILABLE"
|
|
75
|
-
val instance = PlayUtils()
|
|
90
|
+
PromiseUtils.rejectPromisesForKey(key, errorData.code, errorData.message, null)
|
|
76
91
|
}
|
|
77
92
|
}
|