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,75 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Codable+UIKit.swift
|
|
3
|
+
// hyperswitch
|
|
4
|
+
//
|
|
5
|
+
// Created by Harshit Srivastava on 09/10/25.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
import UIKit
|
|
9
|
+
|
|
10
|
+
// MARK: - CodableColor Wrapper
|
|
11
|
+
public struct CodableColor: Codable, Equatable {
|
|
12
|
+
private let wrapped: UIColor
|
|
13
|
+
|
|
14
|
+
public init(_ color: UIColor) {
|
|
15
|
+
self.wrapped = color
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// Accessor for UIKit API compatibility
|
|
19
|
+
public var uiColor: UIColor { wrapped }
|
|
20
|
+
|
|
21
|
+
public func encode(to encoder: Encoder) throws {
|
|
22
|
+
var container = encoder.singleValueContainer()
|
|
23
|
+
guard let hex = wrapped.hexString else {
|
|
24
|
+
throw EncodingError.invalidValue(
|
|
25
|
+
wrapped,
|
|
26
|
+
EncodingError.Context(
|
|
27
|
+
codingPath: container.codingPath,
|
|
28
|
+
debugDescription: "Failed to encode UIColor to hex"
|
|
29
|
+
)
|
|
30
|
+
)
|
|
31
|
+
}
|
|
32
|
+
try container.encode(hex)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
public init(from decoder: Decoder) throws {
|
|
36
|
+
let container = try decoder.singleValueContainer()
|
|
37
|
+
let hex = try container.decode(String.self)
|
|
38
|
+
guard let decoded = UIColor(hexString: hex) else {
|
|
39
|
+
throw DecodingError.dataCorruptedError(
|
|
40
|
+
in: container,
|
|
41
|
+
debugDescription: "Invalid hex string: \(hex)"
|
|
42
|
+
)
|
|
43
|
+
}
|
|
44
|
+
self.wrapped = decoded
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// MARK: - CodableFont Wrapper
|
|
49
|
+
public struct CodableFont: Codable, Equatable {
|
|
50
|
+
private let wrapped: UIFont
|
|
51
|
+
|
|
52
|
+
public init(_ font: UIFont) {
|
|
53
|
+
self.wrapped = font
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Accessor for UIKit API compatibility
|
|
57
|
+
public var uiFont: UIFont { wrapped }
|
|
58
|
+
|
|
59
|
+
public func encode(to encoder: Encoder) throws {
|
|
60
|
+
var container = encoder.singleValueContainer()
|
|
61
|
+
try container.encode(wrapped.fontName)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
public init(from decoder: Decoder) throws {
|
|
65
|
+
let container = try decoder.singleValueContainer()
|
|
66
|
+
let name = try container.decode(String.self)
|
|
67
|
+
guard let decodedFont = UIFont(name: name, size: .zero) else {
|
|
68
|
+
throw DecodingError.dataCorruptedError(
|
|
69
|
+
in: container,
|
|
70
|
+
debugDescription: "Invalid font name: \(name)"
|
|
71
|
+
)
|
|
72
|
+
}
|
|
73
|
+
self.wrapped = decodedFont
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
//
|
|
2
|
+
// CustomEndpointConfiguration.swift
|
|
3
|
+
// HyperswitchCore
|
|
4
|
+
//
|
|
5
|
+
// Created by Harshit Srivastava on 17/05/26.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
public enum CustomEndpointConfiguration: Codable {
|
|
9
|
+
case commonEndpoint(String)
|
|
10
|
+
case overrideEndpoints(OverrideEndpointConfiguration)
|
|
11
|
+
|
|
12
|
+
private enum CodingKeys: String, CodingKey {
|
|
13
|
+
case commonEndpoint
|
|
14
|
+
case overrideEndpoints
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
public func encode(to encoder: Encoder) throws {
|
|
18
|
+
var container = encoder.container(keyedBy: CodingKeys.self)
|
|
19
|
+
switch self {
|
|
20
|
+
case .commonEndpoint(let value):
|
|
21
|
+
try container.encode(value, forKey: .commonEndpoint)
|
|
22
|
+
case .overrideEndpoints(let config):
|
|
23
|
+
try container.encode(config, forKey: .overrideEndpoints)
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
public init(from decoder: Decoder) throws {
|
|
28
|
+
let container = try decoder.container(keyedBy: CodingKeys.self)
|
|
29
|
+
if let value = try container.decodeIfPresent(String.self, forKey: .commonEndpoint) {
|
|
30
|
+
self = .commonEndpoint(value)
|
|
31
|
+
} else if let config = try container.decodeIfPresent(OverrideEndpointConfiguration.self, forKey: .overrideEndpoints) {
|
|
32
|
+
self = .overrideEndpoints(config)
|
|
33
|
+
} else {
|
|
34
|
+
throw DecodingError.dataCorrupted(
|
|
35
|
+
DecodingError.Context(
|
|
36
|
+
codingPath: decoder.codingPath,
|
|
37
|
+
debugDescription: ""
|
|
38
|
+
)
|
|
39
|
+
)
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
public struct OverrideEndpointConfiguration: Codable {
|
|
45
|
+
let customBackendEndpoint: String?
|
|
46
|
+
let customAssetEndpoint: String?
|
|
47
|
+
let customSDKConfigEndpoint: String?
|
|
48
|
+
let customConfirmEndpoint: String?
|
|
49
|
+
let customAirborneEndpoint: String?
|
|
50
|
+
let customLoggingEndpoint: String?
|
|
51
|
+
|
|
52
|
+
public init(
|
|
53
|
+
customBackendEndpoint: String? = nil,
|
|
54
|
+
customAssetEndpoint: String? = nil,
|
|
55
|
+
customSDKConfigEndpoint: String? = nil,
|
|
56
|
+
customConfirmEndpoint: String? = nil,
|
|
57
|
+
customAirborneEndpoint: String? = nil,
|
|
58
|
+
customLoggingEndpoint: String? = nil
|
|
59
|
+
) {
|
|
60
|
+
self.customBackendEndpoint = customBackendEndpoint
|
|
61
|
+
self.customAssetEndpoint = customAssetEndpoint
|
|
62
|
+
self.customSDKConfigEndpoint = customSDKConfigEndpoint
|
|
63
|
+
self.customConfirmEndpoint = customConfirmEndpoint
|
|
64
|
+
self.customAirborneEndpoint = customAirborneEndpoint
|
|
65
|
+
self.customLoggingEndpoint = customLoggingEndpoint
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
//
|
|
2
|
+
// DictionaryConverter.swift
|
|
3
|
+
// Hyperswitch
|
|
4
|
+
//
|
|
5
|
+
// Created by Balaganesh on 20/12/22.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
import Foundation
|
|
9
|
+
import UIKit
|
|
10
|
+
|
|
11
|
+
protocol DictionaryConverter {
|
|
12
|
+
func toDictionary() -> [String: Any]
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
extension DictionaryConverter {
|
|
16
|
+
|
|
17
|
+
/// Helper function to convert a UIColor to a hexadecimal string representation.
|
|
18
|
+
func hexStringFromColor(color: UIColor) -> String {
|
|
19
|
+
let cgColorInRGB = color.cgColor.converted(to: CGColorSpace(name: CGColorSpace.sRGB)!, intent: .defaultIntent, options: nil)!
|
|
20
|
+
let colorRef = cgColorInRGB.components
|
|
21
|
+
let r = colorRef?[0] ?? 0
|
|
22
|
+
let g = colorRef?[1] ?? 0
|
|
23
|
+
let b = ((colorRef?.count ?? 0) > 2 ? colorRef?[2] : g) ?? 0
|
|
24
|
+
let a = color.cgColor.alpha
|
|
25
|
+
|
|
26
|
+
var color = String(
|
|
27
|
+
format: "#%02lX%02lX%02lX",
|
|
28
|
+
lroundf(Float(r * 255)),
|
|
29
|
+
lroundf(Float(g * 255)),
|
|
30
|
+
lroundf(Float(b * 255))
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
if a < 1 {
|
|
34
|
+
color += String(format: "%02lX", lroundf(Float(a * 255)))
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return color
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/// Function to convert the current instance to a dictionary.
|
|
41
|
+
func toDictionary() -> [String: Any] {
|
|
42
|
+
let reflect = Mirror(reflecting: self)
|
|
43
|
+
let children = reflect.children
|
|
44
|
+
let dictionary = toAnyHashable(elements: children)
|
|
45
|
+
return dictionary
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/// Recursive helper function to convert the properties of an instance to a dictionary.
|
|
49
|
+
func toAnyHashable(elements: AnyCollection<Mirror.Child>) -> [String: Any] {
|
|
50
|
+
var dictionary: [String: Any] = [:]
|
|
51
|
+
for element in elements {
|
|
52
|
+
if let key = element.label {
|
|
53
|
+
|
|
54
|
+
if let value = element.value as? AnyHashable {
|
|
55
|
+
if "\(value)" == "nil" {
|
|
56
|
+
continue
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
let isEnumValue = Mirror(reflecting: element.value).displayStyle == .enum
|
|
61
|
+
|
|
62
|
+
if let collectionValidHashable = element.value as? [AnyHashable] {
|
|
63
|
+
dictionary[key] = collectionValidHashable
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if let validHashable = element.value as? AnyHashable {
|
|
67
|
+
if isEnumValue {
|
|
68
|
+
dictionary[key] = "\(validHashable)"
|
|
69
|
+
} else {
|
|
70
|
+
dictionary[key] = validHashable
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/// Handle Theme values
|
|
75
|
+
if let theme = element.value as? PaymentSheet.Appearance.Theme {
|
|
76
|
+
dictionary[key] = theme.themeLabel
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/// Handle UIColor values
|
|
80
|
+
if let color = element.value as? UIColor {
|
|
81
|
+
dictionary[key] = self.hexStringFromColor(color: color)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/// Handle UIFont values
|
|
85
|
+
if let font = element.value as? UIFont {
|
|
86
|
+
dictionary[key] = font.fontName
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if let convertor = element.value as? DictionaryConverter {
|
|
90
|
+
if !isEnumValue {
|
|
91
|
+
dictionary[key] = convertor.toDictionary()
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if let convertorList = element.value as? [DictionaryConverter] {
|
|
96
|
+
dictionary[key] = convertorList.map({ e in
|
|
97
|
+
e.toDictionary()
|
|
98
|
+
})
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return dictionary
|
|
103
|
+
}
|
|
104
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Environment.swift
|
|
3
|
+
// hyperswitch
|
|
4
|
+
//
|
|
5
|
+
// Created by Kuntimaddi Manideep on 24/01/25.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
import Foundation
|
|
9
|
+
|
|
10
|
+
enum SDKEnvironment {
|
|
11
|
+
case PROD, SANDBOX
|
|
12
|
+
|
|
13
|
+
static func getEnvironment(_ publishableKey: String) -> SDKEnvironment {
|
|
14
|
+
return publishableKey.contains("_snd_") ? .SANDBOX : .PROD
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
static func baseURL(for publishableKey: String) -> String {
|
|
18
|
+
return getEnvironment(publishableKey) == .PROD ? "https://api.hyperswitch.io" : "https://sandbox.hyperswitch.io"
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
static func loggingURL(for publishableKey: String) -> String {
|
|
22
|
+
return "\(baseURL(for: publishableKey))/logs/sdk"
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Extensions.swift
|
|
3
|
+
// hyperswitch
|
|
4
|
+
//
|
|
5
|
+
// Created by Harshit Srivastava on 05/09/24.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
import Foundation
|
|
9
|
+
import UIKit
|
|
10
|
+
|
|
11
|
+
internal extension UIColor {
|
|
12
|
+
static func dynamic(light: UIColor, dark: UIColor) -> UIColor {
|
|
13
|
+
return UIColor(dynamicProvider: { (traitCollection) in
|
|
14
|
+
switch traitCollection.userInterfaceStyle {
|
|
15
|
+
case .light, .unspecified:
|
|
16
|
+
return light
|
|
17
|
+
case .dark:
|
|
18
|
+
return dark
|
|
19
|
+
@unknown default:
|
|
20
|
+
return light
|
|
21
|
+
}
|
|
22
|
+
})
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
internal extension String {
|
|
27
|
+
func toJSON() -> Any? {
|
|
28
|
+
guard let data = self.data(using: .utf8, allowLossyConversion: false) else { return nil }
|
|
29
|
+
return try? JSONSerialization.jsonObject(with: data, options: .mutableContainers)
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
internal extension Encodable {
|
|
34
|
+
func toDictionary() throws -> [String: Any] {
|
|
35
|
+
let data = try JSONEncoder().encode(self)
|
|
36
|
+
guard let dict = try JSONSerialization.jsonObject(with: data) as? [String: Any] else {
|
|
37
|
+
throw NSError(domain: "Encoding", code: 0)
|
|
38
|
+
}
|
|
39
|
+
return dict
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
internal extension UIColor {
|
|
44
|
+
/// Convert UIColor to hex string (#RRGGBB or #RRGGBBAA if alpha < 1)
|
|
45
|
+
var hexString: String? {
|
|
46
|
+
guard let sRGB = CGColorSpace(name: CGColorSpace.sRGB),
|
|
47
|
+
let cgColorInRGB = cgColor.converted(
|
|
48
|
+
to: sRGB,
|
|
49
|
+
intent: .defaultIntent,
|
|
50
|
+
options: nil
|
|
51
|
+
),
|
|
52
|
+
let comps = cgColorInRGB.components
|
|
53
|
+
else {
|
|
54
|
+
return nil
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
let r = comps.count > 0 ? comps[0] : 0
|
|
58
|
+
let g = comps.count > 1 ? comps[1] : 0
|
|
59
|
+
let b = comps.count > 2 ? comps[2] : 0
|
|
60
|
+
let a = cgColor.alpha
|
|
61
|
+
|
|
62
|
+
var hex = String(
|
|
63
|
+
format: "#%02lX%02lX%02lX",
|
|
64
|
+
lroundf(Float(r * 255)),
|
|
65
|
+
lroundf(Float(g * 255)),
|
|
66
|
+
lroundf(Float(b * 255))
|
|
67
|
+
)
|
|
68
|
+
if a < 1 {
|
|
69
|
+
hex += String(format: "%02lX", lroundf(Float(a * 255)))
|
|
70
|
+
}
|
|
71
|
+
return hex
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/// Initialize UIColor from hex string (#RRGGBB or #RRGGBBAA)
|
|
75
|
+
convenience init?(hexString: String) {
|
|
76
|
+
var hex = hexString.trimmingCharacters(in: .whitespacesAndNewlines)
|
|
77
|
+
hex = hex.replacingOccurrences(of: "#", with: "")
|
|
78
|
+
|
|
79
|
+
var rgb: UInt64 = 0
|
|
80
|
+
guard Scanner(string: hex).scanHexInt64(&rgb) else { return nil }
|
|
81
|
+
|
|
82
|
+
switch hex.count {
|
|
83
|
+
case 6:
|
|
84
|
+
self.init(
|
|
85
|
+
red: CGFloat((rgb & 0xFF0000) >> 16) / 255,
|
|
86
|
+
green: CGFloat((rgb & 0x00FF00) >> 8) / 255,
|
|
87
|
+
blue: CGFloat(rgb & 0x0000FF) / 255,
|
|
88
|
+
alpha: 1.0
|
|
89
|
+
)
|
|
90
|
+
case 8:
|
|
91
|
+
self.init(
|
|
92
|
+
red: CGFloat((rgb & 0xFF000000) >> 24) / 255,
|
|
93
|
+
green: CGFloat((rgb & 0x00FF0000) >> 16) / 255,
|
|
94
|
+
blue: CGFloat((rgb & 0x0000FF00) >> 8) / 255,
|
|
95
|
+
alpha: CGFloat(rgb & 0x000000FF) / 255
|
|
96
|
+
)
|
|
97
|
+
default:
|
|
98
|
+
return nil
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Helper.swift
|
|
3
|
+
// hyperswitch
|
|
4
|
+
//
|
|
5
|
+
// Created by Harshit Srivastava on 22/10/24.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
import Foundation
|
|
9
|
+
|
|
10
|
+
enum Helper {
|
|
11
|
+
|
|
12
|
+
static func getInfoPlist(_ key: String) -> String? {
|
|
13
|
+
guard let infoDictionary = Bundle.main.infoDictionary,
|
|
14
|
+
let value = infoDictionary[key] as? String, !value.isEmpty
|
|
15
|
+
else {
|
|
16
|
+
return nil
|
|
17
|
+
}
|
|
18
|
+
return value
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/// Dedicated serial queue protecting the read-then-write block
|
|
22
|
+
private static let uuidQueue = DispatchQueue(label: "io.hyperswitch.helper.uuid")
|
|
23
|
+
|
|
24
|
+
static func persistentUUID(for flow: String) -> String {
|
|
25
|
+
uuidQueue.sync {
|
|
26
|
+
/// never call this using another uuidQueue.sync (deadlock)
|
|
27
|
+
let safeFlow = flow.lowercased().replacingOccurrences(of: " ", with: "_")
|
|
28
|
+
let key = "uuid_\(safeFlow)"
|
|
29
|
+
let defaults = UserDefaults.standard
|
|
30
|
+
|
|
31
|
+
if let existing = defaults.string(forKey: key) {
|
|
32
|
+
return existing
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
let newUUID = UUID().uuidString
|
|
36
|
+
defaults.set(newUUID, forKey: key)
|
|
37
|
+
return newUUID
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
//
|
|
2
|
+
// PaymentEventData.swift
|
|
3
|
+
// Hyperswitch
|
|
4
|
+
//
|
|
5
|
+
// Created by Harshit Srivastava on 21/04/26.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
import Foundation
|
|
9
|
+
|
|
10
|
+
public enum PaymentEventData {
|
|
11
|
+
|
|
12
|
+
case cardInfo(CardInfo)
|
|
13
|
+
case paymentMethodStatus(PaymentMethodStatus)
|
|
14
|
+
case formStatus(FormStatusEvent)
|
|
15
|
+
case paymentMethodInfoAddress(PaymentMethodInfoAddress)
|
|
16
|
+
case cvcStatus(CvcStatus)
|
|
17
|
+
|
|
18
|
+
public struct CardInfo: Sendable {
|
|
19
|
+
public let bin: String?
|
|
20
|
+
public let last4: String?
|
|
21
|
+
public let brand: String?
|
|
22
|
+
public let expiryMonth: String?
|
|
23
|
+
public let expiryYear: String?
|
|
24
|
+
public let formattedExpiry: String?
|
|
25
|
+
public let isCardNumberComplete: Bool
|
|
26
|
+
public let isCvcComplete: Bool
|
|
27
|
+
public let isExpiryComplete: Bool
|
|
28
|
+
public let isCardNumberValid: Bool
|
|
29
|
+
public let isExpiryValid: Bool
|
|
30
|
+
|
|
31
|
+
static func from(_ map: [String: Any]) -> CardInfo {
|
|
32
|
+
CardInfo(
|
|
33
|
+
bin: map["bin"] as? String,
|
|
34
|
+
last4: map["last4"] as? String,
|
|
35
|
+
brand: map["brand"] as? String,
|
|
36
|
+
expiryMonth: map["expiryMonth"] as? String,
|
|
37
|
+
expiryYear: map["expiryYear"] as? String,
|
|
38
|
+
formattedExpiry: map["formattedExpiry"] as? String,
|
|
39
|
+
isCardNumberComplete: map["isCardNumberComplete"] as? Bool ?? false,
|
|
40
|
+
isCvcComplete: map["isCvcComplete"] as? Bool ?? false,
|
|
41
|
+
isExpiryComplete: map["isExpiryComplete"] as? Bool ?? false,
|
|
42
|
+
isCardNumberValid: map["isCardNumberValid"] as? Bool ?? false,
|
|
43
|
+
isExpiryValid: map["isExpiryValid"] as? Bool ?? false
|
|
44
|
+
)
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
public struct PaymentMethodStatus: Sendable {
|
|
49
|
+
public let paymentMethod: String
|
|
50
|
+
public let paymentMethodType: String
|
|
51
|
+
public let isSavedPaymentMethod: Bool
|
|
52
|
+
public let isOneClickWallet: Bool
|
|
53
|
+
|
|
54
|
+
static func from(_ map: [String: Any]) -> PaymentMethodStatus {
|
|
55
|
+
PaymentMethodStatus(
|
|
56
|
+
paymentMethod: map["paymentMethod"] as? String ?? "",
|
|
57
|
+
paymentMethodType: map["paymentMethodType"] as? String ?? "",
|
|
58
|
+
isSavedPaymentMethod: map["isSavedPaymentMethod"] as? Bool ?? false,
|
|
59
|
+
isOneClickWallet: map["isOneClickWallet"] as? Bool ?? false
|
|
60
|
+
)
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
public enum FormStatusValue: String, Sendable {
|
|
65
|
+
case empty = "EMPTY"
|
|
66
|
+
case filling = "FILLING"
|
|
67
|
+
case complete = "COMPLETE"
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
public struct FormStatusEvent: Sendable {
|
|
71
|
+
public let status: FormStatusValue?
|
|
72
|
+
|
|
73
|
+
static func from(_ map: [String: Any]) -> FormStatusEvent {
|
|
74
|
+
FormStatusEvent(status: (map["status"] as? String).flatMap(FormStatusValue.init(rawValue:)))
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
public struct PaymentMethodInfoAddress: Sendable {
|
|
79
|
+
public let country: String
|
|
80
|
+
public let state: String
|
|
81
|
+
public let postalCode: String
|
|
82
|
+
|
|
83
|
+
static func from(_ map: [String: Any]) -> PaymentMethodInfoAddress {
|
|
84
|
+
PaymentMethodInfoAddress(
|
|
85
|
+
country: map["country"] as? String ?? "",
|
|
86
|
+
state: map["state"] as? String ?? "",
|
|
87
|
+
postalCode: map["postalCode"] as? String ?? ""
|
|
88
|
+
)
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
public struct CvcStatus: Sendable {
|
|
93
|
+
public let isCvcFocused: Bool
|
|
94
|
+
public let isCvcBlur: Bool
|
|
95
|
+
public let isCvcEmpty: Bool
|
|
96
|
+
public let isCvcComplete: Bool
|
|
97
|
+
|
|
98
|
+
static func from(_ map: [String: Any]) -> CvcStatus {
|
|
99
|
+
let source = (map["cvcStatus"] as? [String: Any]) ?? map
|
|
100
|
+
return CvcStatus(
|
|
101
|
+
isCvcFocused: source["isCvcFocused"] as? Bool ?? false,
|
|
102
|
+
isCvcBlur: source["isCvcBlur"] as? Bool ?? false,
|
|
103
|
+
isCvcEmpty: source["isCvcEmpty"] as? Bool ?? true,
|
|
104
|
+
isCvcComplete: source["isCvcComplete"] as? Bool ?? false
|
|
105
|
+
)
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
public static func from(type: String, payload: [String: Any]) -> PaymentEventData? {
|
|
110
|
+
switch type {
|
|
111
|
+
case PaymentEventType.paymentMethodInfoCard.rawValue:
|
|
112
|
+
return .cardInfo(.from(payload))
|
|
113
|
+
case PaymentEventType.paymentMethodStatus.rawValue:
|
|
114
|
+
return .paymentMethodStatus(.from(payload))
|
|
115
|
+
case PaymentEventType.formStatus.rawValue:
|
|
116
|
+
return .formStatus(.from(payload))
|
|
117
|
+
case PaymentEventType.paymentMethodInfoBillingAddress.rawValue:
|
|
118
|
+
return .paymentMethodInfoAddress(.from(payload))
|
|
119
|
+
case PaymentEventType.cvcStatus.rawValue:
|
|
120
|
+
return .cvcStatus(.from(payload))
|
|
121
|
+
default:
|
|
122
|
+
return nil
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
//
|
|
2
|
+
// PaymentEventSubscriptionBuilder.swift
|
|
3
|
+
// Hyperswitch
|
|
4
|
+
//
|
|
5
|
+
// Created by Harshit Srivastava on 21/04/26.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
import Foundation
|
|
9
|
+
|
|
10
|
+
public final class PaymentEventSubscriptionBuilder {
|
|
11
|
+
private var handlers: [PaymentEventType: (PaymentEvent) -> Void] = [:]
|
|
12
|
+
|
|
13
|
+
public init() {}
|
|
14
|
+
|
|
15
|
+
public func on(_ eventType: PaymentEventType, _ handler: @escaping (PaymentEvent) -> Void) {
|
|
16
|
+
handlers[eventType] = handler
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
internal func build() -> (subscription: PaymentEventSubscription, listener: PaymentEventListener) {
|
|
20
|
+
let dispatch: [String: (PaymentEvent) -> Void] = Dictionary(
|
|
21
|
+
uniqueKeysWithValues: handlers.map { ($0.key.rawValue, $0.value) }
|
|
22
|
+
)
|
|
23
|
+
let subscription = PaymentEventSubscription(eventTypes: Array(handlers.keys))
|
|
24
|
+
let listener = PaymentEventListener { event in
|
|
25
|
+
dispatch[event.type]?(event)
|
|
26
|
+
}
|
|
27
|
+
return (subscription, listener)
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
public struct PaymentEventSubscription: Sendable {
|
|
32
|
+
public let eventTypes: [PaymentEventType]
|
|
33
|
+
|
|
34
|
+
public func isSubscribed(_ rawType: String) -> Bool {
|
|
35
|
+
eventTypes.contains { $0.rawValue == rawType }
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
public func subscribedEventStrings() -> [String] {
|
|
39
|
+
eventTypes.map(\.rawValue)
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
internal struct PaymentEventListener {
|
|
44
|
+
let onPaymentEvent: (PaymentEvent) -> Void
|
|
45
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
//
|
|
2
|
+
// PaymentEventType.swift
|
|
3
|
+
// Hyperswitch
|
|
4
|
+
//
|
|
5
|
+
// Created by Harshit Srivastava on 21/04/26.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
import Foundation
|
|
9
|
+
|
|
10
|
+
public enum PaymentEventType: String, CaseIterable, Sendable {
|
|
11
|
+
case paymentMethodInfoCard = "PAYMENT_METHOD_INFO_CARD"
|
|
12
|
+
case paymentMethodStatus = "PAYMENT_METHOD_STATUS"
|
|
13
|
+
case formStatus = "FORM_STATUS"
|
|
14
|
+
case paymentMethodInfoBillingAddress = "PAYMENT_METHOD_INFO_BILLING_ADDRESS"
|
|
15
|
+
case cvcStatus = "CVC_STATUS"
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
public struct PaymentEvent {
|
|
19
|
+
public let type: String
|
|
20
|
+
public let payload: [String: Any]
|
|
21
|
+
|
|
22
|
+
public var data: PaymentEventData? {
|
|
23
|
+
PaymentEventData.from(type: type, payload: payload)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
public init(type: String, payload: [String: Any]) {
|
|
27
|
+
self.type = type
|
|
28
|
+
self.payload = payload
|
|
29
|
+
}
|
|
30
|
+
}
|