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.
@@ -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
- DoobooUtils.instance
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
- DoobooUtils.instance
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
- DoobooUtils.instance
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
- var debugMessage: String? = null
104
- var errorCode = DoobooUtils.E_UNKNOWN
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
- DoobooUtils.instance
126
+ PromiseUtils
128
127
  .resolvePromisesForKey(
129
128
  RNIapAmazonModule.PROMISE_BUY_ITEM,
130
129
  promiseItem
131
130
  )
132
131
  }
133
- DoobooUtils.instance
132
+ PromiseUtils
134
133
  .resolvePromisesForKey(
135
134
  RNIapAmazonModule.PROMISE_QUERY_PURCHASES,
136
135
  true
137
136
  )
138
- DoobooUtils.instance
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 = DoobooUtils.E_UNKNOWN
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
- DoobooUtils.instance
154
+ PromiseUtils
156
155
  .rejectPromisesForKey(
157
156
  RNIapAmazonModule.PROMISE_QUERY_PURCHASES,
158
157
  errorCode,
159
158
  debugMessage,
160
159
  null
161
160
  )
162
- DoobooUtils.instance
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 = DoobooUtils.E_SERVICE_ERROR
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
- DoobooUtils.instance
179
+ PromiseUtils
181
180
  .rejectPromisesForKey(
182
181
  RNIapAmazonModule.PROMISE_QUERY_PURCHASES,
183
182
  errorCode,
184
183
  debugMessage,
185
184
  null
186
185
  )
187
- DoobooUtils.instance
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
- var debugMessage: String? = null
221
- var errorCode = DoobooUtils.E_UNKNOWN
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
- DoobooUtils.instance
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 = DoobooUtils.E_ALREADY_OWNED
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
- DoobooUtils.instance
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 = DoobooUtils.E_UNKNOWN
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
- DoobooUtils.instance
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 = DoobooUtils.E_ITEM_UNAVAILABLE
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
- DoobooUtils.instance
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 = DoobooUtils.E_SERVICE_ERROR
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
- DoobooUtils.instance
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
- DoobooUtils.instance
312
+ PromiseUtils
314
313
  .resolvePromisesForKey(RNIapAmazonModule.PROMISE_GET_USER_DATA, item)
315
314
  }
316
315
  UserDataResponse.RequestStatus.NOT_SUPPORTED ->
317
- DoobooUtils.instance
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
- DoobooUtils.instance
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
- DoobooUtils.instance.rejectAllPendingPromises()
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
- DoobooUtils.instance.addPromiseForKey(PROMISE_GET_USER_DATA, promise)
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
- DoobooUtils.instance.addPromiseForKey(PROMISE_GET_PRODUCT_DATA, promise)
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
- DoobooUtils.instance.addPromiseForKey(PROMISE_QUERY_AVAILABLE_ITEMS, promise)
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
- DoobooUtils.instance.addPromiseForKey(PROMISE_BUY_ITEM, promise)
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
- DoobooUtils.instance.addPromiseForKey(PROMISE_QUERY_PURCHASES, promise)
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
+ }
@@ -11,7 +11,7 @@ import com.facebook.react.bridge.Promise
11
11
 
12
12
  const val TAG = "IapPromises"
13
13
 
14
- fun Promise.safeResolve(value: Any) {
14
+ fun Promise.safeResolve(value: Any?) {
15
15
  try {
16
16
  this.resolve(value)
17
17
  } catch (oce: ObjectAlreadyConsumedException) {
@@ -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 PlayUtils {
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[0], errorData[1])
12
+ promise.safeReject(errorData.code, errorData.message)
11
13
  }
12
14
 
13
- fun getBillingResponseData(responseCode: Int): Array<String?> {
14
- val errorData = arrayOfNulls<String>(2)
15
+ fun getBillingResponseData(responseCode: Int): BillingResponse {
16
+ val errorData=
15
17
  when (responseCode) {
16
18
  BillingClient.BillingResponseCode.FEATURE_NOT_SUPPORTED -> {
17
- errorData[0] = DoobooUtils.E_SERVICE_ERROR
18
- errorData[1] = "This feature is not available on your device."
19
+ BillingResponse( PromiseUtils.E_SERVICE_ERROR,
20
+ "This feature is not available on your device.")
19
21
  }
20
22
  BillingClient.BillingResponseCode.SERVICE_DISCONNECTED -> {
21
- errorData[0] = DoobooUtils.E_NETWORK_ERROR
22
- errorData[1] = "The service is disconnected (check your internet connection.)"
23
+ BillingResponse( PromiseUtils.E_NETWORK_ERROR
24
+ , "The service is disconnected (check your internet connection.)")
23
25
  }
24
26
  BillingClient.BillingResponseCode.OK -> {
25
- errorData[0] = "OK"
26
- errorData[1] = ""
27
+ BillingResponse( "OK"
28
+ , "")
27
29
  }
28
30
  BillingClient.BillingResponseCode.USER_CANCELED -> {
29
- errorData[0] = DoobooUtils.E_USER_CANCELLED
30
- errorData[1] = "Payment is Cancelled."
31
+ BillingResponse( PromiseUtils.E_USER_CANCELLED
32
+ , "Payment is Cancelled.")
31
33
  }
32
34
  BillingClient.BillingResponseCode.SERVICE_UNAVAILABLE -> {
33
- errorData[0] = DoobooUtils.E_SERVICE_ERROR
34
- errorData[1] =
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
- errorData[0] = DoobooUtils.E_SERVICE_ERROR
39
- errorData[1] =
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
- errorData[0] = DoobooUtils.E_ITEM_UNAVAILABLE
44
- errorData[1] = "That item is unavailable."
45
+ BillingResponse( PromiseUtils.E_ITEM_UNAVAILABLE
46
+ , "That item is unavailable.")
45
47
  }
46
48
  BillingClient.BillingResponseCode.DEVELOPER_ERROR -> {
47
- errorData[0] = DoobooUtils.E_DEVELOPER_ERROR
48
- errorData[1] = "Google is indicating that we have some issue connecting to payment."
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
- errorData[0] = DoobooUtils.E_UNKNOWN
52
- errorData[1] = "An unknown or unexpected error has occurred. Please try again later."
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
- errorData[0] = DoobooUtils.E_ALREADY_OWNED
56
- errorData[1] = "You already own this item."
57
+ BillingResponse( PromiseUtils.E_ALREADY_OWNED
58
+ , "You already own this item.")
57
59
  }
58
60
  else -> {
59
- errorData[0] = DoobooUtils.E_UNKNOWN
60
- errorData[1] = "Purchase failed with code: $responseCode"
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
- DoobooUtils.instance.rejectPromisesForKey(key, errorData[0], errorData[1], null)
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(DoobooUtils.E_NOT_PREPARED, "Unable to auto-initialize connection")
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(DoobooUtils.E_NOT_PREPARED, "Google Play Services are not available on this device")
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
- DoobooUtils.instance.rejectAllPendingPromises()
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.instance
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.instance
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(DoobooUtils.E_UNKNOWN, "getCurrentActivity returned null")
404
+ promise.safeReject(PromiseUtils.E_UNKNOWN, "getCurrentActivity returned null")
407
405
  return
408
406
  }
409
407
  ensureConnection(
410
408
  promise
411
409
  ) { billingClient ->
412
- DoobooUtils.instance.addPromiseForKey(
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: Array<String?> =
524
- PlayUtils.instance.getBillingResponseData(billingResultCode)
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: Array<String?> = PlayUtils.instance
552
- .getBillingResponseData(billingResult.responseCode)
553
- map.putString("code", errorData[0])
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: Array<String?> = PlayUtils.instance
579
- .getBillingResponseData(billingResult.responseCode)
580
- map.putString("code", errorData[0])
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: Array<String?> =
595
- PlayUtils.instance.getBillingResponseData(responseCode)
596
- error.putString("code", errorData[0])
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.instance.rejectPromisesWithBillingError(PROMISE_BUY_ITEM, responseCode)
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
- DoobooUtils.instance.resolvePromisesForKey(PROMISE_BUY_ITEM, promiseItems)
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
- DoobooUtils.instance.resolvePromisesForKey(PROMISE_BUY_ITEM, null)
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