react-native-iap 12.1.2 → 12.3.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.
@@ -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
- }