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,212 @@
|
|
|
1
|
+
//
|
|
2
|
+
// PaymentWidget.swift
|
|
3
|
+
// hyperswitch
|
|
4
|
+
//
|
|
5
|
+
// Created by Harshit Srivastava on 21/04/26.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
import Combine
|
|
9
|
+
import Foundation
|
|
10
|
+
import React
|
|
11
|
+
|
|
12
|
+
public class PaymentWidget: UIControl {
|
|
13
|
+
|
|
14
|
+
private let paymentSession: PaymentSession
|
|
15
|
+
private let configuration: PaymentSheet.Configuration?
|
|
16
|
+
private var configurationDict: [String: Any]?
|
|
17
|
+
private var widgetReactTag: NSNumber?
|
|
18
|
+
internal var rootReactTag: NSNumber? { widgetReactTag }
|
|
19
|
+
private var rootView: RCTRootView?
|
|
20
|
+
private var initCallback: ((PaymentResult) -> Void)?
|
|
21
|
+
private var shouldProceedWithPaymentCallback: ((PaymentRequestData, @escaping (Bool) -> Void) -> Void)?
|
|
22
|
+
private var cancellables = Set<AnyCancellable>()
|
|
23
|
+
private var subscribedEventNames: [String]?
|
|
24
|
+
internal var paymentEventListener: PaymentEventListener?
|
|
25
|
+
|
|
26
|
+
public init(
|
|
27
|
+
paymentSession: PaymentSession,
|
|
28
|
+
configuration: PaymentSheet.Configuration? = nil,
|
|
29
|
+
completion: @escaping ((PaymentResult) -> Void),
|
|
30
|
+
subscribe: ((PaymentEventSubscriptionBuilder) -> Void)? = nil
|
|
31
|
+
) {
|
|
32
|
+
self.paymentSession = paymentSession
|
|
33
|
+
self.configuration = configuration
|
|
34
|
+
self.configurationDict = nil
|
|
35
|
+
if let subscribe {
|
|
36
|
+
let builder = PaymentEventSubscriptionBuilder()
|
|
37
|
+
subscribe(builder)
|
|
38
|
+
let (subscription, listener) = builder.build()
|
|
39
|
+
self.paymentEventListener = listener
|
|
40
|
+
self.subscribedEventNames = subscription.subscribedEventStrings()
|
|
41
|
+
}
|
|
42
|
+
self.initCallback = completion
|
|
43
|
+
super.init(frame: .zero)
|
|
44
|
+
commonInit()
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
public init(
|
|
48
|
+
paymentSession: PaymentSession,
|
|
49
|
+
configurationDict: [String: Any]?,
|
|
50
|
+
completion: @escaping ((PaymentResult) -> Void),
|
|
51
|
+
subscribe: ((PaymentEventSubscriptionBuilder) -> Void)? = nil
|
|
52
|
+
) {
|
|
53
|
+
self.paymentSession = paymentSession
|
|
54
|
+
self.configuration = nil
|
|
55
|
+
self.configurationDict = configurationDict
|
|
56
|
+
if let subscribe {
|
|
57
|
+
let builder = PaymentEventSubscriptionBuilder()
|
|
58
|
+
subscribe(builder)
|
|
59
|
+
let (subscription, listener) = builder.build()
|
|
60
|
+
self.paymentEventListener = listener
|
|
61
|
+
self.subscribedEventNames = subscription.subscribedEventStrings()
|
|
62
|
+
}
|
|
63
|
+
self.initCallback = completion
|
|
64
|
+
super.init(frame: .zero)
|
|
65
|
+
commonInit()
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
required init?(coder: NSCoder) {
|
|
69
|
+
fatalError("init(coder:) has not been implemented")
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
public func shouldProceedWithPayment(_ callback: @escaping (PaymentRequestData, @escaping (Bool) -> Void) -> Void) {
|
|
73
|
+
self.shouldProceedWithPaymentCallback = callback
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
private func commonInit() {
|
|
77
|
+
|
|
78
|
+
let hyperswitchConfiguration = try? paymentSession.hyperswitchConfiguration?.toDictionary()
|
|
79
|
+
let paymentSessionConfiguration = try? paymentSession.paymentSessionConfiguration.toDictionary()
|
|
80
|
+
|
|
81
|
+
let sdkParams = SDKParams.getSDKParams()
|
|
82
|
+
|
|
83
|
+
var nativeConfig = try? configuration?.toDictionary()
|
|
84
|
+
if self.subscribedEventNames == nil {
|
|
85
|
+
self.subscribedEventNames = configurationDict?["subscribedEvents"] as? [String]
|
|
86
|
+
?? nativeConfig?["subscribedEvents"] as? [String]
|
|
87
|
+
}
|
|
88
|
+
nativeConfig?["hideConfirmButton"] = true
|
|
89
|
+
nativeConfig?["subscribedEvents"] = subscribedEventNames
|
|
90
|
+
configurationDict?["hideConfirmButton"] = true
|
|
91
|
+
configurationDict?["subscribedEvents"] = subscribedEventNames
|
|
92
|
+
|
|
93
|
+
let props: [String: Any] = [
|
|
94
|
+
"type": "widgetPaymentSheet",
|
|
95
|
+
"hyperswitchConfig": hyperswitchConfiguration as Any,
|
|
96
|
+
"paymentSessionConfig": paymentSessionConfiguration as Any,
|
|
97
|
+
"sdkParams": sdkParams,
|
|
98
|
+
"configuration": configurationDict ?? nativeConfig as Any,
|
|
99
|
+
"from": (configurationDict != nil) ? "rn" : "nativeWidget",
|
|
100
|
+
]
|
|
101
|
+
|
|
102
|
+
self.rootView = RNViewManager.sharedInstance.widgetViewForModule(
|
|
103
|
+
"hyperSwitch",
|
|
104
|
+
initialProperties: ["props": props]
|
|
105
|
+
)
|
|
106
|
+
if let rootView = self.rootView {
|
|
107
|
+
self.widgetReactTag = rootView.reactTag
|
|
108
|
+
|
|
109
|
+
rootView.backgroundColor = .clear
|
|
110
|
+
|
|
111
|
+
addSubview(rootView)
|
|
112
|
+
|
|
113
|
+
rootView.translatesAutoresizingMaskIntoConstraints = false
|
|
114
|
+
NSLayoutConstraint.activate([
|
|
115
|
+
rootView.topAnchor.constraint(equalTo: topAnchor),
|
|
116
|
+
rootView.bottomAnchor.constraint(equalTo: bottomAnchor),
|
|
117
|
+
rootView.leadingAnchor.constraint(equalTo: leadingAnchor),
|
|
118
|
+
rootView.trailingAnchor.constraint(equalTo: trailingAnchor),
|
|
119
|
+
])
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
paymentSession.updateIntentDidStart
|
|
123
|
+
.receive(on: DispatchQueue.main)
|
|
124
|
+
.sink { [weak self] in
|
|
125
|
+
guard let self = self else { return }
|
|
126
|
+
let payload: [String: Any] = ["rootTag": self.widgetReactTag ?? -1]
|
|
127
|
+
self.rootView?.bridge.enqueueJSCall(
|
|
128
|
+
"RCTDeviceEventEmitter",
|
|
129
|
+
method: "emit",
|
|
130
|
+
args: ["updateIntentInit", payload],
|
|
131
|
+
completion: nil
|
|
132
|
+
)
|
|
133
|
+
}
|
|
134
|
+
.store(in: &cancellables)
|
|
135
|
+
|
|
136
|
+
paymentSession.updateIntentDidComplete
|
|
137
|
+
.receive(on: DispatchQueue.main)
|
|
138
|
+
.sink { [weak self] sdkAuthorization in
|
|
139
|
+
guard let self = self else { return }
|
|
140
|
+
let payload: [String: Any] = [
|
|
141
|
+
"rootTag": self.widgetReactTag ?? -1,
|
|
142
|
+
"sdkAuthorization": sdkAuthorization,
|
|
143
|
+
]
|
|
144
|
+
self.rootView?.bridge.enqueueJSCall(
|
|
145
|
+
"RCTDeviceEventEmitter",
|
|
146
|
+
method: "emit",
|
|
147
|
+
args: ["updateIntentComplete", payload],
|
|
148
|
+
completion: nil
|
|
149
|
+
)
|
|
150
|
+
}
|
|
151
|
+
.store(in: &cancellables)
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
public func confirm() {
|
|
155
|
+
let payload: [String: Any] = [
|
|
156
|
+
"rootTag": self.widgetReactTag ?? -1,
|
|
157
|
+
"actionType": "CONFIRM_PAYMENT_ACTION",
|
|
158
|
+
]
|
|
159
|
+
self.rootView?.bridge.enqueueJSCall(
|
|
160
|
+
"RCTDeviceEventEmitter",
|
|
161
|
+
method: "emit",
|
|
162
|
+
args: ["triggerWidgetAction", payload],
|
|
163
|
+
completion: nil
|
|
164
|
+
)
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
internal func setPaymentEventListener(_ listener: PaymentEventListener?) {
|
|
168
|
+
self.paymentEventListener = listener
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
internal func handleShouldProceedWithPayment(payload: String, callback: @escaping (Bool) -> Void) {
|
|
172
|
+
if shouldProceedWithPaymentCallback == nil {
|
|
173
|
+
callback(true)
|
|
174
|
+
} else {
|
|
175
|
+
if let data = payload.data(using: .utf8),
|
|
176
|
+
let paymentRequestData = try? JSONDecoder().decode(PaymentRequestData.self, from: data)
|
|
177
|
+
{
|
|
178
|
+
shouldProceedWithPaymentCallback?(paymentRequestData, callback)
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
internal func handleUpdateIntentEvent(type: String, result: String) {
|
|
184
|
+
switch type {
|
|
185
|
+
case "UPDATE_INTENT_INIT_RETURNED":
|
|
186
|
+
paymentSession.updateIntentInitReturned.send(result)
|
|
187
|
+
case "UPDATE_INTENT_COMPLETE_RETURNED":
|
|
188
|
+
paymentSession.updateIntentCompleteReturned.send(result)
|
|
189
|
+
default:
|
|
190
|
+
break
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
internal func handleConfirmPaymentResponse(_ result: PaymentResult) {
|
|
195
|
+
initCallback?(result)
|
|
196
|
+
initCallback = nil
|
|
197
|
+
cancellables.removeAll()
|
|
198
|
+
rootView?.removeFromSuperview()
|
|
199
|
+
rootView = nil
|
|
200
|
+
widgetReactTag = nil
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
internal func dispatchPaymentEvent(type: String, payload: [String: Any]) {
|
|
204
|
+
guard let listener = paymentEventListener else { return }
|
|
205
|
+
let event = PaymentEvent(type: type, payload: payload)
|
|
206
|
+
if Thread.isMainThread {
|
|
207
|
+
listener.onPaymentEvent(event)
|
|
208
|
+
} else {
|
|
209
|
+
DispatchQueue.main.async { listener.onPaymentEvent(event) }
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
//
|
|
2
|
+
// PaymentSession+UIKit.swift
|
|
3
|
+
// hyperswitch
|
|
4
|
+
//
|
|
5
|
+
// Created by Harshit Srivastava on 30/08/24.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
import Foundation
|
|
9
|
+
import React
|
|
10
|
+
|
|
11
|
+
extension PaymentSession {
|
|
12
|
+
|
|
13
|
+
private static var hasResponded: Bool = false
|
|
14
|
+
internal static var headlessCompletion: ((PaymentSessionHandler) -> Void)?
|
|
15
|
+
private static var completion: ((PaymentResult) -> Void)?
|
|
16
|
+
internal static weak var activeSession: PaymentSession? // NEW
|
|
17
|
+
|
|
18
|
+
private static func safeResolve(
|
|
19
|
+
_ callback: @escaping RCTResponseSenderBlock,
|
|
20
|
+
_ result: [Any],
|
|
21
|
+
_ resultHandler: @escaping (PaymentResult) -> Void
|
|
22
|
+
) {
|
|
23
|
+
guard !PaymentSession.hasResponded else {
|
|
24
|
+
print("Warning: Attempt to resolve callback more than once")
|
|
25
|
+
resultHandler(.failed(error: NSError(domain: "Not Initialised", code: 0, userInfo: ["message": "An error has occurred."])))
|
|
26
|
+
return
|
|
27
|
+
}
|
|
28
|
+
PaymentSession.hasResponded = true
|
|
29
|
+
callback(result)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
public func presentPaymentSheet(
|
|
33
|
+
viewController: UIViewController,
|
|
34
|
+
configuration: PaymentSheet.Configuration? = nil,
|
|
35
|
+
subscribe: ((PaymentEventSubscriptionBuilder) -> Void)? = nil,
|
|
36
|
+
completion: @escaping (PaymentResult) -> Void
|
|
37
|
+
) {
|
|
38
|
+
let paymentSheet = PaymentSheet(
|
|
39
|
+
paymentSessionConfiguration: paymentSessionConfiguration,
|
|
40
|
+
hyperswitchConfiguration: hyperswitchConfiguration ?? nil,
|
|
41
|
+
configuration: configuration
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
if let subscribe {
|
|
45
|
+
let builder = PaymentEventSubscriptionBuilder()
|
|
46
|
+
subscribe(builder)
|
|
47
|
+
let (subscription, builtListener) = builder.build()
|
|
48
|
+
paymentSheet.subscribedEvents = subscription.subscribedEventStrings()
|
|
49
|
+
paymentSheet.paymentEventListener = builtListener
|
|
50
|
+
}
|
|
51
|
+
paymentSheet.present(from: viewController, completion: completion)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// MARK: for external frameworks
|
|
55
|
+
public func presentPaymentSheetWithParams(
|
|
56
|
+
viewController: UIViewController,
|
|
57
|
+
params: [String: Any],
|
|
58
|
+
subscribe: ((PaymentEventSubscriptionBuilder) -> Void)? = nil,
|
|
59
|
+
completion: @escaping (PaymentResult) -> Void
|
|
60
|
+
) {
|
|
61
|
+
let paymentSheet = PaymentSheet(
|
|
62
|
+
paymentSessionConfiguration: paymentSessionConfiguration,
|
|
63
|
+
hyperswitchConfiguration: hyperswitchConfiguration ?? nil
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
if let subscribe {
|
|
67
|
+
let builder = PaymentEventSubscriptionBuilder()
|
|
68
|
+
subscribe(builder)
|
|
69
|
+
let (subscription, builtListener) = builder.build()
|
|
70
|
+
paymentSheet.subscribedEvents = subscription.subscribedEventStrings()
|
|
71
|
+
paymentSheet.paymentEventListener = builtListener
|
|
72
|
+
}
|
|
73
|
+
paymentSheet.presentWithParams(from: viewController, props: params, completion: completion)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
public func getCustomerSavedPaymentMethods(
|
|
77
|
+
_ func_: @escaping (PaymentSessionHandler) -> Void,
|
|
78
|
+
configuration: SavedPaymentMethodsConfiguration? = nil
|
|
79
|
+
) {
|
|
80
|
+
PaymentSession.hasResponded = false
|
|
81
|
+
PaymentSession.headlessCompletion = func_
|
|
82
|
+
PaymentSession.activeSession = self
|
|
83
|
+
RNHeadlessManager.sharedInstance.reinvalidateBridge()
|
|
84
|
+
let hyperswitchConfiguration = try? hyperswitchConfiguration?.toDictionary()
|
|
85
|
+
let paymentSessionConfiguration = try? paymentSessionConfiguration.toDictionary()
|
|
86
|
+
let sdkParams = SDKParams.getSDKParams()
|
|
87
|
+
let configurationDict = try? configuration.toDictionary()
|
|
88
|
+
|
|
89
|
+
var props: [String: Any] = [
|
|
90
|
+
"hyperswitchConfig": hyperswitchConfiguration as Any,
|
|
91
|
+
"paymentSessionConfig": paymentSessionConfiguration as Any,
|
|
92
|
+
"sdkParams": sdkParams,
|
|
93
|
+
]
|
|
94
|
+
|
|
95
|
+
props["configuration"] = [
|
|
96
|
+
"paymentMethodLayout": [
|
|
97
|
+
"savedMethodCustomization": configurationDict
|
|
98
|
+
]
|
|
99
|
+
]
|
|
100
|
+
|
|
101
|
+
let _ = RNHeadlessManager.sharedInstance.viewForModule("HyperHeadless", initialProperties: ["props": props])
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
internal static func getPaymentSession(
|
|
105
|
+
getPaymentMethodData: NSDictionary,
|
|
106
|
+
getPaymentMethodData2: NSDictionary,
|
|
107
|
+
getPaymentMethodDataArray: NSArray,
|
|
108
|
+
callback: @escaping RCTResponseSenderBlock
|
|
109
|
+
) {
|
|
110
|
+
DispatchQueue.main.async {
|
|
111
|
+
PaymentSession.hasResponded = false
|
|
112
|
+
let handler = PaymentSessionHandler(
|
|
113
|
+
getCustomerDefaultSavedPaymentMethodData: {
|
|
114
|
+
return decodePaymentMethodData(getPaymentMethodData)
|
|
115
|
+
},
|
|
116
|
+
getCustomerLastUsedPaymentMethodData: {
|
|
117
|
+
return decodePaymentMethodData(getPaymentMethodData2)
|
|
118
|
+
},
|
|
119
|
+
getCustomerSavedPaymentMethodData: {
|
|
120
|
+
var array = [PaymentMethod]()
|
|
121
|
+
for i in 0..<getPaymentMethodDataArray.count {
|
|
122
|
+
if let map = getPaymentMethodDataArray[i] as? NSDictionary {
|
|
123
|
+
switch decodePaymentMethodData(map) {
|
|
124
|
+
case .success(let paymentMethod):
|
|
125
|
+
array.append(paymentMethod)
|
|
126
|
+
case .failure(_):
|
|
127
|
+
continue
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
if array.isEmpty {
|
|
132
|
+
return .failure(
|
|
133
|
+
PMError(
|
|
134
|
+
code: "01",
|
|
135
|
+
message: "No default type found"
|
|
136
|
+
)
|
|
137
|
+
)
|
|
138
|
+
}
|
|
139
|
+
return .success(array)
|
|
140
|
+
|
|
141
|
+
},
|
|
142
|
+
confirmWithCustomerDefaultPaymentMethod: { cvc, resultHandler in
|
|
143
|
+
if let paymentToken = getPaymentMethodData["payment_token"] as? String {
|
|
144
|
+
self.completion = resultHandler
|
|
145
|
+
var map = [String: Any]()
|
|
146
|
+
map["paymentToken"] = paymentToken
|
|
147
|
+
map["cvc"] = cvc
|
|
148
|
+
self.safeResolve(callback, [map], resultHandler)
|
|
149
|
+
}
|
|
150
|
+
},
|
|
151
|
+
confirmWithCustomerLastUsedPaymentMethod: { cvc, resultHandler in
|
|
152
|
+
if let paymentToken = getPaymentMethodData2["payment_token"] as? String {
|
|
153
|
+
cvc.confirm(
|
|
154
|
+
sdkAuthorization: PaymentSession.activeSession?.paymentSessionConfiguration.sdkAuthorization ?? "",
|
|
155
|
+
paymentToken: paymentToken
|
|
156
|
+
)
|
|
157
|
+
self.completion = resultHandler
|
|
158
|
+
// var map = [String: Any]()
|
|
159
|
+
// map["paymentToken"] = paymentToken
|
|
160
|
+
// map["cvc"] = cvc
|
|
161
|
+
// self.safeResolve(callback, [map], resultHandler)
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
confirmWithCustomerPaymentToken: { paymentToken, cvc, resultHandler in
|
|
165
|
+
self.completion = resultHandler
|
|
166
|
+
var map = [String: Any]()
|
|
167
|
+
map["paymentToken"] = paymentToken
|
|
168
|
+
map["cvc"] = cvc
|
|
169
|
+
self.safeResolve(callback, [map], resultHandler)
|
|
170
|
+
}
|
|
171
|
+
)
|
|
172
|
+
self.headlessCompletion?(handler)
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
internal static func exitHeadless(rnMessage: String) {
|
|
177
|
+
DispatchQueue.main.async {
|
|
178
|
+
if let data = rnMessage.data(using: .utf8) {
|
|
179
|
+
do {
|
|
180
|
+
if let message = try JSONSerialization.jsonObject(with: data, options: []) as? [String: String] {
|
|
181
|
+
guard let status = message["status"] else {
|
|
182
|
+
completion?(
|
|
183
|
+
.failed(error: NSError(domain: "UNKNOWN_ERROR", code: 0, userInfo: ["message": "An error has occurred."]))
|
|
184
|
+
)
|
|
185
|
+
return
|
|
186
|
+
}
|
|
187
|
+
switch status {
|
|
188
|
+
case "cancelled":
|
|
189
|
+
completion?(.canceled(data: status))
|
|
190
|
+
case "failed", "requires_payment_method":
|
|
191
|
+
let domain = (message["code"]) != "" ? message["code"] : "UNKNOWN_ERROR"
|
|
192
|
+
let errorMessage = message["message"] ?? "An error has occurred."
|
|
193
|
+
let userInfo = ["message": errorMessage]
|
|
194
|
+
completion?(.failed(error: NSError(domain: domain ?? "UNKNOWN_ERROR", code: 0, userInfo: userInfo)))
|
|
195
|
+
default:
|
|
196
|
+
completion?(.completed(data: status))
|
|
197
|
+
}
|
|
198
|
+
} else {
|
|
199
|
+
let domain = "UNKNOWN_ERROR"
|
|
200
|
+
let errorMessage = "An error has occurred."
|
|
201
|
+
let userInfo = ["message": errorMessage]
|
|
202
|
+
self.completion?(.failed(error: NSError(domain: domain, code: 0, userInfo: userInfo)))
|
|
203
|
+
}
|
|
204
|
+
} catch {
|
|
205
|
+
let domain = "UNKNOWN_ERROR"
|
|
206
|
+
let errorMessage = "An error has occurred."
|
|
207
|
+
let userInfo = ["message": errorMessage]
|
|
208
|
+
self.completion?(.failed(error: NSError(domain: domain, code: 0, userInfo: userInfo)))
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
private static func decodePaymentMethodData(_ readableMap: NSDictionary) -> Result<PaymentMethod, PMError> {
|
|
215
|
+
if let jsonData = try? JSONSerialization.data(withJSONObject: readableMap),
|
|
216
|
+
let paymentMethod = try? JSONDecoder().decode(PaymentMethod.self, from: jsonData)
|
|
217
|
+
{
|
|
218
|
+
return .success(paymentMethod)
|
|
219
|
+
} else {
|
|
220
|
+
return .failure(
|
|
221
|
+
PMError(
|
|
222
|
+
code: readableMap["code"] as? String ?? "01",
|
|
223
|
+
message: readableMap["message"] as? String ?? "No default type found"
|
|
224
|
+
)
|
|
225
|
+
)
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
//
|
|
2
|
+
// PaymentSessionTypes.swift
|
|
3
|
+
// hyperswitch
|
|
4
|
+
//
|
|
5
|
+
// Created by Harshit Srivastava on 30/08/24.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
import Foundation
|
|
9
|
+
|
|
10
|
+
/// Represents a valid payment method with all details
|
|
11
|
+
public struct PaymentMethod: Codable {
|
|
12
|
+
public let paymentToken: String
|
|
13
|
+
public let paymentMethodId: String
|
|
14
|
+
public let customerId: String
|
|
15
|
+
public let paymentMethod: String
|
|
16
|
+
public let paymentMethodType: String
|
|
17
|
+
public let paymentMethodIssuer: String
|
|
18
|
+
public let paymentMethodIssuerCode: String?
|
|
19
|
+
public let recurringEnabled: Bool
|
|
20
|
+
public let installmentPaymentEnabled: Bool
|
|
21
|
+
public let paymentExperience: [String]
|
|
22
|
+
public let card: Card?
|
|
23
|
+
public let metadata: String?
|
|
24
|
+
public let created: String
|
|
25
|
+
public let bank: String?
|
|
26
|
+
public let surchargeDetails: String?
|
|
27
|
+
public let requiresCvv: Bool
|
|
28
|
+
public let lastUsedAt: String
|
|
29
|
+
public let defaultPaymentMethodSet: Bool
|
|
30
|
+
|
|
31
|
+
public init(from decoder: Decoder) throws {
|
|
32
|
+
let container = try decoder.container(keyedBy: CodingKeys.self)
|
|
33
|
+
paymentToken = try container.decode(String.self, forKey: .paymentToken)
|
|
34
|
+
paymentMethodId = try container.decodeIfPresent(String.self, forKey: .paymentMethodId) ?? ""
|
|
35
|
+
customerId = try container.decodeIfPresent(String.self, forKey: .customerId) ?? ""
|
|
36
|
+
paymentMethod = try container.decodeIfPresent(String.self, forKey: .paymentMethod) ?? ""
|
|
37
|
+
paymentMethodType = try container.decodeIfPresent(String.self, forKey: .paymentMethodType) ?? ""
|
|
38
|
+
paymentMethodIssuer = try container.decodeIfPresent(String.self, forKey: .paymentMethodIssuer) ?? ""
|
|
39
|
+
paymentMethodIssuerCode = try container.decodeIfPresent(String.self, forKey: .paymentMethodIssuerCode)
|
|
40
|
+
recurringEnabled = try container.decodeIfPresent(Bool.self, forKey: .recurringEnabled) ?? false
|
|
41
|
+
installmentPaymentEnabled = try container.decodeIfPresent(Bool.self, forKey: .installmentPaymentEnabled) ?? false
|
|
42
|
+
paymentExperience = try container.decodeIfPresent([String].self, forKey: .paymentExperience) ?? []
|
|
43
|
+
card = try container.decodeIfPresent(Card.self, forKey: .card)
|
|
44
|
+
metadata = try container.decodeIfPresent(String.self, forKey: .metadata)
|
|
45
|
+
created = try container.decodeIfPresent(String.self, forKey: .created) ?? ""
|
|
46
|
+
bank = try container.decodeIfPresent(String.self, forKey: .bank)
|
|
47
|
+
surchargeDetails = try container.decodeIfPresent(String.self, forKey: .surchargeDetails)
|
|
48
|
+
requiresCvv = try container.decodeIfPresent(Bool.self, forKey: .requiresCvv) ?? false
|
|
49
|
+
lastUsedAt = try container.decodeIfPresent(String.self, forKey: .lastUsedAt) ?? ""
|
|
50
|
+
defaultPaymentMethodSet = try container.decodeIfPresent(Bool.self, forKey: .defaultPaymentMethodSet) ?? false
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
enum CodingKeys: String, CodingKey {
|
|
54
|
+
case paymentToken = "payment_token"
|
|
55
|
+
case paymentMethodId = "payment_method_id"
|
|
56
|
+
case customerId = "customer_id"
|
|
57
|
+
case paymentMethod = "payment_method_str"
|
|
58
|
+
case paymentMethodType = "payment_method_type"
|
|
59
|
+
case paymentMethodIssuer = "payment_method_issuer"
|
|
60
|
+
case paymentMethodIssuerCode = "payment_method_issuer_code"
|
|
61
|
+
case recurringEnabled = "recurring_enabled"
|
|
62
|
+
case installmentPaymentEnabled = "installment_payment_enabled"
|
|
63
|
+
case paymentExperience = "payment_experience"
|
|
64
|
+
case card
|
|
65
|
+
case metadata
|
|
66
|
+
case created
|
|
67
|
+
case bank
|
|
68
|
+
case surchargeDetails = "surcharge_details"
|
|
69
|
+
case requiresCvv = "requires_cvv"
|
|
70
|
+
case lastUsedAt = "last_used_at"
|
|
71
|
+
case defaultPaymentMethodSet = "default_payment_method_set"
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/// Represents card payment method details
|
|
76
|
+
public struct Card: Codable {
|
|
77
|
+
public let scheme: String
|
|
78
|
+
public let issuerCountry: String
|
|
79
|
+
public let last4Digits: String
|
|
80
|
+
public let expiryMonth: String
|
|
81
|
+
public let expiryYear: String
|
|
82
|
+
public let cardToken: String?
|
|
83
|
+
public let cardHolderName: String
|
|
84
|
+
public let cardFingerprint: String?
|
|
85
|
+
public let nickName: String
|
|
86
|
+
public let cardNetwork: String
|
|
87
|
+
public let cardIsin: String
|
|
88
|
+
public let cardIssuer: String
|
|
89
|
+
public let cardType: String
|
|
90
|
+
public let savedToLocker: Bool
|
|
91
|
+
|
|
92
|
+
public init(from decoder: Decoder) throws {
|
|
93
|
+
let container = try decoder.container(keyedBy: CodingKeys.self)
|
|
94
|
+
scheme = try container.decodeIfPresent(String.self, forKey: .scheme) ?? ""
|
|
95
|
+
issuerCountry = try container.decodeIfPresent(String.self, forKey: .issuerCountry) ?? ""
|
|
96
|
+
last4Digits = try container.decodeIfPresent(String.self, forKey: .last4Digits) ?? ""
|
|
97
|
+
expiryMonth = try container.decodeIfPresent(String.self, forKey: .expiryMonth) ?? ""
|
|
98
|
+
expiryYear = try container.decodeIfPresent(String.self, forKey: .expiryYear) ?? ""
|
|
99
|
+
cardToken = try container.decodeIfPresent(String.self, forKey: .cardToken)
|
|
100
|
+
cardHolderName = try container.decodeIfPresent(String.self, forKey: .cardHolderName) ?? ""
|
|
101
|
+
cardFingerprint = try container.decodeIfPresent(String.self, forKey: .cardFingerprint)
|
|
102
|
+
nickName = try container.decodeIfPresent(String.self, forKey: .nickName) ?? ""
|
|
103
|
+
cardNetwork = try container.decodeIfPresent(String.self, forKey: .cardNetwork) ?? ""
|
|
104
|
+
cardIsin = try container.decodeIfPresent(String.self, forKey: .cardIsin) ?? ""
|
|
105
|
+
cardIssuer = try container.decodeIfPresent(String.self, forKey: .cardIssuer) ?? ""
|
|
106
|
+
cardType = try container.decodeIfPresent(String.self, forKey: .cardType) ?? ""
|
|
107
|
+
savedToLocker = try container.decodeIfPresent(Bool.self, forKey: .savedToLocker) ?? false
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
enum CodingKeys: String, CodingKey {
|
|
111
|
+
case scheme
|
|
112
|
+
case issuerCountry = "issuer_country"
|
|
113
|
+
case last4Digits = "last4_digits"
|
|
114
|
+
case expiryMonth = "expiry_month"
|
|
115
|
+
case expiryYear = "expiry_year"
|
|
116
|
+
case cardToken = "card_token"
|
|
117
|
+
case cardHolderName = "card_holder_name"
|
|
118
|
+
case cardFingerprint = "card_fingerprint"
|
|
119
|
+
case nickName = "nick_name"
|
|
120
|
+
case cardNetwork = "card_network"
|
|
121
|
+
case cardIsin = "card_isin"
|
|
122
|
+
case cardIssuer = "card_issuer"
|
|
123
|
+
case cardType = "card_type"
|
|
124
|
+
case savedToLocker = "saved_to_locker"
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/// Represents an error state in payment method retrieval
|
|
129
|
+
public struct PMError: Codable, Error {
|
|
130
|
+
public let code: String
|
|
131
|
+
public let message: String
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/// Handler for payment session operations
|
|
135
|
+
public struct PaymentSessionHandler {
|
|
136
|
+
public let getCustomerDefaultSavedPaymentMethodData: () -> Result<PaymentMethod, PMError>
|
|
137
|
+
public let getCustomerLastUsedPaymentMethodData: () -> Result<PaymentMethod, PMError>
|
|
138
|
+
public let getCustomerSavedPaymentMethodData: () -> Result<[PaymentMethod], PMError>
|
|
139
|
+
private let confirmWithCustomerDefaultPaymentMethod: (_ cvc: String?, _ resultHandler: @escaping (PaymentResult) -> Void) -> Void
|
|
140
|
+
private let confirmWithCustomerLastUsedPaymentMethod:
|
|
141
|
+
(_ cvcWidget: CVCWidget, _ resultHandler: @escaping (PaymentResult) -> Void) -> Void
|
|
142
|
+
private let confirmWithCustomerPaymentToken:
|
|
143
|
+
(_ paymentToken: String, _ cvc: String?, _ resultHandler: @escaping (PaymentResult) -> Void) -> Void
|
|
144
|
+
|
|
145
|
+
public init(
|
|
146
|
+
getCustomerDefaultSavedPaymentMethodData: @escaping () -> Result<PaymentMethod, PMError>,
|
|
147
|
+
getCustomerLastUsedPaymentMethodData: @escaping () -> Result<PaymentMethod, PMError>,
|
|
148
|
+
getCustomerSavedPaymentMethodData: @escaping () -> Result<[PaymentMethod], PMError>,
|
|
149
|
+
confirmWithCustomerDefaultPaymentMethod: @escaping (_ cvc: String?, _ resultHandler: @escaping (PaymentResult) -> Void) -> Void,
|
|
150
|
+
confirmWithCustomerLastUsedPaymentMethod:
|
|
151
|
+
@escaping (_ cvcWidget: CVCWidget, _ resultHandler: @escaping (PaymentResult) -> Void) -> Void,
|
|
152
|
+
confirmWithCustomerPaymentToken:
|
|
153
|
+
@escaping (_ paymentToken: String, _ cvc: String?, _ resultHandler: @escaping (PaymentResult) -> Void) -> Void
|
|
154
|
+
) {
|
|
155
|
+
self.getCustomerDefaultSavedPaymentMethodData = getCustomerDefaultSavedPaymentMethodData
|
|
156
|
+
self.getCustomerLastUsedPaymentMethodData = getCustomerLastUsedPaymentMethodData
|
|
157
|
+
self.getCustomerSavedPaymentMethodData = getCustomerSavedPaymentMethodData
|
|
158
|
+
self.confirmWithCustomerDefaultPaymentMethod = confirmWithCustomerDefaultPaymentMethod
|
|
159
|
+
self.confirmWithCustomerLastUsedPaymentMethod = confirmWithCustomerLastUsedPaymentMethod
|
|
160
|
+
self.confirmWithCustomerPaymentToken = confirmWithCustomerPaymentToken
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
public func confirmWithCustomerDefaultPaymentMethod(resultHandler: @escaping (PaymentResult) -> Void) {
|
|
164
|
+
confirmWithCustomerDefaultPaymentMethod(nil, resultHandler)
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
public func confirmWithCustomerLastUsedPaymentMethod(_ cvcWidget: CVCWidget, resultHandler: @escaping (PaymentResult) -> Void) {
|
|
168
|
+
confirmWithCustomerLastUsedPaymentMethod(cvcWidget, resultHandler)
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
public func confirmWithCustomerPaymentToken(paymentToken: String, resultHandler: @escaping (PaymentResult) -> Void) {
|
|
172
|
+
confirmWithCustomerPaymentToken(paymentToken, nil, resultHandler)
|
|
173
|
+
}
|
|
174
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
//
|
|
2
|
+
// HyperHeadless.m
|
|
3
|
+
// Hyperswitch
|
|
4
|
+
//
|
|
5
|
+
// Created by Shivam Shashank on 06/03/24.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
#import <React/RCTEventEmitter.h>
|
|
9
|
+
|
|
10
|
+
@interface RCT_EXTERN_MODULE(HyperHeadless, RCTEventEmitter)
|
|
11
|
+
|
|
12
|
+
RCT_EXTERN_METHOD(getPaymentSession: (nonnull NSNumber *)rootTag :(NSDictionary)rnMessage :(NSDictionary)rnMessage2 :(NSArray)rnMessage3 :(RCTResponseSenderBlock)rnCallback)
|
|
13
|
+
RCT_EXTERN_METHOD(exitHeadless: (nonnull NSNumber *)rootTag: (NSString)rnMessage)
|
|
14
|
+
|
|
15
|
+
@end
|