react-native-iap 13.0.4 → 14.0.0-rc.2
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 +144 -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,325 +0,0 @@
|
|
|
1
|
-
package com.dooboolab.rniap
|
|
2
|
-
|
|
3
|
-
import android.util.Log
|
|
4
|
-
import com.amazon.device.iap.PurchasingListener
|
|
5
|
-
import com.amazon.device.iap.model.ProductDataResponse
|
|
6
|
-
import com.amazon.device.iap.model.ProductType
|
|
7
|
-
import com.amazon.device.iap.model.PurchaseResponse
|
|
8
|
-
import com.amazon.device.iap.model.PurchaseUpdatesResponse
|
|
9
|
-
import com.amazon.device.iap.model.UserDataResponse
|
|
10
|
-
import com.dooboolab.rniap.utils.toMap
|
|
11
|
-
import com.facebook.react.bridge.Arguments
|
|
12
|
-
import com.facebook.react.bridge.WritableMap
|
|
13
|
-
import com.facebook.react.bridge.WritableNativeArray
|
|
14
|
-
import com.facebook.react.bridge.WritableNativeMap
|
|
15
|
-
import java.lang.NumberFormatException
|
|
16
|
-
|
|
17
|
-
val ProductType.typeString: String
|
|
18
|
-
get() = if (this == ProductType.ENTITLED || this == ProductType.CONSUMABLE) "inapp" else "subs"
|
|
19
|
-
|
|
20
|
-
class RNIapAmazonListener(
|
|
21
|
-
var eventSender: EventSender?,
|
|
22
|
-
var purchasingService: PurchasingServiceProxy?,
|
|
23
|
-
) : PurchasingListener {
|
|
24
|
-
override fun onProductDataResponse(response: ProductDataResponse) {
|
|
25
|
-
when (response.requestStatus) {
|
|
26
|
-
ProductDataResponse.RequestStatus.SUCCESSFUL -> {
|
|
27
|
-
val productData = response.productData
|
|
28
|
-
val items = WritableNativeArray()
|
|
29
|
-
for ((_, product) in productData) {
|
|
30
|
-
var priceNumber: Number = 0.00
|
|
31
|
-
val priceString = product.price
|
|
32
|
-
try {
|
|
33
|
-
if (priceString?.isNotEmpty() == true) {
|
|
34
|
-
priceNumber = priceString.replace("[^\\d.,]+".toRegex(), "").toDouble()
|
|
35
|
-
}
|
|
36
|
-
} catch (e: NumberFormatException) {
|
|
37
|
-
Log.w(
|
|
38
|
-
TAG,
|
|
39
|
-
"onProductDataResponse: Failed to parse price for product: " + product.sku,
|
|
40
|
-
)
|
|
41
|
-
}
|
|
42
|
-
val item = Arguments.createMap()
|
|
43
|
-
val coinsReward = product.coinsReward
|
|
44
|
-
item.putString("productId", product.sku)
|
|
45
|
-
item.putString("price", priceNumber.toString())
|
|
46
|
-
item.putString("type", product.productType.typeString)
|
|
47
|
-
item.putString("localizedPrice", priceString)
|
|
48
|
-
item.putString("title", product.title)
|
|
49
|
-
item.putString("description", product.description)
|
|
50
|
-
item.putString("iconUrl", product.smallIconUrl)
|
|
51
|
-
item.putString("originalJson", product.toString())
|
|
52
|
-
item.putString("originalPrice", priceString)
|
|
53
|
-
// item.putString("userMarketplaceAmazon", marketplace);
|
|
54
|
-
if (coinsReward != null) {
|
|
55
|
-
item.putInt("coinsRewardAmountAmazon", coinsReward.amount)
|
|
56
|
-
}
|
|
57
|
-
items.pushMap(item)
|
|
58
|
-
}
|
|
59
|
-
PromiseUtils
|
|
60
|
-
.resolvePromisesForKey(
|
|
61
|
-
RNIapAmazonModule.PROMISE_GET_PRODUCT_DATA,
|
|
62
|
-
items,
|
|
63
|
-
)
|
|
64
|
-
}
|
|
65
|
-
ProductDataResponse.RequestStatus.FAILED ->
|
|
66
|
-
PromiseUtils
|
|
67
|
-
.rejectPromisesForKey(
|
|
68
|
-
RNIapAmazonModule.PROMISE_GET_PRODUCT_DATA,
|
|
69
|
-
E_PRODUCT_DATA_RESPONSE_FAILED,
|
|
70
|
-
null,
|
|
71
|
-
null,
|
|
72
|
-
)
|
|
73
|
-
ProductDataResponse.RequestStatus.NOT_SUPPORTED ->
|
|
74
|
-
PromiseUtils
|
|
75
|
-
.rejectPromisesForKey(
|
|
76
|
-
RNIapAmazonModule.PROMISE_GET_PRODUCT_DATA,
|
|
77
|
-
E_PRODUCT_DATA_RESPONSE_NOT_SUPPORTED,
|
|
78
|
-
null,
|
|
79
|
-
null,
|
|
80
|
-
)
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
override fun onPurchaseUpdatesResponse(response: PurchaseUpdatesResponse) {
|
|
85
|
-
when (response.requestStatus) {
|
|
86
|
-
PurchaseUpdatesResponse.RequestStatus.SUCCESSFUL -> {
|
|
87
|
-
val availableItems = Arguments.createArray()
|
|
88
|
-
val userData = response.userData
|
|
89
|
-
var promiseItem: WritableMap? = null
|
|
90
|
-
val purchases = response.receipts
|
|
91
|
-
for (receipt in purchases) {
|
|
92
|
-
val item = receipt.toMap(userData)
|
|
93
|
-
promiseItem = WritableNativeMap()
|
|
94
|
-
promiseItem.merge(item)
|
|
95
|
-
eventSender?.sendEvent("purchase-updated", item)
|
|
96
|
-
availableItems.pushMap(promiseItem)
|
|
97
|
-
}
|
|
98
|
-
if (response.hasMore()) {
|
|
99
|
-
purchasingService?.getPurchaseUpdates(false)
|
|
100
|
-
} else {
|
|
101
|
-
if (purchases.size > 0 && promiseItem != null) {
|
|
102
|
-
PromiseUtils
|
|
103
|
-
.resolvePromisesForKey(
|
|
104
|
-
RNIapAmazonModule.PROMISE_BUY_ITEM,
|
|
105
|
-
promiseItem,
|
|
106
|
-
)
|
|
107
|
-
}
|
|
108
|
-
PromiseUtils
|
|
109
|
-
.resolvePromisesForKey(
|
|
110
|
-
RNIapAmazonModule.PROMISE_QUERY_PURCHASES,
|
|
111
|
-
true,
|
|
112
|
-
)
|
|
113
|
-
PromiseUtils
|
|
114
|
-
.resolvePromisesForKey(
|
|
115
|
-
RNIapAmazonModule.PROMISE_QUERY_AVAILABLE_ITEMS,
|
|
116
|
-
availableItems,
|
|
117
|
-
)
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
PurchaseUpdatesResponse.RequestStatus.FAILED -> {
|
|
121
|
-
val error = Arguments.createMap()
|
|
122
|
-
val debugMessage = "An unknown or unexpected error has occured. Please try again later."
|
|
123
|
-
val errorCode = PromiseUtils.E_UNKNOWN
|
|
124
|
-
error.putInt("responseCode", 0)
|
|
125
|
-
error.putString("debugMessage", debugMessage)
|
|
126
|
-
error.putString("code", errorCode)
|
|
127
|
-
error.putString("message", debugMessage)
|
|
128
|
-
eventSender?.sendEvent("purchase-error", error)
|
|
129
|
-
PromiseUtils
|
|
130
|
-
.rejectPromisesForKey(
|
|
131
|
-
RNIapAmazonModule.PROMISE_QUERY_PURCHASES,
|
|
132
|
-
errorCode,
|
|
133
|
-
debugMessage,
|
|
134
|
-
null,
|
|
135
|
-
)
|
|
136
|
-
PromiseUtils
|
|
137
|
-
.rejectPromisesForKey(
|
|
138
|
-
RNIapAmazonModule.PROMISE_QUERY_AVAILABLE_ITEMS,
|
|
139
|
-
errorCode,
|
|
140
|
-
debugMessage,
|
|
141
|
-
null,
|
|
142
|
-
)
|
|
143
|
-
}
|
|
144
|
-
PurchaseUpdatesResponse.RequestStatus.NOT_SUPPORTED -> {
|
|
145
|
-
val error = Arguments.createMap()
|
|
146
|
-
val debugMessage = "This feature is not available on your device."
|
|
147
|
-
val errorCode = PromiseUtils.E_SERVICE_ERROR
|
|
148
|
-
error.putInt("responseCode", 0)
|
|
149
|
-
error.putString("debugMessage", debugMessage)
|
|
150
|
-
error.putString("code", errorCode)
|
|
151
|
-
error.putString("message", debugMessage)
|
|
152
|
-
eventSender?.sendEvent("purchase-error", error)
|
|
153
|
-
PromiseUtils
|
|
154
|
-
.rejectPromisesForKey(
|
|
155
|
-
RNIapAmazonModule.PROMISE_QUERY_PURCHASES,
|
|
156
|
-
errorCode,
|
|
157
|
-
debugMessage,
|
|
158
|
-
null,
|
|
159
|
-
)
|
|
160
|
-
PromiseUtils
|
|
161
|
-
.rejectPromisesForKey(
|
|
162
|
-
RNIapAmazonModule.PROMISE_QUERY_AVAILABLE_ITEMS,
|
|
163
|
-
errorCode,
|
|
164
|
-
debugMessage,
|
|
165
|
-
null,
|
|
166
|
-
)
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
override fun onPurchaseResponse(response: PurchaseResponse) {
|
|
172
|
-
val requestId = response.requestId.toString()
|
|
173
|
-
val userId = response.userData.userId
|
|
174
|
-
|
|
175
|
-
when (response.requestStatus) {
|
|
176
|
-
PurchaseResponse.RequestStatus.SUCCESSFUL -> {
|
|
177
|
-
val receipt = response.receipt
|
|
178
|
-
val userData = response.userData
|
|
179
|
-
val item = receipt.toMap(userData)
|
|
180
|
-
val promiseItem: WritableMap = Arguments.createMap()
|
|
181
|
-
promiseItem.merge(item)
|
|
182
|
-
eventSender?.sendEvent("purchase-updated", item)
|
|
183
|
-
PromiseUtils
|
|
184
|
-
.resolvePromisesForKey(
|
|
185
|
-
RNIapAmazonModule.PROMISE_BUY_ITEM,
|
|
186
|
-
promiseItem,
|
|
187
|
-
)
|
|
188
|
-
}
|
|
189
|
-
PurchaseResponse.RequestStatus.ALREADY_PURCHASED -> {
|
|
190
|
-
val error = Arguments.createMap()
|
|
191
|
-
val debugMessage = "You already own this item."
|
|
192
|
-
val errorCode = PromiseUtils.E_ALREADY_OWNED
|
|
193
|
-
error.putInt("responseCode", 0)
|
|
194
|
-
error.putString("debugMessage", debugMessage)
|
|
195
|
-
error.putString("code", errorCode)
|
|
196
|
-
error.putString("message", debugMessage)
|
|
197
|
-
eventSender?.sendEvent("purchase-error", error)
|
|
198
|
-
PromiseUtils
|
|
199
|
-
.rejectPromisesForKey(
|
|
200
|
-
RNIapAmazonModule.PROMISE_BUY_ITEM,
|
|
201
|
-
errorCode,
|
|
202
|
-
debugMessage,
|
|
203
|
-
null,
|
|
204
|
-
)
|
|
205
|
-
}
|
|
206
|
-
PurchaseResponse.RequestStatus.FAILED -> {
|
|
207
|
-
val error = Arguments.createMap()
|
|
208
|
-
val debugMessage =
|
|
209
|
-
"An unknown or unexpected error has occurred. Please try again later."
|
|
210
|
-
val errorCode = PromiseUtils.E_UNKNOWN
|
|
211
|
-
error.putInt("responseCode", 0)
|
|
212
|
-
error.putString("debugMessage", debugMessage)
|
|
213
|
-
error.putString("code", errorCode)
|
|
214
|
-
error.putString("message", debugMessage)
|
|
215
|
-
eventSender?.sendEvent("purchase-error", error)
|
|
216
|
-
PromiseUtils
|
|
217
|
-
.rejectPromisesForKey(
|
|
218
|
-
RNIapAmazonModule.PROMISE_BUY_ITEM,
|
|
219
|
-
errorCode,
|
|
220
|
-
debugMessage,
|
|
221
|
-
null,
|
|
222
|
-
)
|
|
223
|
-
}
|
|
224
|
-
PurchaseResponse.RequestStatus.INVALID_SKU -> {
|
|
225
|
-
val error = Arguments.createMap()
|
|
226
|
-
val debugMessage = "That item is unavailable."
|
|
227
|
-
val errorCode = PromiseUtils.E_ITEM_UNAVAILABLE
|
|
228
|
-
error.putInt("responseCode", 0)
|
|
229
|
-
error.putString("debugMessage", debugMessage)
|
|
230
|
-
error.putString("code", errorCode)
|
|
231
|
-
error.putString("message", debugMessage)
|
|
232
|
-
eventSender?.sendEvent("purchase-error", error)
|
|
233
|
-
PromiseUtils
|
|
234
|
-
.rejectPromisesForKey(
|
|
235
|
-
RNIapAmazonModule.PROMISE_BUY_ITEM,
|
|
236
|
-
errorCode,
|
|
237
|
-
debugMessage,
|
|
238
|
-
null,
|
|
239
|
-
)
|
|
240
|
-
}
|
|
241
|
-
PurchaseResponse.RequestStatus.PENDING -> {
|
|
242
|
-
val error = Arguments.createMap()
|
|
243
|
-
val debugMessage = "Purchase is pending. Please wait for the transaction to complete."
|
|
244
|
-
val errorCode = PromiseUtils.E_PENDING
|
|
245
|
-
error.putInt("responseCode", 0)
|
|
246
|
-
error.putString("code", errorCode)
|
|
247
|
-
error.putString("debugMessage", debugMessage)
|
|
248
|
-
error.putString("message", debugMessage)
|
|
249
|
-
eventSender?.sendEvent("purchase-error", error)
|
|
250
|
-
PromiseUtils
|
|
251
|
-
.rejectPromisesForKey(
|
|
252
|
-
RNIapAmazonModule.PROMISE_BUY_ITEM,
|
|
253
|
-
errorCode,
|
|
254
|
-
debugMessage,
|
|
255
|
-
null,
|
|
256
|
-
)
|
|
257
|
-
}
|
|
258
|
-
PurchaseResponse.RequestStatus.NOT_SUPPORTED -> {
|
|
259
|
-
val error = Arguments.createMap()
|
|
260
|
-
val debugMessage = "This feature is not available on your device."
|
|
261
|
-
val errorCode = PromiseUtils.E_SERVICE_ERROR
|
|
262
|
-
error.putInt("responseCode", 0)
|
|
263
|
-
error.putString("debugMessage", debugMessage)
|
|
264
|
-
error.putString("code", errorCode)
|
|
265
|
-
error.putString("message", debugMessage)
|
|
266
|
-
eventSender?.sendEvent("purchase-error", error)
|
|
267
|
-
PromiseUtils
|
|
268
|
-
.rejectPromisesForKey(
|
|
269
|
-
RNIapAmazonModule.PROMISE_BUY_ITEM,
|
|
270
|
-
errorCode,
|
|
271
|
-
debugMessage,
|
|
272
|
-
null,
|
|
273
|
-
)
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
override fun onUserDataResponse(response: UserDataResponse) {
|
|
279
|
-
when (response.requestStatus) {
|
|
280
|
-
UserDataResponse.RequestStatus.SUCCESSFUL -> {
|
|
281
|
-
val userData = response.userData
|
|
282
|
-
val item = Arguments.createMap()
|
|
283
|
-
item.putString("userIdAmazon", userData.userId)
|
|
284
|
-
item.putString("userMarketplaceAmazon", userData.marketplace)
|
|
285
|
-
item.putString("userCountryCode", userData.countryCode)
|
|
286
|
-
item.putString("userJsonAmazon", userData.toJSON().toString())
|
|
287
|
-
PromiseUtils
|
|
288
|
-
.resolvePromisesForKey(RNIapAmazonModule.PROMISE_GET_USER_DATA, item)
|
|
289
|
-
}
|
|
290
|
-
UserDataResponse.RequestStatus.NOT_SUPPORTED ->
|
|
291
|
-
PromiseUtils
|
|
292
|
-
.rejectPromisesForKey(
|
|
293
|
-
RNIapAmazonModule.PROMISE_GET_USER_DATA,
|
|
294
|
-
E_USER_DATA_RESPONSE_NOT_SUPPORTED,
|
|
295
|
-
null,
|
|
296
|
-
null,
|
|
297
|
-
)
|
|
298
|
-
UserDataResponse.RequestStatus.FAILED ->
|
|
299
|
-
PromiseUtils
|
|
300
|
-
.rejectPromisesForKey(
|
|
301
|
-
RNIapAmazonModule.PROMISE_GET_USER_DATA,
|
|
302
|
-
E_USER_DATA_RESPONSE_FAILED,
|
|
303
|
-
null,
|
|
304
|
-
null,
|
|
305
|
-
)
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
companion object {
|
|
310
|
-
private const val E_PRODUCT_DATA_RESPONSE_FAILED = "E_PRODUCT_DATA_RESPONSE_FAILED"
|
|
311
|
-
private const val E_PRODUCT_DATA_RESPONSE_NOT_SUPPORTED =
|
|
312
|
-
"E_PRODUCT_DATA_RESPONSE_NOT_SUPPORTED"
|
|
313
|
-
private const val E_PURCHASE_UPDATES_RESPONSE_FAILED = "E_PURCHASE_UPDATES_RESPONSE_FAILED"
|
|
314
|
-
private const val E_PURCHASE_UPDATES_RESPONSE_NOT_SUPPORTED =
|
|
315
|
-
"E_PURCHASE_UPDATES_RESPONSE_NOT_SUPPORTED"
|
|
316
|
-
private const val E_PURCHASE_RESPONSE_FAILED = "E_PURCHASE_RESPONSE_FAILED"
|
|
317
|
-
private const val E_PURCHASE_RESPONSE_ALREADY_PURCHASED =
|
|
318
|
-
"E_PURCHASE_RESPONSE_ALREADY_PURCHASED"
|
|
319
|
-
private const val E_PURCHASE_RESPONSE_NOT_SUPPORTED = "E_PURCHASE_RESPONSE_NOT_SUPPORTED"
|
|
320
|
-
private const val E_PURCHASE_RESPONSE_INVALID_SKU = "E_PURCHASE_RESPONSE_INVALID_SKU"
|
|
321
|
-
private const val E_USER_DATA_RESPONSE_FAILED = "E_USER_DATA_RESPONSE_FAILED"
|
|
322
|
-
private const val E_USER_DATA_RESPONSE_NOT_SUPPORTED = "E_USER_DATA_RESPONSE_NOT_SUPPORTED"
|
|
323
|
-
const val TAG = "RNIapAmazonListener"
|
|
324
|
-
}
|
|
325
|
-
}
|
|
@@ -1,244 +0,0 @@
|
|
|
1
|
-
package com.dooboolab.rniap
|
|
2
|
-
|
|
3
|
-
import android.content.Intent
|
|
4
|
-
import android.net.Uri
|
|
5
|
-
import android.util.Log
|
|
6
|
-
import androidx.core.content.ContextCompat.startActivity
|
|
7
|
-
import com.amazon.device.drm.LicensingService
|
|
8
|
-
import com.amazon.device.drm.model.LicenseResponse
|
|
9
|
-
import com.amazon.device.iap.model.FulfillmentResult
|
|
10
|
-
import com.amazon.device.iap.model.ProrationMode
|
|
11
|
-
import com.facebook.react.bridge.LifecycleEventListener
|
|
12
|
-
import com.facebook.react.bridge.Promise
|
|
13
|
-
import com.facebook.react.bridge.ReactApplicationContext
|
|
14
|
-
import com.facebook.react.bridge.ReactContextBaseJavaModule
|
|
15
|
-
import com.facebook.react.bridge.ReactMethod
|
|
16
|
-
import com.facebook.react.bridge.ReadableArray
|
|
17
|
-
import com.facebook.react.bridge.WritableMap
|
|
18
|
-
import com.facebook.react.module.annotations.ReactModule
|
|
19
|
-
import com.facebook.react.modules.core.DeviceEventManagerModule
|
|
20
|
-
|
|
21
|
-
@ReactModule(name = RNIapAmazonModule.TAG)
|
|
22
|
-
class RNIapAmazonModule(
|
|
23
|
-
private val reactContext: ReactApplicationContext,
|
|
24
|
-
private val purchasingService: PurchasingServiceProxy = PurchasingServiceProxyAmazonImpl(),
|
|
25
|
-
private var eventSender: EventSender? = null,
|
|
26
|
-
) : ReactContextBaseJavaModule(reactContext) {
|
|
27
|
-
override fun getName(): String = TAG
|
|
28
|
-
|
|
29
|
-
@ReactMethod
|
|
30
|
-
fun initConnection(promise: Promise) {
|
|
31
|
-
if (RNIapActivityListener.amazonListener == null) {
|
|
32
|
-
promise.safeReject(
|
|
33
|
-
PromiseUtils.E_DEVELOPER_ERROR,
|
|
34
|
-
Exception("RNIapActivityListener is not registered in your MainActivity.onCreate"),
|
|
35
|
-
)
|
|
36
|
-
return
|
|
37
|
-
}
|
|
38
|
-
if (eventSender == null) {
|
|
39
|
-
eventSender =
|
|
40
|
-
object : EventSender {
|
|
41
|
-
private val rctDeviceEventEmitter =
|
|
42
|
-
reactContext
|
|
43
|
-
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
|
|
44
|
-
|
|
45
|
-
override fun sendEvent(
|
|
46
|
-
eventName: String,
|
|
47
|
-
params: WritableMap?,
|
|
48
|
-
) {
|
|
49
|
-
rctDeviceEventEmitter
|
|
50
|
-
.emit(eventName, params)
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
RNIapActivityListener.initListeners(eventSender, purchasingService)
|
|
55
|
-
promise.resolve(true)
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
@ReactMethod
|
|
59
|
-
fun verifyLicense(promise: Promise) {
|
|
60
|
-
if (!BuildConfig.IS_AMAZON_DRM_ENABLED) {
|
|
61
|
-
Log.d(TAG, "Amazon's DRM is disabled")
|
|
62
|
-
promise.resolve("NOT_LICENSED")
|
|
63
|
-
return
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
Log.d(TAG, "Amazon's DRM is enabled")
|
|
67
|
-
try {
|
|
68
|
-
LicensingService.verifyLicense(reactApplicationContext) { licenseResponse ->
|
|
69
|
-
val status = licenseResponse.requestStatus.also {
|
|
70
|
-
Log.d(TAG, "LicenseResponse status: $it")
|
|
71
|
-
}
|
|
72
|
-
when (status) {
|
|
73
|
-
LicenseResponse.RequestStatus.LICENSED -> "LICENSED"
|
|
74
|
-
LicenseResponse.RequestStatus.NOT_LICENSED -> "NOT_LICENSED"
|
|
75
|
-
LicenseResponse.RequestStatus.EXPIRED -> "EXPIRED"
|
|
76
|
-
LicenseResponse.RequestStatus.ERROR_VERIFICATION -> "ERROR_VERIFICATION"
|
|
77
|
-
LicenseResponse.RequestStatus.ERROR_INVALID_LICENSING_KEYS -> "ERROR_INVALID_LICENSING_KEYS"
|
|
78
|
-
LicenseResponse.RequestStatus.UNKNOWN_ERROR -> "UNKNOWN_ERROR"
|
|
79
|
-
else -> null
|
|
80
|
-
}?.let { promise.resolve(it) }
|
|
81
|
-
}
|
|
82
|
-
} catch (exception: Exception) {
|
|
83
|
-
promise.reject("Error while attempting to check for License", exception)
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
@ReactMethod
|
|
88
|
-
fun endConnection(promise: Promise) {
|
|
89
|
-
PromiseUtils.rejectAllPendingPromises()
|
|
90
|
-
RNIapActivityListener.hasListener = false
|
|
91
|
-
promise.resolve(true)
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
@ReactMethod
|
|
95
|
-
fun getUser(promise: Promise) {
|
|
96
|
-
val requestId = purchasingService.getUserData()
|
|
97
|
-
PromiseUtils.addPromiseForKey(PROMISE_GET_USER_DATA, promise)
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
@ReactMethod
|
|
101
|
-
fun flushFailedPurchasesCachedAsPending(promise: Promise) {
|
|
102
|
-
// No-op
|
|
103
|
-
promise.resolve(true)
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
@ReactMethod
|
|
107
|
-
fun getItemsByType(
|
|
108
|
-
type: String?,
|
|
109
|
-
skuArr: ReadableArray,
|
|
110
|
-
promise: Promise,
|
|
111
|
-
) {
|
|
112
|
-
val productSkus: MutableSet<String> = HashSet()
|
|
113
|
-
var ii = 0
|
|
114
|
-
val skuSize = skuArr.size()
|
|
115
|
-
while (ii < skuSize) {
|
|
116
|
-
skuArr.getString(ii)?.let { sku ->
|
|
117
|
-
productSkus.add(sku)
|
|
118
|
-
}
|
|
119
|
-
ii++
|
|
120
|
-
}
|
|
121
|
-
PromiseUtils.addPromiseForKey(PROMISE_GET_PRODUCT_DATA, promise)
|
|
122
|
-
val requestId = purchasingService.getProductData(productSkus)
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
@ReactMethod
|
|
126
|
-
fun getAvailableItems(promise: Promise) {
|
|
127
|
-
PromiseUtils.addPromiseForKey(PROMISE_QUERY_AVAILABLE_ITEMS, promise)
|
|
128
|
-
purchasingService.getPurchaseUpdates(true)
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
@ReactMethod
|
|
132
|
-
fun buyItemByType(
|
|
133
|
-
sku: String?,
|
|
134
|
-
proration: String?,
|
|
135
|
-
promise: Promise,
|
|
136
|
-
) {
|
|
137
|
-
PromiseUtils.addPromiseForKey(PROMISE_BUY_ITEM, promise)
|
|
138
|
-
val requestId = if (!proration.isNullOrEmpty()) {
|
|
139
|
-
purchasingService.modifySubscription(
|
|
140
|
-
sku,
|
|
141
|
-
if (proration == "DEFERRED") ProrationMode.DEFERRED else ProrationMode.IMMEDIATE,
|
|
142
|
-
)
|
|
143
|
-
} else {
|
|
144
|
-
purchasingService.purchase(sku)
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
@ReactMethod
|
|
149
|
-
fun acknowledgePurchase(
|
|
150
|
-
token: String?,
|
|
151
|
-
developerPayLoad: String?,
|
|
152
|
-
promise: Promise,
|
|
153
|
-
) {
|
|
154
|
-
purchasingService.notifyFulfillment(token, FulfillmentResult.FULFILLED)
|
|
155
|
-
promise.resolve(true)
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
@ReactMethod
|
|
159
|
-
fun consumeProduct(
|
|
160
|
-
token: String?,
|
|
161
|
-
developerPayLoad: String?,
|
|
162
|
-
promise: Promise,
|
|
163
|
-
) {
|
|
164
|
-
purchasingService.notifyFulfillment(token, FulfillmentResult.FULFILLED)
|
|
165
|
-
promise.resolve(true)
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
private fun sendUnconsumedPurchases(promise: Promise) {
|
|
169
|
-
PromiseUtils.addPromiseForKey(PROMISE_QUERY_PURCHASES, promise)
|
|
170
|
-
purchasingService.getPurchaseUpdates(false)
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
/**
|
|
174
|
-
* Redirects user to a screen where they can manage their subscriptions.
|
|
175
|
-
* on Amazon devices it will use the system dialog whereas on Android devices that install the Amazon app store, it'll use the browser.
|
|
176
|
-
* This based on provided parameter `isAmazonDevice`
|
|
177
|
-
* From https://amazon.developer.forums.answerhub.com/questions/175720/how-to-open-store-subscription-screen-directly-use.html?childToView=179402#answer-179402
|
|
178
|
-
*/
|
|
179
|
-
@ReactMethod
|
|
180
|
-
fun deepLinkToSubscriptions(
|
|
181
|
-
isAmazonDevice: Boolean,
|
|
182
|
-
promise: Promise,
|
|
183
|
-
) {
|
|
184
|
-
if (isAmazonDevice) {
|
|
185
|
-
val intent =
|
|
186
|
-
Intent("android.intent.action.VIEW", Uri.parse("amzn://apps/library/subscriptions"))
|
|
187
|
-
startActivity(reactContext, intent, null)
|
|
188
|
-
} else {
|
|
189
|
-
val uri =
|
|
190
|
-
Uri.parse("https://www.amazon.com/gp/mas/your-account/myapps/yoursubscriptions/ref=mas_ya_subs")
|
|
191
|
-
val launchIntent = Intent(Intent.ACTION_VIEW, uri)
|
|
192
|
-
launchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
|
193
|
-
startActivity(reactContext, launchIntent, null)
|
|
194
|
-
}
|
|
195
|
-
promise.resolve(true)
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
@ReactMethod
|
|
199
|
-
fun startListening(promise: Promise) {
|
|
200
|
-
sendUnconsumedPurchases(promise)
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
@ReactMethod
|
|
204
|
-
fun addListener(eventName: String) {
|
|
205
|
-
// Keep: Required for RN built-in Event Emitter Calls.
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
@ReactMethod
|
|
209
|
-
fun removeListeners(count: Double) {
|
|
210
|
-
// Keep: Required for RN built-in Event Emitter Calls.
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
companion object {
|
|
214
|
-
const val PROMISE_BUY_ITEM = "PROMISE_BUY_ITEM"
|
|
215
|
-
const val PROMISE_GET_PRODUCT_DATA = "PROMISE_GET_PRODUCT_DATA"
|
|
216
|
-
const val PROMISE_QUERY_PURCHASES = "PROMISE_QUERY_PURCHASES"
|
|
217
|
-
const val PROMISE_QUERY_AVAILABLE_ITEMS = "PROMISE_QUERY_AVAILABLE_ITEMS"
|
|
218
|
-
const val PROMISE_GET_USER_DATA = "PROMISE_GET_USER_DATA"
|
|
219
|
-
|
|
220
|
-
const val TAG = "RNIapAmazonModule"
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
init {
|
|
224
|
-
val lifecycleEventListener: LifecycleEventListener =
|
|
225
|
-
object : LifecycleEventListener {
|
|
226
|
-
/**
|
|
227
|
-
* From https://developer.amazon.com/docs/in-app-purchasing/iap-implement-iap.html#getpurchaseupdates-responses
|
|
228
|
-
* We should fetch updates on resume
|
|
229
|
-
*/
|
|
230
|
-
override fun onHostResume() {
|
|
231
|
-
if (RNIapActivityListener.hasListener) {
|
|
232
|
-
purchasingService.getUserData()
|
|
233
|
-
purchasingService.getPurchaseUpdates(false)
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
override fun onHostPause() {}
|
|
238
|
-
|
|
239
|
-
override fun onHostDestroy() {
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
reactContext.addLifecycleEventListener(lifecycleEventListener)
|
|
243
|
-
}
|
|
244
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
package com.dooboolab.rniap
|
|
2
|
-
|
|
3
|
-
import com.facebook.react.ReactPackage
|
|
4
|
-
import com.facebook.react.bridge.NativeModule
|
|
5
|
-
import com.facebook.react.bridge.ReactApplicationContext
|
|
6
|
-
import com.facebook.react.uimanager.ViewManager
|
|
7
|
-
import java.util.ArrayList
|
|
8
|
-
|
|
9
|
-
class RNIapPackage : ReactPackage {
|
|
10
|
-
override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> = emptyList()
|
|
11
|
-
|
|
12
|
-
override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
|
|
13
|
-
val modules: MutableList<NativeModule> = ArrayList()
|
|
14
|
-
modules.add(RNIapAmazonModule(reactContext))
|
|
15
|
-
return modules
|
|
16
|
-
}
|
|
17
|
-
}
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
package com.dooboolab.rniap.modifysubscription
|
|
2
|
-
|
|
3
|
-
import android.util.Log
|
|
4
|
-
import com.amazon.device.iap.ModifySubscriptionListener
|
|
5
|
-
import com.amazon.device.iap.model.ModifySubscriptionResponse
|
|
6
|
-
import com.dooboolab.rniap.EventSender
|
|
7
|
-
import com.dooboolab.rniap.PromiseUtils
|
|
8
|
-
import com.dooboolab.rniap.RNIapAmazonModule
|
|
9
|
-
import com.dooboolab.rniap.utils.toMap
|
|
10
|
-
import com.facebook.react.bridge.Arguments
|
|
11
|
-
import com.facebook.react.bridge.WritableMap
|
|
12
|
-
|
|
13
|
-
class RNIapAmazonModifySubscriptionListener(
|
|
14
|
-
var eventSender: EventSender?,
|
|
15
|
-
) : ModifySubscriptionListener {
|
|
16
|
-
|
|
17
|
-
companion object {
|
|
18
|
-
private const val TAG = "AmazonModifySbnListener"
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
override fun onModifySubscriptionResponse(response: ModifySubscriptionResponse) {
|
|
22
|
-
Log.d(TAG, "onModifySubscriptionResponse ${response.requestStatus}")
|
|
23
|
-
|
|
24
|
-
when (response.requestStatus) {
|
|
25
|
-
ModifySubscriptionResponse.RequestStatus.SUCCESSFUL -> {
|
|
26
|
-
response.receipts.map { receipt ->
|
|
27
|
-
val item = receipt.toMap(response.userData)
|
|
28
|
-
val promiseItem: WritableMap = Arguments.createMap()
|
|
29
|
-
promiseItem.merge(item)
|
|
30
|
-
eventSender?.sendEvent("purchase-updated", item)
|
|
31
|
-
PromiseUtils
|
|
32
|
-
.resolvePromisesForKey(
|
|
33
|
-
RNIapAmazonModule.PROMISE_BUY_ITEM,
|
|
34
|
-
promiseItem,
|
|
35
|
-
)
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
else -> {
|
|
40
|
-
val messageAndCode = when (response.requestStatus) {
|
|
41
|
-
ModifySubscriptionResponse.RequestStatus.FAILED -> Pair(
|
|
42
|
-
"An unknown or unexpected error has occurred. Please try again later.",
|
|
43
|
-
PromiseUtils.E_UNKNOWN,
|
|
44
|
-
)
|
|
45
|
-
|
|
46
|
-
ModifySubscriptionResponse.RequestStatus.INVALID_SKU -> Pair(
|
|
47
|
-
"That item is unavailable.",
|
|
48
|
-
PromiseUtils.E_ITEM_UNAVAILABLE,
|
|
49
|
-
)
|
|
50
|
-
|
|
51
|
-
ModifySubscriptionResponse.RequestStatus.NOT_SUPPORTED -> Pair(
|
|
52
|
-
"This feature is not available on your device.",
|
|
53
|
-
PromiseUtils.E_SERVICE_ERROR,
|
|
54
|
-
)
|
|
55
|
-
|
|
56
|
-
else -> null
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if (messageAndCode == null) {
|
|
60
|
-
Log.d(
|
|
61
|
-
TAG,
|
|
62
|
-
"onModifySubscriptionResponse: ${response.requestStatus} is not handled",
|
|
63
|
-
)
|
|
64
|
-
return
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
val debugMessage = messageAndCode.first
|
|
68
|
-
val errorCode = messageAndCode.second
|
|
69
|
-
|
|
70
|
-
Arguments.createMap().also {
|
|
71
|
-
it.putInt("responseCode", 0)
|
|
72
|
-
it.putString("debugMessage", debugMessage)
|
|
73
|
-
it.putString("code", errorCode)
|
|
74
|
-
it.putString("message", debugMessage)
|
|
75
|
-
eventSender?.sendEvent("purchase-error", it)
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
PromiseUtils
|
|
79
|
-
.rejectPromisesForKey(
|
|
80
|
-
RNIapAmazonModule.PROMISE_BUY_ITEM,
|
|
81
|
-
errorCode,
|
|
82
|
-
debugMessage,
|
|
83
|
-
null,
|
|
84
|
-
)
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}
|