react-native-hyperswitch-dev-sdk 0.4.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 +42 -0
- package/LICENSE +201 -0
- package/android/build.gradle +161 -0
- package/android/gradle.properties +5 -0
- package/android/hyperswitch_autolinking.gradle +378 -0
- package/android/proguard-rules.pro +72 -0
- package/android/src/legacy/java/com/facebook/react/viewmanagers/GooglePayButtonManagerDelegate.java +41 -0
- package/android/src/legacy/java/com/facebook/react/viewmanagers/GooglePayButtonManagerInterface.java +20 -0
- package/android/src/legacy/java/com/facebook/react/viewmanagers/NativePaymentWidgetManagerDelegate.java +38 -0
- package/android/src/legacy/java/com/facebook/react/viewmanagers/NativePaymentWidgetManagerInterface.java +21 -0
- package/android/src/legacy/java/com/hyperswitchsdkreactnative/NativeHyperswitchSdkNativeSpec.java +106 -0
- package/android/src/legacy/java/com/hyperswitchsdkreactnative/NativeHyperswitchSdkReactNativeSpec.java +77 -0
- package/android/src/legacy/java/com/hyperswitchsdkreactnative/NativePaymentWidgetNativeSpec.java +36 -0
- package/android/src/main/AndroidManifest.xml +15 -0
- package/android/src/main/assets/hyperswitch.bundle +1535 -0
- package/android/src/main/java/com/hyperswitchsdkreactnative/HyperswitchSdkReactNativePackage.kt +47 -0
- package/android/src/main/java/com/hyperswitchsdkreactnative/modules/NativePaymentWidgetModule.kt +173 -0
- package/android/src/main/java/com/hyperswitchsdkreactnative/modules/ReactNativeHyperswitchModule.kt +396 -0
- package/android/src/main/java/com/hyperswitchsdkreactnative/views/PaymentElementViewManager.kt +99 -0
- package/android/src/main/java/io/hyperswitch/HyperswitchReactPackageProvider.kt +19 -0
- package/android/src/main/java/io/hyperswitch/PaymentEventType.kt +18 -0
- package/android/src/main/java/io/hyperswitch/model/ElementConfiguration.kt +58 -0
- package/android/src/main/java/io/hyperswitch/paymentsession/ExitHeadlessCallBackManager.kt +47 -0
- package/android/src/main/java/io/hyperswitch/paymentsession/GetPaymentSessionCallBackManager.kt +23 -0
- package/android/src/main/java/io/hyperswitch/paymentsession/PaymentMethod.kt +167 -0
- package/android/src/main/java/io/hyperswitch/paymentsession/PaymentSessionHandler.kt +68 -0
- package/android/src/main/java/io/hyperswitch/paymentsession/PaymentSessionHandlerImpl.kt +179 -0
- package/android/src/main/java/io/hyperswitch/paymentsession/PaymentSessionReactLauncher.kt +226 -0
- package/android/src/main/java/io/hyperswitch/paymentsession/PaymentSheetCallbackManager.kt +40 -0
- package/android/src/main/java/io/hyperswitch/paymentsheet/PaymentResult.kt +63 -0
- package/android/src/main/java/io/hyperswitch/react/GooglePayButtonManager.kt +54 -0
- package/android/src/main/java/io/hyperswitch/react/HyperActivity.kt +73 -0
- package/android/src/main/java/io/hyperswitch/react/HyperEventEmitter.kt +144 -0
- package/android/src/main/java/io/hyperswitch/react/HyperFragment.kt +429 -0
- package/android/src/main/java/io/hyperswitch/react/HyperFragmentManager.kt +155 -0
- package/android/src/main/java/io/hyperswitch/react/HyperHeadlessModule.kt +43 -0
- package/android/src/main/java/io/hyperswitch/react/HyperModule.kt +405 -0
- package/android/src/main/java/io/hyperswitch/react/HyperPackage.kt +16 -0
- package/android/src/main/java/io/hyperswitch/react/ReactNativeController.kt +251 -0
- package/android/src/main/java/io/hyperswitch/utils/ConversionUtils.kt +256 -0
- package/android/src/main/java/io/hyperswitch/utils/StandardResult.kt +45 -0
- package/android/src/main/java/io/hyperswitch/view/GooglePayButtonView.kt +59 -0
- package/android/src/main/java/io/hyperswitch/view/PaymentWidgetView.kt +405 -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/ReactNative/HyperswitchModule.swift +470 -0
- package/ios/Modules/ReactNative/HyperswitchSdkReactNative.h +5 -0
- package/ios/Modules/ReactNative/HyperswitchSdkReactNative.mm +121 -0
- package/ios/Modules/ReactNative/NativeHyperswitchModule.h +18 -0
- package/ios/Modules/ReactNative/NativeHyperswitchModule.mm +165 -0
- package/ios/Modules/ReactNative/NativeHyperswitchModuleImpl.swift +290 -0
- package/ios/Modules/ReactNative/NativePaymentElementModule.mm +129 -0
- package/ios/Views/Fabric/ApplePayView.h +14 -0
- package/ios/Views/Fabric/ApplePayView.mm +89 -0
- package/ios/Views/Fabric/NativePaymentElementView.h +21 -0
- package/ios/Views/Fabric/NativePaymentElementView.mm +200 -0
- package/ios/Views/Fabric/NativePaymentWidgetViewRegistry.h +37 -0
- package/ios/Views/Fabric/NativePaymentWidgetViewRegistry.m +45 -0
- package/ios/Views/Native/NativePaymentWidget.m +26 -0
- package/ios/Views/Native/NativePaymentWidget.swift +420 -0
- package/ios/hyperswitchSDK/Core/ApplePay/ApplePayHandler.swift +261 -0
- package/ios/hyperswitchSDK/Core/ApplePay/ApplePayViewManager.m +18 -0
- package/ios/hyperswitchSDK/Core/ApplePay/ApplePayViewManager.swift +126 -0
- package/ios/hyperswitchSDK/Core/DeviceDataCollection/HeadlessWebView.swift +144 -0
- package/ios/hyperswitchSDK/Core/HyperCVCWidget/CVCWidget.swift +136 -0
- package/ios/hyperswitchSDK/Core/HyperExpressCheckout/ExpressCheckoutLauncher.swift +116 -0
- package/ios/hyperswitchSDK/Core/HyperExpressCheckout/ExpressCheckoutWidget.swift +42 -0
- package/ios/hyperswitchSDK/Core/HyperPaymentCardTextField/PaymentCardTextField+SwiftUI.swift +67 -0
- package/ios/hyperswitchSDK/Core/HyperPaymentCardTextField/PaymentCardTextField.swift +44 -0
- package/ios/hyperswitchSDK/Core/HyperPaymentCardTextField/PaymentHandler.swift +59 -0
- package/ios/hyperswitchSDK/Core/HyperPaymentCardTextField/PaymentIntentParams.swift +31 -0
- package/ios/hyperswitchSDK/Core/HyperPaymentCardTextField/PaymentMethodParams.swift +25 -0
- package/ios/hyperswitchSDK/Core/HyperPaymentMethodManagement/PaymentManagementConfiguration.swift +213 -0
- package/ios/hyperswitchSDK/Core/HyperPaymentMethodManagement/PaymentMethodManagementWidget.swift +92 -0
- package/ios/hyperswitchSDK/Core/HyperPaymentSheet/PaymentSheet+Events.swift +36 -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 +68 -0
- package/ios/hyperswitchSDK/Core/HyperPaymentWidget/PaymentWidget.swift +212 -0
- package/ios/hyperswitchSDK/Core/HyperSession/PaymentSession+UIKit.swift +228 -0
- package/ios/hyperswitchSDK/Core/HyperSession/PaymentSessionTypes.swift +174 -0
- package/ios/hyperswitchSDK/Core/NativeModule/HyperHeadless.m +15 -0
- package/ios/hyperswitchSDK/Core/NativeModule/HyperHeadless.swift +108 -0
- package/ios/hyperswitchSDK/Core/NativeModule/HyperModule.m +31 -0
- package/ios/hyperswitchSDK/Core/NativeModule/HyperModule.swift +343 -0
- package/ios/hyperswitchSDK/Core/NativeModule/OTAServices.swift +117 -0
- package/ios/hyperswitchSDK/Core/NativeModule/RNHeadlessManager.swift +47 -0
- package/ios/hyperswitchSDK/Core/NativeModule/RNResponseHandler.swift +12 -0
- package/ios/hyperswitchSDK/Core/NativeModule/RNViewManager.swift +55 -0
- package/ios/hyperswitchSDK/Core/NativeModule/WidgetAction.swift +30 -0
- package/ios/hyperswitchSDK/Core/NativeModule/WidgetResponseRegistry.swift +92 -0
- package/ios/hyperswitchSDK/Core/NativeModule/hyper-Bridging-Header.h +12 -0
- package/ios/hyperswitchSDK/Core/Resources/HyperOTA.plist +20 -0
- package/ios/hyperswitchSDK/Core/Resources/hyperswitch.bundle +1531 -0
- package/ios/hyperswitchSDK/CoreLite/ApplePayHandlerLite.swift +251 -0
- package/ios/hyperswitchSDK/CoreLite/PaymentSession+Lite.swift +25 -0
- package/ios/hyperswitchSDK/CoreLite/PaymentSheetView+Lite.swift +45 -0
- package/ios/hyperswitchSDK/CoreLite/SwiftUI+Lite.swift +48 -0
- package/ios/hyperswitchSDK/CoreLite/WebViewController.swift +278 -0
- package/ios/hyperswitchSDK/Shared/APIClient.swift +22 -0
- package/ios/hyperswitchSDK/Shared/Codable+UIKit.swift +75 -0
- package/ios/hyperswitchSDK/Shared/CustomEndpointConfiguration.swift +67 -0
- package/ios/hyperswitchSDK/Shared/DictionaryConverter.swift +104 -0
- package/ios/hyperswitchSDK/Shared/Environment.swift +24 -0
- package/ios/hyperswitchSDK/Shared/Extensions.swift +101 -0
- package/ios/hyperswitchSDK/Shared/Helper.swift +40 -0
- package/ios/hyperswitchSDK/Shared/HyperEvents/PaymentEventData.swift +125 -0
- package/ios/hyperswitchSDK/Shared/HyperEvents/PaymentEventSubscriptionBuilder.swift +45 -0
- package/ios/hyperswitchSDK/Shared/HyperEvents/PaymentEventType.swift +30 -0
- package/ios/hyperswitchSDK/Shared/HyperNetworking.swift +151 -0
- package/ios/hyperswitchSDK/Shared/HyperParams.swift +44 -0
- package/ios/hyperswitchSDK/Shared/HyperUIViewController.swift +27 -0
- package/ios/hyperswitchSDK/Shared/Hyperswitch.swift +20 -0
- package/ios/hyperswitchSDK/Shared/HyperswitchConfigurationSchema.swift +54 -0
- package/ios/hyperswitchSDK/Shared/HyperswitchEnvironment.swift +11 -0
- package/ios/hyperswitchSDK/Shared/NativeLogger/Debouncer.swift +37 -0
- package/ios/hyperswitchSDK/Shared/NativeLogger/LogBuilder.swift +113 -0
- package/ios/hyperswitchSDK/Shared/NativeLogger/LogFileManager.swift +76 -0
- package/ios/hyperswitchSDK/Shared/NativeLogger/LogManager.swift +113 -0
- package/ios/hyperswitchSDK/Shared/NativeLogger/LogPayload.swift +91 -0
- package/ios/hyperswitchSDK/Shared/PaymentMethodType.swift +15 -0
- package/ios/hyperswitchSDK/Shared/PaymentSession.swift +98 -0
- package/ios/hyperswitchSDK/Shared/PaymentSessionConfiguration.swift +14 -0
- package/ios/hyperswitchSDK/Shared/PaymentSheet.swift +33 -0
- package/ios/hyperswitchSDK/Shared/PaymentSheetAppearance+Codable.swift +182 -0
- package/ios/hyperswitchSDK/Shared/PaymentSheetAppearance.swift +238 -0
- package/ios/hyperswitchSDK/Shared/PaymentSheetConfiguration.swift +161 -0
- package/ios/hyperswitchSDK/Shared/SDKParams.swift +43 -0
- package/ios/hyperswitchSDK/Shared/SavedPaymentMethodsConfiguration.swift +20 -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 +0 -0
- package/lib/bs/build.ninja +8 -0
- package/lib/bs/install.ninja +9 -0
- package/lib/bs/src/context/HyperProvider-JuspayTechReactNativeHyperswitch.cmt +0 -0
- package/lib/bs/src/context/WidgetRegistry-JuspayTechReactNativeHyperswitch.cmt +0 -0
- package/lib/bs/src/core/Hyper-JuspayTechReactNativeHyperswitch.cmt +0 -0
- package/lib/bs/src/core/HyperElements-JuspayTechReactNativeHyperswitch.cmt +0 -0
- package/lib/bs/src/hooks/usePaymentSession-JuspayTechReactNativeHyperswitch.cmt +0 -0
- package/lib/bs/src/hooks/useWidget-JuspayTechReactNativeHyperswitch.cmt +0 -0
- package/lib/bs/src/modules/NativeHyperswitchSdk-JuspayTechReactNativeHyperswitch.cmt +0 -0
- package/lib/bs/src/types/HyperTypes-JuspayTechReactNativeHyperswitch.cmt +0 -0
- package/lib/bs/src/types/NativeModuleTypes-JuspayTechReactNativeHyperswitch.cmt +0 -0
- package/lib/bs/src/types/PaymentSheetConfiguration-JuspayTechReactNativeHyperswitch.cmt +0 -0
- package/lib/bs/src/utils/AppearanceTransformer-JuspayTechReactNativeHyperswitch.cmt +0 -0
- package/lib/bs/src/utils/EventValidator-JuspayTechReactNativeHyperswitch.cmt +0 -0
- package/lib/bs/src/utils/NewArchUtils-JuspayTechReactNativeHyperswitch.cmt +0 -0
- package/lib/bs/src/utils/PaymentSheetEventManager-JuspayTechReactNativeHyperswitch.cmt +0 -0
- package/lib/bs/src/utils/ReactNativeUtils-JuspayTechReactNativeHyperswitch.cmt +0 -0
- package/lib/bs/src/utils/ResponseHandler-JuspayTechReactNativeHyperswitch.cmt +0 -0
- package/lib/bs/src/views/CVCElement-JuspayTechReactNativeHyperswitch.cmt +0 -0
- package/lib/bs/src/views/NativePaymentWidget-JuspayTechReactNativeHyperswitch.cmt +0 -0
- package/lib/bs/src/views/NativePaymentWidgetImpl-JuspayTechReactNativeHyperswitch.cmt +0 -0
- package/lib/bs/src/views/PaymentElement-JuspayTechReactNativeHyperswitch.cmt +0 -0
- package/lib/commonjs/index.bundle.js +2 -0
- package/lib/commonjs/index.bundle.js.map +1 -0
- package/lib/module/index.bundle.js +2 -0
- package/lib/module/index.bundle.js.map +1 -0
- package/lib/typescript/babel.config.d.ts +10 -0
- package/lib/typescript/babel.config.d.ts.map +1 -0
- package/lib/typescript/eslint.config.d.mts +3 -0
- package/lib/typescript/eslint.config.d.mts.map +1 -0
- package/lib/typescript/rollup.config.d.ts +23 -0
- package/lib/typescript/rollup.config.d.ts.map +1 -0
- package/lib/typescript/scripts/bootstrap.d.ts +2 -0
- package/lib/typescript/scripts/bootstrap.d.ts.map +1 -0
- package/lib/typescript/src/context/Elements.d.ts +7 -0
- package/lib/typescript/src/context/Elements.d.ts.map +1 -0
- package/lib/typescript/src/context/HyperElements.d.ts +23 -0
- package/lib/typescript/src/context/HyperElements.d.ts.map +1 -0
- package/lib/typescript/src/context/PaymentSession.d.ts +15 -0
- package/lib/typescript/src/context/PaymentSession.d.ts.map +1 -0
- package/lib/typescript/src/context/SavedPaymentMethods.d.ts +5 -0
- package/lib/typescript/src/context/SavedPaymentMethods.d.ts.map +1 -0
- package/lib/typescript/src/context/WidgetRegistry.d.ts +8 -0
- package/lib/typescript/src/context/WidgetRegistry.d.ts.map +1 -0
- package/lib/typescript/src/context/hooks.d.ts +5 -0
- package/lib/typescript/src/context/hooks.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +10 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/modules/NativeHyperswitchSdk.d.ts +61 -0
- package/lib/typescript/src/modules/NativeHyperswitchSdk.d.ts.map +1 -0
- package/lib/typescript/src/specs/ApplePayViewNativeComponent.d.ts +10 -0
- package/lib/typescript/src/specs/ApplePayViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/src/specs/NativeHyperHeadless.d.ts +14 -0
- package/lib/typescript/src/specs/NativeHyperHeadless.d.ts.map +1 -0
- package/lib/typescript/src/specs/NativeHyperswitchModule.d.ts +32 -0
- package/lib/typescript/src/specs/NativeHyperswitchModule.d.ts.map +1 -0
- package/lib/typescript/src/specs/NativeHyperswitchSdkNative.d.ts +33 -0
- package/lib/typescript/src/specs/NativeHyperswitchSdkNative.d.ts.map +1 -0
- package/lib/typescript/src/specs/NativePaymentElementModule.d.ts +9 -0
- package/lib/typescript/src/specs/NativePaymentElementModule.d.ts.map +1 -0
- package/lib/typescript/src/specs/PaymentElementNativeComponent.d.ts +19 -0
- package/lib/typescript/src/specs/PaymentElementNativeComponent.d.ts.map +1 -0
- package/lib/typescript/src/specs/utils.d.ts +15 -0
- package/lib/typescript/src/specs/utils.d.ts.map +1 -0
- package/lib/typescript/src/types/NativeModuleTypes.d.ts +67 -0
- package/lib/typescript/src/types/NativeModuleTypes.d.ts.map +1 -0
- package/lib/typescript/src/types/PaymentSheetConfiguration.d.ts +255 -0
- package/lib/typescript/src/types/PaymentSheetConfiguration.d.ts.map +1 -0
- package/lib/typescript/src/types/definitions.d.ts +85 -0
- package/lib/typescript/src/types/definitions.d.ts.map +1 -0
- package/lib/typescript/src/types/elements/index.d.ts +23 -0
- package/lib/typescript/src/types/elements/index.d.ts.map +1 -0
- package/lib/typescript/src/types/paymentresult/index.d.ts +5 -0
- package/lib/typescript/src/types/paymentresult/index.d.ts.map +1 -0
- package/lib/typescript/src/types/savedPaymentMethods/index.d.ts +69 -0
- package/lib/typescript/src/types/savedPaymentMethods/index.d.ts.map +1 -0
- package/lib/typescript/src/utils/EventValidator.d.ts +9 -0
- package/lib/typescript/src/utils/EventValidator.d.ts.map +1 -0
- package/lib/typescript/src/utils/InitializationState.d.ts +13 -0
- package/lib/typescript/src/utils/InitializationState.d.ts.map +1 -0
- package/lib/typescript/src/utils/LaunchOptions.d.ts +7 -0
- package/lib/typescript/src/utils/LaunchOptions.d.ts.map +1 -0
- package/lib/typescript/src/utils/NewArchUtils.d.ts +7 -0
- package/lib/typescript/src/utils/NewArchUtils.d.ts.map +1 -0
- package/lib/typescript/src/utils/ReactNativeUtils.d.ts +3 -0
- package/lib/typescript/src/utils/ReactNativeUtils.d.ts.map +1 -0
- package/lib/typescript/src/views/CVCElement.d.ts +15 -0
- package/lib/typescript/src/views/CVCElement.d.ts.map +1 -0
- package/lib/typescript/src/views/NativePaymentWidget.d.ts +3 -0
- package/lib/typescript/src/views/NativePaymentWidget.d.ts.map +1 -0
- package/lib/typescript/src/views/NativePaymentWidgetImpl.d.ts +5 -0
- package/lib/typescript/src/views/NativePaymentWidgetImpl.d.ts.map +1 -0
- package/lib/typescript/src/views/PaymentElement.d.ts +18 -0
- package/lib/typescript/src/views/PaymentElement.d.ts.map +1 -0
- package/package.json +184 -0
- package/src/context/Elements.ts +80 -0
- package/src/context/HyperElements.tsx +81 -0
- package/src/context/PaymentSession.ts +121 -0
- package/src/context/SavedPaymentMethods.ts +80 -0
- package/src/context/WidgetRegistry.ts +74 -0
- package/src/context/hooks.ts +79 -0
- package/src/index.ts +53 -0
- package/src/modules/NativeHyperswitchSdk.ts +155 -0
- package/src/specs/ApplePayViewNativeComponent.ts +11 -0
- package/src/specs/NativeHyperHeadless.ts +22 -0
- package/src/specs/NativeHyperswitchModule.ts +51 -0
- package/src/specs/NativeHyperswitchSdkNative.ts +62 -0
- package/src/specs/NativePaymentElementModule.ts +25 -0
- package/src/specs/PaymentElementNativeComponent.ts +21 -0
- package/src/specs/utils.ts +15 -0
- package/src/types/NativeModuleTypes.ts +73 -0
- package/src/types/PaymentSheetConfiguration.ts +360 -0
- package/src/types/definitions.ts +109 -0
- package/src/types/elements/index.ts +33 -0
- package/src/types/paymentresult/index.ts +4 -0
- package/src/types/savedPaymentMethods/index.ts +74 -0
- package/src/utils/EventValidator.ts +39 -0
- package/src/utils/InitializationState.ts +28 -0
- package/src/utils/LaunchOptions.ts +41 -0
- package/src/utils/NewArchUtils.ts +18 -0
- package/src/utils/ReactNativeUtils.ts +13 -0
- package/src/views/CVCElement.tsx +122 -0
- package/src/views/NativePaymentWidget.ts +2 -0
- package/src/views/NativePaymentWidgetImpl.ts +16 -0
- package/src/views/PaymentElement.tsx +189 -0
- package/tsconfig.build.json +21 -0
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
package io.hyperswitch.paymentsession
|
|
2
|
+
|
|
3
|
+
import android.annotation.SuppressLint
|
|
4
|
+
import android.app.Activity
|
|
5
|
+
import android.content.Intent
|
|
6
|
+
import android.os.Bundle
|
|
7
|
+
import android.util.Log
|
|
8
|
+
import androidx.activity.addCallback
|
|
9
|
+
import androidx.fragment.app.FragmentActivity
|
|
10
|
+
import com.facebook.react.ReactHost
|
|
11
|
+
import com.facebook.react.ReactInstanceEventListener
|
|
12
|
+
import com.facebook.react.ReactNativeHost
|
|
13
|
+
import com.facebook.react.bridge.Arguments
|
|
14
|
+
import com.facebook.react.bridge.ReactContext
|
|
15
|
+
import com.facebook.react.bridge.UiThreadUtil
|
|
16
|
+
import com.facebook.react.common.assets.ReactFontManager
|
|
17
|
+
import com.facebook.react.jstasks.HeadlessJsTaskConfig
|
|
18
|
+
import com.facebook.react.jstasks.HeadlessJsTaskContext
|
|
19
|
+
import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler
|
|
20
|
+
import com.facebook.react.uimanager.PixelUtil
|
|
21
|
+
import com.hyperswitchsdkreactnative.BuildConfig
|
|
22
|
+
import io.hyperswitch.react.HyperActivity
|
|
23
|
+
import io.hyperswitch.react.HyperEventEmitter
|
|
24
|
+
import io.hyperswitch.react.HyperFragment
|
|
25
|
+
import io.hyperswitch.react.ReactNativeController
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* React Native backed engine for presenting the payment sheet and running headless tasks.
|
|
29
|
+
*
|
|
30
|
+
* This class is intentionally independent of [hyperswitch-sdk-android-api]; callers are expected
|
|
31
|
+
* to pass all configuration data as plain [Bundle]s or [Map]s.
|
|
32
|
+
*/
|
|
33
|
+
class PaymentSessionReactLauncher(
|
|
34
|
+
private val activity: Activity,
|
|
35
|
+
) {
|
|
36
|
+
|
|
37
|
+
private var reactHost: ReactHost? = null
|
|
38
|
+
private var reactNativeHost: ReactNativeHost? = null
|
|
39
|
+
private var reactContext: ReactContext? = null
|
|
40
|
+
private var headlessTaskId: Int? = null
|
|
41
|
+
|
|
42
|
+
@SuppressLint("VisibleForTests")
|
|
43
|
+
fun initializeReactNativeInstance() {
|
|
44
|
+
reactContext = try {
|
|
45
|
+
// Get ReactNativeHost from ReactNativeController singleton instead of casting Application to ReactApplication
|
|
46
|
+
// This allows merchants to use their own Application class without extending MainApplication
|
|
47
|
+
if (!ReactNativeController.getIsInitialized()) {
|
|
48
|
+
ReactNativeController.initialize(activity.application)
|
|
49
|
+
}
|
|
50
|
+
reactNativeHost = ReactNativeController.getReactNativeHost()
|
|
51
|
+
reactHost = ReactNativeController.getReactHost()
|
|
52
|
+
|
|
53
|
+
if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
|
|
54
|
+
val reactHost = checkNotNull(reactHost) { "ReactHost is not initialized in New Architecture" }
|
|
55
|
+
reactHost.currentReactContext
|
|
56
|
+
} else {
|
|
57
|
+
val reactInstanceManager = reactNativeHost?.reactInstanceManager
|
|
58
|
+
reactInstanceManager?.currentReactContext
|
|
59
|
+
}
|
|
60
|
+
} catch (ex: IllegalStateException) {
|
|
61
|
+
throw IllegalStateException(
|
|
62
|
+
"HyperSDK not initialized. Please call HyperSDK.initialize() in your Application.onCreate()",
|
|
63
|
+
ex
|
|
64
|
+
)
|
|
65
|
+
} catch (ex: RuntimeException) {
|
|
66
|
+
throw IllegalStateException(
|
|
67
|
+
"Failed to initialize React Native instance. " + "Please check your AndroidManifest.xml and React Native configuration.",
|
|
68
|
+
ex
|
|
69
|
+
)
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Recreates the React context (if needed) and starts a headless JS task with the supplied
|
|
75
|
+
* [bundle]. The caller is responsible for assembling the bundle (e.g. via [LaunchOptions]).
|
|
76
|
+
*/
|
|
77
|
+
fun recreateReactContext(bundle: Bundle) {
|
|
78
|
+
activity.runOnUiThread {
|
|
79
|
+
val context = reactContext
|
|
80
|
+
if (context == null) {
|
|
81
|
+
if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
|
|
82
|
+
val reactHost = checkNotNull(reactHost)
|
|
83
|
+
reactHost.addReactInstanceEventListener(
|
|
84
|
+
object : ReactInstanceEventListener {
|
|
85
|
+
override fun onReactContextInitialized(context: ReactContext) {
|
|
86
|
+
startHeadlessTask(context, bundle)
|
|
87
|
+
reactHost.removeReactInstanceEventListener(this)
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
)
|
|
91
|
+
reactHost.start()
|
|
92
|
+
} else {
|
|
93
|
+
val reactInstanceManager = reactNativeHost?.reactInstanceManager
|
|
94
|
+
reactInstanceManager?.addReactInstanceEventListener(
|
|
95
|
+
object : ReactInstanceEventListener {
|
|
96
|
+
override fun onReactContextInitialized(context: ReactContext) {
|
|
97
|
+
startHeadlessTask(context, bundle)
|
|
98
|
+
reactInstanceManager.removeReactInstanceEventListener(this)
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
)
|
|
102
|
+
reactInstanceManager?.createReactContextInBackground()
|
|
103
|
+
}
|
|
104
|
+
} else {
|
|
105
|
+
startHeadlessTask(context, bundle)
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
private fun startHeadlessTask(reactContext: ReactContext, bundle: Bundle) {
|
|
111
|
+
val taskConfig = HeadlessJsTaskConfig(
|
|
112
|
+
"HyperHeadless", Arguments.fromBundle(bundle), 5000, true, null
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
val headlessJsTaskContext = HeadlessJsTaskContext.getInstance(reactContext)
|
|
116
|
+
UiThreadUtil.runOnUiThread {
|
|
117
|
+
headlessTaskId?.let {
|
|
118
|
+
headlessJsTaskContext.finishTask(it)
|
|
119
|
+
}
|
|
120
|
+
headlessTaskId = headlessJsTaskContext.startTask(taskConfig)
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Presents the payment sheet using a fully prepared launch [bundle].
|
|
126
|
+
*
|
|
127
|
+
* The bundle is expected to contain a `props` bundle with `configuration`, `sdkParams`, etc.
|
|
128
|
+
*/
|
|
129
|
+
fun presentSheet(bundle: Bundle): Boolean {
|
|
130
|
+
applyFonts(bundle)
|
|
131
|
+
return presentSheetInternal(bottomInsetToDIPFromPixel(bundle))
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
private fun presentSheetInternal(bundle: Bundle): Boolean {
|
|
135
|
+
if (activity is DefaultHardwareBackBtnHandler && activity is FragmentActivity) {
|
|
136
|
+
val fragmentActivity = activity as FragmentActivity
|
|
137
|
+
val fragmentManager = fragmentActivity.supportFragmentManager
|
|
138
|
+
try {
|
|
139
|
+
fragmentManager.findFragmentByTag("paymentSheet")?.let { existingFragment ->
|
|
140
|
+
fragmentManager.beginTransaction()
|
|
141
|
+
.remove(existingFragment)
|
|
142
|
+
.commitNowAllowingStateLoss()
|
|
143
|
+
}
|
|
144
|
+
}catch(e:Exception){
|
|
145
|
+
Log.i("Manideep", e.message.toString())
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
val newReactNativeFragmentSheet =
|
|
149
|
+
HyperFragment.Builder()
|
|
150
|
+
.setComponentName("hyperSwitch")
|
|
151
|
+
.setLaunchOptions(bundle)
|
|
152
|
+
.setFabricEnabled(BuildConfig.IS_NEW_ARCHITECTURE_ENABLED)
|
|
153
|
+
.build()
|
|
154
|
+
|
|
155
|
+
fragmentActivity.onBackPressedDispatcher.addCallback {
|
|
156
|
+
newReactNativeFragmentSheet.onBackPressed()
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
fragmentManager.beginTransaction()
|
|
160
|
+
.add(android.R.id.content, newReactNativeFragmentSheet, "paymentSheet")
|
|
161
|
+
.commitAllowingStateLoss()
|
|
162
|
+
|
|
163
|
+
return true
|
|
164
|
+
} else {
|
|
165
|
+
activity.startActivity(
|
|
166
|
+
Intent(
|
|
167
|
+
activity.applicationContext,
|
|
168
|
+
HyperActivity::class.java
|
|
169
|
+
).apply {
|
|
170
|
+
putExtra("flow", 1)
|
|
171
|
+
putExtra("configuration", bundle)
|
|
172
|
+
})
|
|
173
|
+
return false
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Loads any custom fonts declared in the configuration bundle and rewrites the font entries
|
|
179
|
+
* so React Native can resolve them by family name.
|
|
180
|
+
*/
|
|
181
|
+
private fun applyFonts(bundle: Bundle) {
|
|
182
|
+
val configuration = bundle.getBundle("props")?.getBundle("configuration") ?: return
|
|
183
|
+
val appearance = configuration.getBundle("appearance") ?: return
|
|
184
|
+
|
|
185
|
+
appearance.getBundle("font")?.let { font ->
|
|
186
|
+
loadFontAndUpdateBundle(font)
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
appearance.getBundle("primaryButton")?.getBundle("typography")?.let { typography ->
|
|
190
|
+
loadFontAndUpdateBundle(typography)
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
private fun loadFontAndUpdateBundle(fontBundle: Bundle) {
|
|
195
|
+
if (!fontBundle.containsKey("fontResId")) return
|
|
196
|
+
val fontResId = fontBundle.getInt("fontResId", 0)
|
|
197
|
+
if (fontResId == 0) return
|
|
198
|
+
|
|
199
|
+
try {
|
|
200
|
+
val family = activity.resources.getResourceName(fontResId).split("/")[1]
|
|
201
|
+
ReactFontManager.getInstance().addCustomFont(activity, family, fontResId)
|
|
202
|
+
fontBundle.remove("fontResId")
|
|
203
|
+
fontBundle.putString("family", family)
|
|
204
|
+
} catch (_: Exception) {
|
|
205
|
+
// Ignore invalid font resources.
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
private fun bottomInsetToDIPFromPixel(bundle: Bundle): Bundle {
|
|
210
|
+
val propsBundle = bundle.getBundle("props")
|
|
211
|
+
val sdkParamsBundle = propsBundle?.getBundle("sdkParams")
|
|
212
|
+
sdkParamsBundle?.getFloat("topInset")?.let { dipValue ->
|
|
213
|
+
sdkParamsBundle.putFloat("topInset", PixelUtil.toDIPFromPixel(dipValue))
|
|
214
|
+
}
|
|
215
|
+
sdkParamsBundle?.getFloat("leftInset")?.let { dipValue ->
|
|
216
|
+
sdkParamsBundle.putFloat("leftInset", PixelUtil.toDIPFromPixel(dipValue))
|
|
217
|
+
}
|
|
218
|
+
sdkParamsBundle?.getFloat("rightInset")?.let { dipValue ->
|
|
219
|
+
sdkParamsBundle.putFloat("rightInset", PixelUtil.toDIPFromPixel(dipValue))
|
|
220
|
+
}
|
|
221
|
+
sdkParamsBundle?.getFloat("bottomInset")?.let { dipValue ->
|
|
222
|
+
sdkParamsBundle.putFloat("bottomInset", PixelUtil.toDIPFromPixel(dipValue))
|
|
223
|
+
}
|
|
224
|
+
return bundle
|
|
225
|
+
}
|
|
226
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
package io.hyperswitch.paymentsession
|
|
2
|
+
|
|
3
|
+
import org.json.JSONObject
|
|
4
|
+
import java.util.concurrent.atomic.AtomicReference
|
|
5
|
+
|
|
6
|
+
typealias Callback = (String) -> Unit
|
|
7
|
+
|
|
8
|
+
object PaymentSheetCallbackManager {
|
|
9
|
+
private val callback = AtomicReference<Callback?>(null)
|
|
10
|
+
private var isFragment: Boolean = true
|
|
11
|
+
|
|
12
|
+
fun setCallback(newCallback: Callback, newIsFragment: Boolean = true) {
|
|
13
|
+
callback.set(newCallback)
|
|
14
|
+
isFragment = newIsFragment
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
fun getCallback(): Callback? {
|
|
18
|
+
return callback.get()
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
fun executeCallback(data: String): Boolean {
|
|
22
|
+
// val jsonObject = JSONObject(data)
|
|
23
|
+
// val result = when (val status = jsonObject.getString("status")) {
|
|
24
|
+
// "cancelled" -> PaymentResult.Canceled(status)
|
|
25
|
+
// "failed", "requires_payment_method" -> {
|
|
26
|
+
// val message = jsonObject.getString("message")
|
|
27
|
+
// val throwable = Throwable(message.ifEmpty { status })
|
|
28
|
+
// throwable.initCause(Throwable(jsonObject.getString("code")))
|
|
29
|
+
// PaymentResult.Failed(throwable)
|
|
30
|
+
// }
|
|
31
|
+
//
|
|
32
|
+
// else -> PaymentResult.Completed(status)
|
|
33
|
+
// }
|
|
34
|
+
|
|
35
|
+
// Atomically get and clear callback to prevent double-invocation
|
|
36
|
+
val currentCallback = callback.getAndSet(null)
|
|
37
|
+
currentCallback?.invoke(data) ?: println("No callback set")
|
|
38
|
+
return isFragment
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
package io.hyperswitch.paymentsheet
|
|
2
|
+
|
|
3
|
+
import android.content.Intent
|
|
4
|
+
import android.os.Bundle
|
|
5
|
+
import android.os.Parcelable
|
|
6
|
+
import kotlinx.parcelize.Parcelize
|
|
7
|
+
import org.json.JSONObject
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Result to be passed to the callback of [PaymentLauncher]
|
|
11
|
+
*/
|
|
12
|
+
sealed class PaymentResult : Parcelable {
|
|
13
|
+
@Parcelize
|
|
14
|
+
class Completed(val data: String) : PaymentResult()
|
|
15
|
+
|
|
16
|
+
@Parcelize
|
|
17
|
+
class Failed(val throwable: Throwable) : PaymentResult()
|
|
18
|
+
|
|
19
|
+
@Parcelize
|
|
20
|
+
class Canceled(val data: String) : PaymentResult()
|
|
21
|
+
|
|
22
|
+
@JvmSynthetic
|
|
23
|
+
fun toBundle() = Bundle().apply {
|
|
24
|
+
putParcelable(EXTRA, this@PaymentResult)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
@JvmSynthetic
|
|
28
|
+
fun toJSONString(): String {
|
|
29
|
+
return when (this) {
|
|
30
|
+
is Completed -> {
|
|
31
|
+
JSONObject()
|
|
32
|
+
.put("status", "completed")
|
|
33
|
+
.put("data", data)
|
|
34
|
+
.toString()
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
is Canceled -> {
|
|
38
|
+
JSONObject()
|
|
39
|
+
.put("status", "canceled")
|
|
40
|
+
.put("data", data)
|
|
41
|
+
.toString()
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
is Failed -> {
|
|
45
|
+
JSONObject()
|
|
46
|
+
.put("status", "failed")
|
|
47
|
+
.put("error", throwable.message)
|
|
48
|
+
.put("type", throwable::class.java.name)
|
|
49
|
+
.toString()
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
internal companion object {
|
|
55
|
+
private const val EXTRA = "extra_args"
|
|
56
|
+
|
|
57
|
+
@JvmSynthetic
|
|
58
|
+
fun fromIntent(intent: Intent?): PaymentResult {
|
|
59
|
+
return intent?.getParcelableExtra(EXTRA)
|
|
60
|
+
?: Failed(IllegalStateException("Failed to get PaymentResult from Intent"))
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
package io.hyperswitch.react
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.uimanager.SimpleViewManager
|
|
4
|
+
import com.facebook.react.uimanager.ThemedReactContext
|
|
5
|
+
import com.facebook.react.uimanager.annotations.ReactProp
|
|
6
|
+
import com.google.android.gms.wallet.button.ButtonConstants
|
|
7
|
+
import io.hyperswitch.view.GooglePayButtonView
|
|
8
|
+
|
|
9
|
+
class GooglePayButtonManager : SimpleViewManager<GooglePayButtonView>() {
|
|
10
|
+
override fun getName() = REACT_CLASS
|
|
11
|
+
|
|
12
|
+
override fun createViewInstance(context: ThemedReactContext) = GooglePayButtonView(context)
|
|
13
|
+
|
|
14
|
+
override fun onAfterUpdateTransaction(view: GooglePayButtonView) {
|
|
15
|
+
super.onAfterUpdateTransaction(view)
|
|
16
|
+
view.addButton()
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
@ReactProp(name = "allowedPaymentMethods")
|
|
20
|
+
fun allowedPaymentMethods(view: GooglePayButtonView, allowedPaymentMethods: String) {
|
|
21
|
+
view.allowedPaymentMethods = allowedPaymentMethods
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
@ReactProp(name = "buttonType")
|
|
25
|
+
fun buttonType(view: GooglePayButtonView, type: String?) {
|
|
26
|
+
view.type = when (type) {
|
|
27
|
+
"BUY" -> ButtonConstants.ButtonType.BUY
|
|
28
|
+
"BOOK" -> ButtonConstants.ButtonType.BOOK
|
|
29
|
+
"CHECKOUT" -> ButtonConstants.ButtonType.CHECKOUT
|
|
30
|
+
"DONATE" -> ButtonConstants.ButtonType.DONATE
|
|
31
|
+
"ORDER" -> ButtonConstants.ButtonType.ORDER
|
|
32
|
+
"PAY" -> ButtonConstants.ButtonType.PAY
|
|
33
|
+
"SUBSCRIBE" -> ButtonConstants.ButtonType.SUBSCRIBE
|
|
34
|
+
else -> ButtonConstants.ButtonType.PLAIN
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
@ReactProp(name = "buttonStyle")
|
|
39
|
+
fun buttonStyle(view: GooglePayButtonView, theme: String?) {
|
|
40
|
+
view.theme = when (theme) {
|
|
41
|
+
"light" -> ButtonConstants.ButtonTheme.LIGHT
|
|
42
|
+
else -> ButtonConstants.ButtonTheme.DARK
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
@ReactProp(name = "borderRadius")
|
|
47
|
+
fun borderRadius(view: GooglePayButtonView, radius: Int) {
|
|
48
|
+
view.cornerRadius = radius
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
companion object {
|
|
52
|
+
const val REACT_CLASS = "GooglePayButton"
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
package io.hyperswitch.react
|
|
2
|
+
|
|
3
|
+
import android.os.Bundle
|
|
4
|
+
import com.facebook.react.ReactActivity
|
|
5
|
+
import com.facebook.react.ReactActivityDelegate
|
|
6
|
+
import com.facebook.react.ReactNativeHost
|
|
7
|
+
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.fabricEnabled
|
|
8
|
+
import com.facebook.react.defaults.DefaultReactActivityDelegate
|
|
9
|
+
import com.proyecto26.inappbrowser.ChromeTabsDismissedEvent
|
|
10
|
+
import com.proyecto26.inappbrowser.ChromeTabsManagerActivity
|
|
11
|
+
import io.hyperswitch.redirect.RedirectEvent
|
|
12
|
+
import org.greenrobot.eventbus.EventBus
|
|
13
|
+
import org.greenrobot.eventbus.Subscribe
|
|
14
|
+
|
|
15
|
+
class HyperActivity : ReactActivity() {
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Returns the name of the main component registered from JavaScript. This is used to schedule
|
|
19
|
+
* rendering of the component.
|
|
20
|
+
*/
|
|
21
|
+
override fun getMainComponentName(): String = "hyperSwitch"
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Returns the instance of the [ReactActivityDelegate]. We use [DefaultReactActivityDelegate]
|
|
25
|
+
* which allows you to enable New Architecture with a single boolean flags [fabricEnabled]
|
|
26
|
+
*/
|
|
27
|
+
override fun createReactActivityDelegate(): ReactActivityDelegate {
|
|
28
|
+
return object : DefaultReactActivityDelegate(this, mainComponentName, fabricEnabled) {
|
|
29
|
+
override fun getLaunchOptions(): Bundle =
|
|
30
|
+
intent.getBundleExtra("configuration") ?: Bundle()
|
|
31
|
+
|
|
32
|
+
override fun getReactNativeHost(): ReactNativeHost {
|
|
33
|
+
return ReactNativeController.getReactNativeHost()
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
@Subscribe
|
|
39
|
+
fun onEvent(event: RedirectEvent) {
|
|
40
|
+
unRegisterEventBus()
|
|
41
|
+
EventBus.getDefault().post(
|
|
42
|
+
ChromeTabsDismissedEvent(
|
|
43
|
+
event.message,
|
|
44
|
+
event.resultType,
|
|
45
|
+
event.isError
|
|
46
|
+
)
|
|
47
|
+
)
|
|
48
|
+
startActivity(ChromeTabsManagerActivity.createDismissIntent(applicationContext))
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
override fun onCreate(savedInstanceState: Bundle?) {
|
|
52
|
+
super.onCreate(savedInstanceState)
|
|
53
|
+
registerEventBus()
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
override fun onDestroy() {
|
|
57
|
+
super.onDestroy()
|
|
58
|
+
unRegisterEventBus()
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
private fun registerEventBus() {
|
|
62
|
+
if (!EventBus.getDefault().isRegistered(this)) {
|
|
63
|
+
EventBus.getDefault().register(this)
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
private fun unRegisterEventBus() {
|
|
68
|
+
if (EventBus.getDefault().isRegistered(this)) {
|
|
69
|
+
EventBus.getDefault().unregister(this)
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
package io.hyperswitch.react
|
|
2
|
+
|
|
3
|
+
import android.os.Handler
|
|
4
|
+
import android.os.Looper
|
|
5
|
+
import com.facebook.react.bridge.Arguments
|
|
6
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
7
|
+
import com.facebook.react.modules.core.DeviceEventManagerModule
|
|
8
|
+
//import io.hyperswitch.PaymentEvent
|
|
9
|
+
//import io.hyperswitch.PaymentEventListener
|
|
10
|
+
//import io.hyperswitch.PaymentEventSubscription
|
|
11
|
+
import java.util.concurrent.ConcurrentLinkedQueue
|
|
12
|
+
|
|
13
|
+
object HyperEventEmitter {
|
|
14
|
+
private var reactContext: ReactApplicationContext? = null
|
|
15
|
+
private val pendingEvents = ConcurrentLinkedQueue<Pair<String, Map<String, String?>>>()
|
|
16
|
+
// @Volatile private var eventListener: PaymentEventListener? = null
|
|
17
|
+
// @Volatile private var subscriptionEvents: PaymentEventSubscription? = null
|
|
18
|
+
private val mainHandler = Handler(Looper.getMainLooper())
|
|
19
|
+
|
|
20
|
+
fun initialize(context: ReactApplicationContext) {
|
|
21
|
+
reactContext = context
|
|
22
|
+
processPendingEvents()
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
fun deinitialize() {
|
|
26
|
+
reactContext = null
|
|
27
|
+
// eventListener = null
|
|
28
|
+
// subscriptionEvents = null
|
|
29
|
+
mainHandler.removeCallbacksAndMessages(null)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Set the payment event listener for merchant callbacks
|
|
34
|
+
* @param listener The listener to receive payment events
|
|
35
|
+
* @param subscription The event subscription configuration
|
|
36
|
+
*/
|
|
37
|
+
// fun setEventListener(listener: PaymentEventListener?, subscription: PaymentEventSubscription? = null) {
|
|
38
|
+
// eventListener = listener
|
|
39
|
+
// subscriptionEvents = subscription
|
|
40
|
+
// }
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Emit a payment event to merchant listener (if subscribed)
|
|
44
|
+
* @param eventType The type of event (e.g., "payment_method.info.card")
|
|
45
|
+
* @param payload The event payload data
|
|
46
|
+
*/
|
|
47
|
+
fun emitPaymentEvent(
|
|
48
|
+
eventType: String,
|
|
49
|
+
payload: Map<String, Any>
|
|
50
|
+
) {
|
|
51
|
+
// val shouldEmit = isSubscribed(eventType)
|
|
52
|
+
|
|
53
|
+
// if (shouldEmit && eventListener != null) {
|
|
54
|
+
// val event = PaymentEvent(
|
|
55
|
+
// type = eventType,
|
|
56
|
+
// payload = payload
|
|
57
|
+
// )
|
|
58
|
+
//
|
|
59
|
+
// mainHandler.post {
|
|
60
|
+
// eventListener?.onPaymentEvent(event)
|
|
61
|
+
// }
|
|
62
|
+
// }
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// fun isSubscribed(eventType: String): Boolean {
|
|
66
|
+
// val subscription = subscriptionEvents ?: return false
|
|
67
|
+
// return subscription.isSubscribed(eventType)
|
|
68
|
+
// }
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Get the list of subscribed event types
|
|
72
|
+
* Called by React Native to initialize subscription state
|
|
73
|
+
* @return List of subscribed event type strings
|
|
74
|
+
*/
|
|
75
|
+
fun getSubscribedEvents(): List<String> {
|
|
76
|
+
// val subscription = subscriptionEvents ?:
|
|
77
|
+
return emptyList()
|
|
78
|
+
// return subscription.getSubscribedEventStrings()
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
fun confirmStatic(tag: String, map: MutableMap<String, String?>) {
|
|
82
|
+
val writableMap = Arguments.createMap()
|
|
83
|
+
for ((key, value) in map) {
|
|
84
|
+
when (value) {
|
|
85
|
+
"true" -> {
|
|
86
|
+
writableMap.putBoolean(key, true)
|
|
87
|
+
}
|
|
88
|
+
"false" -> {
|
|
89
|
+
writableMap.putBoolean(key, false)
|
|
90
|
+
}
|
|
91
|
+
else -> {
|
|
92
|
+
writableMap.putString(key, value)
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (reactContext != null && reactContext!!.hasCatalystInstance()) {
|
|
98
|
+
try {
|
|
99
|
+
reactContext!!.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
|
|
100
|
+
?.emit(tag, writableMap)
|
|
101
|
+
} catch (e: Exception) {
|
|
102
|
+
pendingEvents.add(Pair(tag, map))
|
|
103
|
+
}
|
|
104
|
+
} else {
|
|
105
|
+
pendingEvents.add(Pair(tag, map))
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
fun confirmCardStatic(map: MutableMap<String, String?>) {
|
|
110
|
+
confirmStatic("confirm", map)
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
fun confirmECStatic(map: MutableMap<String, String?>) {
|
|
114
|
+
confirmStatic("confirmEC", map)
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
private fun processPendingEvents() {
|
|
118
|
+
if (reactContext?.hasCatalystInstance() != true || reactContext?.catalystInstance?.isDestroyed == true) {
|
|
119
|
+
return
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
val iterator = pendingEvents.iterator()
|
|
123
|
+
while (iterator.hasNext()) {
|
|
124
|
+
val (tag, map) = iterator.next()
|
|
125
|
+
val writableMap = Arguments.createMap()
|
|
126
|
+
for ((key, value) in map) {
|
|
127
|
+
when (value) {
|
|
128
|
+
"true" -> {
|
|
129
|
+
writableMap.putBoolean(key, true)
|
|
130
|
+
}
|
|
131
|
+
"false" -> {
|
|
132
|
+
writableMap.putBoolean(key, false)
|
|
133
|
+
}
|
|
134
|
+
else -> {
|
|
135
|
+
writableMap.putString(key, value)
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
reactContext!!.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
|
|
140
|
+
?.emit(tag, writableMap)
|
|
141
|
+
iterator.remove()
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|