react-native-iap 12.1.2 → 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/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 +6 -1
- package/lib/typescript/types/appleSk2.d.ts +1 -0
- package/package.json +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
|
package/ios/RNIapIosSk2.swift
CHANGED
|
@@ -90,6 +90,12 @@ protocol Sk2Delegate {
|
|
|
90
90
|
reject: @escaping RCTPromiseRejectBlock
|
|
91
91
|
)
|
|
92
92
|
|
|
93
|
+
func beginRefundRequest(
|
|
94
|
+
_ sku: String,
|
|
95
|
+
resolve: @escaping RCTPromiseResolveBlock,
|
|
96
|
+
reject: @escaping RCTPromiseRejectBlock
|
|
97
|
+
)
|
|
98
|
+
|
|
93
99
|
func startObserving()
|
|
94
100
|
func stopObserving()
|
|
95
101
|
}
|
|
@@ -212,6 +218,14 @@ class DummySk2: Sk2Delegate {
|
|
|
212
218
|
reject(errorCode, errorMessage, nil)
|
|
213
219
|
}
|
|
214
220
|
|
|
221
|
+
func beginRefundRequest(
|
|
222
|
+
_ sku: String,
|
|
223
|
+
resolve: @escaping RCTPromiseResolveBlock,
|
|
224
|
+
reject: @escaping RCTPromiseRejectBlock
|
|
225
|
+
) {
|
|
226
|
+
reject(errorCode, errorMessage, nil)
|
|
227
|
+
}
|
|
228
|
+
|
|
215
229
|
func startObserving() {
|
|
216
230
|
}
|
|
217
231
|
|
|
@@ -376,6 +390,14 @@ class RNIapIosSk2: RCTEventEmitter, Sk2Delegate {
|
|
|
376
390
|
reject: @escaping RCTPromiseRejectBlock = { _, _, _ in }) {
|
|
377
391
|
delegate.clearTransaction(resolve, reject: reject)
|
|
378
392
|
}
|
|
393
|
+
|
|
394
|
+
@objc public func beginRefundRequest(
|
|
395
|
+
_ sku: String,
|
|
396
|
+
resolve: @escaping RCTPromiseResolveBlock = { _ in },
|
|
397
|
+
reject: @escaping RCTPromiseRejectBlock = { _, _, _ in }
|
|
398
|
+
) {
|
|
399
|
+
delegate.beginRefundRequest(sku, resolve: resolve, reject: reject)
|
|
400
|
+
}
|
|
379
401
|
}
|
|
380
402
|
|
|
381
403
|
@available(iOS 15.0, tvOS 15.0, *)
|
|
@@ -843,4 +865,33 @@ class RNIapIosSk2iOS15: Sk2Delegate {
|
|
|
843
865
|
resolve(nil)
|
|
844
866
|
}
|
|
845
867
|
}
|
|
868
|
+
|
|
869
|
+
// TODO: Duplicated code to get the latest transaction, can be cleaned up.
|
|
870
|
+
func beginRefundRequest(_ sku: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
|
871
|
+
Task {
|
|
872
|
+
if let windowScene = await UIApplication.shared.keyWindow?.windowScene {
|
|
873
|
+
if let product = products[sku] {
|
|
874
|
+
if let result = await product.latestTransaction {
|
|
875
|
+
do {
|
|
876
|
+
// Check whether the transaction is verified. If it isn’t, catch `failedVerification` error.
|
|
877
|
+
let transaction = try checkVerified(result)
|
|
878
|
+
let refund = try await transaction.beginRefundRequest(in: windowScene )
|
|
879
|
+
resolve(serialize(refund))
|
|
880
|
+
} catch StoreError.failedVerification {
|
|
881
|
+
reject(IapErrors.E_UNKNOWN.rawValue, "Failed to verify transaction for sku \(sku)", StoreError.failedVerification)
|
|
882
|
+
} catch {
|
|
883
|
+
debugMessage(error)
|
|
884
|
+
reject(IapErrors.E_UNKNOWN.rawValue, "Failed to refund purchase", error)
|
|
885
|
+
}
|
|
886
|
+
} else {
|
|
887
|
+
reject(IapErrors.E_DEVELOPER_ERROR.rawValue, "Can't find latest transaction for sku \(sku)", nil)
|
|
888
|
+
}
|
|
889
|
+
} else {
|
|
890
|
+
reject(IapErrors.E_DEVELOPER_ERROR.rawValue, "Can't find product for sku \(sku)", nil)
|
|
891
|
+
}
|
|
892
|
+
} else {
|
|
893
|
+
reject(IapErrors.E_DEVELOPER_ERROR.rawValue, "Cannon find window Scene", nil)
|
|
894
|
+
}
|
|
895
|
+
}
|
|
896
|
+
}
|
|
846
897
|
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.sync = exports.subscriptionStatus = exports.latestTransaction = exports.isEligibleForIntroOffer = exports.currentEntitlement = void 0;
|
|
6
|
+
exports.sync = exports.subscriptionStatus = exports.latestTransaction = exports.isEligibleForIntroOffer = exports.currentEntitlement = exports.beginRefundRequest = void 0;
|
|
7
7
|
|
|
8
8
|
var _reactNative = require("react-native");
|
|
9
9
|
|
|
@@ -48,6 +48,14 @@ const currentEntitlement = sku => RNIapIosSk2.currentEntitlement(sku);
|
|
|
48
48
|
exports.currentEntitlement = currentEntitlement;
|
|
49
49
|
|
|
50
50
|
const latestTransaction = sku => RNIapIosSk2.latestTransaction(sku);
|
|
51
|
+
/**
|
|
52
|
+
*
|
|
53
|
+
*/
|
|
54
|
+
|
|
51
55
|
|
|
52
56
|
exports.latestTransaction = latestTransaction;
|
|
57
|
+
|
|
58
|
+
const beginRefundRequest = sku => RNIapIosSk2.beginRefundRequest(sku);
|
|
59
|
+
|
|
60
|
+
exports.beginRefundRequest = beginRefundRequest;
|
|
53
61
|
//# sourceMappingURL=iosSk2.js.map
|
|
@@ -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>;\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 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;;
|
|
1
|
+
{"version":3,"names":["RNIapIosSk2","NativeModules","sync","isEligibleForIntroOffer","groupID","subscriptionStatus","sku","currentEntitlement","latestTransaction","beginRefundRequest"],"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 RefundRequestStatus,\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>;\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 finishTransaction: finishTransaction;\n getPendingTransactions: getPendingTransactions;\n presentCodeRedemptionSheet: presentCodeRedemptionSheet;\n disable: () => Promise<null>;\n beginRefundRequest: (sku: string) => Promise<RefundRequestStatus>;\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\n/**\n *\n */\nexport const beginRefundRequest = (sku: string): Promise<RefundRequestStatus> =>\n RNIapIosSk2.beginRefundRequest(sku);\n"],"mappings":";;;;;;;AAAA;;AAYA,MAAM;EAACA;AAAD,IAAgBC,0BAAtB;;AA+CA;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;AAGP;AACA;AACA;;;;;AACO,MAAMG,kBAAkB,GAAIH,GAAD,IAChCN,WAAW,CAACS,kBAAZ,CAA+BH,GAA/B,CADK"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["productSk2Map","id","description","displayName","price","displayPrice","prod","title","productId","String","type","localizedPrice","currency","subscriptionSk2Map","subscription","platform","SubscriptionPlatform","ios","subscriptionPeriodNumberIOS","subscriptionPeriod","value","subscriptionPeriodUnitIOS","unit","toUpperCase","transactionSk2Map","originalPurchaseDate","productID","purchaseDate","purchasedQuantity","purchase","transactionId","transactionDate","transactionReceipt","purchaseToken","quantityIOS","originalTransactionDateIOS","originalTransactionIdentifierIOS","offerSk2Map","offer","undefined","offerID","identifier","keyID","keyIdentifier","nonce","signature","timestamp","toString"],"sources":["appleSk2.ts"],"sourcesContent":["import type {PurchaseError} from '../purchaseError';\n\nimport type {\n ProductIOS,\n Purchase,\n SubscriptionIOS,\n SubscriptionIosPeriod,\n} from '.';\nimport type * as Apple from './apple';\nimport {SubscriptionPlatform} from '.';\n\nexport type SubscriptionPeriod = {\n unit: 'day' | 'week' | 'month' | 'year';\n value: number;\n};\n\nexport type PaymentMode = 'freeTrial' | 'payAsYouGo' | 'payUpFront';\n\nexport type SubscriptionOffer = {\n displayPrice: string;\n id: string;\n paymentMode: PaymentMode;\n period: SubscriptionPeriod;\n periodCount: number;\n price: number;\n type: 'introductory' | 'promotional';\n};\n\nexport type SubscriptionInfo = {\n introductoryOffer?: SubscriptionOffer;\n promotionalOffers?: SubscriptionOffer[];\n subscriptionGroupID: string;\n subscriptionPeriod: SubscriptionPeriod;\n};\n\nexport type ProductSk2 = {\n description: string;\n displayName: string;\n displayPrice: string;\n id: number;\n isFamilyShareable: boolean;\n jsonRepresentation: string;\n price: number;\n subscription: SubscriptionInfo;\n type: 'autoRenewable' | 'consumable' | 'nonConsumable' | 'nonRenewable';\n};\nexport const productSk2Map = ({\n id,\n description,\n displayName,\n price,\n displayPrice,\n}: ProductSk2): ProductIOS => {\n const prod: ProductIOS = {\n title: displayName,\n productId: String(id),\n description,\n type: 'iap',\n price: String(price),\n localizedPrice: displayPrice,\n currency: '', // Not avaiable on new API, use localizedPrice instead\n };\n return prod;\n};\n\nexport const subscriptionSk2Map = ({\n id,\n description,\n displayName,\n price,\n displayPrice,\n subscription,\n}: ProductSk2): SubscriptionIOS => {\n const prod: SubscriptionIOS = {\n platform: SubscriptionPlatform.ios,\n title: displayName,\n productId: String(id),\n description,\n type: 'subs',\n price: String(price),\n localizedPrice: displayPrice,\n currency: '', // Not avaiable on new API, use localizedPrice instead\n subscriptionPeriodNumberIOS: `${subscription?.subscriptionPeriod?.value}`,\n subscriptionPeriodUnitIOS:\n subscription?.subscriptionPeriod?.unit.toUpperCase() as SubscriptionIosPeriod,\n };\n return prod;\n};\n\nexport type TransactionSk2 = {\n appAccountToken: string;\n appBundleID: string;\n debugDescription: string;\n deviceVerification: string;\n deviceVerificationNonce: string;\n expirationDate: number;\n id: number;\n isUpgraded: boolean;\n jsonRepresentation: string;\n offerID: string;\n offerType: string;\n originalID: string;\n originalPurchaseDate: number;\n ownershipType: string;\n productID: string;\n productType: string;\n purchaseDate: number;\n purchasedQuantity: number;\n revocationDate: number;\n revocationReason: string;\n signedDate: number;\n subscriptionGroupID: number;\n webOrderLineItemID: number;\n};\n\nexport type TransactionError = PurchaseError;\n\n/**\n * Only one of `transaction` and `error` is not undefined at the time\n */\nexport type TransactionEvent = {\n transaction?: TransactionSk2;\n error?: TransactionError;\n};\n\nexport type SubscriptionStatus =\n | 'expired'\n | 'inBillingRetryPeriod'\n | 'inGracePeriod'\n | 'revoked'\n | 'subscribed';\n\nexport type ProductStatus = {\n state: SubscriptionStatus;\n};\n\nexport const transactionSk2Map = ({\n id,\n originalPurchaseDate,\n productID,\n purchaseDate,\n purchasedQuantity,\n}: TransactionSk2): Purchase => {\n const purchase: Purchase = {\n productId: productID,\n transactionId: String(id),\n transactionDate: purchaseDate, //??\n transactionReceipt: '', // Not available\n purchaseToken: '', //Not avaiable\n quantityIOS: purchasedQuantity,\n originalTransactionDateIOS: String(originalPurchaseDate),\n originalTransactionIdentifierIOS: String(id), // ??\n };\n return purchase;\n};\n\n/**\n * Payment discount interface @see https://developer.apple.com/documentation/storekit/skpaymentdiscount?language=objc\n */\nexport interface PaymentDiscountSk2 {\n /**\n * A string used to uniquely identify a discount offer for a product.\n */\n offerID: string;\n\n /**\n * A string that identifies the key used to generate the signature.\n */\n keyID: string;\n\n /**\n * A universally unique ID (UUID) value that you define.\n */\n nonce: string;\n\n /**\n * A UTF-8 string representing the properties of a specific discount offer, cryptographically signed.\n */\n signature: string;\n\n /**\n * The date and time of the signature's creation in milliseconds, formatted in Unix epoch time.\n */\n timestamp: number;\n}\n\nexport const offerSk2Map = (\n offer: Apple.PaymentDiscount | undefined,\n): Record<keyof PaymentDiscountSk2, string> | undefined => {\n if (!offer) {\n return undefined;\n }\n return {\n offerID: offer.identifier,\n keyID: offer.keyIdentifier,\n nonce: offer.nonce,\n signature: offer.signature,\n timestamp: offer.timestamp.toString(),\n };\n};\n"],"mappings":";;;;;;;AASA;;
|
|
1
|
+
{"version":3,"names":["productSk2Map","id","description","displayName","price","displayPrice","prod","title","productId","String","type","localizedPrice","currency","subscriptionSk2Map","subscription","platform","SubscriptionPlatform","ios","subscriptionPeriodNumberIOS","subscriptionPeriod","value","subscriptionPeriodUnitIOS","unit","toUpperCase","transactionSk2Map","originalPurchaseDate","productID","purchaseDate","purchasedQuantity","purchase","transactionId","transactionDate","transactionReceipt","purchaseToken","quantityIOS","originalTransactionDateIOS","originalTransactionIdentifierIOS","offerSk2Map","offer","undefined","offerID","identifier","keyID","keyIdentifier","nonce","signature","timestamp","toString"],"sources":["appleSk2.ts"],"sourcesContent":["import type {PurchaseError} from '../purchaseError';\n\nimport type {\n ProductIOS,\n Purchase,\n SubscriptionIOS,\n SubscriptionIosPeriod,\n} from '.';\nimport type * as Apple from './apple';\nimport {SubscriptionPlatform} from '.';\n\nexport type SubscriptionPeriod = {\n unit: 'day' | 'week' | 'month' | 'year';\n value: number;\n};\n\nexport type PaymentMode = 'freeTrial' | 'payAsYouGo' | 'payUpFront';\n\nexport type SubscriptionOffer = {\n displayPrice: string;\n id: string;\n paymentMode: PaymentMode;\n period: SubscriptionPeriod;\n periodCount: number;\n price: number;\n type: 'introductory' | 'promotional';\n};\n\nexport type SubscriptionInfo = {\n introductoryOffer?: SubscriptionOffer;\n promotionalOffers?: SubscriptionOffer[];\n subscriptionGroupID: string;\n subscriptionPeriod: SubscriptionPeriod;\n};\n\nexport type RefundRequestStatus = 'success' | 'userCancelled';\n\nexport type ProductSk2 = {\n description: string;\n displayName: string;\n displayPrice: string;\n id: number;\n isFamilyShareable: boolean;\n jsonRepresentation: string;\n price: number;\n subscription: SubscriptionInfo;\n type: 'autoRenewable' | 'consumable' | 'nonConsumable' | 'nonRenewable';\n};\nexport const productSk2Map = ({\n id,\n description,\n displayName,\n price,\n displayPrice,\n}: ProductSk2): ProductIOS => {\n const prod: ProductIOS = {\n title: displayName,\n productId: String(id),\n description,\n type: 'iap',\n price: String(price),\n localizedPrice: displayPrice,\n currency: '', // Not avaiable on new API, use localizedPrice instead\n };\n return prod;\n};\n\nexport const subscriptionSk2Map = ({\n id,\n description,\n displayName,\n price,\n displayPrice,\n subscription,\n}: ProductSk2): SubscriptionIOS => {\n const prod: SubscriptionIOS = {\n platform: SubscriptionPlatform.ios,\n title: displayName,\n productId: String(id),\n description,\n type: 'subs',\n price: String(price),\n localizedPrice: displayPrice,\n currency: '', // Not avaiable on new API, use localizedPrice instead\n subscriptionPeriodNumberIOS: `${subscription?.subscriptionPeriod?.value}`,\n subscriptionPeriodUnitIOS:\n subscription?.subscriptionPeriod?.unit.toUpperCase() as SubscriptionIosPeriod,\n };\n return prod;\n};\n\nexport type TransactionSk2 = {\n appAccountToken: string;\n appBundleID: string;\n debugDescription: string;\n deviceVerification: string;\n deviceVerificationNonce: string;\n expirationDate: number;\n id: number;\n isUpgraded: boolean;\n jsonRepresentation: string;\n offerID: string;\n offerType: string;\n originalID: string;\n originalPurchaseDate: number;\n ownershipType: string;\n productID: string;\n productType: string;\n purchaseDate: number;\n purchasedQuantity: number;\n revocationDate: number;\n revocationReason: string;\n signedDate: number;\n subscriptionGroupID: number;\n webOrderLineItemID: number;\n};\n\nexport type TransactionError = PurchaseError;\n\n/**\n * Only one of `transaction` and `error` is not undefined at the time\n */\nexport type TransactionEvent = {\n transaction?: TransactionSk2;\n error?: TransactionError;\n};\n\nexport type SubscriptionStatus =\n | 'expired'\n | 'inBillingRetryPeriod'\n | 'inGracePeriod'\n | 'revoked'\n | 'subscribed';\n\nexport type ProductStatus = {\n state: SubscriptionStatus;\n};\n\nexport const transactionSk2Map = ({\n id,\n originalPurchaseDate,\n productID,\n purchaseDate,\n purchasedQuantity,\n}: TransactionSk2): Purchase => {\n const purchase: Purchase = {\n productId: productID,\n transactionId: String(id),\n transactionDate: purchaseDate, //??\n transactionReceipt: '', // Not available\n purchaseToken: '', //Not avaiable\n quantityIOS: purchasedQuantity,\n originalTransactionDateIOS: String(originalPurchaseDate),\n originalTransactionIdentifierIOS: String(id), // ??\n };\n return purchase;\n};\n\n/**\n * Payment discount interface @see https://developer.apple.com/documentation/storekit/skpaymentdiscount?language=objc\n */\nexport interface PaymentDiscountSk2 {\n /**\n * A string used to uniquely identify a discount offer for a product.\n */\n offerID: string;\n\n /**\n * A string that identifies the key used to generate the signature.\n */\n keyID: string;\n\n /**\n * A universally unique ID (UUID) value that you define.\n */\n nonce: string;\n\n /**\n * A UTF-8 string representing the properties of a specific discount offer, cryptographically signed.\n */\n signature: string;\n\n /**\n * The date and time of the signature's creation in milliseconds, formatted in Unix epoch time.\n */\n timestamp: number;\n}\n\nexport const offerSk2Map = (\n offer: Apple.PaymentDiscount | undefined,\n): Record<keyof PaymentDiscountSk2, string> | undefined => {\n if (!offer) {\n return undefined;\n }\n return {\n offerID: offer.identifier,\n keyID: offer.keyIdentifier,\n nonce: offer.nonce,\n signature: offer.signature,\n timestamp: offer.timestamp.toString(),\n };\n};\n"],"mappings":";;;;;;;AASA;;AAuCO,MAAMA,aAAa,GAAG,QAMC;EAAA,IANA;IAC5BC,EAD4B;IAE5BC,WAF4B;IAG5BC,WAH4B;IAI5BC,KAJ4B;IAK5BC;EAL4B,CAMA;EAC5B,MAAMC,IAAgB,GAAG;IACvBC,KAAK,EAAEJ,WADgB;IAEvBK,SAAS,EAAEC,MAAM,CAACR,EAAD,CAFM;IAGvBC,WAHuB;IAIvBQ,IAAI,EAAE,KAJiB;IAKvBN,KAAK,EAAEK,MAAM,CAACL,KAAD,CALU;IAMvBO,cAAc,EAAEN,YANO;IAOvBO,QAAQ,EAAE,EAPa,CAOT;;EAPS,CAAzB;EASA,OAAON,IAAP;AACD,CAjBM;;;;AAmBA,MAAMO,kBAAkB,GAAG,SAOC;EAAA;;EAAA,IAPA;IACjCZ,EADiC;IAEjCC,WAFiC;IAGjCC,WAHiC;IAIjCC,KAJiC;IAKjCC,YALiC;IAMjCS;EANiC,CAOA;EACjC,MAAMR,IAAqB,GAAG;IAC5BS,QAAQ,EAAEC,sBAAA,CAAqBC,GADH;IAE5BV,KAAK,EAAEJ,WAFqB;IAG5BK,SAAS,EAAEC,MAAM,CAACR,EAAD,CAHW;IAI5BC,WAJ4B;IAK5BQ,IAAI,EAAE,MALsB;IAM5BN,KAAK,EAAEK,MAAM,CAACL,KAAD,CANe;IAO5BO,cAAc,EAAEN,YAPY;IAQ5BO,QAAQ,EAAE,EARkB;IAQd;IACdM,2BAA2B,EAAG,GAAEJ,YAAH,aAAGA,YAAH,gDAAGA,YAAY,CAAEK,kBAAjB,0DAAG,sBAAkCC,KAAM,EAT5C;IAU5BC,yBAAyB,EACvBP,YADuB,aACvBA,YADuB,iDACvBA,YAAY,CAAEK,kBADS,2DACvB,uBAAkCG,IAAlC,CAAuCC,WAAvC;EAX0B,CAA9B;EAaA,OAAOjB,IAAP;AACD,CAtBM;;;;AAuEA,MAAMkB,iBAAiB,GAAG,SAMD;EAAA,IANE;IAChCvB,EADgC;IAEhCwB,oBAFgC;IAGhCC,SAHgC;IAIhCC,YAJgC;IAKhCC;EALgC,CAMF;EAC9B,MAAMC,QAAkB,GAAG;IACzBrB,SAAS,EAAEkB,SADc;IAEzBI,aAAa,EAAErB,MAAM,CAACR,EAAD,CAFI;IAGzB8B,eAAe,EAAEJ,YAHQ;IAGM;IAC/BK,kBAAkB,EAAE,EAJK;IAID;IACxBC,aAAa,EAAE,EALU;IAKN;IACnBC,WAAW,EAAEN,iBANY;IAOzBO,0BAA0B,EAAE1B,MAAM,CAACgB,oBAAD,CAPT;IAQzBW,gCAAgC,EAAE3B,MAAM,CAACR,EAAD,CARf,CAQqB;;EARrB,CAA3B;EAUA,OAAO4B,QAAP;AACD,CAlBM;AAoBP;AACA;AACA;;;;;AA4BO,MAAMQ,WAAW,GACtBC,KADyB,IAEgC;EACzD,IAAI,CAACA,KAAL,EAAY;IACV,OAAOC,SAAP;EACD;;EACD,OAAO;IACLC,OAAO,EAAEF,KAAK,CAACG,UADV;IAELC,KAAK,EAAEJ,KAAK,CAACK,aAFR;IAGLC,KAAK,EAAEN,KAAK,CAACM,KAHR;IAILC,SAAS,EAAEP,KAAK,CAACO,SAJZ;IAKLC,SAAS,EAAER,KAAK,CAACQ,SAAN,CAAgBC,QAAhB;EALN,CAAP;AAOD,CAbM"}
|
|
@@ -28,4 +28,9 @@ export const currentEntitlement = sku => RNIapIosSk2.currentEntitlement(sku);
|
|
|
28
28
|
*/
|
|
29
29
|
|
|
30
30
|
export const latestTransaction = sku => RNIapIosSk2.latestTransaction(sku);
|
|
31
|
+
/**
|
|
32
|
+
*
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
export const beginRefundRequest = sku => RNIapIosSk2.beginRefundRequest(sku);
|
|
31
36
|
//# sourceMappingURL=iosSk2.js.map
|
|
@@ -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>;\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 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;
|
|
1
|
+
{"version":3,"names":["NativeModules","RNIapIosSk2","sync","isEligibleForIntroOffer","groupID","subscriptionStatus","sku","currentEntitlement","latestTransaction","beginRefundRequest"],"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 RefundRequestStatus,\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>;\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 finishTransaction: finishTransaction;\n getPendingTransactions: getPendingTransactions;\n presentCodeRedemptionSheet: presentCodeRedemptionSheet;\n disable: () => Promise<null>;\n beginRefundRequest: (sku: string) => Promise<RefundRequestStatus>;\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\n/**\n *\n */\nexport const beginRefundRequest = (sku: string): Promise<RefundRequestStatus> =>\n RNIapIosSk2.beginRefundRequest(sku);\n"],"mappings":"AAAA,SAAQA,aAAR,QAA4B,cAA5B;AAYA,MAAM;EAACC;AAAD,IAAgBD,aAAtB;;AA+CA;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;AAGP;AACA;AACA;;AACA,OAAO,MAAMG,kBAAkB,GAAIH,GAAD,IAChCL,WAAW,CAACQ,kBAAZ,CAA+BH,GAA/B,CADK"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["SubscriptionPlatform","productSk2Map","id","description","displayName","price","displayPrice","prod","title","productId","String","type","localizedPrice","currency","subscriptionSk2Map","subscription","platform","ios","subscriptionPeriodNumberIOS","subscriptionPeriod","value","subscriptionPeriodUnitIOS","unit","toUpperCase","transactionSk2Map","originalPurchaseDate","productID","purchaseDate","purchasedQuantity","purchase","transactionId","transactionDate","transactionReceipt","purchaseToken","quantityIOS","originalTransactionDateIOS","originalTransactionIdentifierIOS","offerSk2Map","offer","undefined","offerID","identifier","keyID","keyIdentifier","nonce","signature","timestamp","toString"],"sources":["appleSk2.ts"],"sourcesContent":["import type {PurchaseError} from '../purchaseError';\n\nimport type {\n ProductIOS,\n Purchase,\n SubscriptionIOS,\n SubscriptionIosPeriod,\n} from '.';\nimport type * as Apple from './apple';\nimport {SubscriptionPlatform} from '.';\n\nexport type SubscriptionPeriod = {\n unit: 'day' | 'week' | 'month' | 'year';\n value: number;\n};\n\nexport type PaymentMode = 'freeTrial' | 'payAsYouGo' | 'payUpFront';\n\nexport type SubscriptionOffer = {\n displayPrice: string;\n id: string;\n paymentMode: PaymentMode;\n period: SubscriptionPeriod;\n periodCount: number;\n price: number;\n type: 'introductory' | 'promotional';\n};\n\nexport type SubscriptionInfo = {\n introductoryOffer?: SubscriptionOffer;\n promotionalOffers?: SubscriptionOffer[];\n subscriptionGroupID: string;\n subscriptionPeriod: SubscriptionPeriod;\n};\n\nexport type ProductSk2 = {\n description: string;\n displayName: string;\n displayPrice: string;\n id: number;\n isFamilyShareable: boolean;\n jsonRepresentation: string;\n price: number;\n subscription: SubscriptionInfo;\n type: 'autoRenewable' | 'consumable' | 'nonConsumable' | 'nonRenewable';\n};\nexport const productSk2Map = ({\n id,\n description,\n displayName,\n price,\n displayPrice,\n}: ProductSk2): ProductIOS => {\n const prod: ProductIOS = {\n title: displayName,\n productId: String(id),\n description,\n type: 'iap',\n price: String(price),\n localizedPrice: displayPrice,\n currency: '', // Not avaiable on new API, use localizedPrice instead\n };\n return prod;\n};\n\nexport const subscriptionSk2Map = ({\n id,\n description,\n displayName,\n price,\n displayPrice,\n subscription,\n}: ProductSk2): SubscriptionIOS => {\n const prod: SubscriptionIOS = {\n platform: SubscriptionPlatform.ios,\n title: displayName,\n productId: String(id),\n description,\n type: 'subs',\n price: String(price),\n localizedPrice: displayPrice,\n currency: '', // Not avaiable on new API, use localizedPrice instead\n subscriptionPeriodNumberIOS: `${subscription?.subscriptionPeriod?.value}`,\n subscriptionPeriodUnitIOS:\n subscription?.subscriptionPeriod?.unit.toUpperCase() as SubscriptionIosPeriod,\n };\n return prod;\n};\n\nexport type TransactionSk2 = {\n appAccountToken: string;\n appBundleID: string;\n debugDescription: string;\n deviceVerification: string;\n deviceVerificationNonce: string;\n expirationDate: number;\n id: number;\n isUpgraded: boolean;\n jsonRepresentation: string;\n offerID: string;\n offerType: string;\n originalID: string;\n originalPurchaseDate: number;\n ownershipType: string;\n productID: string;\n productType: string;\n purchaseDate: number;\n purchasedQuantity: number;\n revocationDate: number;\n revocationReason: string;\n signedDate: number;\n subscriptionGroupID: number;\n webOrderLineItemID: number;\n};\n\nexport type TransactionError = PurchaseError;\n\n/**\n * Only one of `transaction` and `error` is not undefined at the time\n */\nexport type TransactionEvent = {\n transaction?: TransactionSk2;\n error?: TransactionError;\n};\n\nexport type SubscriptionStatus =\n | 'expired'\n | 'inBillingRetryPeriod'\n | 'inGracePeriod'\n | 'revoked'\n | 'subscribed';\n\nexport type ProductStatus = {\n state: SubscriptionStatus;\n};\n\nexport const transactionSk2Map = ({\n id,\n originalPurchaseDate,\n productID,\n purchaseDate,\n purchasedQuantity,\n}: TransactionSk2): Purchase => {\n const purchase: Purchase = {\n productId: productID,\n transactionId: String(id),\n transactionDate: purchaseDate, //??\n transactionReceipt: '', // Not available\n purchaseToken: '', //Not avaiable\n quantityIOS: purchasedQuantity,\n originalTransactionDateIOS: String(originalPurchaseDate),\n originalTransactionIdentifierIOS: String(id), // ??\n };\n return purchase;\n};\n\n/**\n * Payment discount interface @see https://developer.apple.com/documentation/storekit/skpaymentdiscount?language=objc\n */\nexport interface PaymentDiscountSk2 {\n /**\n * A string used to uniquely identify a discount offer for a product.\n */\n offerID: string;\n\n /**\n * A string that identifies the key used to generate the signature.\n */\n keyID: string;\n\n /**\n * A universally unique ID (UUID) value that you define.\n */\n nonce: string;\n\n /**\n * A UTF-8 string representing the properties of a specific discount offer, cryptographically signed.\n */\n signature: string;\n\n /**\n * The date and time of the signature's creation in milliseconds, formatted in Unix epoch time.\n */\n timestamp: number;\n}\n\nexport const offerSk2Map = (\n offer: Apple.PaymentDiscount | undefined,\n): Record<keyof PaymentDiscountSk2, string> | undefined => {\n if (!offer) {\n return undefined;\n }\n return {\n offerID: offer.identifier,\n keyID: offer.keyIdentifier,\n nonce: offer.nonce,\n signature: offer.signature,\n timestamp: offer.timestamp.toString(),\n };\n};\n"],"mappings":"AASA,SAAQA,oBAAR,QAAmC,GAAnC;
|
|
1
|
+
{"version":3,"names":["SubscriptionPlatform","productSk2Map","id","description","displayName","price","displayPrice","prod","title","productId","String","type","localizedPrice","currency","subscriptionSk2Map","subscription","platform","ios","subscriptionPeriodNumberIOS","subscriptionPeriod","value","subscriptionPeriodUnitIOS","unit","toUpperCase","transactionSk2Map","originalPurchaseDate","productID","purchaseDate","purchasedQuantity","purchase","transactionId","transactionDate","transactionReceipt","purchaseToken","quantityIOS","originalTransactionDateIOS","originalTransactionIdentifierIOS","offerSk2Map","offer","undefined","offerID","identifier","keyID","keyIdentifier","nonce","signature","timestamp","toString"],"sources":["appleSk2.ts"],"sourcesContent":["import type {PurchaseError} from '../purchaseError';\n\nimport type {\n ProductIOS,\n Purchase,\n SubscriptionIOS,\n SubscriptionIosPeriod,\n} from '.';\nimport type * as Apple from './apple';\nimport {SubscriptionPlatform} from '.';\n\nexport type SubscriptionPeriod = {\n unit: 'day' | 'week' | 'month' | 'year';\n value: number;\n};\n\nexport type PaymentMode = 'freeTrial' | 'payAsYouGo' | 'payUpFront';\n\nexport type SubscriptionOffer = {\n displayPrice: string;\n id: string;\n paymentMode: PaymentMode;\n period: SubscriptionPeriod;\n periodCount: number;\n price: number;\n type: 'introductory' | 'promotional';\n};\n\nexport type SubscriptionInfo = {\n introductoryOffer?: SubscriptionOffer;\n promotionalOffers?: SubscriptionOffer[];\n subscriptionGroupID: string;\n subscriptionPeriod: SubscriptionPeriod;\n};\n\nexport type RefundRequestStatus = 'success' | 'userCancelled';\n\nexport type ProductSk2 = {\n description: string;\n displayName: string;\n displayPrice: string;\n id: number;\n isFamilyShareable: boolean;\n jsonRepresentation: string;\n price: number;\n subscription: SubscriptionInfo;\n type: 'autoRenewable' | 'consumable' | 'nonConsumable' | 'nonRenewable';\n};\nexport const productSk2Map = ({\n id,\n description,\n displayName,\n price,\n displayPrice,\n}: ProductSk2): ProductIOS => {\n const prod: ProductIOS = {\n title: displayName,\n productId: String(id),\n description,\n type: 'iap',\n price: String(price),\n localizedPrice: displayPrice,\n currency: '', // Not avaiable on new API, use localizedPrice instead\n };\n return prod;\n};\n\nexport const subscriptionSk2Map = ({\n id,\n description,\n displayName,\n price,\n displayPrice,\n subscription,\n}: ProductSk2): SubscriptionIOS => {\n const prod: SubscriptionIOS = {\n platform: SubscriptionPlatform.ios,\n title: displayName,\n productId: String(id),\n description,\n type: 'subs',\n price: String(price),\n localizedPrice: displayPrice,\n currency: '', // Not avaiable on new API, use localizedPrice instead\n subscriptionPeriodNumberIOS: `${subscription?.subscriptionPeriod?.value}`,\n subscriptionPeriodUnitIOS:\n subscription?.subscriptionPeriod?.unit.toUpperCase() as SubscriptionIosPeriod,\n };\n return prod;\n};\n\nexport type TransactionSk2 = {\n appAccountToken: string;\n appBundleID: string;\n debugDescription: string;\n deviceVerification: string;\n deviceVerificationNonce: string;\n expirationDate: number;\n id: number;\n isUpgraded: boolean;\n jsonRepresentation: string;\n offerID: string;\n offerType: string;\n originalID: string;\n originalPurchaseDate: number;\n ownershipType: string;\n productID: string;\n productType: string;\n purchaseDate: number;\n purchasedQuantity: number;\n revocationDate: number;\n revocationReason: string;\n signedDate: number;\n subscriptionGroupID: number;\n webOrderLineItemID: number;\n};\n\nexport type TransactionError = PurchaseError;\n\n/**\n * Only one of `transaction` and `error` is not undefined at the time\n */\nexport type TransactionEvent = {\n transaction?: TransactionSk2;\n error?: TransactionError;\n};\n\nexport type SubscriptionStatus =\n | 'expired'\n | 'inBillingRetryPeriod'\n | 'inGracePeriod'\n | 'revoked'\n | 'subscribed';\n\nexport type ProductStatus = {\n state: SubscriptionStatus;\n};\n\nexport const transactionSk2Map = ({\n id,\n originalPurchaseDate,\n productID,\n purchaseDate,\n purchasedQuantity,\n}: TransactionSk2): Purchase => {\n const purchase: Purchase = {\n productId: productID,\n transactionId: String(id),\n transactionDate: purchaseDate, //??\n transactionReceipt: '', // Not available\n purchaseToken: '', //Not avaiable\n quantityIOS: purchasedQuantity,\n originalTransactionDateIOS: String(originalPurchaseDate),\n originalTransactionIdentifierIOS: String(id), // ??\n };\n return purchase;\n};\n\n/**\n * Payment discount interface @see https://developer.apple.com/documentation/storekit/skpaymentdiscount?language=objc\n */\nexport interface PaymentDiscountSk2 {\n /**\n * A string used to uniquely identify a discount offer for a product.\n */\n offerID: string;\n\n /**\n * A string that identifies the key used to generate the signature.\n */\n keyID: string;\n\n /**\n * A universally unique ID (UUID) value that you define.\n */\n nonce: string;\n\n /**\n * A UTF-8 string representing the properties of a specific discount offer, cryptographically signed.\n */\n signature: string;\n\n /**\n * The date and time of the signature's creation in milliseconds, formatted in Unix epoch time.\n */\n timestamp: number;\n}\n\nexport const offerSk2Map = (\n offer: Apple.PaymentDiscount | undefined,\n): Record<keyof PaymentDiscountSk2, string> | undefined => {\n if (!offer) {\n return undefined;\n }\n return {\n offerID: offer.identifier,\n keyID: offer.keyIdentifier,\n nonce: offer.nonce,\n signature: offer.signature,\n timestamp: offer.timestamp.toString(),\n };\n};\n"],"mappings":"AASA,SAAQA,oBAAR,QAAmC,GAAnC;AAuCA,OAAO,MAAMC,aAAa,GAAG,QAMC;EAAA,IANA;IAC5BC,EAD4B;IAE5BC,WAF4B;IAG5BC,WAH4B;IAI5BC,KAJ4B;IAK5BC;EAL4B,CAMA;EAC5B,MAAMC,IAAgB,GAAG;IACvBC,KAAK,EAAEJ,WADgB;IAEvBK,SAAS,EAAEC,MAAM,CAACR,EAAD,CAFM;IAGvBC,WAHuB;IAIvBQ,IAAI,EAAE,KAJiB;IAKvBN,KAAK,EAAEK,MAAM,CAACL,KAAD,CALU;IAMvBO,cAAc,EAAEN,YANO;IAOvBO,QAAQ,EAAE,EAPa,CAOT;;EAPS,CAAzB;EASA,OAAON,IAAP;AACD,CAjBM;AAmBP,OAAO,MAAMO,kBAAkB,GAAG,SAOC;EAAA;;EAAA,IAPA;IACjCZ,EADiC;IAEjCC,WAFiC;IAGjCC,WAHiC;IAIjCC,KAJiC;IAKjCC,YALiC;IAMjCS;EANiC,CAOA;EACjC,MAAMR,IAAqB,GAAG;IAC5BS,QAAQ,EAAEhB,oBAAoB,CAACiB,GADH;IAE5BT,KAAK,EAAEJ,WAFqB;IAG5BK,SAAS,EAAEC,MAAM,CAACR,EAAD,CAHW;IAI5BC,WAJ4B;IAK5BQ,IAAI,EAAE,MALsB;IAM5BN,KAAK,EAAEK,MAAM,CAACL,KAAD,CANe;IAO5BO,cAAc,EAAEN,YAPY;IAQ5BO,QAAQ,EAAE,EARkB;IAQd;IACdK,2BAA2B,EAAG,GAAEH,YAAH,aAAGA,YAAH,gDAAGA,YAAY,CAAEI,kBAAjB,0DAAG,sBAAkCC,KAAM,EAT5C;IAU5BC,yBAAyB,EACvBN,YADuB,aACvBA,YADuB,iDACvBA,YAAY,CAAEI,kBADS,2DACvB,uBAAkCG,IAAlC,CAAuCC,WAAvC;EAX0B,CAA9B;EAaA,OAAOhB,IAAP;AACD,CAtBM;AAuEP,OAAO,MAAMiB,iBAAiB,GAAG,SAMD;EAAA,IANE;IAChCtB,EADgC;IAEhCuB,oBAFgC;IAGhCC,SAHgC;IAIhCC,YAJgC;IAKhCC;EALgC,CAMF;EAC9B,MAAMC,QAAkB,GAAG;IACzBpB,SAAS,EAAEiB,SADc;IAEzBI,aAAa,EAAEpB,MAAM,CAACR,EAAD,CAFI;IAGzB6B,eAAe,EAAEJ,YAHQ;IAGM;IAC/BK,kBAAkB,EAAE,EAJK;IAID;IACxBC,aAAa,EAAE,EALU;IAKN;IACnBC,WAAW,EAAEN,iBANY;IAOzBO,0BAA0B,EAAEzB,MAAM,CAACe,oBAAD,CAPT;IAQzBW,gCAAgC,EAAE1B,MAAM,CAACR,EAAD,CARf,CAQqB;;EARrB,CAA3B;EAUA,OAAO2B,QAAP;AACD,CAlBM;AAoBP;AACA;AACA;;AA4BA,OAAO,MAAMQ,WAAW,GACtBC,KADyB,IAEgC;EACzD,IAAI,CAACA,KAAL,EAAY;IACV,OAAOC,SAAP;EACD;;EACD,OAAO;IACLC,OAAO,EAAEF,KAAK,CAACG,UADV;IAELC,KAAK,EAAEJ,KAAK,CAACK,aAFR;IAGLC,KAAK,EAAEN,KAAK,CAACM,KAHR;IAILC,SAAS,EAAEP,KAAK,CAACO,SAJZ;IAKLC,SAAS,EAAER,KAAK,CAACQ,SAAN,CAAgBC,QAAhB;EALN,CAAP;AAOD,CAbM"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Product, ProductPurchase, Purchase, Sku } from '../types';
|
|
2
|
-
import type { PaymentDiscountSk2, ProductSk2, ProductStatus, TransactionSk2 } from '../types/appleSk2';
|
|
2
|
+
import type { PaymentDiscountSk2, ProductSk2, ProductStatus, RefundRequestStatus, TransactionSk2 } from '../types/appleSk2';
|
|
3
3
|
import type { NativeModuleProps } from './common';
|
|
4
4
|
declare type getItems = (skus: Sku[]) => Promise<ProductSk2[]>;
|
|
5
5
|
declare type getAvailableItems = (alsoPublishToEventListener?: boolean) => Promise<TransactionSk2[]>;
|
|
@@ -29,6 +29,7 @@ export interface IosModulePropsSk2 extends NativeModuleProps {
|
|
|
29
29
|
getPendingTransactions: getPendingTransactions;
|
|
30
30
|
presentCodeRedemptionSheet: presentCodeRedemptionSheet;
|
|
31
31
|
disable: () => Promise<null>;
|
|
32
|
+
beginRefundRequest: (sku: string) => Promise<RefundRequestStatus>;
|
|
32
33
|
}
|
|
33
34
|
/**
|
|
34
35
|
* Sync state with Appstore (iOS only)
|
|
@@ -51,4 +52,8 @@ export declare const currentEntitlement: (sku: string) => Promise<TransactionSk2
|
|
|
51
52
|
*
|
|
52
53
|
*/
|
|
53
54
|
export declare const latestTransaction: (sku: string) => Promise<TransactionSk2>;
|
|
55
|
+
/**
|
|
56
|
+
*
|
|
57
|
+
*/
|
|
58
|
+
export declare const beginRefundRequest: (sku: string) => Promise<RefundRequestStatus>;
|
|
54
59
|
export {};
|
|
@@ -21,6 +21,7 @@ export declare type SubscriptionInfo = {
|
|
|
21
21
|
subscriptionGroupID: string;
|
|
22
22
|
subscriptionPeriod: SubscriptionPeriod;
|
|
23
23
|
};
|
|
24
|
+
export declare type RefundRequestStatus = 'success' | 'userCancelled';
|
|
24
25
|
export declare type ProductSk2 = {
|
|
25
26
|
description: string;
|
|
26
27
|
displayName: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-iap",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.2.0",
|
|
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/modules/iosSk2.ts
CHANGED
|
@@ -5,6 +5,7 @@ import type {
|
|
|
5
5
|
PaymentDiscountSk2,
|
|
6
6
|
ProductSk2,
|
|
7
7
|
ProductStatus,
|
|
8
|
+
RefundRequestStatus,
|
|
8
9
|
TransactionSk2,
|
|
9
10
|
} from '../types/appleSk2';
|
|
10
11
|
|
|
@@ -53,6 +54,7 @@ export interface IosModulePropsSk2 extends NativeModuleProps {
|
|
|
53
54
|
getPendingTransactions: getPendingTransactions;
|
|
54
55
|
presentCodeRedemptionSheet: presentCodeRedemptionSheet;
|
|
55
56
|
disable: () => Promise<null>;
|
|
57
|
+
beginRefundRequest: (sku: string) => Promise<RefundRequestStatus>;
|
|
56
58
|
}
|
|
57
59
|
|
|
58
60
|
/**
|
|
@@ -85,3 +87,9 @@ export const currentEntitlement = (sku: string): Promise<TransactionSk2> =>
|
|
|
85
87
|
*/
|
|
86
88
|
export const latestTransaction = (sku: string): Promise<TransactionSk2> =>
|
|
87
89
|
RNIapIosSk2.latestTransaction(sku);
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
*
|
|
93
|
+
*/
|
|
94
|
+
export const beginRefundRequest = (sku: string): Promise<RefundRequestStatus> =>
|
|
95
|
+
RNIapIosSk2.beginRefundRequest(sku);
|
package/src/types/appleSk2.ts
CHANGED
|
@@ -1,188 +0,0 @@
|
|
|
1
|
-
package com.dooboolab.RNIap
|
|
2
|
-
|
|
3
|
-
import android.util.Log
|
|
4
|
-
import com.facebook.react.bridge.ObjectAlreadyConsumedException
|
|
5
|
-
import com.facebook.react.bridge.Promise
|
|
6
|
-
import com.facebook.react.bridge.ReadableArray
|
|
7
|
-
import com.facebook.react.bridge.ReadableMap
|
|
8
|
-
import com.facebook.react.bridge.ReadableType
|
|
9
|
-
import com.facebook.react.bridge.WritableArray
|
|
10
|
-
import com.facebook.react.bridge.WritableMap
|
|
11
|
-
import com.facebook.react.bridge.WritableNativeArray
|
|
12
|
-
import com.facebook.react.bridge.WritableNativeMap
|
|
13
|
-
import org.json.JSONArray
|
|
14
|
-
import org.json.JSONException
|
|
15
|
-
import org.json.JSONObject
|
|
16
|
-
import java.lang.Exception
|
|
17
|
-
import java.util.ArrayList
|
|
18
|
-
import java.util.HashMap
|
|
19
|
-
import kotlin.Throws
|
|
20
|
-
|
|
21
|
-
class DoobooUtils {
|
|
22
|
-
private val promises = HashMap<String, ArrayList<Promise>>()
|
|
23
|
-
fun addPromiseForKey(key: String, promise: Promise) {
|
|
24
|
-
try {
|
|
25
|
-
val list: ArrayList<Promise>
|
|
26
|
-
if (promises.containsKey(key)) {
|
|
27
|
-
list = promises[key]!!
|
|
28
|
-
} else {
|
|
29
|
-
list = ArrayList()
|
|
30
|
-
}
|
|
31
|
-
list.add(promise)
|
|
32
|
-
promises[key] = list
|
|
33
|
-
} catch (oce: ObjectAlreadyConsumedException) {
|
|
34
|
-
Log.e(TAG, oce.message!!)
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
fun resolvePromisesForKey(key: String, value: Any?) {
|
|
39
|
-
try {
|
|
40
|
-
if (promises.containsKey(key)) {
|
|
41
|
-
val list = promises[key]!!
|
|
42
|
-
for (promise in list) {
|
|
43
|
-
promise.resolve(value)
|
|
44
|
-
}
|
|
45
|
-
promises.remove(key)
|
|
46
|
-
}
|
|
47
|
-
} catch (oce: ObjectAlreadyConsumedException) {
|
|
48
|
-
Log.e(TAG, oce.message!!)
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
fun rejectAllPendingPromises() {
|
|
53
|
-
promises.flatMap { it.value }.forEach { promise ->
|
|
54
|
-
promise.safeReject(E_CONNECTION_CLOSED, "Connection has been closed", null)
|
|
55
|
-
}
|
|
56
|
-
promises.clear()
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
fun rejectPromisesForKey(
|
|
60
|
-
key: String,
|
|
61
|
-
code: String?,
|
|
62
|
-
message: String?,
|
|
63
|
-
err: Exception?
|
|
64
|
-
) {
|
|
65
|
-
try {
|
|
66
|
-
if (promises.containsKey(key)) {
|
|
67
|
-
val list = promises[key]!!
|
|
68
|
-
for (promise in list) {
|
|
69
|
-
promise.reject(code, message, err)
|
|
70
|
-
}
|
|
71
|
-
promises.remove(key)
|
|
72
|
-
}
|
|
73
|
-
} catch (oce: ObjectAlreadyConsumedException) {
|
|
74
|
-
Log.e(TAG, oce.message!!)
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
@Throws(JSONException::class)
|
|
79
|
-
fun convertJsonToMap(jsonObject: JSONObject): WritableMap {
|
|
80
|
-
val map: WritableMap = WritableNativeMap()
|
|
81
|
-
val iterator = jsonObject.keys()
|
|
82
|
-
while (iterator.hasNext()) {
|
|
83
|
-
val key = iterator.next()
|
|
84
|
-
val value = jsonObject[key]
|
|
85
|
-
if (value is JSONObject) {
|
|
86
|
-
map.putMap(key, convertJsonToMap(value))
|
|
87
|
-
} else if (value is JSONArray) {
|
|
88
|
-
map.putArray(key, convertJsonToArray(value))
|
|
89
|
-
} else if (value is Boolean) {
|
|
90
|
-
map.putBoolean(key, value)
|
|
91
|
-
} else if (value is Int) {
|
|
92
|
-
map.putInt(key, value)
|
|
93
|
-
} else if (value is Double) {
|
|
94
|
-
map.putDouble(key, value)
|
|
95
|
-
} else if (value is String) {
|
|
96
|
-
map.putString(key, value)
|
|
97
|
-
} else {
|
|
98
|
-
map.putString(key, value.toString())
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
return map
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
@Throws(JSONException::class)
|
|
105
|
-
fun convertJsonToArray(jsonArray: JSONArray): WritableArray {
|
|
106
|
-
val array: WritableArray = WritableNativeArray()
|
|
107
|
-
for (i in 0 until jsonArray.length()) {
|
|
108
|
-
val value = jsonArray[i]
|
|
109
|
-
if (value is JSONObject) {
|
|
110
|
-
array.pushMap(convertJsonToMap(value))
|
|
111
|
-
} else if (value is JSONArray) {
|
|
112
|
-
array.pushArray(convertJsonToArray(value))
|
|
113
|
-
} else if (value is Boolean) {
|
|
114
|
-
array.pushBoolean(value)
|
|
115
|
-
} else if (value is Int) {
|
|
116
|
-
array.pushInt(value)
|
|
117
|
-
} else if (value is Double) {
|
|
118
|
-
array.pushDouble(value)
|
|
119
|
-
} else if (value is String) {
|
|
120
|
-
array.pushString(value)
|
|
121
|
-
} else {
|
|
122
|
-
array.pushString(value.toString())
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
return array
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
@Throws(JSONException::class)
|
|
129
|
-
fun convertMapToJson(readableMap: ReadableMap?): JSONObject {
|
|
130
|
-
val `object` = JSONObject()
|
|
131
|
-
val iterator = readableMap?.keySetIterator()
|
|
132
|
-
iterator?.let {
|
|
133
|
-
while (iterator.hasNextKey()) {
|
|
134
|
-
val key = iterator.nextKey()
|
|
135
|
-
when (readableMap.getType(key)) {
|
|
136
|
-
ReadableType.Null -> `object`.put(key, JSONObject.NULL)
|
|
137
|
-
ReadableType.Boolean -> `object`.put(key, readableMap.getBoolean(key))
|
|
138
|
-
ReadableType.Number -> `object`.put(key, readableMap.getDouble(key))
|
|
139
|
-
ReadableType.String -> `object`.put(key, readableMap.getString(key))
|
|
140
|
-
ReadableType.Map -> `object`.put(key, convertMapToJson(readableMap.getMap(key)))
|
|
141
|
-
ReadableType.Array -> `object`.put(
|
|
142
|
-
key,
|
|
143
|
-
convertArrayToJson(readableMap.getArray(key))
|
|
144
|
-
)
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
return `object`
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
@Throws(JSONException::class)
|
|
152
|
-
fun convertArrayToJson(readableArray: ReadableArray?): JSONArray {
|
|
153
|
-
val array = JSONArray()
|
|
154
|
-
readableArray?.let {
|
|
155
|
-
for (i in 0 until readableArray.size()) {
|
|
156
|
-
when (readableArray.getType(i)) {
|
|
157
|
-
ReadableType.Null -> {
|
|
158
|
-
}
|
|
159
|
-
ReadableType.Boolean -> array.put(readableArray.getBoolean(i))
|
|
160
|
-
ReadableType.Number -> array.put(readableArray.getDouble(i))
|
|
161
|
-
ReadableType.String -> array.put(readableArray.getString(i))
|
|
162
|
-
ReadableType.Map -> array.put(convertMapToJson(readableArray.getMap(i)))
|
|
163
|
-
ReadableType.Array -> array.put(convertArrayToJson(readableArray.getArray(i)))
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
return array
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
companion object {
|
|
171
|
-
private const val TAG = "DoobooUtils"
|
|
172
|
-
const val E_UNKNOWN = "E_UNKNOWN"
|
|
173
|
-
const val E_NOT_PREPARED = "E_NOT_PREPARED"
|
|
174
|
-
const val E_ALREADY_PREPARED = "E_ALREADY_PREPARED"
|
|
175
|
-
const val E_NOT_ENDED = "E_NOT_ENDED"
|
|
176
|
-
const val E_USER_CANCELLED = "E_USER_CANCELLED"
|
|
177
|
-
const val E_ITEM_UNAVAILABLE = "E_ITEM_UNAVAILABLE"
|
|
178
|
-
const val E_NETWORK_ERROR = "E_NETWORK_ERROR"
|
|
179
|
-
const val E_SERVICE_ERROR = "E_SERVICE_ERROR"
|
|
180
|
-
const val E_ALREADY_OWNED = "E_ALREADY_OWNED"
|
|
181
|
-
const val E_REMOTE_ERROR = "E_REMOTE_ERROR"
|
|
182
|
-
const val E_USER_ERROR = "E_USER_ERROR"
|
|
183
|
-
const val E_DEVELOPER_ERROR = "E_DEVELOPER_ERROR"
|
|
184
|
-
const val E_BILLING_RESPONSE_JSON_PARSE_ERROR = "E_BILLING_RESPONSE_JSON_PARSE_ERROR"
|
|
185
|
-
const val E_CONNECTION_CLOSED = "E_CONNECTION_CLOSED"
|
|
186
|
-
val instance = DoobooUtils()
|
|
187
|
-
}
|
|
188
|
-
}
|