react-native-iap 12.1.1 → 12.2.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/android/src/amazon/java/com/dooboolab/RNIap/RNIapAmazonListener.kt +29 -29
- package/android/src/amazon/java/com/dooboolab/RNIap/RNIapAmazonModule.kt +6 -6
- package/android/src/main/java/com/dooboolab/RNIap/PromiseUtils.kt +56 -0
- package/android/src/main/java/com/dooboolab/RNIap/PromiseUtlis.kt +1 -1
- package/android/src/play/java/com/dooboolab/RNIap/PlayUtils.kt +31 -35
- package/android/src/play/java/com/dooboolab/RNIap/RNIapModule.kt +21 -27
- package/ios/IapSerializationUtils.swift +11 -0
- package/ios/RNIapIosSk2.m +4 -0
- package/ios/RNIapIosSk2.swift +51 -0
- package/lib/commonjs/iap.js +1 -1
- package/lib/commonjs/iap.js.map +1 -1
- package/lib/commonjs/modules/android.js.map +1 -1
- 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/iap.js +1 -1
- package/lib/module/iap.js.map +1 -1
- package/lib/module/modules/android.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/android.d.ts +1 -1
- package/lib/typescript/modules/iosSk2.d.ts +6 -1
- package/lib/typescript/types/appleSk2.d.ts +1 -0
- package/package.json +1 -1
- package/src/iap.ts +1 -1
- package/src/modules/android.ts +1 -1
- package/src/modules/iosSk2.ts +8 -0
- package/src/types/appleSk2.ts +2 -0
- package/android/src/main/java/com/dooboolab/RNIap/DoobooUtils.kt +0 -188
|
@@ -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?
|
|
@@ -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,
|
|
@@ -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,
|
|
@@ -360,6 +359,7 @@ class RNIapAmazonListener(private val reactContext: ReactContext) : PurchasingLi
|
|
|
360
359
|
private const val E_PURCHASE_RESPONSE_INVALID_SKU = "E_PURCHASE_RESPONSE_INVALID_SKU"
|
|
361
360
|
private const val E_USER_DATA_RESPONSE_FAILED = "E_USER_DATA_RESPONSE_FAILED"
|
|
362
361
|
private const val E_USER_DATA_RESPONSE_NOT_SUPPORTED = "E_USER_DATA_RESPONSE_NOT_SUPPORTED"
|
|
362
|
+
const val TAG = "RNIapAmazonListener"
|
|
363
363
|
}
|
|
364
364
|
|
|
365
365
|
init {
|
|
@@ -84,7 +84,7 @@ class RNIapAmazonModule(reactContext: ReactApplicationContext) :
|
|
|
84
84
|
|
|
85
85
|
@ReactMethod
|
|
86
86
|
fun endConnection(promise: Promise) {
|
|
87
|
-
|
|
87
|
+
PromiseUtils.rejectAllPendingPromises()
|
|
88
88
|
amazonListener?.clear()
|
|
89
89
|
hasListener = false
|
|
90
90
|
promise.resolve(true)
|
|
@@ -93,7 +93,7 @@ class RNIapAmazonModule(reactContext: ReactApplicationContext) :
|
|
|
93
93
|
@ReactMethod
|
|
94
94
|
fun getUser(promise: Promise) {
|
|
95
95
|
val requestId = PurchasingService.getUserData()
|
|
96
|
-
|
|
96
|
+
PromiseUtils.addPromiseForKey(PROMISE_GET_USER_DATA, promise)
|
|
97
97
|
}
|
|
98
98
|
|
|
99
99
|
@ReactMethod
|
|
@@ -114,13 +114,13 @@ class RNIapAmazonModule(reactContext: ReactApplicationContext) :
|
|
|
114
114
|
}
|
|
115
115
|
ii++
|
|
116
116
|
}
|
|
117
|
-
|
|
117
|
+
PromiseUtils.addPromiseForKey(PROMISE_GET_PRODUCT_DATA, promise)
|
|
118
118
|
val requestId = PurchasingService.getProductData(productSkus)
|
|
119
119
|
}
|
|
120
120
|
|
|
121
121
|
@ReactMethod
|
|
122
122
|
fun getAvailableItems(promise: Promise) {
|
|
123
|
-
|
|
123
|
+
PromiseUtils.addPromiseForKey(PROMISE_QUERY_AVAILABLE_ITEMS, promise)
|
|
124
124
|
PurchasingService.getPurchaseUpdates(true)
|
|
125
125
|
}
|
|
126
126
|
|
|
@@ -129,7 +129,7 @@ class RNIapAmazonModule(reactContext: ReactApplicationContext) :
|
|
|
129
129
|
sku: String?,
|
|
130
130
|
promise: Promise
|
|
131
131
|
) {
|
|
132
|
-
|
|
132
|
+
PromiseUtils.addPromiseForKey(PROMISE_BUY_ITEM, promise)
|
|
133
133
|
val requestId = PurchasingService.purchase(sku)
|
|
134
134
|
}
|
|
135
135
|
|
|
@@ -154,7 +154,7 @@ class RNIapAmazonModule(reactContext: ReactApplicationContext) :
|
|
|
154
154
|
}
|
|
155
155
|
|
|
156
156
|
private fun sendUnconsumedPurchases(promise: Promise) {
|
|
157
|
-
|
|
157
|
+
PromiseUtils.addPromiseForKey(PROMISE_QUERY_PURCHASES, promise)
|
|
158
158
|
PurchasingService.getPurchaseUpdates(false)
|
|
159
159
|
}
|
|
160
160
|
|
|
@@ -0,0 +1,56 @@
|
|
|
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
|
+
|
|
40
|
+
private const val TAG = "PromiseUtils"
|
|
41
|
+
const val E_UNKNOWN = "E_UNKNOWN"
|
|
42
|
+
const val E_NOT_PREPARED = "E_NOT_PREPARED"
|
|
43
|
+
const val E_ALREADY_PREPARED = "E_ALREADY_PREPARED"
|
|
44
|
+
const val E_NOT_ENDED = "E_NOT_ENDED"
|
|
45
|
+
const val E_USER_CANCELLED = "E_USER_CANCELLED"
|
|
46
|
+
const val E_ITEM_UNAVAILABLE = "E_ITEM_UNAVAILABLE"
|
|
47
|
+
const val E_NETWORK_ERROR = "E_NETWORK_ERROR"
|
|
48
|
+
const val E_SERVICE_ERROR = "E_SERVICE_ERROR"
|
|
49
|
+
const val E_ALREADY_OWNED = "E_ALREADY_OWNED"
|
|
50
|
+
const val E_REMOTE_ERROR = "E_REMOTE_ERROR"
|
|
51
|
+
const val E_USER_ERROR = "E_USER_ERROR"
|
|
52
|
+
const val E_DEVELOPER_ERROR = "E_DEVELOPER_ERROR"
|
|
53
|
+
const val E_BILLING_RESPONSE_JSON_PARSE_ERROR = "E_BILLING_RESPONSE_JSON_PARSE_ERROR"
|
|
54
|
+
const val E_CONNECTION_CLOSED = "E_CONNECTION_CLOSED"
|
|
55
|
+
|
|
56
|
+
}
|
|
@@ -4,60 +4,62 @@ 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
|
+
fun getBillingResponseData(responseCode: Int): BillingResponse {
|
|
16
|
+
val errorData=
|
|
15
17
|
when (responseCode) {
|
|
16
18
|
BillingClient.BillingResponseCode.FEATURE_NOT_SUPPORTED -> {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
+
BillingResponse( PromiseUtils.E_SERVICE_ERROR,
|
|
20
|
+
"This feature is not available on your device.")
|
|
19
21
|
}
|
|
20
22
|
BillingClient.BillingResponseCode.SERVICE_DISCONNECTED -> {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
+
BillingResponse( PromiseUtils.E_NETWORK_ERROR
|
|
24
|
+
, "The service is disconnected (check your internet connection.)")
|
|
23
25
|
}
|
|
24
26
|
BillingClient.BillingResponseCode.OK -> {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
+
BillingResponse( "OK"
|
|
28
|
+
, "")
|
|
27
29
|
}
|
|
28
30
|
BillingClient.BillingResponseCode.USER_CANCELED -> {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
+
BillingResponse( PromiseUtils.E_USER_CANCELLED
|
|
32
|
+
, "Payment is Cancelled.")
|
|
31
33
|
}
|
|
32
34
|
BillingClient.BillingResponseCode.SERVICE_UNAVAILABLE -> {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
"The service is unreachable. This may be your internet connection, or the Play Store may be down."
|
|
35
|
+
BillingResponse( PromiseUtils.E_SERVICE_ERROR
|
|
36
|
+
,
|
|
37
|
+
"The service is unreachable. This may be your internet connection, or the Play Store may be down.")
|
|
36
38
|
}
|
|
37
39
|
BillingClient.BillingResponseCode.BILLING_UNAVAILABLE -> {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
"Billing is unavailable. This may be a problem with your device, or the Play Store may be down."
|
|
40
|
+
BillingResponse( PromiseUtils.E_SERVICE_ERROR
|
|
41
|
+
,
|
|
42
|
+
"Billing is unavailable. This may be a problem with your device, or the Play Store may be down.")
|
|
41
43
|
}
|
|
42
44
|
BillingClient.BillingResponseCode.ITEM_UNAVAILABLE -> {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
+
BillingResponse( PromiseUtils.E_ITEM_UNAVAILABLE
|
|
46
|
+
, "That item is unavailable.")
|
|
45
47
|
}
|
|
46
48
|
BillingClient.BillingResponseCode.DEVELOPER_ERROR -> {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
+
BillingResponse( PromiseUtils.E_DEVELOPER_ERROR
|
|
50
|
+
, "Google is indicating that we have some issue connecting to payment.")
|
|
49
51
|
}
|
|
50
52
|
BillingClient.BillingResponseCode.ERROR -> {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
+
BillingResponse( PromiseUtils.E_UNKNOWN
|
|
54
|
+
, "An unknown or unexpected error has occurred. Please try again later.")
|
|
53
55
|
}
|
|
54
56
|
BillingClient.BillingResponseCode.ITEM_ALREADY_OWNED -> {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
+
BillingResponse( PromiseUtils.E_ALREADY_OWNED
|
|
58
|
+
, "You already own this item.")
|
|
57
59
|
}
|
|
58
60
|
else -> {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
+
BillingResponse( PromiseUtils.E_UNKNOWN
|
|
62
|
+
, "Purchase failed with code: $responseCode")
|
|
61
63
|
}
|
|
62
64
|
}
|
|
63
65
|
Log.e(TAG, "Error Code : $responseCode")
|
|
@@ -66,12 +68,6 @@ class PlayUtils {
|
|
|
66
68
|
|
|
67
69
|
fun rejectPromisesWithBillingError(key: String, responseCode: Int) {
|
|
68
70
|
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()
|
|
71
|
+
PromiseUtils.rejectPromisesForKey(key, errorData.code, errorData.message, null)
|
|
76
72
|
}
|
|
77
73
|
}
|
|
@@ -66,7 +66,7 @@ class RNIapModule(
|
|
|
66
66
|
if (connectedBillingClient?.isReady == true) {
|
|
67
67
|
callback(connectedBillingClient)
|
|
68
68
|
} else {
|
|
69
|
-
promise.safeReject(
|
|
69
|
+
promise.safeReject(PromiseUtils.E_NOT_PREPARED, "Unable to auto-initialize connection")
|
|
70
70
|
}
|
|
71
71
|
} else {
|
|
72
72
|
Log.i(TAG, "Incorrect parameter in resolve")
|
|
@@ -93,7 +93,7 @@ class RNIapModule(
|
|
|
93
93
|
!= ConnectionResult.SUCCESS
|
|
94
94
|
) {
|
|
95
95
|
Log.i(TAG, "Google Play Services are not available on this device")
|
|
96
|
-
promise.safeReject(
|
|
96
|
+
promise.safeReject(PromiseUtils.E_NOT_PREPARED, "Google Play Services are not available on this device")
|
|
97
97
|
return
|
|
98
98
|
}
|
|
99
99
|
|
|
@@ -128,7 +128,7 @@ class RNIapModule(
|
|
|
128
128
|
billingClientCache?.endConnection()
|
|
129
129
|
billingClientCache = null
|
|
130
130
|
skus.clear()
|
|
131
|
-
|
|
131
|
+
PromiseUtils.rejectAllPendingPromises()
|
|
132
132
|
promise.safeResolve(true)
|
|
133
133
|
}
|
|
134
134
|
|
|
@@ -147,8 +147,7 @@ class RNIapModule(
|
|
|
147
147
|
val listener =
|
|
148
148
|
ConsumeResponseListener { billingResult: BillingResult, outToken: String? ->
|
|
149
149
|
if (billingResult.responseCode != expectedResponseCode) {
|
|
150
|
-
PlayUtils.
|
|
151
|
-
.rejectPromiseWithBillingError(
|
|
150
|
+
PlayUtils.rejectPromiseWithBillingError(
|
|
152
151
|
promise,
|
|
153
152
|
billingResult.responseCode
|
|
154
153
|
)
|
|
@@ -301,8 +300,7 @@ class RNIapModule(
|
|
|
301
300
|
): Boolean {
|
|
302
301
|
Log.d(TAG, "responseCode: " + billingResult.responseCode)
|
|
303
302
|
if (billingResult.responseCode != BillingClient.BillingResponseCode.OK) {
|
|
304
|
-
PlayUtils.
|
|
305
|
-
.rejectPromiseWithBillingError(promise, billingResult.responseCode)
|
|
303
|
+
PlayUtils.rejectPromiseWithBillingError(promise, billingResult.responseCode)
|
|
306
304
|
return false
|
|
307
305
|
}
|
|
308
306
|
return true
|
|
@@ -403,13 +401,13 @@ class RNIapModule(
|
|
|
403
401
|
) {
|
|
404
402
|
val activity = currentActivity
|
|
405
403
|
if (activity == null) {
|
|
406
|
-
promise.safeReject(
|
|
404
|
+
promise.safeReject(PromiseUtils.E_UNKNOWN, "getCurrentActivity returned null")
|
|
407
405
|
return
|
|
408
406
|
}
|
|
409
407
|
ensureConnection(
|
|
410
408
|
promise
|
|
411
409
|
) { billingClient ->
|
|
412
|
-
|
|
410
|
+
PromiseUtils.addPromiseForKey(
|
|
413
411
|
PROMISE_BUY_ITEM,
|
|
414
412
|
promise
|
|
415
413
|
)
|
|
@@ -520,9 +518,8 @@ class RNIapModule(
|
|
|
520
518
|
promise.safeResolve(true)
|
|
521
519
|
return@ensureConnection
|
|
522
520
|
} else {
|
|
523
|
-
val errorData
|
|
524
|
-
|
|
525
|
-
promise.safeReject(errorData[0], errorData[1])
|
|
521
|
+
val errorData = PlayUtils.getBillingResponseData(billingResultCode)
|
|
522
|
+
promise.safeReject(errorData.code, errorData.message)
|
|
526
523
|
}
|
|
527
524
|
}
|
|
528
525
|
}
|
|
@@ -548,10 +545,9 @@ class RNIapModule(
|
|
|
548
545
|
val map = Arguments.createMap()
|
|
549
546
|
map.putInt("responseCode", billingResult.responseCode)
|
|
550
547
|
map.putString("debugMessage", billingResult.debugMessage)
|
|
551
|
-
val errorData
|
|
552
|
-
|
|
553
|
-
map.putString("
|
|
554
|
-
map.putString("message", errorData[1])
|
|
548
|
+
val errorData = PlayUtils.getBillingResponseData(billingResult.responseCode)
|
|
549
|
+
map.putString("code", errorData.code)
|
|
550
|
+
map.putString("message", errorData.message)
|
|
555
551
|
promise.safeResolve(map)
|
|
556
552
|
}
|
|
557
553
|
}
|
|
@@ -575,10 +571,9 @@ class RNIapModule(
|
|
|
575
571
|
val map = Arguments.createMap()
|
|
576
572
|
map.putInt("responseCode", billingResult.responseCode)
|
|
577
573
|
map.putString("debugMessage", billingResult.debugMessage)
|
|
578
|
-
val errorData
|
|
579
|
-
|
|
580
|
-
map.putString("
|
|
581
|
-
map.putString("message", errorData[1])
|
|
574
|
+
val errorData = PlayUtils.getBillingResponseData(billingResult.responseCode)
|
|
575
|
+
map.putString("code", errorData.code)
|
|
576
|
+
map.putString("message", errorData.message)
|
|
582
577
|
map.putString("purchaseToken", purchaseToken)
|
|
583
578
|
promise.safeResolve(map)
|
|
584
579
|
}
|
|
@@ -591,12 +586,11 @@ class RNIapModule(
|
|
|
591
586
|
val error = Arguments.createMap()
|
|
592
587
|
error.putInt("responseCode", responseCode)
|
|
593
588
|
error.putString("debugMessage", billingResult.debugMessage)
|
|
594
|
-
val errorData
|
|
595
|
-
|
|
596
|
-
error.putString("
|
|
597
|
-
error.putString("message", errorData[1])
|
|
589
|
+
val errorData = PlayUtils.getBillingResponseData(responseCode)
|
|
590
|
+
error.putString("code", errorData.code)
|
|
591
|
+
error.putString("message", errorData.message)
|
|
598
592
|
sendEvent(reactContext, "purchase-error", error)
|
|
599
|
-
PlayUtils.
|
|
593
|
+
PlayUtils.rejectPromisesWithBillingError(PROMISE_BUY_ITEM, responseCode)
|
|
600
594
|
return
|
|
601
595
|
}
|
|
602
596
|
if (purchases != null) {
|
|
@@ -632,7 +626,7 @@ class RNIapModule(
|
|
|
632
626
|
promiseItems.pushMap(item.copy())
|
|
633
627
|
sendEvent(reactContext, "purchase-updated", item)
|
|
634
628
|
}
|
|
635
|
-
|
|
629
|
+
PromiseUtils.resolvePromisesForKey(PROMISE_BUY_ITEM, promiseItems)
|
|
636
630
|
} else {
|
|
637
631
|
val result = Arguments.createMap()
|
|
638
632
|
result.putInt("responseCode", billingResult.responseCode)
|
|
@@ -643,7 +637,7 @@ class RNIapModule(
|
|
|
643
637
|
" proration. If not please report an issue."
|
|
644
638
|
)
|
|
645
639
|
sendEvent(reactContext, "purchase-updated", result)
|
|
646
|
-
|
|
640
|
+
PromiseUtils.resolvePromisesForKey(PROMISE_BUY_ITEM, null)
|
|
647
641
|
}
|
|
648
642
|
}
|
|
649
643
|
|
|
@@ -196,3 +196,14 @@ func serialize(_ pt: Product.ProductType?) -> String? {
|
|
|
196
196
|
return nil
|
|
197
197
|
}
|
|
198
198
|
}
|
|
199
|
+
|
|
200
|
+
@available(iOS 15.0, tvOS 15.0, *)
|
|
201
|
+
func serialize(_ rs: Transaction.RefundRequestStatus?) -> String? {
|
|
202
|
+
guard let rs = rs else {return nil}
|
|
203
|
+
switch rs {
|
|
204
|
+
case .success: return "success"
|
|
205
|
+
case .userCancelled: return "userCancelled"
|
|
206
|
+
default:
|
|
207
|
+
return nil
|
|
208
|
+
}
|
|
209
|
+
}
|
package/ios/RNIapIosSk2.m
CHANGED
|
@@ -89,5 +89,9 @@ RCT_EXTERN_METHOD(clearTransaction:
|
|
|
89
89
|
(RCTPromiseResolveBlock)resolve
|
|
90
90
|
reject:(RCTPromiseRejectBlock)reject)
|
|
91
91
|
|
|
92
|
+
RCT_EXTERN_METHOD(beginRefundRequest:
|
|
93
|
+
(NSString*)sku
|
|
94
|
+
resolve:(RCTPromiseResolveBlock)resolve
|
|
95
|
+
reject:(RCTPromiseRejectBlock)reject)
|
|
92
96
|
@end
|
|
93
97
|
#endif
|