react-native-iap 14.4.9 → 14.4.10
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/README.md
CHANGED
|
@@ -89,14 +89,6 @@ Before installing React Native IAP, make sure you have:
|
|
|
89
89
|
|
|
90
90
|
#### Android Configuration
|
|
91
91
|
|
|
92
|
-
Add the OpenIAP Google library to your `android/app/build.gradle` dependencies. React Native IAP pins the native module versions in `openiap-versions.json` so Android, iOS, and tooling stay in sync:
|
|
93
|
-
|
|
94
|
-
```gradle
|
|
95
|
-
dependencies {
|
|
96
|
-
implementation "io.github.hyochan.openiap:openiap-google:1.2.6"
|
|
97
|
-
}
|
|
98
|
-
```
|
|
99
|
-
|
|
100
92
|
**Kotlin Version Requirement:** This library requires Kotlin 2.0+. Configure your project's Kotlin version:
|
|
101
93
|
|
|
102
94
|
In your root `android/build.gradle`:
|
|
@@ -1002,13 +1002,30 @@ class HybridRnIap : HybridRnIapSpec() {
|
|
|
1002
1002
|
val message = messageOverride?.takeIf { it.isNotBlank() }
|
|
1003
1003
|
?: error.message?.takeIf { it.isNotBlank() }
|
|
1004
1004
|
?: OpenIAPError.Companion.defaultMessage(code)
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
debugMessage = debugMessage ?: error.message,
|
|
1010
|
-
productId = productId
|
|
1005
|
+
|
|
1006
|
+
val errorMap = mutableMapOf<String, Any>(
|
|
1007
|
+
"code" to code,
|
|
1008
|
+
"message" to message
|
|
1011
1009
|
)
|
|
1010
|
+
|
|
1011
|
+
errorMap["responseCode"] = -1
|
|
1012
|
+
debugMessage?.let { errorMap["debugMessage"] = it } ?: error.message?.let { errorMap["debugMessage"] = it }
|
|
1013
|
+
productId?.let { errorMap["productId"] = it }
|
|
1014
|
+
|
|
1015
|
+
return try {
|
|
1016
|
+
val jsonPairs = errorMap.map { (key, value) ->
|
|
1017
|
+
val valueStr = when (value) {
|
|
1018
|
+
is String -> "\"${value.replace("\"", "\\\"")}\""
|
|
1019
|
+
is Number -> value.toString()
|
|
1020
|
+
is Boolean -> value.toString()
|
|
1021
|
+
else -> "\"$value\""
|
|
1022
|
+
}
|
|
1023
|
+
"\"$key\":$valueStr"
|
|
1024
|
+
}
|
|
1025
|
+
"{${jsonPairs.joinToString(",")}}"
|
|
1026
|
+
} catch (e: Exception) {
|
|
1027
|
+
"$code: $message"
|
|
1028
|
+
}
|
|
1012
1029
|
}
|
|
1013
1030
|
|
|
1014
1031
|
private fun toErrorResult(
|
package/openiap-versions.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-iap",
|
|
3
|
-
"version": "14.4.
|
|
3
|
+
"version": "14.4.10",
|
|
4
4
|
"description": "React Native In-App Purchases module for iOS and Android using Nitro",
|
|
5
5
|
"main": "./lib/module/index.js",
|
|
6
6
|
"types": "./lib/typescript/src/index.d.ts",
|
|
@@ -164,7 +164,7 @@
|
|
|
164
164
|
"prettier --write"
|
|
165
165
|
],
|
|
166
166
|
"*.{json,md}": [
|
|
167
|
-
"
|
|
167
|
+
"prettier --write"
|
|
168
168
|
]
|
|
169
169
|
},
|
|
170
170
|
"packageManager": "yarn@3.6.1"
|
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
package com.margelo.nitro.iap
|
|
2
|
-
|
|
3
|
-
import com.android.billingclient.api.BillingClient
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Error codes for IAP operations - centralized error code management
|
|
7
|
-
* Single source of truth for all error codes used across the module
|
|
8
|
-
*/
|
|
9
|
-
object IapErrorCode {
|
|
10
|
-
// Connection and initialization errors
|
|
11
|
-
const val E_NOT_PREPARED = "E_NOT_PREPARED"
|
|
12
|
-
const val E_INIT_CONNECTION = "E_INIT_CONNECTION"
|
|
13
|
-
const val E_SERVICE_DISCONNECTED = "E_SERVICE_DISCONNECTED"
|
|
14
|
-
const val E_ALREADY_PREPARED = "E_ALREADY_PREPARED"
|
|
15
|
-
const val E_CONNECTION_CLOSED = "E_CONNECTION_CLOSED"
|
|
16
|
-
|
|
17
|
-
// Product and purchase errors
|
|
18
|
-
const val E_QUERY_PRODUCT = "E_QUERY_PRODUCT"
|
|
19
|
-
const val E_SKU_NOT_FOUND = "E_SKU_NOT_FOUND"
|
|
20
|
-
const val E_SKU_OFFER_MISMATCH = "E_SKU_OFFER_MISMATCH"
|
|
21
|
-
const val E_PURCHASE_ERROR = "E_PURCHASE_ERROR"
|
|
22
|
-
const val E_USER_CANCELLED = "E_USER_CANCELLED"
|
|
23
|
-
const val E_PENDING = "E_PENDING"
|
|
24
|
-
|
|
25
|
-
// Service and developer errors
|
|
26
|
-
const val E_SERVICE_ERROR = "E_SERVICE_ERROR"
|
|
27
|
-
const val E_DEVELOPER_ERROR = "E_DEVELOPER_ERROR"
|
|
28
|
-
const val E_ITEM_UNAVAILABLE = "E_ITEM_UNAVAILABLE"
|
|
29
|
-
const val E_ALREADY_OWNED = "E_ALREADY_OWNED"
|
|
30
|
-
const val E_ITEM_NOT_OWNED = "E_ITEM_NOT_OWNED"
|
|
31
|
-
|
|
32
|
-
// Network and billing errors
|
|
33
|
-
const val E_NETWORK_ERROR = "E_NETWORK_ERROR"
|
|
34
|
-
const val E_BILLING_UNAVAILABLE = "E_BILLING_UNAVAILABLE"
|
|
35
|
-
const val E_FEATURE_NOT_SUPPORTED = "E_FEATURE_NOT_SUPPORTED"
|
|
36
|
-
const val E_BILLING_RESPONSE_JSON_PARSE_ERROR = "E_BILLING_RESPONSE_JSON_PARSE_ERROR"
|
|
37
|
-
|
|
38
|
-
// Activity and UI errors
|
|
39
|
-
const val E_ACTIVITY_UNAVAILABLE = "E_ACTIVITY_UNAVAILABLE"
|
|
40
|
-
|
|
41
|
-
// User and remote errors
|
|
42
|
-
const val E_USER_ERROR = "E_USER_ERROR"
|
|
43
|
-
const val E_REMOTE_ERROR = "E_REMOTE_ERROR"
|
|
44
|
-
const val E_NOT_ENDED = "E_NOT_ENDED"
|
|
45
|
-
|
|
46
|
-
// Validation errors
|
|
47
|
-
const val E_EMPTY_SKU_LIST = "E_EMPTY_SKU_LIST"
|
|
48
|
-
const val E_RECEIPT_FAILED = "E_RECEIPT_FAILED"
|
|
49
|
-
|
|
50
|
-
// Unknown error
|
|
51
|
-
const val E_UNKNOWN = "E_UNKNOWN"
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Data class for billing error information
|
|
56
|
-
*/
|
|
57
|
-
data class BillingErrorData(
|
|
58
|
-
val code: String,
|
|
59
|
-
val message: String
|
|
60
|
-
)
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Helper object for billing response handling
|
|
64
|
-
*/
|
|
65
|
-
object BillingUtils {
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Get error data from billing response code
|
|
69
|
-
*/
|
|
70
|
-
fun getBillingErrorData(responseCode: Int): BillingErrorData {
|
|
71
|
-
return when (responseCode) {
|
|
72
|
-
BillingClient.BillingResponseCode.OK ->
|
|
73
|
-
BillingErrorData("OK", "Success")
|
|
74
|
-
|
|
75
|
-
BillingClient.BillingResponseCode.USER_CANCELED ->
|
|
76
|
-
BillingErrorData(IapErrorCode.E_USER_CANCELLED, "User cancelled the purchase")
|
|
77
|
-
|
|
78
|
-
BillingClient.BillingResponseCode.SERVICE_UNAVAILABLE ->
|
|
79
|
-
BillingErrorData(IapErrorCode.E_SERVICE_ERROR, "Network connection is down")
|
|
80
|
-
|
|
81
|
-
BillingClient.BillingResponseCode.BILLING_UNAVAILABLE ->
|
|
82
|
-
BillingErrorData(IapErrorCode.E_BILLING_UNAVAILABLE, "Billing API version is not supported for the type requested")
|
|
83
|
-
|
|
84
|
-
BillingClient.BillingResponseCode.ITEM_UNAVAILABLE ->
|
|
85
|
-
BillingErrorData(IapErrorCode.E_ITEM_UNAVAILABLE, "Requested product is not available for purchase")
|
|
86
|
-
|
|
87
|
-
BillingClient.BillingResponseCode.DEVELOPER_ERROR ->
|
|
88
|
-
BillingErrorData(IapErrorCode.E_DEVELOPER_ERROR, "Invalid arguments provided to the API")
|
|
89
|
-
|
|
90
|
-
BillingClient.BillingResponseCode.ERROR ->
|
|
91
|
-
BillingErrorData(IapErrorCode.E_UNKNOWN, "Fatal error during the API action")
|
|
92
|
-
|
|
93
|
-
BillingClient.BillingResponseCode.ITEM_ALREADY_OWNED ->
|
|
94
|
-
BillingErrorData(IapErrorCode.E_ALREADY_OWNED, "Failure to purchase since item is already owned")
|
|
95
|
-
|
|
96
|
-
BillingClient.BillingResponseCode.ITEM_NOT_OWNED ->
|
|
97
|
-
BillingErrorData(IapErrorCode.E_ITEM_NOT_OWNED, "Failure to consume since item is not owned")
|
|
98
|
-
|
|
99
|
-
BillingClient.BillingResponseCode.SERVICE_DISCONNECTED ->
|
|
100
|
-
BillingErrorData(IapErrorCode.E_SERVICE_DISCONNECTED, "Play Store service is not connected now")
|
|
101
|
-
|
|
102
|
-
BillingClient.BillingResponseCode.FEATURE_NOT_SUPPORTED ->
|
|
103
|
-
BillingErrorData(IapErrorCode.E_FEATURE_NOT_SUPPORTED, "The requested feature is not supported by Play Store on the current device")
|
|
104
|
-
|
|
105
|
-
BillingClient.BillingResponseCode.NETWORK_ERROR ->
|
|
106
|
-
BillingErrorData(IapErrorCode.E_NETWORK_ERROR, "A network error occurred during the operation")
|
|
107
|
-
|
|
108
|
-
else ->
|
|
109
|
-
BillingErrorData(IapErrorCode.E_UNKNOWN, "Unknown billing error (code: $responseCode)")
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* Get error message for Google Play Services availability
|
|
115
|
-
*/
|
|
116
|
-
fun getPlayServicesErrorMessage(resultCode: Int): String {
|
|
117
|
-
return when (resultCode) {
|
|
118
|
-
com.google.android.gms.common.ConnectionResult.SERVICE_MISSING ->
|
|
119
|
-
"Google Play Services is missing on this device"
|
|
120
|
-
|
|
121
|
-
com.google.android.gms.common.ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED ->
|
|
122
|
-
"Google Play Services needs to be updated"
|
|
123
|
-
|
|
124
|
-
com.google.android.gms.common.ConnectionResult.SERVICE_DISABLED ->
|
|
125
|
-
"Google Play Services is disabled"
|
|
126
|
-
|
|
127
|
-
com.google.android.gms.common.ConnectionResult.SERVICE_INVALID ->
|
|
128
|
-
"Google Play Services is invalid"
|
|
129
|
-
|
|
130
|
-
else ->
|
|
131
|
-
"Google Play Services is not available (error code: $resultCode)"
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* Create JSON error string from error data and additional info
|
|
137
|
-
*/
|
|
138
|
-
fun createErrorJson(
|
|
139
|
-
code: String,
|
|
140
|
-
message: String,
|
|
141
|
-
responseCode: Int? = null,
|
|
142
|
-
debugMessage: String? = null,
|
|
143
|
-
productId: String? = null,
|
|
144
|
-
additionalData: Map<String, Any> = emptyMap()
|
|
145
|
-
): String {
|
|
146
|
-
val errorMap = mutableMapOf<String, Any>(
|
|
147
|
-
"code" to code,
|
|
148
|
-
"message" to message
|
|
149
|
-
)
|
|
150
|
-
|
|
151
|
-
responseCode?.let { errorMap["responseCode"] = it }
|
|
152
|
-
debugMessage?.let { errorMap["debugMessage"] = it }
|
|
153
|
-
productId?.let { errorMap["productId"] = it }
|
|
154
|
-
errorMap.putAll(additionalData)
|
|
155
|
-
|
|
156
|
-
return try {
|
|
157
|
-
// Simple JSON serialization for basic types
|
|
158
|
-
val jsonPairs = errorMap.map { (key, value) ->
|
|
159
|
-
val valueStr = when (value) {
|
|
160
|
-
is String -> "\"${value.replace("\"", "\\\"")}\""
|
|
161
|
-
is Number -> value.toString()
|
|
162
|
-
is Boolean -> value.toString()
|
|
163
|
-
else -> "\"$value\""
|
|
164
|
-
}
|
|
165
|
-
"\"$key\":$valueStr"
|
|
166
|
-
}
|
|
167
|
-
"{${jsonPairs.joinToString(",")}}"
|
|
168
|
-
} catch (e: Exception) {
|
|
169
|
-
// Fallback to simple format
|
|
170
|
-
"$code: $message"
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
}
|