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,151 @@
|
|
|
1
|
+
//
|
|
2
|
+
// HyperswitchNetworking.swift
|
|
3
|
+
// hyperswitch
|
|
4
|
+
//
|
|
5
|
+
// Created by Kuntimaddi Manideep on 24/01/25.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
import Foundation
|
|
9
|
+
|
|
10
|
+
// MARK: HTTP Methods
|
|
11
|
+
enum HTTPMethod: String, Encodable {
|
|
12
|
+
case get = "GET"
|
|
13
|
+
case head = "HEAD"
|
|
14
|
+
case post = "POST"
|
|
15
|
+
case put = "PUT"
|
|
16
|
+
case delete = "DELETE"
|
|
17
|
+
case connect = "CONNECT"
|
|
18
|
+
case options = "OPTIONS"
|
|
19
|
+
case trace = "TRACE"
|
|
20
|
+
case patch = "PATCH"
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// MARK: HTTPClient
|
|
24
|
+
/// The protocol used to define the specifications necessary for a `HTTPClient`.
|
|
25
|
+
protocol HTTPClient {
|
|
26
|
+
/// The host, conforming to RFC 1808.
|
|
27
|
+
var host: String { get }
|
|
28
|
+
|
|
29
|
+
/// The path, conforming to RFC 1808
|
|
30
|
+
var path: String { get }
|
|
31
|
+
|
|
32
|
+
/// API Endpoint
|
|
33
|
+
var endpoint: String { get }
|
|
34
|
+
|
|
35
|
+
/// The HTTP method used in the request.
|
|
36
|
+
var method: HTTPMethod { get }
|
|
37
|
+
|
|
38
|
+
/// The HTTP JSON request parameters.
|
|
39
|
+
var jsonParameters: [String: Any]? { get }
|
|
40
|
+
|
|
41
|
+
/// The HTTP Data request parameters.
|
|
42
|
+
var bodyData: Data? { get }
|
|
43
|
+
|
|
44
|
+
/// A dictionary containing all the HTTP header fields
|
|
45
|
+
var headers: [String: String]? { get }
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/// HTTPClient Errors
|
|
49
|
+
enum HTTPClientError: Error {
|
|
50
|
+
case badURL
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
extension HTTPClient {
|
|
54
|
+
/// The URL of the receiver.
|
|
55
|
+
fileprivate var url: String {
|
|
56
|
+
return host + path + endpoint
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
func request<T: Codable>(type: T.Type, completionHandler: @escaping (Result<T, Error>, Int) -> Void) {
|
|
60
|
+
guard let url = URL(string: url) else {
|
|
61
|
+
completionHandler(.failure(HTTPClientError.badURL), 400)
|
|
62
|
+
return
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
var request = URLRequest(url: url)
|
|
66
|
+
request.httpMethod = method.rawValue
|
|
67
|
+
request.allHTTPHeaderFields = headers
|
|
68
|
+
request.cachePolicy = .reloadIgnoringLocalAndRemoteCacheData
|
|
69
|
+
|
|
70
|
+
if let parameters = jsonParameters {
|
|
71
|
+
do {
|
|
72
|
+
request.httpBody = try JSONSerialization.data(withJSONObject: parameters, options: [])
|
|
73
|
+
} catch {
|
|
74
|
+
completionHandler(.failure(error), 400)
|
|
75
|
+
return
|
|
76
|
+
}
|
|
77
|
+
} else if let bodyData = bodyData {
|
|
78
|
+
request.httpBody = bodyData
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
let configuration = URLSessionConfiguration.default
|
|
82
|
+
configuration.timeoutIntervalForRequest = 10.0 // 10 seconds
|
|
83
|
+
configuration.timeoutIntervalForResource = 10.0 // 10 seconds
|
|
84
|
+
let session = URLSession(configuration: configuration)
|
|
85
|
+
let dataTask = session.dataTask(
|
|
86
|
+
with: request,
|
|
87
|
+
completionHandler: { (data, response, error) -> Void in
|
|
88
|
+
var responseCode = 400
|
|
89
|
+
if let httpResponse = response as? HTTPURLResponse {
|
|
90
|
+
responseCode = httpResponse.statusCode
|
|
91
|
+
}
|
|
92
|
+
if let error = error {
|
|
93
|
+
completionHandler(.failure(error), responseCode)
|
|
94
|
+
return
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if let data = data {
|
|
98
|
+
do {
|
|
99
|
+
if T.self == Data.self {
|
|
100
|
+
completionHandler(.success(data as! T), responseCode)
|
|
101
|
+
} else {
|
|
102
|
+
completionHandler(.success(try JSONDecoder().decode(type, from: data)), responseCode)
|
|
103
|
+
}
|
|
104
|
+
} catch {
|
|
105
|
+
completionHandler(.failure(error), responseCode)
|
|
106
|
+
return
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
dataTask.resume()
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
class HTTPRequestService: HTTPClient {
|
|
117
|
+
|
|
118
|
+
let host: String
|
|
119
|
+
let path: String
|
|
120
|
+
let endpoint: String
|
|
121
|
+
let method: HTTPMethod
|
|
122
|
+
|
|
123
|
+
var jsonParameters: [String: Any]?
|
|
124
|
+
var bodyData: Data?
|
|
125
|
+
var headers: [String: String]?
|
|
126
|
+
|
|
127
|
+
init(
|
|
128
|
+
host: String,
|
|
129
|
+
path: String,
|
|
130
|
+
endpoint: String,
|
|
131
|
+
method: HTTPMethod,
|
|
132
|
+
jsonParameters: [String: Any]? = nil,
|
|
133
|
+
bodyData: Data? = nil,
|
|
134
|
+
headers: [String: String]? = nil
|
|
135
|
+
) {
|
|
136
|
+
self.host = host
|
|
137
|
+
self.path = path
|
|
138
|
+
self.endpoint = endpoint
|
|
139
|
+
self.method = method
|
|
140
|
+
self.jsonParameters = jsonParameters
|
|
141
|
+
self.bodyData = bodyData
|
|
142
|
+
self.headers = headers
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
func getDictionary() -> [String: Any] {
|
|
146
|
+
return [
|
|
147
|
+
"host": host, "path": path, "endpoint": endpoint, "method": method.rawValue, "jsonParameters": jsonParameters ?? "nil",
|
|
148
|
+
"headers": headers ?? "nil",
|
|
149
|
+
]
|
|
150
|
+
}
|
|
151
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
//
|
|
2
|
+
// HyperParams.swift
|
|
3
|
+
// hyperswitch
|
|
4
|
+
//
|
|
5
|
+
// Created by Shivam Nan on 15/01/25.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
import Foundation
|
|
9
|
+
import WebKit
|
|
10
|
+
|
|
11
|
+
class HyperParams {
|
|
12
|
+
static let appId: String? = Bundle.main.bundleIdentifier
|
|
13
|
+
static let sdkVersion: String = SDKVersion.current
|
|
14
|
+
static let country: String? = NSLocale.current.regionCode
|
|
15
|
+
static let userAgent: String? = WKWebView().value(forKey: "userAgent") as? String
|
|
16
|
+
static let deviceModel: String = UIDevice.current.model
|
|
17
|
+
static let osVersion: String = UIDevice.current.systemVersion
|
|
18
|
+
|
|
19
|
+
static func getSafeAreaInsets() -> UIEdgeInsets {
|
|
20
|
+
let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene
|
|
21
|
+
return windowScene?.windows.first?.safeAreaInsets ?? UIEdgeInsets.zero
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
static func getHyperParams() -> [String: Any?] {
|
|
25
|
+
|
|
26
|
+
let safeAreaInset = getSafeAreaInsets()
|
|
27
|
+
|
|
28
|
+
let params: [String: Any?] = [
|
|
29
|
+
"appId": appId,
|
|
30
|
+
"sdkVersion": sdkVersion,
|
|
31
|
+
"country": country,
|
|
32
|
+
"user-agent": userAgent,
|
|
33
|
+
"device_model": deviceModel,
|
|
34
|
+
"os_version": osVersion,
|
|
35
|
+
"os_type": "ios",
|
|
36
|
+
"launchTime": Int(Date().timeIntervalSince1970 * 1000),
|
|
37
|
+
"topInset": safeAreaInset.top,
|
|
38
|
+
"bottomInset": safeAreaInset.bottom,
|
|
39
|
+
"leftInset": safeAreaInset.left,
|
|
40
|
+
"rightInset": safeAreaInset.right,
|
|
41
|
+
]
|
|
42
|
+
return params
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
//
|
|
2
|
+
// HyperUIViewController.swift
|
|
3
|
+
// hyperswitch
|
|
4
|
+
//
|
|
5
|
+
// Created by Harshit Srivastava on 07/10/24.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
import Foundation
|
|
9
|
+
import UIKit
|
|
10
|
+
|
|
11
|
+
internal class HyperUIViewController: UIViewController {
|
|
12
|
+
internal var paymentSheet: PaymentSheet?
|
|
13
|
+
|
|
14
|
+
internal override var shouldAutorotate: Bool {
|
|
15
|
+
return false
|
|
16
|
+
}
|
|
17
|
+
internal override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
|
|
18
|
+
return UIInterfaceOrientationMask.portrait
|
|
19
|
+
}
|
|
20
|
+
internal override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation {
|
|
21
|
+
return UIInterfaceOrientation.portrait
|
|
22
|
+
}
|
|
23
|
+
internal override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {}
|
|
24
|
+
internal override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {}
|
|
25
|
+
internal override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {}
|
|
26
|
+
internal override func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent?) {}
|
|
27
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Hyperswitch.swift
|
|
3
|
+
// HyperswitchCore
|
|
4
|
+
//
|
|
5
|
+
// Created by Harshit Srivastava on 17/05/26.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
public final class Hyperswitch {
|
|
9
|
+
|
|
10
|
+
internal let hyperswitchConfiguration: HyperswitchConfiguration
|
|
11
|
+
|
|
12
|
+
public init(configuration: HyperswitchConfiguration) { // MARK: async on superposition impl
|
|
13
|
+
self.hyperswitchConfiguration = configuration
|
|
14
|
+
// Task {} Superposition
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
public func initPaymentSession(configuration: PaymentSessionConfiguration) -> PaymentSession {
|
|
18
|
+
PaymentSession(paymentSessionConfiguration: configuration, hyperswitchConfiguration: hyperswitchConfiguration)
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
//
|
|
2
|
+
// HyperswitchConfigurationSchema.swift
|
|
3
|
+
// HyperswitchCore
|
|
4
|
+
//
|
|
5
|
+
// Created by Harshit Srivastava on 17/05/26.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
private protocol HyperswitchConfigurationSchema {
|
|
9
|
+
var publishableKey: String { get }
|
|
10
|
+
var profileId: String? { get }
|
|
11
|
+
var customEndpoints: CustomEndpointConfiguration? { get }
|
|
12
|
+
var environment: HyperswitchEnvironment? { get }
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
public struct HyperswitchConfiguration: HyperswitchConfigurationSchema, Codable {
|
|
16
|
+
let publishableKey: String
|
|
17
|
+
let profileId: String?
|
|
18
|
+
let customEndpoints: CustomEndpointConfiguration?
|
|
19
|
+
let environment: HyperswitchEnvironment?
|
|
20
|
+
|
|
21
|
+
public init(
|
|
22
|
+
publishableKey: String,
|
|
23
|
+
profileId: String? = nil,
|
|
24
|
+
customEndpoints: CustomEndpointConfiguration? = nil,
|
|
25
|
+
environment: HyperswitchEnvironment? = nil
|
|
26
|
+
) {
|
|
27
|
+
self.publishableKey = publishableKey
|
|
28
|
+
self.profileId = profileId
|
|
29
|
+
self.customEndpoints = customEndpoints
|
|
30
|
+
self.environment = environment
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
public struct HyperswitchPlatformConfiguration: HyperswitchConfigurationSchema, Codable {
|
|
35
|
+
let platformPublishableKey: String
|
|
36
|
+
let publishableKey: String
|
|
37
|
+
let profileId: String?
|
|
38
|
+
let customEndpoints: CustomEndpointConfiguration?
|
|
39
|
+
let environment: HyperswitchEnvironment?
|
|
40
|
+
|
|
41
|
+
public init(
|
|
42
|
+
platformPublishableKey: String,
|
|
43
|
+
publishableKey: String,
|
|
44
|
+
profileId: String? = nil,
|
|
45
|
+
customEndpoints: CustomEndpointConfiguration? = nil,
|
|
46
|
+
environment: HyperswitchEnvironment? = nil
|
|
47
|
+
) {
|
|
48
|
+
self.platformPublishableKey = platformPublishableKey
|
|
49
|
+
self.publishableKey = publishableKey
|
|
50
|
+
self.profileId = profileId
|
|
51
|
+
self.customEndpoints = customEndpoints
|
|
52
|
+
self.environment = environment
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Debouncer.swift
|
|
3
|
+
// hyperswitch
|
|
4
|
+
//
|
|
5
|
+
// Created by Kuntimaddi Manideep on 24/01/25.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
import Foundation
|
|
9
|
+
|
|
10
|
+
final class Debouncer {
|
|
11
|
+
private let delay: TimeInterval
|
|
12
|
+
private var workItem: DispatchWorkItem?
|
|
13
|
+
private let queue: DispatchQueue
|
|
14
|
+
private let lock = NSLock()
|
|
15
|
+
|
|
16
|
+
init(delayInMillis: TimeInterval, queue: DispatchQueue = .main) {
|
|
17
|
+
self.delay = delayInMillis / 1000.0
|
|
18
|
+
self.queue = queue
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
func debounce(action: @escaping @Sendable () -> Void) {
|
|
22
|
+
lock.lock()
|
|
23
|
+
defer { lock.unlock() }
|
|
24
|
+
workItem?.cancel()
|
|
25
|
+
let task = DispatchWorkItem { action() }
|
|
26
|
+
workItem = task
|
|
27
|
+
queue.asyncAfter(deadline: .now() + delay, execute: task)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
func cancel() {
|
|
31
|
+
lock.lock()
|
|
32
|
+
defer { lock.unlock() }
|
|
33
|
+
|
|
34
|
+
workItem?.cancel()
|
|
35
|
+
workItem = nil
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
//
|
|
2
|
+
// LogBuilder.swift
|
|
3
|
+
// hyperswitch
|
|
4
|
+
//
|
|
5
|
+
// Created by Kuntimaddi Manideep on 24/01/25.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
import Foundation
|
|
9
|
+
|
|
10
|
+
internal class LogBuilder {
|
|
11
|
+
private var timestamp: String = ""
|
|
12
|
+
private var logType: LogType = .INFO
|
|
13
|
+
private var component: String = "MOBILE"
|
|
14
|
+
private var category: LogCategory = .OTA_LIFE_CYCLE
|
|
15
|
+
private var version: String = SDKVersion.current
|
|
16
|
+
private var codePushVersion: String = "" // MARK: replace with hyperOTAVersion
|
|
17
|
+
private var clientCoreVersion: String = ""
|
|
18
|
+
private var value: String = ""
|
|
19
|
+
private var internalMetadata: String = ""
|
|
20
|
+
private var sessionId: String = ""
|
|
21
|
+
private var merchantId: String = ""
|
|
22
|
+
private var paymentId: String = ""
|
|
23
|
+
private var authenticationId: String = ""
|
|
24
|
+
private var appId: String? = nil
|
|
25
|
+
private var platform: String = "IOS"
|
|
26
|
+
private var userAgent: String = ""
|
|
27
|
+
private var eventName: EventName = .hyperOTAInit
|
|
28
|
+
private var latency: String? = nil
|
|
29
|
+
private var firstEvent: Bool = false
|
|
30
|
+
private var paymentMethod: String? = nil
|
|
31
|
+
private var paymentExperience: String? = nil
|
|
32
|
+
private var source: String = ""
|
|
33
|
+
|
|
34
|
+
func setLogType(_ logType: String) -> LogBuilder {
|
|
35
|
+
switch logType.uppercased() {
|
|
36
|
+
case "ERROR":
|
|
37
|
+
self.logType = .ERROR
|
|
38
|
+
break
|
|
39
|
+
case "WARNING":
|
|
40
|
+
self.logType = .WARNING
|
|
41
|
+
break
|
|
42
|
+
case "DEBUG":
|
|
43
|
+
self.logType = .DEBUG
|
|
44
|
+
break
|
|
45
|
+
default:
|
|
46
|
+
self.logType = .INFO
|
|
47
|
+
}
|
|
48
|
+
return self
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
func setClientCoreVersion(_ clientCoreVersion: String) -> LogBuilder {
|
|
52
|
+
self.clientCoreVersion = clientCoreVersion
|
|
53
|
+
return self
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
func setValue(_ value: String) -> LogBuilder {
|
|
57
|
+
self.value = value
|
|
58
|
+
return self
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
func setEventName(_ eventName: EventName) -> LogBuilder {
|
|
62
|
+
self.eventName = eventName
|
|
63
|
+
return self
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
func setCategory(_ category: LogCategory) -> LogBuilder {
|
|
67
|
+
self.category = category
|
|
68
|
+
return self
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
func setPaymentId(_ paymentId: String) -> LogBuilder {
|
|
72
|
+
self.paymentId = paymentId
|
|
73
|
+
return self
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
func setAuthenticationId(_ authenticationId: String) -> LogBuilder {
|
|
77
|
+
self.authenticationId = authenticationId
|
|
78
|
+
return self
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
func setSessionId(_ sessionId: String) -> LogBuilder {
|
|
82
|
+
self.sessionId = sessionId
|
|
83
|
+
return self
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
func build() -> LogPayload {
|
|
87
|
+
self.timestamp = String(Int(Date().timeIntervalSince1970 * 1000))
|
|
88
|
+
return LogPayload(
|
|
89
|
+
timestamp: timestamp,
|
|
90
|
+
log_type: logType,
|
|
91
|
+
component: component,
|
|
92
|
+
category: category,
|
|
93
|
+
version: version,
|
|
94
|
+
code_push_version: codePushVersion,
|
|
95
|
+
client_core_version: clientCoreVersion,
|
|
96
|
+
value: value,
|
|
97
|
+
internal_metadata: internalMetadata,
|
|
98
|
+
session_id: sessionId,
|
|
99
|
+
merchant_id: merchantId,
|
|
100
|
+
payment_id: paymentId,
|
|
101
|
+
authentication_id: authenticationId,
|
|
102
|
+
app_id: appId,
|
|
103
|
+
platform: platform,
|
|
104
|
+
user_agent: userAgent,
|
|
105
|
+
event_name: eventName,
|
|
106
|
+
latency: latency,
|
|
107
|
+
first_event: firstEvent ? "true" : "false",
|
|
108
|
+
payment_method: paymentMethod,
|
|
109
|
+
payment_experience: paymentExperience,
|
|
110
|
+
source: source
|
|
111
|
+
)
|
|
112
|
+
}
|
|
113
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
//
|
|
2
|
+
// LogFileManager.swift
|
|
3
|
+
// hyperswitch
|
|
4
|
+
//
|
|
5
|
+
// Created by Kuntimaddi Manideep on 24/01/25.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
import Foundation
|
|
9
|
+
|
|
10
|
+
class LogFileManager {
|
|
11
|
+
private let logFileName = "crash_logs.json"
|
|
12
|
+
private let fileManager = FileManager.default
|
|
13
|
+
private let queue = DispatchQueue(label: "logfile.queue", attributes: .concurrent)
|
|
14
|
+
|
|
15
|
+
private func getLogFileName() -> URL? {
|
|
16
|
+
guard let documentDirectory = fileManager.urls(for: .documentDirectory, in: .userDomainMask).first else {
|
|
17
|
+
return nil
|
|
18
|
+
}
|
|
19
|
+
return documentDirectory.appendingPathComponent(logFileName)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
func addLogs(logs: [String]) {
|
|
23
|
+
queue.async(flags: .barrier) { [weak self] in
|
|
24
|
+
guard let self = self, let fileURL = self.getLogFileName() else { return }
|
|
25
|
+
do {
|
|
26
|
+
let existingLogs = self.getStoredLogs() ?? "[]"
|
|
27
|
+
var logsArray = self.parseLogs(existingLogs)
|
|
28
|
+
logsArray.append(contentsOf: logs)
|
|
29
|
+
let jsonData = try JSONSerialization.data(withJSONObject: logsArray, options: .prettyPrinted)
|
|
30
|
+
try jsonData.write(to: fileURL, options: .atomic)
|
|
31
|
+
} catch {
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
func getStoredLogs() -> String? {
|
|
37
|
+
guard let fileURL = getLogFileName(), fileManager.fileExists(atPath: fileURL.path) else {
|
|
38
|
+
return nil
|
|
39
|
+
}
|
|
40
|
+
do {
|
|
41
|
+
let data = try Data(contentsOf: fileURL)
|
|
42
|
+
if let jsonString = String(data: data, encoding: .utf8) {
|
|
43
|
+
return jsonString
|
|
44
|
+
} else {
|
|
45
|
+
return nil
|
|
46
|
+
}
|
|
47
|
+
} catch {
|
|
48
|
+
return nil
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
private func parseLogs(_ logs: String) -> [String] {
|
|
53
|
+
if let data = logs.data(using: .utf8),
|
|
54
|
+
let json = try? JSONSerialization.jsonObject(with: data, options: []) as? [String]
|
|
55
|
+
{
|
|
56
|
+
return json
|
|
57
|
+
}
|
|
58
|
+
return []
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
func getStoredLogsInArray() -> [String] {
|
|
62
|
+
return self.parseLogs(self.getStoredLogs() ?? "")
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
func clearFile() {
|
|
66
|
+
queue.async(flags: .barrier) { [weak self] in
|
|
67
|
+
guard let self = self, let fileURL = self.getLogFileName() else { return }
|
|
68
|
+
do {
|
|
69
|
+
if self.fileManager.fileExists(atPath: fileURL.path) {
|
|
70
|
+
try self.fileManager.removeItem(at: fileURL)
|
|
71
|
+
}
|
|
72
|
+
} catch {
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
//
|
|
2
|
+
// HyperLogManager.swift
|
|
3
|
+
// hyperswitch
|
|
4
|
+
//
|
|
5
|
+
// Created by Kuntimaddi Manideep on 24/01/25.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
import Foundation
|
|
9
|
+
|
|
10
|
+
final class LogManager {
|
|
11
|
+
private static var logsBatch: [LogPayload] = []
|
|
12
|
+
private static var publishableKey: String = ""
|
|
13
|
+
private static var loggingEndPoint: String?
|
|
14
|
+
private static let fileManager = LogFileManager()
|
|
15
|
+
private static let queue = DispatchQueue(label: "hyperlog.queue")
|
|
16
|
+
private static let debouncer = Debouncer(delayInMillis: 2000.0)
|
|
17
|
+
|
|
18
|
+
private static func formatPayload(logs: [String]) -> String {
|
|
19
|
+
return "["
|
|
20
|
+
+ logs.joined(separator: ",")
|
|
21
|
+
.replacingOccurrences(of: "\n", with: " ") + "]"
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
private static func getStringifiedLogs(_ logBatch: [LogPayload]) -> [String] {
|
|
25
|
+
return logBatch.compactMap { $0.toJson() }
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
static func initialize(publishableKey: String) {
|
|
29
|
+
queue.async {
|
|
30
|
+
self.publishableKey = publishableKey
|
|
31
|
+
self.loggingEndPoint = SDKEnvironment.loggingURL(for: publishableKey)
|
|
32
|
+
}
|
|
33
|
+
if !publishableKey.isEmpty {
|
|
34
|
+
sendLogsFromFile()
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
static func sendLogsFromFile() {
|
|
39
|
+
queue.async {
|
|
40
|
+
guard let endpoint = loggingEndPoint else { return }
|
|
41
|
+
let logs = fileManager.getStoredLogsInArray()
|
|
42
|
+
let payload = formatPayload(logs: logs)
|
|
43
|
+
|
|
44
|
+
let data = payload.data(using: .utf8)
|
|
45
|
+
|
|
46
|
+
let logRequest = HTTPRequestService(host: endpoint, path: "", endpoint: "", method: .post)
|
|
47
|
+
logRequest.headers = ["Content-Type": "application/json"]
|
|
48
|
+
logRequest.bodyData = data
|
|
49
|
+
|
|
50
|
+
logRequest.request(type: Data.self) { (result, statusCode) in
|
|
51
|
+
switch (result, statusCode) {
|
|
52
|
+
case (.success(_), 200..<300):
|
|
53
|
+
fileManager.clearFile()
|
|
54
|
+
default:
|
|
55
|
+
break
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
static func saveLogsToFile() {
|
|
62
|
+
queue.async {
|
|
63
|
+
let logs = getStringifiedLogs(logsBatch)
|
|
64
|
+
fileManager.addLogs(logs: logs)
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
static func saveLogsToFile(_ logsBatch: [LogPayload]) {
|
|
69
|
+
queue.async {
|
|
70
|
+
let logs = getStringifiedLogs(logsBatch)
|
|
71
|
+
fileManager.addLogs(logs: logs)
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
static func addLog(_ log: LogPayload) {
|
|
76
|
+
queue.async {
|
|
77
|
+
logsBatch.append(log)
|
|
78
|
+
debouncer.debounce {
|
|
79
|
+
sendLogsOverNetwork()
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
private static func sendLogsOverNetwork() {
|
|
85
|
+
queue.async {
|
|
86
|
+
guard !logsBatch.isEmpty, let endpoint = loggingEndPoint else { return }
|
|
87
|
+
var copiedLogs = logsBatch
|
|
88
|
+
logsBatch.removeAll()
|
|
89
|
+
|
|
90
|
+
for index in copiedLogs.indices {
|
|
91
|
+
copiedLogs[index].merchant_id = LogManager.publishableKey
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
let logsToSend = getStringifiedLogs(copiedLogs)
|
|
95
|
+
guard !logsToSend.isEmpty else { return }
|
|
96
|
+
|
|
97
|
+
let payload = formatPayload(logs: logsToSend)
|
|
98
|
+
let data = payload.data(using: .utf8)
|
|
99
|
+
let logRequest = HTTPRequestService(host: endpoint, path: "", endpoint: "", method: .post)
|
|
100
|
+
|
|
101
|
+
logRequest.headers = ["Content-Type": "application/json"]
|
|
102
|
+
logRequest.bodyData = data
|
|
103
|
+
logRequest.request(type: Data.self) { (result, statusCode) in
|
|
104
|
+
switch (result, statusCode) {
|
|
105
|
+
case (.success(_), 200..<300):
|
|
106
|
+
break
|
|
107
|
+
default:
|
|
108
|
+
saveLogsToFile(copiedLogs)
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|