@juspay-tech/react-native-hyperswitch 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/HyperswitchSdkReactNative.podspec +31 -0
- package/android/build.gradle +119 -0
- package/android/gradle.properties +5 -0
- package/android/hyperswitch_autolinking.gradle +378 -0
- package/android/proguard-rules.pro +72 -0
- package/android/src/main/AndroidManifest.xml +25 -0
- package/android/src/main/assets/hyperswitch.bundle +1677 -0
- package/android/src/main/java/com/hyperswitchsdkreactnative/HyperswitchSdkReactNativePackage.kt +36 -0
- package/android/src/main/java/com/hyperswitchsdkreactnative/activity/RedirectActivity.kt +39 -0
- package/android/src/main/java/com/hyperswitchsdkreactnative/internal/DefaultReactHost.kt +314 -0
- package/android/src/main/java/com/hyperswitchsdkreactnative/internal/DefaultReactNativeHost.kt +131 -0
- package/android/src/main/java/com/hyperswitchsdkreactnative/internal/ReactDelegate.kt +423 -0
- package/android/src/main/java/com/hyperswitchsdkreactnative/internal/ReactFragment.kt +335 -0
- package/android/src/main/java/com/hyperswitchsdkreactnative/modules/HyperswitchSdkNativeModule.kt +143 -0
- package/android/src/main/java/com/hyperswitchsdkreactnative/modules/HyperswitchSdkReactNativeModule.kt +92 -0
- package/android/src/main/java/com/hyperswitchsdkreactnative/provider/HyperProvider.kt +269 -0
- package/android/src/main/java/com/hyperswitchsdkreactnative/views/GooglePayButtonView.kt +60 -0
- package/android/src/main/java/com/hyperswitchsdkreactnative/views/GooglePayButtonViewManager.kt +76 -0
- package/android/src/main/java/io/hyperswitch/hyperota/HyperOtaLogger.kt +122 -0
- package/android/src/main/java/io/hyperswitch/logs/CrashHandler.kt +29 -0
- package/android/src/main/java/io/hyperswitch/logs/Debouncer.kt +20 -0
- package/android/src/main/java/io/hyperswitch/logs/HyperLogManager.kt +113 -0
- package/android/src/main/java/io/hyperswitch/logs/LogData.kt +159 -0
- package/android/src/main/java/io/hyperswitch/logs/LogFileManager.kt +60 -0
- package/android/src/main/java/io/hyperswitch/networking/HyperNetworking.kt +73 -0
- package/android/src/main/java/io/hyperswitch/react/Utils.kt +23 -0
- package/android/src/main/res/values/attrs.xml +6 -0
- package/android/src/main/res/values/strings.xml +5 -0
- package/android/src/main/res/values/theme.xml +16 -0
- package/ios/Modules/HyperswitchModule.swift +61 -0
- package/ios/Modules/HyperswitchNativeModule.swift +113 -0
- package/ios/Modules/HyperswitchSdkNative.h +5 -0
- package/ios/Modules/HyperswitchSdkNative.mm +98 -0
- package/ios/Modules/HyperswitchSdkReactNative.h +5 -0
- package/ios/Modules/HyperswitchSdkReactNative.mm +53 -0
- package/ios/Views/ApplePayView.h +14 -0
- package/ios/Views/ApplePayView.mm +89 -0
- package/ios/hyperswitchSDK/Core/ApplePay/ApplePayHandler.swift +249 -0
- package/ios/hyperswitchSDK/Core/ApplePay/ApplePayViewManager.m +18 -0
- package/ios/hyperswitchSDK/Core/ApplePay/ApplePayViewManager.swift +123 -0
- package/ios/hyperswitchSDK/Core/HyperPaymentSheet/PaymentSheetView+SwiftUI.swift +49 -0
- package/ios/hyperswitchSDK/Core/HyperPaymentSheet/PaymentSheetView+UIKit.swift +49 -0
- package/ios/hyperswitchSDK/Core/HyperPaymentSheet/PaymentSheetView.swift +80 -0
- package/ios/hyperswitchSDK/Core/HyperSession/PaymentSession+UIKit.swift +176 -0
- package/ios/hyperswitchSDK/Core/HyperSession/PaymentSessionTypes.swift +121 -0
- package/ios/hyperswitchSDK/Core/Models/LogPayload.swift +53 -0
- package/ios/hyperswitchSDK/Core/NativeLogger/Debouncer.swift +37 -0
- package/ios/hyperswitchSDK/Core/NativeLogger/LogBuilder.swift +91 -0
- package/ios/hyperswitchSDK/Core/NativeLogger/LogFileManager.swift +75 -0
- package/ios/hyperswitchSDK/Core/NativeLogger/LogManager.swift +113 -0
- package/ios/hyperswitchSDK/Core/NativeModule/HyperHeadless.m +16 -0
- package/ios/hyperswitchSDK/Core/NativeModule/HyperHeadless.swift +74 -0
- package/ios/hyperswitchSDK/Core/NativeModule/HyperModule.m +28 -0
- package/ios/hyperswitchSDK/Core/NativeModule/HyperModule.swift +168 -0
- package/ios/hyperswitchSDK/Core/NativeModule/OTAServices.swift +113 -0
- package/ios/hyperswitchSDK/Core/NativeModule/RNHeadlessManager.swift +45 -0
- package/ios/hyperswitchSDK/Core/NativeModule/RNResponseHandler.swift +12 -0
- package/ios/hyperswitchSDK/Core/NativeModule/RNViewManager.swift +90 -0
- package/ios/hyperswitchSDK/Core/NativeModule/hyper-Bridging-Header.h +9 -0
- package/ios/hyperswitchSDK/Core/Resources/HyperOTA.plist +20 -0
- package/ios/hyperswitchSDK/Core/Resources/hyperswitch.bundle +1673 -0
- package/ios/hyperswitchSDK/Shared/APIClient.swift +21 -0
- package/ios/hyperswitchSDK/Shared/DictionaryConverter.swift +104 -0
- package/ios/hyperswitchSDK/Shared/Environment.swift +24 -0
- package/ios/hyperswitchSDK/Shared/Extensions.swift +31 -0
- package/ios/hyperswitchSDK/Shared/Helper.swift +16 -0
- package/ios/hyperswitchSDK/Shared/HyperNetworking.swift +137 -0
- package/ios/hyperswitchSDK/Shared/HyperParams.swift +44 -0
- package/ios/hyperswitchSDK/Shared/HyperUIViewController.swift +25 -0
- package/ios/hyperswitchSDK/Shared/PaymentSession.swift +43 -0
- package/ios/hyperswitchSDK/Shared/PaymentSheet.swift +30 -0
- package/ios/hyperswitchSDK/Shared/PaymentSheetAppearance.swift +264 -0
- package/ios/hyperswitchSDK/Shared/PaymentSheetConfiguration.swift +494 -0
- package/ios/hyperswitchSDK/Shared/SwiftUIManager.swift +28 -0
- package/ios/hyperswitchSDK/Shared/Version.swift +12 -0
- package/lib/bs/JuspayTechReactNativeHyperswitch.cmi +0 -0
- package/lib/bs/JuspayTechReactNativeHyperswitch.cmj +0 -0
- package/lib/bs/JuspayTechReactNativeHyperswitch.cmt +0 -0
- package/lib/bs/JuspayTechReactNativeHyperswitch.mlmap +5 -0
- package/lib/bs/build.ninja +29 -0
- package/lib/bs/install.ninja +25 -0
- package/lib/bs/src/context/HyperProvider-JuspayTechReactNativeHyperswitch.cmi +0 -0
- package/lib/bs/src/context/HyperProvider-JuspayTechReactNativeHyperswitch.cmj +0 -0
- package/lib/bs/src/context/HyperProvider-JuspayTechReactNativeHyperswitch.cmt +0 -0
- package/lib/bs/src/context/HyperProvider.ast +0 -0
- package/lib/bs/src/context/HyperProvider.d +1 -0
- package/lib/bs/src/hooks/useHyper-JuspayTechReactNativeHyperswitch.cmi +0 -0
- package/lib/bs/src/hooks/useHyper-JuspayTechReactNativeHyperswitch.cmj +0 -0
- package/lib/bs/src/hooks/useHyper-JuspayTechReactNativeHyperswitch.cmt +0 -0
- package/lib/bs/src/hooks/useHyper.ast +0 -0
- package/lib/bs/src/hooks/useHyper.d +1 -0
- package/lib/bs/src/modules/NativeHyperswitchSdk-JuspayTechReactNativeHyperswitch.cmi +0 -0
- package/lib/bs/src/modules/NativeHyperswitchSdk-JuspayTechReactNativeHyperswitch.cmj +0 -0
- package/lib/bs/src/modules/NativeHyperswitchSdk-JuspayTechReactNativeHyperswitch.cmt +0 -0
- package/lib/bs/src/modules/NativeHyperswitchSdk.ast +0 -0
- package/lib/bs/src/modules/NativeHyperswitchSdk.d +1 -0
- package/lib/bs/src/types/PaymentSheetConfiguration-JuspayTechReactNativeHyperswitch.cmi +0 -0
- package/lib/bs/src/types/PaymentSheetConfiguration-JuspayTechReactNativeHyperswitch.cmj +0 -0
- package/lib/bs/src/types/PaymentSheetConfiguration-JuspayTechReactNativeHyperswitch.cmt +0 -0
- package/lib/bs/src/types/PaymentSheetConfiguration.ast +0 -0
- package/lib/bs/src/types/PaymentSheetConfiguration.d +1 -0
- package/lib/commonjs/context/HyperProvider.gen.js +16 -0
- package/lib/commonjs/context/HyperProvider.gen.js.map +1 -0
- package/lib/commonjs/context/HyperProvider.res +78 -0
- package/lib/commonjs/context/HyperProvider.res.js +98 -0
- package/lib/commonjs/context/HyperProvider.res.js.map +1 -0
- package/lib/commonjs/hooks/useHyper.gen.js +15 -0
- package/lib/commonjs/hooks/useHyper.gen.js.map +1 -0
- package/lib/commonjs/hooks/useHyper.res +142 -0
- package/lib/commonjs/hooks/useHyper.res.js +152 -0
- package/lib/commonjs/hooks/useHyper.res.js.map +1 -0
- package/lib/commonjs/index.js +26 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/modules/NativeHyperswitchSdk.gen.js +6 -0
- package/lib/commonjs/modules/NativeHyperswitchSdk.gen.js.map +1 -0
- package/lib/commonjs/modules/NativeHyperswitchSdk.res +55 -0
- package/lib/commonjs/modules/NativeHyperswitchSdk.res.js +14 -0
- package/lib/commonjs/modules/NativeHyperswitchSdk.res.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/shims/Js.shim.js +2 -0
- package/lib/commonjs/shims/Js.shim.js.map +1 -0
- package/lib/commonjs/specs/ApplePayButtonNativeComponent.ts +11 -0
- package/lib/commonjs/specs/GooglePayButtonNativeComponent.android.js +10 -0
- package/lib/commonjs/specs/GooglePayButtonNativeComponent.android.js.map +1 -0
- package/lib/commonjs/specs/HyperswitchSdkReactNativeViewNativeComponent.ts +10 -0
- package/lib/commonjs/specs/NativeHyperswitchSdkNative.js +9 -0
- package/lib/commonjs/specs/NativeHyperswitchSdkNative.js.map +1 -0
- package/lib/commonjs/specs/NativeHyperswitchSdkReactNative.js +9 -0
- package/lib/commonjs/specs/NativeHyperswitchSdkReactNative.js.map +1 -0
- package/lib/commonjs/types/PaymentSheetConfiguration.gen.js +2 -0
- package/lib/commonjs/types/PaymentSheetConfiguration.gen.js.map +1 -0
- package/lib/commonjs/types/PaymentSheetConfiguration.res +215 -0
- package/lib/commonjs/types/PaymentSheetConfiguration.res.js +4 -0
- package/lib/commonjs/types/PaymentSheetConfiguration.res.js.map +1 -0
- package/lib/module/context/HyperProvider.gen.js +11 -0
- package/lib/module/context/HyperProvider.gen.js.map +1 -0
- package/lib/module/context/HyperProvider.res +78 -0
- package/lib/module/context/HyperProvider.res.js +91 -0
- package/lib/module/context/HyperProvider.res.js.map +1 -0
- package/lib/module/hooks/useHyper.gen.js +10 -0
- package/lib/module/hooks/useHyper.gen.js.map +1 -0
- package/lib/module/hooks/useHyper.res +142 -0
- package/lib/module/hooks/useHyper.res.js +142 -0
- package/lib/module/hooks/useHyper.res.js.map +1 -0
- package/lib/module/index.js +5 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/modules/NativeHyperswitchSdk.gen.js +4 -0
- package/lib/module/modules/NativeHyperswitchSdk.gen.js.map +1 -0
- package/lib/module/modules/NativeHyperswitchSdk.res +55 -0
- package/lib/module/modules/NativeHyperswitchSdk.res.js +9 -0
- package/lib/module/modules/NativeHyperswitchSdk.res.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/shims/Js.shim.js +2 -0
- package/lib/module/shims/Js.shim.js.map +1 -0
- package/lib/module/specs/ApplePayButtonNativeComponent.ts +11 -0
- package/lib/module/specs/GooglePayButtonNativeComponent.android.js +5 -0
- package/lib/module/specs/GooglePayButtonNativeComponent.android.js.map +1 -0
- package/lib/module/specs/HyperswitchSdkReactNativeViewNativeComponent.ts +10 -0
- package/lib/module/specs/NativeHyperswitchSdkNative.js +5 -0
- package/lib/module/specs/NativeHyperswitchSdkNative.js.map +1 -0
- package/lib/module/specs/NativeHyperswitchSdkReactNative.js +5 -0
- package/lib/module/specs/NativeHyperswitchSdkReactNative.js.map +1 -0
- package/lib/module/types/PaymentSheetConfiguration.gen.js +2 -0
- package/lib/module/types/PaymentSheetConfiguration.gen.js.map +1 -0
- package/lib/module/types/PaymentSheetConfiguration.res +215 -0
- package/lib/module/types/PaymentSheetConfiguration.res.js +4 -0
- package/lib/module/types/PaymentSheetConfiguration.res.js.map +1 -0
- package/lib/typescript/commonjs/babel.config.d.ts +10 -0
- package/lib/typescript/commonjs/babel.config.d.ts.map +1 -0
- package/lib/typescript/commonjs/eslint.config.d.mts +3 -0
- package/lib/typescript/commonjs/eslint.config.d.mts.map +1 -0
- package/lib/typescript/commonjs/package.json +1 -0
- package/lib/typescript/commonjs/scripts/bootstrap.d.ts +2 -0
- package/lib/typescript/commonjs/scripts/bootstrap.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/context/HyperProvider.gen.d.ts +17 -0
- package/lib/typescript/commonjs/src/context/HyperProvider.gen.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/context/HyperProvider.res.d.ts +20 -0
- package/lib/typescript/commonjs/src/context/HyperProvider.res.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/hooks/useHyper.gen.d.ts +10 -0
- package/lib/typescript/commonjs/src/hooks/useHyper.gen.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/hooks/useHyper.res.d.ts +95 -0
- package/lib/typescript/commonjs/src/hooks/useHyper.res.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/index.d.ts +4 -0
- package/lib/typescript/commonjs/src/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/modules/NativeHyperswitchSdk.gen.d.ts +24 -0
- package/lib/typescript/commonjs/src/modules/NativeHyperswitchSdk.gen.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/modules/NativeHyperswitchSdk.res.d.ts +2 -0
- package/lib/typescript/commonjs/src/modules/NativeHyperswitchSdk.res.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/shims/Js.shim.d.ts +4 -0
- package/lib/typescript/commonjs/src/shims/Js.shim.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/specs/ApplePayButtonNativeComponent.d.ts +10 -0
- package/lib/typescript/commonjs/src/specs/ApplePayButtonNativeComponent.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/specs/GooglePayButtonNativeComponent.android.d.ts +11 -0
- package/lib/typescript/commonjs/src/specs/GooglePayButtonNativeComponent.android.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/specs/HyperswitchSdkReactNativeViewNativeComponent.d.ts +1 -0
- package/lib/typescript/commonjs/src/specs/HyperswitchSdkReactNativeViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/specs/NativeHyperswitchSdkNative.d.ts +17 -0
- package/lib/typescript/commonjs/src/specs/NativeHyperswitchSdkNative.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/specs/NativeHyperswitchSdkReactNative.d.ts +9 -0
- package/lib/typescript/commonjs/src/specs/NativeHyperswitchSdkReactNative.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/types/PaymentSheetConfiguration.gen.d.ts +149 -0
- package/lib/typescript/commonjs/src/types/PaymentSheetConfiguration.gen.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/types/PaymentSheetConfiguration.res.d.ts +1 -0
- package/lib/typescript/commonjs/src/types/PaymentSheetConfiguration.res.d.ts.map +1 -0
- package/lib/typescript/module/babel.config.d.ts +10 -0
- package/lib/typescript/module/babel.config.d.ts.map +1 -0
- package/lib/typescript/module/eslint.config.d.mts +3 -0
- package/lib/typescript/module/eslint.config.d.mts.map +1 -0
- package/lib/typescript/module/package.json +1 -0
- package/lib/typescript/module/scripts/bootstrap.d.ts +2 -0
- package/lib/typescript/module/scripts/bootstrap.d.ts.map +1 -0
- package/lib/typescript/module/src/context/HyperProvider.gen.d.ts +17 -0
- package/lib/typescript/module/src/context/HyperProvider.gen.d.ts.map +1 -0
- package/lib/typescript/module/src/context/HyperProvider.res.d.ts +20 -0
- package/lib/typescript/module/src/context/HyperProvider.res.d.ts.map +1 -0
- package/lib/typescript/module/src/hooks/useHyper.gen.d.ts +10 -0
- package/lib/typescript/module/src/hooks/useHyper.gen.d.ts.map +1 -0
- package/lib/typescript/module/src/hooks/useHyper.res.d.ts +95 -0
- package/lib/typescript/module/src/hooks/useHyper.res.d.ts.map +1 -0
- package/lib/typescript/module/src/index.d.ts +4 -0
- package/lib/typescript/module/src/index.d.ts.map +1 -0
- package/lib/typescript/module/src/modules/NativeHyperswitchSdk.gen.d.ts +24 -0
- package/lib/typescript/module/src/modules/NativeHyperswitchSdk.gen.d.ts.map +1 -0
- package/lib/typescript/module/src/modules/NativeHyperswitchSdk.res.d.ts +2 -0
- package/lib/typescript/module/src/modules/NativeHyperswitchSdk.res.d.ts.map +1 -0
- package/lib/typescript/module/src/shims/Js.shim.d.ts +4 -0
- package/lib/typescript/module/src/shims/Js.shim.d.ts.map +1 -0
- package/lib/typescript/module/src/specs/ApplePayButtonNativeComponent.d.ts +10 -0
- package/lib/typescript/module/src/specs/ApplePayButtonNativeComponent.d.ts.map +1 -0
- package/lib/typescript/module/src/specs/GooglePayButtonNativeComponent.android.d.ts +11 -0
- package/lib/typescript/module/src/specs/GooglePayButtonNativeComponent.android.d.ts.map +1 -0
- package/lib/typescript/module/src/specs/HyperswitchSdkReactNativeViewNativeComponent.d.ts +1 -0
- package/lib/typescript/module/src/specs/HyperswitchSdkReactNativeViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/module/src/specs/NativeHyperswitchSdkNative.d.ts +17 -0
- package/lib/typescript/module/src/specs/NativeHyperswitchSdkNative.d.ts.map +1 -0
- package/lib/typescript/module/src/specs/NativeHyperswitchSdkReactNative.d.ts +9 -0
- package/lib/typescript/module/src/specs/NativeHyperswitchSdkReactNative.d.ts.map +1 -0
- package/lib/typescript/module/src/types/PaymentSheetConfiguration.gen.d.ts +149 -0
- package/lib/typescript/module/src/types/PaymentSheetConfiguration.gen.d.ts.map +1 -0
- package/lib/typescript/module/src/types/PaymentSheetConfiguration.res.d.ts +1 -0
- package/lib/typescript/module/src/types/PaymentSheetConfiguration.res.d.ts.map +1 -0
- package/package.json +196 -0
- package/src/context/HyperProvider.gen.tsx +26 -0
- package/src/context/HyperProvider.res +78 -0
- package/src/context/HyperProvider.res.js +112 -0
- package/src/hooks/useHyper.gen.tsx +18 -0
- package/src/hooks/useHyper.res +142 -0
- package/src/hooks/useHyper.res.js +157 -0
- package/src/index.tsx +13 -0
- package/src/modules/NativeHyperswitchSdk.gen.tsx +25 -0
- package/src/modules/NativeHyperswitchSdk.res +55 -0
- package/src/modules/NativeHyperswitchSdk.res.js +10 -0
- package/src/shims/Js.shim.ts +5 -0
- package/src/specs/ApplePayButtonNativeComponent.ts +11 -0
- package/src/specs/GooglePayButtonNativeComponent.android.ts +12 -0
- package/src/specs/HyperswitchSdkReactNativeViewNativeComponent.ts +10 -0
- package/src/specs/NativeHyperswitchSdkNative.ts +33 -0
- package/src/specs/NativeHyperswitchSdkReactNative.ts +17 -0
- package/src/types/PaymentSheetConfiguration.gen.tsx +202 -0
- package/src/types/PaymentSheetConfiguration.res +215 -0
- package/src/types/PaymentSheetConfiguration.res.js +2 -0
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
package com.hyperswitchsdkreactnative.provider
|
|
2
|
+
|
|
3
|
+
import android.app.Activity
|
|
4
|
+
import android.content.Context
|
|
5
|
+
import android.os.Build
|
|
6
|
+
import android.os.Bundle
|
|
7
|
+
import android.view.View
|
|
8
|
+
import android.webkit.WebSettings
|
|
9
|
+
import android.view.WindowInsets
|
|
10
|
+
import androidx.annotation.RequiresApi
|
|
11
|
+
import androidx.fragment.app.Fragment
|
|
12
|
+
import androidx.fragment.app.FragmentActivity
|
|
13
|
+
import androidx.fragment.app.FragmentManager
|
|
14
|
+
import androidx.fragment.app.FragmentTransaction
|
|
15
|
+
import com.facebook.react.bridge.ReadableMap
|
|
16
|
+
import com.facebook.react.bridge.ReadableType
|
|
17
|
+
import com.facebook.react.bridge.ReadableArray
|
|
18
|
+
import com.hyperswitchsdkreactnative.BuildConfig
|
|
19
|
+
import com.hyperswitchsdkreactnative.internal.ReactFragment
|
|
20
|
+
import org.json.JSONObject
|
|
21
|
+
import org.json.JSONArray
|
|
22
|
+
|
|
23
|
+
internal class HyperProvider internal constructor(private val activity: Activity) {
|
|
24
|
+
|
|
25
|
+
private var customBackendUrl: String? = null
|
|
26
|
+
private var customLogUrl: String? = null
|
|
27
|
+
private var customParams: ReadableMap? = null
|
|
28
|
+
private var clientSecret: String? = null
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
fun initialise(
|
|
32
|
+
publishableKey: String?,
|
|
33
|
+
customBackendUrl: String?,
|
|
34
|
+
customLogUrl: String?,
|
|
35
|
+
customParams: ReadableMap?
|
|
36
|
+
) {
|
|
37
|
+
Companion.publishableKey = publishableKey
|
|
38
|
+
this.customBackendUrl = customBackendUrl
|
|
39
|
+
this.customLogUrl = customLogUrl
|
|
40
|
+
this.customParams = customParams
|
|
41
|
+
try {
|
|
42
|
+
ReactFragment.initOTAServices(context = activity)
|
|
43
|
+
} catch (_: Exception) {
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
fun initPaymentSession(clientSecret: String) {
|
|
48
|
+
this.clientSecret = clientSecret
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
fun presentPaymentSheet(readableMap: ReadableMap) {
|
|
53
|
+
val activity = activity as? FragmentActivity
|
|
54
|
+
removeSheetView(true) // remove any existing payment sheet
|
|
55
|
+
activity?.let {
|
|
56
|
+
val propsBundle = Bundle().apply {
|
|
57
|
+
putString("type", "payment")
|
|
58
|
+
putString("from", "rn")
|
|
59
|
+
putString("publishableKey", publishableKey ?: "")
|
|
60
|
+
putString("clientSecret", clientSecret ?: "")
|
|
61
|
+
putBundle("configuration", readableMapToBundle(readableMap))
|
|
62
|
+
putBundle("hyperParams", getHyperParams(activity, readableMapToBundle(readableMap)))
|
|
63
|
+
customBackendUrl?.let { url -> putString("customBackendUrl", url) }
|
|
64
|
+
customLogUrl?.let { url -> putString("customLogUrl", url) }
|
|
65
|
+
customParams?.let { params ->
|
|
66
|
+
putString(
|
|
67
|
+
"customParams", readableMapToJSON(params).toString()
|
|
68
|
+
)
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
val bundle = Bundle().apply {
|
|
73
|
+
putBundle("props", propsBundle)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
reactFragment =
|
|
77
|
+
ReactFragment.Builder().setComponentName("hyperSwitch").setLaunchOptions(bundle).build()
|
|
78
|
+
|
|
79
|
+
val fragmentManager: FragmentManager = it.supportFragmentManager
|
|
80
|
+
val fragmentTransaction: FragmentTransaction = fragmentManager.beginTransaction()
|
|
81
|
+
fragmentTransaction.add(android.R.id.content, reactFragment!!, "HyperPaymentSheet")
|
|
82
|
+
fragmentTransaction.addToBackStack("HyperPaymentSheet")
|
|
83
|
+
fragmentTransaction.commit()
|
|
84
|
+
} ?: run {
|
|
85
|
+
// callback(PaymentResult(status = "failed", message = "Activity is not a FragmentActivity"))
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
fun removeSheetView(reset: Boolean) {
|
|
90
|
+
val activity = activity as? FragmentActivity
|
|
91
|
+
activity?.let {
|
|
92
|
+
try {
|
|
93
|
+
if (reactFragment != null) {
|
|
94
|
+
it.supportFragmentManager.beginTransaction().remove(reactFragment!!).commitAllowingStateLoss()
|
|
95
|
+
}
|
|
96
|
+
if (reset) {
|
|
97
|
+
reactFragment = null
|
|
98
|
+
}
|
|
99
|
+
} catch (_: Exception) {
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
companion object {
|
|
105
|
+
@JvmStatic
|
|
106
|
+
var reactFragment: Fragment? = null
|
|
107
|
+
|
|
108
|
+
@JvmStatic
|
|
109
|
+
private var publishableKey: String? = null
|
|
110
|
+
|
|
111
|
+
fun publishableKey(): String {
|
|
112
|
+
return publishableKey ?: ""
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
fun readableMapToJSON(readableMap: ReadableMap?): JSONObject {
|
|
116
|
+
val json = JSONObject()
|
|
117
|
+
if (readableMap == null) return json
|
|
118
|
+
|
|
119
|
+
val iterator = readableMap.keySetIterator()
|
|
120
|
+
while (iterator.hasNextKey()) {
|
|
121
|
+
val key = iterator.nextKey()
|
|
122
|
+
val type = readableMap.getType(key)
|
|
123
|
+
|
|
124
|
+
when (type) {
|
|
125
|
+
ReadableType.Null -> json.put(key, JSONObject.NULL)
|
|
126
|
+
ReadableType.Boolean -> json.put(key, readableMap.getBoolean(key))
|
|
127
|
+
ReadableType.Number -> json.put(key, readableMap.getDouble(key))
|
|
128
|
+
ReadableType.String -> json.put(key, readableMap.getString(key))
|
|
129
|
+
ReadableType.Map -> json.put(key, readableMapToJSON(readableMap.getMap(key)))
|
|
130
|
+
ReadableType.Array -> json.put(key, readableArrayToJSON(readableMap.getArray(key)))
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return json
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
fun readableArrayToJSON(readableArray: ReadableArray?): JSONArray {
|
|
137
|
+
val json = JSONArray()
|
|
138
|
+
if (readableArray == null) return json
|
|
139
|
+
|
|
140
|
+
for (i in 0 until readableArray.size()) {
|
|
141
|
+
val type = readableArray.getType(i)
|
|
142
|
+
when (type) {
|
|
143
|
+
ReadableType.Null -> json.put(JSONObject.NULL)
|
|
144
|
+
ReadableType.Boolean -> json.put(readableArray.getBoolean(i))
|
|
145
|
+
ReadableType.Number -> json.put(readableArray.getDouble(i))
|
|
146
|
+
ReadableType.String -> json.put(readableArray.getString(i))
|
|
147
|
+
ReadableType.Map -> json.put(readableMapToJSON(readableArray.getMap(i)))
|
|
148
|
+
ReadableType.Array -> json.put(readableArrayToJSON(readableArray.getArray(i)))
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return json
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
fun getUserAgent(context: Context): String {
|
|
155
|
+
return try {
|
|
156
|
+
WebSettings.getDefaultUserAgent(context)
|
|
157
|
+
} catch (e: RuntimeException) {
|
|
158
|
+
System.getProperty("http.agent") ?: ""
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
fun getCurrentTime(): Double {
|
|
163
|
+
return System.currentTimeMillis().toDouble()
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
@RequiresApi(Build.VERSION_CODES.R)
|
|
167
|
+
private fun getRootWindowInsetsCompatR(rootView: View): EdgeInsets? {
|
|
168
|
+
val insets = rootView.rootWindowInsets?.getInsets(
|
|
169
|
+
WindowInsets.Type.statusBars() or WindowInsets.Type.displayCutout() or WindowInsets.Type.navigationBars() or WindowInsets.Type.captionBar()
|
|
170
|
+
) ?: return null
|
|
171
|
+
return EdgeInsets(
|
|
172
|
+
top = insets.top.toFloat(),
|
|
173
|
+
right = insets.right.toFloat(),
|
|
174
|
+
bottom = insets.bottom.toFloat(),
|
|
175
|
+
left = insets.left.toFloat()
|
|
176
|
+
)
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
private fun getRootWindowInsetsCompatBase(rootView: View): EdgeInsets? {
|
|
180
|
+
val visibleRect = android.graphics.Rect()
|
|
181
|
+
rootView.getWindowVisibleDisplayFrame(visibleRect)
|
|
182
|
+
return EdgeInsets(
|
|
183
|
+
top = visibleRect.top.toFloat(),
|
|
184
|
+
right = (rootView.width - visibleRect.right).toFloat(),
|
|
185
|
+
bottom = (rootView.height - visibleRect.bottom).toFloat(),
|
|
186
|
+
left = visibleRect.left.toFloat()
|
|
187
|
+
)
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
private fun getBottomInset(context: Activity?): EdgeInsets? {
|
|
192
|
+
if (context != null) {
|
|
193
|
+
val rootView = context.window.decorView
|
|
194
|
+
return when {
|
|
195
|
+
Build.VERSION.SDK_INT >= Build.VERSION_CODES.R -> getRootWindowInsetsCompatR(
|
|
196
|
+
rootView
|
|
197
|
+
)
|
|
198
|
+
|
|
199
|
+
else -> getRootWindowInsetsCompatBase(rootView)
|
|
200
|
+
}
|
|
201
|
+
} else {
|
|
202
|
+
return null
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
private fun getHyperParams(context: Activity, configuration: Bundle): Bundle = Bundle().apply {
|
|
207
|
+
putString("appId", context.packageName)
|
|
208
|
+
putString("country", context.resources?.configuration?.locale?.country)
|
|
209
|
+
putString("user-agent", getUserAgent(context))
|
|
210
|
+
putDouble("launchTime", getCurrentTime())
|
|
211
|
+
putString("sdkVersion", BuildConfig.VERSION_NAME)
|
|
212
|
+
putString("device_model", Build.MODEL)
|
|
213
|
+
putString("os_type", "android")
|
|
214
|
+
putString("os_version", Build.VERSION.RELEASE)
|
|
215
|
+
putString("deviceBrand", Build.BRAND)
|
|
216
|
+
val edgeInsets = getBottomInset(context as Activity?)
|
|
217
|
+
// if(edgeInsets!=null) {
|
|
218
|
+
// putFloat("topInset", edgeInsets.top)
|
|
219
|
+
// putFloat("leftInset", edgeInsets.left)
|
|
220
|
+
// putFloat("rightInset", edgeInsets.right)
|
|
221
|
+
// putFloat("bottomInset", edgeInsets.bottom)
|
|
222
|
+
// }
|
|
223
|
+
configuration.getBoolean("disableBranding").let {
|
|
224
|
+
putBoolean(
|
|
225
|
+
"disableBranding", it
|
|
226
|
+
)
|
|
227
|
+
}
|
|
228
|
+
configuration.getBoolean("defaultView").let {
|
|
229
|
+
putBoolean(
|
|
230
|
+
"defaultView", it
|
|
231
|
+
)
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
fun readableMapToBundle(readableMap: ReadableMap?): Bundle {
|
|
236
|
+
val bundle = Bundle()
|
|
237
|
+
if (readableMap == null) return bundle
|
|
238
|
+
|
|
239
|
+
val iterator = readableMap.keySetIterator()
|
|
240
|
+
while (iterator.hasNextKey()) {
|
|
241
|
+
val key = iterator.nextKey()
|
|
242
|
+
val type = readableMap.getType(key)
|
|
243
|
+
|
|
244
|
+
when (type) {
|
|
245
|
+
ReadableType.Null -> bundle.putString(key, null)
|
|
246
|
+
ReadableType.Boolean -> bundle.putBoolean(key, readableMap.getBoolean(key))
|
|
247
|
+
ReadableType.Number -> {
|
|
248
|
+
val value = readableMap.getDouble(key)
|
|
249
|
+
if (value % 1 == 0.0) {
|
|
250
|
+
bundle.putInt(key, value.toInt())
|
|
251
|
+
} else {
|
|
252
|
+
bundle.putDouble(key, value)
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
ReadableType.String -> bundle.putString(key, readableMap.getString(key))
|
|
257
|
+
ReadableType.Map -> bundle.putBundle(key, readableMapToBundle(readableMap.getMap(key)))
|
|
258
|
+
ReadableType.Array -> {
|
|
259
|
+
// Convert array to JSON string for simplicity
|
|
260
|
+
bundle.putString(key, readableMap.getArray(key)?.toString())
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
return bundle
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
data class EdgeInsets(val top: Float, val right: Float, val bottom: Float, val left: Float)
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
package com.hyperswitchsdkreactnative.views
|
|
2
|
+
|
|
3
|
+
import android.annotation.SuppressLint
|
|
4
|
+
import android.util.Log
|
|
5
|
+
import android.view.View
|
|
6
|
+
import android.widget.FrameLayout
|
|
7
|
+
import com.facebook.react.uimanager.PixelUtil
|
|
8
|
+
import com.facebook.react.uimanager.ThemedReactContext
|
|
9
|
+
import com.google.android.gms.wallet.button.ButtonConstants
|
|
10
|
+
import com.google.android.gms.wallet.button.ButtonOptions
|
|
11
|
+
import com.google.android.gms.wallet.button.PayButton
|
|
12
|
+
|
|
13
|
+
@SuppressLint("ViewConstructor")
|
|
14
|
+
class GooglePayButtonView(private val context: ThemedReactContext) : FrameLayout(context) {
|
|
15
|
+
|
|
16
|
+
var allowedPaymentMethods: String = ""
|
|
17
|
+
var type = ButtonConstants.ButtonType.PLAIN
|
|
18
|
+
var theme = ButtonConstants.ButtonTheme.DARK
|
|
19
|
+
var cornerRadius = 10
|
|
20
|
+
private var button: PayButton? = null
|
|
21
|
+
|
|
22
|
+
fun addButton() {
|
|
23
|
+
if (button != null) {
|
|
24
|
+
removeView(button)
|
|
25
|
+
}
|
|
26
|
+
button = initializeGooglePayButton()
|
|
27
|
+
addView(button)
|
|
28
|
+
viewTreeObserver.addOnGlobalLayoutListener { requestLayout() }
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
private fun initializeGooglePayButton(): PayButton {
|
|
32
|
+
val googlePayButton = PayButton(context)
|
|
33
|
+
|
|
34
|
+
val options =
|
|
35
|
+
ButtonOptions.newBuilder().setAllowedPaymentMethods(allowedPaymentMethods).setButtonType(type)
|
|
36
|
+
.setButtonTheme(theme)
|
|
37
|
+
.setCornerRadius(PixelUtil.toPixelFromDIP(this.cornerRadius.toDouble()).toInt())
|
|
38
|
+
googlePayButton.initialize(options.build())
|
|
39
|
+
googlePayButton.setOnClickListener { _ ->
|
|
40
|
+
// Call the Javascript TouchableOpacity parent where the onClick handler is set
|
|
41
|
+
(this.parent as? View)?.performClick() ?: run {
|
|
42
|
+
Log.e("GooglePayReactNative", "Unable to find parent of GooglePayButtonView.")
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
return googlePayButton
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
override fun requestLayout() {
|
|
49
|
+
super.requestLayout()
|
|
50
|
+
post(mLayoutRunnable)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
private val mLayoutRunnable = Runnable {
|
|
54
|
+
measure(
|
|
55
|
+
MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY),
|
|
56
|
+
MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY)
|
|
57
|
+
)
|
|
58
|
+
layout(left, top, right, bottom)
|
|
59
|
+
}
|
|
60
|
+
}
|
package/android/src/main/java/com/hyperswitchsdkreactnative/views/GooglePayButtonViewManager.kt
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
package com.hyperswitchsdkreactnative.views
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.module.annotations.ReactModule
|
|
4
|
+
import com.facebook.react.uimanager.SimpleViewManager
|
|
5
|
+
import com.facebook.react.uimanager.ThemedReactContext
|
|
6
|
+
import com.facebook.react.uimanager.ViewManagerDelegate
|
|
7
|
+
import com.facebook.react.viewmanagers.GooglePayButtonManagerDelegate
|
|
8
|
+
import com.facebook.react.viewmanagers.GooglePayButtonManagerInterface
|
|
9
|
+
import com.google.android.gms.wallet.button.ButtonConstants
|
|
10
|
+
import java.math.BigInteger
|
|
11
|
+
|
|
12
|
+
@ReactModule(name = GooglePayButtonViewManager.NAME)
|
|
13
|
+
class GooglePayButtonViewManager : SimpleViewManager<GooglePayButtonView>(),
|
|
14
|
+
GooglePayButtonManagerInterface<GooglePayButtonView> {
|
|
15
|
+
private val mDelegate: ViewManagerDelegate<GooglePayButtonView> =
|
|
16
|
+
GooglePayButtonManagerDelegate(this)
|
|
17
|
+
|
|
18
|
+
override fun getDelegate(): ViewManagerDelegate<GooglePayButtonView> {
|
|
19
|
+
return mDelegate
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
override fun getName(): String {
|
|
23
|
+
return NAME
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
public override fun createViewInstance(context: ThemedReactContext): GooglePayButtonView {
|
|
27
|
+
return GooglePayButtonView(context)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
public override fun onAfterUpdateTransaction(view: GooglePayButtonView) {
|
|
31
|
+
super.onAfterUpdateTransaction(view)
|
|
32
|
+
view.addButton()
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
override fun setButtonType(
|
|
36
|
+
view: GooglePayButtonView?, value: String?
|
|
37
|
+
) {
|
|
38
|
+
view?.type = when (value) {
|
|
39
|
+
"BUY" -> ButtonConstants.ButtonType.BUY
|
|
40
|
+
"BOOK" -> ButtonConstants.ButtonType.BOOK
|
|
41
|
+
"CHECKOUT" -> ButtonConstants.ButtonType.CHECKOUT
|
|
42
|
+
"DONATE" -> ButtonConstants.ButtonType.DONATE
|
|
43
|
+
"ORDER" -> ButtonConstants.ButtonType.ORDER
|
|
44
|
+
"PAY" -> ButtonConstants.ButtonType.PAY
|
|
45
|
+
"SUBSCRIBE" -> ButtonConstants.ButtonType.SUBSCRIBE
|
|
46
|
+
else -> ButtonConstants.ButtonType.PLAIN
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
override fun setButtonStyle(
|
|
51
|
+
view: GooglePayButtonView?, value: String?
|
|
52
|
+
) {
|
|
53
|
+
view?.theme = when (value) {
|
|
54
|
+
"light" -> ButtonConstants.ButtonTheme.LIGHT
|
|
55
|
+
else -> ButtonConstants.ButtonTheme.DARK
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
override fun setBorderRadius(
|
|
60
|
+
view: GooglePayButtonView?, value: Double
|
|
61
|
+
) {
|
|
62
|
+
view?.cornerRadius = value.toInt()
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
override fun setAllowedPaymentMethods(
|
|
66
|
+
view: GooglePayButtonView?, value: String?
|
|
67
|
+
) {
|
|
68
|
+
if (value != null) {
|
|
69
|
+
view?.allowedPaymentMethods = value
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
companion object {
|
|
74
|
+
const val NAME = "GooglePayButton"
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
package io.hyperswitch.hyperota
|
|
2
|
+
|
|
3
|
+
import `in`.juspay.hyperota.TrackerCallback
|
|
4
|
+
import io.hyperswitch.logs.EventName
|
|
5
|
+
import org.json.JSONObject
|
|
6
|
+
import io.hyperswitch.logs.HSLog
|
|
7
|
+
import io.hyperswitch.logs.HyperLogManager
|
|
8
|
+
import io.hyperswitch.logs.LogCategory
|
|
9
|
+
import org.json.JSONException
|
|
10
|
+
|
|
11
|
+
class HyperOtaLogger : TrackerCallback() {
|
|
12
|
+
|
|
13
|
+
private fun createAndSendLog(
|
|
14
|
+
eventName: EventName,
|
|
15
|
+
level: String,
|
|
16
|
+
label: String,
|
|
17
|
+
category: String,
|
|
18
|
+
subCategory: String,
|
|
19
|
+
key: String,
|
|
20
|
+
value: Any
|
|
21
|
+
) {
|
|
22
|
+
if (!value.toString().contains("index split is empty") && !value.toString()
|
|
23
|
+
.contains("End of input at character") && !value.toString()
|
|
24
|
+
.contains("some files during clean up")
|
|
25
|
+
) {
|
|
26
|
+
val eventData = mapOf(
|
|
27
|
+
"label" to label,
|
|
28
|
+
"value" to value,
|
|
29
|
+
"category" to category,
|
|
30
|
+
"subcategory" to subCategory,
|
|
31
|
+
"key" to key
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
try {
|
|
35
|
+
val jsonData = JSONObject(eventData).toString()
|
|
36
|
+
val log = HSLog.LogBuilder().logType(level).category(LogCategory.OTA_LIFE_CYCLE)
|
|
37
|
+
.eventName(eventName).value(jsonData).version("0.0.1")
|
|
38
|
+
HyperLogManager.addLog(log.build())
|
|
39
|
+
} catch (e: JSONException) {
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
override fun track(
|
|
45
|
+
category: String, subCategory: String, level: String, label: String, key: String, value: Any
|
|
46
|
+
) {
|
|
47
|
+
if (category == "lifecycle") {
|
|
48
|
+
if (subCategory == "hyperota") {
|
|
49
|
+
val eventName = when (key) {
|
|
50
|
+
"init" -> EventName.HYPER_OTA_INIT
|
|
51
|
+
"end" -> EventName.HYPER_OTA_FINISH
|
|
52
|
+
else -> EventName.HYPER_OTA_EVENT
|
|
53
|
+
}
|
|
54
|
+
createAndSendLog(eventName, level, label, category, subCategory, key, value)
|
|
55
|
+
} else {
|
|
56
|
+
createAndSendLog(
|
|
57
|
+
EventName.HYPER_OTA_EVENT, level, label, category, subCategory, key, value
|
|
58
|
+
)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
}
|
|
62
|
+
// Log.i("ota-1" , "category : " + category + "\n subCategory : " + subCategory +
|
|
63
|
+
// "\n level : " + level + "\n label : " + label + "\n key : " + key + "\n value : " + value.toString())
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
override fun track(
|
|
67
|
+
category: String,
|
|
68
|
+
subCategory: String,
|
|
69
|
+
level: String,
|
|
70
|
+
label: String,
|
|
71
|
+
key: String,
|
|
72
|
+
value: JSONObject
|
|
73
|
+
) {
|
|
74
|
+
if (category == "lifecycle") {
|
|
75
|
+
try {
|
|
76
|
+
val otaVersion = value.getString("package_version")
|
|
77
|
+
HyperLogManager.setOtaVersion(otaVersion)
|
|
78
|
+
} catch (_: JSONException) {
|
|
79
|
+
|
|
80
|
+
}
|
|
81
|
+
if (subCategory == "hyperota") {
|
|
82
|
+
val eventName = when (key) {
|
|
83
|
+
"init" -> EventName.HYPER_OTA_INIT
|
|
84
|
+
"end" -> EventName.HYPER_OTA_FINISH
|
|
85
|
+
else -> EventName.HYPER_OTA_EVENT
|
|
86
|
+
}
|
|
87
|
+
createAndSendLog(eventName, level, label, category, subCategory, key, value)
|
|
88
|
+
} else {
|
|
89
|
+
createAndSendLog(
|
|
90
|
+
EventName.HYPER_OTA_EVENT, level, label, category, subCategory, key, value
|
|
91
|
+
)
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
// Log.i("ota-2" , "category : " + category + "\n subCategory : " + subCategory +
|
|
95
|
+
// "\n level : " + level + "\n label : " + label + "\n key : " + key + "\n value : " + value.toString())
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
override fun trackException(
|
|
99
|
+
category: String, subCategory: String, label: String, description: String, e: Throwable
|
|
100
|
+
) {
|
|
101
|
+
if (category == "lifecycle") {
|
|
102
|
+
val eventData = mapOf(
|
|
103
|
+
"label" to label,
|
|
104
|
+
"value" to (e.message ?: e.stackTraceToString()),
|
|
105
|
+
"category" to category,
|
|
106
|
+
"subcategory" to subCategory
|
|
107
|
+
)
|
|
108
|
+
|
|
109
|
+
try {
|
|
110
|
+
val jsonData = JSONObject(eventData).toString()
|
|
111
|
+
val log =
|
|
112
|
+
HSLog.LogBuilder().logType("error").category(LogCategory.OTA_LIFE_CYCLE)
|
|
113
|
+
.eventName(EventName.HYPER_OTA_EVENT).value(jsonData)
|
|
114
|
+
|
|
115
|
+
HyperLogManager.addLog(log.build())
|
|
116
|
+
} catch (e: JSONException) {
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
// Log.i("ota-3" , "category : " + category + "\n subCategory : " + subCategory +
|
|
120
|
+
// "\n level : " + "error" + "\n label : " + label + "\n description : " + description + "\n value : " + e.toString())
|
|
121
|
+
}
|
|
122
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
package io.hyperswitch.logs
|
|
2
|
+
|
|
3
|
+
import android.content.Context
|
|
4
|
+
import org.json.JSONException
|
|
5
|
+
import org.json.JSONObject
|
|
6
|
+
|
|
7
|
+
class CrashHandler(private val context: Context) : Thread.UncaughtExceptionHandler {
|
|
8
|
+
|
|
9
|
+
private val defaultHandler = Thread.getDefaultUncaughtExceptionHandler()
|
|
10
|
+
private val fileManager = LogFileManager(context)
|
|
11
|
+
override fun uncaughtException(thread: Thread, throwable: Throwable) {
|
|
12
|
+
val obj =
|
|
13
|
+
mapOf(
|
|
14
|
+
"label" to "crash_detected",
|
|
15
|
+
"value" to throwable.toString(),
|
|
16
|
+
"category" to "crash",
|
|
17
|
+
"subcategory" to "sdk_crash"
|
|
18
|
+
)
|
|
19
|
+
try {
|
|
20
|
+
val jsonData = JSONObject(obj).toString()
|
|
21
|
+
val log = HSLog.LogBuilder().logType("error").category(LogCategory.USER_EVENT)
|
|
22
|
+
.eventName(EventName.CRASH_EVENT).value(jsonData).version("0.0.1")
|
|
23
|
+
HyperLogManager.addLog(log.build())
|
|
24
|
+
} catch (_: JSONException) {
|
|
25
|
+
}
|
|
26
|
+
fileManager.addLog(HyperLogManager.getAllLogsAsString())
|
|
27
|
+
defaultHandler?.uncaughtException(thread, throwable)
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
package io.hyperswitch.logs
|
|
2
|
+
|
|
3
|
+
import android.os.Handler
|
|
4
|
+
import android.os.Looper
|
|
5
|
+
|
|
6
|
+
class Debouncer(private val delayInMillis: Long) {
|
|
7
|
+
private val handler = Handler(Looper.getMainLooper())
|
|
8
|
+
private var runnable: Runnable? = null
|
|
9
|
+
|
|
10
|
+
fun debounce(action: () -> Unit) {
|
|
11
|
+
cancel()
|
|
12
|
+
runnable = Runnable { action() }
|
|
13
|
+
handler.postDelayed(runnable!!, delayInMillis)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
fun cancel() {
|
|
17
|
+
runnable?.let { handler.removeCallbacks(it) }
|
|
18
|
+
runnable = null
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
package io.hyperswitch.logs
|
|
2
|
+
|
|
3
|
+
import io.hyperswitch.networking.HyperNetworking
|
|
4
|
+
import io.hyperswitch.react.Utils.Companion.getLoggingUrl
|
|
5
|
+
import org.json.JSONArray
|
|
6
|
+
|
|
7
|
+
object HyperLogManager {
|
|
8
|
+
|
|
9
|
+
private val logsBatch = mutableListOf<HSLog>()
|
|
10
|
+
private var publishableKey: String? = null
|
|
11
|
+
private var loggingEndPoint: String? = null
|
|
12
|
+
private const val DEFAULT_DELAY_IN_MILLIS = 2000L
|
|
13
|
+
private var delayInMillis: Long = DEFAULT_DELAY_IN_MILLIS
|
|
14
|
+
private var hyperOtaVersion: String = ""
|
|
15
|
+
private val debouncer = Debouncer(DEFAULT_DELAY_IN_MILLIS)
|
|
16
|
+
|
|
17
|
+
fun initialise(
|
|
18
|
+
pkKey: String,
|
|
19
|
+
customLogUrl: String?,
|
|
20
|
+
delay: Long = DEFAULT_DELAY_IN_MILLIS
|
|
21
|
+
) {
|
|
22
|
+
if (pkKey.isNotBlank()) {
|
|
23
|
+
publishableKey = pkKey
|
|
24
|
+
delayInMillis = delay
|
|
25
|
+
if (customLogUrl != "" && customLogUrl != null) {
|
|
26
|
+
loggingEndPoint = customLogUrl
|
|
27
|
+
} else {
|
|
28
|
+
loggingEndPoint = getLoggingUrl(pkKey)
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
fun addLog(log: HSLog) {
|
|
34
|
+
logsBatch.add(log)
|
|
35
|
+
debouncedPushLogs()
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
fun sendLogsFromFile(fileManager: LogFileManager) {
|
|
39
|
+
if (publishableKey.isNullOrBlank()) return
|
|
40
|
+
try {
|
|
41
|
+
val logArray = fileManager.getAllLogs()
|
|
42
|
+
if (logArray.length() > 0) {
|
|
43
|
+
enrichLogs(logArray)
|
|
44
|
+
loggingEndPoint?.let { endpoint ->
|
|
45
|
+
try {
|
|
46
|
+
HyperNetworking.makePostRequest(
|
|
47
|
+
endpoint,
|
|
48
|
+
logArray.toString(),
|
|
49
|
+
callback = { result ->
|
|
50
|
+
result.onSuccess {
|
|
51
|
+
fileManager.clearFile()
|
|
52
|
+
}
|
|
53
|
+
})
|
|
54
|
+
} catch (_: Exception) {
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
} catch (e: Exception) {
|
|
59
|
+
e.printStackTrace()
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
fun setOtaVersion(version: String) {
|
|
64
|
+
hyperOtaVersion = version
|
|
65
|
+
debouncedPushLogs()
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
private fun debouncedPushLogs() {
|
|
69
|
+
debouncer.debounce { sendLogsOverNetwork() }
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
private fun enrichLogs(logsArray: JSONArray) {
|
|
73
|
+
for (i in 0 until logsArray.length()) {
|
|
74
|
+
logsArray.getJSONObject(i).apply {
|
|
75
|
+
put("merchant_id", publishableKey)
|
|
76
|
+
put("code_push_version", hyperOtaVersion)
|
|
77
|
+
put("client_core_version", hyperOtaVersion)
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
fun getAllLogsAsString(): String =
|
|
83
|
+
logsBatch.joinToString(prefix = "[", postfix = "]") { it.toJson() }
|
|
84
|
+
|
|
85
|
+
private fun sendLogsOverNetwork() {
|
|
86
|
+
if (logsBatch.isEmpty()) {
|
|
87
|
+
return
|
|
88
|
+
}
|
|
89
|
+
if (!publishableKey.isNullOrBlank() && !loggingEndPoint.isNullOrBlank()) {
|
|
90
|
+
logsBatch.map { log ->
|
|
91
|
+
log.apply {
|
|
92
|
+
merchantId = publishableKey!!
|
|
93
|
+
codePushVersion = hyperOtaVersion
|
|
94
|
+
clientCoreVersion = hyperOtaVersion
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
val logsToSend = getAllLogsAsString()
|
|
98
|
+
logsBatch.clear()
|
|
99
|
+
loggingEndPoint?.let { endpoint ->
|
|
100
|
+
try {
|
|
101
|
+
HyperNetworking.makePostRequest(
|
|
102
|
+
endpoint, logsToSend,
|
|
103
|
+
callback = {}
|
|
104
|
+
)
|
|
105
|
+
} catch (_: Exception) {
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
} else {
|
|
109
|
+
debouncedPushLogs()
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
}
|