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.
- package/NitroIap.podspec +33 -0
- package/README.md +163 -51
- package/android/CMakeLists.txt +32 -0
- package/android/build.gradle +107 -138
- package/android/fix-prefab.gradle +51 -0
- package/android/gradle.properties +5 -13
- package/android/src/main/AndroidManifest.xml +1 -4
- package/android/src/main/cpp/cpp-adapter.cpp +6 -0
- package/android/src/main/java/com/margelo/nitro/iap/HybridRnIap.kt +843 -0
- package/android/src/main/java/com/margelo/nitro/iap/NitroIapPackage.java +33 -0
- package/android/src/main/java/com/margelo/nitro/iap/Types.kt +173 -0
- package/ios/Bridge.h +8 -0
- package/ios/ErrorUtils.swift +153 -0
- package/ios/HybridRnIap.swift +1326 -0
- package/ios/ProductStore.swift +33 -0
- package/ios/reactnativeiap.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
- package/ios/reactnativeiap.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
- package/lib/module/helpers/subscription.js +56 -0
- package/lib/module/helpers/subscription.js.map +1 -0
- package/lib/module/hooks/useIAP.js +175 -123
- package/lib/module/hooks/useIAP.js.map +1 -1
- package/lib/module/index.js +1015 -9
- package/lib/module/index.js.map +1 -1
- package/lib/module/package.json +1 -0
- package/lib/module/specs/RnIap.nitro.js +4 -0
- package/lib/{commonjs/modules/common.js.map → module/specs/RnIap.nitro.js.map} +1 -1
- package/lib/module/types.js +187 -0
- package/lib/module/types.js.map +1 -0
- package/lib/module/utils/error.js +80 -0
- package/lib/module/utils/error.js.map +1 -0
- package/lib/module/utils/type-bridge.js +202 -0
- package/lib/module/utils/type-bridge.js.map +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/plugin/src/withIAP.d.ts +2 -7
- package/lib/typescript/plugin/src/withIAP.d.ts.map +1 -1
- package/lib/typescript/scripts/check-nitro-versions.d.ts +3 -0
- package/lib/typescript/scripts/check-nitro-versions.d.ts.map +1 -0
- package/lib/typescript/src/helpers/subscription.d.ts +14 -0
- package/lib/typescript/src/helpers/subscription.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useIAP.d.ts +42 -26
- package/lib/typescript/src/hooks/useIAP.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +356 -8
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/specs/RnIap.nitro.d.ts +404 -0
- package/lib/typescript/src/specs/RnIap.nitro.d.ts.map +1 -0
- package/lib/typescript/src/types.d.ts +544 -0
- package/lib/typescript/src/types.d.ts.map +1 -0
- package/lib/typescript/src/utils/error.d.ts +30 -0
- package/lib/typescript/src/utils/error.d.ts.map +1 -0
- package/lib/typescript/src/utils/type-bridge.d.ts +40 -0
- package/lib/typescript/src/utils/type-bridge.d.ts.map +1 -0
- package/nitro.json +17 -0
- package/nitrogen/generated/android/NitroIap+autolinking.cmake +80 -0
- package/nitrogen/generated/android/NitroIap+autolinking.gradle +27 -0
- package/nitrogen/generated/android/NitroIapOnLoad.cpp +50 -0
- package/nitrogen/generated/android/NitroIapOnLoad.hpp +25 -0
- package/nitrogen/generated/android/c++/JFunc_void_NitroProduct.hpp +78 -0
- package/nitrogen/generated/android/c++/JFunc_void_NitroPurchase.hpp +78 -0
- package/nitrogen/generated/android/c++/JFunc_void_NitroPurchaseResult.hpp +78 -0
- package/nitrogen/generated/android/c++/JHybridRnIapSpec.cpp +577 -0
- package/nitrogen/generated/android/c++/JHybridRnIapSpec.hpp +93 -0
- package/nitrogen/generated/android/c++/JNitroAndroidReceiptValidationOptions.hpp +66 -0
- package/nitrogen/generated/android/c++/JNitroAvailablePurchasesAndroidOptions.hpp +54 -0
- package/nitrogen/generated/android/c++/JNitroAvailablePurchasesIosOptions.hpp +65 -0
- package/nitrogen/generated/android/c++/JNitroAvailablePurchasesOptions.hpp +62 -0
- package/nitrogen/generated/android/c++/JNitroFinishTransactionAndroidParams.hpp +58 -0
- package/nitrogen/generated/android/c++/JNitroFinishTransactionIosParams.hpp +53 -0
- package/nitrogen/generated/android/c++/JNitroFinishTransactionParams.hpp +62 -0
- package/nitrogen/generated/android/c++/JNitroProduct.hpp +154 -0
- package/nitrogen/generated/android/c++/JNitroPurchase.hpp +122 -0
- package/nitrogen/generated/android/c++/JNitroPurchaseRequest.hpp +66 -0
- package/nitrogen/generated/android/c++/JNitroPurchaseResult.hpp +70 -0
- package/nitrogen/generated/android/c++/JNitroReceiptValidationParams.hpp +60 -0
- package/nitrogen/generated/android/c++/JNitroReceiptValidationResultAndroid.hpp +122 -0
- package/nitrogen/generated/android/c++/JNitroReceiptValidationResultIOS.hpp +68 -0
- package/nitrogen/generated/android/c++/JNitroRequestPurchaseAndroid.hpp +115 -0
- package/nitrogen/generated/android/c++/JNitroRequestPurchaseIos.hpp +84 -0
- package/nitrogen/generated/android/c++/JNitroSubscriptionOffer.hpp +57 -0
- package/nitrogen/generated/android/c++/JNitroSubscriptionRenewalInfo.hpp +74 -0
- package/nitrogen/generated/android/c++/JNitroSubscriptionStatus.hpp +64 -0
- package/nitrogen/generated/android/c++/JVariant_Boolean_NitroPurchaseResult.cpp +26 -0
- package/nitrogen/generated/android/c++/JVariant_Boolean_NitroPurchaseResult.hpp +71 -0
- package/nitrogen/generated/android/c++/JVariant_NitroReceiptValidationResultIOS_NitroReceiptValidationResultAndroid.cpp +26 -0
- package/nitrogen/generated/android/c++/JVariant_NitroReceiptValidationResultIOS_NitroReceiptValidationResultAndroid.hpp +75 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/Func_void_NitroProduct.kt +81 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/Func_void_NitroPurchase.kt +81 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/Func_void_NitroPurchaseResult.kt +81 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/HybridRnIapSpec.kt +198 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/NitroAndroidReceiptValidationOptions.kt +38 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/NitroAvailablePurchasesAndroidOptions.kt +29 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/NitroAvailablePurchasesIosOptions.kt +38 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/NitroAvailablePurchasesOptions.kt +32 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/NitroFinishTransactionAndroidParams.kt +32 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/NitroFinishTransactionIosParams.kt +29 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/NitroFinishTransactionParams.kt +32 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/NitroIapOnLoad.kt +35 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/NitroProduct.kt +104 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/NitroPurchase.kt +80 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/NitroPurchaseRequest.kt +32 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/NitroPurchaseResult.kt +41 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/NitroReceiptValidationParams.kt +32 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/NitroReceiptValidationResultAndroid.kt +80 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/NitroReceiptValidationResultIOS.kt +38 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/NitroRequestPurchaseAndroid.kt +47 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/NitroRequestPurchaseIos.kt +41 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/NitroSubscriptionOffer.kt +32 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/NitroSubscriptionRenewalInfo.kt +44 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/NitroSubscriptionStatus.kt +35 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/Variant_Boolean_NitroPurchaseResult.kt +42 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/Variant_NitroReceiptValidationResultIOS_NitroReceiptValidationResultAndroid.kt +42 -0
- package/nitrogen/generated/ios/NitroIap+autolinking.rb +60 -0
- package/nitrogen/generated/ios/NitroIap-Swift-Cxx-Bridge.cpp +152 -0
- package/nitrogen/generated/ios/NitroIap-Swift-Cxx-Bridge.hpp +1061 -0
- package/nitrogen/generated/ios/NitroIap-Swift-Cxx-Umbrella.hpp +107 -0
- package/nitrogen/generated/ios/NitroIapAutolinking.mm +33 -0
- package/nitrogen/generated/ios/NitroIapAutolinking.swift +25 -0
- package/nitrogen/generated/ios/c++/HybridRnIapSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridRnIapSpecSwift.hpp +355 -0
- package/nitrogen/generated/ios/swift/Func_void.swift +47 -0
- package/nitrogen/generated/ios/swift/Func_void_NitroProduct.swift +47 -0
- package/nitrogen/generated/ios/swift/Func_void_NitroPurchase.swift +47 -0
- package/nitrogen/generated/ios/swift/Func_void_NitroPurchaseResult.swift +47 -0
- package/nitrogen/generated/ios/swift/Func_void_bool.swift +47 -0
- package/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift +47 -0
- package/nitrogen/generated/ios/swift/Func_void_std__optional_NitroProduct_.swift +54 -0
- package/nitrogen/generated/ios/swift/Func_void_std__optional_NitroPurchase_.swift +54 -0
- package/nitrogen/generated/ios/swift/Func_void_std__optional_std__string_.swift +54 -0
- package/nitrogen/generated/ios/swift/Func_void_std__optional_std__vector_NitroSubscriptionStatus__.swift +54 -0
- package/nitrogen/generated/ios/swift/Func_void_std__string.swift +47 -0
- package/nitrogen/generated/ios/swift/Func_void_std__variant_NitroReceiptValidationResultIOS__NitroReceiptValidationResultAndroid_.swift +59 -0
- package/nitrogen/generated/ios/swift/Func_void_std__variant_bool__NitroPurchaseResult_.swift +59 -0
- package/nitrogen/generated/ios/swift/Func_void_std__vector_NitroProduct_.swift +47 -0
- package/nitrogen/generated/ios/swift/Func_void_std__vector_NitroPurchase_.swift +47 -0
- package/nitrogen/generated/ios/swift/HybridRnIapSpec.swift +78 -0
- package/nitrogen/generated/ios/swift/HybridRnIapSpec_cxx.swift +750 -0
- package/nitrogen/generated/ios/swift/NitroAndroidReceiptValidationOptions.swift +80 -0
- package/nitrogen/generated/ios/swift/NitroAvailablePurchasesAndroidOptions.swift +54 -0
- package/nitrogen/generated/ios/swift/NitroAvailablePurchasesIosOptions.swift +116 -0
- package/nitrogen/generated/ios/swift/NitroAvailablePurchasesOptions.swift +84 -0
- package/nitrogen/generated/ios/swift/NitroFinishTransactionAndroidParams.swift +58 -0
- package/nitrogen/generated/ios/swift/NitroFinishTransactionIosParams.swift +35 -0
- package/nitrogen/generated/ios/swift/NitroFinishTransactionParams.swift +84 -0
- package/nitrogen/generated/ios/swift/NitroProduct.swift +653 -0
- package/nitrogen/generated/ios/swift/NitroPurchase.swift +453 -0
- package/nitrogen/generated/ios/swift/NitroPurchaseRequest.swift +84 -0
- package/nitrogen/generated/ios/swift/NitroPurchaseResult.swift +117 -0
- package/nitrogen/generated/ios/swift/NitroReceiptValidationParams.swift +65 -0
- package/nitrogen/generated/ios/swift/NitroReceiptValidationResultAndroid.swift +258 -0
- package/nitrogen/generated/ios/swift/NitroReceiptValidationResultIOS.swift +87 -0
- package/nitrogen/generated/ios/swift/NitroRequestPurchaseAndroid.swift +225 -0
- package/nitrogen/generated/ios/swift/NitroRequestPurchaseIos.swift +161 -0
- package/nitrogen/generated/ios/swift/NitroSubscriptionOffer.swift +46 -0
- package/nitrogen/generated/ios/swift/NitroSubscriptionRenewalInfo.swift +152 -0
- package/nitrogen/generated/ios/swift/NitroSubscriptionStatus.swift +76 -0
- package/nitrogen/generated/ios/swift/Variant_Bool_NitroPurchaseResult.swift +18 -0
- package/nitrogen/generated/ios/swift/Variant_NitroReceiptValidationResultIOS_NitroReceiptValidationResultAndroid.swift +18 -0
- package/nitrogen/generated/shared/c++/HybridRnIapSpec.cpp +50 -0
- package/nitrogen/generated/shared/c++/HybridRnIapSpec.hpp +125 -0
- package/nitrogen/generated/shared/c++/NitroAndroidReceiptValidationOptions.hpp +80 -0
- package/nitrogen/generated/shared/c++/NitroAvailablePurchasesAndroidOptions.hpp +68 -0
- package/nitrogen/generated/shared/c++/NitroAvailablePurchasesIosOptions.hpp +79 -0
- package/nitrogen/generated/shared/c++/NitroAvailablePurchasesOptions.hpp +76 -0
- package/nitrogen/generated/shared/c++/NitroFinishTransactionAndroidParams.hpp +72 -0
- package/nitrogen/generated/shared/c++/NitroFinishTransactionIosParams.hpp +67 -0
- package/nitrogen/generated/shared/c++/NitroFinishTransactionParams.hpp +76 -0
- package/nitrogen/generated/shared/c++/NitroProduct.hpp +168 -0
- package/nitrogen/generated/shared/c++/NitroPurchase.hpp +136 -0
- package/nitrogen/generated/shared/c++/NitroPurchaseRequest.hpp +76 -0
- package/nitrogen/generated/shared/c++/NitroPurchaseResult.hpp +84 -0
- package/nitrogen/generated/shared/c++/NitroReceiptValidationParams.hpp +74 -0
- package/nitrogen/generated/shared/c++/NitroReceiptValidationResultAndroid.hpp +136 -0
- package/nitrogen/generated/shared/c++/NitroReceiptValidationResultIOS.hpp +82 -0
- package/nitrogen/generated/shared/c++/NitroRequestPurchaseAndroid.hpp +95 -0
- package/nitrogen/generated/shared/c++/NitroRequestPurchaseIos.hpp +85 -0
- package/nitrogen/generated/shared/c++/NitroSubscriptionOffer.hpp +71 -0
- package/nitrogen/generated/shared/c++/NitroSubscriptionRenewalInfo.hpp +88 -0
- package/nitrogen/generated/shared/c++/NitroSubscriptionStatus.hpp +78 -0
- package/package.json +145 -104
- package/plugin/build/src/withIAP.d.ts +3 -0
- package/plugin/build/src/withIAP.js +81 -0
- package/plugin/build/tsconfig.tsbuildinfo +1 -0
- package/plugin/build/withIAP.d.ts +2 -7
- package/plugin/build/withIAP.js +62 -51
- package/plugin/src/withIAP.ts +119 -0
- package/plugin/tsconfig.json +18 -0
- package/plugin/tsconfig.tsbuildinfo +1 -0
- package/src/helpers/subscription.ts +65 -0
- package/src/hooks/useIAP.ts +361 -222
- package/src/index.ts +1194 -9
- package/src/specs/RnIap.nitro.ts +501 -0
- package/src/types.ts +680 -0
- package/src/utils/error.ts +97 -0
- package/src/utils/type-bridge.ts +209 -0
- package/LICENSE +0 -21
- package/RNIap.podspec +0 -36
- package/android/src/amazon/AndroidManifest.xml +0 -14
- package/android/src/amazon/java/com/dooboolab/rniap/EventSender.kt +0 -10
- package/android/src/amazon/java/com/dooboolab/rniap/PurchasingServiceProxy.kt +0 -29
- package/android/src/amazon/java/com/dooboolab/rniap/PurchasingServiceProxyAmazonImpl.kt +0 -31
- package/android/src/amazon/java/com/dooboolab/rniap/RNIapActivityListener.kt +0 -55
- package/android/src/amazon/java/com/dooboolab/rniap/RNIapAmazonListener.kt +0 -325
- package/android/src/amazon/java/com/dooboolab/rniap/RNIapAmazonModule.kt +0 -244
- package/android/src/amazon/java/com/dooboolab/rniap/RNIapPackage.kt +0 -17
- package/android/src/amazon/java/com/dooboolab/rniap/modifysubscription/RNIapAmazonModifySubscriptionListener.kt +0 -88
- package/android/src/amazon/java/com/dooboolab/rniap/utils/Extensions.kt +0 -22
- package/android/src/main/java/com/dooboolab/rniap/PromiseUtils.kt +0 -62
- package/android/src/main/java/com/dooboolab/rniap/PromiseUtlis.kt +0 -43
- package/android/src/play/java/com/dooboolab/rniap/PlayUtils.kt +0 -114
- package/android/src/play/java/com/dooboolab/rniap/RNIapActivityListener.kt +0 -15
- package/android/src/play/java/com/dooboolab/rniap/RNIapModule.kt +0 -911
- package/android/src/play/java/com/dooboolab/rniap/RNIapPackage.kt +0 -17
- package/android/src/testAmazon/java/com/dooboolab/rniap/RNIapAmazonModuleTest.kt +0 -170
- package/app.plugin.js +0 -1
- package/ios/IapSerializationUtils.swift +0 -290
- package/ios/IapTypes.swift +0 -56
- package/ios/IapUtils.swift +0 -40
- package/ios/LatestPromiseKeeper.swift +0 -52
- package/ios/RNIapIos-Bridging-Header.h +0 -2
- package/ios/RNIapIos.m +0 -69
- package/ios/RNIapIos.swift +0 -868
- package/ios/RNIapIos.xcodeproj/project.pbxproj +0 -289
- package/ios/RNIapIosSk2.m +0 -126
- package/ios/RNIapIosSk2.swift +0 -1413
- package/ios/ThreadSafe.swift +0 -18
- package/lib/commonjs/eventEmitter.js +0 -195
- package/lib/commonjs/eventEmitter.js.map +0 -1
- package/lib/commonjs/hooks/index.js +0 -17
- package/lib/commonjs/hooks/index.js.map +0 -1
- package/lib/commonjs/hooks/useIAP.js +0 -203
- package/lib/commonjs/hooks/useIAP.js.map +0 -1
- package/lib/commonjs/hooks/withIAPContext.js +0 -95
- package/lib/commonjs/hooks/withIAPContext.js.map +0 -1
- package/lib/commonjs/iap.js +0 -836
- package/lib/commonjs/iap.js.map +0 -1
- package/lib/commonjs/index.js +0 -105
- package/lib/commonjs/index.js.map +0 -1
- package/lib/commonjs/internal/enhancedFetch.js +0 -26
- package/lib/commonjs/internal/enhancedFetch.js.map +0 -1
- package/lib/commonjs/internal/fillProductsWithAdditionalData.js +0 -50
- package/lib/commonjs/internal/fillProductsWithAdditionalData.js.map +0 -1
- package/lib/commonjs/internal/index.js +0 -39
- package/lib/commonjs/internal/index.js.map +0 -1
- package/lib/commonjs/internal/platform.js +0 -119
- package/lib/commonjs/internal/platform.js.map +0 -1
- package/lib/commonjs/modules/amazon.js +0 -50
- package/lib/commonjs/modules/amazon.js.map +0 -1
- package/lib/commonjs/modules/android.js +0 -92
- package/lib/commonjs/modules/android.js.map +0 -1
- package/lib/commonjs/modules/common.js +0 -2
- package/lib/commonjs/modules/index.js +0 -50
- package/lib/commonjs/modules/index.js.map +0 -1
- package/lib/commonjs/modules/ios.js +0 -160
- package/lib/commonjs/modules/ios.js.map +0 -1
- package/lib/commonjs/modules/iosSk2.js +0 -113
- package/lib/commonjs/modules/iosSk2.js.map +0 -1
- package/lib/commonjs/purchaseError.js +0 -170
- package/lib/commonjs/purchaseError.js.map +0 -1
- package/lib/commonjs/types/amazon.js +0 -2
- package/lib/commonjs/types/amazon.js.map +0 -1
- package/lib/commonjs/types/android.js +0 -67
- package/lib/commonjs/types/android.js.map +0 -1
- package/lib/commonjs/types/apple.js +0 -24
- package/lib/commonjs/types/apple.js.map +0 -1
- package/lib/commonjs/types/appleSk2.js +0 -137
- package/lib/commonjs/types/appleSk2.js.map +0 -1
- package/lib/commonjs/types/index.js +0 -67
- package/lib/commonjs/types/index.js.map +0 -1
- package/lib/commonjs/utils/errorMapping.js +0 -83
- package/lib/commonjs/utils/errorMapping.js.map +0 -1
- package/lib/commonjs/utils/typeGuards.js +0 -74
- package/lib/commonjs/utils/typeGuards.js.map +0 -1
- package/lib/module/eventEmitter.js +0 -185
- package/lib/module/eventEmitter.js.map +0 -1
- package/lib/module/hooks/index.js +0 -2
- package/lib/module/hooks/index.js.map +0 -1
- package/lib/module/hooks/withIAPContext.js +0 -86
- package/lib/module/hooks/withIAPContext.js.map +0 -1
- package/lib/module/iap.js +0 -805
- package/lib/module/iap.js.map +0 -1
- package/lib/module/internal/enhancedFetch.js +0 -19
- package/lib/module/internal/enhancedFetch.js.map +0 -1
- package/lib/module/internal/fillProductsWithAdditionalData.js +0 -43
- package/lib/module/internal/fillProductsWithAdditionalData.js.map +0 -1
- package/lib/module/internal/index.js +0 -4
- package/lib/module/internal/index.js.map +0 -1
- package/lib/module/internal/platform.js +0 -102
- package/lib/module/internal/platform.js.map +0 -1
- package/lib/module/modules/amazon.js +0 -42
- package/lib/module/modules/amazon.js.map +0 -1
- package/lib/module/modules/android.js +0 -81
- package/lib/module/modules/android.js.map +0 -1
- package/lib/module/modules/common.js +0 -2
- package/lib/module/modules/common.js.map +0 -1
- package/lib/module/modules/index.js +0 -5
- package/lib/module/modules/index.js.map +0 -1
- package/lib/module/modules/ios.js +0 -145
- package/lib/module/modules/ios.js.map +0 -1
- package/lib/module/modules/iosSk2.js +0 -96
- package/lib/module/modules/iosSk2.js.map +0 -1
- package/lib/module/purchaseError.js +0 -164
- package/lib/module/purchaseError.js.map +0 -1
- package/lib/module/types/amazon.js +0 -2
- package/lib/module/types/amazon.js.map +0 -1
- package/lib/module/types/android.js +0 -63
- package/lib/module/types/android.js.map +0 -1
- package/lib/module/types/apple.js +0 -17
- package/lib/module/types/apple.js.map +0 -1
- package/lib/module/types/appleSk2.js +0 -129
- package/lib/module/types/appleSk2.js.map +0 -1
- package/lib/module/types/index.js +0 -75
- package/lib/module/types/index.js.map +0 -1
- package/lib/module/utils/errorMapping.js +0 -75
- package/lib/module/utils/errorMapping.js.map +0 -1
- package/lib/module/utils/typeGuards.js +0 -61
- package/lib/module/utils/typeGuards.js.map +0 -1
- package/lib/typescript/src/eventEmitter.d.ts +0 -151
- package/lib/typescript/src/eventEmitter.d.ts.map +0 -1
- package/lib/typescript/src/hooks/index.d.ts +0 -2
- package/lib/typescript/src/hooks/index.d.ts.map +0 -1
- package/lib/typescript/src/hooks/withIAPContext.d.ts +0 -27
- package/lib/typescript/src/hooks/withIAPContext.d.ts.map +0 -1
- package/lib/typescript/src/iap.d.ts +0 -503
- package/lib/typescript/src/iap.d.ts.map +0 -1
- package/lib/typescript/src/internal/enhancedFetch.d.ts +0 -6
- package/lib/typescript/src/internal/enhancedFetch.d.ts.map +0 -1
- package/lib/typescript/src/internal/fillProductsWithAdditionalData.d.ts +0 -7
- package/lib/typescript/src/internal/fillProductsWithAdditionalData.d.ts.map +0 -1
- package/lib/typescript/src/internal/index.d.ts +0 -4
- package/lib/typescript/src/internal/index.d.ts.map +0 -1
- package/lib/typescript/src/internal/platform.d.ts +0 -27
- package/lib/typescript/src/internal/platform.d.ts.map +0 -1
- package/lib/typescript/src/modules/amazon.d.ts +0 -55
- package/lib/typescript/src/modules/amazon.d.ts.map +0 -1
- package/lib/typescript/src/modules/android.d.ts +0 -74
- package/lib/typescript/src/modules/android.d.ts.map +0 -1
- package/lib/typescript/src/modules/common.d.ts +0 -14
- package/lib/typescript/src/modules/common.d.ts.map +0 -1
- package/lib/typescript/src/modules/index.d.ts +0 -5
- package/lib/typescript/src/modules/index.d.ts.map +0 -1
- package/lib/typescript/src/modules/ios.d.ts +0 -117
- package/lib/typescript/src/modules/ios.d.ts.map +0 -1
- package/lib/typescript/src/modules/iosSk2.d.ts +0 -140
- package/lib/typescript/src/modules/iosSk2.d.ts.map +0 -1
- package/lib/typescript/src/purchaseError.d.ts +0 -133
- package/lib/typescript/src/purchaseError.d.ts.map +0 -1
- package/lib/typescript/src/types/amazon.d.ts +0 -33
- package/lib/typescript/src/types/amazon.d.ts.map +0 -1
- package/lib/typescript/src/types/android.d.ts +0 -66
- package/lib/typescript/src/types/android.d.ts.map +0 -1
- package/lib/typescript/src/types/apple.d.ts +0 -27
- package/lib/typescript/src/types/apple.d.ts.map +0 -1
- package/lib/typescript/src/types/appleSk2.d.ts +0 -129
- package/lib/typescript/src/types/appleSk2.d.ts.map +0 -1
- package/lib/typescript/src/types/index.d.ts +0 -302
- package/lib/typescript/src/types/index.d.ts.map +0 -1
- package/lib/typescript/src/utils/errorMapping.d.ts +0 -29
- package/lib/typescript/src/utils/errorMapping.d.ts.map +0 -1
- package/lib/typescript/src/utils/typeGuards.d.ts +0 -53
- package/lib/typescript/src/utils/typeGuards.d.ts.map +0 -1
- package/src/eventEmitter.ts +0 -212
- package/src/hooks/index.ts +0 -1
- package/src/hooks/withIAPContext.tsx +0 -179
- package/src/iap.ts +0 -1046
- package/src/internal/enhancedFetch.ts +0 -25
- package/src/internal/fillProductsWithAdditionalData.ts +0 -47
- package/src/internal/index.ts +0 -3
- package/src/internal/platform.ts +0 -135
- package/src/modules/amazon.ts +0 -94
- package/src/modules/android.ts +0 -179
- package/src/modules/common.ts +0 -16
- package/src/modules/index.ts +0 -4
- package/src/modules/ios.ts +0 -229
- package/src/modules/iosSk2.ts +0 -194
- package/src/purchaseError.ts +0 -196
- package/src/types/amazon.ts +0 -40
- package/src/types/android.ts +0 -89
- package/src/types/apple.ts +0 -44
- package/src/types/appleSk2.ts +0 -275
- package/src/types/index.ts +0 -379
- package/src/utils/errorMapping.ts +0 -88
- package/src/utils/typeGuards.ts +0 -90
package/src/hooks/useIAP.ts
CHANGED
|
@@ -1,317 +1,456 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
1
|
+
// External dependencies
|
|
2
|
+
import { useCallback, useEffect, useState, useRef } from 'react'
|
|
3
|
+
import { Platform } from 'react-native'
|
|
3
4
|
|
|
5
|
+
// Internal modules
|
|
4
6
|
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
7
|
+
endConnection,
|
|
8
|
+
initConnection,
|
|
9
|
+
purchaseErrorListener,
|
|
10
|
+
purchaseUpdatedListener,
|
|
11
|
+
promotedProductListenerIOS,
|
|
12
|
+
getAvailablePurchases,
|
|
13
|
+
finishTransaction as finishTransactionInternal,
|
|
14
|
+
requestPurchase as requestPurchaseInternal,
|
|
15
|
+
fetchProducts,
|
|
16
|
+
validateReceipt as validateReceiptInternal,
|
|
17
|
+
getActiveSubscriptions,
|
|
18
|
+
hasActiveSubscriptions,
|
|
19
|
+
} from '../'
|
|
20
|
+
import { syncIOS, requestPromotedProductIOS, buyPromotedProductIOS } from '../'
|
|
21
|
+
|
|
22
|
+
// Types
|
|
23
|
+
import type {
|
|
24
|
+
Product,
|
|
25
|
+
Purchase,
|
|
26
|
+
PurchaseError,
|
|
27
|
+
PurchaseResult,
|
|
28
|
+
SubscriptionProduct,
|
|
29
|
+
RequestPurchaseProps,
|
|
30
|
+
RequestSubscriptionProps,
|
|
31
|
+
ActiveSubscription,
|
|
32
|
+
} from '../types'
|
|
33
|
+
|
|
34
|
+
// Types for event subscriptions
|
|
35
|
+
interface EventSubscription {
|
|
36
|
+
remove(): void
|
|
24
37
|
}
|
|
25
38
|
|
|
26
|
-
type
|
|
27
|
-
connected: boolean
|
|
28
|
-
products: Product[]
|
|
29
|
-
promotedProductsIOS:
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
availablePurchases: Purchase[]
|
|
33
|
-
currentPurchase?: Purchase
|
|
34
|
-
currentPurchaseError?: PurchaseError
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
39
|
+
type UseIap = {
|
|
40
|
+
connected: boolean
|
|
41
|
+
products: Product[]
|
|
42
|
+
promotedProductsIOS: Purchase[]
|
|
43
|
+
promotedProductIdIOS?: string
|
|
44
|
+
subscriptions: SubscriptionProduct[]
|
|
45
|
+
availablePurchases: Purchase[]
|
|
46
|
+
currentPurchase?: Purchase
|
|
47
|
+
currentPurchaseError?: PurchaseError
|
|
48
|
+
promotedProductIOS?: Product
|
|
49
|
+
activeSubscriptions: ActiveSubscription[]
|
|
50
|
+
clearCurrentPurchase: () => void
|
|
51
|
+
clearCurrentPurchaseError: () => void
|
|
38
52
|
finishTransaction: ({
|
|
39
53
|
purchase,
|
|
40
54
|
isConsumable,
|
|
41
|
-
developerPayloadAndroid,
|
|
42
55
|
}: {
|
|
43
|
-
purchase: Purchase
|
|
44
|
-
isConsumable?: boolean
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
56
|
+
purchase: Purchase
|
|
57
|
+
isConsumable?: boolean
|
|
58
|
+
}) => Promise<PurchaseResult | boolean>
|
|
59
|
+
getAvailablePurchases: () => Promise<void>
|
|
60
|
+
fetchProducts: (params: {
|
|
61
|
+
skus: string[]
|
|
62
|
+
type?: 'inapp' | 'subs'
|
|
63
|
+
}) => Promise<void>
|
|
64
|
+
/**
|
|
65
|
+
* @deprecated Use fetchProducts({ skus, type: 'inapp' }) instead. This method will be removed in version 3.0.0.
|
|
66
|
+
* Note: This method internally uses fetchProducts, so no deprecation warning is shown.
|
|
67
|
+
*/
|
|
68
|
+
getProducts: (skus: string[]) => Promise<void>
|
|
69
|
+
/**
|
|
70
|
+
* @deprecated Use fetchProducts({ skus, type: 'subs' }) instead. This method will be removed in version 3.0.0.
|
|
71
|
+
* Note: This method internally uses fetchProducts, so no deprecation warning is shown.
|
|
72
|
+
*/
|
|
73
|
+
getSubscriptions: (skus: string[]) => Promise<void>
|
|
74
|
+
requestPurchase: (params: {
|
|
75
|
+
request: RequestPurchaseProps | RequestSubscriptionProps
|
|
76
|
+
type?: 'inapp' | 'subs'
|
|
77
|
+
}) => Promise<any>
|
|
54
78
|
validateReceipt: (
|
|
55
79
|
sku: string,
|
|
56
80
|
androidOptions?: {
|
|
57
|
-
packageName: string
|
|
58
|
-
productToken: string
|
|
59
|
-
accessToken: string
|
|
60
|
-
isSub?: boolean
|
|
61
|
-
}
|
|
62
|
-
) => Promise<any
|
|
63
|
-
|
|
81
|
+
packageName: string
|
|
82
|
+
productToken: string
|
|
83
|
+
accessToken: string
|
|
84
|
+
isSub?: boolean
|
|
85
|
+
}
|
|
86
|
+
) => Promise<any>
|
|
87
|
+
restorePurchases: () => Promise<void> // 구매 복원 함수 추가
|
|
88
|
+
requestPromotedProductIOS: () => Promise<any | null>
|
|
89
|
+
buyPromotedProductIOS: () => Promise<void>
|
|
90
|
+
getActiveSubscriptions: (
|
|
91
|
+
subscriptionIds?: string[]
|
|
92
|
+
) => Promise<ActiveSubscription[]>
|
|
93
|
+
hasActiveSubscriptions: (subscriptionIds?: string[]) => Promise<boolean>
|
|
94
|
+
}
|
|
64
95
|
|
|
65
|
-
export
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
availablePurchases,
|
|
73
|
-
currentPurchase,
|
|
74
|
-
currentPurchaseError,
|
|
75
|
-
initConnectionError,
|
|
76
|
-
setConnected,
|
|
77
|
-
setProducts,
|
|
78
|
-
setSubscriptions,
|
|
79
|
-
setAvailablePurchases,
|
|
80
|
-
setPurchaseHistory,
|
|
81
|
-
setCurrentPurchase,
|
|
82
|
-
setCurrentPurchaseError,
|
|
83
|
-
} = useIAPContext();
|
|
84
|
-
|
|
85
|
-
const optionsRef = useRef<UseIAPOptions | undefined>(options);
|
|
96
|
+
export interface UseIapOptions {
|
|
97
|
+
onPurchaseSuccess?: (purchase: Purchase) => void
|
|
98
|
+
onPurchaseError?: (error: PurchaseError) => void
|
|
99
|
+
onSyncError?: (error: Error) => void
|
|
100
|
+
shouldAutoSyncPurchases?: boolean // New option to control auto-syncing
|
|
101
|
+
onPromotedProductIOS?: (product: Product) => void
|
|
102
|
+
}
|
|
86
103
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
104
|
+
/**
|
|
105
|
+
* React Hook for managing In-App Purchases.
|
|
106
|
+
* See documentation at https://expo-iap.hyo.dev/docs/hooks/useIAP
|
|
107
|
+
*/
|
|
108
|
+
export function useIAP(options?: UseIapOptions): UseIap {
|
|
109
|
+
const [connected, setConnected] = useState<boolean>(false)
|
|
110
|
+
const [products, setProducts] = useState<Product[]>([])
|
|
111
|
+
const [promotedProductsIOS] = useState<Purchase[]>([])
|
|
112
|
+
const [subscriptions, setSubscriptions] = useState<SubscriptionProduct[]>([])
|
|
113
|
+
const [availablePurchases, setAvailablePurchases] = useState<Purchase[]>([])
|
|
114
|
+
const [currentPurchase, setCurrentPurchase] = useState<Purchase>()
|
|
115
|
+
const [promotedProductIOS, setPromotedProductIOS] = useState<Product>()
|
|
116
|
+
const [currentPurchaseError, setCurrentPurchaseError] =
|
|
117
|
+
useState<PurchaseError>()
|
|
118
|
+
const [promotedProductIdIOS] = useState<string>()
|
|
119
|
+
const [activeSubscriptions, setActiveSubscriptions] = useState<
|
|
120
|
+
ActiveSubscription[]
|
|
121
|
+
>([])
|
|
122
|
+
|
|
123
|
+
const optionsRef = useRef<UseIapOptions | undefined>(options)
|
|
90
124
|
|
|
91
125
|
// Helper function to merge arrays with duplicate checking
|
|
92
126
|
const mergeWithDuplicateCheck = useCallback(
|
|
93
127
|
<T>(
|
|
94
128
|
existingItems: T[],
|
|
95
129
|
newItems: T[],
|
|
96
|
-
getKey: (item: T) => string
|
|
130
|
+
getKey: (item: T) => string
|
|
97
131
|
): T[] => {
|
|
98
|
-
const merged = [...existingItems]
|
|
132
|
+
const merged = [...existingItems]
|
|
99
133
|
newItems.forEach((newItem) => {
|
|
100
134
|
const isDuplicate = merged.some(
|
|
101
|
-
(existingItem) => getKey(existingItem) === getKey(newItem)
|
|
102
|
-
)
|
|
135
|
+
(existingItem) => getKey(existingItem) === getKey(newItem)
|
|
136
|
+
)
|
|
103
137
|
if (!isDuplicate) {
|
|
104
|
-
merged.push(newItem)
|
|
138
|
+
merged.push(newItem)
|
|
105
139
|
}
|
|
106
|
-
})
|
|
107
|
-
return merged
|
|
140
|
+
})
|
|
141
|
+
return merged
|
|
108
142
|
},
|
|
109
|
-
[]
|
|
110
|
-
)
|
|
143
|
+
[]
|
|
144
|
+
)
|
|
145
|
+
|
|
146
|
+
useEffect(() => {
|
|
147
|
+
optionsRef.current = options
|
|
148
|
+
}, [options])
|
|
149
|
+
|
|
150
|
+
const subscriptionsRef = useRef<{
|
|
151
|
+
purchaseUpdate?: EventSubscription
|
|
152
|
+
purchaseError?: EventSubscription
|
|
153
|
+
promotedProductsIOS?: EventSubscription
|
|
154
|
+
promotedProductIOS?: EventSubscription
|
|
155
|
+
}>({})
|
|
156
|
+
|
|
157
|
+
const subscriptionsRefState = useRef<SubscriptionProduct[]>([])
|
|
158
|
+
|
|
159
|
+
useEffect(() => {
|
|
160
|
+
subscriptionsRefState.current = subscriptions
|
|
161
|
+
}, [subscriptions])
|
|
111
162
|
|
|
112
163
|
const clearCurrentPurchase = useCallback(() => {
|
|
113
|
-
setCurrentPurchase(undefined)
|
|
114
|
-
}, [
|
|
164
|
+
setCurrentPurchase(undefined)
|
|
165
|
+
}, [])
|
|
115
166
|
|
|
116
167
|
const clearCurrentPurchaseError = useCallback(() => {
|
|
117
|
-
setCurrentPurchaseError(undefined)
|
|
118
|
-
}, [
|
|
168
|
+
setCurrentPurchaseError(undefined)
|
|
169
|
+
}, [])
|
|
119
170
|
|
|
120
|
-
const
|
|
121
|
-
async (
|
|
171
|
+
const getProductsInternal = useCallback(
|
|
172
|
+
async (skus: string[]): Promise<void> => {
|
|
122
173
|
try {
|
|
123
|
-
const result = await
|
|
124
|
-
setProducts(
|
|
174
|
+
const result = await fetchProducts({ skus, type: 'inapp' })
|
|
175
|
+
setProducts((prevProducts: Product[]) =>
|
|
125
176
|
mergeWithDuplicateCheck(
|
|
126
|
-
|
|
127
|
-
result,
|
|
128
|
-
(product) =>
|
|
129
|
-
)
|
|
130
|
-
)
|
|
177
|
+
prevProducts,
|
|
178
|
+
result as Product[],
|
|
179
|
+
(product: Product) => product.id
|
|
180
|
+
)
|
|
181
|
+
)
|
|
131
182
|
} catch (error) {
|
|
132
|
-
console.error('Error
|
|
183
|
+
console.error('Error fetching products:', error)
|
|
133
184
|
}
|
|
134
185
|
},
|
|
135
|
-
[
|
|
136
|
-
)
|
|
186
|
+
[mergeWithDuplicateCheck]
|
|
187
|
+
)
|
|
137
188
|
|
|
138
|
-
const
|
|
139
|
-
async (
|
|
189
|
+
const getSubscriptionsInternal = useCallback(
|
|
190
|
+
async (skus: string[]): Promise<void> => {
|
|
140
191
|
try {
|
|
141
|
-
const result = await
|
|
142
|
-
setSubscriptions(
|
|
192
|
+
const result = await fetchProducts({ skus, type: 'subs' })
|
|
193
|
+
setSubscriptions((prevSubscriptions: SubscriptionProduct[]) =>
|
|
143
194
|
mergeWithDuplicateCheck(
|
|
144
|
-
|
|
145
|
-
result,
|
|
146
|
-
(subscription) =>
|
|
147
|
-
)
|
|
148
|
-
)
|
|
195
|
+
prevSubscriptions,
|
|
196
|
+
result as SubscriptionProduct[],
|
|
197
|
+
(subscription: SubscriptionProduct) => subscription.id
|
|
198
|
+
)
|
|
199
|
+
)
|
|
149
200
|
} catch (error) {
|
|
150
|
-
console.error('Error
|
|
201
|
+
console.error('Error fetching subscriptions:', error)
|
|
151
202
|
}
|
|
152
203
|
},
|
|
153
|
-
[
|
|
154
|
-
)
|
|
204
|
+
[mergeWithDuplicateCheck]
|
|
205
|
+
)
|
|
155
206
|
|
|
156
|
-
const
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
207
|
+
const fetchProductsInternal = useCallback(
|
|
208
|
+
async (params: {
|
|
209
|
+
skus: string[]
|
|
210
|
+
type?: 'inapp' | 'subs'
|
|
211
|
+
}): Promise<void> => {
|
|
212
|
+
try {
|
|
213
|
+
const result = await fetchProducts(params)
|
|
214
|
+
if (params.type === 'subs') {
|
|
215
|
+
setSubscriptions((prevSubscriptions: SubscriptionProduct[]) =>
|
|
216
|
+
mergeWithDuplicateCheck(
|
|
217
|
+
prevSubscriptions,
|
|
218
|
+
result as SubscriptionProduct[],
|
|
219
|
+
(subscription: SubscriptionProduct) => subscription.id
|
|
220
|
+
)
|
|
221
|
+
)
|
|
222
|
+
} else {
|
|
223
|
+
setProducts((prevProducts: Product[]) =>
|
|
224
|
+
mergeWithDuplicateCheck(
|
|
225
|
+
prevProducts,
|
|
226
|
+
result as Product[],
|
|
227
|
+
(product: Product) => product.id
|
|
228
|
+
)
|
|
229
|
+
)
|
|
230
|
+
}
|
|
231
|
+
} catch (error) {
|
|
232
|
+
console.error('Error fetching products:', error)
|
|
233
|
+
}
|
|
234
|
+
},
|
|
235
|
+
[mergeWithDuplicateCheck]
|
|
236
|
+
)
|
|
164
237
|
|
|
165
|
-
const
|
|
238
|
+
const getAvailablePurchasesInternal = useCallback(async (): Promise<void> => {
|
|
166
239
|
try {
|
|
167
|
-
const result = await
|
|
168
|
-
|
|
240
|
+
const result = await getAvailablePurchases()
|
|
241
|
+
setAvailablePurchases(result)
|
|
169
242
|
} catch (error) {
|
|
170
|
-
console.error('Error
|
|
243
|
+
console.error('Error fetching available purchases:', error)
|
|
171
244
|
}
|
|
172
|
-
}, [
|
|
245
|
+
}, [])
|
|
246
|
+
|
|
247
|
+
const getActiveSubscriptionsInternal = useCallback(
|
|
248
|
+
async (subscriptionIds?: string[]): Promise<ActiveSubscription[]> => {
|
|
249
|
+
try {
|
|
250
|
+
const result = await getActiveSubscriptions(subscriptionIds)
|
|
251
|
+
setActiveSubscriptions(result)
|
|
252
|
+
return result
|
|
253
|
+
} catch (error) {
|
|
254
|
+
console.error('Error getting active subscriptions:', error)
|
|
255
|
+
// Don't clear existing activeSubscriptions on error - preserve current state
|
|
256
|
+
// This prevents the UI from showing empty state when there are temporary network issues
|
|
257
|
+
return []
|
|
258
|
+
}
|
|
259
|
+
},
|
|
260
|
+
[]
|
|
261
|
+
)
|
|
262
|
+
|
|
263
|
+
const hasActiveSubscriptionsInternal = useCallback(
|
|
264
|
+
async (subscriptionIds?: string[]): Promise<boolean> => {
|
|
265
|
+
try {
|
|
266
|
+
return await hasActiveSubscriptions(subscriptionIds)
|
|
267
|
+
} catch (error) {
|
|
268
|
+
console.error('Error checking active subscriptions:', error)
|
|
269
|
+
return false
|
|
270
|
+
}
|
|
271
|
+
},
|
|
272
|
+
[]
|
|
273
|
+
)
|
|
173
274
|
|
|
174
275
|
const finishTransaction = useCallback(
|
|
175
276
|
async ({
|
|
176
277
|
purchase,
|
|
177
278
|
isConsumable,
|
|
178
|
-
developerPayloadAndroid,
|
|
179
279
|
}: {
|
|
180
|
-
purchase: Purchase
|
|
181
|
-
isConsumable?: boolean
|
|
182
|
-
|
|
183
|
-
}): Promise<string | boolean | PurchaseResult | void> => {
|
|
280
|
+
purchase: Purchase
|
|
281
|
+
isConsumable?: boolean
|
|
282
|
+
}): Promise<PurchaseResult | boolean> => {
|
|
184
283
|
try {
|
|
185
|
-
return await
|
|
284
|
+
return await finishTransactionInternal({
|
|
186
285
|
purchase,
|
|
187
286
|
isConsumable,
|
|
188
|
-
|
|
189
|
-
});
|
|
287
|
+
})
|
|
190
288
|
} catch (err) {
|
|
191
|
-
throw err
|
|
289
|
+
throw err
|
|
192
290
|
} finally {
|
|
193
|
-
if (purchase.
|
|
194
|
-
|
|
291
|
+
if (purchase.id === currentPurchase?.id) {
|
|
292
|
+
clearCurrentPurchase()
|
|
195
293
|
}
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
setCurrentPurchaseError(undefined);
|
|
294
|
+
if (purchase.id === currentPurchaseError?.productId) {
|
|
295
|
+
clearCurrentPurchaseError()
|
|
199
296
|
}
|
|
200
297
|
}
|
|
201
298
|
},
|
|
202
299
|
[
|
|
203
|
-
currentPurchase?.
|
|
300
|
+
currentPurchase?.id,
|
|
204
301
|
currentPurchaseError?.productId,
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
]
|
|
208
|
-
)
|
|
302
|
+
clearCurrentPurchase,
|
|
303
|
+
clearCurrentPurchaseError,
|
|
304
|
+
]
|
|
305
|
+
)
|
|
209
306
|
|
|
210
|
-
const
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
307
|
+
const requestPurchaseWithReset = useCallback(
|
|
308
|
+
async (requestObj: { request: any; type?: 'inapp' | 'subs' }) => {
|
|
309
|
+
clearCurrentPurchase()
|
|
310
|
+
clearCurrentPurchaseError()
|
|
311
|
+
|
|
312
|
+
try {
|
|
313
|
+
return await requestPurchaseInternal(requestObj)
|
|
314
|
+
} catch (error) {
|
|
315
|
+
throw error
|
|
316
|
+
}
|
|
317
|
+
},
|
|
318
|
+
[clearCurrentPurchase, clearCurrentPurchaseError]
|
|
319
|
+
)
|
|
320
|
+
|
|
321
|
+
const refreshSubscriptionStatus = useCallback(
|
|
322
|
+
async (productId: string) => {
|
|
323
|
+
try {
|
|
324
|
+
if (
|
|
325
|
+
subscriptionsRefState.current.some(
|
|
326
|
+
(sub: SubscriptionProduct) => sub.id === productId
|
|
327
|
+
)
|
|
328
|
+
) {
|
|
329
|
+
await getSubscriptionsInternal([productId])
|
|
330
|
+
await getAvailablePurchasesInternal()
|
|
222
331
|
}
|
|
332
|
+
} catch (error) {
|
|
333
|
+
console.warn('Failed to refresh subscription status:', error)
|
|
223
334
|
}
|
|
335
|
+
},
|
|
336
|
+
[getAvailablePurchasesInternal, getSubscriptionsInternal]
|
|
337
|
+
)
|
|
224
338
|
|
|
225
|
-
|
|
226
|
-
|
|
339
|
+
const restorePurchases = useCallback(async (): Promise<void> => {
|
|
340
|
+
try {
|
|
341
|
+
if (Platform.OS === 'ios') {
|
|
342
|
+
await syncIOS().catch((error) => {
|
|
343
|
+
if (optionsRef.current?.onSyncError) {
|
|
344
|
+
optionsRef.current.onSyncError(error)
|
|
345
|
+
} else {
|
|
346
|
+
console.warn('Error restoring purchases:', error)
|
|
347
|
+
}
|
|
348
|
+
})
|
|
349
|
+
}
|
|
350
|
+
await getAvailablePurchasesInternal()
|
|
227
351
|
} catch (error) {
|
|
228
|
-
console.
|
|
229
|
-
throw error;
|
|
352
|
+
console.warn('Failed to restore purchases:', error)
|
|
230
353
|
}
|
|
231
|
-
}, [
|
|
354
|
+
}, [getAvailablePurchasesInternal])
|
|
232
355
|
|
|
233
356
|
const validateReceipt = useCallback(
|
|
234
357
|
async (
|
|
235
358
|
sku: string,
|
|
236
359
|
androidOptions?: {
|
|
237
|
-
packageName: string
|
|
238
|
-
productToken: string
|
|
239
|
-
accessToken: string
|
|
240
|
-
isSub?: boolean
|
|
241
|
-
},
|
|
242
|
-
): Promise<any> => {
|
|
243
|
-
try {
|
|
244
|
-
if (Platform.OS === 'ios') {
|
|
245
|
-
// For iOS, use the new validateReceiptIos function
|
|
246
|
-
const result = await validateReceiptIos(sku);
|
|
247
|
-
return result;
|
|
248
|
-
} else if (Platform.OS === 'android' && androidOptions) {
|
|
249
|
-
// For Android, you would need to implement server-side validation
|
|
250
|
-
// This is a placeholder - Android validation should be done server-side
|
|
251
|
-
console.warn(
|
|
252
|
-
'Android receipt validation should be performed server-side',
|
|
253
|
-
);
|
|
254
|
-
return {
|
|
255
|
-
isValid: false,
|
|
256
|
-
message:
|
|
257
|
-
'Android receipt validation should be performed server-side',
|
|
258
|
-
};
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
throw new Error(
|
|
262
|
-
'Invalid platform or missing options for receipt validation',
|
|
263
|
-
);
|
|
264
|
-
} catch (error) {
|
|
265
|
-
console.error('Error validating receipt:', error);
|
|
266
|
-
throw error;
|
|
360
|
+
packageName: string
|
|
361
|
+
productToken: string
|
|
362
|
+
accessToken: string
|
|
363
|
+
isSub?: boolean
|
|
267
364
|
}
|
|
365
|
+
) => {
|
|
366
|
+
return validateReceiptInternal(sku, androidOptions)
|
|
268
367
|
},
|
|
269
|
-
[]
|
|
270
|
-
)
|
|
368
|
+
[]
|
|
369
|
+
)
|
|
271
370
|
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
optionsRef.current.onPurchaseSuccess(currentPurchase);
|
|
276
|
-
}
|
|
277
|
-
}, [currentPurchase]);
|
|
371
|
+
const initIapWithSubscriptions = useCallback(async (): Promise<void> => {
|
|
372
|
+
const result = await initConnection()
|
|
373
|
+
setConnected(result)
|
|
278
374
|
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
375
|
+
if (result) {
|
|
376
|
+
subscriptionsRef.current.purchaseUpdate = purchaseUpdatedListener(
|
|
377
|
+
async (purchase: Purchase) => {
|
|
378
|
+
setCurrentPurchaseError(undefined)
|
|
379
|
+
setCurrentPurchase(purchase)
|
|
380
|
+
|
|
381
|
+
if ('expirationDateIOS' in purchase) {
|
|
382
|
+
await refreshSubscriptionStatus(purchase.id)
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
if (optionsRef.current?.onPurchaseSuccess) {
|
|
386
|
+
optionsRef.current.onPurchaseSuccess(purchase)
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
)
|
|
390
|
+
|
|
391
|
+
subscriptionsRef.current.purchaseError = purchaseErrorListener(
|
|
392
|
+
(error: PurchaseError) => {
|
|
393
|
+
setCurrentPurchase(undefined)
|
|
394
|
+
setCurrentPurchaseError(error)
|
|
395
|
+
|
|
396
|
+
if (optionsRef.current?.onPurchaseError) {
|
|
397
|
+
optionsRef.current.onPurchaseError(error)
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
)
|
|
401
|
+
|
|
402
|
+
if (Platform.OS === 'ios') {
|
|
403
|
+
// iOS promoted products listener
|
|
404
|
+
subscriptionsRef.current.promotedProductsIOS =
|
|
405
|
+
promotedProductListenerIOS((product: Product) => {
|
|
406
|
+
setPromotedProductIOS(product)
|
|
407
|
+
|
|
408
|
+
if (optionsRef.current?.onPromotedProductIOS) {
|
|
409
|
+
optionsRef.current.onPromotedProductIOS(product)
|
|
410
|
+
}
|
|
411
|
+
})
|
|
412
|
+
}
|
|
282
413
|
}
|
|
283
|
-
}, [
|
|
414
|
+
}, [refreshSubscriptionStatus])
|
|
284
415
|
|
|
285
416
|
useEffect(() => {
|
|
286
|
-
|
|
417
|
+
initIapWithSubscriptions()
|
|
418
|
+
const currentSubscriptions = subscriptionsRef.current
|
|
287
419
|
|
|
288
420
|
return () => {
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
421
|
+
currentSubscriptions.purchaseUpdate?.remove()
|
|
422
|
+
currentSubscriptions.purchaseError?.remove()
|
|
423
|
+
currentSubscriptions.promotedProductsIOS?.remove()
|
|
424
|
+
currentSubscriptions.promotedProductIOS?.remove()
|
|
425
|
+
endConnection()
|
|
426
|
+
setConnected(false)
|
|
427
|
+
}
|
|
428
|
+
}, [initIapWithSubscriptions])
|
|
294
429
|
|
|
295
430
|
return {
|
|
296
431
|
connected,
|
|
297
432
|
products,
|
|
298
433
|
promotedProductsIOS,
|
|
434
|
+
promotedProductIdIOS,
|
|
299
435
|
subscriptions,
|
|
300
|
-
|
|
436
|
+
finishTransaction,
|
|
301
437
|
availablePurchases,
|
|
302
438
|
currentPurchase,
|
|
303
439
|
currentPurchaseError,
|
|
304
|
-
|
|
440
|
+
promotedProductIOS,
|
|
441
|
+
activeSubscriptions,
|
|
305
442
|
clearCurrentPurchase,
|
|
306
443
|
clearCurrentPurchaseError,
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
getAvailablePurchases,
|
|
311
|
-
getPurchaseHistory,
|
|
312
|
-
requestPurchase: iapRequestPurchase,
|
|
313
|
-
requestSubscription: iapRequestSubscription,
|
|
314
|
-
restorePurchases,
|
|
444
|
+
getAvailablePurchases: getAvailablePurchasesInternal,
|
|
445
|
+
fetchProducts: fetchProductsInternal,
|
|
446
|
+
requestPurchase: requestPurchaseWithReset,
|
|
315
447
|
validateReceipt,
|
|
316
|
-
|
|
317
|
-
|
|
448
|
+
restorePurchases,
|
|
449
|
+
getProducts: getProductsInternal,
|
|
450
|
+
getSubscriptions: getSubscriptionsInternal,
|
|
451
|
+
requestPromotedProductIOS,
|
|
452
|
+
buyPromotedProductIOS,
|
|
453
|
+
getActiveSubscriptions: getActiveSubscriptionsInternal,
|
|
454
|
+
hasActiveSubscriptions: hasActiveSubscriptionsInternal,
|
|
455
|
+
}
|
|
456
|
+
}
|