expo-iap 1.0.3 → 2.0.0-rc.1

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.
Files changed (103) hide show
  1. package/.eslintrc.js +9 -0
  2. package/.prettierrc.js +9 -0
  3. package/.swiftlint.yml +10 -0
  4. package/README.md +28 -21
  5. package/android/build.gradle +34 -72
  6. package/android/src/main/AndroidManifest.xml +1 -4
  7. package/android/src/main/java/expo/modules/iap/ExpoIapModule.kt +535 -0
  8. package/android/src/main/java/expo/modules/iap/MissingCurrentActivityException.kt +6 -0
  9. package/android/src/main/java/expo/modules/iap/PlayUtils.kt +124 -0
  10. package/build/ExpoIap.types.d.ts +89 -0
  11. package/build/ExpoIap.types.d.ts.map +1 -0
  12. package/build/ExpoIap.types.js +59 -0
  13. package/build/ExpoIap.types.js.map +1 -0
  14. package/build/ExpoIapModule.d.ts +3 -0
  15. package/build/ExpoIapModule.d.ts.map +1 -0
  16. package/build/ExpoIapModule.js +5 -0
  17. package/build/ExpoIapModule.js.map +1 -0
  18. package/build/index.d.ts +38 -0
  19. package/build/index.d.ts.map +1 -0
  20. package/build/index.js +202 -0
  21. package/build/index.js.map +1 -0
  22. package/build/modules/android.d.ts +40 -0
  23. package/build/modules/android.d.ts.map +1 -0
  24. package/build/modules/android.js +54 -0
  25. package/build/modules/android.js.map +1 -0
  26. package/build/modules/ios.d.ts +41 -0
  27. package/build/modules/ios.d.ts.map +1 -0
  28. package/build/modules/ios.js +44 -0
  29. package/build/modules/ios.js.map +1 -0
  30. package/build/types/ExpoIapAndroid.types.d.ts +113 -0
  31. package/build/types/ExpoIapAndroid.types.d.ts.map +1 -0
  32. package/build/types/ExpoIapAndroid.types.js +23 -0
  33. package/build/types/ExpoIapAndroid.types.js.map +1 -0
  34. package/build/types/ExpoIapIos.types.d.ts +122 -0
  35. package/build/types/ExpoIapIos.types.d.ts.map +1 -0
  36. package/build/types/ExpoIapIos.types.js +2 -0
  37. package/build/types/ExpoIapIos.types.js.map +1 -0
  38. package/bun.lockb +0 -0
  39. package/expo-module.config.json +4 -8
  40. package/ios/ExpoIap.podspec +27 -0
  41. package/ios/ExpoIapModule.swift +498 -0
  42. package/ios/ProductStore.swift +27 -0
  43. package/ios/Types.swift +54 -0
  44. package/package.json +33 -62
  45. package/src/ExpoIap.types.ts +125 -0
  46. package/src/ExpoIapModule.ts +5 -0
  47. package/src/index.ts +397 -0
  48. package/src/modules/android.ts +89 -0
  49. package/src/modules/ios.ts +81 -0
  50. package/src/types/ExpoIapAndroid.types.ts +123 -0
  51. package/src/types/ExpoIapIos.types.ts +141 -0
  52. package/tsconfig.json +9 -0
  53. package/.editorconfig +0 -10
  54. package/.flowconfig +0 -11
  55. package/.monolinterrc +0 -3
  56. package/.yarn/install-state.gz +0 -0
  57. package/.yarn/releases/yarn-3.1.1.cjs +0 -768
  58. package/.yarnrc.yml +0 -3
  59. package/LICENSE +0 -21
  60. package/RNIap.podspec +0 -18
  61. package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  62. package/android/gradle/wrapper/gradle-wrapper.properties +0 -6
  63. package/android/gradle.properties +0 -2
  64. package/android/gradlew +0 -160
  65. package/android/gradlew.bat +0 -90
  66. package/android/libs/in-app-purchasing-2.0.76.jar +0 -0
  67. package/android/src/amazon/AndroidManifest.xml +0 -12
  68. package/android/src/amazon/java/com/dooboolab/RNIap/RNIapAmazonListener.kt +0 -356
  69. package/android/src/amazon/java/com/dooboolab/RNIap/RNIapAmazonModule.kt +0 -128
  70. package/android/src/amazon/java/com/dooboolab/RNIap/RNIapPackage.kt +0 -20
  71. package/android/src/main/java/com/dooboolab/RNIap/DoobooUtils.kt +0 -180
  72. package/android/src/play/java/com/dooboolab/RNIap/PlayUtils.kt +0 -77
  73. package/android/src/play/java/com/dooboolab/RNIap/RNIapModule.kt +0 -698
  74. package/android/src/play/java/com/dooboolab/RNIap/RNIapPackage.kt +0 -20
  75. package/babel.config.js +0 -10
  76. package/index.d.ts +0 -3
  77. package/index.js +0 -3
  78. package/index.js.flow +0 -9
  79. package/ios/RNIap.xcodeproj/project.pbxproj +0 -370
  80. package/ios/RNIap.xcodeproj/xcshareddata/xcschemes/RNIap.xcscheme +0 -80
  81. package/ios/RNIapIos.m +0 -60
  82. package/ios/RNIapIos.swift +0 -932
  83. package/ios/RNIapQueue.swift +0 -35
  84. package/jest.config.js +0 -194
  85. package/src/__test__/iap.test.d.ts +0 -1
  86. package/src/__test__/iap.test.js +0 -59
  87. package/src/hooks/useIAP.d.ts +0 -21
  88. package/src/hooks/useIAP.js +0 -140
  89. package/src/hooks/withIAPContext.d.ts +0 -21
  90. package/src/hooks/withIAPContext.js +0 -142
  91. package/src/iap.d.ts +0 -197
  92. package/src/iap.js +0 -625
  93. package/src/index.d.ts +0 -4
  94. package/src/index.js +0 -4
  95. package/src/types/amazon.d.ts +0 -23
  96. package/src/types/amazon.js +0 -1
  97. package/src/types/android.d.ts +0 -47
  98. package/src/types/android.js +0 -22
  99. package/src/types/apple.d.ts +0 -424
  100. package/src/types/apple.js +0 -165
  101. package/src/types/index.d.ts +0 -117
  102. package/src/types/index.js +0 -40
  103. package/test/mocks/react-native-modules.js +0 -14
@@ -1,128 +0,0 @@
1
- package com.dooboolab.RNIap
2
-
3
- import com.amazon.device.iap.PurchasingService
4
- import com.amazon.device.iap.model.FulfillmentResult
5
- import com.facebook.react.bridge.Promise
6
- import com.facebook.react.bridge.ReactApplicationContext
7
- import com.facebook.react.bridge.ReactContextBaseJavaModule
8
- import com.facebook.react.bridge.ReactMethod
9
- import com.facebook.react.bridge.ReadableArray
10
- import com.facebook.react.bridge.WritableNativeArray
11
- import java.util.HashSet
12
-
13
- class RNIapAmazonModule(reactContext: ReactApplicationContext?) :
14
- ReactContextBaseJavaModule(reactContext) {
15
- val TAG = "RNIapAmazonModule"
16
- override fun getName(): String {
17
- return TAG
18
- }
19
-
20
- @ReactMethod
21
- fun initConnection(promise: Promise) {
22
- val context = reactApplicationContext
23
- PurchasingService.registerListener(context, RNIapAmazonListener(context))
24
- // Prefetch user and purchases as per Amazon SDK documentation:
25
- PurchasingService.getUserData()
26
- PurchasingService.getPurchaseUpdates(false)
27
- promise.resolve(true)
28
- }
29
-
30
- @ReactMethod
31
- fun endConnection(promise: Promise) {
32
- promise.resolve(true)
33
- }
34
-
35
- @ReactMethod
36
- fun getUser(promise: Promise) {
37
- val requestId = PurchasingService.getUserData()
38
- DoobooUtils.instance.addPromiseForKey(PROMISE_GET_USER_DATA, promise)
39
- }
40
-
41
- @ReactMethod
42
- fun flushFailedPurchasesCachedAsPending(promise: Promise) {
43
- // No-op
44
- val items = WritableNativeArray()
45
- promise.resolve(items)
46
- }
47
-
48
- @ReactMethod
49
- fun getItemsByType(type: String?, skuArr: ReadableArray, promise: Promise) {
50
- val productSkus: MutableSet<String> = HashSet()
51
- var ii = 0
52
- val skuSize = skuArr.size()
53
- while (ii < skuSize) {
54
- productSkus.add(skuArr.getString(ii))
55
- ii++
56
- }
57
- DoobooUtils.instance.addPromiseForKey(PROMISE_GET_PRODUCT_DATA, promise)
58
- val requestId = PurchasingService.getProductData(productSkus)
59
- }
60
-
61
- @ReactMethod
62
- fun getAvailableItems(promise: Promise) {
63
- DoobooUtils.instance.addPromiseForKey(PROMISE_QUERY_AVAILABLE_ITEMS, promise)
64
- PurchasingService.getPurchaseUpdates(true)
65
- }
66
-
67
- @ReactMethod
68
- fun buyItemByType(
69
- type: String?,
70
- sku: String?,
71
- purchaseToken: String?,
72
- prorationMode: Int?,
73
- obfuscatedAccountId: String?,
74
- obfuscatedProfileId: String?,
75
- promise: Promise
76
- ) {
77
- DoobooUtils.instance.addPromiseForKey(PROMISE_BUY_ITEM, promise)
78
- val requestId = PurchasingService.purchase(sku)
79
- }
80
-
81
- @ReactMethod
82
- fun acknowledgePurchase(
83
- token: String?,
84
- developerPayLoad: String?,
85
- promise: Promise
86
- ) {
87
- PurchasingService.notifyFulfillment(token, FulfillmentResult.FULFILLED)
88
- promise.resolve(true)
89
- }
90
-
91
- @ReactMethod
92
- fun consumeProduct(
93
- token: String?,
94
- developerPayLoad: String?,
95
- promise: Promise
96
- ) {
97
- PurchasingService.notifyFulfillment(token, FulfillmentResult.FULFILLED)
98
- promise.resolve(true)
99
- }
100
-
101
- private fun sendUnconsumedPurchases(promise: Promise) {
102
- PurchasingService.getPurchaseUpdates(false)
103
- DoobooUtils.instance.addPromiseForKey(PROMISE_QUERY_PURCHASES, promise)
104
- }
105
-
106
- @ReactMethod
107
- fun startListening(promise: Promise) {
108
- sendUnconsumedPurchases(promise)
109
- }
110
-
111
- @ReactMethod
112
- fun addListener(eventName: String) {
113
- // Keep: Required for RN built-in Event Emitter Calls.
114
- }
115
-
116
- @ReactMethod
117
- fun removeListeners(count: Double) {
118
- // Keep: Required for RN built-in Event Emitter Calls.
119
- }
120
-
121
- companion object {
122
- const val PROMISE_BUY_ITEM = "PROMISE_BUY_ITEM"
123
- const val PROMISE_GET_PRODUCT_DATA = "PROMISE_GET_PRODUCT_DATA"
124
- const val PROMISE_QUERY_PURCHASES = "PROMISE_QUERY_PURCHASES"
125
- const val PROMISE_QUERY_AVAILABLE_ITEMS = "PROMISE_QUERY_AVAILABLE_ITEMS"
126
- const val PROMISE_GET_USER_DATA = "PROMISE_GET_USER_DATA"
127
- }
128
- }
@@ -1,20 +0,0 @@
1
- package com.dooboolab.RNIap
2
-
3
- import com.facebook.react.ReactPackage
4
- import com.facebook.react.bridge.NativeModule
5
- import com.facebook.react.bridge.ReactApplicationContext
6
- import com.facebook.react.uimanager.ViewManager
7
- import java.util.ArrayList
8
-
9
- class RNIapPackage : ReactPackage {
10
-
11
- override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
12
- return emptyList()
13
- }
14
-
15
- override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
16
- val modules: MutableList<NativeModule> = ArrayList()
17
- modules.add(RNIapAmazonModule(reactContext))
18
- return modules
19
- }
20
- }
@@ -1,180 +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 rejectPromisesForKey(
53
- key: String,
54
- code: String?,
55
- message: String?,
56
- err: Exception?
57
- ) {
58
- try {
59
- if (promises.containsKey(key)) {
60
- val list = promises[key]!!
61
- for (promise in list) {
62
- promise.reject(code, message, err)
63
- }
64
- promises.remove(key)
65
- }
66
- } catch (oce: ObjectAlreadyConsumedException) {
67
- Log.e(TAG, oce.message!!)
68
- }
69
- }
70
-
71
- @Throws(JSONException::class)
72
- fun convertJsonToMap(jsonObject: JSONObject): WritableMap {
73
- val map: WritableMap = WritableNativeMap()
74
- val iterator = jsonObject.keys()
75
- while (iterator.hasNext()) {
76
- val key = iterator.next()
77
- val value = jsonObject[key]
78
- if (value is JSONObject) {
79
- map.putMap(key, convertJsonToMap(value))
80
- } else if (value is JSONArray) {
81
- map.putArray(key, convertJsonToArray(value))
82
- } else if (value is Boolean) {
83
- map.putBoolean(key, value)
84
- } else if (value is Int) {
85
- map.putInt(key, value)
86
- } else if (value is Double) {
87
- map.putDouble(key, value)
88
- } else if (value is String) {
89
- map.putString(key, value)
90
- } else {
91
- map.putString(key, value.toString())
92
- }
93
- }
94
- return map
95
- }
96
-
97
- @Throws(JSONException::class)
98
- fun convertJsonToArray(jsonArray: JSONArray): WritableArray {
99
- val array: WritableArray = WritableNativeArray()
100
- for (i in 0 until jsonArray.length()) {
101
- val value = jsonArray[i]
102
- if (value is JSONObject) {
103
- array.pushMap(convertJsonToMap(value))
104
- } else if (value is JSONArray) {
105
- array.pushArray(convertJsonToArray(value))
106
- } else if (value is Boolean) {
107
- array.pushBoolean(value)
108
- } else if (value is Int) {
109
- array.pushInt(value)
110
- } else if (value is Double) {
111
- array.pushDouble(value)
112
- } else if (value is String) {
113
- array.pushString(value)
114
- } else {
115
- array.pushString(value.toString())
116
- }
117
- }
118
- return array
119
- }
120
-
121
- @Throws(JSONException::class)
122
- fun convertMapToJson(readableMap: ReadableMap?): JSONObject {
123
- val `object` = JSONObject()
124
- val iterator = readableMap?.keySetIterator()
125
- iterator?.let {
126
- while (iterator.hasNextKey()) {
127
- val key = iterator.nextKey()
128
- when (readableMap.getType(key)) {
129
- ReadableType.Null -> `object`.put(key, JSONObject.NULL)
130
- ReadableType.Boolean -> `object`.put(key, readableMap.getBoolean(key))
131
- ReadableType.Number -> `object`.put(key, readableMap.getDouble(key))
132
- ReadableType.String -> `object`.put(key, readableMap.getString(key))
133
- ReadableType.Map -> `object`.put(key, convertMapToJson(readableMap.getMap(key)))
134
- ReadableType.Array -> `object`.put(
135
- key,
136
- convertArrayToJson(readableMap.getArray(key))
137
- )
138
- }
139
- }
140
- }
141
- return `object`
142
- }
143
-
144
- @Throws(JSONException::class)
145
- fun convertArrayToJson(readableArray: ReadableArray?): JSONArray {
146
- val array = JSONArray()
147
- readableArray?.let {
148
- for (i in 0 until readableArray.size()) {
149
- when (readableArray.getType(i)) {
150
- ReadableType.Null -> {
151
- }
152
- ReadableType.Boolean -> array.put(readableArray.getBoolean(i))
153
- ReadableType.Number -> array.put(readableArray.getDouble(i))
154
- ReadableType.String -> array.put(readableArray.getString(i))
155
- ReadableType.Map -> array.put(convertMapToJson(readableArray.getMap(i)))
156
- ReadableType.Array -> array.put(convertArrayToJson(readableArray.getArray(i)))
157
- }
158
- }
159
- }
160
- return array
161
- }
162
-
163
- companion object {
164
- private const val TAG = "DoobooUtils"
165
- const val E_UNKNOWN = "E_UNKNOWN"
166
- const val E_NOT_PREPARED = "E_NOT_PREPARED"
167
- const val E_ALREADY_PREPARED = "E_ALREADY_PREPARED"
168
- const val E_NOT_ENDED = "E_NOT_ENDED"
169
- const val E_USER_CANCELLED = "E_USER_CANCELLED"
170
- const val E_ITEM_UNAVAILABLE = "E_ITEM_UNAVAILABLE"
171
- const val E_NETWORK_ERROR = "E_NETWORK_ERROR"
172
- const val E_SERVICE_ERROR = "E_SERVICE_ERROR"
173
- const val E_ALREADY_OWNED = "E_ALREADY_OWNED"
174
- const val E_REMOTE_ERROR = "E_REMOTE_ERROR"
175
- const val E_USER_ERROR = "E_USER_ERROR"
176
- const val E_DEVELOPER_ERROR = "E_DEVELOPER_ERROR"
177
- const val E_BILLING_RESPONSE_JSON_PARSE_ERROR = "E_BILLING_RESPONSE_JSON_PARSE_ERROR"
178
- val instance = DoobooUtils()
179
- }
180
- }
@@ -1,77 +0,0 @@
1
- package com.dooboolab.RNIap
2
-
3
- import android.util.Log
4
- import com.android.billingclient.api.BillingClient
5
- import com.facebook.react.bridge.Promise
6
-
7
- class PlayUtils {
8
- fun rejectPromiseWithBillingError(promise: Promise, responseCode: Int) {
9
- val errorData = getBillingResponseData(responseCode)
10
- promise.reject(errorData[0], errorData[1])
11
- }
12
-
13
- fun getBillingResponseData(responseCode: Int): Array<String?> {
14
- val errorData = arrayOfNulls<String>(2)
15
- when (responseCode) {
16
- BillingClient.BillingResponseCode.FEATURE_NOT_SUPPORTED -> {
17
- errorData[0] = DoobooUtils.E_SERVICE_ERROR
18
- errorData[1] = "This feature is not available on your device."
19
- }
20
- BillingClient.BillingResponseCode.SERVICE_DISCONNECTED -> {
21
- errorData[0] = DoobooUtils.E_NETWORK_ERROR
22
- errorData[1] = "The service is disconnected (check your internet connection.)"
23
- }
24
- BillingClient.BillingResponseCode.OK -> {
25
- errorData[0] = "OK"
26
- errorData[1] = ""
27
- }
28
- BillingClient.BillingResponseCode.USER_CANCELED -> {
29
- errorData[0] = DoobooUtils.E_USER_CANCELLED
30
- errorData[1] = "Payment is Cancelled."
31
- }
32
- 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."
36
- }
37
- 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."
41
- }
42
- BillingClient.BillingResponseCode.ITEM_UNAVAILABLE -> {
43
- errorData[0] = DoobooUtils.E_ITEM_UNAVAILABLE
44
- errorData[1] = "That item is unavailable."
45
- }
46
- 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
- }
50
- BillingClient.BillingResponseCode.ERROR -> {
51
- errorData[0] = DoobooUtils.E_UNKNOWN
52
- errorData[1] = "An unknown or unexpected error has occured. Please try again later."
53
- }
54
- BillingClient.BillingResponseCode.ITEM_ALREADY_OWNED -> {
55
- errorData[0] = DoobooUtils.E_ALREADY_OWNED
56
- errorData[1] = "You already own this item."
57
- }
58
- else -> {
59
- errorData[0] = DoobooUtils.E_UNKNOWN
60
- errorData[1] = "Purchase failed with code: $responseCode"
61
- }
62
- }
63
- Log.e(TAG, "Error Code : $responseCode")
64
- return errorData
65
- }
66
-
67
- fun rejectPromisesWithBillingError(key: String, responseCode: Int) {
68
- 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()
76
- }
77
- }