react-native-iap 13.0.4 → 14.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 (381) hide show
  1. package/NitroIap.podspec +33 -0
  2. package/README.md +163 -51
  3. package/android/CMakeLists.txt +32 -0
  4. package/android/build.gradle +107 -138
  5. package/android/fix-prefab.gradle +51 -0
  6. package/android/gradle.properties +5 -13
  7. package/android/src/main/AndroidManifest.xml +1 -4
  8. package/android/src/main/cpp/cpp-adapter.cpp +6 -0
  9. package/android/src/main/java/com/margelo/nitro/iap/HybridRnIap.kt +843 -0
  10. package/android/src/main/java/com/margelo/nitro/iap/NitroIapPackage.java +33 -0
  11. package/android/src/main/java/com/margelo/nitro/iap/Types.kt +173 -0
  12. package/ios/Bridge.h +8 -0
  13. package/ios/ErrorUtils.swift +153 -0
  14. package/ios/HybridRnIap.swift +1326 -0
  15. package/ios/ProductStore.swift +33 -0
  16. package/ios/reactnativeiap.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  17. package/ios/reactnativeiap.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
  18. package/lib/module/helpers/subscription.js +56 -0
  19. package/lib/module/helpers/subscription.js.map +1 -0
  20. package/lib/module/hooks/useIAP.js +175 -123
  21. package/lib/module/hooks/useIAP.js.map +1 -1
  22. package/lib/module/index.js +1015 -9
  23. package/lib/module/index.js.map +1 -1
  24. package/lib/module/package.json +1 -0
  25. package/lib/module/specs/RnIap.nitro.js +4 -0
  26. package/lib/{commonjs/modules/common.js.map → module/specs/RnIap.nitro.js.map} +1 -1
  27. package/lib/module/types.js +187 -0
  28. package/lib/module/types.js.map +1 -0
  29. package/lib/module/utils/error.js +80 -0
  30. package/lib/module/utils/error.js.map +1 -0
  31. package/lib/module/utils/type-bridge.js +202 -0
  32. package/lib/module/utils/type-bridge.js.map +1 -0
  33. package/lib/typescript/package.json +1 -0
  34. package/lib/typescript/plugin/src/withIAP.d.ts +2 -7
  35. package/lib/typescript/plugin/src/withIAP.d.ts.map +1 -1
  36. package/lib/typescript/scripts/check-nitro-versions.d.ts +3 -0
  37. package/lib/typescript/scripts/check-nitro-versions.d.ts.map +1 -0
  38. package/lib/typescript/src/helpers/subscription.d.ts +14 -0
  39. package/lib/typescript/src/helpers/subscription.d.ts.map +1 -0
  40. package/lib/typescript/src/hooks/useIAP.d.ts +42 -26
  41. package/lib/typescript/src/hooks/useIAP.d.ts.map +1 -1
  42. package/lib/typescript/src/index.d.ts +356 -8
  43. package/lib/typescript/src/index.d.ts.map +1 -1
  44. package/lib/typescript/src/specs/RnIap.nitro.d.ts +404 -0
  45. package/lib/typescript/src/specs/RnIap.nitro.d.ts.map +1 -0
  46. package/lib/typescript/src/types.d.ts +544 -0
  47. package/lib/typescript/src/types.d.ts.map +1 -0
  48. package/lib/typescript/src/utils/error.d.ts +30 -0
  49. package/lib/typescript/src/utils/error.d.ts.map +1 -0
  50. package/lib/typescript/src/utils/type-bridge.d.ts +40 -0
  51. package/lib/typescript/src/utils/type-bridge.d.ts.map +1 -0
  52. package/nitro.json +17 -0
  53. package/nitrogen/generated/android/NitroIap+autolinking.cmake +80 -0
  54. package/nitrogen/generated/android/NitroIap+autolinking.gradle +27 -0
  55. package/nitrogen/generated/android/NitroIapOnLoad.cpp +50 -0
  56. package/nitrogen/generated/android/NitroIapOnLoad.hpp +25 -0
  57. package/nitrogen/generated/android/c++/JFunc_void_NitroProduct.hpp +78 -0
  58. package/nitrogen/generated/android/c++/JFunc_void_NitroPurchase.hpp +78 -0
  59. package/nitrogen/generated/android/c++/JFunc_void_NitroPurchaseResult.hpp +78 -0
  60. package/nitrogen/generated/android/c++/JHybridRnIapSpec.cpp +577 -0
  61. package/nitrogen/generated/android/c++/JHybridRnIapSpec.hpp +93 -0
  62. package/nitrogen/generated/android/c++/JNitroAndroidReceiptValidationOptions.hpp +66 -0
  63. package/nitrogen/generated/android/c++/JNitroAvailablePurchasesAndroidOptions.hpp +54 -0
  64. package/nitrogen/generated/android/c++/JNitroAvailablePurchasesIosOptions.hpp +65 -0
  65. package/nitrogen/generated/android/c++/JNitroAvailablePurchasesOptions.hpp +62 -0
  66. package/nitrogen/generated/android/c++/JNitroFinishTransactionAndroidParams.hpp +58 -0
  67. package/nitrogen/generated/android/c++/JNitroFinishTransactionIosParams.hpp +53 -0
  68. package/nitrogen/generated/android/c++/JNitroFinishTransactionParams.hpp +62 -0
  69. package/nitrogen/generated/android/c++/JNitroProduct.hpp +154 -0
  70. package/nitrogen/generated/android/c++/JNitroPurchase.hpp +122 -0
  71. package/nitrogen/generated/android/c++/JNitroPurchaseRequest.hpp +66 -0
  72. package/nitrogen/generated/android/c++/JNitroPurchaseResult.hpp +70 -0
  73. package/nitrogen/generated/android/c++/JNitroReceiptValidationParams.hpp +60 -0
  74. package/nitrogen/generated/android/c++/JNitroReceiptValidationResultAndroid.hpp +122 -0
  75. package/nitrogen/generated/android/c++/JNitroReceiptValidationResultIOS.hpp +68 -0
  76. package/nitrogen/generated/android/c++/JNitroRequestPurchaseAndroid.hpp +115 -0
  77. package/nitrogen/generated/android/c++/JNitroRequestPurchaseIos.hpp +84 -0
  78. package/nitrogen/generated/android/c++/JNitroSubscriptionOffer.hpp +57 -0
  79. package/nitrogen/generated/android/c++/JNitroSubscriptionRenewalInfo.hpp +74 -0
  80. package/nitrogen/generated/android/c++/JNitroSubscriptionStatus.hpp +64 -0
  81. package/nitrogen/generated/android/c++/JVariant_Boolean_NitroPurchaseResult.cpp +26 -0
  82. package/nitrogen/generated/android/c++/JVariant_Boolean_NitroPurchaseResult.hpp +71 -0
  83. package/nitrogen/generated/android/c++/JVariant_NitroReceiptValidationResultIOS_NitroReceiptValidationResultAndroid.cpp +26 -0
  84. package/nitrogen/generated/android/c++/JVariant_NitroReceiptValidationResultIOS_NitroReceiptValidationResultAndroid.hpp +75 -0
  85. package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/Func_void_NitroProduct.kt +81 -0
  86. package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/Func_void_NitroPurchase.kt +81 -0
  87. package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/Func_void_NitroPurchaseResult.kt +81 -0
  88. package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/HybridRnIapSpec.kt +198 -0
  89. package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/NitroAndroidReceiptValidationOptions.kt +38 -0
  90. package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/NitroAvailablePurchasesAndroidOptions.kt +29 -0
  91. package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/NitroAvailablePurchasesIosOptions.kt +38 -0
  92. package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/NitroAvailablePurchasesOptions.kt +32 -0
  93. package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/NitroFinishTransactionAndroidParams.kt +32 -0
  94. package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/NitroFinishTransactionIosParams.kt +29 -0
  95. package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/NitroFinishTransactionParams.kt +32 -0
  96. package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/NitroIapOnLoad.kt +35 -0
  97. package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/NitroProduct.kt +104 -0
  98. package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/NitroPurchase.kt +80 -0
  99. package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/NitroPurchaseRequest.kt +32 -0
  100. package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/NitroPurchaseResult.kt +41 -0
  101. package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/NitroReceiptValidationParams.kt +32 -0
  102. package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/NitroReceiptValidationResultAndroid.kt +80 -0
  103. package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/NitroReceiptValidationResultIOS.kt +38 -0
  104. package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/NitroRequestPurchaseAndroid.kt +47 -0
  105. package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/NitroRequestPurchaseIos.kt +41 -0
  106. package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/NitroSubscriptionOffer.kt +32 -0
  107. package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/NitroSubscriptionRenewalInfo.kt +44 -0
  108. package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/NitroSubscriptionStatus.kt +35 -0
  109. package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/Variant_Boolean_NitroPurchaseResult.kt +42 -0
  110. package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/Variant_NitroReceiptValidationResultIOS_NitroReceiptValidationResultAndroid.kt +42 -0
  111. package/nitrogen/generated/ios/NitroIap+autolinking.rb +60 -0
  112. package/nitrogen/generated/ios/NitroIap-Swift-Cxx-Bridge.cpp +152 -0
  113. package/nitrogen/generated/ios/NitroIap-Swift-Cxx-Bridge.hpp +1061 -0
  114. package/nitrogen/generated/ios/NitroIap-Swift-Cxx-Umbrella.hpp +107 -0
  115. package/nitrogen/generated/ios/NitroIapAutolinking.mm +33 -0
  116. package/nitrogen/generated/ios/NitroIapAutolinking.swift +25 -0
  117. package/nitrogen/generated/ios/c++/HybridRnIapSpecSwift.cpp +11 -0
  118. package/nitrogen/generated/ios/c++/HybridRnIapSpecSwift.hpp +355 -0
  119. package/nitrogen/generated/ios/swift/Func_void.swift +47 -0
  120. package/nitrogen/generated/ios/swift/Func_void_NitroProduct.swift +47 -0
  121. package/nitrogen/generated/ios/swift/Func_void_NitroPurchase.swift +47 -0
  122. package/nitrogen/generated/ios/swift/Func_void_NitroPurchaseResult.swift +47 -0
  123. package/nitrogen/generated/ios/swift/Func_void_bool.swift +47 -0
  124. package/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift +47 -0
  125. package/nitrogen/generated/ios/swift/Func_void_std__optional_NitroProduct_.swift +54 -0
  126. package/nitrogen/generated/ios/swift/Func_void_std__optional_NitroPurchase_.swift +54 -0
  127. package/nitrogen/generated/ios/swift/Func_void_std__optional_std__string_.swift +54 -0
  128. package/nitrogen/generated/ios/swift/Func_void_std__optional_std__vector_NitroSubscriptionStatus__.swift +54 -0
  129. package/nitrogen/generated/ios/swift/Func_void_std__string.swift +47 -0
  130. package/nitrogen/generated/ios/swift/Func_void_std__variant_NitroReceiptValidationResultIOS__NitroReceiptValidationResultAndroid_.swift +59 -0
  131. package/nitrogen/generated/ios/swift/Func_void_std__variant_bool__NitroPurchaseResult_.swift +59 -0
  132. package/nitrogen/generated/ios/swift/Func_void_std__vector_NitroProduct_.swift +47 -0
  133. package/nitrogen/generated/ios/swift/Func_void_std__vector_NitroPurchase_.swift +47 -0
  134. package/nitrogen/generated/ios/swift/HybridRnIapSpec.swift +78 -0
  135. package/nitrogen/generated/ios/swift/HybridRnIapSpec_cxx.swift +750 -0
  136. package/nitrogen/generated/ios/swift/NitroAndroidReceiptValidationOptions.swift +80 -0
  137. package/nitrogen/generated/ios/swift/NitroAvailablePurchasesAndroidOptions.swift +54 -0
  138. package/nitrogen/generated/ios/swift/NitroAvailablePurchasesIosOptions.swift +116 -0
  139. package/nitrogen/generated/ios/swift/NitroAvailablePurchasesOptions.swift +84 -0
  140. package/nitrogen/generated/ios/swift/NitroFinishTransactionAndroidParams.swift +58 -0
  141. package/nitrogen/generated/ios/swift/NitroFinishTransactionIosParams.swift +35 -0
  142. package/nitrogen/generated/ios/swift/NitroFinishTransactionParams.swift +84 -0
  143. package/nitrogen/generated/ios/swift/NitroProduct.swift +653 -0
  144. package/nitrogen/generated/ios/swift/NitroPurchase.swift +453 -0
  145. package/nitrogen/generated/ios/swift/NitroPurchaseRequest.swift +84 -0
  146. package/nitrogen/generated/ios/swift/NitroPurchaseResult.swift +117 -0
  147. package/nitrogen/generated/ios/swift/NitroReceiptValidationParams.swift +65 -0
  148. package/nitrogen/generated/ios/swift/NitroReceiptValidationResultAndroid.swift +258 -0
  149. package/nitrogen/generated/ios/swift/NitroReceiptValidationResultIOS.swift +87 -0
  150. package/nitrogen/generated/ios/swift/NitroRequestPurchaseAndroid.swift +225 -0
  151. package/nitrogen/generated/ios/swift/NitroRequestPurchaseIos.swift +161 -0
  152. package/nitrogen/generated/ios/swift/NitroSubscriptionOffer.swift +46 -0
  153. package/nitrogen/generated/ios/swift/NitroSubscriptionRenewalInfo.swift +152 -0
  154. package/nitrogen/generated/ios/swift/NitroSubscriptionStatus.swift +76 -0
  155. package/nitrogen/generated/ios/swift/Variant_Bool_NitroPurchaseResult.swift +18 -0
  156. package/nitrogen/generated/ios/swift/Variant_NitroReceiptValidationResultIOS_NitroReceiptValidationResultAndroid.swift +18 -0
  157. package/nitrogen/generated/shared/c++/HybridRnIapSpec.cpp +50 -0
  158. package/nitrogen/generated/shared/c++/HybridRnIapSpec.hpp +125 -0
  159. package/nitrogen/generated/shared/c++/NitroAndroidReceiptValidationOptions.hpp +80 -0
  160. package/nitrogen/generated/shared/c++/NitroAvailablePurchasesAndroidOptions.hpp +68 -0
  161. package/nitrogen/generated/shared/c++/NitroAvailablePurchasesIosOptions.hpp +79 -0
  162. package/nitrogen/generated/shared/c++/NitroAvailablePurchasesOptions.hpp +76 -0
  163. package/nitrogen/generated/shared/c++/NitroFinishTransactionAndroidParams.hpp +72 -0
  164. package/nitrogen/generated/shared/c++/NitroFinishTransactionIosParams.hpp +67 -0
  165. package/nitrogen/generated/shared/c++/NitroFinishTransactionParams.hpp +76 -0
  166. package/nitrogen/generated/shared/c++/NitroProduct.hpp +168 -0
  167. package/nitrogen/generated/shared/c++/NitroPurchase.hpp +136 -0
  168. package/nitrogen/generated/shared/c++/NitroPurchaseRequest.hpp +76 -0
  169. package/nitrogen/generated/shared/c++/NitroPurchaseResult.hpp +84 -0
  170. package/nitrogen/generated/shared/c++/NitroReceiptValidationParams.hpp +74 -0
  171. package/nitrogen/generated/shared/c++/NitroReceiptValidationResultAndroid.hpp +136 -0
  172. package/nitrogen/generated/shared/c++/NitroReceiptValidationResultIOS.hpp +82 -0
  173. package/nitrogen/generated/shared/c++/NitroRequestPurchaseAndroid.hpp +95 -0
  174. package/nitrogen/generated/shared/c++/NitroRequestPurchaseIos.hpp +85 -0
  175. package/nitrogen/generated/shared/c++/NitroSubscriptionOffer.hpp +71 -0
  176. package/nitrogen/generated/shared/c++/NitroSubscriptionRenewalInfo.hpp +88 -0
  177. package/nitrogen/generated/shared/c++/NitroSubscriptionStatus.hpp +78 -0
  178. package/package.json +145 -104
  179. package/plugin/build/src/withIAP.d.ts +3 -0
  180. package/plugin/build/src/withIAP.js +81 -0
  181. package/plugin/build/tsconfig.tsbuildinfo +1 -0
  182. package/plugin/build/withIAP.d.ts +2 -7
  183. package/plugin/build/withIAP.js +62 -51
  184. package/plugin/src/withIAP.ts +119 -0
  185. package/plugin/tsconfig.json +18 -0
  186. package/plugin/tsconfig.tsbuildinfo +1 -0
  187. package/src/helpers/subscription.ts +65 -0
  188. package/src/hooks/useIAP.ts +361 -222
  189. package/src/index.ts +1194 -9
  190. package/src/specs/RnIap.nitro.ts +501 -0
  191. package/src/types.ts +680 -0
  192. package/src/utils/error.ts +97 -0
  193. package/src/utils/type-bridge.ts +209 -0
  194. package/LICENSE +0 -21
  195. package/RNIap.podspec +0 -36
  196. package/android/src/amazon/AndroidManifest.xml +0 -14
  197. package/android/src/amazon/java/com/dooboolab/rniap/EventSender.kt +0 -10
  198. package/android/src/amazon/java/com/dooboolab/rniap/PurchasingServiceProxy.kt +0 -29
  199. package/android/src/amazon/java/com/dooboolab/rniap/PurchasingServiceProxyAmazonImpl.kt +0 -31
  200. package/android/src/amazon/java/com/dooboolab/rniap/RNIapActivityListener.kt +0 -55
  201. package/android/src/amazon/java/com/dooboolab/rniap/RNIapAmazonListener.kt +0 -325
  202. package/android/src/amazon/java/com/dooboolab/rniap/RNIapAmazonModule.kt +0 -244
  203. package/android/src/amazon/java/com/dooboolab/rniap/RNIapPackage.kt +0 -17
  204. package/android/src/amazon/java/com/dooboolab/rniap/modifysubscription/RNIapAmazonModifySubscriptionListener.kt +0 -88
  205. package/android/src/amazon/java/com/dooboolab/rniap/utils/Extensions.kt +0 -22
  206. package/android/src/main/java/com/dooboolab/rniap/PromiseUtils.kt +0 -62
  207. package/android/src/main/java/com/dooboolab/rniap/PromiseUtlis.kt +0 -43
  208. package/android/src/play/java/com/dooboolab/rniap/PlayUtils.kt +0 -114
  209. package/android/src/play/java/com/dooboolab/rniap/RNIapActivityListener.kt +0 -15
  210. package/android/src/play/java/com/dooboolab/rniap/RNIapModule.kt +0 -911
  211. package/android/src/play/java/com/dooboolab/rniap/RNIapPackage.kt +0 -17
  212. package/android/src/testAmazon/java/com/dooboolab/rniap/RNIapAmazonModuleTest.kt +0 -170
  213. package/app.plugin.js +0 -1
  214. package/ios/IapSerializationUtils.swift +0 -290
  215. package/ios/IapTypes.swift +0 -56
  216. package/ios/IapUtils.swift +0 -40
  217. package/ios/LatestPromiseKeeper.swift +0 -52
  218. package/ios/RNIapIos-Bridging-Header.h +0 -2
  219. package/ios/RNIapIos.m +0 -69
  220. package/ios/RNIapIos.swift +0 -868
  221. package/ios/RNIapIos.xcodeproj/project.pbxproj +0 -289
  222. package/ios/RNIapIosSk2.m +0 -126
  223. package/ios/RNIapIosSk2.swift +0 -1413
  224. package/ios/ThreadSafe.swift +0 -18
  225. package/lib/commonjs/eventEmitter.js +0 -195
  226. package/lib/commonjs/eventEmitter.js.map +0 -1
  227. package/lib/commonjs/hooks/index.js +0 -17
  228. package/lib/commonjs/hooks/index.js.map +0 -1
  229. package/lib/commonjs/hooks/useIAP.js +0 -203
  230. package/lib/commonjs/hooks/useIAP.js.map +0 -1
  231. package/lib/commonjs/hooks/withIAPContext.js +0 -95
  232. package/lib/commonjs/hooks/withIAPContext.js.map +0 -1
  233. package/lib/commonjs/iap.js +0 -836
  234. package/lib/commonjs/iap.js.map +0 -1
  235. package/lib/commonjs/index.js +0 -105
  236. package/lib/commonjs/index.js.map +0 -1
  237. package/lib/commonjs/internal/enhancedFetch.js +0 -26
  238. package/lib/commonjs/internal/enhancedFetch.js.map +0 -1
  239. package/lib/commonjs/internal/fillProductsWithAdditionalData.js +0 -50
  240. package/lib/commonjs/internal/fillProductsWithAdditionalData.js.map +0 -1
  241. package/lib/commonjs/internal/index.js +0 -39
  242. package/lib/commonjs/internal/index.js.map +0 -1
  243. package/lib/commonjs/internal/platform.js +0 -119
  244. package/lib/commonjs/internal/platform.js.map +0 -1
  245. package/lib/commonjs/modules/amazon.js +0 -50
  246. package/lib/commonjs/modules/amazon.js.map +0 -1
  247. package/lib/commonjs/modules/android.js +0 -92
  248. package/lib/commonjs/modules/android.js.map +0 -1
  249. package/lib/commonjs/modules/common.js +0 -2
  250. package/lib/commonjs/modules/index.js +0 -50
  251. package/lib/commonjs/modules/index.js.map +0 -1
  252. package/lib/commonjs/modules/ios.js +0 -160
  253. package/lib/commonjs/modules/ios.js.map +0 -1
  254. package/lib/commonjs/modules/iosSk2.js +0 -113
  255. package/lib/commonjs/modules/iosSk2.js.map +0 -1
  256. package/lib/commonjs/purchaseError.js +0 -170
  257. package/lib/commonjs/purchaseError.js.map +0 -1
  258. package/lib/commonjs/types/amazon.js +0 -2
  259. package/lib/commonjs/types/amazon.js.map +0 -1
  260. package/lib/commonjs/types/android.js +0 -67
  261. package/lib/commonjs/types/android.js.map +0 -1
  262. package/lib/commonjs/types/apple.js +0 -24
  263. package/lib/commonjs/types/apple.js.map +0 -1
  264. package/lib/commonjs/types/appleSk2.js +0 -137
  265. package/lib/commonjs/types/appleSk2.js.map +0 -1
  266. package/lib/commonjs/types/index.js +0 -67
  267. package/lib/commonjs/types/index.js.map +0 -1
  268. package/lib/commonjs/utils/errorMapping.js +0 -83
  269. package/lib/commonjs/utils/errorMapping.js.map +0 -1
  270. package/lib/commonjs/utils/typeGuards.js +0 -74
  271. package/lib/commonjs/utils/typeGuards.js.map +0 -1
  272. package/lib/module/eventEmitter.js +0 -185
  273. package/lib/module/eventEmitter.js.map +0 -1
  274. package/lib/module/hooks/index.js +0 -2
  275. package/lib/module/hooks/index.js.map +0 -1
  276. package/lib/module/hooks/withIAPContext.js +0 -86
  277. package/lib/module/hooks/withIAPContext.js.map +0 -1
  278. package/lib/module/iap.js +0 -805
  279. package/lib/module/iap.js.map +0 -1
  280. package/lib/module/internal/enhancedFetch.js +0 -19
  281. package/lib/module/internal/enhancedFetch.js.map +0 -1
  282. package/lib/module/internal/fillProductsWithAdditionalData.js +0 -43
  283. package/lib/module/internal/fillProductsWithAdditionalData.js.map +0 -1
  284. package/lib/module/internal/index.js +0 -4
  285. package/lib/module/internal/index.js.map +0 -1
  286. package/lib/module/internal/platform.js +0 -102
  287. package/lib/module/internal/platform.js.map +0 -1
  288. package/lib/module/modules/amazon.js +0 -42
  289. package/lib/module/modules/amazon.js.map +0 -1
  290. package/lib/module/modules/android.js +0 -81
  291. package/lib/module/modules/android.js.map +0 -1
  292. package/lib/module/modules/common.js +0 -2
  293. package/lib/module/modules/common.js.map +0 -1
  294. package/lib/module/modules/index.js +0 -5
  295. package/lib/module/modules/index.js.map +0 -1
  296. package/lib/module/modules/ios.js +0 -145
  297. package/lib/module/modules/ios.js.map +0 -1
  298. package/lib/module/modules/iosSk2.js +0 -96
  299. package/lib/module/modules/iosSk2.js.map +0 -1
  300. package/lib/module/purchaseError.js +0 -164
  301. package/lib/module/purchaseError.js.map +0 -1
  302. package/lib/module/types/amazon.js +0 -2
  303. package/lib/module/types/amazon.js.map +0 -1
  304. package/lib/module/types/android.js +0 -63
  305. package/lib/module/types/android.js.map +0 -1
  306. package/lib/module/types/apple.js +0 -17
  307. package/lib/module/types/apple.js.map +0 -1
  308. package/lib/module/types/appleSk2.js +0 -129
  309. package/lib/module/types/appleSk2.js.map +0 -1
  310. package/lib/module/types/index.js +0 -75
  311. package/lib/module/types/index.js.map +0 -1
  312. package/lib/module/utils/errorMapping.js +0 -75
  313. package/lib/module/utils/errorMapping.js.map +0 -1
  314. package/lib/module/utils/typeGuards.js +0 -61
  315. package/lib/module/utils/typeGuards.js.map +0 -1
  316. package/lib/typescript/src/eventEmitter.d.ts +0 -151
  317. package/lib/typescript/src/eventEmitter.d.ts.map +0 -1
  318. package/lib/typescript/src/hooks/index.d.ts +0 -2
  319. package/lib/typescript/src/hooks/index.d.ts.map +0 -1
  320. package/lib/typescript/src/hooks/withIAPContext.d.ts +0 -27
  321. package/lib/typescript/src/hooks/withIAPContext.d.ts.map +0 -1
  322. package/lib/typescript/src/iap.d.ts +0 -503
  323. package/lib/typescript/src/iap.d.ts.map +0 -1
  324. package/lib/typescript/src/internal/enhancedFetch.d.ts +0 -6
  325. package/lib/typescript/src/internal/enhancedFetch.d.ts.map +0 -1
  326. package/lib/typescript/src/internal/fillProductsWithAdditionalData.d.ts +0 -7
  327. package/lib/typescript/src/internal/fillProductsWithAdditionalData.d.ts.map +0 -1
  328. package/lib/typescript/src/internal/index.d.ts +0 -4
  329. package/lib/typescript/src/internal/index.d.ts.map +0 -1
  330. package/lib/typescript/src/internal/platform.d.ts +0 -27
  331. package/lib/typescript/src/internal/platform.d.ts.map +0 -1
  332. package/lib/typescript/src/modules/amazon.d.ts +0 -55
  333. package/lib/typescript/src/modules/amazon.d.ts.map +0 -1
  334. package/lib/typescript/src/modules/android.d.ts +0 -74
  335. package/lib/typescript/src/modules/android.d.ts.map +0 -1
  336. package/lib/typescript/src/modules/common.d.ts +0 -14
  337. package/lib/typescript/src/modules/common.d.ts.map +0 -1
  338. package/lib/typescript/src/modules/index.d.ts +0 -5
  339. package/lib/typescript/src/modules/index.d.ts.map +0 -1
  340. package/lib/typescript/src/modules/ios.d.ts +0 -117
  341. package/lib/typescript/src/modules/ios.d.ts.map +0 -1
  342. package/lib/typescript/src/modules/iosSk2.d.ts +0 -140
  343. package/lib/typescript/src/modules/iosSk2.d.ts.map +0 -1
  344. package/lib/typescript/src/purchaseError.d.ts +0 -133
  345. package/lib/typescript/src/purchaseError.d.ts.map +0 -1
  346. package/lib/typescript/src/types/amazon.d.ts +0 -33
  347. package/lib/typescript/src/types/amazon.d.ts.map +0 -1
  348. package/lib/typescript/src/types/android.d.ts +0 -66
  349. package/lib/typescript/src/types/android.d.ts.map +0 -1
  350. package/lib/typescript/src/types/apple.d.ts +0 -27
  351. package/lib/typescript/src/types/apple.d.ts.map +0 -1
  352. package/lib/typescript/src/types/appleSk2.d.ts +0 -129
  353. package/lib/typescript/src/types/appleSk2.d.ts.map +0 -1
  354. package/lib/typescript/src/types/index.d.ts +0 -302
  355. package/lib/typescript/src/types/index.d.ts.map +0 -1
  356. package/lib/typescript/src/utils/errorMapping.d.ts +0 -29
  357. package/lib/typescript/src/utils/errorMapping.d.ts.map +0 -1
  358. package/lib/typescript/src/utils/typeGuards.d.ts +0 -53
  359. package/lib/typescript/src/utils/typeGuards.d.ts.map +0 -1
  360. package/src/eventEmitter.ts +0 -212
  361. package/src/hooks/index.ts +0 -1
  362. package/src/hooks/withIAPContext.tsx +0 -179
  363. package/src/iap.ts +0 -1046
  364. package/src/internal/enhancedFetch.ts +0 -25
  365. package/src/internal/fillProductsWithAdditionalData.ts +0 -47
  366. package/src/internal/index.ts +0 -3
  367. package/src/internal/platform.ts +0 -135
  368. package/src/modules/amazon.ts +0 -94
  369. package/src/modules/android.ts +0 -179
  370. package/src/modules/common.ts +0 -16
  371. package/src/modules/index.ts +0 -4
  372. package/src/modules/ios.ts +0 -229
  373. package/src/modules/iosSk2.ts +0 -194
  374. package/src/purchaseError.ts +0 -196
  375. package/src/types/amazon.ts +0 -40
  376. package/src/types/android.ts +0 -89
  377. package/src/types/apple.ts +0 -44
  378. package/src/types/appleSk2.ts +0 -275
  379. package/src/types/index.ts +0 -379
  380. package/src/utils/errorMapping.ts +0 -88
  381. package/src/utils/typeGuards.ts +0 -90
package/src/iap.ts DELETED
@@ -1,1046 +0,0 @@
1
- import {NativeModules, Platform} from 'react-native';
2
-
3
- import * as IapAmazon from './modules/amazon';
4
- import * as IapAndroid from './modules/android';
5
- import * as IapIos from './modules/ios';
6
- import * as IapIosSk2 from './modules/iosSk2';
7
- import {singleProductAndroidMap} from './types/android';
8
- import {offerToRecord} from './types/apple';
9
- import {
10
- offerSk2Map,
11
- ProductSk2,
12
- productSk2Map,
13
- subscriptionSk2Map,
14
- transactionSk2ToPurchaseMap,
15
- } from './types/appleSk2';
16
- import {
17
- fillProductsWithAdditionalData,
18
- getAndroidModule,
19
- getAndroidModuleType,
20
- getIosModule,
21
- getNativeModule,
22
- isAmazon,
23
- isIosStorekit2,
24
- storekit1Mode,
25
- storekit2Mode,
26
- storekitHybridMode,
27
- } from './internal';
28
- import {
29
- Product,
30
- ProductPurchase,
31
- ProductType,
32
- ProrationModesAmazon,
33
- Purchase,
34
- PurchaseResult,
35
- PurchaseStateAndroid,
36
- RequestPurchase,
37
- RequestSubscription,
38
- Subscription,
39
- SubscriptionAmazon,
40
- SubscriptionAndroid,
41
- SubscriptionIOS,
42
- SubscriptionPlatform,
43
- SubscriptionPurchase,
44
- } from './types';
45
-
46
- export {IapAndroid, IapAmazon, IapIos, IapIosSk2, isIosStorekit2};
47
-
48
- const {RNIapIos, RNIapIosSk2, RNIapModule, RNIapAmazonModule} = NativeModules;
49
- const ANDROID_ITEM_TYPE_SUBSCRIPTION = ProductType.subs;
50
- const ANDROID_ITEM_TYPE_IAP = ProductType.inapp;
51
-
52
- /**
53
- * STOREKIT1_MODE: Will not enable Storekit 2 even if the device supports it. Thigs will work as before,
54
- * minimum changes required in the migration guide (default)
55
- * HYBRID_MODE: Will enable Storekit 2 for iOS devices > 15.0 but will fallback to Sk1 on older devices
56
- * There are some edge cases that you need to handle in this case (described in migration guide). This mode
57
- * is for developers that are migrating to Storekit 2 but want to keep supporting older versions.
58
- * STOREKIT2_MODE: Will *only* enable Storekit 2. This disables Storekit 1. This is for apps that
59
- * have already targeted a min version of 15 for their app.
60
- */
61
- export type STOREKIT_OPTIONS =
62
- | 'STOREKIT1_MODE'
63
- | 'STOREKIT_HYBRID_MODE'
64
- | 'STOREKIT2_MODE';
65
-
66
- export const setup = ({
67
- storekitMode = 'STOREKIT1_MODE',
68
- }: {
69
- storekitMode?: STOREKIT_OPTIONS;
70
- } = {}) => {
71
- switch (storekitMode) {
72
- case 'STOREKIT1_MODE':
73
- storekit1Mode();
74
- break;
75
- case 'STOREKIT2_MODE':
76
- storekit2Mode();
77
- break;
78
- case 'STOREKIT_HYBRID_MODE':
79
- storekitHybridMode();
80
- break;
81
- default:
82
- break;
83
- }
84
- };
85
-
86
- /**
87
- * Init module for purchase flow. Required on Android. In ios it will check whether user canMakePayment.
88
- * ## Usage
89
-
90
- ```tsx
91
- import React, {useEffect} from 'react';
92
- import {View} from 'react-native';
93
- import {initConnection} from 'react-native-iap';
94
-
95
- const App = () => {
96
- useEffect(() => {
97
- void initConnection();
98
- }, []);
99
-
100
- return <View />;
101
- };
102
- ```
103
- */
104
- export const initConnection = (): Promise<boolean> =>
105
- getNativeModule().initConnection();
106
-
107
- /**
108
- * Disconnects from native SDK
109
- * Usage
110
- * ```tsx
111
- import React, {useEffect} from 'react';
112
- import {View} from 'react-native';
113
- import {endConnection} from 'react-native-iap';
114
-
115
- const App = () => {
116
- useEffect(() => {
117
- return () => {
118
- void endConnection();
119
- };
120
- }, []);
121
-
122
- return <View />;
123
- };
124
- ```
125
- * @returns {Promise<void>}
126
- */
127
- export const endConnection = (): Promise<boolean> =>
128
- getNativeModule().endConnection();
129
-
130
- /**
131
- * Consume all 'ghost' purchases (that is, pending payment that already failed but is still marked as pending in Play Store cache). Android only.
132
- * @returns {Promise<boolean>}
133
- */
134
- export const flushFailedPurchasesCachedAsPendingAndroid =
135
- (): Promise<boolean> =>
136
- getAndroidModule().flushFailedPurchasesCachedAsPending();
137
-
138
- /**
139
- * Get a list of products (consumable and non-consumable items, but not subscriptions)
140
- ## Usage
141
-
142
- ```ts
143
- import React, {useState} from 'react';
144
- import {Platform} from 'react-native';
145
- import {getProducts, Product} from 'react-native-iap';
146
-
147
- const skus = Platform.select({
148
- ios: ['com.example.consumableIos'],
149
- android: ['com.example.consumableAndroid'],
150
- });
151
-
152
- const App = () => {
153
- const [products, setProducts] = useState<Product[]>([]);
154
-
155
- const handleProducts = async () => {
156
- const items = await getProducts({skus});
157
-
158
- setProducts(items);
159
- };
160
-
161
- useEffect(() => {
162
- void handleProducts();
163
- }, []);
164
-
165
- return (
166
- <>
167
- {products.map((product) => (
168
- <Text key={product.productId}>{product.productId}</Text>
169
- ))}
170
- </>
171
- );
172
- };
173
- ```
174
-
175
- Just a few things to keep in mind:
176
-
177
- - You can get your products in `componentDidMount`, `useEffect` or another appropriate area of your app.
178
- - Since a user may start your app with a bad or no internet connection, preparing/getting the items more than once may be a good idea.
179
- - If the user has no IAPs available when the app starts first, you may want to check again when the user enters your IAP store.
180
-
181
- */
182
- export const getProducts = ({
183
- skus,
184
- }: {
185
- skus: string[];
186
- }): Promise<Array<Product>> => {
187
- if (!skus?.length) {
188
- return Promise.reject('"skus" is required');
189
- }
190
- return (
191
- Platform.select({
192
- ios: async () => {
193
- let items: Product[];
194
- if (isIosStorekit2()) {
195
- items = ((await RNIapIosSk2.getItems(skus)) as ProductSk2[]).map(
196
- productSk2Map,
197
- );
198
- } else {
199
- items = (await RNIapIos.getItems(skus)) as Product[];
200
- }
201
- return items.filter((item: Product) => skus.includes(item.productId));
202
- },
203
- android: async () => {
204
- const products = (
205
- await getAndroidModule().getItemsByType(ANDROID_ITEM_TYPE_IAP, skus)
206
- ).map(singleProductAndroidMap);
207
-
208
- return fillProductsWithAdditionalData(products);
209
- },
210
- }) || (() => Promise.reject(new Error('Unsupported Platform')))
211
- )();
212
- };
213
-
214
- /**
215
- * Get a list of subscriptions
216
- * ## Usage
217
-
218
- ```tsx
219
- import React, {useCallback} from 'react';
220
- import {View} from 'react-native';
221
- import {getSubscriptions} from 'react-native-iap';
222
-
223
- const App = () => {
224
- const subscriptions = useCallback(
225
- async () =>
226
- await getSubscriptions({skus:['com.example.product1', 'com.example.product2']}),
227
- [],
228
- );
229
-
230
- return <View />;
231
- };
232
- ```
233
-
234
- */
235
- export const getSubscriptions = ({
236
- skus,
237
- }: {
238
- skus: string[];
239
- }): Promise<Subscription[]> => {
240
- if (!skus?.length) {
241
- return Promise.reject('"skus" is required');
242
- }
243
- return (
244
- Platform.select({
245
- ios: async (): Promise<SubscriptionIOS[]> => {
246
- let items: SubscriptionIOS[];
247
- if (isIosStorekit2()) {
248
- items = ((await RNIapIosSk2.getItems(skus)) as ProductSk2[]).map(
249
- subscriptionSk2Map,
250
- );
251
- } else {
252
- items = (await RNIapIos.getItems(skus)) as SubscriptionIOS[];
253
- }
254
-
255
- items = items.filter((item: SubscriptionIOS) =>
256
- skus.includes(item.productId),
257
- );
258
-
259
- return addSubscriptionPlatform(items, SubscriptionPlatform.ios);
260
- },
261
- android: async (): Promise<Subscription[]> => {
262
- const androidPlatform = getAndroidModuleType();
263
-
264
- let subscriptions = (await getAndroidModule().getItemsByType(
265
- ANDROID_ITEM_TYPE_SUBSCRIPTION,
266
- skus,
267
- )) as SubscriptionAndroid[] | SubscriptionAmazon[];
268
-
269
- switch (androidPlatform) {
270
- case 'android': {
271
- const castSubscriptions = subscriptions as SubscriptionAndroid[];
272
- return addSubscriptionPlatform(
273
- castSubscriptions,
274
- SubscriptionPlatform.android,
275
- );
276
- }
277
- case 'amazon':
278
- let castSubscriptions = subscriptions as SubscriptionAmazon[];
279
- castSubscriptions = await fillProductsWithAdditionalData(
280
- castSubscriptions,
281
- );
282
- return addSubscriptionPlatform(
283
- castSubscriptions,
284
- SubscriptionPlatform.amazon,
285
- );
286
- case null:
287
- default:
288
- throw new Error(
289
- `getSubscriptions received unknown platform ${androidPlatform}. Verify the logic in getAndroidModuleType`,
290
- );
291
- }
292
- },
293
- }) || (() => Promise.reject(new Error('Unsupported Platform')))
294
- )();
295
- };
296
-
297
- /**
298
- * Adds an extra property to subscriptions so we can distinguish the platform
299
- * we retrieved them on.
300
- */
301
- const addSubscriptionPlatform = <T>(
302
- subscriptions: T[],
303
- platform: SubscriptionPlatform,
304
- ): T[] => {
305
- return subscriptions.map((subscription) => ({...subscription, platform}));
306
- };
307
-
308
- /**
309
- * Gets an inventory of purchases made by the user regardless of consumption status
310
- * ## Usage
311
-
312
- ```tsx
313
- import React, {useCallback} from 'react';
314
- import {View} from 'react-native';
315
- import {getPurchaseHistory} from 'react-native-iap';
316
-
317
- const App = () => {
318
- const history = useCallback(
319
- async () =>
320
- await getPurchaseHistory([
321
- 'com.example.product1',
322
- 'com.example.product2',
323
- ]),
324
- [],
325
- );
326
-
327
- return <View />;
328
- };
329
- ```
330
- @param {alsoPublishToEventListener}:boolean. (IOS Sk2 only) When `true`, every element will also be pushed to the purchaseUpdated listener.
331
- Note that this is only for backaward compatiblity. It won't publish to transactionUpdated (Storekit2) Defaults to `false`
332
- @param {automaticallyFinishRestoredTransactions}:boolean. (IOS Sk1 only) When `true`, all the transactions that are returned are automatically
333
- finished. This means that if you call this method again you won't get the same result on the same device. On the other hand, if `false` you'd
334
- have to manually finish the returned transaction once you have delivered the content to your user.
335
- @param {onlyIncludeActiveItems}:boolean. (IOS Sk2 only). Defaults to false, meaning that it will return one transaction per item purchased.
336
- @See https://developer.apple.com/documentation/storekit/transaction/3851204-currententitlements for details
337
- */
338
- export const getPurchaseHistory = ({
339
- alsoPublishToEventListener = false,
340
- automaticallyFinishRestoredTransactions = true,
341
- onlyIncludeActiveItems = false,
342
- }: {
343
- alsoPublishToEventListener?: boolean;
344
- automaticallyFinishRestoredTransactions?: boolean;
345
- onlyIncludeActiveItems?: boolean;
346
- } = {}): Promise<Purchase[]> =>
347
- (
348
- Platform.select({
349
- ios: async () => {
350
- if (isIosStorekit2()) {
351
- return Promise.resolve(
352
- (
353
- await RNIapIosSk2.getAvailableItems(
354
- alsoPublishToEventListener,
355
- onlyIncludeActiveItems,
356
- )
357
- ).map(transactionSk2ToPurchaseMap),
358
- );
359
- } else {
360
- return RNIapIos.getAvailableItems(
361
- automaticallyFinishRestoredTransactions,
362
- );
363
- }
364
- },
365
- android: async () => {
366
- if (RNIapAmazonModule) {
367
- return await RNIapAmazonModule.getAvailableItems();
368
- }
369
-
370
- // getPurchaseHistoryByType was removed in Google Play Billing Library v8
371
- // Android doesn't provide purchase history anymore, only active purchases
372
- console.warn(
373
- 'getPurchaseHistory is not supported on Android with Google Play Billing Library v8. Use getAvailablePurchases instead to get active purchases.',
374
- );
375
- return [];
376
- },
377
- }) || (() => Promise.resolve([]))
378
- )();
379
-
380
- /**
381
- * Get all purchases made by the user (either non-consumable, or haven't been consumed yet)
382
- * ## Usage
383
-
384
- ```tsx
385
- import React, {useCallback} from 'react';
386
- import {View} from 'react-native';
387
- import {getAvailablePurchases} from 'react-native-iap';
388
-
389
- const App = () => {
390
- const availablePurchases = useCallback(
391
- async () => await getAvailablePurchases(),
392
- [],
393
- );
394
-
395
- return <View />;
396
- };
397
- ```
398
-
399
- ## Restoring purchases
400
-
401
- You can use `getAvailablePurchases()` to do what's commonly understood as "restoring" purchases.
402
-
403
- :::note
404
- For debugging you may want to consume all items, you have then to iterate over the purchases returned by `getAvailablePurchases()`.
405
- :::
406
-
407
- :::warning
408
- Beware that if you consume an item without having recorded the purchase in your database the user may have paid for something without getting it delivered and you will have no way to recover the receipt to validate and restore their purchase.
409
- :::
410
-
411
- ```tsx
412
- import React from 'react';
413
- import {Button} from 'react-native';
414
- import {getAvailablePurchases,finishTransaction} from 'react-native-iap';
415
-
416
- const App = () => {
417
- handleRestore = async () => {
418
- try {
419
- const purchases = await getAvailablePurchases();
420
- const newState = {premium: false, ads: true};
421
- let titles = [];
422
-
423
- await Promise.all(purchases.map(async purchase => {
424
- switch (purchase.productId) {
425
- case 'com.example.premium':
426
- newState.premium = true;
427
- titles.push('Premium Version');
428
- break;
429
-
430
- case 'com.example.no_ads':
431
- newState.ads = false;
432
- titles.push('No Ads');
433
- break;
434
-
435
- case 'com.example.coins100':
436
- await finishTransaction({purchase});
437
- CoinStore.addCoins(100);
438
- }
439
- }));
440
-
441
- Alert.alert(
442
- 'Restore Successful',
443
- `You successfully restored the following purchases: ${titles.join(', ')}`,
444
- );
445
- } catch (error) {
446
- console.warn(error);
447
- Alert.alert(error.message);
448
- }
449
- };
450
-
451
- return (
452
- <Button title="Restore purchases" onPress={handleRestore} />
453
- )
454
- };
455
- ```
456
- @param {alsoPublishToEventListener}:boolean When `true`, every element will also be pushed to the purchaseUpdated listener.
457
- Note that this is only for backaward compatiblity. It won't publish to transactionUpdated (Storekit2) Defaults to `false`
458
- @param {onlyIncludeActiveItems}:boolean. (IOS Sk2 only). Defaults to true, meaning that it will return the transaction if suscription has not expired.
459
- @See https://developer.apple.com/documentation/storekit/transaction/3851204-currententitlements for details
460
- *
461
- */
462
- export const getAvailablePurchases = ({
463
- alsoPublishToEventListener = false,
464
- automaticallyFinishRestoredTransactions = false,
465
- onlyIncludeActiveItems = true,
466
- }: {
467
- alsoPublishToEventListener?: boolean;
468
- automaticallyFinishRestoredTransactions?: boolean;
469
- onlyIncludeActiveItems?: boolean;
470
- } = {}): Promise<Purchase[]> =>
471
- (
472
- Platform.select({
473
- ios: async () => {
474
- if (isIosStorekit2()) {
475
- return Promise.resolve(
476
- (
477
- await RNIapIosSk2.getAvailableItems(
478
- alsoPublishToEventListener,
479
- onlyIncludeActiveItems,
480
- )
481
- ).map(transactionSk2ToPurchaseMap),
482
- );
483
- } else {
484
- return RNIapIos.getAvailableItems(
485
- automaticallyFinishRestoredTransactions,
486
- );
487
- }
488
- },
489
- android: async () => {
490
- if (RNIapAmazonModule) {
491
- return await RNIapAmazonModule.getAvailableItems();
492
- }
493
-
494
- // Use the new getAvailableItems method if available
495
- if (RNIapModule.getAvailableItems) {
496
- try {
497
- return await RNIapModule.getAvailableItems();
498
- } catch (error) {
499
- console.warn(
500
- 'getAvailableItems failed, falling back to getAvailableItemsByType',
501
- error,
502
- );
503
- // Fall through to the old method
504
- }
505
- }
506
-
507
- // Fallback to the old method for backward compatibility
508
- // Use Promise.all with timeout to avoid hanging
509
- const timeout = 10000; // 10 seconds timeout
510
- const timeoutPromise = new Promise<never>((_, reject) =>
511
- setTimeout(
512
- () => reject(new Error('getAvailablePurchases timeout')),
513
- timeout,
514
- ),
515
- );
516
-
517
- try {
518
- const [products, subscriptions] = await Promise.race([
519
- Promise.all([
520
- RNIapModule.getAvailableItemsByType(ANDROID_ITEM_TYPE_IAP).catch(
521
- () => [] as Purchase[],
522
- ),
523
- RNIapModule.getAvailableItemsByType(
524
- ANDROID_ITEM_TYPE_SUBSCRIPTION,
525
- ).catch(() => [] as Purchase[]),
526
- ]),
527
- timeoutPromise,
528
- ]);
529
-
530
- return products.concat(subscriptions);
531
- } catch (error) {
532
- console.error('getAvailablePurchases error:', error);
533
- return [];
534
- }
535
- },
536
- }) || (() => Promise.resolve([]))
537
- )();
538
-
539
- /**
540
- * Request a purchase for product. This will be received in `PurchaseUpdatedListener`.
541
- * Request a purchase for a product (consumables or non-consumables).
542
-
543
- The response will be received through the `PurchaseUpdatedListener`.
544
-
545
- :::note
546
- `andDangerouslyFinishTransactionAutomatically` defaults to false. We recommend
547
- always keeping at false, and verifying the transaction receipts on the server-side.
548
- :::
549
-
550
- ## Signature
551
-
552
- ```ts
553
- requestPurchase(
554
- The product's sku/ID
555
- sku,
556
-
557
-
558
- * You should set this to false and call finishTransaction manually when you have delivered the purchased goods to the user.
559
- * @default false
560
-
561
- andDangerouslyFinishTransactionAutomaticallyIOS = false,
562
-
563
- /** Specifies an optional obfuscated string that is uniquely associated with the user's account in your app.
564
- obfuscatedAccountIdAndroid,
565
-
566
- Specifies an optional obfuscated string that is uniquely associated with the user's profile in your app.
567
- obfuscatedProfileIdAndroid,
568
-
569
- The purchaser's user ID
570
- applicationUsername,
571
- ): Promise<ProductPurchase>;
572
- ```
573
-
574
- ## Usage
575
-
576
- ```tsx
577
- import React, { useState, useEffect } from 'react';
578
- import {Button} from 'react-native';
579
- import {requestPurchase, Product, Sku, getProducts} from 'react-native-iap';
580
-
581
- const App = () => {
582
- const [products, setProducts] = useState<Product[]>([]);
583
-
584
- useEffect(() => {
585
- const fetchProducts = async () => {
586
- const productList = await getProducts({skus:['com.example.product']});
587
- setProducts(productList);
588
- }
589
-
590
- fetchProducts();
591
- }, []);
592
-
593
- const handlePurchase = async (sku: Sku) => {
594
- await requestPurchase({sku});
595
- };
596
-
597
- return (
598
- <>
599
- {products.map((product) => (
600
- <Button
601
- key={product.productId}
602
- title="Buy product"
603
- onPress={() => handlePurchase(product.productId)}
604
- />
605
- ))}
606
- </>
607
- );
608
- };
609
- ```
610
-
611
- */
612
-
613
- export const requestPurchase = (
614
- request: RequestPurchase,
615
- ): Promise<ProductPurchase | ProductPurchase[] | void> =>
616
- (
617
- Platform.select({
618
- ios: async () => {
619
- if (!('sku' in request)) {
620
- throw new Error('sku is required for iOS purchase');
621
- }
622
-
623
- const {
624
- sku,
625
- andDangerouslyFinishTransactionAutomaticallyIOS = false,
626
- appAccountToken,
627
- quantity,
628
- withOffer,
629
- } = request;
630
-
631
- if (andDangerouslyFinishTransactionAutomaticallyIOS) {
632
- console.warn(
633
- 'You are dangerously allowing react-native-iap to finish your transaction automatically. You should set andDangerouslyFinishTransactionAutomatically to false when calling requestPurchase and call finishTransaction manually when you have delivered the purchased goods to the user. It defaults to true to provide backwards compatibility. Will default to false in version 4.0.0.',
634
- );
635
- }
636
- if (isIosStorekit2()) {
637
- const offer = offerSk2Map(withOffer);
638
-
639
- const purchase = transactionSk2ToPurchaseMap(
640
- await RNIapIosSk2.buyProduct(
641
- sku,
642
- andDangerouslyFinishTransactionAutomaticallyIOS,
643
- appAccountToken,
644
- quantity ?? -1,
645
- offer,
646
- ),
647
- );
648
- return Promise.resolve(purchase);
649
- } else {
650
- return RNIapIos.buyProduct(
651
- sku,
652
- andDangerouslyFinishTransactionAutomaticallyIOS,
653
- appAccountToken,
654
- quantity ?? -1,
655
- offerToRecord(withOffer),
656
- );
657
- }
658
- },
659
- android: async () => {
660
- if (isAmazon) {
661
- if (!('sku' in request)) {
662
- throw new Error('sku is required for Amazon purchase');
663
- }
664
- const {sku} = request;
665
- return RNIapAmazonModule.buyItemByType(sku, '');
666
- } else {
667
- if (!('skus' in request) || !request.skus.length) {
668
- throw new Error('skus is required for Android purchase');
669
- }
670
-
671
- const {
672
- skus,
673
- obfuscatedAccountIdAndroid,
674
- obfuscatedProfileIdAndroid,
675
- isOfferPersonalized,
676
- } = request;
677
- return RNIapModule.buyItemByType(
678
- ANDROID_ITEM_TYPE_IAP,
679
- skus,
680
- undefined,
681
- -1,
682
- obfuscatedAccountIdAndroid,
683
- obfuscatedProfileIdAndroid,
684
- [],
685
- isOfferPersonalized ?? false,
686
- );
687
- }
688
- },
689
- }) || Promise.resolve
690
- )();
691
-
692
- /**
693
- * Request a purchase for product. This will be received in `PurchaseUpdatedListener`.
694
- * Request a purchase for a subscription.
695
-
696
- The response will be received through the `PurchaseUpdatedListener`.
697
-
698
- :::note
699
- `andDangerouslyFinishTransactionAutomatically` defaults to false. We recommend
700
- always keeping at false, and verifying the transaction receipts on the server-side.
701
- :::
702
-
703
- ## Signature
704
-
705
- ```ts
706
- requestSubscription(
707
- The product's sku/ID
708
- sku,
709
-
710
-
711
- * You should set this to false and call finishTransaction manually when you have delivered the purchased goods to the user.
712
- * @default false
713
-
714
- andDangerouslyFinishTransactionAutomaticallyIOS = false,
715
-
716
- purchaseToken that the user is upgrading or downgrading from (Android).
717
- purchaseTokenAndroid,
718
-
719
- UNKNOWN_SUBSCRIPTION_UPGRADE_DOWNGRADE_POLICY, IMMEDIATE_WITH_TIME_PRORATION, IMMEDIATE_AND_CHARGE_PRORATED_PRICE, IMMEDIATE_WITHOUT_PRORATION, DEFERRED
720
- prorationModeAndroid = -1,
721
-
722
- /** Specifies an optional obfuscated string that is uniquely associated with the user's account in your app.
723
- obfuscatedAccountIdAndroid,
724
-
725
- Specifies an optional obfuscated string that is uniquely associated with the user's profile in your app.
726
- obfuscatedProfileIdAndroid,
727
-
728
- The purchaser's user ID
729
- applicationUsername,
730
- ): Promise<SubscriptionPurchase>
731
- ```
732
-
733
- ## Usage
734
-
735
- ```tsx
736
- import React, {useCallback} from 'react';
737
- import {Button} from 'react-native';
738
- import {
739
- requestSubscription,
740
- Product,
741
- Sku,
742
- getSubscriptions,
743
- } from 'react-native-iap';
744
-
745
- const App = () => {
746
- const subscriptions = useCallback(
747
- async () => getSubscriptions(['com.example.subscription']),
748
- [],
749
- );
750
-
751
- const handlePurchase = async (sku: Sku) => {
752
- await requestSubscription({sku});
753
- };
754
-
755
- return (
756
- <>
757
- {subscriptions.map((subscription) => (
758
- <Button
759
- key={subscription.productId}
760
- title="Buy subscription"
761
- onPress={() => handlePurchase(subscription.productId)}
762
- />
763
- ))}
764
- </>
765
- );
766
- };
767
- ```
768
- */
769
- export const requestSubscription = (
770
- request: RequestSubscription,
771
- ): Promise<SubscriptionPurchase | SubscriptionPurchase[] | null | void> =>
772
- (
773
- Platform.select({
774
- ios: async () => {
775
- if (!('sku' in request)) {
776
- throw new Error('sku is required for iOS subscriptions');
777
- }
778
-
779
- const {
780
- sku,
781
- andDangerouslyFinishTransactionAutomaticallyIOS = false,
782
- appAccountToken,
783
- quantity,
784
- withOffer,
785
- } = request;
786
-
787
- if (andDangerouslyFinishTransactionAutomaticallyIOS) {
788
- console.warn(
789
- 'You are dangerously allowing react-native-iap to finish your transaction automatically. You should set andDangerouslyFinishTransactionAutomatically to false when calling requestPurchase and call finishTransaction manually when you have delivered the purchased goods to the user. It defaults to true to provide backwards compatibility. Will default to false in version 4.0.0.',
790
- );
791
- }
792
-
793
- if (isIosStorekit2()) {
794
- const offer = offerSk2Map(withOffer);
795
-
796
- const purchase = transactionSk2ToPurchaseMap(
797
- await RNIapIosSk2.buyProduct(
798
- sku,
799
- andDangerouslyFinishTransactionAutomaticallyIOS,
800
- appAccountToken,
801
- quantity ?? -1,
802
- offer,
803
- ),
804
- );
805
- return Promise.resolve(purchase);
806
- } else {
807
- return RNIapIos.buyProduct(
808
- sku,
809
- andDangerouslyFinishTransactionAutomaticallyIOS,
810
- appAccountToken,
811
- quantity ?? -1,
812
- offerToRecord(withOffer),
813
- );
814
- }
815
- },
816
- android: async () => {
817
- if (isAmazon) {
818
- if (!('sku' in request)) {
819
- throw new Error('sku is required for Amazon subscriptions');
820
- }
821
- const {sku} = request;
822
- var prorationModeAmazon: ProrationModesAmazon = '';
823
- if ('prorationModeAmazon' in request) {
824
- prorationModeAmazon = request.prorationModeAmazon || '';
825
- }
826
- return RNIapAmazonModule.buyItemByType(sku, prorationModeAmazon);
827
- } else {
828
- if (
829
- !('subscriptionOffers' in request) ||
830
- request.subscriptionOffers.length === 0
831
- ) {
832
- throw new Error(
833
- 'subscriptionOffers are required for Google Play subscriptions',
834
- );
835
- }
836
-
837
- const {
838
- subscriptionOffers,
839
- purchaseTokenAndroid,
840
- replacementModeAndroid = -1,
841
- obfuscatedAccountIdAndroid,
842
- obfuscatedProfileIdAndroid,
843
- isOfferPersonalized,
844
- } = request;
845
-
846
- return RNIapModule.buyItemByType(
847
- ANDROID_ITEM_TYPE_SUBSCRIPTION,
848
- subscriptionOffers?.map((so) => so.sku),
849
- purchaseTokenAndroid,
850
- replacementModeAndroid,
851
- obfuscatedAccountIdAndroid,
852
- obfuscatedProfileIdAndroid,
853
- subscriptionOffers?.map((so) => so.offerToken),
854
- isOfferPersonalized ?? false,
855
- );
856
- }
857
- },
858
- }) || (() => Promise.resolve(null))
859
- )();
860
-
861
- /**
862
- * Finish Transaction (both platforms)
863
- * Abstracts Finish Transaction
864
- * iOS: Tells StoreKit that you have delivered the purchase to the user and StoreKit can now let go of the transaction.
865
- * Call this after you have persisted the purchased state to your server or local data in your app.
866
- * `react-native-iap` will continue to deliver the purchase updated events with the successful purchase until you finish the transaction. **Even after the app has relaunched.**
867
- * Android: it will consume purchase for consumables and acknowledge purchase for non-consumables.
868
- *
869
- ```tsx
870
- import React from 'react';
871
- import {Button} from 'react-native';
872
- import {finishTransaction} from 'react-native-iap';
873
-
874
- const App = () => {
875
- const handlePurchase = async () => {
876
- // ... handle the purchase request
877
-
878
- const result = finishTransaction({purchase});
879
- };
880
-
881
- return <Button title="Buy product" onPress={handlePurchase} />;
882
- };
883
- ```
884
- @returns {Promise<PurchaseResult | boolean>} Android: PurchaseResult, iOS: true
885
- */
886
- export const finishTransaction = ({
887
- purchase,
888
- isConsumable,
889
- developerPayloadAndroid,
890
- }: {
891
- purchase: Purchase;
892
- isConsumable?: boolean;
893
- developerPayloadAndroid?: string;
894
- }): Promise<PurchaseResult | boolean> => {
895
- return (
896
- Platform.select({
897
- ios: async () => {
898
- const transactionId = purchase.transactionId;
899
-
900
- if (!transactionId) {
901
- return Promise.reject(
902
- new Error('transactionId required to finish iOS transaction'),
903
- );
904
- }
905
- await getIosModule().finishTransaction(transactionId);
906
- return Promise.resolve(true);
907
- },
908
- android: async () => {
909
- if (purchase?.purchaseToken) {
910
- if (isConsumable) {
911
- return getAndroidModule().consumeProduct(
912
- purchase.purchaseToken,
913
- developerPayloadAndroid,
914
- );
915
- } else if (
916
- purchase.userIdAmazon ||
917
- (!purchase.isAcknowledgedAndroid &&
918
- purchase.purchaseStateAndroid === PurchaseStateAndroid.PURCHASED)
919
- ) {
920
- return getAndroidModule().acknowledgePurchase(
921
- purchase.purchaseToken,
922
- developerPayloadAndroid,
923
- );
924
- } else {
925
- return Promise.reject(
926
- new Error('purchase is not suitable to be purchased'),
927
- );
928
- }
929
- }
930
- return Promise.reject(
931
- new Error('purchase is not suitable to be purchased'),
932
- );
933
- },
934
- }) || (() => Promise.reject(new Error('Unsupported Platform')))
935
- )();
936
- };
937
-
938
- /**
939
- * Deeplinks to native interface that allows users to manage their subscriptions
940
- *
941
- */
942
- export const deepLinkToSubscriptions = ({
943
- sku,
944
- isAmazonDevice = true,
945
- }: {
946
- sku?: string;
947
- isAmazonDevice?: boolean;
948
- }): Promise<void> => {
949
- return (
950
- Platform.select({
951
- ios: async () => {
952
- IapIos.deepLinkToSubscriptionsIos();
953
- },
954
- android: async () => {
955
- if (isAmazon) {
956
- IapAmazon.deepLinkToSubscriptionsAmazon({isAmazonDevice});
957
- } else if (sku) {
958
- IapAndroid.deepLinkToSubscriptionsAndroid({sku});
959
- } else {
960
- Promise.reject(
961
- new Error(
962
- 'Sku is required to locate subscription in Android Store',
963
- ),
964
- );
965
- }
966
- },
967
- }) || (() => Promise.reject(new Error('Unsupported Platform')))
968
- )();
969
- };
970
-
971
- /**
972
- * Get App Store and Google Play device region.
973
- *
974
- * App Store: string - ISO 3166-1 Alpha-3 country code representation https://developer.apple.com/documentation/storekit/storefront.
975
- *
976
- * Google Play: string - ISO-3166-1 alpha2 country code representation https://developer.android.com/reference/com/android/billingclient/api/BillingConfig#getCountryCode()
977
- *
978
- * ```tsx
979
- * import React from 'react';
980
- * import {getStorefront} from 'react-native-iap';
981
- *
982
- * const App = () => {
983
- * React.useEffect(() => {
984
- * getStorefront().then((countryCode) => {
985
- * // ... handle region
986
- * });
987
- * }, []);
988
- * };
989
- * ```
990
- */
991
- export const getStorefront = (): Promise<string> => {
992
- return (
993
- Platform.select({
994
- android: async () => {
995
- return await RNIapModule.getStorefront();
996
- },
997
- ios: async () => {
998
- return await RNIapIosSk2.getStorefront();
999
- },
1000
- }) || (() => Promise.reject(new Error('Unsupported Platform')))
1001
- )();
1002
- };
1003
-
1004
- /**
1005
- * Get the app transaction information (iOS only, StoreKit 2).
1006
- * This contains the appTransactionID and other app purchase information.
1007
- *
1008
- * @platform iOS (16.0+)
1009
- * @returns {Promise<AppTransaction>} A promise that resolves to the app transaction information
1010
- *
1011
- * @example
1012
- * ```tsx
1013
- * import React from 'react';
1014
- * import {getAppTransaction} from 'react-native-iap';
1015
- *
1016
- * const App = () => {
1017
- * React.useEffect(() => {
1018
- * getAppTransaction().then((appTransaction) => {
1019
- * console.log('App Transaction ID:', appTransaction.appTransactionID);
1020
- * }).catch(error => {
1021
- * console.error('Error getting app transaction:', error);
1022
- * });
1023
- * }, []);
1024
- * };
1025
- * ```
1026
- */
1027
- export const getAppTransaction = (): Promise<{
1028
- appTransactionID: string;
1029
- originalAppVersion: string;
1030
- originalPurchaseDate: number;
1031
- deviceVerification: string;
1032
- deviceVerificationNonce: string;
1033
- appVersion: string;
1034
- signedDate: number;
1035
- environment: string;
1036
- }> => {
1037
- return (
1038
- Platform.select({
1039
- ios: async () => {
1040
- return await RNIapIosSk2.getAppTransaction();
1041
- },
1042
- }) ||
1043
- (() =>
1044
- Promise.reject(new Error('getAppTransaction is only available on iOS')))
1045
- )();
1046
- };