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
package/.yarnrc.yml DELETED
@@ -1,3 +0,0 @@
1
- nodeLinker: node-modules
2
-
3
- yarnPath: .yarn/releases/yarn-3.1.1.cjs
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2017-2021 dooboolab
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
package/RNIap.podspec DELETED
@@ -1,18 +0,0 @@
1
- require 'json'
2
- package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
3
-
4
- Pod::Spec.new do |s|
5
- s.name = "RNIap"
6
- s.version = package['version']
7
- s.summary = package['description']
8
- s.homepage = "https://github.com/dooboolab/react-native-iap"
9
- s.license = "MIT"
10
- s.author = package['author']
11
- s.platforms = { :ios => "9.0", :tvos => "9.0" }
12
- s.source = { :git => "https://github.com/dooboolab/react-native-iap.git", :tag => "#{s.version}" }
13
- s.source_files = "ios/*.{h,m,swift}"
14
- s.swift_version = "4.2"
15
- s.requires_arc = true
16
-
17
- s.dependency 'ExpoModulesCore'
18
- end
@@ -1,6 +0,0 @@
1
- #Thu Nov 23 15:00:14 KST 2017
2
- distributionBase=GRADLE_USER_HOME
3
- distributionPath=wrapper/dists
4
- zipStoreBase=GRADLE_USER_HOME
5
- zipStorePath=wrapper/dists
6
- distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-all.zip
@@ -1,2 +0,0 @@
1
- android.useAndroidX=true
2
- android.enableJetifier=true
package/android/gradlew DELETED
@@ -1,160 +0,0 @@
1
- #!/usr/bin/env bash
2
-
3
- ##############################################################################
4
- ##
5
- ## Gradle start up script for UN*X
6
- ##
7
- ##############################################################################
8
-
9
- # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10
- DEFAULT_JVM_OPTS=""
11
-
12
- APP_NAME="Gradle"
13
- APP_BASE_NAME=`basename "$0"`
14
-
15
- # Use the maximum available, or set MAX_FD != -1 to use that value.
16
- MAX_FD="maximum"
17
-
18
- warn ( ) {
19
- echo "$*"
20
- }
21
-
22
- die ( ) {
23
- echo
24
- echo "$*"
25
- echo
26
- exit 1
27
- }
28
-
29
- # OS specific support (must be 'true' or 'false').
30
- cygwin=false
31
- msys=false
32
- darwin=false
33
- case "`uname`" in
34
- CYGWIN* )
35
- cygwin=true
36
- ;;
37
- Darwin* )
38
- darwin=true
39
- ;;
40
- MINGW* )
41
- msys=true
42
- ;;
43
- esac
44
-
45
- # Attempt to set APP_HOME
46
- # Resolve links: $0 may be a link
47
- PRG="$0"
48
- # Need this for relative symlinks.
49
- while [ -h "$PRG" ] ; do
50
- ls=`ls -ld "$PRG"`
51
- link=`expr "$ls" : '.*-> \(.*\)$'`
52
- if expr "$link" : '/.*' > /dev/null; then
53
- PRG="$link"
54
- else
55
- PRG=`dirname "$PRG"`"/$link"
56
- fi
57
- done
58
- SAVED="`pwd`"
59
- cd "`dirname \"$PRG\"`/" >/dev/null
60
- APP_HOME="`pwd -P`"
61
- cd "$SAVED" >/dev/null
62
-
63
- CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64
-
65
- # Determine the Java command to use to start the JVM.
66
- if [ -n "$JAVA_HOME" ] ; then
67
- if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68
- # IBM's JDK on AIX uses strange locations for the executables
69
- JAVACMD="$JAVA_HOME/jre/sh/java"
70
- else
71
- JAVACMD="$JAVA_HOME/bin/java"
72
- fi
73
- if [ ! -x "$JAVACMD" ] ; then
74
- die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75
-
76
- Please set the JAVA_HOME variable in your environment to match the
77
- location of your Java installation."
78
- fi
79
- else
80
- JAVACMD="java"
81
- which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82
-
83
- Please set the JAVA_HOME variable in your environment to match the
84
- location of your Java installation."
85
- fi
86
-
87
- # Increase the maximum file descriptors if we can.
88
- if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89
- MAX_FD_LIMIT=`ulimit -H -n`
90
- if [ $? -eq 0 ] ; then
91
- if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92
- MAX_FD="$MAX_FD_LIMIT"
93
- fi
94
- ulimit -n $MAX_FD
95
- if [ $? -ne 0 ] ; then
96
- warn "Could not set maximum file descriptor limit: $MAX_FD"
97
- fi
98
- else
99
- warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100
- fi
101
- fi
102
-
103
- # For Darwin, add options to specify how the application appears in the dock
104
- if $darwin; then
105
- GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106
- fi
107
-
108
- # For Cygwin, switch paths to Windows format before running java
109
- if $cygwin ; then
110
- APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111
- CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112
- JAVACMD=`cygpath --unix "$JAVACMD"`
113
-
114
- # We build the pattern for arguments to be converted via cygpath
115
- ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116
- SEP=""
117
- for dir in $ROOTDIRSRAW ; do
118
- ROOTDIRS="$ROOTDIRS$SEP$dir"
119
- SEP="|"
120
- done
121
- OURCYGPATTERN="(^($ROOTDIRS))"
122
- # Add a user-defined pattern to the cygpath arguments
123
- if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124
- OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125
- fi
126
- # Now convert the arguments - kludge to limit ourselves to /bin/sh
127
- i=0
128
- for arg in "$@" ; do
129
- CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130
- CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131
-
132
- if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133
- eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134
- else
135
- eval `echo args$i`="\"$arg\""
136
- fi
137
- i=$((i+1))
138
- done
139
- case $i in
140
- (0) set -- ;;
141
- (1) set -- "$args0" ;;
142
- (2) set -- "$args0" "$args1" ;;
143
- (3) set -- "$args0" "$args1" "$args2" ;;
144
- (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145
- (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146
- (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147
- (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148
- (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149
- (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150
- esac
151
- fi
152
-
153
- # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154
- function splitJvmOpts() {
155
- JVM_OPTS=("$@")
156
- }
157
- eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158
- JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159
-
160
- exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
@@ -1,90 +0,0 @@
1
- @if "%DEBUG%" == "" @echo off
2
- @rem ##########################################################################
3
- @rem
4
- @rem Gradle startup script for Windows
5
- @rem
6
- @rem ##########################################################################
7
-
8
- @rem Set local scope for the variables with windows NT shell
9
- if "%OS%"=="Windows_NT" setlocal
10
-
11
- @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12
- set DEFAULT_JVM_OPTS=
13
-
14
- set DIRNAME=%~dp0
15
- if "%DIRNAME%" == "" set DIRNAME=.
16
- set APP_BASE_NAME=%~n0
17
- set APP_HOME=%DIRNAME%
18
-
19
- @rem Find java.exe
20
- if defined JAVA_HOME goto findJavaFromJavaHome
21
-
22
- set JAVA_EXE=java.exe
23
- %JAVA_EXE% -version >NUL 2>&1
24
- if "%ERRORLEVEL%" == "0" goto init
25
-
26
- echo.
27
- echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28
- echo.
29
- echo Please set the JAVA_HOME variable in your environment to match the
30
- echo location of your Java installation.
31
-
32
- goto fail
33
-
34
- :findJavaFromJavaHome
35
- set JAVA_HOME=%JAVA_HOME:"=%
36
- set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37
-
38
- if exist "%JAVA_EXE%" goto init
39
-
40
- echo.
41
- echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42
- echo.
43
- echo Please set the JAVA_HOME variable in your environment to match the
44
- echo location of your Java installation.
45
-
46
- goto fail
47
-
48
- :init
49
- @rem Get command-line arguments, handling Windowz variants
50
-
51
- if not "%OS%" == "Windows_NT" goto win9xME_args
52
- if "%@eval[2+2]" == "4" goto 4NT_args
53
-
54
- :win9xME_args
55
- @rem Slurp the command line arguments.
56
- set CMD_LINE_ARGS=
57
- set _SKIP=2
58
-
59
- :win9xME_args_slurp
60
- if "x%~1" == "x" goto execute
61
-
62
- set CMD_LINE_ARGS=%*
63
- goto execute
64
-
65
- :4NT_args
66
- @rem Get arguments from the 4NT Shell from JP Software
67
- set CMD_LINE_ARGS=%$
68
-
69
- :execute
70
- @rem Setup the command line
71
-
72
- set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73
-
74
- @rem Execute Gradle
75
- "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76
-
77
- :end
78
- @rem End local scope for the variables with windows NT shell
79
- if "%ERRORLEVEL%"=="0" goto mainEnd
80
-
81
- :fail
82
- rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83
- rem the _cmd.exe /c_ return code!
84
- if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85
- exit /b 1
86
-
87
- :mainEnd
88
- if "%OS%"=="Windows_NT" endlocal
89
-
90
- :omega
@@ -1,12 +0,0 @@
1
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
2
- package="com.dooboolab.RNIap">
3
- <application android:exported="true">
4
- <receiver android:name = "com.amazon.device.iap.ResponseReceiver"
5
- android:permission = "com.amazon.inapp.purchasing.Permission.NOTIFY"
6
- android:exported="true">
7
- <intent-filter>
8
- <action android:name = "com.amazon.inapp.purchasing.NOTIFY" />
9
- </intent-filter>
10
- </receiver>
11
- </application>
12
- </manifest>
@@ -1,356 +0,0 @@
1
- package com.dooboolab.RNIap
2
-
3
- import android.util.Log
4
- import com.amazon.device.iap.PurchasingListener
5
- import com.amazon.device.iap.PurchasingService
6
- import com.amazon.device.iap.model.Product
7
- import com.amazon.device.iap.model.ProductDataResponse
8
- import com.amazon.device.iap.model.ProductType
9
- import com.amazon.device.iap.model.PurchaseResponse
10
- import com.amazon.device.iap.model.PurchaseUpdatesResponse
11
- import com.amazon.device.iap.model.Receipt
12
- import com.amazon.device.iap.model.UserData
13
- import com.amazon.device.iap.model.UserDataResponse
14
- import com.facebook.react.bridge.Arguments
15
- import com.facebook.react.bridge.ReactContext
16
- import com.facebook.react.bridge.WritableMap
17
- import com.facebook.react.bridge.WritableNativeArray
18
- import com.facebook.react.bridge.WritableNativeMap
19
- import com.facebook.react.modules.core.DeviceEventManagerModule.RCTDeviceEventEmitter
20
- import java.lang.NumberFormatException
21
- import java.util.ArrayList
22
-
23
- class RNIapAmazonListener(private val reactContext: ReactContext) : PurchasingListener {
24
- val TAG = "RNIapAmazonListener"
25
- private val skus: MutableList<Product>
26
- private var availableItems: WritableNativeArray
27
- private var availableItemsType: String?
28
- fun getPurchaseUpdatesByType(type: String?) {
29
- availableItemsType = type
30
- PurchasingService.getPurchaseUpdates(true)
31
- }
32
-
33
- override fun onProductDataResponse(response: ProductDataResponse) {
34
- val status = response.requestStatus
35
- val requestId = response.requestId.toString()
36
- when (status) {
37
- ProductDataResponse.RequestStatus.SUCCESSFUL -> {
38
- val productData = response.productData
39
- val unavailableSkus = response.unavailableSkus
40
- val items = WritableNativeArray()
41
- for ((_, product) in productData) {
42
- if (!skus.contains(product)) {
43
- skus.add(product)
44
- }
45
- val productType = product.productType
46
- val productTypeString =
47
- if (productType == ProductType.ENTITLED || productType == ProductType.CONSUMABLE) "inapp" else "subs"
48
- var priceNumber: Number = 0.00
49
- val priceString = product.price
50
- try {
51
- if (priceString != null && !priceString.isEmpty()) {
52
- priceNumber = priceString.replace("[^\\d.,]+".toRegex(), "").toDouble()
53
- }
54
- } catch (e: NumberFormatException) {
55
- Log.w(
56
- TAG,
57
- "onProductDataResponse: Failed to parse price for product: " + product.sku
58
- )
59
- }
60
- val item = Arguments.createMap()
61
- val coinsReward = product.coinsReward
62
- item.putString("productId", product.sku)
63
- item.putString("price", priceNumber.toString())
64
- item.putString("type", productTypeString)
65
- item.putString("localizedPrice", priceString)
66
- item.putString("title", product.title)
67
- item.putString("description", product.description)
68
- item.putString("iconUrl", product.smallIconUrl)
69
- item.putString("originalJson", product.toString())
70
- item.putString("originalPrice", priceString)
71
- // item.putString("userMarketplaceAmazon", marketplace);
72
- if (coinsReward != null) {
73
- item.putInt("coinsRewardAmountAmazon", coinsReward.amount)
74
- }
75
- items.pushMap(item)
76
- }
77
- DoobooUtils.instance
78
- .resolvePromisesForKey(
79
- RNIapAmazonModule.Companion.PROMISE_GET_PRODUCT_DATA,
80
- items
81
- )
82
- }
83
- ProductDataResponse.RequestStatus.FAILED ->
84
- DoobooUtils.instance
85
- .rejectPromisesForKey(
86
- RNIapAmazonModule.Companion.PROMISE_GET_PRODUCT_DATA,
87
- E_PRODUCT_DATA_RESPONSE_FAILED,
88
- null,
89
- null
90
- )
91
- ProductDataResponse.RequestStatus.NOT_SUPPORTED ->
92
- DoobooUtils.instance
93
- .rejectPromisesForKey(
94
- RNIapAmazonModule.Companion.PROMISE_GET_PRODUCT_DATA,
95
- E_PRODUCT_DATA_RESPONSE_NOT_SUPPORTED,
96
- null,
97
- null
98
- )
99
- }
100
- }
101
-
102
- override fun onPurchaseUpdatesResponse(response: PurchaseUpdatesResponse) {
103
- // Info for potential error reporting
104
- var debugMessage: String? = null
105
- var errorCode = DoobooUtils.E_UNKNOWN
106
- val error = Arguments.createMap()
107
- val status = response.requestStatus
108
- when (status) {
109
- PurchaseUpdatesResponse.RequestStatus.SUCCESSFUL -> {
110
- val userData = response.userData
111
- var promiseItem: WritableMap? = null
112
- val purchases = response.receipts
113
- for (receipt in purchases) {
114
- val item = receiptToMap(userData, receipt)
115
- promiseItem = WritableNativeMap()
116
- promiseItem.merge(item)
117
- sendEvent(reactContext, "purchase-updated", item)
118
- val productType = receipt.productType
119
- val productTypeString =
120
- if (productType == ProductType.ENTITLED || productType == ProductType.CONSUMABLE) "inapp" else "subs"
121
- if (productTypeString == availableItemsType) {
122
- availableItems.pushMap(promiseItem)
123
- }
124
- }
125
- if (response.hasMore()) {
126
- PurchasingService.getPurchaseUpdates(false)
127
- } else {
128
- if (purchases.size > 0 && promiseItem != null) {
129
- DoobooUtils.instance
130
- .resolvePromisesForKey(
131
- RNIapAmazonModule.Companion.PROMISE_BUY_ITEM,
132
- promiseItem
133
- )
134
- }
135
- DoobooUtils.instance
136
- .resolvePromisesForKey(
137
- RNIapAmazonModule.Companion.PROMISE_QUERY_PURCHASES,
138
- true
139
- )
140
- DoobooUtils.instance
141
- .resolvePromisesForKey(
142
- RNIapAmazonModule.Companion.PROMISE_QUERY_AVAILABLE_ITEMS,
143
- availableItems
144
- )
145
- availableItems = WritableNativeArray()
146
- availableItemsType = null
147
- }
148
- }
149
- PurchaseUpdatesResponse.RequestStatus.FAILED -> {
150
- debugMessage = "An unknown or unexpected error has occured. Please try again later."
151
- errorCode = DoobooUtils.E_UNKNOWN
152
- error.putInt("responseCode", 0)
153
- error.putString("debugMessage", debugMessage)
154
- error.putString("code", errorCode)
155
- error.putString("message", debugMessage)
156
- sendEvent(reactContext, "purchase-error", error)
157
- DoobooUtils.instance
158
- .rejectPromisesForKey(
159
- RNIapAmazonModule.Companion.PROMISE_QUERY_PURCHASES,
160
- errorCode,
161
- debugMessage,
162
- null
163
- )
164
- DoobooUtils.instance
165
- .rejectPromisesForKey(
166
- RNIapAmazonModule.Companion.PROMISE_QUERY_AVAILABLE_ITEMS,
167
- errorCode,
168
- debugMessage,
169
- null
170
- )
171
- availableItems = WritableNativeArray()
172
- availableItemsType = null
173
- }
174
- PurchaseUpdatesResponse.RequestStatus.NOT_SUPPORTED -> {
175
- debugMessage = "This feature is not available on your device."
176
- errorCode = DoobooUtils.E_SERVICE_ERROR
177
- error.putInt("responseCode", 0)
178
- error.putString("debugMessage", debugMessage)
179
- error.putString("code", errorCode)
180
- error.putString("message", debugMessage)
181
- sendEvent(reactContext, "purchase-error", error)
182
- DoobooUtils.instance
183
- .rejectPromisesForKey(
184
- RNIapAmazonModule.Companion.PROMISE_QUERY_PURCHASES,
185
- errorCode,
186
- debugMessage,
187
- null
188
- )
189
- DoobooUtils.instance
190
- .rejectPromisesForKey(
191
- RNIapAmazonModule.Companion.PROMISE_QUERY_AVAILABLE_ITEMS,
192
- errorCode,
193
- debugMessage,
194
- null
195
- )
196
- availableItems = WritableNativeArray()
197
- availableItemsType = null
198
- }
199
- }
200
- }
201
-
202
- private fun receiptToMap(userData: UserData, receipt: Receipt): WritableMap {
203
- val item = Arguments.createMap()
204
- item.putString("productId", receipt.sku)
205
- item.putDouble("transactionDate", receipt.purchaseDate.time.toDouble())
206
- item.putString("purchaseToken", receipt.receiptId)
207
- item.putString("transactionReceipt", receipt.toJSON().toString())
208
- item.putString("userIdAmazon", userData.userId)
209
- item.putString("userMarketplaceAmazon", userData.marketplace)
210
- item.putString("userJsonAmazon", userData.toJSON().toString())
211
- item.putBoolean("isCanceledAmazon", receipt.isCanceled)
212
- return item
213
- }
214
-
215
- override fun onPurchaseResponse(response: PurchaseResponse) {
216
- val requestId = response.requestId.toString()
217
- val userId = response.userData.userId
218
- val status = response.requestStatus
219
-
220
- // Info for potential error reporting
221
- var debugMessage: String? = null
222
- var errorCode = DoobooUtils.E_UNKNOWN
223
- val error = Arguments.createMap()
224
- when (status) {
225
- PurchaseResponse.RequestStatus.SUCCESSFUL -> {
226
- val receipt = response.receipt
227
- val userData = response.userData
228
- val item = receiptToMap(userData, receipt)
229
- val promiseItem: WritableMap = WritableNativeMap()
230
- promiseItem.merge(item)
231
- sendEvent(reactContext, "purchase-updated", item)
232
- DoobooUtils.instance
233
- .resolvePromisesForKey(
234
- RNIapAmazonModule.Companion.PROMISE_BUY_ITEM,
235
- promiseItem
236
- )
237
- }
238
- PurchaseResponse.RequestStatus.ALREADY_PURCHASED -> {
239
- debugMessage = "You already own this item."
240
- errorCode = DoobooUtils.E_ALREADY_OWNED
241
- error.putInt("responseCode", 0)
242
- error.putString("debugMessage", debugMessage)
243
- error.putString("code", errorCode)
244
- error.putString("message", debugMessage)
245
- sendEvent(reactContext, "purchase-error", error)
246
- DoobooUtils.instance
247
- .rejectPromisesForKey(
248
- RNIapAmazonModule.Companion.PROMISE_BUY_ITEM, errorCode, debugMessage, null
249
- )
250
- }
251
- PurchaseResponse.RequestStatus.FAILED -> {
252
- debugMessage =
253
- "An unknown or unexpected error has occurred. Please try again later."
254
- errorCode = DoobooUtils.E_UNKNOWN
255
- error.putInt("responseCode", 0)
256
- error.putString("debugMessage", debugMessage)
257
- error.putString("code", errorCode)
258
- error.putString("message", debugMessage)
259
- sendEvent(reactContext, "purchase-error", error)
260
- DoobooUtils.instance
261
- .rejectPromisesForKey(
262
- RNIapAmazonModule.Companion.PROMISE_BUY_ITEM, errorCode, debugMessage, null
263
- )
264
- }
265
- PurchaseResponse.RequestStatus.INVALID_SKU -> {
266
- debugMessage = "That item is unavailable."
267
- errorCode = DoobooUtils.E_ITEM_UNAVAILABLE
268
- error.putInt("responseCode", 0)
269
- error.putString("debugMessage", debugMessage)
270
- error.putString("code", errorCode)
271
- error.putString("message", debugMessage)
272
- sendEvent(reactContext, "purchase-error", error)
273
- DoobooUtils.instance
274
- .rejectPromisesForKey(
275
- RNIapAmazonModule.Companion.PROMISE_BUY_ITEM, errorCode, debugMessage, null
276
- )
277
- }
278
- PurchaseResponse.RequestStatus.NOT_SUPPORTED -> {
279
- debugMessage = "This feature is not available on your device."
280
- errorCode = DoobooUtils.E_SERVICE_ERROR
281
- error.putInt("responseCode", 0)
282
- error.putString("debugMessage", debugMessage)
283
- error.putString("code", errorCode)
284
- error.putString("message", debugMessage)
285
- sendEvent(reactContext, "purchase-error", error)
286
- DoobooUtils.instance
287
- .rejectPromisesForKey(
288
- RNIapAmazonModule.Companion.PROMISE_BUY_ITEM, errorCode, debugMessage, null
289
- )
290
- }
291
- }
292
- }
293
-
294
- override fun onUserDataResponse(response: UserDataResponse) {
295
- val status = response.requestStatus
296
- when (status) {
297
- UserDataResponse.RequestStatus.SUCCESSFUL -> {
298
- val userData = response.userData
299
- val item = Arguments.createMap()
300
- item.putString("userIdAmazon", userData.userId)
301
- item.putString("userMarketplaceAmazon", userData.marketplace)
302
- item.putString("userJsonAmazon", userData.toJSON().toString())
303
- DoobooUtils.instance
304
- .resolvePromisesForKey(RNIapAmazonModule.Companion.PROMISE_GET_USER_DATA, item)
305
- }
306
- UserDataResponse.RequestStatus.NOT_SUPPORTED ->
307
- DoobooUtils.instance
308
- .rejectPromisesForKey(
309
- RNIapAmazonModule.Companion.PROMISE_GET_USER_DATA,
310
- E_USER_DATA_RESPONSE_NOT_SUPPORTED,
311
- null,
312
- null
313
- )
314
- UserDataResponse.RequestStatus.FAILED ->
315
- DoobooUtils.instance
316
- .rejectPromisesForKey(
317
- RNIapAmazonModule.Companion.PROMISE_GET_USER_DATA,
318
- E_USER_DATA_RESPONSE_FAILED,
319
- null,
320
- null
321
- )
322
- }
323
- }
324
-
325
- private fun sendEvent(
326
- reactContext: ReactContext,
327
- eventName: String,
328
- params: WritableMap?
329
- ) {
330
- reactContext
331
- .getJSModule(RCTDeviceEventEmitter::class.java)
332
- .emit(eventName, params)
333
- }
334
-
335
- companion object {
336
- private const val E_PRODUCT_DATA_RESPONSE_FAILED = "E_PRODUCT_DATA_RESPONSE_FAILED"
337
- private const val E_PRODUCT_DATA_RESPONSE_NOT_SUPPORTED =
338
- "E_PRODUCT_DATA_RESPONSE_NOT_SUPPORTED"
339
- private const val E_PURCHASE_UPDATES_RESPONSE_FAILED = "E_PURCHASE_UPDATES_RESPONSE_FAILED"
340
- private const val E_PURCHASE_UPDATES_RESPONSE_NOT_SUPPORTED =
341
- "E_PURCHASE_UPDATES_RESPONSE_NOT_SUPPORTED"
342
- private const val E_PURCHASE_RESPONSE_FAILED = "E_PURCHASE_RESPONSE_FAILED"
343
- private const val E_PURCHASE_RESPONSE_ALREADY_PURCHASED =
344
- "E_PURCHASE_RESPONSE_ALREADY_PURCHASED"
345
- private const val E_PURCHASE_RESPONSE_NOT_SUPPORTED = "E_PURCHASE_RESPONSE_NOT_SUPPORTED"
346
- private const val E_PURCHASE_RESPONSE_INVALID_SKU = "E_PURCHASE_RESPONSE_INVALID_SKU"
347
- private const val E_USER_DATA_RESPONSE_FAILED = "E_USER_DATA_RESPONSE_FAILED"
348
- private const val E_USER_DATA_RESPONSE_NOT_SUPPORTED = "E_USER_DATA_RESPONSE_NOT_SUPPORTED"
349
- }
350
-
351
- init {
352
- skus = ArrayList()
353
- availableItems = WritableNativeArray()
354
- availableItemsType = null
355
- }
356
- }