@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,335 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
package com.hyperswitchsdkreactnative.internal
|
|
9
|
+
|
|
10
|
+
import android.app.Activity
|
|
11
|
+
import android.app.Application
|
|
12
|
+
import android.content.Context
|
|
13
|
+
import android.content.Intent
|
|
14
|
+
import android.os.Bundle
|
|
15
|
+
import android.view.KeyEvent
|
|
16
|
+
import android.view.LayoutInflater
|
|
17
|
+
import android.view.View
|
|
18
|
+
import android.view.ViewGroup
|
|
19
|
+
import androidx.fragment.app.Fragment
|
|
20
|
+
import com.facebook.react.HyperPackageList
|
|
21
|
+
import com.facebook.react.ReactApplication
|
|
22
|
+
import com.facebook.react.ReactHost
|
|
23
|
+
import com.facebook.react.ReactNativeHost
|
|
24
|
+
import com.facebook.react.ReactPackage
|
|
25
|
+
import com.facebook.react.internal.featureflags.ReactNativeFeatureFlags
|
|
26
|
+
import com.facebook.react.modules.core.PermissionAwareActivity
|
|
27
|
+
import com.facebook.react.modules.core.PermissionListener
|
|
28
|
+
import com.facebook.react.runtime.hermes.HermesInstance
|
|
29
|
+
import com.facebook.react.shell.MainReactPackage
|
|
30
|
+
import com.hyperswitchsdkreactnative.BuildConfig
|
|
31
|
+
import com.hyperswitchsdkreactnative.R
|
|
32
|
+
import com.hyperswitchsdkreactnative.internal.DefaultReactHost.getDefaultReactHost
|
|
33
|
+
import com.hyperswitchsdkreactnative.provider.HyperProvider
|
|
34
|
+
import `in`.juspay.hyperota.LazyDownloadCallback
|
|
35
|
+
import `in`.juspay.hyperotareact.HyperOTAReact
|
|
36
|
+
import io.hyperswitch.hyperota.HyperOtaLogger
|
|
37
|
+
import io.hyperswitch.react.SDKEnvironment
|
|
38
|
+
import io.hyperswitch.react.Utils.Companion.checkEnvironment
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Fragment for creating a React View. This allows the developer to "embed" a React Application
|
|
42
|
+
* inside native components such as a Drawer, ViewPager, etc.
|
|
43
|
+
*/
|
|
44
|
+
internal open class ReactFragment : Fragment(), PermissionAwareActivity {
|
|
45
|
+
protected lateinit var reactDelegate: ReactDelegate
|
|
46
|
+
|
|
47
|
+
private var disableHostLifecycleEvents = false
|
|
48
|
+
private var permissionListener: PermissionListener? = null
|
|
49
|
+
|
|
50
|
+
override fun onCreate(savedInstanceState: Bundle?) {
|
|
51
|
+
super.onCreate(savedInstanceState)
|
|
52
|
+
var mainComponentName: String? = null
|
|
53
|
+
var launchOptions: Bundle? = null
|
|
54
|
+
var fabricEnabled = false
|
|
55
|
+
arguments?.let { args ->
|
|
56
|
+
mainComponentName = args.getString(ARG_COMPONENT_NAME)
|
|
57
|
+
launchOptions = args.getBundle(ARG_LAUNCH_OPTIONS)
|
|
58
|
+
fabricEnabled = args.getBoolean(ARG_FABRIC_ENABLED)
|
|
59
|
+
@Suppress("DEPRECATION")
|
|
60
|
+
disableHostLifecycleEvents = args.getBoolean(ARG_DISABLE_HOST_LIFECYCLE_EVENTS)
|
|
61
|
+
}
|
|
62
|
+
checkNotNull(mainComponentName) { "Cannot loadApp if component name is null" }
|
|
63
|
+
reactDelegate =
|
|
64
|
+
if (ReactNativeFeatureFlags.enableBridgelessArchitecture()) {
|
|
65
|
+
ReactDelegate(requireActivity(), reactHost, mainComponentName, launchOptions)
|
|
66
|
+
} else {
|
|
67
|
+
@Suppress("DEPRECATION")
|
|
68
|
+
(ReactDelegate(
|
|
69
|
+
requireActivity(),
|
|
70
|
+
reactNativeHost,
|
|
71
|
+
mainComponentName,
|
|
72
|
+
launchOptions,
|
|
73
|
+
fabricEnabled,
|
|
74
|
+
))
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Get the [ReactNativeHost] used by this app. By default, assumes [Activity.getApplication] is an
|
|
80
|
+
* instance of [ReactApplication] and calls [ReactApplication.reactNativeHost]. Override this
|
|
81
|
+
* method if your application class does not implement `ReactApplication` or you simply have a
|
|
82
|
+
* different mechanism for storing a `ReactNativeHost`, e.g. as a static field somewhere.
|
|
83
|
+
*/
|
|
84
|
+
@Suppress("DEPRECATION")
|
|
85
|
+
@Deprecated(
|
|
86
|
+
"You should not use ReactNativeHost directly in the New Architecture. Use ReactHost instead.",
|
|
87
|
+
ReplaceWith("reactHost"),
|
|
88
|
+
)
|
|
89
|
+
protected open val reactNativeHost: ReactNativeHost?
|
|
90
|
+
get() = // (activity?.application as ReactApplication?)?.reactNativeHost
|
|
91
|
+
object : DefaultReactNativeHost(requireActivity().application) {
|
|
92
|
+
override fun getPackages(): List<ReactPackage> =
|
|
93
|
+
HyperPackageList(this).packages.apply {
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
override fun getJSMainModuleName(): String = "index"
|
|
97
|
+
override fun getBundleAssetName(): String = "hyperswitch.bundle"
|
|
98
|
+
override fun getJSBundleFile(): String {
|
|
99
|
+
return try {
|
|
100
|
+
hyperOTAServices?.getBundlePath()?.takeUnless { it.contains("ios") }
|
|
101
|
+
?: "assets://hyperswitch.bundle"
|
|
102
|
+
} catch (_: Exception) {
|
|
103
|
+
"assets://hyperswitch.bundle"
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
override fun getUseDeveloperSupport(): Boolean = false
|
|
108
|
+
override val isNewArchEnabled: Boolean = true
|
|
109
|
+
override val isHermesEnabled: Boolean = true
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Get the [ReactHost] used by this app. By default, assumes [Activity.getApplication] is an
|
|
114
|
+
* instance of [ReactApplication] and calls [ReactApplication.reactHost]. Override this method if
|
|
115
|
+
* your application class does not implement `ReactApplication` or you simply have a different
|
|
116
|
+
* mechanism for storing a `ReactHost`, e.g. as a static field somewhere.
|
|
117
|
+
*
|
|
118
|
+
* If you're using Old Architecture/Bridge Mode, this method should return null as [ReactHost] is
|
|
119
|
+
* a Bridgeless-only concept.
|
|
120
|
+
*/
|
|
121
|
+
protected open val reactHost: ReactHost?
|
|
122
|
+
get() = DefaultReactHost.getDefaultReactHost(
|
|
123
|
+
requireContext(),
|
|
124
|
+
HyperPackageList(requireContext().applicationContext as Application).packages,
|
|
125
|
+
"index",
|
|
126
|
+
"hyperswitch",
|
|
127
|
+
try {
|
|
128
|
+
hyperOTAServices?.getBundlePath()?.takeUnless { it.contains("ios") }
|
|
129
|
+
?: "assets://hyperswitch.bundle"
|
|
130
|
+
} catch (_: Exception) {
|
|
131
|
+
"assets://hyperswitch.bundle"
|
|
132
|
+
},
|
|
133
|
+
HermesInstance(),
|
|
134
|
+
false
|
|
135
|
+
)
|
|
136
|
+
|
|
137
|
+
override fun onCreateView(
|
|
138
|
+
inflater: LayoutInflater,
|
|
139
|
+
container: ViewGroup?,
|
|
140
|
+
savedInstanceState: Bundle?,
|
|
141
|
+
): View? {
|
|
142
|
+
reactDelegate.loadApp()
|
|
143
|
+
return reactDelegate.reactRootView
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
override fun onResume() {
|
|
147
|
+
super.onResume()
|
|
148
|
+
if (!disableHostLifecycleEvents) {
|
|
149
|
+
reactDelegate.onHostResume()
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
override fun onPause() {
|
|
154
|
+
super.onPause()
|
|
155
|
+
if (!disableHostLifecycleEvents) {
|
|
156
|
+
reactDelegate.onHostPause()
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
override fun onDestroy() {
|
|
161
|
+
super.onDestroy()
|
|
162
|
+
if (!disableHostLifecycleEvents) {
|
|
163
|
+
reactDelegate.onHostDestroy()
|
|
164
|
+
} else {
|
|
165
|
+
reactDelegate.unloadApp()
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
@Deprecated("Deprecated in Java")
|
|
170
|
+
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
|
171
|
+
@Suppress("DEPRECATION") super.onActivityResult(requestCode, resultCode, data)
|
|
172
|
+
reactDelegate.onActivityResult(requestCode, resultCode, data, false)
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Helper to forward hardware back presses to our React Native Host.
|
|
177
|
+
*
|
|
178
|
+
* This must be called via a forward from your host Activity.
|
|
179
|
+
*/
|
|
180
|
+
open fun onBackPressed(): Boolean = reactDelegate.onBackPressed()
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Helper to forward onKeyUp commands from our host Activity. This allows [ReactFragment] to
|
|
184
|
+
* handle double tap reloads and dev menus.
|
|
185
|
+
*
|
|
186
|
+
* This must be called via a forward from your host Activity.
|
|
187
|
+
*
|
|
188
|
+
* @param keyCode keyCode
|
|
189
|
+
* @param event event
|
|
190
|
+
* @return true if we handled onKeyUp
|
|
191
|
+
*/
|
|
192
|
+
open fun onKeyUp(keyCode: Int, event: KeyEvent): Boolean =
|
|
193
|
+
reactDelegate.shouldShowDevMenuOrReload(keyCode, event)
|
|
194
|
+
|
|
195
|
+
@Deprecated("Deprecated in Java")
|
|
196
|
+
override fun onRequestPermissionsResult(
|
|
197
|
+
requestCode: Int,
|
|
198
|
+
permissions: Array<String>,
|
|
199
|
+
grantResults: IntArray,
|
|
200
|
+
) {
|
|
201
|
+
@Suppress("DEPRECATION")
|
|
202
|
+
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
|
|
203
|
+
permissionListener?.let {
|
|
204
|
+
if (it.onRequestPermissionsResult(requestCode, permissions, grantResults)) {
|
|
205
|
+
permissionListener = null
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
override fun checkPermission(permission: String, pid: Int, uid: Int): Int =
|
|
211
|
+
activity?.checkPermission(permission, pid, uid) ?: 0
|
|
212
|
+
|
|
213
|
+
override fun checkSelfPermission(permission: String): Int =
|
|
214
|
+
activity?.checkSelfPermission(permission) ?: 0
|
|
215
|
+
|
|
216
|
+
@Suppress("DEPRECATION")
|
|
217
|
+
override fun requestPermissions(
|
|
218
|
+
permissions: Array<String>,
|
|
219
|
+
requestCode: Int,
|
|
220
|
+
listener: PermissionListener?,
|
|
221
|
+
) {
|
|
222
|
+
permissionListener = listener
|
|
223
|
+
requestPermissions(permissions, requestCode)
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/** Builder class to help instantiate a ReactFragment. */
|
|
227
|
+
class Builder {
|
|
228
|
+
var componentName: String? = null
|
|
229
|
+
var launchOptions: Bundle? = null
|
|
230
|
+
var fabricEnabled: Boolean = false
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Set the Component name for our React Native instance.
|
|
234
|
+
*
|
|
235
|
+
* @param componentName The name of the component
|
|
236
|
+
* @return Builder
|
|
237
|
+
*/
|
|
238
|
+
fun setComponentName(componentName: String): Builder {
|
|
239
|
+
this.componentName = componentName
|
|
240
|
+
return this
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Set the Launch Options for our React Native instance.
|
|
245
|
+
*
|
|
246
|
+
* @param launchOptions launchOptions
|
|
247
|
+
* @return Builder
|
|
248
|
+
*/
|
|
249
|
+
fun setLaunchOptions(launchOptions: Bundle): Builder {
|
|
250
|
+
this.launchOptions = launchOptions
|
|
251
|
+
return this
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
fun build(): ReactFragment = newInstance(componentName, launchOptions, fabricEnabled)
|
|
255
|
+
|
|
256
|
+
@Deprecated(
|
|
257
|
+
"You should not change call ReactFragment.setFabricEnabled. Instead enable the NewArchitecture for the whole application with newArchEnabled=true in your gradle.properties file"
|
|
258
|
+
)
|
|
259
|
+
fun setFabricEnabled(fabricEnabled: Boolean): Builder {
|
|
260
|
+
this.fabricEnabled = fabricEnabled
|
|
261
|
+
return this
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
companion object {
|
|
266
|
+
protected const val ARG_COMPONENT_NAME: String = "arg_component_name"
|
|
267
|
+
protected const val ARG_LAUNCH_OPTIONS: String = "arg_launch_options"
|
|
268
|
+
protected const val ARG_FABRIC_ENABLED: String = "arg_fabric_enabled"
|
|
269
|
+
|
|
270
|
+
@Deprecated(
|
|
271
|
+
"We will remove this and use a different solution for handling Fragment lifecycle events."
|
|
272
|
+
)
|
|
273
|
+
protected const val ARG_DISABLE_HOST_LIFECYCLE_EVENTS: String =
|
|
274
|
+
"arg_disable_host_lifecycle_events"
|
|
275
|
+
|
|
276
|
+
private var hyperOTAServices: HyperOTAReact? = null
|
|
277
|
+
private lateinit var tracker: HyperOtaLogger
|
|
278
|
+
|
|
279
|
+
fun initOTAServices(
|
|
280
|
+
context : Context
|
|
281
|
+
) {
|
|
282
|
+
val environment = checkEnvironment(HyperProvider.publishableKey())
|
|
283
|
+
val hyperOTAUrl = context.getString(
|
|
284
|
+
if (environment == SDKEnvironment.SANDBOX)
|
|
285
|
+
R.string.hyperOTASandBoxEndPoint
|
|
286
|
+
else
|
|
287
|
+
R.string.hyperOTAEndPoint
|
|
288
|
+
)
|
|
289
|
+
if (hyperOTAUrl != "hyperOTA_END_POINT_") {
|
|
290
|
+
tracker = HyperOtaLogger()
|
|
291
|
+
val headers = mapOf(
|
|
292
|
+
"Content-Encoding" to "br, gzip"
|
|
293
|
+
)
|
|
294
|
+
context.applicationContext?.let {
|
|
295
|
+
HyperOTAReact(
|
|
296
|
+
it,
|
|
297
|
+
"hyperswitchRN",
|
|
298
|
+
"hyperswitch.bundle",
|
|
299
|
+
BuildConfig.VERSION_NAME,
|
|
300
|
+
"$hyperOTAUrl/mobile-ota/rn/android/${BuildConfig.VERSION_NAME}/config.json",
|
|
301
|
+
headers,
|
|
302
|
+
object : LazyDownloadCallback {
|
|
303
|
+
override fun fileInstalled(filePath: String, success: Boolean) {
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
override fun lazySplitsInstalled(success: Boolean) {
|
|
307
|
+
}
|
|
308
|
+
},
|
|
309
|
+
tracker,
|
|
310
|
+
)
|
|
311
|
+
}.also { hyperOTAServices = it }
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* @param componentName The name of the react native component
|
|
317
|
+
* @param launchOptions The launch options for the react native component
|
|
318
|
+
* @param fabricEnabled Flag to enable Fabric for ReactFragment
|
|
319
|
+
* @return A new instance of fragment ReactFragment.
|
|
320
|
+
*/
|
|
321
|
+
private fun newInstance(
|
|
322
|
+
componentName: String?,
|
|
323
|
+
launchOptions: Bundle?,
|
|
324
|
+
fabricEnabled: Boolean,
|
|
325
|
+
): ReactFragment {
|
|
326
|
+
val args =
|
|
327
|
+
Bundle().apply {
|
|
328
|
+
putString(ARG_COMPONENT_NAME, componentName)
|
|
329
|
+
putBundle(ARG_LAUNCH_OPTIONS, launchOptions)
|
|
330
|
+
putBoolean(ARG_FABRIC_ENABLED, fabricEnabled)
|
|
331
|
+
}
|
|
332
|
+
return ReactFragment().apply { setArguments(args) }
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
}
|
package/android/src/main/java/com/hyperswitchsdkreactnative/modules/HyperswitchSdkNativeModule.kt
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
package com.hyperswitchsdkreactnative.modules
|
|
2
|
+
|
|
3
|
+
import android.util.Log
|
|
4
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
5
|
+
import com.facebook.react.bridge.Callback
|
|
6
|
+
import com.facebook.react.bridge.ReactMethod
|
|
7
|
+
import com.facebook.react.bridge.WritableMap
|
|
8
|
+
import com.facebook.react.bridge.WritableNativeMap
|
|
9
|
+
import org.json.JSONException
|
|
10
|
+
import com.hyperswitchsdkreactnative.NativeHyperswitchSdkNativeSpec
|
|
11
|
+
import com.hyperswitchsdkreactnative.modules.HyperswitchSdkReactNativeModule.Companion.resetView
|
|
12
|
+
import com.hyperswitchsdkreactnative.modules.HyperswitchSdkReactNativeModule.Companion.resolvePromise
|
|
13
|
+
import io.hyperswitch.payments.GooglePayCallbackManager
|
|
14
|
+
/**
|
|
15
|
+
* HyperModules TurboModule implementation that bridges the bundle's expectations
|
|
16
|
+
* with the existing HyperswitchSdkModule functionality
|
|
17
|
+
*/
|
|
18
|
+
class HyperswitchSdkNativeModule(reactContext: ReactApplicationContext) :
|
|
19
|
+
NativeHyperswitchSdkNativeSpec(reactContext) {
|
|
20
|
+
|
|
21
|
+
override fun getName(): String {
|
|
22
|
+
return NAME
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
@ReactMethod
|
|
26
|
+
override fun sendMessageToNative(message: String) {
|
|
27
|
+
// Log.d(NAME, "sendMessageToNative called with: $message")
|
|
28
|
+
// Forward to HyperswitchSdkModule if needed
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
@ReactMethod
|
|
32
|
+
override fun launchApplePay(requestObj: String, callback: Callback) {
|
|
33
|
+
// Log.d(NAME, "launchApplePay called")
|
|
34
|
+
// Implementation for Apple Pay
|
|
35
|
+
callback.invoke("Apple Pay not implemented")
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
@ReactMethod
|
|
40
|
+
override fun launchGPay(requestObj: String, callback: Callback) {
|
|
41
|
+
Log.i("Manideep", "called gpay here")
|
|
42
|
+
currentActivity?.let {
|
|
43
|
+
GooglePayCallbackManager.setCallback(
|
|
44
|
+
it,
|
|
45
|
+
requestObj,
|
|
46
|
+
fun(data: Map<String, Any?>) {
|
|
47
|
+
callback.invoke(mapToWritableMap(data))
|
|
48
|
+
},
|
|
49
|
+
)
|
|
50
|
+
} ?: run {
|
|
51
|
+
GooglePayCallbackManager.setCallback(
|
|
52
|
+
reactApplicationContext,
|
|
53
|
+
requestObj,
|
|
54
|
+
fun(data: Map<String, Any?>) {
|
|
55
|
+
callback.invoke(mapToWritableMap(data))
|
|
56
|
+
},
|
|
57
|
+
)
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
@ReactMethod
|
|
62
|
+
override fun exitPaymentsheet(rootTag: Double, result: String, reset: Boolean) {
|
|
63
|
+
try {
|
|
64
|
+
resetView()
|
|
65
|
+
resolvePromise(result)
|
|
66
|
+
} catch (e: JSONException) {
|
|
67
|
+
// Log.e(NAME, "Failed to parse JSON result: $result", e)
|
|
68
|
+
resolvePromise(result)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
@ReactMethod
|
|
74
|
+
override fun exitPaymentMethodManagement(rootTag: Double, result: String, reset: Boolean) {
|
|
75
|
+
// Log.d(NAME, "exitPaymentMethodManagement called $result")
|
|
76
|
+
resolvePromise(result)
|
|
77
|
+
|
|
78
|
+
// Implementation for exiting payment method management
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
@ReactMethod
|
|
82
|
+
override fun exitWidget(result: String, widgetType: String) {
|
|
83
|
+
// Log.d(NAME, "exitWidget called with result: $result, widgetType: $widgetType")
|
|
84
|
+
resolvePromise(result)
|
|
85
|
+
|
|
86
|
+
// Implementation for exiting widget
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
@ReactMethod
|
|
90
|
+
override fun exitCardForm(result: String) {
|
|
91
|
+
// Log.d(NAME, "exitCardForm called with result: $result")
|
|
92
|
+
resolvePromise(result)
|
|
93
|
+
|
|
94
|
+
// Implementation for exiting card form
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
@ReactMethod
|
|
98
|
+
override fun exitWidgetPaymentsheet(rootTag: Double, result: String, reset: Boolean) {
|
|
99
|
+
// Log.d(NAME, "exitWidgetPaymentsheet called")
|
|
100
|
+
resolvePromise(result)
|
|
101
|
+
|
|
102
|
+
// Implementation for exiting widget payment sheet
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
@ReactMethod
|
|
106
|
+
override fun launchWidgetPaymentSheet(requestObj: String, callback: Callback) {
|
|
107
|
+
// Log.d(NAME, "launchWidgetPaymentSheet called")
|
|
108
|
+
// Implementation for launching widget payment sheet
|
|
109
|
+
callback.invoke("Widget payment sheet not implemented")
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
@ReactMethod
|
|
113
|
+
override fun updateWidgetHeight(height: Double) {
|
|
114
|
+
// Log.d(NAME, "updateWidgetHeight called with height: $height")
|
|
115
|
+
// Implementation for updating widget height
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
@ReactMethod
|
|
119
|
+
override fun onAddPaymentMethod(data: String) {
|
|
120
|
+
// Log.d(NAME, "onAddPaymentMethod called with data: $data")
|
|
121
|
+
// Implementation for adding payment method
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
private fun mapToWritableMap(map: Map<String, Any?>): WritableMap {
|
|
125
|
+
val writableMap = WritableNativeMap()
|
|
126
|
+
for ((key, value) in map) {
|
|
127
|
+
when (value) {
|
|
128
|
+
null -> writableMap.putNull(key)
|
|
129
|
+
is Boolean -> writableMap.putBoolean(key, value)
|
|
130
|
+
is Double -> writableMap.putDouble(key, value)
|
|
131
|
+
is Int -> writableMap.putInt(key, value)
|
|
132
|
+
is String -> writableMap.putString(key, value)
|
|
133
|
+
is Map<*, *> -> writableMap.putMap(key, mapToWritableMap(value as Map<String, Any?>))
|
|
134
|
+
else -> writableMap.putString(key, value.toString())
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return writableMap
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
companion object {
|
|
141
|
+
const val NAME = "HyperModules"
|
|
142
|
+
}
|
|
143
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
package com.hyperswitchsdkreactnative.modules
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
import android.R.attr.id
|
|
5
|
+
import androidx.fragment.app.FragmentActivity
|
|
6
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
7
|
+
import com.facebook.react.module.annotations.ReactModule
|
|
8
|
+
import com.facebook.react.bridge.Promise
|
|
9
|
+
import com.facebook.react.bridge.ReadableMap
|
|
10
|
+
import com.hyperswitchsdkreactnative.NativeHyperswitchSdkReactNativeSpec
|
|
11
|
+
import com.hyperswitchsdkreactnative.provider.HyperProvider
|
|
12
|
+
import io.hyperswitch.react.Utils
|
|
13
|
+
|
|
14
|
+
@ReactModule(name = HyperswitchSdkReactNativeModule.NAME)
|
|
15
|
+
class HyperswitchSdkReactNativeModule(reactContext: ReactApplicationContext) :
|
|
16
|
+
NativeHyperswitchSdkReactNativeSpec(reactContext) {
|
|
17
|
+
|
|
18
|
+
private var hyperProvider: HyperProvider? = null
|
|
19
|
+
|
|
20
|
+
init {
|
|
21
|
+
currentInstance = this
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
override fun getName(): String {
|
|
25
|
+
return NAME
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
override fun initialise(
|
|
29
|
+
publishableKey: String,
|
|
30
|
+
customBackendUrl: String?,
|
|
31
|
+
customLogUrl: String?,
|
|
32
|
+
customParams: ReadableMap?,
|
|
33
|
+
promise: Promise?
|
|
34
|
+
) {
|
|
35
|
+
try {
|
|
36
|
+
currentActivity?.let { activity ->
|
|
37
|
+
hyperProvider = HyperProvider(activity)
|
|
38
|
+
hyperProvider!!.initialise(publishableKey, customBackendUrl, customLogUrl, customParams)
|
|
39
|
+
promise?.resolve(null)
|
|
40
|
+
} ?: run {
|
|
41
|
+
promise?.reject("INITIALIZATION_ERROR", "Current activity is null")
|
|
42
|
+
}
|
|
43
|
+
} catch (e: Exception) {
|
|
44
|
+
promise?.reject("INITIALIZATION_ERROR", "Failed to initialize Hyperswitch SDK: ${e.message}")
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
override fun initPaymentSession(paymentIntentClientSecret: String, promise: Promise?) {
|
|
49
|
+
try {
|
|
50
|
+
hyperProvider?.let { provider ->
|
|
51
|
+
provider.initPaymentSession(clientSecret = paymentIntentClientSecret)
|
|
52
|
+
promise?.resolve(null)
|
|
53
|
+
} ?: run {
|
|
54
|
+
promise?.reject("INIT_ERROR", "HyperProvider not initialized")
|
|
55
|
+
}
|
|
56
|
+
} catch (e: Exception) {
|
|
57
|
+
promise?.reject("INIT_ERROR", "Failed to initialize payment sheet: ${e.message}")
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
override fun presentPaymentSheet(readableMap: ReadableMap, promise: Promise?) {
|
|
62
|
+
try {
|
|
63
|
+
hyperProvider?.let { provider ->
|
|
64
|
+
sheetPromise = promise
|
|
65
|
+
provider.presentPaymentSheet(readableMap)
|
|
66
|
+
}
|
|
67
|
+
} catch (e: Exception) {
|
|
68
|
+
promise?.reject("PRESENT_ERROR", "Failed to present payment sheet: ${e.message}")
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
fun resetView() {
|
|
73
|
+
hyperProvider?.removeSheetView(true)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
companion object {
|
|
77
|
+
const val NAME = "HyperswitchSdkReactNative"
|
|
78
|
+
private var sheetPromise: Promise? = null
|
|
79
|
+
private var currentInstance: HyperswitchSdkReactNativeModule? = null
|
|
80
|
+
|
|
81
|
+
fun resolvePromise(data: Any?) {
|
|
82
|
+
try {
|
|
83
|
+
sheetPromise?.resolve(data)
|
|
84
|
+
} catch (e: Exception) {
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
fun resetView() {
|
|
89
|
+
currentInstance?.resetView()
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|