react-native-iap 11.0.7 → 12.0.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.
- package/README.md +3 -1
- package/android/build.gradle +2 -1
- package/android/gradle.properties +1 -0
- package/android/src/amazon/AndroidManifest.xml +11 -9
- package/android/src/amazon/java/com/dooboolab/RNIap/RNIapAmazonListener.kt +23 -25
- package/android/src/amazon/java/com/dooboolab/RNIap/RNIapAmazonModule.kt +58 -9
- package/ios/IapTypes.swift +21 -0
- package/ios/RNIapIos.swift +8 -58
- package/ios/RNIapIosSk2.m +4 -0
- package/ios/RNIapIosSk2.swift +33 -0
- package/lib/commonjs/internal/platform.js +5 -3
- package/lib/commonjs/internal/platform.js.map +1 -1
- package/lib/commonjs/modules/amazon.js +9 -1
- package/lib/commonjs/modules/amazon.js.map +1 -1
- package/lib/commonjs/types/amazon.js.map +1 -1
- package/lib/module/internal/platform.js +2 -1
- package/lib/module/internal/platform.js.map +1 -1
- package/lib/module/modules/amazon.js +5 -0
- package/lib/module/modules/amazon.js.map +1 -1
- package/lib/module/types/amazon.js.map +1 -1
- package/lib/typescript/internal/platform.d.ts +1 -0
- package/lib/typescript/modules/amazon.d.ts +7 -3
- package/lib/typescript/types/amazon.d.ts +1 -0
- package/package.json +1 -1
- package/src/internal/platform.ts +1 -0
- package/src/modules/amazon.ts +14 -4
- package/src/types/amazon.ts +8 -0
- package/android/libs/in-app-purchasing-2.0.76.jar +0 -0
package/README.md
CHANGED
|
@@ -28,7 +28,9 @@ Please [fund the project](https://opencollective.com/react-native-iap) if you ar
|
|
|
28
28
|
|
|
29
29
|
## Announcement
|
|
30
30
|
|
|
31
|
-
- Version `
|
|
31
|
+
- Version `12.0.0`: Implements Amazon 3.x SDK including the new DRM verification.
|
|
32
|
+
|
|
33
|
+
- Version `11.0.0`: The module migrates OS sdk to [storekit2](https://developer.apple.com/videos/play/wwdc2021/10114). [andresesfm](https://github.com/andresesfm) is working hard on this.
|
|
32
34
|
|
|
33
35
|
```
|
|
34
36
|
yarn add react-native-iap@next
|
package/android/build.gradle
CHANGED
|
@@ -150,6 +150,7 @@ def supportLibVersion = getExtOrDefault("supportLibVersion")
|
|
|
150
150
|
def androidXVersion = getExtOrDefault("androidXVersion")
|
|
151
151
|
def androidXAnnotation = getExtOrDefault("androidXAnnotation")
|
|
152
152
|
def androidXBrowser = getExtOrDefault("androidXBrowser")
|
|
153
|
+
def amazonSdkVersion = getExtOrDefault("amazonSdkVersion")
|
|
153
154
|
|
|
154
155
|
dependencies {
|
|
155
156
|
implementation "com.facebook.react:react-native:+"
|
|
@@ -161,7 +162,7 @@ dependencies {
|
|
|
161
162
|
playImplementation "com.android.billingclient:billing-ktx:5.0.0"
|
|
162
163
|
playImplementation "com.google.android.gms:play-services-base:$playServicesVersion"
|
|
163
164
|
|
|
164
|
-
amazonImplementation
|
|
165
|
+
amazonImplementation "com.amazon.device:amazon-appstore-sdk:$amazonSdkVersion"
|
|
165
166
|
|
|
166
167
|
if (supportLibVersion && androidXVersion == null) {
|
|
167
168
|
implementation "com.android.support:support-annotations:$supportLibVersion"
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
|
2
2
|
package="com.dooboolab.RNIap">
|
|
3
|
-
|
|
4
|
-
<
|
|
5
|
-
android:
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
</
|
|
3
|
+
|
|
4
|
+
<application android:exported="true">
|
|
5
|
+
<receiver android:name="com.amazon.device.iap.ResponseReceiver" android:exported="true"
|
|
6
|
+
>
|
|
7
|
+
<intent-filter>
|
|
8
|
+
<action
|
|
9
|
+
android:name="com.amazon.inapp.purchasing.NOTIFY"
|
|
10
|
+
android:permission="com.amazon.inapp.purchasing.Permission.NOTIFY" />
|
|
11
|
+
</intent-filter>
|
|
12
|
+
</receiver>
|
|
13
|
+
</application>
|
|
12
14
|
</manifest>
|
|
@@ -31,9 +31,8 @@ class RNIapAmazonListener(private val reactContext: ReactContext) : PurchasingLi
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
override fun onProductDataResponse(response: ProductDataResponse) {
|
|
34
|
-
val status = response.requestStatus
|
|
35
34
|
val requestId = response.requestId.toString()
|
|
36
|
-
when (
|
|
35
|
+
when (response.requestStatus) {
|
|
37
36
|
ProductDataResponse.RequestStatus.SUCCESSFUL -> {
|
|
38
37
|
val productData = response.productData
|
|
39
38
|
val unavailableSkus = response.unavailableSkus
|
|
@@ -48,7 +47,7 @@ class RNIapAmazonListener(private val reactContext: ReactContext) : PurchasingLi
|
|
|
48
47
|
var priceNumber: Number = 0.00
|
|
49
48
|
val priceString = product.price
|
|
50
49
|
try {
|
|
51
|
-
if (priceString
|
|
50
|
+
if (priceString?.isNotEmpty()== true) {
|
|
52
51
|
priceNumber = priceString.replace("[^\\d.,]+".toRegex(), "").toDouble()
|
|
53
52
|
}
|
|
54
53
|
} catch (e: NumberFormatException) {
|
|
@@ -76,14 +75,14 @@ class RNIapAmazonListener(private val reactContext: ReactContext) : PurchasingLi
|
|
|
76
75
|
}
|
|
77
76
|
DoobooUtils.instance
|
|
78
77
|
.resolvePromisesForKey(
|
|
79
|
-
RNIapAmazonModule.
|
|
78
|
+
RNIapAmazonModule.PROMISE_GET_PRODUCT_DATA,
|
|
80
79
|
items
|
|
81
80
|
)
|
|
82
81
|
}
|
|
83
82
|
ProductDataResponse.RequestStatus.FAILED ->
|
|
84
83
|
DoobooUtils.instance
|
|
85
84
|
.rejectPromisesForKey(
|
|
86
|
-
RNIapAmazonModule.
|
|
85
|
+
RNIapAmazonModule.PROMISE_GET_PRODUCT_DATA,
|
|
87
86
|
E_PRODUCT_DATA_RESPONSE_FAILED,
|
|
88
87
|
null,
|
|
89
88
|
null
|
|
@@ -91,7 +90,7 @@ class RNIapAmazonListener(private val reactContext: ReactContext) : PurchasingLi
|
|
|
91
90
|
ProductDataResponse.RequestStatus.NOT_SUPPORTED ->
|
|
92
91
|
DoobooUtils.instance
|
|
93
92
|
.rejectPromisesForKey(
|
|
94
|
-
RNIapAmazonModule.
|
|
93
|
+
RNIapAmazonModule.PROMISE_GET_PRODUCT_DATA,
|
|
95
94
|
E_PRODUCT_DATA_RESPONSE_NOT_SUPPORTED,
|
|
96
95
|
null,
|
|
97
96
|
null
|
|
@@ -104,8 +103,7 @@ class RNIapAmazonListener(private val reactContext: ReactContext) : PurchasingLi
|
|
|
104
103
|
var debugMessage: String? = null
|
|
105
104
|
var errorCode = DoobooUtils.E_UNKNOWN
|
|
106
105
|
val error = Arguments.createMap()
|
|
107
|
-
|
|
108
|
-
when (status) {
|
|
106
|
+
when (response.requestStatus) {
|
|
109
107
|
PurchaseUpdatesResponse.RequestStatus.SUCCESSFUL -> {
|
|
110
108
|
val userData = response.userData
|
|
111
109
|
var promiseItem: WritableMap? = null
|
|
@@ -128,18 +126,18 @@ class RNIapAmazonListener(private val reactContext: ReactContext) : PurchasingLi
|
|
|
128
126
|
if (purchases.size > 0 && promiseItem != null) {
|
|
129
127
|
DoobooUtils.instance
|
|
130
128
|
.resolvePromisesForKey(
|
|
131
|
-
RNIapAmazonModule.
|
|
129
|
+
RNIapAmazonModule.PROMISE_BUY_ITEM,
|
|
132
130
|
promiseItem
|
|
133
131
|
)
|
|
134
132
|
}
|
|
135
133
|
DoobooUtils.instance
|
|
136
134
|
.resolvePromisesForKey(
|
|
137
|
-
RNIapAmazonModule.
|
|
135
|
+
RNIapAmazonModule.PROMISE_QUERY_PURCHASES,
|
|
138
136
|
true
|
|
139
137
|
)
|
|
140
138
|
DoobooUtils.instance
|
|
141
139
|
.resolvePromisesForKey(
|
|
142
|
-
RNIapAmazonModule.
|
|
140
|
+
RNIapAmazonModule.PROMISE_QUERY_AVAILABLE_ITEMS,
|
|
143
141
|
availableItems
|
|
144
142
|
)
|
|
145
143
|
availableItems = WritableNativeArray()
|
|
@@ -156,14 +154,14 @@ class RNIapAmazonListener(private val reactContext: ReactContext) : PurchasingLi
|
|
|
156
154
|
sendEvent(reactContext, "purchase-error", error)
|
|
157
155
|
DoobooUtils.instance
|
|
158
156
|
.rejectPromisesForKey(
|
|
159
|
-
RNIapAmazonModule.
|
|
157
|
+
RNIapAmazonModule.PROMISE_QUERY_PURCHASES,
|
|
160
158
|
errorCode,
|
|
161
159
|
debugMessage,
|
|
162
160
|
null
|
|
163
161
|
)
|
|
164
162
|
DoobooUtils.instance
|
|
165
163
|
.rejectPromisesForKey(
|
|
166
|
-
RNIapAmazonModule.
|
|
164
|
+
RNIapAmazonModule.PROMISE_QUERY_AVAILABLE_ITEMS,
|
|
167
165
|
errorCode,
|
|
168
166
|
debugMessage,
|
|
169
167
|
null
|
|
@@ -181,14 +179,14 @@ class RNIapAmazonListener(private val reactContext: ReactContext) : PurchasingLi
|
|
|
181
179
|
sendEvent(reactContext, "purchase-error", error)
|
|
182
180
|
DoobooUtils.instance
|
|
183
181
|
.rejectPromisesForKey(
|
|
184
|
-
RNIapAmazonModule.
|
|
182
|
+
RNIapAmazonModule.PROMISE_QUERY_PURCHASES,
|
|
185
183
|
errorCode,
|
|
186
184
|
debugMessage,
|
|
187
185
|
null
|
|
188
186
|
)
|
|
189
187
|
DoobooUtils.instance
|
|
190
188
|
.rejectPromisesForKey(
|
|
191
|
-
RNIapAmazonModule.
|
|
189
|
+
RNIapAmazonModule.PROMISE_QUERY_AVAILABLE_ITEMS,
|
|
192
190
|
errorCode,
|
|
193
191
|
debugMessage,
|
|
194
192
|
null
|
|
@@ -209,6 +207,7 @@ class RNIapAmazonListener(private val reactContext: ReactContext) : PurchasingLi
|
|
|
209
207
|
item.putString("userMarketplaceAmazon", userData.marketplace)
|
|
210
208
|
item.putString("userJsonAmazon", userData.toJSON().toString())
|
|
211
209
|
item.putBoolean("isCanceledAmazon", receipt.isCanceled)
|
|
210
|
+
item.putString("termSku",receipt.termSku)
|
|
212
211
|
return item
|
|
213
212
|
}
|
|
214
213
|
|
|
@@ -231,7 +230,7 @@ class RNIapAmazonListener(private val reactContext: ReactContext) : PurchasingLi
|
|
|
231
230
|
sendEvent(reactContext, "purchase-updated", item)
|
|
232
231
|
DoobooUtils.instance
|
|
233
232
|
.resolvePromisesForKey(
|
|
234
|
-
RNIapAmazonModule.
|
|
233
|
+
RNIapAmazonModule.PROMISE_BUY_ITEM,
|
|
235
234
|
promiseItem
|
|
236
235
|
)
|
|
237
236
|
}
|
|
@@ -245,7 +244,7 @@ class RNIapAmazonListener(private val reactContext: ReactContext) : PurchasingLi
|
|
|
245
244
|
sendEvent(reactContext, "purchase-error", error)
|
|
246
245
|
DoobooUtils.instance
|
|
247
246
|
.rejectPromisesForKey(
|
|
248
|
-
RNIapAmazonModule.
|
|
247
|
+
RNIapAmazonModule.PROMISE_BUY_ITEM,
|
|
249
248
|
errorCode,
|
|
250
249
|
debugMessage,
|
|
251
250
|
null
|
|
@@ -262,7 +261,7 @@ class RNIapAmazonListener(private val reactContext: ReactContext) : PurchasingLi
|
|
|
262
261
|
sendEvent(reactContext, "purchase-error", error)
|
|
263
262
|
DoobooUtils.instance
|
|
264
263
|
.rejectPromisesForKey(
|
|
265
|
-
RNIapAmazonModule.
|
|
264
|
+
RNIapAmazonModule.PROMISE_BUY_ITEM,
|
|
266
265
|
errorCode,
|
|
267
266
|
debugMessage,
|
|
268
267
|
null
|
|
@@ -278,7 +277,7 @@ class RNIapAmazonListener(private val reactContext: ReactContext) : PurchasingLi
|
|
|
278
277
|
sendEvent(reactContext, "purchase-error", error)
|
|
279
278
|
DoobooUtils.instance
|
|
280
279
|
.rejectPromisesForKey(
|
|
281
|
-
RNIapAmazonModule.
|
|
280
|
+
RNIapAmazonModule.PROMISE_BUY_ITEM,
|
|
282
281
|
errorCode,
|
|
283
282
|
debugMessage,
|
|
284
283
|
null
|
|
@@ -294,7 +293,7 @@ class RNIapAmazonListener(private val reactContext: ReactContext) : PurchasingLi
|
|
|
294
293
|
sendEvent(reactContext, "purchase-error", error)
|
|
295
294
|
DoobooUtils.instance
|
|
296
295
|
.rejectPromisesForKey(
|
|
297
|
-
RNIapAmazonModule.
|
|
296
|
+
RNIapAmazonModule.PROMISE_BUY_ITEM,
|
|
298
297
|
errorCode,
|
|
299
298
|
debugMessage,
|
|
300
299
|
null
|
|
@@ -304,8 +303,7 @@ class RNIapAmazonListener(private val reactContext: ReactContext) : PurchasingLi
|
|
|
304
303
|
}
|
|
305
304
|
|
|
306
305
|
override fun onUserDataResponse(response: UserDataResponse) {
|
|
307
|
-
|
|
308
|
-
when (status) {
|
|
306
|
+
when (response.requestStatus) {
|
|
309
307
|
UserDataResponse.RequestStatus.SUCCESSFUL -> {
|
|
310
308
|
val userData = response.userData
|
|
311
309
|
val item = Arguments.createMap()
|
|
@@ -313,12 +311,12 @@ class RNIapAmazonListener(private val reactContext: ReactContext) : PurchasingLi
|
|
|
313
311
|
item.putString("userMarketplaceAmazon", userData.marketplace)
|
|
314
312
|
item.putString("userJsonAmazon", userData.toJSON().toString())
|
|
315
313
|
DoobooUtils.instance
|
|
316
|
-
.resolvePromisesForKey(RNIapAmazonModule.
|
|
314
|
+
.resolvePromisesForKey(RNIapAmazonModule.PROMISE_GET_USER_DATA, item)
|
|
317
315
|
}
|
|
318
316
|
UserDataResponse.RequestStatus.NOT_SUPPORTED ->
|
|
319
317
|
DoobooUtils.instance
|
|
320
318
|
.rejectPromisesForKey(
|
|
321
|
-
RNIapAmazonModule.
|
|
319
|
+
RNIapAmazonModule.PROMISE_GET_USER_DATA,
|
|
322
320
|
E_USER_DATA_RESPONSE_NOT_SUPPORTED,
|
|
323
321
|
null,
|
|
324
322
|
null
|
|
@@ -326,7 +324,7 @@ class RNIapAmazonListener(private val reactContext: ReactContext) : PurchasingLi
|
|
|
326
324
|
UserDataResponse.RequestStatus.FAILED ->
|
|
327
325
|
DoobooUtils.instance
|
|
328
326
|
.rejectPromisesForKey(
|
|
329
|
-
RNIapAmazonModule.
|
|
327
|
+
RNIapAmazonModule.PROMISE_GET_USER_DATA,
|
|
330
328
|
E_USER_DATA_RESPONSE_FAILED,
|
|
331
329
|
null,
|
|
332
330
|
null
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
package com.dooboolab.RNIap
|
|
2
2
|
|
|
3
|
+
import android.util.Log
|
|
4
|
+
import com.amazon.device.drm.LicensingListener
|
|
5
|
+
import com.amazon.device.drm.LicensingService
|
|
6
|
+
import com.amazon.device.drm.model.LicenseResponse
|
|
3
7
|
import com.amazon.device.iap.PurchasingService
|
|
4
8
|
import com.amazon.device.iap.model.FulfillmentResult
|
|
5
9
|
import com.facebook.react.bridge.LifecycleEventListener
|
|
@@ -8,9 +12,10 @@ import com.facebook.react.bridge.ReactApplicationContext
|
|
|
8
12
|
import com.facebook.react.bridge.ReactContextBaseJavaModule
|
|
9
13
|
import com.facebook.react.bridge.ReactMethod
|
|
10
14
|
import com.facebook.react.bridge.ReadableArray
|
|
11
|
-
import com.facebook.react.bridge.
|
|
15
|
+
import com.facebook.react.bridge.UiThreadUtil
|
|
12
16
|
import com.facebook.react.module.annotations.ReactModule
|
|
13
|
-
|
|
17
|
+
|
|
18
|
+
|
|
14
19
|
@ReactModule(name = RNIapAmazonModule.TAG)
|
|
15
20
|
class RNIapAmazonModule(reactContext: ReactApplicationContext) :
|
|
16
21
|
ReactContextBaseJavaModule(reactContext) {
|
|
@@ -25,12 +30,56 @@ class RNIapAmazonModule(reactContext: ReactApplicationContext) :
|
|
|
25
30
|
val context = reactApplicationContext
|
|
26
31
|
val amazonListener = RNIapAmazonListener(context)
|
|
27
32
|
this.amazonListener = amazonListener
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
33
|
+
UiThreadUtil.runOnUiThread {
|
|
34
|
+
try {
|
|
35
|
+
PurchasingService.registerListener(context.applicationContext, amazonListener)
|
|
36
|
+
hasListener = true
|
|
37
|
+
// Prefetch user and purchases as per Amazon SDK documentation:
|
|
38
|
+
PurchasingService.getUserData()
|
|
39
|
+
PurchasingService.getPurchaseUpdates(false)
|
|
40
|
+
promise.safeResolve(true)
|
|
41
|
+
|
|
42
|
+
}catch (e:Exception){
|
|
43
|
+
promise.safeReject("Error initializing Amazon appstore sdk", e)
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
@ReactMethod
|
|
49
|
+
fun verifyLicense(promise: Promise){
|
|
50
|
+
try {
|
|
51
|
+
LicensingService.verifyLicense(reactApplicationContext) { licenseResponse ->
|
|
52
|
+
when (val status: LicenseResponse.RequestStatus =
|
|
53
|
+
licenseResponse.requestStatus) {
|
|
54
|
+
LicenseResponse.RequestStatus.LICENSED -> {
|
|
55
|
+
Log.d(TAG, "LicenseResponse status: $status")
|
|
56
|
+
promise.resolve("LICENSED")
|
|
57
|
+
}
|
|
58
|
+
LicenseResponse.RequestStatus.NOT_LICENSED -> {
|
|
59
|
+
Log.d(TAG, "LicenseResponse status: $status")
|
|
60
|
+
promise.resolve("NOT_LICENSED")
|
|
61
|
+
}
|
|
62
|
+
LicenseResponse.RequestStatus.EXPIRED -> {
|
|
63
|
+
Log.d(TAG, "LicenseResponse status: $status")
|
|
64
|
+
promise.resolve("EXPIRED")
|
|
65
|
+
}
|
|
66
|
+
LicenseResponse.RequestStatus.ERROR_VERIFICATION -> {
|
|
67
|
+
Log.d(TAG, "LicenseResponse status: $status")
|
|
68
|
+
promise.resolve("ERROR_VERIFICATION")
|
|
69
|
+
}
|
|
70
|
+
LicenseResponse.RequestStatus.ERROR_INVALID_LICENSING_KEYS -> {
|
|
71
|
+
Log.d(TAG, "LicenseResponse status: $status")
|
|
72
|
+
promise.resolve("ERROR_INVALID_LICENSING_KEYS")
|
|
73
|
+
}
|
|
74
|
+
LicenseResponse.RequestStatus.UNKNOWN_ERROR -> {
|
|
75
|
+
Log.d(TAG, "LicenseResponse status: $status")
|
|
76
|
+
promise.resolve("UNKNOWN_ERROR")
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}catch (exception: Exception){
|
|
81
|
+
promise.reject("Error while attempting to check for License",exception)
|
|
82
|
+
}
|
|
34
83
|
}
|
|
35
84
|
|
|
36
85
|
@ReactMethod
|
|
@@ -105,8 +154,8 @@ class RNIapAmazonModule(reactContext: ReactApplicationContext) :
|
|
|
105
154
|
}
|
|
106
155
|
|
|
107
156
|
private fun sendUnconsumedPurchases(promise: Promise) {
|
|
108
|
-
PurchasingService.getPurchaseUpdates(false)
|
|
109
157
|
DoobooUtils.instance.addPromiseForKey(PROMISE_QUERY_PURCHASES, promise)
|
|
158
|
+
PurchasingService.getPurchaseUpdates(false)
|
|
110
159
|
}
|
|
111
160
|
|
|
112
161
|
@ReactMethod
|
package/ios/IapTypes.swift
CHANGED
|
@@ -33,3 +33,24 @@ enum IapErrors: String, CaseIterable {
|
|
|
33
33
|
return IapErrors.allCases.firstIndex(of: self)!
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
|
+
|
|
37
|
+
// Based on https://stackoverflow.com/a/40135192/570612
|
|
38
|
+
extension Date {
|
|
39
|
+
var millisecondsSince1970: Int64 {
|
|
40
|
+
return Int64((self.timeIntervalSince1970 * 1000.0).rounded())
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
var millisecondsSince1970String: String {
|
|
44
|
+
return String((self.timeIntervalSince1970 * 1000.0).rounded())
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
init(milliseconds: Int64) {
|
|
48
|
+
self = Date(timeIntervalSince1970: TimeInterval(milliseconds) / 1000)
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
extension SKProductsRequest {
|
|
53
|
+
var key: String {
|
|
54
|
+
return String(self.hashValue)
|
|
55
|
+
}
|
|
56
|
+
}
|
package/ios/RNIapIos.swift
CHANGED
|
@@ -1,27 +1,6 @@
|
|
|
1
1
|
import React
|
|
2
2
|
import StoreKit
|
|
3
3
|
|
|
4
|
-
// Based on https://stackoverflow.com/a/40135192/570612
|
|
5
|
-
extension Date {
|
|
6
|
-
var millisecondsSince1970: Int64 {
|
|
7
|
-
return Int64((self.timeIntervalSince1970 * 1000.0).rounded())
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
var millisecondsSince1970String: String {
|
|
11
|
-
return String((self.timeIntervalSince1970 * 1000.0).rounded())
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
init(milliseconds: Int64) {
|
|
15
|
-
self = Date(timeIntervalSince1970: TimeInterval(milliseconds) / 1000)
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
extension SKProductsRequest {
|
|
20
|
-
var key: String {
|
|
21
|
-
return String(self.hashValue)
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
4
|
@objc(RNIapIos)
|
|
26
5
|
class RNIapIos: RCTEventEmitter, SKRequestDelegate, SKPaymentTransactionObserver, SKProductsRequestDelegate {
|
|
27
6
|
private var promisesByKey: [String: [RNIapIosPromise]]
|
|
@@ -29,7 +8,7 @@ class RNIapIos: RCTEventEmitter, SKRequestDelegate, SKPaymentTransactionObserver
|
|
|
29
8
|
private var hasListeners = false
|
|
30
9
|
private var pendingTransactionWithAutoFinish = false
|
|
31
10
|
private var receiptBlock: ((Data?, Error?) -> Void)? // Block to handle request the receipt async from delegate
|
|
32
|
-
private var validProducts: [SKProduct]
|
|
11
|
+
private var validProducts: [String: SKProduct]
|
|
33
12
|
private var promotedPayment: SKPayment?
|
|
34
13
|
private var promotedProduct: SKProduct?
|
|
35
14
|
private var productsRequest: SKProductsRequest?
|
|
@@ -40,7 +19,7 @@ class RNIapIos: RCTEventEmitter, SKRequestDelegate, SKPaymentTransactionObserver
|
|
|
40
19
|
promisesByKey = [String: [RNIapIosPromise]]()
|
|
41
20
|
pendingTransactionWithAutoFinish = false
|
|
42
21
|
myQueue = DispatchQueue(label: "reject")
|
|
43
|
-
validProducts = [SKProduct]()
|
|
22
|
+
validProducts = [String: SKProduct]()
|
|
44
23
|
super.init()
|
|
45
24
|
addTransactionObserver()
|
|
46
25
|
}
|
|
@@ -212,16 +191,8 @@ class RNIapIos: RCTEventEmitter, SKRequestDelegate, SKPaymentTransactionObserver
|
|
|
212
191
|
reject: @escaping RCTPromiseRejectBlock = { _, _, _ in }
|
|
213
192
|
) {
|
|
214
193
|
pendingTransactionWithAutoFinish = andDangerouslyFinishTransactionAutomatically
|
|
215
|
-
var product: SKProduct?
|
|
216
|
-
|
|
217
|
-
lockQueue.sync {
|
|
218
|
-
for p in validProducts {
|
|
219
|
-
if sku == p.productIdentifier {
|
|
220
|
-
product = p
|
|
221
|
-
break
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
}
|
|
194
|
+
var product: SKProduct? = validProducts[sku]
|
|
195
|
+
|
|
225
196
|
if let prod = product {
|
|
226
197
|
addPromise(forKey: prod.productIdentifier, resolve: resolve, reject: reject)
|
|
227
198
|
|
|
@@ -391,12 +362,8 @@ class RNIapIos: RCTEventEmitter, SKRequestDelegate, SKPaymentTransactionObserver
|
|
|
391
362
|
}
|
|
392
363
|
|
|
393
364
|
var items: [[String: Any?]] = [[:]]
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
lockQueue.sync {
|
|
397
|
-
for product in validProducts {
|
|
398
|
-
items.append(getProductObject(product))
|
|
399
|
-
}
|
|
365
|
+
for product in validProducts.values {
|
|
366
|
+
items.append(getProductObject(product))
|
|
400
367
|
}
|
|
401
368
|
|
|
402
369
|
resolvePromises(forKey: request.key, value: items)
|
|
@@ -405,25 +372,8 @@ class RNIapIos: RCTEventEmitter, SKRequestDelegate, SKPaymentTransactionObserver
|
|
|
405
372
|
// Add to valid products from Apple server response. Allowing getProducts, getSubscriptions call several times.
|
|
406
373
|
// Doesn't allow duplication. Replace new product.
|
|
407
374
|
func add(_ aProd: SKProduct) {
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
lockQueue.sync {
|
|
411
|
-
debugMessage("Add new object: \(aProd.productIdentifier)")
|
|
412
|
-
var delTar = -1
|
|
413
|
-
|
|
414
|
-
for k in 0..<validProducts.count {
|
|
415
|
-
let cur = validProducts[k]
|
|
416
|
-
if cur.productIdentifier == aProd.productIdentifier {
|
|
417
|
-
delTar = k
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
if delTar >= 0 {
|
|
422
|
-
validProducts.remove(at: delTar)
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
validProducts.append(aProd)
|
|
426
|
-
}
|
|
375
|
+
debugMessage("Add new object: \(aProd.productIdentifier)")
|
|
376
|
+
validProducts[aProd.productIdentifier] = aProd
|
|
427
377
|
}
|
|
428
378
|
|
|
429
379
|
func request(_ request: SKRequest, didFailWithError error: Error) {
|
package/ios/RNIapIosSk2.m
CHANGED
|
@@ -85,5 +85,9 @@ RCT_EXTERN_METHOD(presentCodeRedemptionSheet:
|
|
|
85
85
|
(RCTPromiseResolveBlock)resolve
|
|
86
86
|
reject:(RCTPromiseRejectBlock)reject)
|
|
87
87
|
|
|
88
|
+
RCT_EXTERN_METHOD(clearTransaction:
|
|
89
|
+
(RCTPromiseResolveBlock)resolve
|
|
90
|
+
reject:(RCTPromiseRejectBlock)reject)
|
|
91
|
+
|
|
88
92
|
@end
|
|
89
93
|
#endif
|
package/ios/RNIapIosSk2.swift
CHANGED
|
@@ -85,6 +85,11 @@ protocol Sk2Delegate {
|
|
|
85
85
|
reject: @escaping RCTPromiseRejectBlock
|
|
86
86
|
)
|
|
87
87
|
|
|
88
|
+
func clearTransaction(
|
|
89
|
+
_ resolve: @escaping RCTPromiseResolveBlock,
|
|
90
|
+
reject: @escaping RCTPromiseRejectBlock
|
|
91
|
+
)
|
|
92
|
+
|
|
88
93
|
func startObserving()
|
|
89
94
|
func stopObserving()
|
|
90
95
|
}
|
|
@@ -203,6 +208,10 @@ class DummySk2: Sk2Delegate {
|
|
|
203
208
|
reject(errorCode, errorMessage, nil)
|
|
204
209
|
}
|
|
205
210
|
|
|
211
|
+
func clearTransaction(_ resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
|
212
|
+
reject(errorCode, errorMessage, nil)
|
|
213
|
+
}
|
|
214
|
+
|
|
206
215
|
func startObserving() {
|
|
207
216
|
}
|
|
208
217
|
|
|
@@ -361,6 +370,12 @@ class RNIapIosSk2: RCTEventEmitter, Sk2Delegate {
|
|
|
361
370
|
) {
|
|
362
371
|
delegate.presentCodeRedemptionSheet(resolve, reject: reject)
|
|
363
372
|
}
|
|
373
|
+
|
|
374
|
+
@objc func clearTransaction(
|
|
375
|
+
_ resolve: @escaping RCTPromiseResolveBlock = { _ in },
|
|
376
|
+
reject: @escaping RCTPromiseRejectBlock = { _, _, _ in }) {
|
|
377
|
+
delegate.clearTransaction(resolve, reject: reject)
|
|
378
|
+
}
|
|
364
379
|
}
|
|
365
380
|
|
|
366
381
|
@available(iOS 15.0, tvOS 15.0, *)
|
|
@@ -810,4 +825,22 @@ class RNIapIosSk2iOS15: Sk2Delegate {
|
|
|
810
825
|
reject(IapErrors.E_USER_CANCELLED.rawValue, "This method is not available on tvOS", nil)
|
|
811
826
|
#endif
|
|
812
827
|
}
|
|
828
|
+
|
|
829
|
+
func clearTransaction(_ resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
|
830
|
+
Task {
|
|
831
|
+
for await result in Transaction.unfinished {
|
|
832
|
+
do {
|
|
833
|
+
// Check whether the transaction is verified. If it isn’t, catch `failedVerification` error.
|
|
834
|
+
let transaction = try checkVerified(result)
|
|
835
|
+
debugMessage("Finishing transaction")
|
|
836
|
+
await transaction.finish()
|
|
837
|
+
debugMessage("Finished transaction")
|
|
838
|
+
transactions.removeValue(forKey: String(transaction.id))
|
|
839
|
+
} catch {
|
|
840
|
+
debugMessage("Failed to finish transaction")
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
resolve(nil)
|
|
844
|
+
}
|
|
845
|
+
}
|
|
813
846
|
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.storekitHybridMode = exports.storekit2Mode = exports.storekit1Mode = exports.setIosNativeModule = exports.setAndroidNativeModule = exports.isStorekit2Avaiable = exports.isIosStorekit2 = exports.isIos = exports.isAndroid = exports.isAmazon = exports.getNativeModule = exports.getIosModule = exports.getAndroidModule = exports.checkNativeAndroidAvailable = void 0;
|
|
6
|
+
exports.storekitHybridMode = exports.storekit2Mode = exports.storekit1Mode = exports.setIosNativeModule = exports.setAndroidNativeModule = exports.isStorekit2Avaiable = exports.isPlay = exports.isIosStorekit2 = exports.isIos = exports.isAndroid = exports.isAmazon = exports.getNativeModule = exports.getIosModule = exports.getAndroidModule = exports.checkNativeAndroidAvailable = void 0;
|
|
7
7
|
|
|
8
8
|
var _reactNative = require("react-native");
|
|
9
9
|
|
|
@@ -19,9 +19,11 @@ const isIos = _reactNative.Platform.OS === 'ios';
|
|
|
19
19
|
exports.isIos = isIos;
|
|
20
20
|
const isAndroid = _reactNative.Platform.OS === 'android';
|
|
21
21
|
exports.isAndroid = isAndroid;
|
|
22
|
-
const isAmazon = isAndroid && !!RNIapAmazonModule;
|
|
23
|
-
|
|
22
|
+
const isAmazon = isAndroid && !!RNIapAmazonModule;
|
|
24
23
|
exports.isAmazon = isAmazon;
|
|
24
|
+
const isPlay = isAndroid && !!RNIapModule; // Android
|
|
25
|
+
|
|
26
|
+
exports.isPlay = isPlay;
|
|
25
27
|
let androidNativeModule = RNIapModule;
|
|
26
28
|
|
|
27
29
|
const setAndroidNativeModule = nativeModule => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["RNIapIos","RNIapIosSk2","RNIapModule","RNIapAmazonModule","NativeModules","isIos","Platform","OS","isAndroid","isAmazon","androidNativeModule","setAndroidNativeModule","nativeModule","checkNativeAndroidAvailable","Error","ErrorCode","E_IAP_NOT_AVAILABLE","getAndroidModule","getNativeModule","getIosModule","iosNativeModule","isStorekit2Avaiable","isAvailable","isIosStorekit2","setIosNativeModule","storekit2Mode","disable","console","warn","storekit1Mode","storekitHybridMode","info","checkNativeIOSAvailable"],"sources":["platform.ts"],"sourcesContent":["import {NativeModules, Platform} from 'react-native';\n\nimport {ErrorCode} from '../purchaseError';\n\nconst {RNIapIos, RNIapIosSk2, RNIapModule, RNIapAmazonModule} = NativeModules;\n\nexport const isIos = Platform.OS === 'ios';\nexport const isAndroid = Platform.OS === 'android';\nexport const isAmazon = isAndroid && !!RNIapAmazonModule;\n\n// Android\n\nlet androidNativeModule = RNIapModule;\n\nexport const setAndroidNativeModule = (\n nativeModule: typeof RNIapModule,\n): void => {\n androidNativeModule = nativeModule;\n};\n\nexport const checkNativeAndroidAvailable = (): void => {\n if (!RNIapModule && !RNIapAmazonModule) {\n throw new Error(ErrorCode.E_IAP_NOT_AVAILABLE);\n }\n};\n\nexport const getAndroidModule = ():\n | typeof RNIapModule\n | typeof RNIapAmazonModule => {\n checkNativeAndroidAvailable();\n\n return androidNativeModule\n ? androidNativeModule\n : RNIapModule\n ? RNIapModule\n : RNIapAmazonModule;\n};\n\nexport const getNativeModule = ():\n | typeof RNIapModule\n | typeof RNIapAmazonModule\n | typeof RNIapIos\n | typeof RNIapIosSk2 => {\n return isAndroid ? getAndroidModule() : getIosModule();\n};\n\n// iOS\n\nlet iosNativeModule: typeof RNIapIos | typeof RNIapIosSk2 = RNIapIos;\n\nexport const isStorekit2Avaiable = (): boolean =>\n isIos && RNIapIosSk2?.isAvailable() === 1;\n\nexport const isIosStorekit2 = () =>\n isIos &&\n !!iosNativeModule &&\n iosNativeModule === RNIapIosSk2 &&\n isStorekit2Avaiable();\n\nexport const setIosNativeModule = (\n nativeModule: typeof RNIapIos | typeof RNIapIosSk2,\n): void => {\n iosNativeModule = nativeModule;\n};\n\nexport const storekit2Mode = () => {\n iosNativeModule = RNIapIosSk2;\n if (isStorekit2Avaiable()) {\n RNIapIos.disable();\n return true;\n }\n if (isIos) {\n console.warn('Storekit 2 is not available on this device');\n return false;\n }\n return true;\n};\n\nexport const storekit1Mode = () => {\n iosNativeModule = RNIapIos;\n if (isStorekit2Avaiable()) {\n RNIapIosSk2.disable();\n return true;\n }\n return false;\n};\n\nexport const storekitHybridMode = () => {\n if (isStorekit2Avaiable()) {\n iosNativeModule = RNIapIosSk2;\n console.info('Using Storekit 2');\n return true;\n } else {\n iosNativeModule = RNIapIos;\n console.info('Using Storekit 1');\n return true;\n }\n};\n\nconst checkNativeIOSAvailable = (): void => {\n if (!RNIapIos && !isStorekit2Avaiable()) {\n throw new Error(ErrorCode.E_IAP_NOT_AVAILABLE);\n }\n};\n\nexport const getIosModule = (): typeof RNIapIos | typeof RNIapIosSk2 => {\n checkNativeIOSAvailable();\n\n return iosNativeModule\n ? iosNativeModule\n : RNIapIosSk2\n ? RNIapIosSk2\n : RNIapIos;\n};\n"],"mappings":";;;;;;;AAAA;;AAEA;;AAEA,MAAM;EAACA,QAAD;EAAWC,WAAX;EAAwBC,WAAxB;EAAqCC;AAArC,IAA0DC,0BAAhE;AAEO,MAAMC,KAAK,GAAGC,qBAAA,CAASC,EAAT,KAAgB,KAA9B;;AACA,MAAMC,SAAS,GAAGF,qBAAA,CAASC,EAAT,KAAgB,SAAlC;;AACA,MAAME,QAAQ,GAAGD,SAAS,IAAI,CAAC,CAACL,iBAAhC,C,CAEP;;;AAEA,
|
|
1
|
+
{"version":3,"names":["RNIapIos","RNIapIosSk2","RNIapModule","RNIapAmazonModule","NativeModules","isIos","Platform","OS","isAndroid","isAmazon","isPlay","androidNativeModule","setAndroidNativeModule","nativeModule","checkNativeAndroidAvailable","Error","ErrorCode","E_IAP_NOT_AVAILABLE","getAndroidModule","getNativeModule","getIosModule","iosNativeModule","isStorekit2Avaiable","isAvailable","isIosStorekit2","setIosNativeModule","storekit2Mode","disable","console","warn","storekit1Mode","storekitHybridMode","info","checkNativeIOSAvailable"],"sources":["platform.ts"],"sourcesContent":["import {NativeModules, Platform} from 'react-native';\n\nimport {ErrorCode} from '../purchaseError';\n\nconst {RNIapIos, RNIapIosSk2, RNIapModule, RNIapAmazonModule} = NativeModules;\n\nexport const isIos = Platform.OS === 'ios';\nexport const isAndroid = Platform.OS === 'android';\nexport const isAmazon = isAndroid && !!RNIapAmazonModule;\nexport const isPlay = isAndroid && !!RNIapModule;\n\n// Android\n\nlet androidNativeModule = RNIapModule;\n\nexport const setAndroidNativeModule = (\n nativeModule: typeof RNIapModule,\n): void => {\n androidNativeModule = nativeModule;\n};\n\nexport const checkNativeAndroidAvailable = (): void => {\n if (!RNIapModule && !RNIapAmazonModule) {\n throw new Error(ErrorCode.E_IAP_NOT_AVAILABLE);\n }\n};\n\nexport const getAndroidModule = ():\n | typeof RNIapModule\n | typeof RNIapAmazonModule => {\n checkNativeAndroidAvailable();\n\n return androidNativeModule\n ? androidNativeModule\n : RNIapModule\n ? RNIapModule\n : RNIapAmazonModule;\n};\n\nexport const getNativeModule = ():\n | typeof RNIapModule\n | typeof RNIapAmazonModule\n | typeof RNIapIos\n | typeof RNIapIosSk2 => {\n return isAndroid ? getAndroidModule() : getIosModule();\n};\n\n// iOS\n\nlet iosNativeModule: typeof RNIapIos | typeof RNIapIosSk2 = RNIapIos;\n\nexport const isStorekit2Avaiable = (): boolean =>\n isIos && RNIapIosSk2?.isAvailable() === 1;\n\nexport const isIosStorekit2 = () =>\n isIos &&\n !!iosNativeModule &&\n iosNativeModule === RNIapIosSk2 &&\n isStorekit2Avaiable();\n\nexport const setIosNativeModule = (\n nativeModule: typeof RNIapIos | typeof RNIapIosSk2,\n): void => {\n iosNativeModule = nativeModule;\n};\n\nexport const storekit2Mode = () => {\n iosNativeModule = RNIapIosSk2;\n if (isStorekit2Avaiable()) {\n RNIapIos.disable();\n return true;\n }\n if (isIos) {\n console.warn('Storekit 2 is not available on this device');\n return false;\n }\n return true;\n};\n\nexport const storekit1Mode = () => {\n iosNativeModule = RNIapIos;\n if (isStorekit2Avaiable()) {\n RNIapIosSk2.disable();\n return true;\n }\n return false;\n};\n\nexport const storekitHybridMode = () => {\n if (isStorekit2Avaiable()) {\n iosNativeModule = RNIapIosSk2;\n console.info('Using Storekit 2');\n return true;\n } else {\n iosNativeModule = RNIapIos;\n console.info('Using Storekit 1');\n return true;\n }\n};\n\nconst checkNativeIOSAvailable = (): void => {\n if (!RNIapIos && !isStorekit2Avaiable()) {\n throw new Error(ErrorCode.E_IAP_NOT_AVAILABLE);\n }\n};\n\nexport const getIosModule = (): typeof RNIapIos | typeof RNIapIosSk2 => {\n checkNativeIOSAvailable();\n\n return iosNativeModule\n ? iosNativeModule\n : RNIapIosSk2\n ? RNIapIosSk2\n : RNIapIos;\n};\n"],"mappings":";;;;;;;AAAA;;AAEA;;AAEA,MAAM;EAACA,QAAD;EAAWC,WAAX;EAAwBC,WAAxB;EAAqCC;AAArC,IAA0DC,0BAAhE;AAEO,MAAMC,KAAK,GAAGC,qBAAA,CAASC,EAAT,KAAgB,KAA9B;;AACA,MAAMC,SAAS,GAAGF,qBAAA,CAASC,EAAT,KAAgB,SAAlC;;AACA,MAAME,QAAQ,GAAGD,SAAS,IAAI,CAAC,CAACL,iBAAhC;;AACA,MAAMO,MAAM,GAAGF,SAAS,IAAI,CAAC,CAACN,WAA9B,C,CAEP;;;AAEA,IAAIS,mBAAmB,GAAGT,WAA1B;;AAEO,MAAMU,sBAAsB,GACjCC,YADoC,IAE3B;EACTF,mBAAmB,GAAGE,YAAtB;AACD,CAJM;;;;AAMA,MAAMC,2BAA2B,GAAG,MAAY;EACrD,IAAI,CAACZ,WAAD,IAAgB,CAACC,iBAArB,EAAwC;IACtC,MAAM,IAAIY,KAAJ,CAAUC,wBAAA,CAAUC,mBAApB,CAAN;EACD;AACF,CAJM;;;;AAMA,MAAMC,gBAAgB,GAAG,MAEA;EAC9BJ,2BAA2B;EAE3B,OAAOH,mBAAmB,GACtBA,mBADsB,GAEtBT,WAAW,GACXA,WADW,GAEXC,iBAJJ;AAKD,CAVM;;;;AAYA,MAAMgB,eAAe,GAAG,MAIL;EACxB,OAAOX,SAAS,GAAGU,gBAAgB,EAAnB,GAAwBE,YAAY,EAApD;AACD,CANM,C,CAQP;;;;AAEA,IAAIC,eAAqD,GAAGrB,QAA5D;;AAEO,MAAMsB,mBAAmB,GAAG,MACjCjB,KAAK,IAAI,CAAAJ,WAAW,SAAX,IAAAA,WAAW,WAAX,YAAAA,WAAW,CAAEsB,WAAb,QAA+B,CADnC;;;;AAGA,MAAMC,cAAc,GAAG,MAC5BnB,KAAK,IACL,CAAC,CAACgB,eADF,IAEAA,eAAe,KAAKpB,WAFpB,IAGAqB,mBAAmB,EAJd;;;;AAMA,MAAMG,kBAAkB,GAC7BZ,YADgC,IAEvB;EACTQ,eAAe,GAAGR,YAAlB;AACD,CAJM;;;;AAMA,MAAMa,aAAa,GAAG,MAAM;EACjCL,eAAe,GAAGpB,WAAlB;;EACA,IAAIqB,mBAAmB,EAAvB,EAA2B;IACzBtB,QAAQ,CAAC2B,OAAT;IACA,OAAO,IAAP;EACD;;EACD,IAAItB,KAAJ,EAAW;IACTuB,OAAO,CAACC,IAAR,CAAa,4CAAb;IACA,OAAO,KAAP;EACD;;EACD,OAAO,IAAP;AACD,CAXM;;;;AAaA,MAAMC,aAAa,GAAG,MAAM;EACjCT,eAAe,GAAGrB,QAAlB;;EACA,IAAIsB,mBAAmB,EAAvB,EAA2B;IACzBrB,WAAW,CAAC0B,OAAZ;IACA,OAAO,IAAP;EACD;;EACD,OAAO,KAAP;AACD,CAPM;;;;AASA,MAAMI,kBAAkB,GAAG,MAAM;EACtC,IAAIT,mBAAmB,EAAvB,EAA2B;IACzBD,eAAe,GAAGpB,WAAlB;IACA2B,OAAO,CAACI,IAAR,CAAa,kBAAb;IACA,OAAO,IAAP;EACD,CAJD,MAIO;IACLX,eAAe,GAAGrB,QAAlB;IACA4B,OAAO,CAACI,IAAR,CAAa,kBAAb;IACA,OAAO,IAAP;EACD;AACF,CAVM;;;;AAYP,MAAMC,uBAAuB,GAAG,MAAY;EAC1C,IAAI,CAACjC,QAAD,IAAa,CAACsB,mBAAmB,EAArC,EAAyC;IACvC,MAAM,IAAIP,KAAJ,CAAUC,wBAAA,CAAUC,mBAApB,CAAN;EACD;AACF,CAJD;;AAMO,MAAMG,YAAY,GAAG,MAA4C;EACtEa,uBAAuB;EAEvB,OAAOZ,eAAe,GAClBA,eADkB,GAElBpB,WAAW,GACXA,WADW,GAEXD,QAJJ;AAKD,CARM"}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.validateReceiptAmazon = exports.AmazonModule = void 0;
|
|
6
|
+
exports.verifyLicense = exports.validateReceiptAmazon = exports.AmazonModule = void 0;
|
|
7
7
|
|
|
8
8
|
var _reactNative = require("react-native");
|
|
9
9
|
|
|
@@ -34,6 +34,14 @@ const validateReceiptAmazon = async _ref => {
|
|
|
34
34
|
const url = `https://appstore-sdk.amazon.com/${sandBoxUrl}version/1.0/verifyReceiptId/developer/${developerSecret}/user/${userId}/receiptId/${receiptId}`;
|
|
35
35
|
return await (0, _internal.enhancedFetch)(url);
|
|
36
36
|
};
|
|
37
|
+
/**
|
|
38
|
+
* Returns the status of verifying app's license @see AmazonLicensingStatus
|
|
39
|
+
*/
|
|
40
|
+
|
|
37
41
|
|
|
38
42
|
exports.validateReceiptAmazon = validateReceiptAmazon;
|
|
43
|
+
|
|
44
|
+
const verifyLicense = async () => AmazonModule.verifyLicense();
|
|
45
|
+
|
|
46
|
+
exports.verifyLicense = verifyLicense;
|
|
39
47
|
//# sourceMappingURL=amazon.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["AmazonModule","NativeModules","RNIapAmazonModule","validateReceiptAmazon","developerSecret","userId","receiptId","useSandbox","sandBoxUrl","url","enhancedFetch"],"sources":["amazon.ts"],"sourcesContent":["import {NativeModules} from 'react-native';\n\nimport {enhancedFetch} from '../internal';\nimport type {Product, Purchase, Sku} from '../types';\nimport type {UserDataAmazon} from '../types/amazon';\
|
|
1
|
+
{"version":3,"names":["AmazonModule","NativeModules","RNIapAmazonModule","validateReceiptAmazon","developerSecret","userId","receiptId","useSandbox","sandBoxUrl","url","enhancedFetch","verifyLicense"],"sources":["amazon.ts"],"sourcesContent":["import {NativeModules} from 'react-native';\n\nimport {enhancedFetch} from '../internal';\nimport type {Product, Purchase, Sku} from '../types';\nimport type {\n AmazonLicensingStatus,\n ReceiptType,\n UserDataAmazon,\n} from '../types/amazon';\n\nimport type {NativeModuleProps} from './common';\n// ----------\n\ntype GetUser = () => Promise<UserDataAmazon>;\ntype FlushFailedPurchasesCachedAsPending = () => Promise<boolean>;\ntype GetItemsByType = (type: string, skus: Sku[]) => Promise<Product[]>;\ntype GetAvailableItems = () => Promise<Purchase[]>;\ntype BuyItemByType = (sku: Sku) => Promise<Purchase>;\n\ntype AcknowledgePurchase = (\n purchaseToken: string,\n developerPayloadAndroid?: string,\n) => Promise<boolean>;\n\ntype ConsumeProduct = (\n purchaseToken: string,\n developerPayloadAndroid?: string,\n) => Promise<boolean>;\n\ntype StartListening = () => Promise<void>;\n\nexport interface AmazonModuleProps extends NativeModuleProps {\n getUser: GetUser;\n flushFailedPurchasesCachedAsPending: FlushFailedPurchasesCachedAsPending;\n getItemsByType: GetItemsByType;\n getAvailableItems: GetAvailableItems;\n buyItemByType: BuyItemByType;\n acknowledgePurchase: AcknowledgePurchase;\n consumeProduct: ConsumeProduct;\n startListening: StartListening;\n verifyLicense: () => Promise<AmazonLicensingStatus>;\n}\n\nexport const AmazonModule =\n NativeModules.RNIapAmazonModule as AmazonModuleProps;\n\n/**\n * Validate receipt for Amazon. NOTE: This method is here for debugging purposes only. Including\n * your developer secret in the binary you ship to users is potentially dangerous.\n * Use server side validation instead for your production builds\n * @param {string} developerSecret: from the Amazon developer console.\n * @param {string} userId who purchased the item.\n * @param {string} receiptId long obfuscated string returned when purchasing the item\n * @param {boolean} useSandbox Defaults to true, use sandbox environment or production.\n * @returns {Promise<object>}\n */\nexport const validateReceiptAmazon = async ({\n developerSecret,\n userId,\n receiptId,\n useSandbox = true,\n}: {\n developerSecret: string;\n userId: string;\n receiptId: string;\n useSandbox: boolean;\n}): Promise<ReceiptType> => {\n const sandBoxUrl = useSandbox ? 'sandbox/' : '';\n const url = `https://appstore-sdk.amazon.com/${sandBoxUrl}version/1.0/verifyReceiptId/developer/${developerSecret}/user/${userId}/receiptId/${receiptId}`;\n\n return await enhancedFetch<ReceiptType>(url);\n};\n\n/**\n * Returns the status of verifying app's license @see AmazonLicensingStatus\n */\nexport const verifyLicense = async (): Promise<AmazonLicensingStatus> =>\n AmazonModule.verifyLicense();\n"],"mappings":";;;;;;;AAAA;;AAEA;;AAyCO,MAAMA,YAAY,GACvBC,0BAAA,CAAcC,iBADT;AAGP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;AACO,MAAMC,qBAAqB,GAAG,cAUT;EAAA,IAVgB;IAC1CC,eAD0C;IAE1CC,MAF0C;IAG1CC,SAH0C;IAI1CC,UAAU,GAAG;EAJ6B,CAUhB;EAC1B,MAAMC,UAAU,GAAGD,UAAU,GAAG,UAAH,GAAgB,EAA7C;EACA,MAAME,GAAG,GAAI,mCAAkCD,UAAW,yCAAwCJ,eAAgB,SAAQC,MAAO,cAAaC,SAAU,EAAxJ;EAEA,OAAO,MAAM,IAAAI,uBAAA,EAA2BD,GAA3B,CAAb;AACD,CAfM;AAiBP;AACA;AACA;;;;;AACO,MAAME,aAAa,GAAG,YAC3BX,YAAY,CAACW,aAAb,EADK"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["amazon.ts"],"sourcesContent":["export interface UserDataAmazon {\n userIdAmazon?: string;\n userMarketplaceAmazon?: string;\n userJsonAmazon?: string;\n}\n\nexport interface ProductPurchaseAmazon extends UserDataAmazon {\n isCanceledAmazon?: boolean;\n}\n/**\n * From: https://developer.amazon.com/es/docs/in-app-purchasing/iap-rvs-examples.html\n */\nexport type ReceiptType = {\n autoRenewing: boolean;\n betaProduct: boolean;\n cancelDate: number | null;\n cancelReason: string;\n deferredDate: number | null;\n deferredSku: number | null;\n freeTrialEndDate: number;\n gracePeriodEndDate: number;\n parentProductId: string;\n productId: string;\n productType: string;\n purchaseDate: number;\n quantity: number;\n receiptId: string;\n renewalDate: number;\n term: string;\n termSku: string;\n testTransaction: boolean;\n} & Record<string, unknown>;\n"],"mappings":""}
|
|
1
|
+
{"version":3,"names":[],"sources":["amazon.ts"],"sourcesContent":["export interface UserDataAmazon {\n userIdAmazon?: string;\n userMarketplaceAmazon?: string;\n userJsonAmazon?: string;\n}\n\nexport interface ProductPurchaseAmazon extends UserDataAmazon {\n isCanceledAmazon?: boolean;\n}\n/**\n * From: https://developer.amazon.com/es/docs/in-app-purchasing/iap-rvs-examples.html\n */\nexport type ReceiptType = {\n autoRenewing: boolean;\n betaProduct: boolean;\n cancelDate: number | null;\n cancelReason: string;\n deferredDate: number | null;\n deferredSku: number | null;\n freeTrialEndDate: number;\n gracePeriodEndDate: number;\n parentProductId: string;\n productId: string;\n productType: string;\n purchaseDate: number;\n quantity: number;\n receiptId: string;\n renewalDate: number;\n term: string;\n termSku: string;\n testTransaction: boolean;\n} & Record<string, unknown>;\n\nexport type AmazonLicensingStatus =\n | 'LICENSED'\n | 'NOT_LICENSED'\n | 'EXPIRED'\n | 'ERROR_VERIFICATION'\n | 'ERROR_INVALID_LICENSING_KEYS'\n | 'UNKNOWN_ERROR';\n"],"mappings":""}
|
|
@@ -8,7 +8,8 @@ const {
|
|
|
8
8
|
} = NativeModules;
|
|
9
9
|
export const isIos = Platform.OS === 'ios';
|
|
10
10
|
export const isAndroid = Platform.OS === 'android';
|
|
11
|
-
export const isAmazon = isAndroid && !!RNIapAmazonModule;
|
|
11
|
+
export const isAmazon = isAndroid && !!RNIapAmazonModule;
|
|
12
|
+
export const isPlay = isAndroid && !!RNIapModule; // Android
|
|
12
13
|
|
|
13
14
|
let androidNativeModule = RNIapModule;
|
|
14
15
|
export const setAndroidNativeModule = nativeModule => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["NativeModules","Platform","ErrorCode","RNIapIos","RNIapIosSk2","RNIapModule","RNIapAmazonModule","isIos","OS","isAndroid","isAmazon","androidNativeModule","setAndroidNativeModule","nativeModule","checkNativeAndroidAvailable","Error","E_IAP_NOT_AVAILABLE","getAndroidModule","getNativeModule","getIosModule","iosNativeModule","isStorekit2Avaiable","isAvailable","isIosStorekit2","setIosNativeModule","storekit2Mode","disable","console","warn","storekit1Mode","storekitHybridMode","info","checkNativeIOSAvailable"],"sources":["platform.ts"],"sourcesContent":["import {NativeModules, Platform} from 'react-native';\n\nimport {ErrorCode} from '../purchaseError';\n\nconst {RNIapIos, RNIapIosSk2, RNIapModule, RNIapAmazonModule} = NativeModules;\n\nexport const isIos = Platform.OS === 'ios';\nexport const isAndroid = Platform.OS === 'android';\nexport const isAmazon = isAndroid && !!RNIapAmazonModule;\n\n// Android\n\nlet androidNativeModule = RNIapModule;\n\nexport const setAndroidNativeModule = (\n nativeModule: typeof RNIapModule,\n): void => {\n androidNativeModule = nativeModule;\n};\n\nexport const checkNativeAndroidAvailable = (): void => {\n if (!RNIapModule && !RNIapAmazonModule) {\n throw new Error(ErrorCode.E_IAP_NOT_AVAILABLE);\n }\n};\n\nexport const getAndroidModule = ():\n | typeof RNIapModule\n | typeof RNIapAmazonModule => {\n checkNativeAndroidAvailable();\n\n return androidNativeModule\n ? androidNativeModule\n : RNIapModule\n ? RNIapModule\n : RNIapAmazonModule;\n};\n\nexport const getNativeModule = ():\n | typeof RNIapModule\n | typeof RNIapAmazonModule\n | typeof RNIapIos\n | typeof RNIapIosSk2 => {\n return isAndroid ? getAndroidModule() : getIosModule();\n};\n\n// iOS\n\nlet iosNativeModule: typeof RNIapIos | typeof RNIapIosSk2 = RNIapIos;\n\nexport const isStorekit2Avaiable = (): boolean =>\n isIos && RNIapIosSk2?.isAvailable() === 1;\n\nexport const isIosStorekit2 = () =>\n isIos &&\n !!iosNativeModule &&\n iosNativeModule === RNIapIosSk2 &&\n isStorekit2Avaiable();\n\nexport const setIosNativeModule = (\n nativeModule: typeof RNIapIos | typeof RNIapIosSk2,\n): void => {\n iosNativeModule = nativeModule;\n};\n\nexport const storekit2Mode = () => {\n iosNativeModule = RNIapIosSk2;\n if (isStorekit2Avaiable()) {\n RNIapIos.disable();\n return true;\n }\n if (isIos) {\n console.warn('Storekit 2 is not available on this device');\n return false;\n }\n return true;\n};\n\nexport const storekit1Mode = () => {\n iosNativeModule = RNIapIos;\n if (isStorekit2Avaiable()) {\n RNIapIosSk2.disable();\n return true;\n }\n return false;\n};\n\nexport const storekitHybridMode = () => {\n if (isStorekit2Avaiable()) {\n iosNativeModule = RNIapIosSk2;\n console.info('Using Storekit 2');\n return true;\n } else {\n iosNativeModule = RNIapIos;\n console.info('Using Storekit 1');\n return true;\n }\n};\n\nconst checkNativeIOSAvailable = (): void => {\n if (!RNIapIos && !isStorekit2Avaiable()) {\n throw new Error(ErrorCode.E_IAP_NOT_AVAILABLE);\n }\n};\n\nexport const getIosModule = (): typeof RNIapIos | typeof RNIapIosSk2 => {\n checkNativeIOSAvailable();\n\n return iosNativeModule\n ? iosNativeModule\n : RNIapIosSk2\n ? RNIapIosSk2\n : RNIapIos;\n};\n"],"mappings":"AAAA,SAAQA,aAAR,EAAuBC,QAAvB,QAAsC,cAAtC;AAEA,SAAQC,SAAR,QAAwB,kBAAxB;AAEA,MAAM;EAACC,QAAD;EAAWC,WAAX;EAAwBC,WAAxB;EAAqCC;AAArC,IAA0DN,aAAhE;AAEA,OAAO,MAAMO,KAAK,GAAGN,QAAQ,CAACO,EAAT,KAAgB,KAA9B;AACP,OAAO,MAAMC,SAAS,GAAGR,QAAQ,CAACO,EAAT,KAAgB,SAAlC;AACP,OAAO,MAAME,QAAQ,GAAGD,SAAS,IAAI,CAAC,CAACH,iBAAhC,C,CAEP;;AAEA,
|
|
1
|
+
{"version":3,"names":["NativeModules","Platform","ErrorCode","RNIapIos","RNIapIosSk2","RNIapModule","RNIapAmazonModule","isIos","OS","isAndroid","isAmazon","isPlay","androidNativeModule","setAndroidNativeModule","nativeModule","checkNativeAndroidAvailable","Error","E_IAP_NOT_AVAILABLE","getAndroidModule","getNativeModule","getIosModule","iosNativeModule","isStorekit2Avaiable","isAvailable","isIosStorekit2","setIosNativeModule","storekit2Mode","disable","console","warn","storekit1Mode","storekitHybridMode","info","checkNativeIOSAvailable"],"sources":["platform.ts"],"sourcesContent":["import {NativeModules, Platform} from 'react-native';\n\nimport {ErrorCode} from '../purchaseError';\n\nconst {RNIapIos, RNIapIosSk2, RNIapModule, RNIapAmazonModule} = NativeModules;\n\nexport const isIos = Platform.OS === 'ios';\nexport const isAndroid = Platform.OS === 'android';\nexport const isAmazon = isAndroid && !!RNIapAmazonModule;\nexport const isPlay = isAndroid && !!RNIapModule;\n\n// Android\n\nlet androidNativeModule = RNIapModule;\n\nexport const setAndroidNativeModule = (\n nativeModule: typeof RNIapModule,\n): void => {\n androidNativeModule = nativeModule;\n};\n\nexport const checkNativeAndroidAvailable = (): void => {\n if (!RNIapModule && !RNIapAmazonModule) {\n throw new Error(ErrorCode.E_IAP_NOT_AVAILABLE);\n }\n};\n\nexport const getAndroidModule = ():\n | typeof RNIapModule\n | typeof RNIapAmazonModule => {\n checkNativeAndroidAvailable();\n\n return androidNativeModule\n ? androidNativeModule\n : RNIapModule\n ? RNIapModule\n : RNIapAmazonModule;\n};\n\nexport const getNativeModule = ():\n | typeof RNIapModule\n | typeof RNIapAmazonModule\n | typeof RNIapIos\n | typeof RNIapIosSk2 => {\n return isAndroid ? getAndroidModule() : getIosModule();\n};\n\n// iOS\n\nlet iosNativeModule: typeof RNIapIos | typeof RNIapIosSk2 = RNIapIos;\n\nexport const isStorekit2Avaiable = (): boolean =>\n isIos && RNIapIosSk2?.isAvailable() === 1;\n\nexport const isIosStorekit2 = () =>\n isIos &&\n !!iosNativeModule &&\n iosNativeModule === RNIapIosSk2 &&\n isStorekit2Avaiable();\n\nexport const setIosNativeModule = (\n nativeModule: typeof RNIapIos | typeof RNIapIosSk2,\n): void => {\n iosNativeModule = nativeModule;\n};\n\nexport const storekit2Mode = () => {\n iosNativeModule = RNIapIosSk2;\n if (isStorekit2Avaiable()) {\n RNIapIos.disable();\n return true;\n }\n if (isIos) {\n console.warn('Storekit 2 is not available on this device');\n return false;\n }\n return true;\n};\n\nexport const storekit1Mode = () => {\n iosNativeModule = RNIapIos;\n if (isStorekit2Avaiable()) {\n RNIapIosSk2.disable();\n return true;\n }\n return false;\n};\n\nexport const storekitHybridMode = () => {\n if (isStorekit2Avaiable()) {\n iosNativeModule = RNIapIosSk2;\n console.info('Using Storekit 2');\n return true;\n } else {\n iosNativeModule = RNIapIos;\n console.info('Using Storekit 1');\n return true;\n }\n};\n\nconst checkNativeIOSAvailable = (): void => {\n if (!RNIapIos && !isStorekit2Avaiable()) {\n throw new Error(ErrorCode.E_IAP_NOT_AVAILABLE);\n }\n};\n\nexport const getIosModule = (): typeof RNIapIos | typeof RNIapIosSk2 => {\n checkNativeIOSAvailable();\n\n return iosNativeModule\n ? iosNativeModule\n : RNIapIosSk2\n ? RNIapIosSk2\n : RNIapIos;\n};\n"],"mappings":"AAAA,SAAQA,aAAR,EAAuBC,QAAvB,QAAsC,cAAtC;AAEA,SAAQC,SAAR,QAAwB,kBAAxB;AAEA,MAAM;EAACC,QAAD;EAAWC,WAAX;EAAwBC,WAAxB;EAAqCC;AAArC,IAA0DN,aAAhE;AAEA,OAAO,MAAMO,KAAK,GAAGN,QAAQ,CAACO,EAAT,KAAgB,KAA9B;AACP,OAAO,MAAMC,SAAS,GAAGR,QAAQ,CAACO,EAAT,KAAgB,SAAlC;AACP,OAAO,MAAME,QAAQ,GAAGD,SAAS,IAAI,CAAC,CAACH,iBAAhC;AACP,OAAO,MAAMK,MAAM,GAAGF,SAAS,IAAI,CAAC,CAACJ,WAA9B,C,CAEP;;AAEA,IAAIO,mBAAmB,GAAGP,WAA1B;AAEA,OAAO,MAAMQ,sBAAsB,GACjCC,YADoC,IAE3B;EACTF,mBAAmB,GAAGE,YAAtB;AACD,CAJM;AAMP,OAAO,MAAMC,2BAA2B,GAAG,MAAY;EACrD,IAAI,CAACV,WAAD,IAAgB,CAACC,iBAArB,EAAwC;IACtC,MAAM,IAAIU,KAAJ,CAAUd,SAAS,CAACe,mBAApB,CAAN;EACD;AACF,CAJM;AAMP,OAAO,MAAMC,gBAAgB,GAAG,MAEA;EAC9BH,2BAA2B;EAE3B,OAAOH,mBAAmB,GACtBA,mBADsB,GAEtBP,WAAW,GACXA,WADW,GAEXC,iBAJJ;AAKD,CAVM;AAYP,OAAO,MAAMa,eAAe,GAAG,MAIL;EACxB,OAAOV,SAAS,GAAGS,gBAAgB,EAAnB,GAAwBE,YAAY,EAApD;AACD,CANM,C,CAQP;;AAEA,IAAIC,eAAqD,GAAGlB,QAA5D;AAEA,OAAO,MAAMmB,mBAAmB,GAAG,MACjCf,KAAK,IAAI,CAAAH,WAAW,SAAX,IAAAA,WAAW,WAAX,YAAAA,WAAW,CAAEmB,WAAb,QAA+B,CADnC;AAGP,OAAO,MAAMC,cAAc,GAAG,MAC5BjB,KAAK,IACL,CAAC,CAACc,eADF,IAEAA,eAAe,KAAKjB,WAFpB,IAGAkB,mBAAmB,EAJd;AAMP,OAAO,MAAMG,kBAAkB,GAC7BX,YADgC,IAEvB;EACTO,eAAe,GAAGP,YAAlB;AACD,CAJM;AAMP,OAAO,MAAMY,aAAa,GAAG,MAAM;EACjCL,eAAe,GAAGjB,WAAlB;;EACA,IAAIkB,mBAAmB,EAAvB,EAA2B;IACzBnB,QAAQ,CAACwB,OAAT;IACA,OAAO,IAAP;EACD;;EACD,IAAIpB,KAAJ,EAAW;IACTqB,OAAO,CAACC,IAAR,CAAa,4CAAb;IACA,OAAO,KAAP;EACD;;EACD,OAAO,IAAP;AACD,CAXM;AAaP,OAAO,MAAMC,aAAa,GAAG,MAAM;EACjCT,eAAe,GAAGlB,QAAlB;;EACA,IAAImB,mBAAmB,EAAvB,EAA2B;IACzBlB,WAAW,CAACuB,OAAZ;IACA,OAAO,IAAP;EACD;;EACD,OAAO,KAAP;AACD,CAPM;AASP,OAAO,MAAMI,kBAAkB,GAAG,MAAM;EACtC,IAAIT,mBAAmB,EAAvB,EAA2B;IACzBD,eAAe,GAAGjB,WAAlB;IACAwB,OAAO,CAACI,IAAR,CAAa,kBAAb;IACA,OAAO,IAAP;EACD,CAJD,MAIO;IACLX,eAAe,GAAGlB,QAAlB;IACAyB,OAAO,CAACI,IAAR,CAAa,kBAAb;IACA,OAAO,IAAP;EACD;AACF,CAVM;;AAYP,MAAMC,uBAAuB,GAAG,MAAY;EAC1C,IAAI,CAAC9B,QAAD,IAAa,CAACmB,mBAAmB,EAArC,EAAyC;IACvC,MAAM,IAAIN,KAAJ,CAAUd,SAAS,CAACe,mBAApB,CAAN;EACD;AACF,CAJD;;AAMA,OAAO,MAAMG,YAAY,GAAG,MAA4C;EACtEa,uBAAuB;EAEvB,OAAOZ,eAAe,GAClBA,eADkB,GAElBjB,WAAW,GACXA,WADW,GAEXD,QAJJ;AAKD,CARM"}
|
|
@@ -23,4 +23,9 @@ export const validateReceiptAmazon = async _ref => {
|
|
|
23
23
|
const url = `https://appstore-sdk.amazon.com/${sandBoxUrl}version/1.0/verifyReceiptId/developer/${developerSecret}/user/${userId}/receiptId/${receiptId}`;
|
|
24
24
|
return await enhancedFetch(url);
|
|
25
25
|
};
|
|
26
|
+
/**
|
|
27
|
+
* Returns the status of verifying app's license @see AmazonLicensingStatus
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
export const verifyLicense = async () => AmazonModule.verifyLicense();
|
|
26
31
|
//# sourceMappingURL=amazon.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["NativeModules","enhancedFetch","AmazonModule","RNIapAmazonModule","validateReceiptAmazon","developerSecret","userId","receiptId","useSandbox","sandBoxUrl","url"],"sources":["amazon.ts"],"sourcesContent":["import {NativeModules} from 'react-native';\n\nimport {enhancedFetch} from '../internal';\nimport type {Product, Purchase, Sku} from '../types';\nimport type {UserDataAmazon} from '../types/amazon';\
|
|
1
|
+
{"version":3,"names":["NativeModules","enhancedFetch","AmazonModule","RNIapAmazonModule","validateReceiptAmazon","developerSecret","userId","receiptId","useSandbox","sandBoxUrl","url","verifyLicense"],"sources":["amazon.ts"],"sourcesContent":["import {NativeModules} from 'react-native';\n\nimport {enhancedFetch} from '../internal';\nimport type {Product, Purchase, Sku} from '../types';\nimport type {\n AmazonLicensingStatus,\n ReceiptType,\n UserDataAmazon,\n} from '../types/amazon';\n\nimport type {NativeModuleProps} from './common';\n// ----------\n\ntype GetUser = () => Promise<UserDataAmazon>;\ntype FlushFailedPurchasesCachedAsPending = () => Promise<boolean>;\ntype GetItemsByType = (type: string, skus: Sku[]) => Promise<Product[]>;\ntype GetAvailableItems = () => Promise<Purchase[]>;\ntype BuyItemByType = (sku: Sku) => Promise<Purchase>;\n\ntype AcknowledgePurchase = (\n purchaseToken: string,\n developerPayloadAndroid?: string,\n) => Promise<boolean>;\n\ntype ConsumeProduct = (\n purchaseToken: string,\n developerPayloadAndroid?: string,\n) => Promise<boolean>;\n\ntype StartListening = () => Promise<void>;\n\nexport interface AmazonModuleProps extends NativeModuleProps {\n getUser: GetUser;\n flushFailedPurchasesCachedAsPending: FlushFailedPurchasesCachedAsPending;\n getItemsByType: GetItemsByType;\n getAvailableItems: GetAvailableItems;\n buyItemByType: BuyItemByType;\n acknowledgePurchase: AcknowledgePurchase;\n consumeProduct: ConsumeProduct;\n startListening: StartListening;\n verifyLicense: () => Promise<AmazonLicensingStatus>;\n}\n\nexport const AmazonModule =\n NativeModules.RNIapAmazonModule as AmazonModuleProps;\n\n/**\n * Validate receipt for Amazon. NOTE: This method is here for debugging purposes only. Including\n * your developer secret in the binary you ship to users is potentially dangerous.\n * Use server side validation instead for your production builds\n * @param {string} developerSecret: from the Amazon developer console.\n * @param {string} userId who purchased the item.\n * @param {string} receiptId long obfuscated string returned when purchasing the item\n * @param {boolean} useSandbox Defaults to true, use sandbox environment or production.\n * @returns {Promise<object>}\n */\nexport const validateReceiptAmazon = async ({\n developerSecret,\n userId,\n receiptId,\n useSandbox = true,\n}: {\n developerSecret: string;\n userId: string;\n receiptId: string;\n useSandbox: boolean;\n}): Promise<ReceiptType> => {\n const sandBoxUrl = useSandbox ? 'sandbox/' : '';\n const url = `https://appstore-sdk.amazon.com/${sandBoxUrl}version/1.0/verifyReceiptId/developer/${developerSecret}/user/${userId}/receiptId/${receiptId}`;\n\n return await enhancedFetch<ReceiptType>(url);\n};\n\n/**\n * Returns the status of verifying app's license @see AmazonLicensingStatus\n */\nexport const verifyLicense = async (): Promise<AmazonLicensingStatus> =>\n AmazonModule.verifyLicense();\n"],"mappings":"AAAA,SAAQA,aAAR,QAA4B,cAA5B;AAEA,SAAQC,aAAR,QAA4B,aAA5B;AAyCA,OAAO,MAAMC,YAAY,GACvBF,aAAa,CAACG,iBADT;AAGP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,qBAAqB,GAAG,cAUT;EAAA,IAVgB;IAC1CC,eAD0C;IAE1CC,MAF0C;IAG1CC,SAH0C;IAI1CC,UAAU,GAAG;EAJ6B,CAUhB;EAC1B,MAAMC,UAAU,GAAGD,UAAU,GAAG,UAAH,GAAgB,EAA7C;EACA,MAAME,GAAG,GAAI,mCAAkCD,UAAW,yCAAwCJ,eAAgB,SAAQC,MAAO,cAAaC,SAAU,EAAxJ;EAEA,OAAO,MAAMN,aAAa,CAAcS,GAAd,CAA1B;AACD,CAfM;AAiBP;AACA;AACA;;AACA,OAAO,MAAMC,aAAa,GAAG,YAC3BT,YAAY,CAACS,aAAb,EADK"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["amazon.ts"],"sourcesContent":["export interface UserDataAmazon {\n userIdAmazon?: string;\n userMarketplaceAmazon?: string;\n userJsonAmazon?: string;\n}\n\nexport interface ProductPurchaseAmazon extends UserDataAmazon {\n isCanceledAmazon?: boolean;\n}\n/**\n * From: https://developer.amazon.com/es/docs/in-app-purchasing/iap-rvs-examples.html\n */\nexport type ReceiptType = {\n autoRenewing: boolean;\n betaProduct: boolean;\n cancelDate: number | null;\n cancelReason: string;\n deferredDate: number | null;\n deferredSku: number | null;\n freeTrialEndDate: number;\n gracePeriodEndDate: number;\n parentProductId: string;\n productId: string;\n productType: string;\n purchaseDate: number;\n quantity: number;\n receiptId: string;\n renewalDate: number;\n term: string;\n termSku: string;\n testTransaction: boolean;\n} & Record<string, unknown>;\n"],"mappings":""}
|
|
1
|
+
{"version":3,"names":[],"sources":["amazon.ts"],"sourcesContent":["export interface UserDataAmazon {\n userIdAmazon?: string;\n userMarketplaceAmazon?: string;\n userJsonAmazon?: string;\n}\n\nexport interface ProductPurchaseAmazon extends UserDataAmazon {\n isCanceledAmazon?: boolean;\n}\n/**\n * From: https://developer.amazon.com/es/docs/in-app-purchasing/iap-rvs-examples.html\n */\nexport type ReceiptType = {\n autoRenewing: boolean;\n betaProduct: boolean;\n cancelDate: number | null;\n cancelReason: string;\n deferredDate: number | null;\n deferredSku: number | null;\n freeTrialEndDate: number;\n gracePeriodEndDate: number;\n parentProductId: string;\n productId: string;\n productType: string;\n purchaseDate: number;\n quantity: number;\n receiptId: string;\n renewalDate: number;\n term: string;\n termSku: string;\n testTransaction: boolean;\n} & Record<string, unknown>;\n\nexport type AmazonLicensingStatus =\n | 'LICENSED'\n | 'NOT_LICENSED'\n | 'EXPIRED'\n | 'ERROR_VERIFICATION'\n | 'ERROR_INVALID_LICENSING_KEYS'\n | 'UNKNOWN_ERROR';\n"],"mappings":""}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export declare const isIos: boolean;
|
|
2
2
|
export declare const isAndroid: boolean;
|
|
3
3
|
export declare const isAmazon: boolean;
|
|
4
|
+
export declare const isPlay: boolean;
|
|
4
5
|
export declare const setAndroidNativeModule: (nativeModule: import("..").AndroidModuleProps) => void;
|
|
5
6
|
export declare const checkNativeAndroidAvailable: () => void;
|
|
6
7
|
export declare const getAndroidModule: () => import("..").AmazonModuleProps | import("..").AndroidModuleProps;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { Product, Purchase, Sku } from '../types';
|
|
2
|
-
import type { UserDataAmazon } from '../types/amazon';
|
|
3
|
-
import type * as Amazon from '../types/amazon';
|
|
2
|
+
import type { AmazonLicensingStatus, ReceiptType, UserDataAmazon } from '../types/amazon';
|
|
4
3
|
import type { NativeModuleProps } from './common';
|
|
5
4
|
declare type GetUser = () => Promise<UserDataAmazon>;
|
|
6
5
|
declare type FlushFailedPurchasesCachedAsPending = () => Promise<boolean>;
|
|
@@ -19,6 +18,7 @@ export interface AmazonModuleProps extends NativeModuleProps {
|
|
|
19
18
|
acknowledgePurchase: AcknowledgePurchase;
|
|
20
19
|
consumeProduct: ConsumeProduct;
|
|
21
20
|
startListening: StartListening;
|
|
21
|
+
verifyLicense: () => Promise<AmazonLicensingStatus>;
|
|
22
22
|
}
|
|
23
23
|
export declare const AmazonModule: AmazonModuleProps;
|
|
24
24
|
/**
|
|
@@ -36,5 +36,9 @@ export declare const validateReceiptAmazon: ({ developerSecret, userId, receiptI
|
|
|
36
36
|
userId: string;
|
|
37
37
|
receiptId: string;
|
|
38
38
|
useSandbox: boolean;
|
|
39
|
-
}) => Promise<
|
|
39
|
+
}) => Promise<ReceiptType>;
|
|
40
|
+
/**
|
|
41
|
+
* Returns the status of verifying app's license @see AmazonLicensingStatus
|
|
42
|
+
*/
|
|
43
|
+
export declare const verifyLicense: () => Promise<AmazonLicensingStatus>;
|
|
40
44
|
export {};
|
|
@@ -29,3 +29,4 @@ export declare type ReceiptType = {
|
|
|
29
29
|
termSku: string;
|
|
30
30
|
testTransaction: boolean;
|
|
31
31
|
} & Record<string, unknown>;
|
|
32
|
+
export declare type AmazonLicensingStatus = 'LICENSED' | 'NOT_LICENSED' | 'EXPIRED' | 'ERROR_VERIFICATION' | 'ERROR_INVALID_LICENSING_KEYS' | 'UNKNOWN_ERROR';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-iap",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "12.0.1",
|
|
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)",
|
package/src/internal/platform.ts
CHANGED
|
@@ -7,6 +7,7 @@ const {RNIapIos, RNIapIosSk2, RNIapModule, RNIapAmazonModule} = NativeModules;
|
|
|
7
7
|
export const isIos = Platform.OS === 'ios';
|
|
8
8
|
export const isAndroid = Platform.OS === 'android';
|
|
9
9
|
export const isAmazon = isAndroid && !!RNIapAmazonModule;
|
|
10
|
+
export const isPlay = isAndroid && !!RNIapModule;
|
|
10
11
|
|
|
11
12
|
// Android
|
|
12
13
|
|
package/src/modules/amazon.ts
CHANGED
|
@@ -2,8 +2,11 @@ import {NativeModules} from 'react-native';
|
|
|
2
2
|
|
|
3
3
|
import {enhancedFetch} from '../internal';
|
|
4
4
|
import type {Product, Purchase, Sku} from '../types';
|
|
5
|
-
import type {
|
|
6
|
-
|
|
5
|
+
import type {
|
|
6
|
+
AmazonLicensingStatus,
|
|
7
|
+
ReceiptType,
|
|
8
|
+
UserDataAmazon,
|
|
9
|
+
} from '../types/amazon';
|
|
7
10
|
|
|
8
11
|
import type {NativeModuleProps} from './common';
|
|
9
12
|
// ----------
|
|
@@ -35,6 +38,7 @@ export interface AmazonModuleProps extends NativeModuleProps {
|
|
|
35
38
|
acknowledgePurchase: AcknowledgePurchase;
|
|
36
39
|
consumeProduct: ConsumeProduct;
|
|
37
40
|
startListening: StartListening;
|
|
41
|
+
verifyLicense: () => Promise<AmazonLicensingStatus>;
|
|
38
42
|
}
|
|
39
43
|
|
|
40
44
|
export const AmazonModule =
|
|
@@ -60,9 +64,15 @@ export const validateReceiptAmazon = async ({
|
|
|
60
64
|
userId: string;
|
|
61
65
|
receiptId: string;
|
|
62
66
|
useSandbox: boolean;
|
|
63
|
-
}): Promise<
|
|
67
|
+
}): Promise<ReceiptType> => {
|
|
64
68
|
const sandBoxUrl = useSandbox ? 'sandbox/' : '';
|
|
65
69
|
const url = `https://appstore-sdk.amazon.com/${sandBoxUrl}version/1.0/verifyReceiptId/developer/${developerSecret}/user/${userId}/receiptId/${receiptId}`;
|
|
66
70
|
|
|
67
|
-
return await enhancedFetch<
|
|
71
|
+
return await enhancedFetch<ReceiptType>(url);
|
|
68
72
|
};
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Returns the status of verifying app's license @see AmazonLicensingStatus
|
|
76
|
+
*/
|
|
77
|
+
export const verifyLicense = async (): Promise<AmazonLicensingStatus> =>
|
|
78
|
+
AmazonModule.verifyLicense();
|
package/src/types/amazon.ts
CHANGED
|
@@ -30,3 +30,11 @@ export type ReceiptType = {
|
|
|
30
30
|
termSku: string;
|
|
31
31
|
testTransaction: boolean;
|
|
32
32
|
} & Record<string, unknown>;
|
|
33
|
+
|
|
34
|
+
export type AmazonLicensingStatus =
|
|
35
|
+
| 'LICENSED'
|
|
36
|
+
| 'NOT_LICENSED'
|
|
37
|
+
| 'EXPIRED'
|
|
38
|
+
| 'ERROR_VERIFICATION'
|
|
39
|
+
| 'ERROR_INVALID_LICENSING_KEYS'
|
|
40
|
+
| 'UNKNOWN_ERROR';
|
|
Binary file
|