react-native-iap 10.0.2 → 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 +7 -1
- 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 +2 -0
- package/ios/RNIapIos.swift +16 -0
- package/package.json +1 -1
|
@@ -15,6 +15,7 @@ import java.util.HashSet
|
|
|
15
15
|
class RNIapAmazonModule(reactContext: ReactApplicationContext) :
|
|
16
16
|
ReactContextBaseJavaModule(reactContext) {
|
|
17
17
|
var hasListener = false
|
|
18
|
+
private var amazonListener: RNIapAmazonListener? = null
|
|
18
19
|
override fun getName(): String {
|
|
19
20
|
return TAG
|
|
20
21
|
}
|
|
@@ -22,7 +23,9 @@ class RNIapAmazonModule(reactContext: ReactApplicationContext) :
|
|
|
22
23
|
@ReactMethod
|
|
23
24
|
fun initConnection(promise: Promise) {
|
|
24
25
|
val context = reactApplicationContext
|
|
25
|
-
|
|
26
|
+
val amazonListener = RNIapAmazonListener(context)
|
|
27
|
+
this.amazonListener = amazonListener
|
|
28
|
+
PurchasingService.registerListener(context, amazonListener)
|
|
26
29
|
hasListener = true
|
|
27
30
|
// Prefetch user and purchases as per Amazon SDK documentation:
|
|
28
31
|
PurchasingService.getUserData()
|
|
@@ -32,6 +35,9 @@ class RNIapAmazonModule(reactContext: ReactApplicationContext) :
|
|
|
32
35
|
|
|
33
36
|
@ReactMethod
|
|
34
37
|
fun endConnection(promise: Promise) {
|
|
38
|
+
DoobooUtils.instance.rejectAllPendingPromises()
|
|
39
|
+
amazonListener?.clear()
|
|
40
|
+
hasListener = false
|
|
35
41
|
promise.resolve(true)
|
|
36
42
|
}
|
|
37
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
|
}
|
package/ios/RNIapIos.swift
CHANGED
|
@@ -133,6 +133,14 @@ class RNIapIos: RCTEventEmitter, SKRequestDelegate, SKPaymentTransactionObserver
|
|
|
133
133
|
}
|
|
134
134
|
}
|
|
135
135
|
|
|
136
|
+
func rejectAllPendingPromises() {
|
|
137
|
+
promisesByKey.values.reduce([], +).forEach({tuple in
|
|
138
|
+
let reject = tuple.1
|
|
139
|
+
reject("E_CONNECTION_CLOSED", "Connection has been closed", nil)
|
|
140
|
+
})
|
|
141
|
+
promisesByKey.removeAll()
|
|
142
|
+
}
|
|
143
|
+
|
|
136
144
|
func paymentQueue(_ queue: SKPaymentQueue, shouldAddStorePayment payment: SKPayment, for product: SKProduct) -> Bool {
|
|
137
145
|
promotedProduct = product
|
|
138
146
|
promotedPayment = payment
|
|
@@ -160,6 +168,14 @@ class RNIapIos: RCTEventEmitter, SKRequestDelegate, SKPaymentTransactionObserver
|
|
|
160
168
|
reject: @escaping RCTPromiseRejectBlock = { _, _, _ in }
|
|
161
169
|
) {
|
|
162
170
|
removeTransactionObserver()
|
|
171
|
+
stopObserving()
|
|
172
|
+
rejectAllPendingPromises()
|
|
173
|
+
receiptBlock = nil
|
|
174
|
+
validProducts.removeAll()
|
|
175
|
+
promotedPayment = nil
|
|
176
|
+
promotedProduct = nil
|
|
177
|
+
productsRequest = nil
|
|
178
|
+
countPendingTransaction = 0
|
|
163
179
|
resolve(nil)
|
|
164
180
|
}
|
|
165
181
|
@objc public func getItems(
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-iap",
|
|
3
|
-
"version": "10.0.
|
|
3
|
+
"version": "10.0.3",
|
|
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)",
|