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
|
@@ -1,911 +0,0 @@
|
|
|
1
|
-
package com.dooboolab.rniap
|
|
2
|
-
|
|
3
|
-
import android.util.Log
|
|
4
|
-
import com.android.billingclient.api.AcknowledgePurchaseParams
|
|
5
|
-
import com.android.billingclient.api.BillingClient
|
|
6
|
-
import com.android.billingclient.api.BillingClientStateListener
|
|
7
|
-
import com.android.billingclient.api.BillingConfig
|
|
8
|
-
import com.android.billingclient.api.BillingConfigResponseListener
|
|
9
|
-
import com.android.billingclient.api.BillingFlowParams
|
|
10
|
-
import com.android.billingclient.api.BillingFlowParams.SubscriptionUpdateParams
|
|
11
|
-
import com.android.billingclient.api.BillingResult
|
|
12
|
-
import com.android.billingclient.api.ConsumeParams
|
|
13
|
-
import com.android.billingclient.api.ConsumeResponseListener
|
|
14
|
-
import com.android.billingclient.api.GetBillingConfigParams
|
|
15
|
-
import com.android.billingclient.api.GetBillingConfigParams.Builder
|
|
16
|
-
import com.android.billingclient.api.ProductDetails
|
|
17
|
-
import com.android.billingclient.api.Purchase
|
|
18
|
-
import com.android.billingclient.api.PurchaseHistoryRecord
|
|
19
|
-
import com.android.billingclient.api.PurchasesUpdatedListener
|
|
20
|
-
import com.android.billingclient.api.QueryProductDetailsParams
|
|
21
|
-
import com.android.billingclient.api.QueryPurchaseHistoryParams
|
|
22
|
-
import com.android.billingclient.api.QueryPurchasesParams
|
|
23
|
-
import com.facebook.react.bridge.Arguments
|
|
24
|
-
import com.facebook.react.bridge.LifecycleEventListener
|
|
25
|
-
import com.facebook.react.bridge.Promise
|
|
26
|
-
import com.facebook.react.bridge.PromiseImpl
|
|
27
|
-
import com.facebook.react.bridge.ReactApplicationContext
|
|
28
|
-
import com.facebook.react.bridge.ReactContext
|
|
29
|
-
import com.facebook.react.bridge.ReactContextBaseJavaModule
|
|
30
|
-
import com.facebook.react.bridge.ReactMethod
|
|
31
|
-
import com.facebook.react.bridge.ReadableArray
|
|
32
|
-
import com.facebook.react.bridge.ReadableType
|
|
33
|
-
import com.facebook.react.bridge.WritableArray
|
|
34
|
-
import com.facebook.react.bridge.WritableMap
|
|
35
|
-
import com.facebook.react.bridge.WritableNativeArray
|
|
36
|
-
import com.facebook.react.bridge.WritableNativeMap
|
|
37
|
-
import com.facebook.react.module.annotations.ReactModule
|
|
38
|
-
import com.facebook.react.modules.core.DeviceEventManagerModule.RCTDeviceEventEmitter
|
|
39
|
-
import com.google.android.gms.common.ConnectionResult
|
|
40
|
-
import com.google.android.gms.common.GoogleApiAvailability
|
|
41
|
-
|
|
42
|
-
@ReactModule(name = RNIapModule.TAG)
|
|
43
|
-
class RNIapModule(
|
|
44
|
-
private val reactContext: ReactApplicationContext,
|
|
45
|
-
private val builder: BillingClient.Builder = BillingClient.newBuilder(reactContext).enablePendingPurchases(),
|
|
46
|
-
private val googleApiAvailability: GoogleApiAvailability = GoogleApiAvailability.getInstance(),
|
|
47
|
-
) : ReactContextBaseJavaModule(reactContext),
|
|
48
|
-
PurchasesUpdatedListener {
|
|
49
|
-
private var billingClientCache: BillingClient? = null
|
|
50
|
-
private val skus: MutableMap<String, ProductDetails> = mutableMapOf()
|
|
51
|
-
|
|
52
|
-
override fun getName(): String = TAG
|
|
53
|
-
|
|
54
|
-
fun ensureConnection(
|
|
55
|
-
promise: Promise,
|
|
56
|
-
callback: (billingClient: BillingClient) -> Unit,
|
|
57
|
-
) {
|
|
58
|
-
val billingClient = billingClientCache
|
|
59
|
-
if (billingClient?.isReady == true) {
|
|
60
|
-
callback(billingClient)
|
|
61
|
-
return
|
|
62
|
-
} else {
|
|
63
|
-
val nested =
|
|
64
|
-
PromiseImpl(
|
|
65
|
-
{
|
|
66
|
-
if (it.isNotEmpty() && it[0] is Boolean && it[0] as Boolean) {
|
|
67
|
-
val connectedBillingClient = billingClientCache
|
|
68
|
-
if (connectedBillingClient?.isReady == true) {
|
|
69
|
-
callback(connectedBillingClient)
|
|
70
|
-
} else {
|
|
71
|
-
promise.safeReject(PromiseUtils.E_NOT_PREPARED, "Unable to auto-initialize connection")
|
|
72
|
-
}
|
|
73
|
-
} else {
|
|
74
|
-
promise.safeReject(PromiseUtils.E_UNKNOWN, "ensureConnection - incorrect parameter in resolve")
|
|
75
|
-
Log.i(TAG, "Incorrect parameter in resolve")
|
|
76
|
-
}
|
|
77
|
-
},
|
|
78
|
-
{
|
|
79
|
-
var errorCode: String? = null
|
|
80
|
-
var errorMessage: String? = null
|
|
81
|
-
if (it.size > 1 && it[0] is String && it[1] is String) {
|
|
82
|
-
errorCode = it[0] as String
|
|
83
|
-
errorMessage = it[1] as String
|
|
84
|
-
} else if (it.isNotEmpty() && it[0] is WritableNativeMap) {
|
|
85
|
-
val errorMap = it[0] as WritableNativeMap
|
|
86
|
-
errorCode = errorMap.getString("code")
|
|
87
|
-
errorMessage = errorMap.getString("message")
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
if (errorCode is String && errorMessage is String) {
|
|
91
|
-
promise.safeReject(
|
|
92
|
-
errorCode,
|
|
93
|
-
errorMessage,
|
|
94
|
-
)
|
|
95
|
-
} else {
|
|
96
|
-
promise.safeReject(PromiseUtils.E_UNKNOWN, "ensureConnection - incorrect parameter in reject")
|
|
97
|
-
Log.i(TAG, "Incorrect parameters in reject")
|
|
98
|
-
}
|
|
99
|
-
},
|
|
100
|
-
)
|
|
101
|
-
initConnection(nested)
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
@ReactMethod
|
|
106
|
-
fun isFeatureSupported(
|
|
107
|
-
feature: String,
|
|
108
|
-
promise: Promise,
|
|
109
|
-
) {
|
|
110
|
-
ensureConnection(
|
|
111
|
-
promise,
|
|
112
|
-
) { billingClient ->
|
|
113
|
-
val f =
|
|
114
|
-
when (feature) {
|
|
115
|
-
"IN_APP_MESSAGING" ->
|
|
116
|
-
BillingClient.FeatureType.IN_APP_MESSAGING
|
|
117
|
-
"PRICE_CHANGE_CONFIRMATION" ->
|
|
118
|
-
BillingClient.FeatureType.PRICE_CHANGE_CONFIRMATION
|
|
119
|
-
"PRODUCT_DETAILS" ->
|
|
120
|
-
BillingClient.FeatureType.PRODUCT_DETAILS
|
|
121
|
-
"SUBSCRIPTIONS" ->
|
|
122
|
-
BillingClient.FeatureType.SUBSCRIPTIONS
|
|
123
|
-
"SUBSCRIPTIONS_UPDATE" ->
|
|
124
|
-
BillingClient.FeatureType.SUBSCRIPTIONS_UPDATE
|
|
125
|
-
else -> {
|
|
126
|
-
promise.safeReject("Invalid Feature name")
|
|
127
|
-
return@ensureConnection
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
promise.safeResolve(billingClient.isFeatureSupported(f))
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
@ReactMethod
|
|
135
|
-
fun initConnection(promise: Promise) {
|
|
136
|
-
if (googleApiAvailability.isGooglePlayServicesAvailable(reactContext)
|
|
137
|
-
!= ConnectionResult.SUCCESS
|
|
138
|
-
) {
|
|
139
|
-
Log.i(TAG, "Google Play Services are not available on this device")
|
|
140
|
-
promise.safeReject(PromiseUtils.E_NOT_PREPARED, "Google Play Services are not available on this device")
|
|
141
|
-
return
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
if (billingClientCache?.isReady == true) {
|
|
145
|
-
Log.i(
|
|
146
|
-
TAG,
|
|
147
|
-
"Already initialized, you should only call initConnection() once when your app starts",
|
|
148
|
-
)
|
|
149
|
-
promise.safeResolve(true)
|
|
150
|
-
return
|
|
151
|
-
}
|
|
152
|
-
builder.setListener(this).build().also {
|
|
153
|
-
billingClientCache = it
|
|
154
|
-
it.startConnection(
|
|
155
|
-
object : BillingClientStateListener {
|
|
156
|
-
override fun onBillingSetupFinished(billingResult: BillingResult) {
|
|
157
|
-
if (!isValidResult(billingResult, promise)) return
|
|
158
|
-
|
|
159
|
-
promise.safeResolve(true)
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
override fun onBillingServiceDisconnected() {
|
|
163
|
-
Log.i(TAG, "Billing service disconnected")
|
|
164
|
-
}
|
|
165
|
-
},
|
|
166
|
-
)
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
@ReactMethod
|
|
171
|
-
fun endConnection(promise: Promise) {
|
|
172
|
-
billingClientCache?.endConnection()
|
|
173
|
-
billingClientCache = null
|
|
174
|
-
skus.clear()
|
|
175
|
-
PromiseUtils.rejectAllPendingPromises()
|
|
176
|
-
promise.safeResolve(true)
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
private fun consumeItems(
|
|
180
|
-
purchases: List<Purchase>,
|
|
181
|
-
promise: Promise,
|
|
182
|
-
expectedResponseCode: Int = BillingClient.BillingResponseCode.OK,
|
|
183
|
-
) {
|
|
184
|
-
for (purchase in purchases) {
|
|
185
|
-
ensureConnection(
|
|
186
|
-
promise,
|
|
187
|
-
) { billingClient ->
|
|
188
|
-
val consumeParams =
|
|
189
|
-
ConsumeParams
|
|
190
|
-
.newBuilder()
|
|
191
|
-
.setPurchaseToken(purchase.purchaseToken)
|
|
192
|
-
.build()
|
|
193
|
-
val listener =
|
|
194
|
-
ConsumeResponseListener { billingResult: BillingResult, outToken: String? ->
|
|
195
|
-
if (billingResult.responseCode != expectedResponseCode) {
|
|
196
|
-
PlayUtils.rejectPromiseWithBillingError(
|
|
197
|
-
promise,
|
|
198
|
-
billingResult.responseCode,
|
|
199
|
-
)
|
|
200
|
-
return@ConsumeResponseListener
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
promise.safeResolve(true)
|
|
204
|
-
}
|
|
205
|
-
billingClient.consumeAsync(consumeParams, listener)
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
@ReactMethod
|
|
211
|
-
fun flushFailedPurchasesCachedAsPending(promise: Promise) {
|
|
212
|
-
ensureConnection(
|
|
213
|
-
promise,
|
|
214
|
-
) { billingClient ->
|
|
215
|
-
billingClient.queryPurchasesAsync(
|
|
216
|
-
QueryPurchasesParams
|
|
217
|
-
.newBuilder()
|
|
218
|
-
.setProductType(
|
|
219
|
-
BillingClient.ProductType.INAPP,
|
|
220
|
-
).build(),
|
|
221
|
-
) { billingResult: BillingResult, list: List<Purchase>? ->
|
|
222
|
-
if (!isValidResult(billingResult, promise)) return@queryPurchasesAsync
|
|
223
|
-
if (list == null) {
|
|
224
|
-
// No purchases found
|
|
225
|
-
promise.safeResolve(false)
|
|
226
|
-
return@queryPurchasesAsync
|
|
227
|
-
}
|
|
228
|
-
// we only want to try to consume PENDING items, in order to force cache-refresh
|
|
229
|
-
// for them
|
|
230
|
-
val pendingPurchases = list.filter { it.purchaseState == Purchase.PurchaseState.PENDING }
|
|
231
|
-
|
|
232
|
-
if (pendingPurchases.isEmpty()) {
|
|
233
|
-
promise.safeResolve(false)
|
|
234
|
-
return@queryPurchasesAsync
|
|
235
|
-
}
|
|
236
|
-
consumeItems(
|
|
237
|
-
pendingPurchases,
|
|
238
|
-
promise,
|
|
239
|
-
BillingClient.BillingResponseCode.ITEM_NOT_OWNED,
|
|
240
|
-
)
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
@ReactMethod
|
|
246
|
-
fun getItemsByType(
|
|
247
|
-
type: String,
|
|
248
|
-
skuArr: ReadableArray,
|
|
249
|
-
promise: Promise,
|
|
250
|
-
) {
|
|
251
|
-
ensureConnection(promise) { billingClient ->
|
|
252
|
-
val skuList = mutableListOf<QueryProductDetailsParams.Product>()
|
|
253
|
-
for (i in 0 until skuArr.size()) {
|
|
254
|
-
if (skuArr.getType(i) == ReadableType.String) {
|
|
255
|
-
skuArr.getString(i)?.let { sku ->
|
|
256
|
-
skuList.add(
|
|
257
|
-
QueryProductDetailsParams.Product
|
|
258
|
-
.newBuilder()
|
|
259
|
-
.setProductId(sku)
|
|
260
|
-
.setProductType(type)
|
|
261
|
-
.build(),
|
|
262
|
-
)
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
if (skuList.isEmpty()) {
|
|
268
|
-
promise.safeReject("EMPTY_SKU_LIST", "The SKU list is empty.")
|
|
269
|
-
return@ensureConnection
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
val params =
|
|
273
|
-
QueryProductDetailsParams
|
|
274
|
-
.newBuilder()
|
|
275
|
-
.setProductList(skuList)
|
|
276
|
-
.build()
|
|
277
|
-
|
|
278
|
-
billingClient.queryProductDetailsAsync(params) { billingResult, skuDetailsList ->
|
|
279
|
-
if (!isValidResult(billingResult, promise)) return@queryProductDetailsAsync
|
|
280
|
-
|
|
281
|
-
val items = Arguments.createArray()
|
|
282
|
-
for (skuDetails in skuDetailsList) {
|
|
283
|
-
skus[skuDetails.productId] = skuDetails
|
|
284
|
-
|
|
285
|
-
val item = Arguments.createMap()
|
|
286
|
-
// Add both field names for compatibility
|
|
287
|
-
item.putString("productId", skuDetails.productId)
|
|
288
|
-
item.putString("id", skuDetails.productId)
|
|
289
|
-
item.putString("title", skuDetails.title)
|
|
290
|
-
item.putString("description", skuDetails.description)
|
|
291
|
-
item.putString("productType", skuDetails.productType)
|
|
292
|
-
item.putString("type", skuDetails.productType)
|
|
293
|
-
item.putString("name", skuDetails.name)
|
|
294
|
-
item.putString("displayName", skuDetails.name)
|
|
295
|
-
item.putString("platform", "android")
|
|
296
|
-
|
|
297
|
-
skuDetails.oneTimePurchaseOfferDetails?.let {
|
|
298
|
-
val oneTimePurchaseOfferDetails =
|
|
299
|
-
Arguments.createMap().apply {
|
|
300
|
-
putString("priceCurrencyCode", it.priceCurrencyCode)
|
|
301
|
-
putString("formattedPrice", it.formattedPrice)
|
|
302
|
-
putString("priceAmountMicros", it.priceAmountMicros.toString())
|
|
303
|
-
}
|
|
304
|
-
item.putMap("oneTimePurchaseOfferDetails", oneTimePurchaseOfferDetails)
|
|
305
|
-
// Add expo-iap compatible fields
|
|
306
|
-
item.putString("currency", it.priceCurrencyCode)
|
|
307
|
-
item.putString("displayPrice", it.formattedPrice)
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
skuDetails.subscriptionOfferDetails?.let {
|
|
311
|
-
val subscriptionOfferDetails = Arguments.createArray()
|
|
312
|
-
it.forEach { subscriptionOfferDetailsItem ->
|
|
313
|
-
val offerDetails =
|
|
314
|
-
Arguments.createMap().apply {
|
|
315
|
-
putString("basePlanId", subscriptionOfferDetailsItem.basePlanId)
|
|
316
|
-
putString("offerId", subscriptionOfferDetailsItem.offerId)
|
|
317
|
-
putString("offerToken", subscriptionOfferDetailsItem.offerToken)
|
|
318
|
-
|
|
319
|
-
val offerTags = Arguments.createArray()
|
|
320
|
-
subscriptionOfferDetailsItem.offerTags.forEach { offerTag ->
|
|
321
|
-
offerTags.pushString(offerTag)
|
|
322
|
-
}
|
|
323
|
-
putArray("offerTags", offerTags)
|
|
324
|
-
|
|
325
|
-
val pricingPhasesList = Arguments.createArray()
|
|
326
|
-
subscriptionOfferDetailsItem.pricingPhases.pricingPhaseList.forEach { pricingPhaseItem ->
|
|
327
|
-
val pricingPhase =
|
|
328
|
-
Arguments.createMap().apply {
|
|
329
|
-
putString("formattedPrice", pricingPhaseItem.formattedPrice)
|
|
330
|
-
putString("priceCurrencyCode", pricingPhaseItem.priceCurrencyCode)
|
|
331
|
-
putString("billingPeriod", pricingPhaseItem.billingPeriod)
|
|
332
|
-
putInt("billingCycleCount", pricingPhaseItem.billingCycleCount)
|
|
333
|
-
putString("priceAmountMicros", pricingPhaseItem.priceAmountMicros.toString())
|
|
334
|
-
putInt("recurrenceMode", pricingPhaseItem.recurrenceMode)
|
|
335
|
-
}
|
|
336
|
-
pricingPhasesList.pushMap(pricingPhase)
|
|
337
|
-
}
|
|
338
|
-
val pricingPhases =
|
|
339
|
-
Arguments.createMap().apply {
|
|
340
|
-
putArray("pricingPhaseList", pricingPhasesList)
|
|
341
|
-
}
|
|
342
|
-
putMap("pricingPhases", pricingPhases)
|
|
343
|
-
}
|
|
344
|
-
subscriptionOfferDetails.pushMap(offerDetails)
|
|
345
|
-
}
|
|
346
|
-
item.putArray("subscriptionOfferDetails", subscriptionOfferDetails)
|
|
347
|
-
}
|
|
348
|
-
items.pushMap(item)
|
|
349
|
-
}
|
|
350
|
-
promise.safeResolve(items)
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
/**
|
|
356
|
-
* Rejects promise with billing code if BillingResult is not OK
|
|
357
|
-
*/
|
|
358
|
-
private fun isValidResult(
|
|
359
|
-
billingResult: BillingResult,
|
|
360
|
-
promise: Promise,
|
|
361
|
-
): Boolean {
|
|
362
|
-
Log.d(TAG, "responseCode: " + billingResult.responseCode)
|
|
363
|
-
if (billingResult.responseCode != BillingClient.BillingResponseCode.OK) {
|
|
364
|
-
PlayUtils.rejectPromiseWithBillingError(promise, billingResult.responseCode)
|
|
365
|
-
return false
|
|
366
|
-
}
|
|
367
|
-
return true
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
@ReactMethod
|
|
371
|
-
fun getAvailableItemsByType(
|
|
372
|
-
type: String,
|
|
373
|
-
promise: Promise,
|
|
374
|
-
) {
|
|
375
|
-
Log.d(TAG, "getAvailableItemsByType called for type: $type")
|
|
376
|
-
ensureConnection(
|
|
377
|
-
promise,
|
|
378
|
-
) { billingClient ->
|
|
379
|
-
val items = WritableNativeArray()
|
|
380
|
-
val productType = if (type == "subs") BillingClient.ProductType.SUBS else BillingClient.ProductType.INAPP
|
|
381
|
-
billingClient.queryPurchasesAsync(
|
|
382
|
-
QueryPurchasesParams
|
|
383
|
-
.newBuilder()
|
|
384
|
-
.setProductType(productType)
|
|
385
|
-
.build(),
|
|
386
|
-
) { billingResult: BillingResult, purchases: List<Purchase>? ->
|
|
387
|
-
Log.d(TAG, "queryPurchasesAsync response for $type: ${billingResult.responseCode}, purchases count: ${purchases?.size ?: 0}")
|
|
388
|
-
if (!isValidResult(billingResult, promise)) {
|
|
389
|
-
Log.e(TAG, "Invalid result for getAvailableItemsByType: ${billingResult.debugMessage}")
|
|
390
|
-
return@queryPurchasesAsync
|
|
391
|
-
}
|
|
392
|
-
purchases?.forEach { purchase ->
|
|
393
|
-
val item = WritableNativeMap()
|
|
394
|
-
// Add both field names for compatibility
|
|
395
|
-
item.putString("productId", purchase.products[0]) // kept for convenience/backward-compatibility
|
|
396
|
-
item.putString("id", purchase.products[0])
|
|
397
|
-
val products = Arguments.createArray()
|
|
398
|
-
purchase.products.forEach { products.pushString(it) }
|
|
399
|
-
item.putArray("productIds", products)
|
|
400
|
-
// Create a copy for ids to avoid "Array already consumed" error
|
|
401
|
-
val productsForIds = Arguments.createArray()
|
|
402
|
-
purchase.products.forEach { productsForIds.pushString(it) }
|
|
403
|
-
item.putArray("ids", productsForIds)
|
|
404
|
-
item.putString("transactionId", purchase.orderId)
|
|
405
|
-
item.putDouble("transactionDate", purchase.purchaseTime.toDouble())
|
|
406
|
-
item.putString("transactionReceipt", purchase.originalJson)
|
|
407
|
-
item.putString("orderId", purchase.orderId)
|
|
408
|
-
item.putString("purchaseToken", purchase.purchaseToken)
|
|
409
|
-
item.putString("purchaseTokenAndroid", purchase.purchaseToken)
|
|
410
|
-
item.putString("developerPayloadAndroid", purchase.developerPayload)
|
|
411
|
-
item.putString("signatureAndroid", purchase.signature)
|
|
412
|
-
item.putInt("purchaseStateAndroid", purchase.purchaseState)
|
|
413
|
-
item.putBoolean("isAcknowledgedAndroid", purchase.isAcknowledged)
|
|
414
|
-
item.putString("packageNameAndroid", purchase.packageName)
|
|
415
|
-
item.putString(
|
|
416
|
-
"obfuscatedAccountIdAndroid",
|
|
417
|
-
purchase.accountIdentifiers?.obfuscatedAccountId,
|
|
418
|
-
)
|
|
419
|
-
item.putString(
|
|
420
|
-
"obfuscatedProfileIdAndroid",
|
|
421
|
-
purchase.accountIdentifiers?.obfuscatedProfileId,
|
|
422
|
-
)
|
|
423
|
-
if (type == BillingClient.ProductType.SUBS) {
|
|
424
|
-
item.putBoolean("autoRenewingAndroid", purchase.isAutoRenewing)
|
|
425
|
-
}
|
|
426
|
-
item.putString("platform", "android")
|
|
427
|
-
items.pushMap(item)
|
|
428
|
-
}
|
|
429
|
-
Log.d(TAG, "getAvailableItemsByType returning ${items.toArrayList().size} items for type: $type")
|
|
430
|
-
promise.safeResolve(items)
|
|
431
|
-
}
|
|
432
|
-
}
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
@ReactMethod
|
|
436
|
-
fun getAvailableItems(promise: Promise) {
|
|
437
|
-
ensureConnection(
|
|
438
|
-
promise,
|
|
439
|
-
) { billingClient ->
|
|
440
|
-
val allItems = WritableNativeArray()
|
|
441
|
-
val remainingTypes = mutableListOf(BillingClient.ProductType.INAPP, BillingClient.ProductType.SUBS)
|
|
442
|
-
var completedQueries = 0
|
|
443
|
-
|
|
444
|
-
fun checkCompletion() {
|
|
445
|
-
completedQueries++
|
|
446
|
-
if (completedQueries >= 2) {
|
|
447
|
-
Log.d(TAG, "getAvailableItems returning ${allItems.toArrayList().size} items")
|
|
448
|
-
promise.safeResolve(allItems)
|
|
449
|
-
}
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
// Query INAPP purchases
|
|
453
|
-
billingClient.queryPurchasesAsync(
|
|
454
|
-
QueryPurchasesParams
|
|
455
|
-
.newBuilder()
|
|
456
|
-
.setProductType(BillingClient.ProductType.INAPP)
|
|
457
|
-
.build(),
|
|
458
|
-
) { billingResult: BillingResult, purchases: List<Purchase>? ->
|
|
459
|
-
if (billingResult.responseCode == BillingClient.BillingResponseCode.OK) {
|
|
460
|
-
purchases?.forEach { purchase ->
|
|
461
|
-
val item = WritableNativeMap()
|
|
462
|
-
// Add both field names for compatibility
|
|
463
|
-
item.putString("productId", purchase.products[0]) // kept for convenience/backward-compatibility
|
|
464
|
-
item.putString("id", purchase.products[0])
|
|
465
|
-
val products = Arguments.createArray()
|
|
466
|
-
purchase.products.forEach { products.pushString(it) }
|
|
467
|
-
item.putArray("productIds", products)
|
|
468
|
-
// Create a copy for ids to avoid "Array already consumed" error
|
|
469
|
-
val productsForIds = Arguments.createArray()
|
|
470
|
-
purchase.products.forEach { productsForIds.pushString(it) }
|
|
471
|
-
item.putArray("ids", productsForIds)
|
|
472
|
-
item.putString("transactionId", purchase.orderId)
|
|
473
|
-
item.putDouble("transactionDate", purchase.purchaseTime.toDouble())
|
|
474
|
-
item.putString("transactionReceipt", purchase.originalJson)
|
|
475
|
-
item.putString("orderId", purchase.orderId)
|
|
476
|
-
item.putString("purchaseToken", purchase.purchaseToken)
|
|
477
|
-
item.putString("purchaseTokenAndroid", purchase.purchaseToken)
|
|
478
|
-
item.putString("developerPayloadAndroid", purchase.developerPayload)
|
|
479
|
-
item.putString("signatureAndroid", purchase.signature)
|
|
480
|
-
item.putInt("purchaseStateAndroid", purchase.purchaseState)
|
|
481
|
-
item.putBoolean("isAcknowledgedAndroid", purchase.isAcknowledged)
|
|
482
|
-
item.putString("packageNameAndroid", purchase.packageName)
|
|
483
|
-
item.putString(
|
|
484
|
-
"obfuscatedAccountIdAndroid",
|
|
485
|
-
purchase.accountIdentifiers?.obfuscatedAccountId,
|
|
486
|
-
)
|
|
487
|
-
item.putString(
|
|
488
|
-
"obfuscatedProfileIdAndroid",
|
|
489
|
-
purchase.accountIdentifiers?.obfuscatedProfileId,
|
|
490
|
-
)
|
|
491
|
-
item.putString("platform", "android")
|
|
492
|
-
allItems.pushMap(item)
|
|
493
|
-
}
|
|
494
|
-
} else {
|
|
495
|
-
Log.w(TAG, "Failed to query INAPP purchases: ${billingResult.debugMessage}")
|
|
496
|
-
}
|
|
497
|
-
checkCompletion()
|
|
498
|
-
}
|
|
499
|
-
|
|
500
|
-
// Query SUBS purchases
|
|
501
|
-
billingClient.queryPurchasesAsync(
|
|
502
|
-
QueryPurchasesParams
|
|
503
|
-
.newBuilder()
|
|
504
|
-
.setProductType(BillingClient.ProductType.SUBS)
|
|
505
|
-
.build(),
|
|
506
|
-
) { billingResult: BillingResult, purchases: List<Purchase>? ->
|
|
507
|
-
if (billingResult.responseCode == BillingClient.BillingResponseCode.OK) {
|
|
508
|
-
purchases?.forEach { purchase ->
|
|
509
|
-
val item = WritableNativeMap()
|
|
510
|
-
// Add both field names for compatibility
|
|
511
|
-
item.putString("productId", purchase.products[0]) // kept for convenience/backward-compatibility
|
|
512
|
-
item.putString("id", purchase.products[0])
|
|
513
|
-
val products = Arguments.createArray()
|
|
514
|
-
purchase.products.forEach { products.pushString(it) }
|
|
515
|
-
item.putArray("productIds", products)
|
|
516
|
-
// Create a copy for ids to avoid "Array already consumed" error
|
|
517
|
-
val productsForIds = Arguments.createArray()
|
|
518
|
-
purchase.products.forEach { productsForIds.pushString(it) }
|
|
519
|
-
item.putArray("ids", productsForIds)
|
|
520
|
-
item.putString("transactionId", purchase.orderId)
|
|
521
|
-
item.putDouble("transactionDate", purchase.purchaseTime.toDouble())
|
|
522
|
-
item.putString("transactionReceipt", purchase.originalJson)
|
|
523
|
-
item.putString("orderId", purchase.orderId)
|
|
524
|
-
item.putString("purchaseToken", purchase.purchaseToken)
|
|
525
|
-
item.putString("purchaseTokenAndroid", purchase.purchaseToken)
|
|
526
|
-
item.putString("developerPayloadAndroid", purchase.developerPayload)
|
|
527
|
-
item.putString("signatureAndroid", purchase.signature)
|
|
528
|
-
item.putInt("purchaseStateAndroid", purchase.purchaseState)
|
|
529
|
-
item.putBoolean("isAcknowledgedAndroid", purchase.isAcknowledged)
|
|
530
|
-
item.putString("packageNameAndroid", purchase.packageName)
|
|
531
|
-
item.putString(
|
|
532
|
-
"obfuscatedAccountIdAndroid",
|
|
533
|
-
purchase.accountIdentifiers?.obfuscatedAccountId,
|
|
534
|
-
)
|
|
535
|
-
item.putString(
|
|
536
|
-
"obfuscatedProfileIdAndroid",
|
|
537
|
-
purchase.accountIdentifiers?.obfuscatedProfileId,
|
|
538
|
-
)
|
|
539
|
-
item.putBoolean("autoRenewingAndroid", purchase.isAutoRenewing)
|
|
540
|
-
item.putString("platform", "android")
|
|
541
|
-
allItems.pushMap(item)
|
|
542
|
-
}
|
|
543
|
-
} else {
|
|
544
|
-
Log.w(TAG, "Failed to query SUBS purchases: ${billingResult.debugMessage}")
|
|
545
|
-
}
|
|
546
|
-
checkCompletion()
|
|
547
|
-
}
|
|
548
|
-
}
|
|
549
|
-
}
|
|
550
|
-
|
|
551
|
-
@ReactMethod
|
|
552
|
-
fun getPurchaseHistoryByType(
|
|
553
|
-
type: String,
|
|
554
|
-
promise: Promise,
|
|
555
|
-
) {
|
|
556
|
-
ensureConnection(
|
|
557
|
-
promise,
|
|
558
|
-
) { billingClient ->
|
|
559
|
-
billingClient.queryPurchaseHistoryAsync(
|
|
560
|
-
QueryPurchaseHistoryParams
|
|
561
|
-
.newBuilder()
|
|
562
|
-
.setProductType(
|
|
563
|
-
if (type == "subs") BillingClient.ProductType.SUBS else BillingClient.ProductType.INAPP,
|
|
564
|
-
).build(),
|
|
565
|
-
) { billingResult: BillingResult, purchaseHistoryRecordList: MutableList<PurchaseHistoryRecord>? ->
|
|
566
|
-
|
|
567
|
-
if (!isValidResult(billingResult, promise)) return@queryPurchaseHistoryAsync
|
|
568
|
-
|
|
569
|
-
Log.d(TAG, purchaseHistoryRecordList.toString())
|
|
570
|
-
val items = Arguments.createArray()
|
|
571
|
-
purchaseHistoryRecordList?.forEach { purchase ->
|
|
572
|
-
val item = Arguments.createMap()
|
|
573
|
-
// Add both field names for compatibility
|
|
574
|
-
item.putString("productId", purchase.products[0])
|
|
575
|
-
item.putString("id", purchase.products[0])
|
|
576
|
-
val products = Arguments.createArray()
|
|
577
|
-
purchase.products.forEach { products.pushString(it) }
|
|
578
|
-
item.putArray("productIds", products)
|
|
579
|
-
item.putArray("ids", products)
|
|
580
|
-
item.putDouble("transactionDate", purchase.purchaseTime.toDouble())
|
|
581
|
-
item.putString("transactionReceipt", purchase.originalJson)
|
|
582
|
-
item.putString("purchaseToken", purchase.purchaseToken)
|
|
583
|
-
item.putString("purchaseTokenAndroid", purchase.purchaseToken)
|
|
584
|
-
item.putString("dataAndroid", purchase.originalJson)
|
|
585
|
-
item.putString("signatureAndroid", purchase.signature)
|
|
586
|
-
item.putString("developerPayload", purchase.developerPayload.orEmpty())
|
|
587
|
-
item.putString("platform", "android")
|
|
588
|
-
items.pushMap(item)
|
|
589
|
-
}
|
|
590
|
-
promise.safeResolve(items)
|
|
591
|
-
}
|
|
592
|
-
}
|
|
593
|
-
}
|
|
594
|
-
|
|
595
|
-
@ReactMethod
|
|
596
|
-
fun buyItemByType(
|
|
597
|
-
type: String,
|
|
598
|
-
skuArr: ReadableArray,
|
|
599
|
-
purchaseToken: String?,
|
|
600
|
-
replacementMode: Int,
|
|
601
|
-
obfuscatedAccountId: String?,
|
|
602
|
-
obfuscatedProfileId: String?,
|
|
603
|
-
offerTokenArr: ReadableArray, // New parameter in V5
|
|
604
|
-
isOfferPersonalized: Boolean, // New parameter in V5
|
|
605
|
-
promise: Promise,
|
|
606
|
-
) {
|
|
607
|
-
val activity = currentActivity
|
|
608
|
-
if (activity == null) {
|
|
609
|
-
promise.safeReject(PromiseUtils.E_UNKNOWN, "getCurrentActivity returned null")
|
|
610
|
-
return
|
|
611
|
-
}
|
|
612
|
-
ensureConnection(
|
|
613
|
-
promise,
|
|
614
|
-
) { billingClient ->
|
|
615
|
-
PromiseUtils.addPromiseForKey(
|
|
616
|
-
PROMISE_BUY_ITEM,
|
|
617
|
-
promise,
|
|
618
|
-
)
|
|
619
|
-
if (type == BillingClient.ProductType.SUBS && skuArr.size() != offerTokenArr.size()) {
|
|
620
|
-
val debugMessage =
|
|
621
|
-
"The number of skus (${skuArr.size()}) must match: the number of offerTokens (${offerTokenArr.size()}) for Subscriptions"
|
|
622
|
-
val error = Arguments.createMap()
|
|
623
|
-
error.putString("debugMessage", debugMessage)
|
|
624
|
-
error.putString("code", PROMISE_BUY_ITEM)
|
|
625
|
-
error.putString("message", debugMessage)
|
|
626
|
-
sendEvent(reactContext, "purchase-error", error)
|
|
627
|
-
promise.safeReject(PROMISE_BUY_ITEM, debugMessage)
|
|
628
|
-
return@ensureConnection
|
|
629
|
-
}
|
|
630
|
-
val productParamsList =
|
|
631
|
-
skuArr.toArrayList().map { it.toString() }.mapIndexed { index, sku ->
|
|
632
|
-
val selectedSku: ProductDetails? = skus[sku]
|
|
633
|
-
if (selectedSku == null) {
|
|
634
|
-
val debugMessage =
|
|
635
|
-
"The sku was not found. Please fetch products first by calling getItems"
|
|
636
|
-
val error = Arguments.createMap()
|
|
637
|
-
error.putString("debugMessage", debugMessage)
|
|
638
|
-
error.putString("code", PROMISE_BUY_ITEM)
|
|
639
|
-
error.putString("message", debugMessage)
|
|
640
|
-
error.putString("productId", sku)
|
|
641
|
-
sendEvent(reactContext, "purchase-error", error)
|
|
642
|
-
promise.safeReject(PROMISE_BUY_ITEM, debugMessage)
|
|
643
|
-
return@ensureConnection
|
|
644
|
-
}
|
|
645
|
-
var productDetailParams = BillingFlowParams.ProductDetailsParams.newBuilder().setProductDetails(selectedSku)
|
|
646
|
-
if (type == BillingClient.ProductType.SUBS) {
|
|
647
|
-
offerTokenArr.getString(index)?.let { offerToken ->
|
|
648
|
-
productDetailParams = productDetailParams.setOfferToken(offerToken)
|
|
649
|
-
}
|
|
650
|
-
}
|
|
651
|
-
productDetailParams.build()
|
|
652
|
-
}
|
|
653
|
-
val builder = BillingFlowParams.newBuilder()
|
|
654
|
-
builder.setProductDetailsParamsList(productParamsList).setIsOfferPersonalized(isOfferPersonalized)
|
|
655
|
-
|
|
656
|
-
val subscriptionUpdateParamsBuilder = SubscriptionUpdateParams.newBuilder()
|
|
657
|
-
if (purchaseToken != null) {
|
|
658
|
-
subscriptionUpdateParamsBuilder.setOldPurchaseToken(purchaseToken)
|
|
659
|
-
|
|
660
|
-
if (type == BillingClient.ProductType.SUBS && replacementMode != -1) {
|
|
661
|
-
val replacementMode =
|
|
662
|
-
when (replacementMode) {
|
|
663
|
-
BillingFlowParams.SubscriptionUpdateParams.ReplacementMode.CHARGE_PRORATED_PRICE -> BillingFlowParams.SubscriptionUpdateParams.ReplacementMode.CHARGE_PRORATED_PRICE
|
|
664
|
-
BillingFlowParams.SubscriptionUpdateParams.ReplacementMode.WITHOUT_PRORATION -> BillingFlowParams.SubscriptionUpdateParams.ReplacementMode.WITHOUT_PRORATION
|
|
665
|
-
BillingFlowParams.SubscriptionUpdateParams.ReplacementMode.DEFERRED -> BillingFlowParams.SubscriptionUpdateParams.ReplacementMode.DEFERRED
|
|
666
|
-
BillingFlowParams.SubscriptionUpdateParams.ReplacementMode.WITH_TIME_PRORATION -> BillingFlowParams.SubscriptionUpdateParams.ReplacementMode.WITH_TIME_PRORATION
|
|
667
|
-
BillingFlowParams.SubscriptionUpdateParams.ReplacementMode.CHARGE_FULL_PRICE -> BillingFlowParams.SubscriptionUpdateParams.ReplacementMode.CHARGE_FULL_PRICE
|
|
668
|
-
else -> BillingFlowParams.SubscriptionUpdateParams.ReplacementMode.UNKNOWN_REPLACEMENT_MODE
|
|
669
|
-
}
|
|
670
|
-
subscriptionUpdateParamsBuilder.setSubscriptionReplacementMode(replacementMode)
|
|
671
|
-
}
|
|
672
|
-
val subscriptionUpdateParams = subscriptionUpdateParamsBuilder.build()
|
|
673
|
-
builder.setSubscriptionUpdateParams(subscriptionUpdateParams)
|
|
674
|
-
}
|
|
675
|
-
if (obfuscatedAccountId != null) {
|
|
676
|
-
builder.setObfuscatedAccountId(obfuscatedAccountId)
|
|
677
|
-
}
|
|
678
|
-
if (obfuscatedProfileId != null) {
|
|
679
|
-
builder.setObfuscatedProfileId(obfuscatedProfileId)
|
|
680
|
-
}
|
|
681
|
-
|
|
682
|
-
val flowParams = builder.build()
|
|
683
|
-
val billingResultCode = billingClient.launchBillingFlow(activity, flowParams).responseCode
|
|
684
|
-
if (billingResultCode != BillingClient.BillingResponseCode.OK) {
|
|
685
|
-
val errorData = PlayUtils.getBillingResponseData(billingResultCode)
|
|
686
|
-
promise.safeReject(errorData.code, errorData.message)
|
|
687
|
-
}
|
|
688
|
-
}
|
|
689
|
-
}
|
|
690
|
-
|
|
691
|
-
@ReactMethod
|
|
692
|
-
fun acknowledgePurchase(
|
|
693
|
-
token: String,
|
|
694
|
-
developerPayLoad: String?,
|
|
695
|
-
promise: Promise,
|
|
696
|
-
) {
|
|
697
|
-
ensureConnection(
|
|
698
|
-
promise,
|
|
699
|
-
) { billingClient ->
|
|
700
|
-
val acknowledgePurchaseParams =
|
|
701
|
-
AcknowledgePurchaseParams
|
|
702
|
-
.newBuilder()
|
|
703
|
-
.setPurchaseToken(
|
|
704
|
-
token,
|
|
705
|
-
).build()
|
|
706
|
-
billingClient.acknowledgePurchase(
|
|
707
|
-
acknowledgePurchaseParams,
|
|
708
|
-
) { billingResult: BillingResult ->
|
|
709
|
-
if (!isValidResult(billingResult, promise)) return@acknowledgePurchase
|
|
710
|
-
|
|
711
|
-
val map = Arguments.createMap()
|
|
712
|
-
map.putInt("responseCode", billingResult.responseCode)
|
|
713
|
-
map.putString("debugMessage", billingResult.debugMessage)
|
|
714
|
-
val errorData = PlayUtils.getBillingResponseData(billingResult.responseCode)
|
|
715
|
-
map.putString("code", errorData.code)
|
|
716
|
-
map.putString("message", errorData.message)
|
|
717
|
-
promise.safeResolve(map)
|
|
718
|
-
}
|
|
719
|
-
}
|
|
720
|
-
}
|
|
721
|
-
|
|
722
|
-
@ReactMethod
|
|
723
|
-
fun consumeProduct(
|
|
724
|
-
token: String,
|
|
725
|
-
developerPayLoad: String?,
|
|
726
|
-
promise: Promise,
|
|
727
|
-
) {
|
|
728
|
-
val params = ConsumeParams.newBuilder().setPurchaseToken(token).build()
|
|
729
|
-
ensureConnection(
|
|
730
|
-
promise,
|
|
731
|
-
) { billingClient ->
|
|
732
|
-
billingClient.consumeAsync(
|
|
733
|
-
params,
|
|
734
|
-
) { billingResult: BillingResult, purchaseToken: String? ->
|
|
735
|
-
if (!isValidResult(billingResult, promise)) return@consumeAsync
|
|
736
|
-
|
|
737
|
-
val map = Arguments.createMap()
|
|
738
|
-
map.putInt("responseCode", billingResult.responseCode)
|
|
739
|
-
map.putString("debugMessage", billingResult.debugMessage)
|
|
740
|
-
val errorData = PlayUtils.getBillingResponseData(billingResult.responseCode)
|
|
741
|
-
map.putString("code", errorData.code)
|
|
742
|
-
map.putString("message", errorData.message)
|
|
743
|
-
map.putString("purchaseToken", purchaseToken)
|
|
744
|
-
map.putString("purchaseTokenAndroid", purchaseToken)
|
|
745
|
-
promise.safeResolve(map)
|
|
746
|
-
}
|
|
747
|
-
}
|
|
748
|
-
}
|
|
749
|
-
|
|
750
|
-
override fun onPurchasesUpdated(
|
|
751
|
-
billingResult: BillingResult,
|
|
752
|
-
purchases: List<Purchase>?,
|
|
753
|
-
) {
|
|
754
|
-
val responseCode = billingResult.responseCode
|
|
755
|
-
if (responseCode != BillingClient.BillingResponseCode.OK) {
|
|
756
|
-
val error = Arguments.createMap()
|
|
757
|
-
error.putInt("responseCode", responseCode)
|
|
758
|
-
error.putString("debugMessage", billingResult.debugMessage)
|
|
759
|
-
val errorData = PlayUtils.getBillingResponseData(responseCode)
|
|
760
|
-
error.putString("code", errorData.code)
|
|
761
|
-
error.putString("message", errorData.message)
|
|
762
|
-
sendEvent(reactContext, "purchase-error", error)
|
|
763
|
-
PlayUtils.rejectPromisesWithBillingError(PROMISE_BUY_ITEM, responseCode)
|
|
764
|
-
return
|
|
765
|
-
}
|
|
766
|
-
if (purchases != null) {
|
|
767
|
-
val promiseItems: WritableArray = Arguments.createArray()
|
|
768
|
-
purchases.forEach { purchase ->
|
|
769
|
-
val item = Arguments.createMap()
|
|
770
|
-
// Add both productId (for backward compatibility) and id (for expo-iap compatibility)
|
|
771
|
-
item.putString("productId", purchase.products[0])
|
|
772
|
-
item.putString("id", purchase.products[0])
|
|
773
|
-
val products = Arguments.createArray()
|
|
774
|
-
purchase.products.forEach { products.pushString(it) }
|
|
775
|
-
item.putArray("productIds", products)
|
|
776
|
-
// Create a new array for "ids" to avoid "Array already consumed" error
|
|
777
|
-
val productsForIds = Arguments.createArray()
|
|
778
|
-
purchase.products.forEach { productsForIds.pushString(it) }
|
|
779
|
-
item.putArray("ids", productsForIds)
|
|
780
|
-
item.putString("transactionId", purchase.orderId)
|
|
781
|
-
item.putDouble("transactionDate", purchase.purchaseTime.toDouble())
|
|
782
|
-
item.putString("transactionReceipt", purchase.originalJson)
|
|
783
|
-
item.putString("purchaseToken", purchase.purchaseToken)
|
|
784
|
-
item.putString("purchaseTokenAndroid", purchase.purchaseToken)
|
|
785
|
-
item.putString("dataAndroid", purchase.originalJson)
|
|
786
|
-
item.putString("signatureAndroid", purchase.signature)
|
|
787
|
-
item.putBoolean("autoRenewingAndroid", purchase.isAutoRenewing)
|
|
788
|
-
item.putBoolean("isAcknowledgedAndroid", purchase.isAcknowledged)
|
|
789
|
-
item.putInt("purchaseStateAndroid", purchase.purchaseState)
|
|
790
|
-
item.putString("packageNameAndroid", purchase.packageName)
|
|
791
|
-
item.putString("developerPayloadAndroid", purchase.developerPayload)
|
|
792
|
-
val accountIdentifiers = purchase.accountIdentifiers
|
|
793
|
-
if (accountIdentifiers != null) {
|
|
794
|
-
item.putString(
|
|
795
|
-
"obfuscatedAccountIdAndroid",
|
|
796
|
-
accountIdentifiers.obfuscatedAccountId,
|
|
797
|
-
)
|
|
798
|
-
item.putString(
|
|
799
|
-
"obfuscatedProfileIdAndroid",
|
|
800
|
-
accountIdentifiers.obfuscatedProfileId,
|
|
801
|
-
)
|
|
802
|
-
}
|
|
803
|
-
item.putString("platform", "android")
|
|
804
|
-
promiseItems.pushMap(item.copy())
|
|
805
|
-
sendEvent(reactContext, "purchase-updated", item)
|
|
806
|
-
}
|
|
807
|
-
PromiseUtils.resolvePromisesForKey(PROMISE_BUY_ITEM, promiseItems)
|
|
808
|
-
} else {
|
|
809
|
-
val result = Arguments.createMap()
|
|
810
|
-
result.putInt("responseCode", billingResult.responseCode)
|
|
811
|
-
result.putString("debugMessage", billingResult.debugMessage)
|
|
812
|
-
result.putString(
|
|
813
|
-
"extraMessage",
|
|
814
|
-
"The purchases are null. This is a normal behavior if you have requested DEFERRED" +
|
|
815
|
-
" proration. If not please report an issue.",
|
|
816
|
-
)
|
|
817
|
-
sendEvent(reactContext, "purchase-updated", result)
|
|
818
|
-
PromiseUtils.resolvePromisesForKey(PROMISE_BUY_ITEM, null)
|
|
819
|
-
}
|
|
820
|
-
}
|
|
821
|
-
|
|
822
|
-
private fun sendUnconsumedPurchases(promise: Promise) {
|
|
823
|
-
ensureConnection(
|
|
824
|
-
promise,
|
|
825
|
-
) { billingClient ->
|
|
826
|
-
val types = arrayOf(BillingClient.ProductType.INAPP, BillingClient.ProductType.SUBS)
|
|
827
|
-
for (type in types) {
|
|
828
|
-
billingClient.queryPurchasesAsync(
|
|
829
|
-
QueryPurchasesParams
|
|
830
|
-
.newBuilder()
|
|
831
|
-
.setProductType(
|
|
832
|
-
type,
|
|
833
|
-
).build(),
|
|
834
|
-
) { billingResult: BillingResult, list: List<Purchase> ->
|
|
835
|
-
if (!isValidResult(billingResult, promise)) return@queryPurchasesAsync
|
|
836
|
-
|
|
837
|
-
val unacknowledgedPurchases = list.filter { !it.isAcknowledged }
|
|
838
|
-
onPurchasesUpdated(billingResult, unacknowledgedPurchases)
|
|
839
|
-
}
|
|
840
|
-
}
|
|
841
|
-
promise.safeResolve(true)
|
|
842
|
-
}
|
|
843
|
-
}
|
|
844
|
-
|
|
845
|
-
@ReactMethod
|
|
846
|
-
fun startListening(promise: Promise) {
|
|
847
|
-
sendUnconsumedPurchases(promise)
|
|
848
|
-
}
|
|
849
|
-
|
|
850
|
-
@ReactMethod
|
|
851
|
-
fun addListener(eventName: String) {
|
|
852
|
-
// Keep: Required for RN built-in Event Emitter Calls.
|
|
853
|
-
}
|
|
854
|
-
|
|
855
|
-
@ReactMethod
|
|
856
|
-
fun removeListeners(count: Double) {
|
|
857
|
-
// Keep: Required for RN built-in Event Emitter Calls.
|
|
858
|
-
}
|
|
859
|
-
|
|
860
|
-
@ReactMethod
|
|
861
|
-
fun getPackageName(promise: Promise) = promise.resolve(reactApplicationContext.packageName)
|
|
862
|
-
|
|
863
|
-
@ReactMethod
|
|
864
|
-
fun getStorefront(promise: Promise) {
|
|
865
|
-
ensureConnection(
|
|
866
|
-
promise,
|
|
867
|
-
) { billingClient ->
|
|
868
|
-
billingClient.getBillingConfigAsync(
|
|
869
|
-
GetBillingConfigParams.newBuilder().build(),
|
|
870
|
-
BillingConfigResponseListener { result: BillingResult, config: BillingConfig? ->
|
|
871
|
-
if (result.responseCode == BillingClient.BillingResponseCode.OK) {
|
|
872
|
-
promise.safeResolve(config?.countryCode.orEmpty())
|
|
873
|
-
} else {
|
|
874
|
-
val debugMessage = result.debugMessage.orEmpty()
|
|
875
|
-
promise.safeReject(result.responseCode.toString(), debugMessage)
|
|
876
|
-
}
|
|
877
|
-
},
|
|
878
|
-
)
|
|
879
|
-
}
|
|
880
|
-
}
|
|
881
|
-
|
|
882
|
-
private fun sendEvent(
|
|
883
|
-
reactContext: ReactContext,
|
|
884
|
-
eventName: String,
|
|
885
|
-
params: WritableMap?,
|
|
886
|
-
) {
|
|
887
|
-
reactContext
|
|
888
|
-
.getJSModule(RCTDeviceEventEmitter::class.java)
|
|
889
|
-
.emit(eventName, params)
|
|
890
|
-
}
|
|
891
|
-
|
|
892
|
-
companion object {
|
|
893
|
-
private const val PROMISE_BUY_ITEM = "PROMISE_BUY_ITEM"
|
|
894
|
-
const val TAG = "RNIapModule"
|
|
895
|
-
}
|
|
896
|
-
|
|
897
|
-
init {
|
|
898
|
-
val lifecycleEventListener: LifecycleEventListener =
|
|
899
|
-
object : LifecycleEventListener {
|
|
900
|
-
override fun onHostResume() {}
|
|
901
|
-
|
|
902
|
-
override fun onHostPause() {}
|
|
903
|
-
|
|
904
|
-
override fun onHostDestroy() {
|
|
905
|
-
billingClientCache?.endConnection()
|
|
906
|
-
billingClientCache = null
|
|
907
|
-
}
|
|
908
|
-
}
|
|
909
|
-
reactContext.addLifecycleEventListener(lifecycleEventListener)
|
|
910
|
-
}
|
|
911
|
-
}
|