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
package/ios/RNIapIos.swift
DELETED
|
@@ -1,868 +0,0 @@
|
|
|
1
|
-
import React
|
|
2
|
-
import StoreKit
|
|
3
|
-
|
|
4
|
-
@objc(RNIapIos)
|
|
5
|
-
class RNIapIos: RCTEventEmitter, SKRequestDelegate, SKPaymentTransactionObserver, SKProductsRequestDelegate {
|
|
6
|
-
private var promisesByKey: [String: [RNIapIosPromise]]
|
|
7
|
-
private var myQueue: DispatchQueue
|
|
8
|
-
private var hasListeners = false
|
|
9
|
-
private var pendingTransactionWithAutoFinish = false
|
|
10
|
-
private var receiptBlock: ((Data?, Error?) -> Void)? // Block to handle request the receipt async from delegate
|
|
11
|
-
private var validProducts: ThreadSafe<[String: SKProduct]>
|
|
12
|
-
private var promotedPayment: SKPayment?
|
|
13
|
-
private var promotedProduct: SKProduct?
|
|
14
|
-
private var productsRequest: SKProductsRequest?
|
|
15
|
-
private let latestPromiseKeeper = LatestPromiseKeeper()
|
|
16
|
-
private var countPendingTransaction: Int = 0
|
|
17
|
-
private var hasTransactionObserver = false
|
|
18
|
-
|
|
19
|
-
override init() {
|
|
20
|
-
promisesByKey = [String: [RNIapIosPromise]]()
|
|
21
|
-
pendingTransactionWithAutoFinish = false
|
|
22
|
-
myQueue = DispatchQueue(label: "reject")
|
|
23
|
-
validProducts = ThreadSafe<[String: SKProduct]>([:])
|
|
24
|
-
super.init()
|
|
25
|
-
addTransactionObserver()
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
deinit {
|
|
29
|
-
removeTransactionObserver()
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
@objc public func disable(
|
|
33
|
-
_ resolve: @escaping RCTPromiseResolveBlock = { _ in },
|
|
34
|
-
reject: @escaping RCTPromiseRejectBlock = { _, _, _ in }
|
|
35
|
-
) {
|
|
36
|
-
removeTransactionObserver()
|
|
37
|
-
resolve(nil)
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
override class func requiresMainQueueSetup() -> Bool {
|
|
41
|
-
return true
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
func addTransactionObserver() {
|
|
45
|
-
if !hasTransactionObserver {
|
|
46
|
-
hasTransactionObserver = true
|
|
47
|
-
SKPaymentQueue.default().add(self)
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
func removeTransactionObserver() {
|
|
52
|
-
if hasTransactionObserver {
|
|
53
|
-
hasTransactionObserver = false
|
|
54
|
-
SKPaymentQueue.default().remove(self)
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
func flushUnheardEvents() {
|
|
59
|
-
paymentQueue(SKPaymentQueue.default(), updatedTransactions: SKPaymentQueue.default().transactions)
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
override func startObserving() {
|
|
63
|
-
hasListeners = true
|
|
64
|
-
flushUnheardEvents()
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
override func stopObserving() {
|
|
68
|
-
hasListeners = false
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
override func addListener(_ eventName: String?) {
|
|
72
|
-
super.addListener(eventName)
|
|
73
|
-
|
|
74
|
-
if (eventName == "iap-promoted-product") && promotedPayment != nil {
|
|
75
|
-
sendEvent(withName: "iap-promoted-product", body: promotedPayment?.productIdentifier)
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
func addPromise(forKey key: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
|
80
|
-
var promises: [RNIapIosPromise]? = promisesByKey[key]
|
|
81
|
-
|
|
82
|
-
if promises == nil {
|
|
83
|
-
promises = []
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
promises?.append((resolve, reject))
|
|
87
|
-
promisesByKey[key] = promises
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
func resolvePromises(forKey key: String?, value: Any?) {
|
|
91
|
-
let promises: [RNIapIosPromise]? = promisesByKey[key ?? ""]
|
|
92
|
-
|
|
93
|
-
if let promises = promises {
|
|
94
|
-
for tuple in promises {
|
|
95
|
-
let resolveBlck = tuple.0
|
|
96
|
-
resolveBlck(value)
|
|
97
|
-
}
|
|
98
|
-
promisesByKey[key ?? ""] = nil
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
func rejectPromises(forKey key: String, code: String?, message: String?, error: Error?) {
|
|
103
|
-
let promises = promisesByKey[key]
|
|
104
|
-
|
|
105
|
-
if let promises = promises {
|
|
106
|
-
for tuple in promises {
|
|
107
|
-
let reject = tuple.1
|
|
108
|
-
reject(code, message, error)
|
|
109
|
-
}
|
|
110
|
-
promisesByKey[key] = nil
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
func rejectAllPendingPromises() {
|
|
115
|
-
promisesByKey.values.reduce([], +).forEach({tuple in
|
|
116
|
-
let reject = tuple.1
|
|
117
|
-
reject("E_CONNECTION_CLOSED", "Connection has been closed", nil)
|
|
118
|
-
})
|
|
119
|
-
promisesByKey.removeAll()
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
func paymentQueue(_ queue: SKPaymentQueue, shouldAddStorePayment payment: SKPayment, for product: SKProduct) -> Bool {
|
|
123
|
-
promotedProduct = product
|
|
124
|
-
promotedPayment = payment
|
|
125
|
-
|
|
126
|
-
if hasListeners {
|
|
127
|
-
sendEvent(withName: "iap-promoted-product", body: product.productIdentifier)
|
|
128
|
-
}
|
|
129
|
-
return false
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
override func supportedEvents() -> [String]? {
|
|
133
|
-
return ["iap-promoted-product", "purchase-updated", "purchase-error"]
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
@objc public func initConnection(
|
|
137
|
-
_ resolve: @escaping RCTPromiseResolveBlock = { _ in },
|
|
138
|
-
reject: @escaping RCTPromiseRejectBlock = { _, _, _ in }
|
|
139
|
-
) {
|
|
140
|
-
addTransactionObserver()
|
|
141
|
-
let canMakePayments = SKPaymentQueue.canMakePayments()
|
|
142
|
-
resolve(NSNumber(value: canMakePayments))
|
|
143
|
-
}
|
|
144
|
-
@objc public func endConnection(
|
|
145
|
-
_ resolve: @escaping RCTPromiseResolveBlock = { _ in },
|
|
146
|
-
reject: @escaping RCTPromiseRejectBlock = { _, _, _ in }
|
|
147
|
-
) {
|
|
148
|
-
removeTransactionObserver()
|
|
149
|
-
stopObserving()
|
|
150
|
-
rejectAllPendingPromises()
|
|
151
|
-
receiptBlock = nil
|
|
152
|
-
validProducts.atomically { $0.removeAll() }
|
|
153
|
-
promotedPayment = nil
|
|
154
|
-
promotedProduct = nil
|
|
155
|
-
productsRequest = nil
|
|
156
|
-
countPendingTransaction = 0
|
|
157
|
-
resolve(nil)
|
|
158
|
-
}
|
|
159
|
-
@objc public func getItems(
|
|
160
|
-
_ skus: [String],
|
|
161
|
-
resolve: @escaping RCTPromiseResolveBlock = { _ in },
|
|
162
|
-
reject: @escaping RCTPromiseRejectBlock = { _, _, _ in }
|
|
163
|
-
) {
|
|
164
|
-
let productIdentifiers = Set<String>(skus)
|
|
165
|
-
productsRequest = SKProductsRequest(productIdentifiers: productIdentifiers)
|
|
166
|
-
|
|
167
|
-
if let productsRequest = productsRequest {
|
|
168
|
-
productsRequest.delegate = self
|
|
169
|
-
|
|
170
|
-
self.latestPromiseKeeper.setLatestPromise(request: productsRequest, resolve: resolve, reject: reject)
|
|
171
|
-
|
|
172
|
-
productsRequest.start()
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
@objc public func getAvailableItems(
|
|
176
|
-
_ automaticallyFinishRestoredTransactions: Bool,
|
|
177
|
-
resolve: @escaping RCTPromiseResolveBlock = { _ in },
|
|
178
|
-
reject: @escaping RCTPromiseRejectBlock = { _, _, _ in }
|
|
179
|
-
) {
|
|
180
|
-
pendingTransactionWithAutoFinish = automaticallyFinishRestoredTransactions
|
|
181
|
-
addPromise(forKey: "availableItems", resolve: resolve, reject: reject)
|
|
182
|
-
SKPaymentQueue.default().restoreCompletedTransactions()
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
@objc public func buyProduct(
|
|
186
|
-
_ sku: String,
|
|
187
|
-
andDangerouslyFinishTransactionAutomatically: Bool,
|
|
188
|
-
applicationUsername: String?,
|
|
189
|
-
quantity: Int,
|
|
190
|
-
withOffer discountOffer: [String: String]?,
|
|
191
|
-
resolve: @escaping RCTPromiseResolveBlock = { _ in },
|
|
192
|
-
reject: @escaping RCTPromiseRejectBlock = { _, _, _ in }
|
|
193
|
-
) {
|
|
194
|
-
pendingTransactionWithAutoFinish = andDangerouslyFinishTransactionAutomatically
|
|
195
|
-
if let product = validProducts.value[sku] {
|
|
196
|
-
addPromise(forKey: product.productIdentifier, resolve: resolve, reject: reject)
|
|
197
|
-
|
|
198
|
-
let payment = SKMutablePayment(product: product)
|
|
199
|
-
|
|
200
|
-
if #available(iOS 12.2, tvOS 12.2, *) {
|
|
201
|
-
if let discountOffer = discountOffer, let identifier = discountOffer["identifier"], let keyIdentifier = discountOffer["keyIdentifier"], let nonce = discountOffer["nonce"], let signature = discountOffer["signature"], let timestamp = discountOffer["timestamp"] {
|
|
202
|
-
let discount = SKPaymentDiscount(
|
|
203
|
-
identifier: identifier,
|
|
204
|
-
keyIdentifier: keyIdentifier,
|
|
205
|
-
nonce: UUID(uuidString: nonce)!,
|
|
206
|
-
signature: signature,
|
|
207
|
-
timestamp: NSNumber(value: Int(timestamp)!))
|
|
208
|
-
payment.paymentDiscount = discount
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
if let applicationUsername = applicationUsername {
|
|
213
|
-
payment.applicationUsername = applicationUsername
|
|
214
|
-
}
|
|
215
|
-
if quantity > 0 {
|
|
216
|
-
payment.quantity = quantity
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
SKPaymentQueue.default().add(payment)
|
|
220
|
-
} else {
|
|
221
|
-
if hasListeners {
|
|
222
|
-
let err = [
|
|
223
|
-
"debugMessage": "Invalid product ID.",
|
|
224
|
-
"code": "E_DEVELOPER_ERROR",
|
|
225
|
-
"message": "Invalid product ID.",
|
|
226
|
-
"productId": sku
|
|
227
|
-
]
|
|
228
|
-
|
|
229
|
-
sendEvent(withName: "purchase-error", body: err)
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
reject("E_DEVELOPER_ERROR", "Invalid product ID.", nil)
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
@objc public func clearTransaction(
|
|
237
|
-
_ resolve: @escaping RCTPromiseResolveBlock = { _ in },
|
|
238
|
-
reject: @escaping RCTPromiseRejectBlock = { _, _, _ in }
|
|
239
|
-
) {
|
|
240
|
-
let pendingTrans = SKPaymentQueue.default().transactions
|
|
241
|
-
countPendingTransaction = pendingTrans.count
|
|
242
|
-
|
|
243
|
-
debugMessage("clear remaining Transactions (\(countPendingTransaction)). Call this before make a new transaction")
|
|
244
|
-
|
|
245
|
-
if countPendingTransaction > 0 {
|
|
246
|
-
addPromise(forKey: "cleaningTransactions", resolve: resolve, reject: reject)
|
|
247
|
-
for transaction in pendingTrans {
|
|
248
|
-
SKPaymentQueue.default().finishTransaction(transaction)
|
|
249
|
-
}
|
|
250
|
-
} else {
|
|
251
|
-
resolve(nil)
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
@objc public func clearProducts(
|
|
256
|
-
_ resolve: @escaping RCTPromiseResolveBlock = { _ in },
|
|
257
|
-
reject: @escaping RCTPromiseRejectBlock = { _, _, _ in }
|
|
258
|
-
) {
|
|
259
|
-
debugMessage("clear valid products")
|
|
260
|
-
validProducts.atomically { $0.removeAll() }
|
|
261
|
-
resolve(nil)
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
@objc public func promotedProduct(
|
|
265
|
-
_ resolve: @escaping RCTPromiseResolveBlock = { _ in },
|
|
266
|
-
reject: @escaping RCTPromiseRejectBlock = { _, _, _ in }
|
|
267
|
-
) {
|
|
268
|
-
debugMessage("get promoted product")
|
|
269
|
-
resolve((promotedProduct != nil) ? getProductObject(promotedProduct!) : nil)
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
@objc public func buyPromotedProduct(
|
|
273
|
-
_ resolve: @escaping RCTPromiseResolveBlock = { _ in },
|
|
274
|
-
reject: @escaping RCTPromiseRejectBlock = { _, _, _ in }
|
|
275
|
-
) {
|
|
276
|
-
if let promoPayment = promotedPayment {
|
|
277
|
-
debugMessage("buy promoted product")
|
|
278
|
-
SKPaymentQueue.default().add(promoPayment)
|
|
279
|
-
} else {
|
|
280
|
-
reject("E_DEVELOPER_ERROR", "Invalid product ID.", nil)
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
/** The sequence should be as follows. call this with forceRefresh: false. That will return the cached receipt that is available on TestFlight and Production. In the case of Sandbox the receipt might not be cached, this will return nil. In that case you might want to let the user that they will to be prompted for credentials. If they accept, launch this with forceRefresh:true. For reference: https://developer.apple.com/forums/thread/662350 */
|
|
285
|
-
@objc public func requestReceipt(
|
|
286
|
-
_ refresh: Bool,
|
|
287
|
-
resolve: @escaping RCTPromiseResolveBlock = { _ in },
|
|
288
|
-
reject: @escaping RCTPromiseRejectBlock = { _, _, _ in }
|
|
289
|
-
) {
|
|
290
|
-
requestReceiptData(withBlock: refresh) { [self] receiptData, error in
|
|
291
|
-
if error == nil {
|
|
292
|
-
resolve(receiptData?.base64EncodedString(options: [.endLineWithCarriageReturn]))
|
|
293
|
-
} else {
|
|
294
|
-
reject(standardErrorCode(9), "Invalid receipt", error)
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
@objc public func finishTransaction(
|
|
300
|
-
_ transactionIdentifier: String,
|
|
301
|
-
resolve: @escaping RCTPromiseResolveBlock = { _ in },
|
|
302
|
-
reject: @escaping RCTPromiseRejectBlock = { _, _, _ in }
|
|
303
|
-
) {
|
|
304
|
-
finishTransaction(withIdentifier: transactionIdentifier)
|
|
305
|
-
resolve(nil)
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
@objc public func getPendingTransactions (
|
|
309
|
-
_ resolve: @escaping RCTPromiseResolveBlock = { _ in },
|
|
310
|
-
reject: @escaping RCTPromiseRejectBlock = { _, _, _ in }
|
|
311
|
-
) {
|
|
312
|
-
requestReceiptData(withBlock: false) { receiptData, _ in
|
|
313
|
-
var output: [AnyHashable] = []
|
|
314
|
-
|
|
315
|
-
if let receipt = receiptData {
|
|
316
|
-
let transactions = SKPaymentQueue.default().transactions
|
|
317
|
-
|
|
318
|
-
for item in transactions {
|
|
319
|
-
let timestamp = item.transactionDate?.millisecondsSince1970 == nil ? nil : String(item.transactionDate!.millisecondsSince1970)
|
|
320
|
-
let purchase = [
|
|
321
|
-
"transactionDate": timestamp,
|
|
322
|
-
"transactionId": item.transactionIdentifier,
|
|
323
|
-
"productId": item.payment.productIdentifier,
|
|
324
|
-
"quantity": "\(item.payment.quantity)",
|
|
325
|
-
"transactionReceipt": receipt.base64EncodedString(options: [.endLineWithCarriageReturn])
|
|
326
|
-
]
|
|
327
|
-
|
|
328
|
-
output.append(purchase)
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
resolve(output)
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
@objc public func presentCodeRedemptionSheet(
|
|
337
|
-
_ resolve: @escaping RCTPromiseResolveBlock = { _ in },
|
|
338
|
-
reject: @escaping RCTPromiseRejectBlock = { _, _, _ in }
|
|
339
|
-
) {
|
|
340
|
-
#if !os(tvOS)
|
|
341
|
-
if #available(iOS 14.0, tvOS 14.0, *) {
|
|
342
|
-
SKPaymentQueue.default().presentCodeRedemptionSheet()
|
|
343
|
-
resolve(nil)
|
|
344
|
-
} else {
|
|
345
|
-
reject(standardErrorCode(2), "This method only available above iOS 14", nil)
|
|
346
|
-
}
|
|
347
|
-
#else
|
|
348
|
-
reject(standardErrorCode(2), "This method is not available on tvOS", nil)
|
|
349
|
-
#endif
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
// StoreKitDelegate
|
|
353
|
-
func productsRequest(_ request: SKProductsRequest, didReceive response: SKProductsResponse) {
|
|
354
|
-
// Add received products
|
|
355
|
-
for prod in response.products {
|
|
356
|
-
add(prod)
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
var items: [[String: Any?]] = [[:]]
|
|
360
|
-
for product in validProducts.value.values {
|
|
361
|
-
items.append(getProductObject(product))
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
self.latestPromiseKeeper.resolveIfRequestMatches(matchingRequest: request, items: items) { (resolve, items) in
|
|
365
|
-
resolve(items)
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
// Add to valid products from Apple server response. Allowing getProducts, getSubscriptions call several times.
|
|
370
|
-
// Doesn't allow duplication. Replace new product.
|
|
371
|
-
func add(_ aProd: SKProduct) {
|
|
372
|
-
debugMessage("Add new object: \(aProd.productIdentifier)")
|
|
373
|
-
validProducts.atomically { $0[aProd.productIdentifier] = aProd }
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
func request(_ request: SKRequest, didFailWithError error: Error) {
|
|
377
|
-
let nsError = error as NSError
|
|
378
|
-
|
|
379
|
-
if request is SKReceiptRefreshRequest {
|
|
380
|
-
if let receiptBlock = self.receiptBlock {
|
|
381
|
-
let standardError = NSError(domain: nsError.domain, code: 9, userInfo: nsError.userInfo)
|
|
382
|
-
receiptBlock(nil, standardError)
|
|
383
|
-
self.receiptBlock = nil
|
|
384
|
-
return
|
|
385
|
-
} else {
|
|
386
|
-
if let key: String = productsRequest?.key {
|
|
387
|
-
myQueue.sync(execute: { [self] in
|
|
388
|
-
rejectPromises(
|
|
389
|
-
forKey: key,
|
|
390
|
-
code: standardErrorCode(nsError.code),
|
|
391
|
-
message: error.localizedDescription,
|
|
392
|
-
error: error)}
|
|
393
|
-
)
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {
|
|
400
|
-
for transaction in transactions {
|
|
401
|
-
switch transaction.transactionState {
|
|
402
|
-
case .purchasing:
|
|
403
|
-
debugMessage("Purchase Started")
|
|
404
|
-
|
|
405
|
-
case .purchased:
|
|
406
|
-
debugMessage("Purchase Successful")
|
|
407
|
-
purchaseProcess(transaction)
|
|
408
|
-
|
|
409
|
-
case .restored:
|
|
410
|
-
debugMessage("Restored")
|
|
411
|
-
SKPaymentQueue.default().finishTransaction(transaction)
|
|
412
|
-
|
|
413
|
-
case .deferred:
|
|
414
|
-
debugMessage("Deferred (awaiting approval via parental controls, etc.)")
|
|
415
|
-
|
|
416
|
-
myQueue.sync(execute: { [self] in
|
|
417
|
-
if hasListeners {
|
|
418
|
-
let err = [
|
|
419
|
-
"debugMessage": "The payment was deferred (awaiting approval via parental controls for instance)",
|
|
420
|
-
"code": "E_DEFERRED_PAYMENT",
|
|
421
|
-
"message": "The payment was deferred (awaiting approval via parental controls for instance)",
|
|
422
|
-
"productId": transaction.payment.productIdentifier,
|
|
423
|
-
"quantity": "\(transaction.payment.quantity)"
|
|
424
|
-
]
|
|
425
|
-
|
|
426
|
-
sendEvent(withName: "purchase-error", body: err)
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
rejectPromises(
|
|
430
|
-
forKey: transaction.payment.productIdentifier,
|
|
431
|
-
code: "E_DEFERRED_PAYMENT",
|
|
432
|
-
message: "The payment was deferred (awaiting approval via parental controls for instance)",
|
|
433
|
-
error: nil)
|
|
434
|
-
})
|
|
435
|
-
|
|
436
|
-
case .failed:
|
|
437
|
-
debugMessage("Purchase Failed")
|
|
438
|
-
|
|
439
|
-
SKPaymentQueue.default().finishTransaction(transaction)
|
|
440
|
-
|
|
441
|
-
myQueue.sync(execute: { [self] in
|
|
442
|
-
var nsError = transaction.error as? NSError
|
|
443
|
-
// From https://developer.apple.com/forums/thread/674081
|
|
444
|
-
if let underlyingError = nsError?.userInfo["NSUnderlyingError"] as? NSError,
|
|
445
|
-
underlyingError.code == 3038 {
|
|
446
|
-
// General conditions have changed, don't display an error for the interrupted transaction
|
|
447
|
-
nsError = underlyingError
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
if hasListeners {
|
|
451
|
-
let code = nsError?.code
|
|
452
|
-
let responseCode = String(code ?? 0)
|
|
453
|
-
let err = [
|
|
454
|
-
"responseCode": responseCode,
|
|
455
|
-
"debugMessage": transaction.error?.localizedDescription,
|
|
456
|
-
"code": standardErrorCode(code),
|
|
457
|
-
"message": transaction.error?.localizedDescription,
|
|
458
|
-
"productId": transaction.payment.productIdentifier
|
|
459
|
-
]
|
|
460
|
-
|
|
461
|
-
sendEvent(withName: "purchase-error", body: err)
|
|
462
|
-
}
|
|
463
|
-
|
|
464
|
-
rejectPromises(
|
|
465
|
-
forKey: transaction.payment.productIdentifier,
|
|
466
|
-
code: standardErrorCode(nsError?.code),
|
|
467
|
-
message: nsError?.localizedDescription,
|
|
468
|
-
error: nsError)
|
|
469
|
-
})
|
|
470
|
-
}
|
|
471
|
-
}
|
|
472
|
-
}
|
|
473
|
-
|
|
474
|
-
func finishTransaction(withIdentifier transactionIdentifier: String?) {
|
|
475
|
-
let queue = SKPaymentQueue.default()
|
|
476
|
-
|
|
477
|
-
for transaction in queue.transactions {
|
|
478
|
-
if transaction.transactionIdentifier == transactionIdentifier {
|
|
479
|
-
SKPaymentQueue.default().finishTransaction(transaction)
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
func paymentQueueRestoreCompletedTransactionsFinished(_ queue: SKPaymentQueue) {
|
|
485
|
-
debugMessage("PaymentQueueRestoreCompletedTransactionsFinished")
|
|
486
|
-
var items = [[String: Any?]]()
|
|
487
|
-
|
|
488
|
-
for transaction in queue.transactions {
|
|
489
|
-
if transaction.transactionState == .restored || transaction.transactionState == .purchased {
|
|
490
|
-
getPurchaseData(transaction) { restored in
|
|
491
|
-
if let restored = restored {
|
|
492
|
-
items.append(restored)
|
|
493
|
-
}
|
|
494
|
-
if self.pendingTransactionWithAutoFinish {
|
|
495
|
-
SKPaymentQueue.default().finishTransaction(transaction)
|
|
496
|
-
}
|
|
497
|
-
}
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
pendingTransactionWithAutoFinish = false
|
|
501
|
-
resolvePromises(forKey: "availableItems", value: items)
|
|
502
|
-
}
|
|
503
|
-
|
|
504
|
-
func paymentQueue(_ queue: SKPaymentQueue, restoreCompletedTransactionsFailedWithError error: Error) {
|
|
505
|
-
myQueue.sync(execute: { [self] in
|
|
506
|
-
rejectPromises(
|
|
507
|
-
forKey: "availableItems",
|
|
508
|
-
code: standardErrorCode((error as NSError).code),
|
|
509
|
-
message: error.localizedDescription,
|
|
510
|
-
error: error)
|
|
511
|
-
})
|
|
512
|
-
|
|
513
|
-
debugMessage("restoreCompletedTransactionsFailedWithError")
|
|
514
|
-
}
|
|
515
|
-
|
|
516
|
-
func purchaseProcess(_ transaction: SKPaymentTransaction) {
|
|
517
|
-
if pendingTransactionWithAutoFinish {
|
|
518
|
-
SKPaymentQueue.default().finishTransaction(transaction)
|
|
519
|
-
pendingTransactionWithAutoFinish = false
|
|
520
|
-
}
|
|
521
|
-
|
|
522
|
-
getPurchaseData(transaction) { [self] purchase in
|
|
523
|
-
resolvePromises(forKey: transaction.payment.productIdentifier, value: purchase)
|
|
524
|
-
|
|
525
|
-
// additionally send event
|
|
526
|
-
if hasListeners {
|
|
527
|
-
sendEvent(withName: "purchase-updated", body: purchase)
|
|
528
|
-
}
|
|
529
|
-
}
|
|
530
|
-
}
|
|
531
|
-
|
|
532
|
-
func standardErrorCode(_ code: Int?) -> String? {
|
|
533
|
-
let descriptions = [
|
|
534
|
-
"E_UNKNOWN",
|
|
535
|
-
"E_SERVICE_ERROR",
|
|
536
|
-
"E_USER_CANCELLED",
|
|
537
|
-
"E_USER_ERROR",
|
|
538
|
-
"E_USER_ERROR",
|
|
539
|
-
"E_ITEM_UNAVAILABLE",
|
|
540
|
-
"E_REMOTE_ERROR",
|
|
541
|
-
"E_NETWORK_ERROR",
|
|
542
|
-
"E_SERVICE_ERROR",
|
|
543
|
-
"E_RECEIPT_FAILED",
|
|
544
|
-
"E_RECEIPT_FINISHED_FAILED"
|
|
545
|
-
]
|
|
546
|
-
|
|
547
|
-
guard let code = code else {
|
|
548
|
-
return descriptions[0]
|
|
549
|
-
}
|
|
550
|
-
if code == 3038 { // Purchase interrupted so user can accept terms and conditions
|
|
551
|
-
return "E_INTERRUPTED"
|
|
552
|
-
}
|
|
553
|
-
|
|
554
|
-
if code > descriptions.count - 1 || code < 0 { // Fix crash app without internet connection
|
|
555
|
-
return descriptions[0]
|
|
556
|
-
}
|
|
557
|
-
|
|
558
|
-
return descriptions[code]
|
|
559
|
-
}
|
|
560
|
-
|
|
561
|
-
func getProductObject(_ product: SKProduct) -> [String: Any?] {
|
|
562
|
-
let formatter = NumberFormatter()
|
|
563
|
-
formatter.numberStyle = .currency
|
|
564
|
-
formatter.locale = product.priceLocale
|
|
565
|
-
|
|
566
|
-
let localizedPrice = formatter.string(from: product.price)
|
|
567
|
-
var introductoryPrice = localizedPrice
|
|
568
|
-
var introductoryPriceAsAmountIOS = "\(product.price)"
|
|
569
|
-
|
|
570
|
-
var introductoryPricePaymentMode = ""
|
|
571
|
-
var introductoryPriceNumberOfPeriods = ""
|
|
572
|
-
|
|
573
|
-
var introductoryPriceSubscriptionPeriod = ""
|
|
574
|
-
|
|
575
|
-
var currencyCode: String? = ""
|
|
576
|
-
var countryCode: String? = ""
|
|
577
|
-
var periodNumberIOS = "0"
|
|
578
|
-
var periodUnitIOS = ""
|
|
579
|
-
var itemType = "iap"
|
|
580
|
-
|
|
581
|
-
if #available(iOS 11.2, tvOS 11.2, *) {
|
|
582
|
-
let numOfUnits = UInt(product.subscriptionPeriod?.numberOfUnits ?? 0)
|
|
583
|
-
let unit = product.subscriptionPeriod?.unit
|
|
584
|
-
|
|
585
|
-
if unit == .year {
|
|
586
|
-
periodUnitIOS = "YEAR"
|
|
587
|
-
} else if unit == .month {
|
|
588
|
-
periodUnitIOS = "MONTH"
|
|
589
|
-
} else if unit == .week {
|
|
590
|
-
periodUnitIOS = "WEEK"
|
|
591
|
-
} else if unit == .day {
|
|
592
|
-
periodUnitIOS = "DAY"
|
|
593
|
-
}
|
|
594
|
-
|
|
595
|
-
periodNumberIOS = String(format: "%lu", numOfUnits)
|
|
596
|
-
|
|
597
|
-
if product.subscriptionPeriod != nil {
|
|
598
|
-
itemType = "subs"
|
|
599
|
-
}
|
|
600
|
-
|
|
601
|
-
// subscriptionPeriod = product.subscriptionPeriod ? [product.subscriptionPeriod stringValue] : @"";
|
|
602
|
-
// introductoryPrice = product.introductoryPrice != nil ? [NSString stringWithFormat:@"%@", product.introductoryPrice] : @"";
|
|
603
|
-
if product.introductoryPrice != nil {
|
|
604
|
-
formatter.locale = product.introductoryPrice?.priceLocale
|
|
605
|
-
|
|
606
|
-
if let price = product.introductoryPrice?.price {
|
|
607
|
-
introductoryPrice = formatter.string(from: price)
|
|
608
|
-
}
|
|
609
|
-
|
|
610
|
-
introductoryPriceAsAmountIOS = product.introductoryPrice?.price.stringValue ?? ""
|
|
611
|
-
|
|
612
|
-
switch product.introductoryPrice?.paymentMode {
|
|
613
|
-
case .freeTrial:
|
|
614
|
-
introductoryPricePaymentMode = "FREETRIAL"
|
|
615
|
-
introductoryPriceNumberOfPeriods = String( product.introductoryPrice?.subscriptionPeriod.numberOfUnits ?? 0)
|
|
616
|
-
|
|
617
|
-
case .payAsYouGo:
|
|
618
|
-
introductoryPricePaymentMode = "PAYASYOUGO"
|
|
619
|
-
introductoryPriceNumberOfPeriods = String( product.introductoryPrice?.numberOfPeriods ?? 0)
|
|
620
|
-
|
|
621
|
-
case .payUpFront:
|
|
622
|
-
introductoryPricePaymentMode = "PAYUPFRONT"
|
|
623
|
-
introductoryPriceNumberOfPeriods = String( product.introductoryPrice?.subscriptionPeriod.numberOfUnits ?? 0)
|
|
624
|
-
|
|
625
|
-
default:
|
|
626
|
-
introductoryPricePaymentMode = ""
|
|
627
|
-
introductoryPriceNumberOfPeriods = "0"
|
|
628
|
-
}
|
|
629
|
-
|
|
630
|
-
if product.introductoryPrice?.subscriptionPeriod.unit == .day {
|
|
631
|
-
introductoryPriceSubscriptionPeriod = "DAY"
|
|
632
|
-
} else if product.introductoryPrice?.subscriptionPeriod.unit == .week {
|
|
633
|
-
introductoryPriceSubscriptionPeriod = "WEEK"
|
|
634
|
-
} else if product.introductoryPrice?.subscriptionPeriod.unit == .month {
|
|
635
|
-
introductoryPriceSubscriptionPeriod = "MONTH"
|
|
636
|
-
} else if product.introductoryPrice?.subscriptionPeriod.unit == .year {
|
|
637
|
-
introductoryPriceSubscriptionPeriod = "YEAR"
|
|
638
|
-
} else {
|
|
639
|
-
introductoryPriceSubscriptionPeriod = ""
|
|
640
|
-
}
|
|
641
|
-
} else {
|
|
642
|
-
introductoryPrice = ""
|
|
643
|
-
introductoryPriceAsAmountIOS = ""
|
|
644
|
-
introductoryPricePaymentMode = ""
|
|
645
|
-
introductoryPriceNumberOfPeriods = ""
|
|
646
|
-
introductoryPriceSubscriptionPeriod = ""
|
|
647
|
-
}
|
|
648
|
-
}
|
|
649
|
-
|
|
650
|
-
if #available(iOS 10.0, tvOS 10.0, *) {
|
|
651
|
-
currencyCode = product.priceLocale.currencyCode
|
|
652
|
-
}
|
|
653
|
-
|
|
654
|
-
if #available(iOS 13.0, tvOS 13.0, *) {
|
|
655
|
-
countryCode = SKPaymentQueue.default().storefront?.countryCode
|
|
656
|
-
} else if #available(iOS 10.0, tvOS 10.0, *) {
|
|
657
|
-
countryCode = product.priceLocale.regionCode
|
|
658
|
-
}
|
|
659
|
-
|
|
660
|
-
var discounts: [[String: String?]]?
|
|
661
|
-
|
|
662
|
-
if #available(iOS 12.2, tvOS 12.2, *) {
|
|
663
|
-
discounts = getDiscountData(product)
|
|
664
|
-
}
|
|
665
|
-
|
|
666
|
-
let obj: [String: Any?] = [
|
|
667
|
-
"productId": product.productIdentifier,
|
|
668
|
-
"price": "\(product.price)",
|
|
669
|
-
"currency": currencyCode,
|
|
670
|
-
"countryCode": countryCode ?? "",
|
|
671
|
-
"type": itemType,
|
|
672
|
-
"title": product.localizedTitle != "" ? product.localizedTitle : "",
|
|
673
|
-
"description": product.localizedDescription != "" ? product.localizedDescription : "",
|
|
674
|
-
"localizedPrice": localizedPrice,
|
|
675
|
-
"subscriptionPeriodNumberIOS": periodNumberIOS,
|
|
676
|
-
"subscriptionPeriodUnitIOS": periodUnitIOS,
|
|
677
|
-
"introductoryPrice": introductoryPrice,
|
|
678
|
-
"introductoryPriceAsAmountIOS": introductoryPriceAsAmountIOS,
|
|
679
|
-
"introductoryPricePaymentModeIOS": introductoryPricePaymentMode,
|
|
680
|
-
"introductoryPriceNumberOfPeriodsIOS": introductoryPriceNumberOfPeriods,
|
|
681
|
-
"introductoryPriceSubscriptionPeriodIOS": introductoryPriceSubscriptionPeriod,
|
|
682
|
-
"discounts": discounts
|
|
683
|
-
]
|
|
684
|
-
|
|
685
|
-
return obj
|
|
686
|
-
}
|
|
687
|
-
|
|
688
|
-
func getDiscountData(_ product: SKProduct) -> [[String: String?]]? {
|
|
689
|
-
if #available(iOS 12.2, tvOS 12.2, *) {
|
|
690
|
-
var mappedDiscounts: [[String: String?]] = []
|
|
691
|
-
var localizedPrice: String?
|
|
692
|
-
var paymendMode: String?
|
|
693
|
-
var subscriptionPeriods: String?
|
|
694
|
-
var discountType: String?
|
|
695
|
-
|
|
696
|
-
for discount in product.discounts {
|
|
697
|
-
let formatter = NumberFormatter()
|
|
698
|
-
formatter.numberStyle = .currency
|
|
699
|
-
// This causes a crash on certain versions of iOS.
|
|
700
|
-
// let priceLocale: Locale? = discount.priceLocale
|
|
701
|
-
// if let priceLocale = priceLocale {
|
|
702
|
-
// formatter.locale = priceLocale
|
|
703
|
-
// }
|
|
704
|
-
localizedPrice = formatter.string(from: discount.price)
|
|
705
|
-
var numberOfPeriods: String?
|
|
706
|
-
|
|
707
|
-
switch discount.paymentMode {
|
|
708
|
-
case .freeTrial:
|
|
709
|
-
paymendMode = "FREETRIAL"
|
|
710
|
-
numberOfPeriods = String(discount.subscriptionPeriod.numberOfUnits)
|
|
711
|
-
|
|
712
|
-
case .payAsYouGo:
|
|
713
|
-
paymendMode = "PAYASYOUGO"
|
|
714
|
-
numberOfPeriods = String(discount.numberOfPeriods)
|
|
715
|
-
|
|
716
|
-
case .payUpFront:
|
|
717
|
-
paymendMode = "PAYUPFRONT"
|
|
718
|
-
numberOfPeriods = String(discount.subscriptionPeriod.numberOfUnits )
|
|
719
|
-
|
|
720
|
-
default:
|
|
721
|
-
paymendMode = ""
|
|
722
|
-
numberOfPeriods = "0"
|
|
723
|
-
}
|
|
724
|
-
|
|
725
|
-
switch discount.subscriptionPeriod.unit {
|
|
726
|
-
case .day:
|
|
727
|
-
subscriptionPeriods = "DAY"
|
|
728
|
-
|
|
729
|
-
case .week:
|
|
730
|
-
subscriptionPeriods = "WEEK"
|
|
731
|
-
|
|
732
|
-
case .month:
|
|
733
|
-
subscriptionPeriods = "MONTH"
|
|
734
|
-
|
|
735
|
-
case .year:
|
|
736
|
-
subscriptionPeriods = "YEAR"
|
|
737
|
-
|
|
738
|
-
default:
|
|
739
|
-
subscriptionPeriods = ""
|
|
740
|
-
}
|
|
741
|
-
|
|
742
|
-
let discountIdentifier = discount.identifier
|
|
743
|
-
switch discount.type {
|
|
744
|
-
case SKProductDiscount.Type.introductory:
|
|
745
|
-
discountType = "INTRODUCTORY"
|
|
746
|
-
|
|
747
|
-
case SKProductDiscount.Type.subscription:
|
|
748
|
-
discountType = "SUBSCRIPTION"
|
|
749
|
-
|
|
750
|
-
default:
|
|
751
|
-
discountType = ""
|
|
752
|
-
}
|
|
753
|
-
|
|
754
|
-
let discountObj = [
|
|
755
|
-
"identifier": discountIdentifier,
|
|
756
|
-
"type": discountType,
|
|
757
|
-
"numberOfPeriods": numberOfPeriods,
|
|
758
|
-
"price": "\(discount.price)",
|
|
759
|
-
"localizedPrice": localizedPrice,
|
|
760
|
-
"paymentMode": paymendMode,
|
|
761
|
-
"subscriptionPeriod": subscriptionPeriods
|
|
762
|
-
]
|
|
763
|
-
|
|
764
|
-
mappedDiscounts.append(discountObj)
|
|
765
|
-
}
|
|
766
|
-
|
|
767
|
-
return mappedDiscounts
|
|
768
|
-
}
|
|
769
|
-
|
|
770
|
-
return nil
|
|
771
|
-
}
|
|
772
|
-
|
|
773
|
-
func getPurchaseData(_ transaction: SKPaymentTransaction, withBlock block: @escaping (_ transactionDict: [String: Any?]?) -> Void) {
|
|
774
|
-
requestReceiptData(withBlock: false) { receiptData, _ in
|
|
775
|
-
if receiptData == nil {
|
|
776
|
-
block(nil)
|
|
777
|
-
} else {
|
|
778
|
-
var purchase: [String: Any?] = [
|
|
779
|
-
"transactionDate": transaction.transactionDate?.millisecondsSince1970,
|
|
780
|
-
"transactionId": transaction.transactionIdentifier,
|
|
781
|
-
"productId": transaction.payment.productIdentifier,
|
|
782
|
-
"transactionReceipt": receiptData?.base64EncodedString(options: [.endLineWithCarriageReturn])
|
|
783
|
-
]
|
|
784
|
-
|
|
785
|
-
// originalTransaction is available for restore purchase and purchase of cancelled/expired subscriptions
|
|
786
|
-
if let originalTransaction = transaction.original {
|
|
787
|
-
purchase["originalTransactionDateIOS"] = originalTransaction.transactionDate?.millisecondsSince1970
|
|
788
|
-
purchase["originalTransactionIdentifierIOS"] = originalTransaction.transactionIdentifier
|
|
789
|
-
}
|
|
790
|
-
|
|
791
|
-
block(purchase)
|
|
792
|
-
}
|
|
793
|
-
}
|
|
794
|
-
}
|
|
795
|
-
|
|
796
|
-
/** forcheRefresh should only set to true when coming from a direct user action. i.e. requestReceipt react method. See doc on that method for details*/
|
|
797
|
-
func requestReceiptData(withBlock forceRefresh: Bool, withBlock block: @escaping (_ data: Data?, _ error: Error?) -> Void) {
|
|
798
|
-
debugMessage("requestReceiptDataWithBlock with force refresh: \(forceRefresh ? "YES" : "NO")")
|
|
799
|
-
|
|
800
|
-
if forceRefresh {
|
|
801
|
-
let refreshRequest = SKReceiptRefreshRequest()
|
|
802
|
-
refreshRequest.delegate = self
|
|
803
|
-
refreshRequest.start()
|
|
804
|
-
receiptBlock = block
|
|
805
|
-
} else {
|
|
806
|
-
receiptBlock = nil
|
|
807
|
-
block(receiptData(), nil)
|
|
808
|
-
}
|
|
809
|
-
}
|
|
810
|
-
|
|
811
|
-
func isReceiptPresent() -> Bool {
|
|
812
|
-
let receiptURL = Bundle.main.appStoreReceiptURL
|
|
813
|
-
var canReachError: Error?
|
|
814
|
-
|
|
815
|
-
do {
|
|
816
|
-
try _ = receiptURL?.checkResourceIsReachable()
|
|
817
|
-
} catch let error {
|
|
818
|
-
canReachError = error
|
|
819
|
-
}
|
|
820
|
-
|
|
821
|
-
return canReachError == nil
|
|
822
|
-
}
|
|
823
|
-
|
|
824
|
-
func receiptData() -> Data? {
|
|
825
|
-
let receiptURL = Bundle.main.appStoreReceiptURL
|
|
826
|
-
var receiptData: Data?
|
|
827
|
-
|
|
828
|
-
if let receiptURL = receiptURL {
|
|
829
|
-
do {
|
|
830
|
-
try receiptData = Data(contentsOf: receiptURL, options: .alwaysMapped)
|
|
831
|
-
} catch _ {
|
|
832
|
-
}
|
|
833
|
-
}
|
|
834
|
-
|
|
835
|
-
return receiptData
|
|
836
|
-
}
|
|
837
|
-
|
|
838
|
-
func requestDidFinish(_ request: SKRequest) {
|
|
839
|
-
if request is SKReceiptRefreshRequest {
|
|
840
|
-
if let receiptBlock = self.receiptBlock {
|
|
841
|
-
if isReceiptPresent() {
|
|
842
|
-
debugMessage("Receipt refreshed success")
|
|
843
|
-
receiptBlock(receiptData(), nil)
|
|
844
|
-
} else {
|
|
845
|
-
debugMessage("Finished but receipt refreshed failed")
|
|
846
|
-
let error = NSError(domain: "Receipt request finished but it failed!", code: 10, userInfo: nil)
|
|
847
|
-
receiptBlock(nil, error)
|
|
848
|
-
}
|
|
849
|
-
self.receiptBlock = nil
|
|
850
|
-
} else {
|
|
851
|
-
debugMessage("Receipt refresh request with null receiptBlock ")
|
|
852
|
-
}
|
|
853
|
-
}
|
|
854
|
-
}
|
|
855
|
-
|
|
856
|
-
func paymentQueue(_ queue: SKPaymentQueue, removedTransactions transactions: [SKPaymentTransaction]) {
|
|
857
|
-
debugMessage("removedTransactions - countPendingTransactions \(countPendingTransaction)")
|
|
858
|
-
|
|
859
|
-
if countPendingTransaction > 0 {
|
|
860
|
-
countPendingTransaction -= transactions.count
|
|
861
|
-
|
|
862
|
-
if countPendingTransaction <= 0 {
|
|
863
|
-
resolvePromises(forKey: "cleaningTransactions", value: nil)
|
|
864
|
-
countPendingTransaction = 0
|
|
865
|
-
}
|
|
866
|
-
}
|
|
867
|
-
}
|
|
868
|
-
}
|