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
package/android/src/main/java/com/hyperswitchsdkreactnative/views/PaymentElementViewManager.kt
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
package com.hyperswitchsdkreactnative.views
|
|
2
|
+
|
|
3
|
+
import android.app.Activity
|
|
4
|
+
import com.facebook.react.bridge.Dynamic
|
|
5
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
6
|
+
import com.facebook.react.uimanager.SimpleViewManager
|
|
7
|
+
import com.facebook.react.uimanager.ThemedReactContext
|
|
8
|
+
import com.facebook.react.uimanager.ViewManagerDelegate
|
|
9
|
+
import com.facebook.react.uimanager.annotations.ReactProp
|
|
10
|
+
import com.facebook.react.viewmanagers.NativePaymentElementManagerDelegate
|
|
11
|
+
import com.facebook.react.viewmanagers.NativePaymentElementManagerInterface
|
|
12
|
+
import io.hyperswitch.view.PaymentWidgetView
|
|
13
|
+
|
|
14
|
+
class PaymentElementViewManager : SimpleViewManager<PaymentWidgetView>(),
|
|
15
|
+
NativePaymentElementManagerInterface<PaymentWidgetView> {
|
|
16
|
+
|
|
17
|
+
private val mDelegate: ViewManagerDelegate<PaymentWidgetView> =
|
|
18
|
+
NativePaymentElementManagerDelegate(this)
|
|
19
|
+
|
|
20
|
+
override fun getName(): String = NAME
|
|
21
|
+
|
|
22
|
+
override fun getDelegate(): ViewManagerDelegate<PaymentWidgetView> {
|
|
23
|
+
return mDelegate
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
private var context: ReactApplicationContext? = null
|
|
27
|
+
|
|
28
|
+
override fun createViewInstance(reactContext: ThemedReactContext): PaymentWidgetView {
|
|
29
|
+
context = reactContext.reactApplicationContext
|
|
30
|
+
return NativeWidgetContainer(context?.currentActivity)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
override fun onAfterUpdateTransaction(container: PaymentWidgetView) {
|
|
34
|
+
super.onAfterUpdateTransaction(container)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@ReactProp(name = "widgetType")
|
|
38
|
+
override fun setWidgetType(container: PaymentWidgetView, widgetType: String?) {
|
|
39
|
+
container.setWidgetType(widgetType)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
@ReactProp(name = "sdkAuthorization")
|
|
43
|
+
override fun setSdkAuthorization(container: PaymentWidgetView, sdkAuthorization: String?) {
|
|
44
|
+
sdkAuthorization?.let {
|
|
45
|
+
container.setSdkAuthorization(sdkAuthorization)
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
@ReactProp(name = "options")
|
|
50
|
+
override fun setOptions(container: PaymentWidgetView, options: Dynamic?) {
|
|
51
|
+
options?.let {
|
|
52
|
+
container.setConfiguration(it.asMap())
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
// @Suppress("UNCHECKED_CAST")
|
|
58
|
+
// private fun emitOnPaymentEvent(container: PaymentWidgetView, event: PaymentEvent) {
|
|
59
|
+
// val payloadMap = Arguments.makeNativeMap(event.payload as Map<String, Object>)
|
|
60
|
+
// val eventData = Arguments.createMap().apply {
|
|
61
|
+
// putString("eventName", event.type)
|
|
62
|
+
// putMap("payload", payloadMap)
|
|
63
|
+
// }
|
|
64
|
+
// context?.runOnUiQueueThread {
|
|
65
|
+
// context?.getJSModule(RCTEventEmitter::class.java)
|
|
66
|
+
// ?.receiveEvent(container.id, "topOnPaymentEvent", eventData)
|
|
67
|
+
// }
|
|
68
|
+
// }
|
|
69
|
+
|
|
70
|
+
override fun getExportedCustomDirectEventTypeConstants(): MutableMap<String, Any>? {
|
|
71
|
+
return com.facebook.react.common.MapBuilder.of(
|
|
72
|
+
"onPaymentEvent",
|
|
73
|
+
com.facebook.react.common.MapBuilder.of("registrationName", "onPaymentEvent")
|
|
74
|
+
)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
private class NativeWidgetContainer(activity: Activity?) : PaymentWidgetView(activity!!) {
|
|
78
|
+
override fun requestLayout() {
|
|
79
|
+
super.requestLayout()
|
|
80
|
+
post(measureAndLayout)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
private val measureAndLayout = Runnable {
|
|
84
|
+
measure(
|
|
85
|
+
MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY),
|
|
86
|
+
MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY)
|
|
87
|
+
)
|
|
88
|
+
layout(left, top, right, bottom)
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
companion object {
|
|
93
|
+
const val NAME = "RCTNativePaymentElement"
|
|
94
|
+
private const val CVC_WIDGET = "cvcWidget"
|
|
95
|
+
private const val PAYMENT_ELEMENT = "paymentElement"
|
|
96
|
+
private const val WIDGET_PAYMENT_SHEET = "widgetPaymentSheet"
|
|
97
|
+
private const val PAYMENT_ELEMENT_TYPE = "payment"
|
|
98
|
+
}
|
|
99
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
package io.hyperswitch
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.HyperPackageList
|
|
4
|
+
import com.facebook.react.ReactNativeHost
|
|
5
|
+
import com.facebook.react.ReactPackage
|
|
6
|
+
import io.hyperswitch.react.HyperPackage
|
|
7
|
+
//import io.hyperswitch.react.HyperReactPackageProvider
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Host-side implementation of [io.hyperswitch.react.HyperReactPackageProvider].
|
|
11
|
+
*
|
|
12
|
+
* This class lives in :app so it can reference the autolinked [PackageList]
|
|
13
|
+
* generated by the React Native Gradle plugin.
|
|
14
|
+
*/
|
|
15
|
+
//class HyperswitchReactPackageProvider : HyperReactPackageProvider() {
|
|
16
|
+
// override fun getPackages(host: ReactNativeHost): List<ReactPackage> {
|
|
17
|
+
// return HyperPackageList(host).packages
|
|
18
|
+
// }
|
|
19
|
+
//}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
package io.hyperswitch
|
|
2
|
+
|
|
3
|
+
import io.hyperswitch.utils.ConversionUtils
|
|
4
|
+
import org.json.JSONObject
|
|
5
|
+
|
|
6
|
+
interface PaymentEventListener {
|
|
7
|
+
fun onPaymentEvent(event: PaymentEvent)
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
data class PaymentEvent(
|
|
11
|
+
val type: String,
|
|
12
|
+
val payload: Map<String, Any>,
|
|
13
|
+
) {
|
|
14
|
+
val data = JSONObject().apply {
|
|
15
|
+
put("type", type)
|
|
16
|
+
put("payload", ConversionUtils.convertMapToJson(payload))
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
package io.hyperswitch.model
|
|
2
|
+
|
|
3
|
+
import io.hyperswitch.utils.StandardResult
|
|
4
|
+
|
|
5
|
+
//sealed class ElementsUpdateResult {
|
|
6
|
+
//
|
|
7
|
+
// /** All elements updated successfully. */
|
|
8
|
+
// object Success : ElementsUpdateResult()
|
|
9
|
+
//
|
|
10
|
+
// /**
|
|
11
|
+
// * Session token fetch failed before any element was updated.
|
|
12
|
+
// * No element was touched — safe to retry the entire call.
|
|
13
|
+
// */
|
|
14
|
+
// data class TotalFailure(
|
|
15
|
+
// val cause: Throwable
|
|
16
|
+
// ) : ElementsUpdateResult()
|
|
17
|
+
//
|
|
18
|
+
// /**
|
|
19
|
+
// * Token fetch succeeded but one or more elements failed to update.
|
|
20
|
+
// * [succeeded] elements are live; [failed] elements can be selectively retried.
|
|
21
|
+
// */
|
|
22
|
+
// data class PartialFailure(
|
|
23
|
+
// val succeeded: List<HyperswitchBoundElement>,
|
|
24
|
+
// val failed: Map<HyperswitchBoundElement, Throwable>
|
|
25
|
+
// ) : ElementsUpdateResult() {
|
|
26
|
+
// val canRetry: Boolean get() = failed.isNotEmpty()
|
|
27
|
+
// }
|
|
28
|
+
//}
|
|
29
|
+
|
|
30
|
+
sealed class ElementUpdateIntentResult {
|
|
31
|
+
object Success : ElementUpdateIntentResult()
|
|
32
|
+
object Cancelled : ElementUpdateIntentResult()
|
|
33
|
+
data class Failure(val cause: Throwable) : ElementUpdateIntentResult()
|
|
34
|
+
|
|
35
|
+
fun ElementUpdateIntentResult.toStandardResult(): StandardResult {
|
|
36
|
+
return when (this) {
|
|
37
|
+
ElementUpdateIntentResult.Success -> {
|
|
38
|
+
StandardResult.Success(
|
|
39
|
+
message = "Element update intent completed successfully"
|
|
40
|
+
)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
ElementUpdateIntentResult.Cancelled -> {
|
|
44
|
+
StandardResult.Cancelled(
|
|
45
|
+
message = "Element update intent was cancelled"
|
|
46
|
+
)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
is ElementUpdateIntentResult.Failure -> {
|
|
50
|
+
StandardResult.Failed(
|
|
51
|
+
code = "element_update_failed",
|
|
52
|
+
message = cause.message ?: "Element update intent failed",
|
|
53
|
+
error = cause
|
|
54
|
+
)
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
package io.hyperswitch.paymentsession
|
|
2
|
+
|
|
3
|
+
import io.hyperswitch.paymentsheet.PaymentResult
|
|
4
|
+
|
|
5
|
+
import org.json.JSONObject
|
|
6
|
+
import java.util.concurrent.ConcurrentHashMap
|
|
7
|
+
|
|
8
|
+
typealias ExitCallback = (PaymentResult) -> Unit
|
|
9
|
+
|
|
10
|
+
object ExitHeadlessCallBackManager {
|
|
11
|
+
private val callbacks = ConcurrentHashMap<Int, ExitCallback>()
|
|
12
|
+
|
|
13
|
+
fun tryRegisterCallback(rootTag: Int, callback: ExitCallback): Boolean {
|
|
14
|
+
return if (rootTag == -1) {
|
|
15
|
+
callbacks[-1] = callback
|
|
16
|
+
true
|
|
17
|
+
} else {
|
|
18
|
+
callbacks.putIfAbsent(rootTag, callback) == null
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
fun executeCallback(rootTag: Int, data: String): Boolean {
|
|
23
|
+
val cb = callbacks.remove(rootTag) ?: callbacks.remove(-1)
|
|
24
|
+
|
|
25
|
+
val result = parseResult(data)
|
|
26
|
+
cb?.invoke(result)
|
|
27
|
+
return true
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
fun clearCallback(rootTag: Int) {
|
|
31
|
+
callbacks.remove(rootTag)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
private fun parseResult(data: String): PaymentResult {
|
|
35
|
+
val message = JSONObject(data)
|
|
36
|
+
return when (val status = message.getString("status")) {
|
|
37
|
+
"cancelled" -> PaymentResult.Canceled(status)
|
|
38
|
+
"failed", "requires_payment_method" -> {
|
|
39
|
+
val throwable = Throwable(message.getString("message"))
|
|
40
|
+
throwable.initCause(Throwable(message.getString("code")))
|
|
41
|
+
PaymentResult.Failed(throwable)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
else -> PaymentResult.Completed(status ?: "default")
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
package/android/src/main/java/io/hyperswitch/paymentsession/GetPaymentSessionCallBackManager.kt
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
package io.hyperswitch.paymentsession
|
|
2
|
+
|
|
3
|
+
import java.util.concurrent.atomic.AtomicReference
|
|
4
|
+
|
|
5
|
+
typealias SessionCallback = (PaymentSessionHandler) -> Unit
|
|
6
|
+
|
|
7
|
+
object GetPaymentSessionCallBackManager {
|
|
8
|
+
private val callbackRef = AtomicReference<SessionCallback?>(null)
|
|
9
|
+
private val sdkAuthorizationRef = AtomicReference<String?>(null)
|
|
10
|
+
fun setCallback(sdkAuthorization: String?, newCallback: SessionCallback?) {
|
|
11
|
+
callbackRef.set(newCallback)
|
|
12
|
+
sdkAuthorizationRef.set(sdkAuthorization)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
fun getCallback(): SessionCallback? = callbackRef.get()
|
|
16
|
+
|
|
17
|
+
fun getSdkAuthorization(): String = sdkAuthorizationRef.get() ?: ""
|
|
18
|
+
|
|
19
|
+
fun executeCallback(data: PaymentSessionHandler) {
|
|
20
|
+
callbackRef.getAndSet(null)?.invoke(data)
|
|
21
|
+
?: println("No callback set")
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
package io.hyperswitch.paymentsession
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Sealed class representing different payment method types
|
|
5
|
+
*/
|
|
6
|
+
sealed class PaymentMethodType {
|
|
7
|
+
data object WALLET : PaymentMethodType()
|
|
8
|
+
data object CARD : PaymentMethodType()
|
|
9
|
+
data object CARD_REDIRECT : PaymentMethodType()
|
|
10
|
+
data object PAY_LATER : PaymentMethodType()
|
|
11
|
+
data object BANK_REDIRECT : PaymentMethodType()
|
|
12
|
+
data object OPEN_BANKING : PaymentMethodType()
|
|
13
|
+
data object BANK_DEBIT : PaymentMethodType()
|
|
14
|
+
data object BANK_TRANSFER : PaymentMethodType()
|
|
15
|
+
data object CRYPTO : PaymentMethodType()
|
|
16
|
+
data object REWARD : PaymentMethodType()
|
|
17
|
+
data object GIFT_CARD : PaymentMethodType()
|
|
18
|
+
data class OTHERS(val value: String) : PaymentMethodType()
|
|
19
|
+
|
|
20
|
+
companion object {
|
|
21
|
+
/**
|
|
22
|
+
* Converts a string value to the corresponding PaymentMethodType
|
|
23
|
+
* @param value The string representation of the payment method
|
|
24
|
+
* @return The corresponding PaymentMethodType, returns OTHERS(value) for unrecognized types
|
|
25
|
+
*/
|
|
26
|
+
fun fromString(value: String): PaymentMethodType {
|
|
27
|
+
return when (value.lowercase()) {
|
|
28
|
+
"wallet" -> WALLET
|
|
29
|
+
"card" -> CARD
|
|
30
|
+
"card_redirect" -> CARD_REDIRECT
|
|
31
|
+
"pay_later" -> PAY_LATER
|
|
32
|
+
"bank_redirect" -> BANK_REDIRECT
|
|
33
|
+
"open_banking" -> OPEN_BANKING
|
|
34
|
+
"bank_debit" -> BANK_DEBIT
|
|
35
|
+
"bank_transfer" -> BANK_TRANSFER
|
|
36
|
+
"crypto" -> CRYPTO
|
|
37
|
+
"reward" -> REWARD
|
|
38
|
+
"gift_card" -> GIFT_CARD
|
|
39
|
+
else -> OTHERS(value)
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Converts the PaymentMethodType to its string representation
|
|
46
|
+
* @return The string representation of the payment method type
|
|
47
|
+
*/
|
|
48
|
+
fun toStringValue(): String {
|
|
49
|
+
return when (this) {
|
|
50
|
+
is WALLET -> "wallet"
|
|
51
|
+
is CARD -> "card"
|
|
52
|
+
is CARD_REDIRECT -> "card_redirect"
|
|
53
|
+
is PAY_LATER -> "pay_later"
|
|
54
|
+
is BANK_REDIRECT -> "bank_redirect"
|
|
55
|
+
is OPEN_BANKING -> "open_banking"
|
|
56
|
+
is BANK_DEBIT -> "bank_debit"
|
|
57
|
+
is BANK_TRANSFER -> "bank_transfer"
|
|
58
|
+
is CRYPTO -> "crypto"
|
|
59
|
+
is REWARD -> "reward"
|
|
60
|
+
is GIFT_CARD -> "gift_card"
|
|
61
|
+
is OTHERS -> this.value
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Represents card payment method details
|
|
68
|
+
*/
|
|
69
|
+
data class Card(
|
|
70
|
+
val scheme: String,
|
|
71
|
+
val issuerCountry: String,
|
|
72
|
+
val last4Digits: String,
|
|
73
|
+
val expiryMonth: String,
|
|
74
|
+
val expiryYear: String,
|
|
75
|
+
val cardToken: String?,
|
|
76
|
+
val cardHolderName: String,
|
|
77
|
+
val cardFingerprint: String?,
|
|
78
|
+
val nickName: String,
|
|
79
|
+
val cardNetwork: String,
|
|
80
|
+
val cardIsin: String,
|
|
81
|
+
val cardIssuer: String,
|
|
82
|
+
val cardType: String,
|
|
83
|
+
val savedToLocker: Boolean,
|
|
84
|
+
) {
|
|
85
|
+
fun toMap(): HashMap<String, Any?> {
|
|
86
|
+
return HashMap<String, Any?>().apply {
|
|
87
|
+
this["scheme"] = scheme
|
|
88
|
+
this["issuer_country"] = issuerCountry
|
|
89
|
+
this["last4_digits"] = last4Digits
|
|
90
|
+
this["expiry_month"] = expiryMonth
|
|
91
|
+
this["expiry_year"] = expiryYear
|
|
92
|
+
this["card_token"] = cardToken
|
|
93
|
+
this["card_holder_name"] = cardHolderName
|
|
94
|
+
this["card_fingerprint"] = cardFingerprint
|
|
95
|
+
this["nick_name"] = nickName
|
|
96
|
+
this["card_network"] = cardNetwork
|
|
97
|
+
this["card_isin"] = cardIsin
|
|
98
|
+
this["card_issuer"] = cardIssuer
|
|
99
|
+
this["card_type"] = cardType
|
|
100
|
+
this["saved_to_locker"] = savedToLocker
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Represents a valid payment method with all details
|
|
107
|
+
*/
|
|
108
|
+
data class PaymentMethod(
|
|
109
|
+
val paymentToken: String,
|
|
110
|
+
val paymentMethodId: String,
|
|
111
|
+
val customerId: String,
|
|
112
|
+
val paymentMethod: PaymentMethodType,
|
|
113
|
+
val paymentMethodType: String,
|
|
114
|
+
val paymentMethodIssuer: String,
|
|
115
|
+
val paymentMethodIssuerCode: String?,
|
|
116
|
+
val recurringEnabled: Boolean,
|
|
117
|
+
val installmentPaymentEnabled: Boolean,
|
|
118
|
+
val paymentExperience: List<String>,
|
|
119
|
+
val card: Card?,
|
|
120
|
+
val metadata: String?,
|
|
121
|
+
val created: String,
|
|
122
|
+
val bank: String?,
|
|
123
|
+
val surchargeDetails: String?,
|
|
124
|
+
val requiresCvv: Boolean,
|
|
125
|
+
val lastUsedAt: String,
|
|
126
|
+
val defaultPaymentMethodSet: Boolean,
|
|
127
|
+
val billing: String?,
|
|
128
|
+
) {
|
|
129
|
+
fun toMap(): HashMap<String, Any?> {
|
|
130
|
+
return HashMap<String, Any?>().apply {
|
|
131
|
+
this["payment_token"] = paymentToken
|
|
132
|
+
this["payment_method_id"] = paymentMethodId
|
|
133
|
+
this["customer_id"] = customerId
|
|
134
|
+
this["payment_method"] = paymentMethod.toStringValue()
|
|
135
|
+
this["payment_method_type"] = paymentMethodType
|
|
136
|
+
this["payment_method_issuer"] = paymentMethodIssuer
|
|
137
|
+
this["payment_method_issuer_code"] = paymentMethodIssuerCode
|
|
138
|
+
this["recurring_enabled"] = recurringEnabled
|
|
139
|
+
this["installment_payment_enabled"] = installmentPaymentEnabled
|
|
140
|
+
this["payment_experience"] = paymentExperience
|
|
141
|
+
this["card"] = card?.toMap()
|
|
142
|
+
this["metadata"] = metadata
|
|
143
|
+
this["created"] = created
|
|
144
|
+
this["bank"] = bank
|
|
145
|
+
this["surcharge_details"] = surchargeDetails
|
|
146
|
+
this["requires_cvv"] = requiresCvv
|
|
147
|
+
this["last_used_at"] = lastUsedAt
|
|
148
|
+
this["default_payment_method_set"] = defaultPaymentMethodSet
|
|
149
|
+
this["billing"] = billing
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Represents an error state in payment method retrieval
|
|
156
|
+
*/
|
|
157
|
+
data class PMError(
|
|
158
|
+
val code: String,
|
|
159
|
+
override val message: String,
|
|
160
|
+
) : Throwable(message) {
|
|
161
|
+
fun toMap(): HashMap<String, Any> {
|
|
162
|
+
return HashMap<String, Any>().apply {
|
|
163
|
+
this["code"] = code
|
|
164
|
+
this["message"] = message
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
package io.hyperswitch.paymentsession
|
|
2
|
+
|
|
3
|
+
import android.view.View
|
|
4
|
+
import io.hyperswitch.paymentsheet.PaymentResult
|
|
5
|
+
|
|
6
|
+
interface PaymentSessionHandler {
|
|
7
|
+
// -------------------------------------------------------------------------
|
|
8
|
+
// Kotlin-only API — DO NOT call from Java.
|
|
9
|
+
// -------------------------------------------------------------------------
|
|
10
|
+
fun getCustomerDefaultSavedPaymentMethodData(): Result<PaymentMethod>
|
|
11
|
+
fun getCustomerLastUsedPaymentMethodData(): Result<PaymentMethod>
|
|
12
|
+
fun getCustomerSavedPaymentMethodData(): Result<List<PaymentMethod>>
|
|
13
|
+
|
|
14
|
+
// -------------------------------------------------------------------------
|
|
15
|
+
// Java-friendly callback variants.
|
|
16
|
+
// -------------------------------------------------------------------------
|
|
17
|
+
fun getCustomerDefaultSavedPaymentMethodData(
|
|
18
|
+
onSuccess: (PaymentMethod) -> Unit,
|
|
19
|
+
onFailure: (Throwable) -> Unit
|
|
20
|
+
) {
|
|
21
|
+
getCustomerDefaultSavedPaymentMethodData()
|
|
22
|
+
.onSuccess(onSuccess)
|
|
23
|
+
.onFailure(onFailure)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
fun getCustomerLastUsedPaymentMethodData(
|
|
27
|
+
onSuccess: (PaymentMethod) -> Unit,
|
|
28
|
+
onFailure: (Throwable) -> Unit
|
|
29
|
+
) {
|
|
30
|
+
getCustomerLastUsedPaymentMethodData()
|
|
31
|
+
.onSuccess(onSuccess)
|
|
32
|
+
.onFailure(onFailure)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
fun getCustomerSavedPaymentMethodData(
|
|
36
|
+
onSuccess: (List<PaymentMethod>) -> Unit,
|
|
37
|
+
onFailure: (Throwable) -> Unit
|
|
38
|
+
) {
|
|
39
|
+
getCustomerSavedPaymentMethodData()
|
|
40
|
+
.onSuccess(onSuccess)
|
|
41
|
+
.onFailure(onFailure)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
fun confirmWithCustomerDefaultPaymentMethod(
|
|
45
|
+
cvc: String? = null, resultHandler: (PaymentResult) -> Unit
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
fun confirmWithCustomerLastUsedPaymentMethod(
|
|
49
|
+
cvc: String? = null, resultHandler: (PaymentResult) -> Unit
|
|
50
|
+
)
|
|
51
|
+
fun updateSdkAuthorization(sdkAuthorization : String)
|
|
52
|
+
|
|
53
|
+
fun confirmWithCustomerPaymentToken(
|
|
54
|
+
paymentToken: String, cvc: String? = null, resultHandler: (PaymentResult) -> Unit
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
// -------------------------------------------------------------------------
|
|
58
|
+
// Kotlin-only — hidden Continuation<T> parameter; not callable from Java.
|
|
59
|
+
// -------------------------------------------------------------------------
|
|
60
|
+
suspend fun confirmWithCustomerLastUsedPaymentMethod(cvcWidget: View): PaymentResult
|
|
61
|
+
suspend fun confirmWithCustomerDefaultPaymentMethod(cvcWidget: View): PaymentResult
|
|
62
|
+
|
|
63
|
+
// -------------------------------------------------------------------------
|
|
64
|
+
// Java-friendly callback variants — no Continuation, no name mangling.
|
|
65
|
+
// -------------------------------------------------------------------------
|
|
66
|
+
fun confirmWithCustomerLastUsedPaymentMethod(cvcWidget: View, resultHandler: (PaymentResult) -> Unit)
|
|
67
|
+
fun confirmWithCustomerDefaultPaymentMethod(cvcWidget: View, resultHandler: (PaymentResult) -> Unit)
|
|
68
|
+
}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
package io.hyperswitch.paymentsession
|
|
2
|
+
|
|
3
|
+
import android.view.View
|
|
4
|
+
import com.facebook.react.bridge.Arguments
|
|
5
|
+
import com.facebook.react.bridge.Callback
|
|
6
|
+
import com.facebook.react.bridge.ReadableArray
|
|
7
|
+
import com.facebook.react.bridge.ReadableMap
|
|
8
|
+
import io.hyperswitch.paymentsheet.PaymentResult
|
|
9
|
+
import io.hyperswitch.utils.ConversionUtils
|
|
10
|
+
import io.hyperswitch.view.PaymentWidgetView
|
|
11
|
+
//import io.hyperswitch.view.CVCWidget
|
|
12
|
+
import kotlinx.coroutines.CoroutineScope
|
|
13
|
+
import kotlinx.coroutines.Dispatchers
|
|
14
|
+
import kotlinx.coroutines.launch
|
|
15
|
+
|
|
16
|
+
internal class PaymentSessionHandlerImpl(
|
|
17
|
+
private var sdkAuthorization: String,
|
|
18
|
+
private val defaultMethodData: ReadableMap,
|
|
19
|
+
private val lastUsedMethodData: ReadableMap,
|
|
20
|
+
private val allMethodsData: ReadableArray,
|
|
21
|
+
private val jsCallback: Callback,
|
|
22
|
+
) : PaymentSessionHandler {
|
|
23
|
+
|
|
24
|
+
override fun getCustomerDefaultSavedPaymentMethodData(): Result<PaymentMethod> =
|
|
25
|
+
parsePaymentMethod(defaultMethodData)
|
|
26
|
+
|
|
27
|
+
override fun getCustomerLastUsedPaymentMethodData(): Result<PaymentMethod> =
|
|
28
|
+
parsePaymentMethod(lastUsedMethodData)
|
|
29
|
+
|
|
30
|
+
override fun getCustomerSavedPaymentMethodData(): Result<List<PaymentMethod>> {
|
|
31
|
+
val list = mutableListOf<PaymentMethod>()
|
|
32
|
+
for (i in 0 until allMethodsData.size()) {
|
|
33
|
+
allMethodsData.getMap(i)?.let { map ->
|
|
34
|
+
parsePaymentMethod(map).onSuccess { list.add(it) }
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return Result.success(list)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
override fun confirmWithCustomerDefaultPaymentMethod(
|
|
41
|
+
cvc: String?, resultHandler: (PaymentResult) -> Unit
|
|
42
|
+
) {
|
|
43
|
+
defaultMethodData.getString("payment_token")
|
|
44
|
+
?.let { confirmWithCustomerPaymentToken(it, cvc, resultHandler) }
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
override fun confirmWithCustomerLastUsedPaymentMethod(
|
|
48
|
+
cvc: String?, resultHandler: (PaymentResult) -> Unit
|
|
49
|
+
) {
|
|
50
|
+
lastUsedMethodData.getString("payment_token")
|
|
51
|
+
?.let { confirmWithCustomerPaymentToken(it, cvc, resultHandler) }
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
override fun updateSdkAuthorization(sdkAuthorization: String){
|
|
55
|
+
this.sdkAuthorization = sdkAuthorization
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
override fun confirmWithCustomerPaymentToken(
|
|
59
|
+
paymentToken: String, cvc: String?, resultHandler: (PaymentResult) -> Unit
|
|
60
|
+
) {
|
|
61
|
+
try {
|
|
62
|
+
val registered = ExitHeadlessCallBackManager.tryRegisterCallback(-1, resultHandler)
|
|
63
|
+
if (!registered) {
|
|
64
|
+
resultHandler(PaymentResult.Failed(
|
|
65
|
+
Throwable("Payment confirmation already in progress for this handler").apply {
|
|
66
|
+
initCause(Throwable("ALREADY_IN_PROGRESS"))
|
|
67
|
+
}
|
|
68
|
+
))
|
|
69
|
+
return
|
|
70
|
+
}
|
|
71
|
+
jsCallback.invoke(Arguments.createMap().apply {
|
|
72
|
+
putString("paymentToken", paymentToken)
|
|
73
|
+
putString("cvc", cvc)
|
|
74
|
+
})
|
|
75
|
+
} catch (ex: Exception) {
|
|
76
|
+
ExitHeadlessCallBackManager.clearCallback(-1)
|
|
77
|
+
resultHandler(PaymentResult.Failed(Throwable("Not Initialised").apply {
|
|
78
|
+
initCause(Throwable("Not Initialised"))
|
|
79
|
+
}))
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// ── CVCWidget suspend overloads ───────────────────────────────────────────
|
|
84
|
+
|
|
85
|
+
override suspend fun confirmWithCustomerLastUsedPaymentMethod(cvcWidget: View): PaymentResult {
|
|
86
|
+
val method = getCustomerLastUsedPaymentMethodData()
|
|
87
|
+
.getOrElse { return PaymentResult.Failed(it) }
|
|
88
|
+
(cvcWidget as? PaymentWidgetView)?.let {
|
|
89
|
+
it.setSdkAuthorization(sdkAuthorization)
|
|
90
|
+
// return it.confirmCVCWidget(sdkAuthorization, method.paymentToken, method.billing)
|
|
91
|
+
}
|
|
92
|
+
return PaymentResult.Failed(Throwable("View can't be cast as CVCWidget"))
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
override suspend fun confirmWithCustomerDefaultPaymentMethod(cvcWidget: View): PaymentResult {
|
|
96
|
+
val method = getCustomerDefaultSavedPaymentMethodData()
|
|
97
|
+
.getOrElse { return PaymentResult.Failed(it) }
|
|
98
|
+
(cvcWidget as? PaymentWidgetView)?.let {
|
|
99
|
+
it.setSdkAuthorization(sdkAuthorization)
|
|
100
|
+
// return it.confirmCVCWidget(sdkAuthorization, method.paymentToken, method.billing)
|
|
101
|
+
}
|
|
102
|
+
return PaymentResult.Failed(Throwable("View can't be cast as CVCWidget"))
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// ── CVCWidget callback overloads (Java-friendly, no Continuation needed) ─
|
|
106
|
+
|
|
107
|
+
override fun confirmWithCustomerLastUsedPaymentMethod(
|
|
108
|
+
cvcWidget: View, resultHandler: (PaymentResult) -> Unit
|
|
109
|
+
) {
|
|
110
|
+
CoroutineScope(Dispatchers.Main).launch {
|
|
111
|
+
resultHandler(confirmWithCustomerLastUsedPaymentMethod(cvcWidget))
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
override fun confirmWithCustomerDefaultPaymentMethod(
|
|
116
|
+
cvcWidget: View, resultHandler: (PaymentResult) -> Unit
|
|
117
|
+
) {
|
|
118
|
+
CoroutineScope(Dispatchers.Main).launch {
|
|
119
|
+
resultHandler(confirmWithCustomerDefaultPaymentMethod(cvcWidget))
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// ── Parsing ──────────────────────────────────────────────────────────────
|
|
124
|
+
|
|
125
|
+
private fun parsePaymentMethod(map: ReadableMap): Result<PaymentMethod> {
|
|
126
|
+
val paymentMethodStr = map.getString("payment_method_str")
|
|
127
|
+
?: return Result.failure(PMError(
|
|
128
|
+
code = map.getString("code") ?: "",
|
|
129
|
+
message = map.getString("message") ?: ""
|
|
130
|
+
))
|
|
131
|
+
|
|
132
|
+
val cardMap = map.getMap("card")
|
|
133
|
+
val card = cardMap?.let {
|
|
134
|
+
Card(
|
|
135
|
+
scheme = it.getString("scheme") ?: "",
|
|
136
|
+
issuerCountry = it.getString("issuer_country") ?: "",
|
|
137
|
+
last4Digits = it.getString("last4_digits") ?: "",
|
|
138
|
+
expiryMonth = it.getString("expiry_month") ?: "",
|
|
139
|
+
expiryYear = it.getString("expiry_year") ?: "",
|
|
140
|
+
cardToken = it.getString("card_token"),
|
|
141
|
+
cardHolderName = it.getString("card_holder_name") ?: "",
|
|
142
|
+
cardFingerprint = it.getString("card_fingerprint"),
|
|
143
|
+
nickName = it.getString("nick_name") ?: "",
|
|
144
|
+
cardNetwork = it.getString("card_network") ?: "",
|
|
145
|
+
cardIsin = it.getString("card_isin") ?: "",
|
|
146
|
+
cardIssuer = it.getString("card_issuer") ?: "",
|
|
147
|
+
cardType = it.getString("card_type") ?: "",
|
|
148
|
+
savedToLocker = it.getBoolean("saved_to_locker"),
|
|
149
|
+
)
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
val paymentExperience = buildList {
|
|
153
|
+
val arr = map.getArray("payment_experience") ?: return@buildList
|
|
154
|
+
for (i in 0 until arr.size()) arr.getString(i)?.let { add(it) }
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
return Result.success(PaymentMethod(
|
|
158
|
+
paymentToken = map.getString("payment_token") ?: "",
|
|
159
|
+
paymentMethodId = map.getString("payment_method_id") ?: "",
|
|
160
|
+
customerId = map.getString("customer_id") ?: "",
|
|
161
|
+
paymentMethod = PaymentMethodType.fromString(paymentMethodStr),
|
|
162
|
+
paymentMethodType = map.getString("payment_method_type") ?: "",
|
|
163
|
+
paymentMethodIssuer = map.getString("payment_method_issuer") ?: "",
|
|
164
|
+
paymentMethodIssuerCode = map.getString("payment_method_issuer_code"),
|
|
165
|
+
recurringEnabled = map.getBoolean("recurring_enabled"),
|
|
166
|
+
installmentPaymentEnabled = map.getBoolean("installment_payment_enabled"),
|
|
167
|
+
paymentExperience = paymentExperience,
|
|
168
|
+
card = card,
|
|
169
|
+
metadata = map.getString("metadata"),
|
|
170
|
+
created = map.getString("created") ?: "",
|
|
171
|
+
bank = map.getString("bank"),
|
|
172
|
+
surchargeDetails = map.getString("surcharge_details"),
|
|
173
|
+
requiresCvv = map.getBoolean("requires_cvv"),
|
|
174
|
+
lastUsedAt = map.getString("last_used_at") ?: "",
|
|
175
|
+
defaultPaymentMethodSet = map.getBoolean("default_payment_method_set"),
|
|
176
|
+
billing = map.getMap("billing")?.let { ConversionUtils.convertMapToJson(it).toString() },
|
|
177
|
+
))
|
|
178
|
+
}
|
|
179
|
+
}
|