react-native-iap 10.0.0 → 10.0.3
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 +4 -0
- package/android/src/amazon/java/com/dooboolab/RNIap/RNIapAmazonModule.kt +9 -2
- package/android/src/main/java/com/dooboolab/RNIap/DoobooUtils.kt +8 -0
- package/android/src/{play → main}/java/com/dooboolab/RNIap/PromiseUtlis.kt +4 -2
- package/android/src/play/java/com/dooboolab/RNIap/RNIapModule.kt +4 -1
- package/ios/RNIapIos.swift +866 -850
- package/package.json +1 -1
|
@@ -9,11 +9,13 @@ import com.facebook.react.bridge.ReactContextBaseJavaModule
|
|
|
9
9
|
import com.facebook.react.bridge.ReactMethod
|
|
10
10
|
import com.facebook.react.bridge.ReadableArray
|
|
11
11
|
import com.facebook.react.bridge.WritableNativeArray
|
|
12
|
+
import com.facebook.react.module.annotations.ReactModule
|
|
12
13
|
import java.util.HashSet
|
|
13
|
-
|
|
14
|
+
@ReactModule(name = RNIapAmazonModule.TAG)
|
|
14
15
|
class RNIapAmazonModule(reactContext: ReactApplicationContext) :
|
|
15
16
|
ReactContextBaseJavaModule(reactContext) {
|
|
16
17
|
var hasListener = false
|
|
18
|
+
private var amazonListener: RNIapAmazonListener? = null
|
|
17
19
|
override fun getName(): String {
|
|
18
20
|
return TAG
|
|
19
21
|
}
|
|
@@ -21,7 +23,9 @@ class RNIapAmazonModule(reactContext: ReactApplicationContext) :
|
|
|
21
23
|
@ReactMethod
|
|
22
24
|
fun initConnection(promise: Promise) {
|
|
23
25
|
val context = reactApplicationContext
|
|
24
|
-
|
|
26
|
+
val amazonListener = RNIapAmazonListener(context)
|
|
27
|
+
this.amazonListener = amazonListener
|
|
28
|
+
PurchasingService.registerListener(context, amazonListener)
|
|
25
29
|
hasListener = true
|
|
26
30
|
// Prefetch user and purchases as per Amazon SDK documentation:
|
|
27
31
|
PurchasingService.getUserData()
|
|
@@ -31,6 +35,9 @@ class RNIapAmazonModule(reactContext: ReactApplicationContext) :
|
|
|
31
35
|
|
|
32
36
|
@ReactMethod
|
|
33
37
|
fun endConnection(promise: Promise) {
|
|
38
|
+
DoobooUtils.instance.rejectAllPendingPromises()
|
|
39
|
+
amazonListener?.clear()
|
|
40
|
+
hasListener = false
|
|
34
41
|
promise.resolve(true)
|
|
35
42
|
}
|
|
36
43
|
|
|
@@ -49,6 +49,13 @@ class DoobooUtils {
|
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
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
|
+
|
|
52
59
|
fun rejectPromisesForKey(
|
|
53
60
|
key: String,
|
|
54
61
|
code: String?,
|
|
@@ -175,6 +182,7 @@ class DoobooUtils {
|
|
|
175
182
|
const val E_USER_ERROR = "E_USER_ERROR"
|
|
176
183
|
const val E_DEVELOPER_ERROR = "E_DEVELOPER_ERROR"
|
|
177
184
|
const val E_BILLING_RESPONSE_JSON_PARSE_ERROR = "E_BILLING_RESPONSE_JSON_PARSE_ERROR"
|
|
185
|
+
const val E_CONNECTION_CLOSED = "E_CONNECTION_CLOSED"
|
|
178
186
|
val instance = DoobooUtils()
|
|
179
187
|
}
|
|
180
188
|
}
|
|
@@ -9,11 +9,13 @@ import com.facebook.react.bridge.Promise
|
|
|
9
9
|
* want to crash in the case of it being resolved/rejected more than once
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
+
const val TAG = "IapPromises"
|
|
13
|
+
|
|
12
14
|
fun Promise.safeResolve(value: Any) {
|
|
13
15
|
try {
|
|
14
16
|
this.resolve(value)
|
|
15
17
|
} catch (oce: ObjectAlreadyConsumedException) {
|
|
16
|
-
Log.d(
|
|
18
|
+
Log.d(TAG, "Already consumed ${oce.message}")
|
|
17
19
|
}
|
|
18
20
|
}
|
|
19
21
|
|
|
@@ -28,6 +30,6 @@ fun Promise.safeReject(code: String?, message: String?, throwable: Throwable?) {
|
|
|
28
30
|
try {
|
|
29
31
|
this.reject(code, message, throwable)
|
|
30
32
|
} catch (oce: ObjectAlreadyConsumedException) {
|
|
31
|
-
Log.d(
|
|
33
|
+
Log.d(TAG, "Already consumed ${oce.message}")
|
|
32
34
|
}
|
|
33
35
|
}
|
|
@@ -30,11 +30,12 @@ import com.facebook.react.bridge.WritableArray
|
|
|
30
30
|
import com.facebook.react.bridge.WritableMap
|
|
31
31
|
import com.facebook.react.bridge.WritableNativeArray
|
|
32
32
|
import com.facebook.react.bridge.WritableNativeMap
|
|
33
|
+
import com.facebook.react.module.annotations.ReactModule
|
|
33
34
|
import com.facebook.react.modules.core.DeviceEventManagerModule.RCTDeviceEventEmitter
|
|
34
35
|
import com.google.android.gms.common.ConnectionResult
|
|
35
36
|
import com.google.android.gms.common.GoogleApiAvailability
|
|
36
37
|
import java.util.ArrayList
|
|
37
|
-
|
|
38
|
+
@ReactModule(name = RNIapModule.TAG)
|
|
38
39
|
class RNIapModule(
|
|
39
40
|
private val reactContext: ReactApplicationContext,
|
|
40
41
|
private val builder: BillingClient.Builder = BillingClient.newBuilder(reactContext).enablePendingPurchases(),
|
|
@@ -126,6 +127,8 @@ class RNIapModule(
|
|
|
126
127
|
fun endConnection(promise: Promise) {
|
|
127
128
|
billingClientCache?.endConnection()
|
|
128
129
|
billingClientCache = null
|
|
130
|
+
skus.clear()
|
|
131
|
+
DoobooUtils.instance.rejectAllPendingPromises()
|
|
129
132
|
promise.safeResolve(true)
|
|
130
133
|
}
|
|
131
134
|
|