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
@@ -1,836 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.initConnection = exports.getSubscriptions = exports.getStorefront = exports.getPurchaseHistory = exports.getProducts = exports.getAvailablePurchases = exports.getAppTransaction = exports.flushFailedPurchasesCachedAsPendingAndroid = exports.finishTransaction = exports.endConnection = exports.deepLinkToSubscriptions = exports.IapIosSk2 = exports.IapIos = exports.IapAndroid = exports.IapAmazon = void 0;
7
- Object.defineProperty(exports, "isIosStorekit2", {
8
- enumerable: true,
9
- get: function () {
10
- return _internal.isIosStorekit2;
11
- }
12
- });
13
- exports.setup = exports.requestSubscription = exports.requestPurchase = void 0;
14
- var _reactNative = require("react-native");
15
- var IapAmazon = _interopRequireWildcard(require("./modules/amazon"));
16
- exports.IapAmazon = IapAmazon;
17
- var IapAndroid = _interopRequireWildcard(require("./modules/android"));
18
- exports.IapAndroid = IapAndroid;
19
- var IapIos = _interopRequireWildcard(require("./modules/ios"));
20
- exports.IapIos = IapIos;
21
- var IapIosSk2 = _interopRequireWildcard(require("./modules/iosSk2"));
22
- exports.IapIosSk2 = IapIosSk2;
23
- var _android2 = require("./types/android");
24
- var _apple = require("./types/apple");
25
- var _appleSk = require("./types/appleSk2");
26
- var _internal = require("./internal");
27
- var _types = require("./types");
28
- function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
29
- function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
30
- const {
31
- RNIapIos,
32
- RNIapIosSk2,
33
- RNIapModule,
34
- RNIapAmazonModule
35
- } = _reactNative.NativeModules;
36
- const ANDROID_ITEM_TYPE_SUBSCRIPTION = _types.ProductType.subs;
37
- const ANDROID_ITEM_TYPE_IAP = _types.ProductType.inapp;
38
-
39
- /**
40
- * STOREKIT1_MODE: Will not enable Storekit 2 even if the device supports it. Thigs will work as before,
41
- * minimum changes required in the migration guide (default)
42
- * HYBRID_MODE: Will enable Storekit 2 for iOS devices > 15.0 but will fallback to Sk1 on older devices
43
- * There are some edge cases that you need to handle in this case (described in migration guide). This mode
44
- * is for developers that are migrating to Storekit 2 but want to keep supporting older versions.
45
- * STOREKIT2_MODE: Will *only* enable Storekit 2. This disables Storekit 1. This is for apps that
46
- * have already targeted a min version of 15 for their app.
47
- */
48
-
49
- const setup = ({
50
- storekitMode = 'STOREKIT1_MODE'
51
- } = {}) => {
52
- switch (storekitMode) {
53
- case 'STOREKIT1_MODE':
54
- (0, _internal.storekit1Mode)();
55
- break;
56
- case 'STOREKIT2_MODE':
57
- (0, _internal.storekit2Mode)();
58
- break;
59
- case 'STOREKIT_HYBRID_MODE':
60
- (0, _internal.storekitHybridMode)();
61
- break;
62
- default:
63
- break;
64
- }
65
- };
66
-
67
- /**
68
- * Init module for purchase flow. Required on Android. In ios it will check whether user canMakePayment.
69
- * ## Usage
70
-
71
- ```tsx
72
- import React, {useEffect} from 'react';
73
- import {View} from 'react-native';
74
- import {initConnection} from 'react-native-iap';
75
-
76
- const App = () => {
77
- useEffect(() => {
78
- void initConnection();
79
- }, []);
80
-
81
- return <View />;
82
- };
83
- ```
84
- */
85
- exports.setup = setup;
86
- const initConnection = () => (0, _internal.getNativeModule)().initConnection();
87
-
88
- /**
89
- * Disconnects from native SDK
90
- * Usage
91
- * ```tsx
92
- import React, {useEffect} from 'react';
93
- import {View} from 'react-native';
94
- import {endConnection} from 'react-native-iap';
95
-
96
- const App = () => {
97
- useEffect(() => {
98
- return () => {
99
- void endConnection();
100
- };
101
- }, []);
102
-
103
- return <View />;
104
- };
105
- ```
106
- * @returns {Promise<void>}
107
- */
108
- exports.initConnection = initConnection;
109
- const endConnection = () => (0, _internal.getNativeModule)().endConnection();
110
-
111
- /**
112
- * Consume all 'ghost' purchases (that is, pending payment that already failed but is still marked as pending in Play Store cache). Android only.
113
- * @returns {Promise<boolean>}
114
- */
115
- exports.endConnection = endConnection;
116
- const flushFailedPurchasesCachedAsPendingAndroid = () => (0, _internal.getAndroidModule)().flushFailedPurchasesCachedAsPending();
117
-
118
- /**
119
- * Get a list of products (consumable and non-consumable items, but not subscriptions)
120
- ## Usage
121
-
122
- ```ts
123
- import React, {useState} from 'react';
124
- import {Platform} from 'react-native';
125
- import {getProducts, Product} from 'react-native-iap';
126
-
127
- const skus = Platform.select({
128
- ios: ['com.example.consumableIos'],
129
- android: ['com.example.consumableAndroid'],
130
- });
131
-
132
- const App = () => {
133
- const [products, setProducts] = useState<Product[]>([]);
134
-
135
- const handleProducts = async () => {
136
- const items = await getProducts({skus});
137
-
138
- setProducts(items);
139
- };
140
-
141
- useEffect(() => {
142
- void handleProducts();
143
- }, []);
144
-
145
- return (
146
- <>
147
- {products.map((product) => (
148
- <Text key={product.productId}>{product.productId}</Text>
149
- ))}
150
- </>
151
- );
152
- };
153
- ```
154
-
155
- Just a few things to keep in mind:
156
-
157
- - You can get your products in `componentDidMount`, `useEffect` or another appropriate area of your app.
158
- - 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.
159
- - 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.
160
-
161
- */
162
- exports.flushFailedPurchasesCachedAsPendingAndroid = flushFailedPurchasesCachedAsPendingAndroid;
163
- const getProducts = ({
164
- skus
165
- }) => {
166
- if (!(skus !== null && skus !== void 0 && skus.length)) {
167
- return Promise.reject('"skus" is required');
168
- }
169
- return (_reactNative.Platform.select({
170
- ios: async () => {
171
- let items;
172
- if ((0, _internal.isIosStorekit2)()) {
173
- items = (await RNIapIosSk2.getItems(skus)).map(_appleSk.productSk2Map);
174
- } else {
175
- items = await RNIapIos.getItems(skus);
176
- }
177
- return items.filter(item => skus.includes(item.productId));
178
- },
179
- android: async () => {
180
- const products = (await (0, _internal.getAndroidModule)().getItemsByType(ANDROID_ITEM_TYPE_IAP, skus)).map(_android2.singleProductAndroidMap);
181
- return (0, _internal.fillProductsWithAdditionalData)(products);
182
- }
183
- }) || (() => Promise.reject(new Error('Unsupported Platform'))))();
184
- };
185
-
186
- /**
187
- * Get a list of subscriptions
188
- * ## Usage
189
-
190
- ```tsx
191
- import React, {useCallback} from 'react';
192
- import {View} from 'react-native';
193
- import {getSubscriptions} from 'react-native-iap';
194
-
195
- const App = () => {
196
- const subscriptions = useCallback(
197
- async () =>
198
- await getSubscriptions({skus:['com.example.product1', 'com.example.product2']}),
199
- [],
200
- );
201
-
202
- return <View />;
203
- };
204
- ```
205
-
206
- */
207
- exports.getProducts = getProducts;
208
- const getSubscriptions = ({
209
- skus
210
- }) => {
211
- if (!(skus !== null && skus !== void 0 && skus.length)) {
212
- return Promise.reject('"skus" is required');
213
- }
214
- return (_reactNative.Platform.select({
215
- ios: async () => {
216
- let items;
217
- if ((0, _internal.isIosStorekit2)()) {
218
- items = (await RNIapIosSk2.getItems(skus)).map(_appleSk.subscriptionSk2Map);
219
- } else {
220
- items = await RNIapIos.getItems(skus);
221
- }
222
- items = items.filter(item => skus.includes(item.productId));
223
- return addSubscriptionPlatform(items, _types.SubscriptionPlatform.ios);
224
- },
225
- android: async () => {
226
- const androidPlatform = (0, _internal.getAndroidModuleType)();
227
- let subscriptions = await (0, _internal.getAndroidModule)().getItemsByType(ANDROID_ITEM_TYPE_SUBSCRIPTION, skus);
228
- switch (androidPlatform) {
229
- case 'android':
230
- {
231
- const castSubscriptions = subscriptions;
232
- return addSubscriptionPlatform(castSubscriptions, _types.SubscriptionPlatform.android);
233
- }
234
- case 'amazon':
235
- let castSubscriptions = subscriptions;
236
- castSubscriptions = await (0, _internal.fillProductsWithAdditionalData)(castSubscriptions);
237
- return addSubscriptionPlatform(castSubscriptions, _types.SubscriptionPlatform.amazon);
238
- case null:
239
- default:
240
- throw new Error(`getSubscriptions received unknown platform ${androidPlatform}. Verify the logic in getAndroidModuleType`);
241
- }
242
- }
243
- }) || (() => Promise.reject(new Error('Unsupported Platform'))))();
244
- };
245
-
246
- /**
247
- * Adds an extra property to subscriptions so we can distinguish the platform
248
- * we retrieved them on.
249
- */
250
- exports.getSubscriptions = getSubscriptions;
251
- const addSubscriptionPlatform = (subscriptions, platform) => {
252
- return subscriptions.map(subscription => ({
253
- ...subscription,
254
- platform
255
- }));
256
- };
257
-
258
- /**
259
- * Gets an inventory of purchases made by the user regardless of consumption status
260
- * ## Usage
261
-
262
- ```tsx
263
- import React, {useCallback} from 'react';
264
- import {View} from 'react-native';
265
- import {getPurchaseHistory} from 'react-native-iap';
266
-
267
- const App = () => {
268
- const history = useCallback(
269
- async () =>
270
- await getPurchaseHistory([
271
- 'com.example.product1',
272
- 'com.example.product2',
273
- ]),
274
- [],
275
- );
276
-
277
- return <View />;
278
- };
279
- ```
280
- @param {alsoPublishToEventListener}:boolean. (IOS Sk2 only) When `true`, every element will also be pushed to the purchaseUpdated listener.
281
- Note that this is only for backaward compatiblity. It won't publish to transactionUpdated (Storekit2) Defaults to `false`
282
- @param {automaticallyFinishRestoredTransactions}:boolean. (IOS Sk1 only) When `true`, all the transactions that are returned are automatically
283
- 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
284
- have to manually finish the returned transaction once you have delivered the content to your user.
285
- @param {onlyIncludeActiveItems}:boolean. (IOS Sk2 only). Defaults to false, meaning that it will return one transaction per item purchased.
286
- @See https://developer.apple.com/documentation/storekit/transaction/3851204-currententitlements for details
287
- */
288
- const getPurchaseHistory = ({
289
- alsoPublishToEventListener = false,
290
- automaticallyFinishRestoredTransactions = true,
291
- onlyIncludeActiveItems = false
292
- } = {}) => (_reactNative.Platform.select({
293
- ios: async () => {
294
- if ((0, _internal.isIosStorekit2)()) {
295
- return Promise.resolve((await RNIapIosSk2.getAvailableItems(alsoPublishToEventListener, onlyIncludeActiveItems)).map(_appleSk.transactionSk2ToPurchaseMap));
296
- } else {
297
- return RNIapIos.getAvailableItems(automaticallyFinishRestoredTransactions);
298
- }
299
- },
300
- android: async () => {
301
- if (RNIapAmazonModule) {
302
- return await RNIapAmazonModule.getAvailableItems();
303
- }
304
-
305
- // getPurchaseHistoryByType was removed in Google Play Billing Library v8
306
- // Android doesn't provide purchase history anymore, only active purchases
307
- console.warn('getPurchaseHistory is not supported on Android with Google Play Billing Library v8. Use getAvailablePurchases instead to get active purchases.');
308
- return [];
309
- }
310
- }) || (() => Promise.resolve([])))();
311
-
312
- /**
313
- * Get all purchases made by the user (either non-consumable, or haven't been consumed yet)
314
- * ## Usage
315
-
316
- ```tsx
317
- import React, {useCallback} from 'react';
318
- import {View} from 'react-native';
319
- import {getAvailablePurchases} from 'react-native-iap';
320
-
321
- const App = () => {
322
- const availablePurchases = useCallback(
323
- async () => await getAvailablePurchases(),
324
- [],
325
- );
326
-
327
- return <View />;
328
- };
329
- ```
330
-
331
- ## Restoring purchases
332
-
333
- You can use `getAvailablePurchases()` to do what's commonly understood as "restoring" purchases.
334
-
335
- :::note
336
- For debugging you may want to consume all items, you have then to iterate over the purchases returned by `getAvailablePurchases()`.
337
- :::
338
-
339
- :::warning
340
- 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.
341
- :::
342
-
343
- ```tsx
344
- import React from 'react';
345
- import {Button} from 'react-native';
346
- import {getAvailablePurchases,finishTransaction} from 'react-native-iap';
347
-
348
- const App = () => {
349
- handleRestore = async () => {
350
- try {
351
- const purchases = await getAvailablePurchases();
352
- const newState = {premium: false, ads: true};
353
- let titles = [];
354
-
355
- await Promise.all(purchases.map(async purchase => {
356
- switch (purchase.productId) {
357
- case 'com.example.premium':
358
- newState.premium = true;
359
- titles.push('Premium Version');
360
- break;
361
-
362
- case 'com.example.no_ads':
363
- newState.ads = false;
364
- titles.push('No Ads');
365
- break;
366
-
367
- case 'com.example.coins100':
368
- await finishTransaction({purchase});
369
- CoinStore.addCoins(100);
370
- }
371
- }));
372
-
373
- Alert.alert(
374
- 'Restore Successful',
375
- `You successfully restored the following purchases: ${titles.join(', ')}`,
376
- );
377
- } catch (error) {
378
- console.warn(error);
379
- Alert.alert(error.message);
380
- }
381
- };
382
-
383
- return (
384
- <Button title="Restore purchases" onPress={handleRestore} />
385
- )
386
- };
387
- ```
388
- @param {alsoPublishToEventListener}:boolean When `true`, every element will also be pushed to the purchaseUpdated listener.
389
- Note that this is only for backaward compatiblity. It won't publish to transactionUpdated (Storekit2) Defaults to `false`
390
- @param {onlyIncludeActiveItems}:boolean. (IOS Sk2 only). Defaults to true, meaning that it will return the transaction if suscription has not expired.
391
- @See https://developer.apple.com/documentation/storekit/transaction/3851204-currententitlements for details
392
- *
393
- */
394
- exports.getPurchaseHistory = getPurchaseHistory;
395
- const getAvailablePurchases = ({
396
- alsoPublishToEventListener = false,
397
- automaticallyFinishRestoredTransactions = false,
398
- onlyIncludeActiveItems = true
399
- } = {}) => (_reactNative.Platform.select({
400
- ios: async () => {
401
- if ((0, _internal.isIosStorekit2)()) {
402
- return Promise.resolve((await RNIapIosSk2.getAvailableItems(alsoPublishToEventListener, onlyIncludeActiveItems)).map(_appleSk.transactionSk2ToPurchaseMap));
403
- } else {
404
- return RNIapIos.getAvailableItems(automaticallyFinishRestoredTransactions);
405
- }
406
- },
407
- android: async () => {
408
- if (RNIapAmazonModule) {
409
- return await RNIapAmazonModule.getAvailableItems();
410
- }
411
-
412
- // Use the new getAvailableItems method if available
413
- if (RNIapModule.getAvailableItems) {
414
- try {
415
- return await RNIapModule.getAvailableItems();
416
- } catch (error) {
417
- console.warn('getAvailableItems failed, falling back to getAvailableItemsByType', error);
418
- // Fall through to the old method
419
- }
420
- }
421
-
422
- // Fallback to the old method for backward compatibility
423
- // Use Promise.all with timeout to avoid hanging
424
- const timeout = 10000; // 10 seconds timeout
425
- const timeoutPromise = new Promise((_, reject) => setTimeout(() => reject(new Error('getAvailablePurchases timeout')), timeout));
426
- try {
427
- const [products, subscriptions] = await Promise.race([Promise.all([RNIapModule.getAvailableItemsByType(ANDROID_ITEM_TYPE_IAP).catch(() => []), RNIapModule.getAvailableItemsByType(ANDROID_ITEM_TYPE_SUBSCRIPTION).catch(() => [])]), timeoutPromise]);
428
- return products.concat(subscriptions);
429
- } catch (error) {
430
- console.error('getAvailablePurchases error:', error);
431
- return [];
432
- }
433
- }
434
- }) || (() => Promise.resolve([])))();
435
-
436
- /**
437
- * Request a purchase for product. This will be received in `PurchaseUpdatedListener`.
438
- * Request a purchase for a product (consumables or non-consumables).
439
-
440
- The response will be received through the `PurchaseUpdatedListener`.
441
-
442
- :::note
443
- `andDangerouslyFinishTransactionAutomatically` defaults to false. We recommend
444
- always keeping at false, and verifying the transaction receipts on the server-side.
445
- :::
446
-
447
- ## Signature
448
-
449
- ```ts
450
- requestPurchase(
451
- The product's sku/ID
452
- sku,
453
-
454
-
455
- * You should set this to false and call finishTransaction manually when you have delivered the purchased goods to the user.
456
- * @default false
457
-
458
- andDangerouslyFinishTransactionAutomaticallyIOS = false,
459
-
460
- /** Specifies an optional obfuscated string that is uniquely associated with the user's account in your app.
461
- obfuscatedAccountIdAndroid,
462
-
463
- Specifies an optional obfuscated string that is uniquely associated with the user's profile in your app.
464
- obfuscatedProfileIdAndroid,
465
-
466
- The purchaser's user ID
467
- applicationUsername,
468
- ): Promise<ProductPurchase>;
469
- ```
470
-
471
- ## Usage
472
-
473
- ```tsx
474
- import React, { useState, useEffect } from 'react';
475
- import {Button} from 'react-native';
476
- import {requestPurchase, Product, Sku, getProducts} from 'react-native-iap';
477
-
478
- const App = () => {
479
- const [products, setProducts] = useState<Product[]>([]);
480
-
481
- useEffect(() => {
482
- const fetchProducts = async () => {
483
- const productList = await getProducts({skus:['com.example.product']});
484
- setProducts(productList);
485
- }
486
-
487
- fetchProducts();
488
- }, []);
489
-
490
- const handlePurchase = async (sku: Sku) => {
491
- await requestPurchase({sku});
492
- };
493
-
494
- return (
495
- <>
496
- {products.map((product) => (
497
- <Button
498
- key={product.productId}
499
- title="Buy product"
500
- onPress={() => handlePurchase(product.productId)}
501
- />
502
- ))}
503
- </>
504
- );
505
- };
506
- ```
507
-
508
- */
509
- exports.getAvailablePurchases = getAvailablePurchases;
510
- const requestPurchase = request => (_reactNative.Platform.select({
511
- ios: async () => {
512
- if (!('sku' in request)) {
513
- throw new Error('sku is required for iOS purchase');
514
- }
515
- const {
516
- sku,
517
- andDangerouslyFinishTransactionAutomaticallyIOS = false,
518
- appAccountToken,
519
- quantity,
520
- withOffer
521
- } = request;
522
- if (andDangerouslyFinishTransactionAutomaticallyIOS) {
523
- console.warn('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.');
524
- }
525
- if ((0, _internal.isIosStorekit2)()) {
526
- const offer = (0, _appleSk.offerSk2Map)(withOffer);
527
- const purchase = (0, _appleSk.transactionSk2ToPurchaseMap)(await RNIapIosSk2.buyProduct(sku, andDangerouslyFinishTransactionAutomaticallyIOS, appAccountToken, quantity ?? -1, offer));
528
- return Promise.resolve(purchase);
529
- } else {
530
- return RNIapIos.buyProduct(sku, andDangerouslyFinishTransactionAutomaticallyIOS, appAccountToken, quantity ?? -1, (0, _apple.offerToRecord)(withOffer));
531
- }
532
- },
533
- android: async () => {
534
- if (_internal.isAmazon) {
535
- if (!('sku' in request)) {
536
- throw new Error('sku is required for Amazon purchase');
537
- }
538
- const {
539
- sku
540
- } = request;
541
- return RNIapAmazonModule.buyItemByType(sku, '');
542
- } else {
543
- if (!('skus' in request) || !request.skus.length) {
544
- throw new Error('skus is required for Android purchase');
545
- }
546
- const {
547
- skus,
548
- obfuscatedAccountIdAndroid,
549
- obfuscatedProfileIdAndroid,
550
- isOfferPersonalized
551
- } = request;
552
- return RNIapModule.buyItemByType(ANDROID_ITEM_TYPE_IAP, skus, undefined, -1, obfuscatedAccountIdAndroid, obfuscatedProfileIdAndroid, [], isOfferPersonalized ?? false);
553
- }
554
- }
555
- }) || Promise.resolve)();
556
-
557
- /**
558
- * Request a purchase for product. This will be received in `PurchaseUpdatedListener`.
559
- * Request a purchase for a subscription.
560
-
561
- The response will be received through the `PurchaseUpdatedListener`.
562
-
563
- :::note
564
- `andDangerouslyFinishTransactionAutomatically` defaults to false. We recommend
565
- always keeping at false, and verifying the transaction receipts on the server-side.
566
- :::
567
-
568
- ## Signature
569
-
570
- ```ts
571
- requestSubscription(
572
- The product's sku/ID
573
- sku,
574
-
575
-
576
- * You should set this to false and call finishTransaction manually when you have delivered the purchased goods to the user.
577
- * @default false
578
-
579
- andDangerouslyFinishTransactionAutomaticallyIOS = false,
580
-
581
- purchaseToken that the user is upgrading or downgrading from (Android).
582
- purchaseTokenAndroid,
583
-
584
- UNKNOWN_SUBSCRIPTION_UPGRADE_DOWNGRADE_POLICY, IMMEDIATE_WITH_TIME_PRORATION, IMMEDIATE_AND_CHARGE_PRORATED_PRICE, IMMEDIATE_WITHOUT_PRORATION, DEFERRED
585
- prorationModeAndroid = -1,
586
-
587
- /** Specifies an optional obfuscated string that is uniquely associated with the user's account in your app.
588
- obfuscatedAccountIdAndroid,
589
-
590
- Specifies an optional obfuscated string that is uniquely associated with the user's profile in your app.
591
- obfuscatedProfileIdAndroid,
592
-
593
- The purchaser's user ID
594
- applicationUsername,
595
- ): Promise<SubscriptionPurchase>
596
- ```
597
-
598
- ## Usage
599
-
600
- ```tsx
601
- import React, {useCallback} from 'react';
602
- import {Button} from 'react-native';
603
- import {
604
- requestSubscription,
605
- Product,
606
- Sku,
607
- getSubscriptions,
608
- } from 'react-native-iap';
609
-
610
- const App = () => {
611
- const subscriptions = useCallback(
612
- async () => getSubscriptions(['com.example.subscription']),
613
- [],
614
- );
615
-
616
- const handlePurchase = async (sku: Sku) => {
617
- await requestSubscription({sku});
618
- };
619
-
620
- return (
621
- <>
622
- {subscriptions.map((subscription) => (
623
- <Button
624
- key={subscription.productId}
625
- title="Buy subscription"
626
- onPress={() => handlePurchase(subscription.productId)}
627
- />
628
- ))}
629
- </>
630
- );
631
- };
632
- ```
633
- */
634
- exports.requestPurchase = requestPurchase;
635
- const requestSubscription = request => (_reactNative.Platform.select({
636
- ios: async () => {
637
- if (!('sku' in request)) {
638
- throw new Error('sku is required for iOS subscriptions');
639
- }
640
- const {
641
- sku,
642
- andDangerouslyFinishTransactionAutomaticallyIOS = false,
643
- appAccountToken,
644
- quantity,
645
- withOffer
646
- } = request;
647
- if (andDangerouslyFinishTransactionAutomaticallyIOS) {
648
- console.warn('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.');
649
- }
650
- if ((0, _internal.isIosStorekit2)()) {
651
- const offer = (0, _appleSk.offerSk2Map)(withOffer);
652
- const purchase = (0, _appleSk.transactionSk2ToPurchaseMap)(await RNIapIosSk2.buyProduct(sku, andDangerouslyFinishTransactionAutomaticallyIOS, appAccountToken, quantity ?? -1, offer));
653
- return Promise.resolve(purchase);
654
- } else {
655
- return RNIapIos.buyProduct(sku, andDangerouslyFinishTransactionAutomaticallyIOS, appAccountToken, quantity ?? -1, (0, _apple.offerToRecord)(withOffer));
656
- }
657
- },
658
- android: async () => {
659
- if (_internal.isAmazon) {
660
- if (!('sku' in request)) {
661
- throw new Error('sku is required for Amazon subscriptions');
662
- }
663
- const {
664
- sku
665
- } = request;
666
- var prorationModeAmazon = '';
667
- if ('prorationModeAmazon' in request) {
668
- prorationModeAmazon = request.prorationModeAmazon || '';
669
- }
670
- return RNIapAmazonModule.buyItemByType(sku, prorationModeAmazon);
671
- } else {
672
- if (!('subscriptionOffers' in request) || request.subscriptionOffers.length === 0) {
673
- throw new Error('subscriptionOffers are required for Google Play subscriptions');
674
- }
675
- const {
676
- subscriptionOffers,
677
- purchaseTokenAndroid,
678
- replacementModeAndroid = -1,
679
- obfuscatedAccountIdAndroid,
680
- obfuscatedProfileIdAndroid,
681
- isOfferPersonalized
682
- } = request;
683
- return RNIapModule.buyItemByType(ANDROID_ITEM_TYPE_SUBSCRIPTION, subscriptionOffers === null || subscriptionOffers === void 0 ? void 0 : subscriptionOffers.map(so => so.sku), purchaseTokenAndroid, replacementModeAndroid, obfuscatedAccountIdAndroid, obfuscatedProfileIdAndroid, subscriptionOffers === null || subscriptionOffers === void 0 ? void 0 : subscriptionOffers.map(so => so.offerToken), isOfferPersonalized ?? false);
684
- }
685
- }
686
- }) || (() => Promise.resolve(null)))();
687
-
688
- /**
689
- * Finish Transaction (both platforms)
690
- * Abstracts Finish Transaction
691
- * iOS: Tells StoreKit that you have delivered the purchase to the user and StoreKit can now let go of the transaction.
692
- * Call this after you have persisted the purchased state to your server or local data in your app.
693
- * `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.**
694
- * Android: it will consume purchase for consumables and acknowledge purchase for non-consumables.
695
- *
696
- ```tsx
697
- import React from 'react';
698
- import {Button} from 'react-native';
699
- import {finishTransaction} from 'react-native-iap';
700
-
701
- const App = () => {
702
- const handlePurchase = async () => {
703
- // ... handle the purchase request
704
-
705
- const result = finishTransaction({purchase});
706
- };
707
-
708
- return <Button title="Buy product" onPress={handlePurchase} />;
709
- };
710
- ```
711
- @returns {Promise<PurchaseResult | boolean>} Android: PurchaseResult, iOS: true
712
- */
713
- exports.requestSubscription = requestSubscription;
714
- const finishTransaction = ({
715
- purchase,
716
- isConsumable,
717
- developerPayloadAndroid
718
- }) => {
719
- return (_reactNative.Platform.select({
720
- ios: async () => {
721
- const transactionId = purchase.transactionId;
722
- if (!transactionId) {
723
- return Promise.reject(new Error('transactionId required to finish iOS transaction'));
724
- }
725
- await (0, _internal.getIosModule)().finishTransaction(transactionId);
726
- return Promise.resolve(true);
727
- },
728
- android: async () => {
729
- if (purchase !== null && purchase !== void 0 && purchase.purchaseToken) {
730
- if (isConsumable) {
731
- return (0, _internal.getAndroidModule)().consumeProduct(purchase.purchaseToken, developerPayloadAndroid);
732
- } else if (purchase.userIdAmazon || !purchase.isAcknowledgedAndroid && purchase.purchaseStateAndroid === _types.PurchaseStateAndroid.PURCHASED) {
733
- return (0, _internal.getAndroidModule)().acknowledgePurchase(purchase.purchaseToken, developerPayloadAndroid);
734
- } else {
735
- return Promise.reject(new Error('purchase is not suitable to be purchased'));
736
- }
737
- }
738
- return Promise.reject(new Error('purchase is not suitable to be purchased'));
739
- }
740
- }) || (() => Promise.reject(new Error('Unsupported Platform'))))();
741
- };
742
-
743
- /**
744
- * Deeplinks to native interface that allows users to manage their subscriptions
745
- *
746
- */
747
- exports.finishTransaction = finishTransaction;
748
- const deepLinkToSubscriptions = ({
749
- sku,
750
- isAmazonDevice = true
751
- }) => {
752
- return (_reactNative.Platform.select({
753
- ios: async () => {
754
- IapIos.deepLinkToSubscriptionsIos();
755
- },
756
- android: async () => {
757
- if (_internal.isAmazon) {
758
- IapAmazon.deepLinkToSubscriptionsAmazon({
759
- isAmazonDevice
760
- });
761
- } else if (sku) {
762
- IapAndroid.deepLinkToSubscriptionsAndroid({
763
- sku
764
- });
765
- } else {
766
- Promise.reject(new Error('Sku is required to locate subscription in Android Store'));
767
- }
768
- }
769
- }) || (() => Promise.reject(new Error('Unsupported Platform'))))();
770
- };
771
-
772
- /**
773
- * Get App Store and Google Play device region.
774
- *
775
- * App Store: string - ISO 3166-1 Alpha-3 country code representation https://developer.apple.com/documentation/storekit/storefront.
776
- *
777
- * Google Play: string - ISO-3166-1 alpha2 country code representation https://developer.android.com/reference/com/android/billingclient/api/BillingConfig#getCountryCode()
778
- *
779
- * ```tsx
780
- * import React from 'react';
781
- * import {getStorefront} from 'react-native-iap';
782
- *
783
- * const App = () => {
784
- * React.useEffect(() => {
785
- * getStorefront().then((countryCode) => {
786
- * // ... handle region
787
- * });
788
- * }, []);
789
- * };
790
- * ```
791
- */
792
- exports.deepLinkToSubscriptions = deepLinkToSubscriptions;
793
- const getStorefront = () => {
794
- return (_reactNative.Platform.select({
795
- android: async () => {
796
- return await RNIapModule.getStorefront();
797
- },
798
- ios: async () => {
799
- return await RNIapIosSk2.getStorefront();
800
- }
801
- }) || (() => Promise.reject(new Error('Unsupported Platform'))))();
802
- };
803
-
804
- /**
805
- * Get the app transaction information (iOS only, StoreKit 2).
806
- * This contains the appTransactionID and other app purchase information.
807
- *
808
- * @platform iOS (16.0+)
809
- * @returns {Promise<AppTransaction>} A promise that resolves to the app transaction information
810
- *
811
- * @example
812
- * ```tsx
813
- * import React from 'react';
814
- * import {getAppTransaction} from 'react-native-iap';
815
- *
816
- * const App = () => {
817
- * React.useEffect(() => {
818
- * getAppTransaction().then((appTransaction) => {
819
- * console.log('App Transaction ID:', appTransaction.appTransactionID);
820
- * }).catch(error => {
821
- * console.error('Error getting app transaction:', error);
822
- * });
823
- * }, []);
824
- * };
825
- * ```
826
- */
827
- exports.getStorefront = getStorefront;
828
- const getAppTransaction = () => {
829
- return (_reactNative.Platform.select({
830
- ios: async () => {
831
- return await RNIapIosSk2.getAppTransaction();
832
- }
833
- }) || (() => Promise.reject(new Error('getAppTransaction is only available on iOS'))))();
834
- };
835
- exports.getAppTransaction = getAppTransaction;
836
- //# sourceMappingURL=iap.js.map