@juspay-tech/react-native-hyperswitch 0.2.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 +31 -0
- package/android/build.gradle +119 -0
- package/android/gradle.properties +5 -0
- package/android/hyperswitch_autolinking.gradle +378 -0
- package/android/proguard-rules.pro +72 -0
- package/android/src/main/AndroidManifest.xml +25 -0
- package/android/src/main/assets/hyperswitch.bundle +1677 -0
- package/android/src/main/java/com/hyperswitchsdkreactnative/HyperswitchSdkReactNativePackage.kt +36 -0
- package/android/src/main/java/com/hyperswitchsdkreactnative/activity/RedirectActivity.kt +39 -0
- package/android/src/main/java/com/hyperswitchsdkreactnative/internal/DefaultReactHost.kt +314 -0
- package/android/src/main/java/com/hyperswitchsdkreactnative/internal/DefaultReactNativeHost.kt +131 -0
- package/android/src/main/java/com/hyperswitchsdkreactnative/internal/ReactDelegate.kt +423 -0
- package/android/src/main/java/com/hyperswitchsdkreactnative/internal/ReactFragment.kt +335 -0
- package/android/src/main/java/com/hyperswitchsdkreactnative/modules/HyperswitchSdkNativeModule.kt +143 -0
- package/android/src/main/java/com/hyperswitchsdkreactnative/modules/HyperswitchSdkReactNativeModule.kt +92 -0
- package/android/src/main/java/com/hyperswitchsdkreactnative/provider/HyperProvider.kt +269 -0
- package/android/src/main/java/com/hyperswitchsdkreactnative/views/GooglePayButtonView.kt +60 -0
- package/android/src/main/java/com/hyperswitchsdkreactnative/views/GooglePayButtonViewManager.kt +76 -0
- package/android/src/main/java/io/hyperswitch/hyperota/HyperOtaLogger.kt +122 -0
- package/android/src/main/java/io/hyperswitch/logs/CrashHandler.kt +29 -0
- package/android/src/main/java/io/hyperswitch/logs/Debouncer.kt +20 -0
- package/android/src/main/java/io/hyperswitch/logs/HyperLogManager.kt +113 -0
- package/android/src/main/java/io/hyperswitch/logs/LogData.kt +159 -0
- package/android/src/main/java/io/hyperswitch/logs/LogFileManager.kt +60 -0
- package/android/src/main/java/io/hyperswitch/networking/HyperNetworking.kt +73 -0
- package/android/src/main/java/io/hyperswitch/react/Utils.kt +23 -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/HyperswitchModule.swift +61 -0
- package/ios/Modules/HyperswitchNativeModule.swift +113 -0
- package/ios/Modules/HyperswitchSdkNative.h +5 -0
- package/ios/Modules/HyperswitchSdkNative.mm +98 -0
- package/ios/Modules/HyperswitchSdkReactNative.h +5 -0
- package/ios/Modules/HyperswitchSdkReactNative.mm +53 -0
- package/ios/Views/ApplePayView.h +14 -0
- package/ios/Views/ApplePayView.mm +89 -0
- package/ios/hyperswitchSDK/Core/ApplePay/ApplePayHandler.swift +249 -0
- package/ios/hyperswitchSDK/Core/ApplePay/ApplePayViewManager.m +18 -0
- package/ios/hyperswitchSDK/Core/ApplePay/ApplePayViewManager.swift +123 -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 +80 -0
- package/ios/hyperswitchSDK/Core/HyperSession/PaymentSession+UIKit.swift +176 -0
- package/ios/hyperswitchSDK/Core/HyperSession/PaymentSessionTypes.swift +121 -0
- package/ios/hyperswitchSDK/Core/Models/LogPayload.swift +53 -0
- package/ios/hyperswitchSDK/Core/NativeLogger/Debouncer.swift +37 -0
- package/ios/hyperswitchSDK/Core/NativeLogger/LogBuilder.swift +91 -0
- package/ios/hyperswitchSDK/Core/NativeLogger/LogFileManager.swift +75 -0
- package/ios/hyperswitchSDK/Core/NativeLogger/LogManager.swift +113 -0
- package/ios/hyperswitchSDK/Core/NativeModule/HyperHeadless.m +16 -0
- package/ios/hyperswitchSDK/Core/NativeModule/HyperHeadless.swift +74 -0
- package/ios/hyperswitchSDK/Core/NativeModule/HyperModule.m +28 -0
- package/ios/hyperswitchSDK/Core/NativeModule/HyperModule.swift +168 -0
- package/ios/hyperswitchSDK/Core/NativeModule/OTAServices.swift +113 -0
- package/ios/hyperswitchSDK/Core/NativeModule/RNHeadlessManager.swift +45 -0
- package/ios/hyperswitchSDK/Core/NativeModule/RNResponseHandler.swift +12 -0
- package/ios/hyperswitchSDK/Core/NativeModule/RNViewManager.swift +90 -0
- package/ios/hyperswitchSDK/Core/NativeModule/hyper-Bridging-Header.h +9 -0
- package/ios/hyperswitchSDK/Core/Resources/HyperOTA.plist +20 -0
- package/ios/hyperswitchSDK/Core/Resources/hyperswitch.bundle +1673 -0
- package/ios/hyperswitchSDK/Shared/APIClient.swift +21 -0
- package/ios/hyperswitchSDK/Shared/DictionaryConverter.swift +104 -0
- package/ios/hyperswitchSDK/Shared/Environment.swift +24 -0
- package/ios/hyperswitchSDK/Shared/Extensions.swift +31 -0
- package/ios/hyperswitchSDK/Shared/Helper.swift +16 -0
- package/ios/hyperswitchSDK/Shared/HyperNetworking.swift +137 -0
- package/ios/hyperswitchSDK/Shared/HyperParams.swift +44 -0
- package/ios/hyperswitchSDK/Shared/HyperUIViewController.swift +25 -0
- package/ios/hyperswitchSDK/Shared/PaymentSession.swift +43 -0
- package/ios/hyperswitchSDK/Shared/PaymentSheet.swift +30 -0
- package/ios/hyperswitchSDK/Shared/PaymentSheetAppearance.swift +264 -0
- package/ios/hyperswitchSDK/Shared/PaymentSheetConfiguration.swift +494 -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 +5 -0
- package/lib/bs/build.ninja +29 -0
- package/lib/bs/install.ninja +25 -0
- package/lib/bs/src/context/HyperProvider-JuspayTechReactNativeHyperswitch.cmi +0 -0
- package/lib/bs/src/context/HyperProvider-JuspayTechReactNativeHyperswitch.cmj +0 -0
- package/lib/bs/src/context/HyperProvider-JuspayTechReactNativeHyperswitch.cmt +0 -0
- package/lib/bs/src/context/HyperProvider.ast +0 -0
- package/lib/bs/src/context/HyperProvider.d +1 -0
- package/lib/bs/src/hooks/useHyper-JuspayTechReactNativeHyperswitch.cmi +0 -0
- package/lib/bs/src/hooks/useHyper-JuspayTechReactNativeHyperswitch.cmj +0 -0
- package/lib/bs/src/hooks/useHyper-JuspayTechReactNativeHyperswitch.cmt +0 -0
- package/lib/bs/src/hooks/useHyper.ast +0 -0
- package/lib/bs/src/hooks/useHyper.d +1 -0
- package/lib/bs/src/modules/NativeHyperswitchSdk-JuspayTechReactNativeHyperswitch.cmi +0 -0
- package/lib/bs/src/modules/NativeHyperswitchSdk-JuspayTechReactNativeHyperswitch.cmj +0 -0
- package/lib/bs/src/modules/NativeHyperswitchSdk-JuspayTechReactNativeHyperswitch.cmt +0 -0
- package/lib/bs/src/modules/NativeHyperswitchSdk.ast +0 -0
- package/lib/bs/src/modules/NativeHyperswitchSdk.d +1 -0
- package/lib/bs/src/types/PaymentSheetConfiguration-JuspayTechReactNativeHyperswitch.cmi +0 -0
- package/lib/bs/src/types/PaymentSheetConfiguration-JuspayTechReactNativeHyperswitch.cmj +0 -0
- package/lib/bs/src/types/PaymentSheetConfiguration-JuspayTechReactNativeHyperswitch.cmt +0 -0
- package/lib/bs/src/types/PaymentSheetConfiguration.ast +0 -0
- package/lib/bs/src/types/PaymentSheetConfiguration.d +1 -0
- package/lib/commonjs/context/HyperProvider.gen.js +16 -0
- package/lib/commonjs/context/HyperProvider.gen.js.map +1 -0
- package/lib/commonjs/context/HyperProvider.res +78 -0
- package/lib/commonjs/context/HyperProvider.res.js +98 -0
- package/lib/commonjs/context/HyperProvider.res.js.map +1 -0
- package/lib/commonjs/hooks/useHyper.gen.js +15 -0
- package/lib/commonjs/hooks/useHyper.gen.js.map +1 -0
- package/lib/commonjs/hooks/useHyper.res +142 -0
- package/lib/commonjs/hooks/useHyper.res.js +152 -0
- package/lib/commonjs/hooks/useHyper.res.js.map +1 -0
- package/lib/commonjs/index.js +26 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/modules/NativeHyperswitchSdk.gen.js +6 -0
- package/lib/commonjs/modules/NativeHyperswitchSdk.gen.js.map +1 -0
- package/lib/commonjs/modules/NativeHyperswitchSdk.res +55 -0
- package/lib/commonjs/modules/NativeHyperswitchSdk.res.js +14 -0
- package/lib/commonjs/modules/NativeHyperswitchSdk.res.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/shims/Js.shim.js +2 -0
- package/lib/commonjs/shims/Js.shim.js.map +1 -0
- package/lib/commonjs/specs/ApplePayButtonNativeComponent.ts +11 -0
- package/lib/commonjs/specs/GooglePayButtonNativeComponent.android.js +10 -0
- package/lib/commonjs/specs/GooglePayButtonNativeComponent.android.js.map +1 -0
- package/lib/commonjs/specs/HyperswitchSdkReactNativeViewNativeComponent.ts +10 -0
- package/lib/commonjs/specs/NativeHyperswitchSdkNative.js +9 -0
- package/lib/commonjs/specs/NativeHyperswitchSdkNative.js.map +1 -0
- package/lib/commonjs/specs/NativeHyperswitchSdkReactNative.js +9 -0
- package/lib/commonjs/specs/NativeHyperswitchSdkReactNative.js.map +1 -0
- package/lib/commonjs/types/PaymentSheetConfiguration.gen.js +2 -0
- package/lib/commonjs/types/PaymentSheetConfiguration.gen.js.map +1 -0
- package/lib/commonjs/types/PaymentSheetConfiguration.res +215 -0
- package/lib/commonjs/types/PaymentSheetConfiguration.res.js +4 -0
- package/lib/commonjs/types/PaymentSheetConfiguration.res.js.map +1 -0
- package/lib/module/context/HyperProvider.gen.js +11 -0
- package/lib/module/context/HyperProvider.gen.js.map +1 -0
- package/lib/module/context/HyperProvider.res +78 -0
- package/lib/module/context/HyperProvider.res.js +91 -0
- package/lib/module/context/HyperProvider.res.js.map +1 -0
- package/lib/module/hooks/useHyper.gen.js +10 -0
- package/lib/module/hooks/useHyper.gen.js.map +1 -0
- package/lib/module/hooks/useHyper.res +142 -0
- package/lib/module/hooks/useHyper.res.js +142 -0
- package/lib/module/hooks/useHyper.res.js.map +1 -0
- package/lib/module/index.js +5 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/modules/NativeHyperswitchSdk.gen.js +4 -0
- package/lib/module/modules/NativeHyperswitchSdk.gen.js.map +1 -0
- package/lib/module/modules/NativeHyperswitchSdk.res +55 -0
- package/lib/module/modules/NativeHyperswitchSdk.res.js +9 -0
- package/lib/module/modules/NativeHyperswitchSdk.res.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/shims/Js.shim.js +2 -0
- package/lib/module/shims/Js.shim.js.map +1 -0
- package/lib/module/specs/ApplePayButtonNativeComponent.ts +11 -0
- package/lib/module/specs/GooglePayButtonNativeComponent.android.js +5 -0
- package/lib/module/specs/GooglePayButtonNativeComponent.android.js.map +1 -0
- package/lib/module/specs/HyperswitchSdkReactNativeViewNativeComponent.ts +10 -0
- package/lib/module/specs/NativeHyperswitchSdkNative.js +5 -0
- package/lib/module/specs/NativeHyperswitchSdkNative.js.map +1 -0
- package/lib/module/specs/NativeHyperswitchSdkReactNative.js +5 -0
- package/lib/module/specs/NativeHyperswitchSdkReactNative.js.map +1 -0
- package/lib/module/types/PaymentSheetConfiguration.gen.js +2 -0
- package/lib/module/types/PaymentSheetConfiguration.gen.js.map +1 -0
- package/lib/module/types/PaymentSheetConfiguration.res +215 -0
- package/lib/module/types/PaymentSheetConfiguration.res.js +4 -0
- package/lib/module/types/PaymentSheetConfiguration.res.js.map +1 -0
- package/lib/typescript/commonjs/babel.config.d.ts +10 -0
- package/lib/typescript/commonjs/babel.config.d.ts.map +1 -0
- package/lib/typescript/commonjs/eslint.config.d.mts +3 -0
- package/lib/typescript/commonjs/eslint.config.d.mts.map +1 -0
- package/lib/typescript/commonjs/package.json +1 -0
- package/lib/typescript/commonjs/scripts/bootstrap.d.ts +2 -0
- package/lib/typescript/commonjs/scripts/bootstrap.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/context/HyperProvider.gen.d.ts +17 -0
- package/lib/typescript/commonjs/src/context/HyperProvider.gen.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/context/HyperProvider.res.d.ts +20 -0
- package/lib/typescript/commonjs/src/context/HyperProvider.res.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/hooks/useHyper.gen.d.ts +10 -0
- package/lib/typescript/commonjs/src/hooks/useHyper.gen.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/hooks/useHyper.res.d.ts +95 -0
- package/lib/typescript/commonjs/src/hooks/useHyper.res.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/index.d.ts +4 -0
- package/lib/typescript/commonjs/src/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/modules/NativeHyperswitchSdk.gen.d.ts +24 -0
- package/lib/typescript/commonjs/src/modules/NativeHyperswitchSdk.gen.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/modules/NativeHyperswitchSdk.res.d.ts +2 -0
- package/lib/typescript/commonjs/src/modules/NativeHyperswitchSdk.res.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/shims/Js.shim.d.ts +4 -0
- package/lib/typescript/commonjs/src/shims/Js.shim.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/specs/ApplePayButtonNativeComponent.d.ts +10 -0
- package/lib/typescript/commonjs/src/specs/ApplePayButtonNativeComponent.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/specs/GooglePayButtonNativeComponent.android.d.ts +11 -0
- package/lib/typescript/commonjs/src/specs/GooglePayButtonNativeComponent.android.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/specs/HyperswitchSdkReactNativeViewNativeComponent.d.ts +1 -0
- package/lib/typescript/commonjs/src/specs/HyperswitchSdkReactNativeViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/specs/NativeHyperswitchSdkNative.d.ts +17 -0
- package/lib/typescript/commonjs/src/specs/NativeHyperswitchSdkNative.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/specs/NativeHyperswitchSdkReactNative.d.ts +9 -0
- package/lib/typescript/commonjs/src/specs/NativeHyperswitchSdkReactNative.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/types/PaymentSheetConfiguration.gen.d.ts +149 -0
- package/lib/typescript/commonjs/src/types/PaymentSheetConfiguration.gen.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/types/PaymentSheetConfiguration.res.d.ts +1 -0
- package/lib/typescript/commonjs/src/types/PaymentSheetConfiguration.res.d.ts.map +1 -0
- package/lib/typescript/module/babel.config.d.ts +10 -0
- package/lib/typescript/module/babel.config.d.ts.map +1 -0
- package/lib/typescript/module/eslint.config.d.mts +3 -0
- package/lib/typescript/module/eslint.config.d.mts.map +1 -0
- package/lib/typescript/module/package.json +1 -0
- package/lib/typescript/module/scripts/bootstrap.d.ts +2 -0
- package/lib/typescript/module/scripts/bootstrap.d.ts.map +1 -0
- package/lib/typescript/module/src/context/HyperProvider.gen.d.ts +17 -0
- package/lib/typescript/module/src/context/HyperProvider.gen.d.ts.map +1 -0
- package/lib/typescript/module/src/context/HyperProvider.res.d.ts +20 -0
- package/lib/typescript/module/src/context/HyperProvider.res.d.ts.map +1 -0
- package/lib/typescript/module/src/hooks/useHyper.gen.d.ts +10 -0
- package/lib/typescript/module/src/hooks/useHyper.gen.d.ts.map +1 -0
- package/lib/typescript/module/src/hooks/useHyper.res.d.ts +95 -0
- package/lib/typescript/module/src/hooks/useHyper.res.d.ts.map +1 -0
- package/lib/typescript/module/src/index.d.ts +4 -0
- package/lib/typescript/module/src/index.d.ts.map +1 -0
- package/lib/typescript/module/src/modules/NativeHyperswitchSdk.gen.d.ts +24 -0
- package/lib/typescript/module/src/modules/NativeHyperswitchSdk.gen.d.ts.map +1 -0
- package/lib/typescript/module/src/modules/NativeHyperswitchSdk.res.d.ts +2 -0
- package/lib/typescript/module/src/modules/NativeHyperswitchSdk.res.d.ts.map +1 -0
- package/lib/typescript/module/src/shims/Js.shim.d.ts +4 -0
- package/lib/typescript/module/src/shims/Js.shim.d.ts.map +1 -0
- package/lib/typescript/module/src/specs/ApplePayButtonNativeComponent.d.ts +10 -0
- package/lib/typescript/module/src/specs/ApplePayButtonNativeComponent.d.ts.map +1 -0
- package/lib/typescript/module/src/specs/GooglePayButtonNativeComponent.android.d.ts +11 -0
- package/lib/typescript/module/src/specs/GooglePayButtonNativeComponent.android.d.ts.map +1 -0
- package/lib/typescript/module/src/specs/HyperswitchSdkReactNativeViewNativeComponent.d.ts +1 -0
- package/lib/typescript/module/src/specs/HyperswitchSdkReactNativeViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/module/src/specs/NativeHyperswitchSdkNative.d.ts +17 -0
- package/lib/typescript/module/src/specs/NativeHyperswitchSdkNative.d.ts.map +1 -0
- package/lib/typescript/module/src/specs/NativeHyperswitchSdkReactNative.d.ts +9 -0
- package/lib/typescript/module/src/specs/NativeHyperswitchSdkReactNative.d.ts.map +1 -0
- package/lib/typescript/module/src/types/PaymentSheetConfiguration.gen.d.ts +149 -0
- package/lib/typescript/module/src/types/PaymentSheetConfiguration.gen.d.ts.map +1 -0
- package/lib/typescript/module/src/types/PaymentSheetConfiguration.res.d.ts +1 -0
- package/lib/typescript/module/src/types/PaymentSheetConfiguration.res.d.ts.map +1 -0
- package/package.json +196 -0
- package/src/context/HyperProvider.gen.tsx +26 -0
- package/src/context/HyperProvider.res +78 -0
- package/src/context/HyperProvider.res.js +112 -0
- package/src/hooks/useHyper.gen.tsx +18 -0
- package/src/hooks/useHyper.res +142 -0
- package/src/hooks/useHyper.res.js +157 -0
- package/src/index.tsx +13 -0
- package/src/modules/NativeHyperswitchSdk.gen.tsx +25 -0
- package/src/modules/NativeHyperswitchSdk.res +55 -0
- package/src/modules/NativeHyperswitchSdk.res.js +10 -0
- package/src/shims/Js.shim.ts +5 -0
- package/src/specs/ApplePayButtonNativeComponent.ts +11 -0
- package/src/specs/GooglePayButtonNativeComponent.android.ts +12 -0
- package/src/specs/HyperswitchSdkReactNativeViewNativeComponent.ts +10 -0
- package/src/specs/NativeHyperswitchSdkNative.ts +33 -0
- package/src/specs/NativeHyperswitchSdkReactNative.ts +17 -0
- package/src/types/PaymentSheetConfiguration.gen.tsx +202 -0
- package/src/types/PaymentSheetConfiguration.res +215 -0
- package/src/types/PaymentSheetConfiguration.res.js +2 -0
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
//
|
|
2
|
+
// PaymentSheetView.swift
|
|
3
|
+
// Hyperswitch
|
|
4
|
+
//
|
|
5
|
+
// Created by Harshit Srivastava on 15/12/23.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
import Foundation
|
|
9
|
+
import React
|
|
10
|
+
import WebKit
|
|
11
|
+
|
|
12
|
+
/// Extension on the PaymentSheet class to handle the creation of the React Native root view for the payment sheet.
|
|
13
|
+
internal extension PaymentSheet {
|
|
14
|
+
|
|
15
|
+
/// Method to get the root view for the payment sheet based on the configured properties.
|
|
16
|
+
func getRootView() -> UIView? {
|
|
17
|
+
|
|
18
|
+
/// Get the configuration dictionary from the configuration object.
|
|
19
|
+
let configuration = self.configuration?.toDictionary()
|
|
20
|
+
|
|
21
|
+
/// Create a dictionary of hyperParams with app ID, sdkVersion, country, user agent, default view, and launch time.
|
|
22
|
+
let hyperParams = HyperParams.getHyperParams()
|
|
23
|
+
|
|
24
|
+
/// Create a dictionary of props to be sent to React Native with configuration, type, client secret, publishable key, hyperParams, custom backend URL, themes, and custom parameters.
|
|
25
|
+
let props: [String : Any] = [
|
|
26
|
+
"configuration": configuration as Any,
|
|
27
|
+
"type":"payment",
|
|
28
|
+
"clientSecret": self.intentClientSecret,
|
|
29
|
+
"publishableKey": APIClient.shared.publishableKey as Any,
|
|
30
|
+
"hyperParams": hyperParams,
|
|
31
|
+
"customBackendUrl": APIClient.shared.customBackendUrl as Any,
|
|
32
|
+
"customLogUrl": APIClient.shared.customLogUrl as Any,
|
|
33
|
+
"customParams": APIClient.shared.customParams as Any
|
|
34
|
+
]
|
|
35
|
+
/// Get the root view from the RNViewManager with the "hyperSwitch" module and the props dictionary.
|
|
36
|
+
let rootView = RNFabricManager.sharedInstance.viewForModule("hyperSwitch", initialProperties: ["props": props]);
|
|
37
|
+
|
|
38
|
+
rootView?.backgroundColor = UIColor.clear
|
|
39
|
+
return rootView
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/// Method to get the root view for the payment sheet with custom parameters.
|
|
43
|
+
/// - Note: Used by Flutter and React Native Wrappers to send separate props.
|
|
44
|
+
func getRootViewWithParams(props: [String: Any]) -> UIView? {
|
|
45
|
+
|
|
46
|
+
let hyperParams = HyperParams.getHyperParams()
|
|
47
|
+
|
|
48
|
+
let props: [String : Any] = [
|
|
49
|
+
"configuration": props,
|
|
50
|
+
"type":"payment",
|
|
51
|
+
"clientSecret": self.intentClientSecret,
|
|
52
|
+
"publishableKey": APIClient.shared.publishableKey as Any,
|
|
53
|
+
"hyperParams": hyperParams,
|
|
54
|
+
"customBackendUrl": APIClient.shared.customBackendUrl as Any,
|
|
55
|
+
"customLogUrl": APIClient.shared.customLogUrl as Any,
|
|
56
|
+
"customParams": APIClient.shared.customParams as Any
|
|
57
|
+
]
|
|
58
|
+
|
|
59
|
+
let rootView = RNFabricManager.sharedInstance.viewForModule("hyperSwitch", initialProperties: ["props": props]);
|
|
60
|
+
rootView?.backgroundColor = UIColor.clear
|
|
61
|
+
return rootView
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/// An extension that conforms to the RNResponseHandler protocol, which handles the response from the payment sheet operation.
|
|
66
|
+
extension PaymentSheet: RNResponseHandler {
|
|
67
|
+
func didReceiveResponse(response: String?, error: Error?) {
|
|
68
|
+
if let completion = completion {
|
|
69
|
+
if let error = error {
|
|
70
|
+
completion(.failed(error: error))
|
|
71
|
+
}
|
|
72
|
+
else if (response == "cancelled"){
|
|
73
|
+
completion(.canceled(data: "cancelled"))
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
completion(.completed(data: response ?? "failed"))
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
@@ -0,0 +1,176 @@
|
|
|
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
|
+
|
|
17
|
+
private static func safeResolve(_ callback: @escaping RCTResponseSenderBlock,_ result: [Any],_ resultHandler: @escaping (PaymentResult) -> Void){
|
|
18
|
+
guard !PaymentSession.hasResponded else {
|
|
19
|
+
print("Warning: Attempt to resolve callback more than once")
|
|
20
|
+
resultHandler(.failed(error: NSError(domain: "Not Initialised", code: 0, userInfo: ["message" : "An error has occurred."])))
|
|
21
|
+
return
|
|
22
|
+
}
|
|
23
|
+
PaymentSession.hasResponded = true
|
|
24
|
+
callback(result)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
public func presentPaymentSheet(viewController: UIViewController, completion: @escaping (PaymentSheetResult) -> ()){
|
|
28
|
+
presentPaymentSheet(viewController: viewController, configuration: PaymentSheet.Configuration(), completion: completion)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
public func presentPaymentSheet(viewController: UIViewController, configuration: PaymentSheet.Configuration, completion: @escaping (PaymentSheetResult) -> ()){
|
|
32
|
+
PaymentSession.isPresented = true
|
|
33
|
+
let paymentSheet = PaymentSheet(paymentIntentClientSecret: PaymentSession.paymentIntentClientSecret ?? "", configuration: configuration)
|
|
34
|
+
paymentSheet.present(from: viewController, completion: completion)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// for external frameworks
|
|
38
|
+
public func presentPaymentSheetWithParams(viewController: UIViewController, params: [String: Any], completion: @escaping (PaymentSheetResult) -> ()){
|
|
39
|
+
PaymentSession.isPresented = true
|
|
40
|
+
let paymentSheet = PaymentSheet(paymentIntentClientSecret: PaymentSession.paymentIntentClientSecret ?? "", configuration: PaymentSheet.Configuration())
|
|
41
|
+
paymentSheet.presentWithParams(from: viewController, props: params, completion: completion)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
public func getCustomerSavedPaymentMethods(_ func_: @escaping (PaymentSessionHandler) -> Void) {
|
|
45
|
+
PaymentSession.hasResponded = false
|
|
46
|
+
PaymentSession.isPresented = false
|
|
47
|
+
PaymentSession.headlessCompletion = func_
|
|
48
|
+
// RNHeadlessManager.sharedInstance.reinvalidateBridge()
|
|
49
|
+
// let _ = RNHeadlessManager.sharedInstance.viewForModule("dummy", initialProperties: [:])
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
internal static func getPaymentSession(getPaymentMethodData: NSDictionary, getPaymentMethodData2: NSDictionary, getPaymentMethodDataArray: NSArray, callback: @escaping RCTResponseSenderBlock) {
|
|
53
|
+
DispatchQueue.main.async {
|
|
54
|
+
PaymentSession.hasResponded = false
|
|
55
|
+
let handler = PaymentSessionHandler(
|
|
56
|
+
getCustomerDefaultSavedPaymentMethodData: {
|
|
57
|
+
return parseGetPaymentMethodData(getPaymentMethodData)
|
|
58
|
+
},
|
|
59
|
+
getCustomerLastUsedPaymentMethodData: {
|
|
60
|
+
return parseGetPaymentMethodData(getPaymentMethodData2)
|
|
61
|
+
},
|
|
62
|
+
getCustomerSavedPaymentMethodData: {
|
|
63
|
+
var array = [PaymentMethod]()
|
|
64
|
+
for i in 0..<getPaymentMethodDataArray.count {
|
|
65
|
+
if let map = getPaymentMethodDataArray[i] as? NSDictionary {
|
|
66
|
+
array.append(parseGetPaymentMethodData(map))
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return array
|
|
70
|
+
},
|
|
71
|
+
confirmWithCustomerDefaultPaymentMethod: { cvc, resultHandler in
|
|
72
|
+
if let map = getPaymentMethodData["_0"] as? NSDictionary,
|
|
73
|
+
let paymentToken = map["payment_token"] as? String {
|
|
74
|
+
self.completion = resultHandler
|
|
75
|
+
var map = [String: Any]()
|
|
76
|
+
map["paymentToken"] = paymentToken
|
|
77
|
+
map["cvc"] = cvc
|
|
78
|
+
self.safeResolve(callback, [map], resultHandler)
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
confirmWithCustomerLastUsedPaymentMethod: { cvc, resultHandler in
|
|
82
|
+
if let map = getPaymentMethodData2["_0"] as? NSDictionary,
|
|
83
|
+
let paymentToken = map["payment_token"] as? String {
|
|
84
|
+
self.completion = resultHandler
|
|
85
|
+
var map = [String: Any]()
|
|
86
|
+
map["paymentToken"] = paymentToken
|
|
87
|
+
map["cvc"] = cvc
|
|
88
|
+
self.safeResolve(callback, [map], resultHandler)
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
confirmWithCustomerPaymentToken: { paymentToken, cvc, resultHandler in
|
|
92
|
+
self.completion = resultHandler
|
|
93
|
+
var map = [String: Any]()
|
|
94
|
+
map["paymentToken"] = paymentToken
|
|
95
|
+
map["cvc"] = cvc
|
|
96
|
+
self.safeResolve(callback, [map], resultHandler)
|
|
97
|
+
}
|
|
98
|
+
)
|
|
99
|
+
self.headlessCompletion?(handler)
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
internal static func exitHeadless(rnMessage: String) {
|
|
105
|
+
DispatchQueue.main.async {
|
|
106
|
+
if let data = rnMessage.data(using: .utf8) {
|
|
107
|
+
do {
|
|
108
|
+
if let message = try JSONSerialization.jsonObject(with: data, options: []) as? [String: String] {
|
|
109
|
+
guard let status = message["status"] else {
|
|
110
|
+
completion?(.failed(error: NSError(domain: "UNKNOWN_ERROR", code: 0, userInfo: ["message" : "An error has occurred."])))
|
|
111
|
+
return
|
|
112
|
+
}
|
|
113
|
+
switch status {
|
|
114
|
+
case "cancelled":
|
|
115
|
+
completion?(.canceled(data: status))
|
|
116
|
+
case "failed", "requires_payment_method":
|
|
117
|
+
let domain = (message["code"]) != "" ? message["code"] : "UNKNOWN_ERROR"
|
|
118
|
+
let errorMessage = message["message"] ?? "An error has occurred."
|
|
119
|
+
let userInfo = ["message": errorMessage]
|
|
120
|
+
completion?(.failed(error: NSError(domain: domain ?? "UNKNOWN_ERROR", code: 0, userInfo: userInfo)))
|
|
121
|
+
default:
|
|
122
|
+
completion?(.completed(data: status))
|
|
123
|
+
}
|
|
124
|
+
} else {
|
|
125
|
+
let domain = "UNKNOWN_ERROR"
|
|
126
|
+
let errorMessage = "An error has occurred."
|
|
127
|
+
let userInfo = ["message": errorMessage]
|
|
128
|
+
self.completion?(.failed(error: NSError(domain: domain , code: 0, userInfo: userInfo)))
|
|
129
|
+
}
|
|
130
|
+
} catch {
|
|
131
|
+
let domain = "UNKNOWN_ERROR"
|
|
132
|
+
let errorMessage = "An error has occurred."
|
|
133
|
+
let userInfo = ["message": errorMessage]
|
|
134
|
+
self.completion?(.failed(error: NSError(domain: domain , code: 0, userInfo: userInfo)))
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
private static func parseGetPaymentMethodData(_ readableMap: NSDictionary) -> PaymentMethod {
|
|
141
|
+
let tag = readableMap["TAG"] as? String ?? ""
|
|
142
|
+
let dataObject = readableMap["_0"] as? [String: Any]
|
|
143
|
+
|
|
144
|
+
switch tag {
|
|
145
|
+
case "SAVEDLISTCARD":
|
|
146
|
+
if let it = dataObject {
|
|
147
|
+
return Card(
|
|
148
|
+
isDefaultPaymentMethod: it["isDefaultPaymentMethod"] as? Bool ?? false,
|
|
149
|
+
paymentToken: it["payment_token"] as? String ?? "",
|
|
150
|
+
cardScheme: it["cardScheme"] as? String ?? "",
|
|
151
|
+
name: it["name"] as? String ?? "",
|
|
152
|
+
expiryDate: it["expiry_date"] as? String ?? "",
|
|
153
|
+
cardNumber: it["cardNumber"] as? String ?? "",
|
|
154
|
+
nickName: it["nick_name"] as? String ?? "",
|
|
155
|
+
cardHolderName: it["cardHolderName"] as? String ?? "",
|
|
156
|
+
requiresCVV: it["requiresCVV"] as? Bool ?? false,
|
|
157
|
+
created: it["created"] as? String ?? "",
|
|
158
|
+
lastUsedAt: it["lastUsedAt"] as? String ?? ""
|
|
159
|
+
)
|
|
160
|
+
}
|
|
161
|
+
case "SAVEDLISTWALLET":
|
|
162
|
+
if let it = dataObject {
|
|
163
|
+
return Wallet(
|
|
164
|
+
isDefaultPaymentMethod: it["isDefaultPaymentMethod"] as? Bool ?? false,
|
|
165
|
+
paymentToken: it["payment_token"] as? String ?? "",
|
|
166
|
+
walletType: it["walletType"] as? String ?? "",
|
|
167
|
+
created: it["created"] as? String ?? "",
|
|
168
|
+
lastUsedAt: it["lastUsedAt"] as? String ?? ""
|
|
169
|
+
)
|
|
170
|
+
}
|
|
171
|
+
default:
|
|
172
|
+
return PMError(code: readableMap["code"] as? String ?? "",message: readableMap["message"] as? String ?? "No default type found")
|
|
173
|
+
}
|
|
174
|
+
return PMError(code: "01", message: "No default type found")
|
|
175
|
+
}
|
|
176
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
//
|
|
2
|
+
// PaymentSessionTypes.swift
|
|
3
|
+
// hyperswitch
|
|
4
|
+
//
|
|
5
|
+
// Created by Harshit Srivastava on 30/08/24.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
import Foundation
|
|
9
|
+
|
|
10
|
+
public struct Card: PaymentMethod {
|
|
11
|
+
public let isDefaultPaymentMethod: Bool
|
|
12
|
+
public let paymentToken: String
|
|
13
|
+
public let cardScheme: String
|
|
14
|
+
public let name: String
|
|
15
|
+
public let expiryDate: String
|
|
16
|
+
public let cardNumber: String
|
|
17
|
+
public let nickName: String
|
|
18
|
+
public let cardHolderName: String
|
|
19
|
+
public let requiresCVV: Bool
|
|
20
|
+
public let created: String
|
|
21
|
+
public let lastUsedAt: String
|
|
22
|
+
|
|
23
|
+
public func toHashMap() -> [String: Any] {
|
|
24
|
+
return [
|
|
25
|
+
"isDefaultPaymentMethod": isDefaultPaymentMethod,
|
|
26
|
+
"paymentToken": paymentToken,
|
|
27
|
+
"cardScheme": cardScheme,
|
|
28
|
+
"name": name,
|
|
29
|
+
"expiryDate": expiryDate,
|
|
30
|
+
"cardNumber": cardNumber,
|
|
31
|
+
"nickName": nickName,
|
|
32
|
+
"cardHolderName": cardHolderName,
|
|
33
|
+
"requiresCVV": requiresCVV,
|
|
34
|
+
"created": created,
|
|
35
|
+
"lastUsedAt": lastUsedAt
|
|
36
|
+
]
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
public struct Wallet: PaymentMethod {
|
|
41
|
+
public let isDefaultPaymentMethod: Bool
|
|
42
|
+
public let paymentToken: String
|
|
43
|
+
public let walletType: String
|
|
44
|
+
public let created: String
|
|
45
|
+
public let lastUsedAt: String
|
|
46
|
+
|
|
47
|
+
public func toHashMap() -> [String: Any] {
|
|
48
|
+
return [
|
|
49
|
+
"isDefaultPaymentMethod": isDefaultPaymentMethod,
|
|
50
|
+
"paymentToken": paymentToken,
|
|
51
|
+
"walletType": walletType,
|
|
52
|
+
"created": created,
|
|
53
|
+
"lastUsedAt": lastUsedAt
|
|
54
|
+
]
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
public struct PMError: PaymentMethod {
|
|
59
|
+
public let isDefaultPaymentMethod: Bool = false
|
|
60
|
+
public let paymentToken: String = ""
|
|
61
|
+
public let created: String = ""
|
|
62
|
+
public let lastUsedAt: String = ""
|
|
63
|
+
public let code: String
|
|
64
|
+
public let message: String
|
|
65
|
+
|
|
66
|
+
public func toHashMap() -> [String: Any] {
|
|
67
|
+
return [
|
|
68
|
+
"code": code,
|
|
69
|
+
"message": message,
|
|
70
|
+
"isDefaultPaymentMethod": isDefaultPaymentMethod,
|
|
71
|
+
"paymentToken": paymentToken,
|
|
72
|
+
"created": created,
|
|
73
|
+
"lastUsedAt": lastUsedAt
|
|
74
|
+
]
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
public struct PaymentSessionHandler {
|
|
79
|
+
public let getCustomerDefaultSavedPaymentMethodData: () -> PaymentMethod
|
|
80
|
+
public let getCustomerLastUsedPaymentMethodData: () -> PaymentMethod
|
|
81
|
+
public let getCustomerSavedPaymentMethodData: () -> [PaymentMethod]
|
|
82
|
+
private let confirmWithCustomerDefaultPaymentMethod: (_ cvc: String?, _ resultHandler: @escaping (PaymentResult) -> Void) -> Void
|
|
83
|
+
private let confirmWithCustomerLastUsedPaymentMethod: (_ cvc: String?, _ resultHandler: @escaping (PaymentResult) -> Void) -> Void
|
|
84
|
+
private let confirmWithCustomerPaymentToken: (_ paymentToken: String, _ cvc: String?, _ resultHandler: @escaping (PaymentResult) -> Void) -> Void
|
|
85
|
+
|
|
86
|
+
init(
|
|
87
|
+
getCustomerDefaultSavedPaymentMethodData: @escaping () -> PaymentMethod,
|
|
88
|
+
getCustomerLastUsedPaymentMethodData: @escaping () -> PaymentMethod,
|
|
89
|
+
getCustomerSavedPaymentMethodData: @escaping () -> [PaymentMethod],
|
|
90
|
+
confirmWithCustomerDefaultPaymentMethod: @escaping (_ cvc: String?, _ resultHandler: @escaping (PaymentResult) -> Void) -> Void,
|
|
91
|
+
confirmWithCustomerLastUsedPaymentMethod: @escaping (_ cvc: String?, _ resultHandler: @escaping (PaymentResult) -> Void) -> Void,
|
|
92
|
+
confirmWithCustomerPaymentToken: @escaping (_ paymentToken: String, _ cvc: String?, _ resultHandler: @escaping (PaymentResult) -> Void) -> Void
|
|
93
|
+
) {
|
|
94
|
+
self.getCustomerDefaultSavedPaymentMethodData = getCustomerDefaultSavedPaymentMethodData
|
|
95
|
+
self.getCustomerLastUsedPaymentMethodData = getCustomerLastUsedPaymentMethodData
|
|
96
|
+
self.getCustomerSavedPaymentMethodData = getCustomerSavedPaymentMethodData
|
|
97
|
+
self.confirmWithCustomerDefaultPaymentMethod = confirmWithCustomerDefaultPaymentMethod
|
|
98
|
+
self.confirmWithCustomerLastUsedPaymentMethod = confirmWithCustomerLastUsedPaymentMethod
|
|
99
|
+
self.confirmWithCustomerPaymentToken = confirmWithCustomerPaymentToken
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
public func confirmWithCustomerDefaultPaymentMethod(resultHandler: @escaping (PaymentResult) -> Void) {
|
|
103
|
+
confirmWithCustomerDefaultPaymentMethod(nil, resultHandler)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
public func confirmWithCustomerLastUsedPaymentMethod(resultHandler: @escaping (PaymentResult) -> Void) {
|
|
107
|
+
confirmWithCustomerLastUsedPaymentMethod(nil, resultHandler)
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
public func confirmWithCustomerPaymentToken(paymentToken: String, resultHandler: @escaping (PaymentResult) -> Void) {
|
|
111
|
+
confirmWithCustomerPaymentToken(paymentToken, nil, resultHandler)
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
public protocol PaymentMethod {
|
|
116
|
+
var isDefaultPaymentMethod: Bool { get }
|
|
117
|
+
var paymentToken: String { get }
|
|
118
|
+
var created: String { get }
|
|
119
|
+
var lastUsedAt: String { get }
|
|
120
|
+
func toHashMap() -> [String: Any]
|
|
121
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
//
|
|
2
|
+
// LogPayload.swift
|
|
3
|
+
// hyperswitch
|
|
4
|
+
//
|
|
5
|
+
// Created by Kuntimaddi Manideep on 24/01/25.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
import Foundation
|
|
9
|
+
|
|
10
|
+
struct LogPayload: Codable {
|
|
11
|
+
let timestamp: String
|
|
12
|
+
let log_type: LogType
|
|
13
|
+
let component: String
|
|
14
|
+
let category: LogCategory
|
|
15
|
+
let version: String
|
|
16
|
+
let code_push_version: String
|
|
17
|
+
let client_core_version: String
|
|
18
|
+
let value: String
|
|
19
|
+
let internal_metadata: String
|
|
20
|
+
let session_id: String
|
|
21
|
+
var merchant_id: String
|
|
22
|
+
let payment_id: String
|
|
23
|
+
let app_id: String?
|
|
24
|
+
let platform: String
|
|
25
|
+
let user_agent: String
|
|
26
|
+
let event_name: EventName
|
|
27
|
+
let latency: String?
|
|
28
|
+
let first_event: String
|
|
29
|
+
let payment_method: String?
|
|
30
|
+
let payment_experience: String?
|
|
31
|
+
let source: String
|
|
32
|
+
|
|
33
|
+
func toJson() -> String? {
|
|
34
|
+
do {
|
|
35
|
+
let jsonData = try JSONEncoder().encode(self)
|
|
36
|
+
return String(data: jsonData, encoding: .utf8)
|
|
37
|
+
} catch {
|
|
38
|
+
return nil
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
enum LogType: String, Codable {
|
|
44
|
+
case DEBUG, INFO, ERROR, WARNING
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
enum LogCategory: String, Codable {
|
|
48
|
+
case API, USER_ERROR, USER_EVENT, MERCHANT_EVENT, OTA_LIFE_CYCLE
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
enum EventName: String, Codable {
|
|
52
|
+
case HYPER_OTA_INIT, HYPER_OTA_FINISH , HYPER_OTA_EVENT
|
|
53
|
+
}
|
|
@@ -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,91 @@
|
|
|
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 appId: String? = nil
|
|
24
|
+
private var platform: String = "IOS"
|
|
25
|
+
private var userAgent: String = ""
|
|
26
|
+
private var eventName: EventName = .HYPER_OTA_INIT
|
|
27
|
+
private var latency: String? = nil
|
|
28
|
+
private var firstEvent: Bool = false
|
|
29
|
+
private var paymentMethod: String? = nil
|
|
30
|
+
private var paymentExperience: String? = nil
|
|
31
|
+
private var source: String = ""
|
|
32
|
+
|
|
33
|
+
func setLogType(_ logType: String) -> LogBuilder {
|
|
34
|
+
switch logType.uppercased() {
|
|
35
|
+
case "ERROR":
|
|
36
|
+
self.logType = .ERROR
|
|
37
|
+
break
|
|
38
|
+
case "WARNING":
|
|
39
|
+
self.logType = .WARNING
|
|
40
|
+
break
|
|
41
|
+
case "DEBUG":
|
|
42
|
+
self.logType = .DEBUG
|
|
43
|
+
break
|
|
44
|
+
default:
|
|
45
|
+
self.logType = .INFO
|
|
46
|
+
}
|
|
47
|
+
return self
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
func setClientCoreVersion(_ clientCoreVersion: String) -> LogBuilder {
|
|
51
|
+
self.clientCoreVersion = clientCoreVersion
|
|
52
|
+
return self
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
func setValue(_ value: String) -> LogBuilder {
|
|
56
|
+
self.value = value
|
|
57
|
+
return self
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
func setEventName(_ eventName: EventName) -> LogBuilder {
|
|
61
|
+
self.eventName = eventName
|
|
62
|
+
return self
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
func build() -> LogPayload {
|
|
66
|
+
self.timestamp = String(Int(Date().timeIntervalSince1970 * 1000))
|
|
67
|
+
return LogPayload(
|
|
68
|
+
timestamp: timestamp,
|
|
69
|
+
log_type: logType,
|
|
70
|
+
component: component,
|
|
71
|
+
category: category,
|
|
72
|
+
version: version,
|
|
73
|
+
code_push_version: codePushVersion,
|
|
74
|
+
client_core_version: clientCoreVersion,
|
|
75
|
+
value: value,
|
|
76
|
+
internal_metadata: internalMetadata,
|
|
77
|
+
session_id: sessionId,
|
|
78
|
+
merchant_id: merchantId,
|
|
79
|
+
payment_id: paymentId,
|
|
80
|
+
app_id: appId,
|
|
81
|
+
platform: platform,
|
|
82
|
+
user_agent: userAgent,
|
|
83
|
+
event_name: eventName,
|
|
84
|
+
latency: latency,
|
|
85
|
+
first_event: firstEvent ? "true" : "false",
|
|
86
|
+
payment_method: paymentMethod,
|
|
87
|
+
payment_experience: paymentExperience,
|
|
88
|
+
source: source
|
|
89
|
+
)
|
|
90
|
+
}
|
|
91
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
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
|
+
return json
|
|
56
|
+
}
|
|
57
|
+
return []
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
func getStoredLogsInArray() -> [String] {
|
|
61
|
+
return self.parseLogs(self.getStoredLogs() ?? "")
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
func clearFile() {
|
|
65
|
+
queue.async(flags: .barrier) { [weak self] in
|
|
66
|
+
guard let self = self, let fileURL = self.getLogFileName() else { return }
|
|
67
|
+
do {
|
|
68
|
+
if self.fileManager.fileExists(atPath: fileURL.path) {
|
|
69
|
+
try self.fileManager.removeItem(at: fileURL)
|
|
70
|
+
}
|
|
71
|
+
} catch {
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|