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,126 @@
|
|
|
1
|
+
//
|
|
2
|
+
// ApplePayViewManager.swift
|
|
3
|
+
// Hyperswitch
|
|
4
|
+
//
|
|
5
|
+
// Created by Harshit Srivastava on 20/06/24.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
import PassKit
|
|
9
|
+
import React
|
|
10
|
+
import UIKit
|
|
11
|
+
|
|
12
|
+
@objc(ApplePayViewManager)
|
|
13
|
+
internal class ApplePayViewManager: RCTViewManager {
|
|
14
|
+
|
|
15
|
+
override func view() -> (ApplePayView) {
|
|
16
|
+
return ApplePayView()
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
@objc override static func requiresMainQueueSetup() -> Bool {
|
|
20
|
+
return false
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
internal class ApplePayView: UIView {
|
|
25
|
+
|
|
26
|
+
private var button: PKPaymentButton?
|
|
27
|
+
private var paymentHandler = ApplePayHandler()
|
|
28
|
+
@objc private var onPaymentResultCallback: RCTDirectEventBlock?
|
|
29
|
+
|
|
30
|
+
@objc var buttonStyle: String = "" {
|
|
31
|
+
didSet {
|
|
32
|
+
setButton(setButtonType: buttonType, setButtonStyle: buttonStyle, setButtonCornerRadius: cornerRadius)
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
@objc var buttonType: String = "" {
|
|
36
|
+
didSet {
|
|
37
|
+
setButton(setButtonType: buttonType, setButtonStyle: buttonStyle, setButtonCornerRadius: cornerRadius)
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
@objc var color: String = "" {
|
|
41
|
+
didSet {
|
|
42
|
+
setButton(setButtonType: buttonType, setButtonStyle: buttonStyle, setButtonCornerRadius: cornerRadius)
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
@objc var cornerRadius: CGFloat = 0.0 {
|
|
46
|
+
didSet {
|
|
47
|
+
setButton(setButtonType: buttonType, setButtonStyle: buttonStyle, setButtonCornerRadius: cornerRadius)
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
override init(frame: CGRect) {
|
|
52
|
+
super.init(frame: frame)
|
|
53
|
+
|
|
54
|
+
let cornerRadiusValue: CGFloat = 4.0
|
|
55
|
+
let buttonType = "plain"
|
|
56
|
+
let buttonStyle = "black"
|
|
57
|
+
setButton(setButtonType: buttonType, setButtonStyle: buttonStyle, setButtonCornerRadius: cornerRadiusValue)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
required init?(coder: NSCoder) {
|
|
61
|
+
super.init(coder: coder)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
private func setButton(setButtonType: String?, setButtonStyle: String?, setButtonCornerRadius cornerRadius: CGFloat?) {
|
|
65
|
+
for view in subviews {
|
|
66
|
+
view.removeFromSuperview()
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
var type: PKPaymentButtonType
|
|
70
|
+
var style: PKPaymentButtonStyle
|
|
71
|
+
|
|
72
|
+
switch setButtonType {
|
|
73
|
+
case "buy":
|
|
74
|
+
type = .buy
|
|
75
|
+
case "setUp":
|
|
76
|
+
type = .setUp
|
|
77
|
+
case "inStore":
|
|
78
|
+
type = .inStore
|
|
79
|
+
case "donate":
|
|
80
|
+
type = .donate
|
|
81
|
+
case "checkout":
|
|
82
|
+
type = .checkout
|
|
83
|
+
case "book":
|
|
84
|
+
type = .book
|
|
85
|
+
case "subscribe":
|
|
86
|
+
type = .subscribe
|
|
87
|
+
default:
|
|
88
|
+
type = .plain
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
switch setButtonStyle {
|
|
92
|
+
case "white":
|
|
93
|
+
style = .white
|
|
94
|
+
case "whiteOutline":
|
|
95
|
+
style = .whiteOutline
|
|
96
|
+
default:
|
|
97
|
+
style = .black
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if #available(iOS 26.0, *) { // TODO: temp fix need to clamp corner-radius to be < height/2
|
|
101
|
+
button = PKPaymentButton(type: type, style: style, disableCardArt: true)
|
|
102
|
+
} else {
|
|
103
|
+
button = PKPaymentButton(paymentButtonType: type, paymentButtonStyle: style)
|
|
104
|
+
}
|
|
105
|
+
button?.addTarget(self, action: #selector(touchUpInside(_:)), for: .touchUpInside)
|
|
106
|
+
if let cornerRadius = cornerRadius {
|
|
107
|
+
button?.cornerRadius = cornerRadius
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if let buttonView = button {
|
|
111
|
+
addSubview(buttonView)
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
@objc private func touchUpInside(_ button: PKPaymentButton) {
|
|
116
|
+
if let onPaymentResultCallback = onPaymentResultCallback {
|
|
117
|
+
onPaymentResultCallback(nil)
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
internal override func layoutSubviews() {
|
|
123
|
+
super.layoutSubviews()
|
|
124
|
+
button?.frame = bounds
|
|
125
|
+
}
|
|
126
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
//
|
|
2
|
+
// HeadlessWebView.swift
|
|
3
|
+
// hyperswitch
|
|
4
|
+
//
|
|
5
|
+
// Created by Harshit Srivastava on 25/05/26.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
import React
|
|
9
|
+
import WebKit
|
|
10
|
+
|
|
11
|
+
final internal class HeadlessWebView: NSObject, WKNavigationDelegate, WKUIDelegate, WKScriptMessageHandler {
|
|
12
|
+
|
|
13
|
+
private let url: String
|
|
14
|
+
private let timeoutMs: NSNumber
|
|
15
|
+
private let callback: RCTResponseSenderBlock
|
|
16
|
+
private var webView: WKWebView?
|
|
17
|
+
private var timeoutWorkItem: DispatchWorkItem?
|
|
18
|
+
private var selfRetain: HeadlessWebView?
|
|
19
|
+
private var callbackInvoked = false
|
|
20
|
+
|
|
21
|
+
init(url: String, timeoutMs: NSNumber, callback: @escaping RCTResponseSenderBlock) {
|
|
22
|
+
self.url = url
|
|
23
|
+
self.timeoutMs = timeoutMs
|
|
24
|
+
self.callback = callback
|
|
25
|
+
super.init()
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
deinit {
|
|
29
|
+
if !callbackInvoked { callback([""]) }
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
internal func startFlow() {
|
|
33
|
+
selfRetain = self
|
|
34
|
+
|
|
35
|
+
let contentController = WKUserContentController()
|
|
36
|
+
let weakHandler = WeakScriptMessageHandler(delegate: self)
|
|
37
|
+
contentController.add(weakHandler, name: "HSInterfaceDDC")
|
|
38
|
+
|
|
39
|
+
let configuration = WKWebViewConfiguration()
|
|
40
|
+
configuration.userContentController = contentController
|
|
41
|
+
configuration.defaultWebpagePreferences.allowsContentJavaScript = true
|
|
42
|
+
configuration.preferences.javaScriptCanOpenWindowsAutomatically = true
|
|
43
|
+
|
|
44
|
+
webView = WKWebView(frame: .zero, configuration: configuration)
|
|
45
|
+
webView?.isHidden = false // Keep visible to prevent freezing
|
|
46
|
+
webView?.alpha = 0.01
|
|
47
|
+
webView?.accessibilityElementsHidden = true // Hide this element AND all its subviews from VoiceOver
|
|
48
|
+
|
|
49
|
+
webView?.navigationDelegate = self
|
|
50
|
+
webView?.uiDelegate = self
|
|
51
|
+
|
|
52
|
+
guard let baseURL = URL(string: url) else {
|
|
53
|
+
invokeCallback("")
|
|
54
|
+
return
|
|
55
|
+
}
|
|
56
|
+
guard let window = keyWindow() else {
|
|
57
|
+
invokeCallback("")
|
|
58
|
+
return
|
|
59
|
+
}
|
|
60
|
+
if let webView = webView {
|
|
61
|
+
window.addSubview(webView)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
let baseHtml = """
|
|
65
|
+
<html><body>
|
|
66
|
+
<iframe src="\(url)" style="display:none;width:1px;height:1px;"></iframe>
|
|
67
|
+
<script>
|
|
68
|
+
window.addEventListener('message', function(event) {
|
|
69
|
+
var str = typeof event.data === 'string' ? event.data : JSON.stringify(event.data);
|
|
70
|
+
try { window.webkit.messageHandlers.HSInterfaceDDC.postMessage(str); } catch(e) {}
|
|
71
|
+
});
|
|
72
|
+
</script>
|
|
73
|
+
</body></html>
|
|
74
|
+
"""
|
|
75
|
+
|
|
76
|
+
webView?.loadHTMLString(baseHtml, baseURL: baseURL)
|
|
77
|
+
|
|
78
|
+
let timeoutInterval = timeoutMs.doubleValue / 1000.0
|
|
79
|
+
let workItem = DispatchWorkItem { [weak self] in
|
|
80
|
+
self?.invokeCallback("")
|
|
81
|
+
}
|
|
82
|
+
timeoutWorkItem = workItem
|
|
83
|
+
DispatchQueue.main.asyncAfter(deadline: .now() + timeoutInterval, execute: workItem)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
func invokeCallback(_ result: String) {
|
|
87
|
+
guard !callbackInvoked else { return }
|
|
88
|
+
callbackInvoked = true
|
|
89
|
+
timeoutWorkItem?.cancel()
|
|
90
|
+
timeoutWorkItem = nil
|
|
91
|
+
DispatchQueue.main.async { [weak self] in
|
|
92
|
+
guard let self = self else { return }
|
|
93
|
+
webView?.configuration.userContentController.removeScriptMessageHandler(forName: "HSInterfaceDDC")
|
|
94
|
+
webView?.stopLoading()
|
|
95
|
+
webView?.navigationDelegate = nil
|
|
96
|
+
webView?.uiDelegate = nil
|
|
97
|
+
webView?.removeFromSuperview()
|
|
98
|
+
webView = nil
|
|
99
|
+
callback([result])
|
|
100
|
+
self.selfRetain = nil
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
|
|
105
|
+
guard message.name == "HSInterfaceDDC",
|
|
106
|
+
let body = message.body as? String
|
|
107
|
+
else { return }
|
|
108
|
+
invokeCallback(body)
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
func webView(_ webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, withError error: Error) {
|
|
112
|
+
invokeCallback("")
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
func webView(_ webView: WKWebView, didFail navigation: WKNavigation!, withError error: Error) {
|
|
116
|
+
invokeCallback("")
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/// A weak wrapper for WKScriptMessageHandler to break the retain cycle
|
|
120
|
+
private class WeakScriptMessageHandler: NSObject, WKScriptMessageHandler {
|
|
121
|
+
weak var delegate: WKScriptMessageHandler?
|
|
122
|
+
|
|
123
|
+
init(delegate: WKScriptMessageHandler) {
|
|
124
|
+
self.delegate = delegate
|
|
125
|
+
super.init()
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
|
|
129
|
+
delegate?.userContentController(userContentController, didReceive: message)
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
private func keyWindow() -> UIWindow? {
|
|
134
|
+
return UIApplication.shared.connectedScenes
|
|
135
|
+
.compactMap { $0 as? UIWindowScene }
|
|
136
|
+
.filter { $0.activationState == .foregroundActive }
|
|
137
|
+
.flatMap { $0.windows }
|
|
138
|
+
.first { $0.isKeyWindow }
|
|
139
|
+
?? UIApplication.shared.connectedScenes
|
|
140
|
+
.compactMap { $0 as? UIWindowScene }
|
|
141
|
+
.flatMap { $0.windows }
|
|
142
|
+
.first { $0.isKeyWindow }
|
|
143
|
+
}
|
|
144
|
+
}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
//
|
|
2
|
+
// CVCWidget.swift
|
|
3
|
+
// hyperswitch
|
|
4
|
+
//
|
|
5
|
+
// Created by Harshit Srivastava on 21/04/26.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
import Foundation
|
|
9
|
+
import React
|
|
10
|
+
|
|
11
|
+
public class CVCWidget: UIControl {
|
|
12
|
+
|
|
13
|
+
private let configuration: PaymentSheet.Configuration?
|
|
14
|
+
private var configurationDict: [String: Any]?
|
|
15
|
+
private var widgetReactTag: NSNumber?
|
|
16
|
+
internal var rootReactTag: NSNumber? { widgetReactTag }
|
|
17
|
+
private var rootView: RCTRootView?
|
|
18
|
+
private var cvcCallback: ((PaymentResult) -> Void)?
|
|
19
|
+
private var subscribedEventNames: [String]?
|
|
20
|
+
private let hyperswitch: Hyperswitch
|
|
21
|
+
|
|
22
|
+
internal var paymentEventListener: PaymentEventListener?
|
|
23
|
+
|
|
24
|
+
public init(
|
|
25
|
+
hyperswitch: Hyperswitch,
|
|
26
|
+
configuration: PaymentSheet.Configuration? = nil,
|
|
27
|
+
subscribe: ((PaymentEventSubscriptionBuilder) -> Void)? = nil
|
|
28
|
+
) {
|
|
29
|
+
self.hyperswitch = hyperswitch
|
|
30
|
+
self.configuration = configuration
|
|
31
|
+
self.configurationDict = nil
|
|
32
|
+
if let subscribe {
|
|
33
|
+
let builder = PaymentEventSubscriptionBuilder()
|
|
34
|
+
subscribe(builder)
|
|
35
|
+
let (subscription, listener) = builder.build()
|
|
36
|
+
self.paymentEventListener = listener
|
|
37
|
+
self.subscribedEventNames = subscription.subscribedEventStrings()
|
|
38
|
+
}
|
|
39
|
+
super.init(frame: .zero)
|
|
40
|
+
commonInit()
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
//MARK: pass through
|
|
44
|
+
public init(hyperswitch: Hyperswitch, configurationDict: [String: Any]?, subscribe: ((PaymentEventSubscriptionBuilder) -> Void)? = nil)
|
|
45
|
+
{
|
|
46
|
+
self.hyperswitch = hyperswitch
|
|
47
|
+
self.configuration = nil
|
|
48
|
+
self.configurationDict = configurationDict
|
|
49
|
+
if let subscribe {
|
|
50
|
+
let builder = PaymentEventSubscriptionBuilder()
|
|
51
|
+
subscribe(builder)
|
|
52
|
+
let (subscription, listener) = builder.build()
|
|
53
|
+
self.paymentEventListener = listener
|
|
54
|
+
self.subscribedEventNames = subscription.subscribedEventStrings()
|
|
55
|
+
}
|
|
56
|
+
super.init(frame: .zero)
|
|
57
|
+
commonInit()
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
required init?(coder: NSCoder) {
|
|
61
|
+
fatalError("init(coder:) has not been implemented")
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
private func commonInit() {
|
|
65
|
+
|
|
66
|
+
let hyperswitchConfiguration = try? hyperswitch.hyperswitchConfiguration.toDictionary()
|
|
67
|
+
|
|
68
|
+
let sdkParams = SDKParams.getSDKParams()
|
|
69
|
+
|
|
70
|
+
var nativeConfig = try? configuration?.toDictionary()
|
|
71
|
+
if self.subscribedEventNames == nil {
|
|
72
|
+
self.subscribedEventNames = configurationDict?["subscribedEvents"] as? [String]
|
|
73
|
+
?? nativeConfig?["subscribedEvents"] as? [String]
|
|
74
|
+
}
|
|
75
|
+
nativeConfig?["subscribedEvents"] = self.subscribedEventNames
|
|
76
|
+
configurationDict?["subscribedEvents"] = self.subscribedEventNames
|
|
77
|
+
|
|
78
|
+
let props: [String: Any] = [
|
|
79
|
+
"hyperswitchConfig": hyperswitchConfiguration as Any,
|
|
80
|
+
"type": "cvcWidget",
|
|
81
|
+
"sdkParams": sdkParams,
|
|
82
|
+
"configuration": configurationDict ?? nativeConfig as Any,
|
|
83
|
+
"from": (configurationDict != nil) ? "rn" : "nativeWidget",
|
|
84
|
+
]
|
|
85
|
+
|
|
86
|
+
self.rootView = RNViewManager.sharedInstance.widgetViewForModule(
|
|
87
|
+
"hyperSwitch",
|
|
88
|
+
initialProperties: ["props": props]
|
|
89
|
+
)
|
|
90
|
+
if let rootView = self.rootView {
|
|
91
|
+
self.widgetReactTag = rootView.reactTag
|
|
92
|
+
|
|
93
|
+
rootView.backgroundColor = .clear
|
|
94
|
+
|
|
95
|
+
addSubview(rootView)
|
|
96
|
+
|
|
97
|
+
rootView.translatesAutoresizingMaskIntoConstraints = false
|
|
98
|
+
NSLayoutConstraint.activate([
|
|
99
|
+
rootView.topAnchor.constraint(equalTo: topAnchor),
|
|
100
|
+
rootView.bottomAnchor.constraint(equalTo: bottomAnchor),
|
|
101
|
+
rootView.leadingAnchor.constraint(equalTo: leadingAnchor),
|
|
102
|
+
rootView.trailingAnchor.constraint(equalTo: trailingAnchor),
|
|
103
|
+
])
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
func confirm(sdkAuthorization: String, paymentToken: String, paymentMethodId: String? = nil) {
|
|
108
|
+
let payload: [String: Any] = [
|
|
109
|
+
"actionType": "CONFIRM_CVC_PAYMENT",
|
|
110
|
+
"rootTag": self.widgetReactTag ?? -1,
|
|
111
|
+
"sdkAuthorization": sdkAuthorization,
|
|
112
|
+
"paymentToken": paymentToken,
|
|
113
|
+
"paymentMethodId": paymentMethodId as Any,
|
|
114
|
+
]
|
|
115
|
+
self.rootView?.bridge.enqueueJSCall(
|
|
116
|
+
"RCTDeviceEventEmitter",
|
|
117
|
+
method: "emit",
|
|
118
|
+
args: ["triggerWidgetAction", payload],
|
|
119
|
+
completion: nil
|
|
120
|
+
)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
internal func dispatchPaymentEvent(type: String, payload: [String: Any]) {
|
|
124
|
+
guard let listener = paymentEventListener else { return }
|
|
125
|
+
let event = PaymentEvent(type: type, payload: payload)
|
|
126
|
+
if Thread.isMainThread {
|
|
127
|
+
listener.onPaymentEvent(event)
|
|
128
|
+
} else {
|
|
129
|
+
DispatchQueue.main.async { listener.onPaymentEvent(event) }
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
internal func setPaymentEventListener(_ listener: PaymentEventListener?) {
|
|
134
|
+
self.paymentEventListener = listener
|
|
135
|
+
}
|
|
136
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
//
|
|
2
|
+
// ExpressCheckoutLauncher.swift
|
|
3
|
+
// Hyperswitch
|
|
4
|
+
//
|
|
5
|
+
// Created by Harshit Srivastava on 21/02/24.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
import Foundation
|
|
9
|
+
import React
|
|
10
|
+
import WebKit
|
|
11
|
+
|
|
12
|
+
@frozen public enum ExpressCheckoutResult {
|
|
13
|
+
case completed(data: String)
|
|
14
|
+
case canceled(data: String)
|
|
15
|
+
case failed(error: Error)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
public class ExpressCheckoutLauncher {
|
|
19
|
+
|
|
20
|
+
init() {}
|
|
21
|
+
|
|
22
|
+
static var configuration: PaymentSheet.Configuration?
|
|
23
|
+
static var sdkAuthorization: String?
|
|
24
|
+
static var completion: ((ExpressCheckoutResult) -> Void)?
|
|
25
|
+
static var themes: String?
|
|
26
|
+
|
|
27
|
+
public convenience init(
|
|
28
|
+
sdkAuthorization: String,
|
|
29
|
+
configuration: PaymentSheet.Configuration,
|
|
30
|
+
themes: String? = nil,
|
|
31
|
+
completion: @escaping ((ExpressCheckoutResult) -> Void)
|
|
32
|
+
) {
|
|
33
|
+
|
|
34
|
+
self.init()
|
|
35
|
+
|
|
36
|
+
ExpressCheckoutLauncher.configuration = configuration
|
|
37
|
+
ExpressCheckoutLauncher.sdkAuthorization = sdkAuthorization
|
|
38
|
+
ExpressCheckoutLauncher.themes = themes
|
|
39
|
+
ExpressCheckoutLauncher.completion = completion
|
|
40
|
+
|
|
41
|
+
let props: [String: Any] = [
|
|
42
|
+
"publishableKey": APIClient.shared.publishableKey as Any,
|
|
43
|
+
"profileId": APIClient.shared.profileId as Any,
|
|
44
|
+
"sdkAuthorization": sdkAuthorization,
|
|
45
|
+
"paymentMethodType": "expressCheckout",
|
|
46
|
+
"paymentMethodData": "",
|
|
47
|
+
"confirm": false,
|
|
48
|
+
]
|
|
49
|
+
// HyperModule.shared?.confirmEC(data: props) //MARK: WIP
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
public func launchPaymentSheet(paymentResult: NSMutableDictionary, callBack: @escaping RCTResponseSenderBlock) {
|
|
53
|
+
|
|
54
|
+
DispatchQueue.main.async {
|
|
55
|
+
|
|
56
|
+
RNViewManager.sharedInstance.responseHandler = self
|
|
57
|
+
|
|
58
|
+
let hyperParams = SDKParams.getSDKParams()
|
|
59
|
+
|
|
60
|
+
let props: [String: Any] = [
|
|
61
|
+
"type": "widgetPayment",
|
|
62
|
+
"sdkAuthorization": ExpressCheckoutLauncher.sdkAuthorization as Any,
|
|
63
|
+
"publishableKey": APIClient.shared.publishableKey as Any,
|
|
64
|
+
"profileId": APIClient.shared.profileId as Any,
|
|
65
|
+
"hyperParams": hyperParams,
|
|
66
|
+
"customBackendUrl": APIClient.shared.customBackendUrl as Any,
|
|
67
|
+
"customLogUrl": APIClient.shared.customLogUrl as Any,
|
|
68
|
+
"customParams": APIClient.shared.customParams as Any,
|
|
69
|
+
]
|
|
70
|
+
|
|
71
|
+
let rootView = RNViewManager.sharedInstance.viewForModule("hyperSwitch", initialProperties: ["props": props])
|
|
72
|
+
|
|
73
|
+
rootView.backgroundColor = UIColor.clear
|
|
74
|
+
|
|
75
|
+
let paymentSheetViewController = UIViewController()
|
|
76
|
+
paymentSheetViewController.modalPresentationStyle = .overFullScreen
|
|
77
|
+
paymentSheetViewController.view = rootView
|
|
78
|
+
|
|
79
|
+
RCTPresentedViewController()!.present(paymentSheetViewController, animated: false)
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
extension ExpressCheckoutLauncher: RNResponseHandler {
|
|
86
|
+
func didReceiveResponse(response: String?, error: Error?) {
|
|
87
|
+
|
|
88
|
+
if let completion = ExpressCheckoutLauncher.completion {
|
|
89
|
+
if let error = error {
|
|
90
|
+
completion(.failed(error: error))
|
|
91
|
+
} else if response == "cancelled" {
|
|
92
|
+
completion(.canceled(data: "cancelled"))
|
|
93
|
+
} else {
|
|
94
|
+
completion(.completed(data: response ?? "failed"))
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
extension ExpressCheckoutLauncher {
|
|
101
|
+
public func confirm() {
|
|
102
|
+
|
|
103
|
+
ExpressCheckoutLauncher.completion = ExpressCheckoutLauncher.completion
|
|
104
|
+
RNViewManager.sharedInstance.responseHandler = self
|
|
105
|
+
|
|
106
|
+
var props: [String: Any] = [
|
|
107
|
+
"publishableKey": APIClient.shared.publishableKey as Any,
|
|
108
|
+
"profileId": APIClient.shared.profileId as Any,
|
|
109
|
+
"sdkAuthorization": ExpressCheckoutLauncher.sdkAuthorization as Any,
|
|
110
|
+
"paymentMethodType": "expressCheckout",
|
|
111
|
+
"paymentMethodData": "",
|
|
112
|
+
"confirm": true,
|
|
113
|
+
]
|
|
114
|
+
// HyperModule.shared?.confirmEC(data: props) //MARK: WIP
|
|
115
|
+
}
|
|
116
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
//
|
|
2
|
+
// ExpressCheckout.swift
|
|
3
|
+
// Hyperswitch
|
|
4
|
+
//
|
|
5
|
+
// Created by Harshit Srivastava on 21/02/24.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
import Foundation
|
|
9
|
+
|
|
10
|
+
public class ExpressCheckout: UIControl {
|
|
11
|
+
|
|
12
|
+
required public init?(
|
|
13
|
+
coder aDecoder: NSCoder
|
|
14
|
+
) {
|
|
15
|
+
super.init(coder: aDecoder)
|
|
16
|
+
commonInit()
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
public override init(
|
|
20
|
+
frame: CGRect
|
|
21
|
+
) {
|
|
22
|
+
super.init(frame: frame)
|
|
23
|
+
self.backgroundColor = .clear
|
|
24
|
+
commonInit()
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
public override var intrinsicContentSize: CGSize {
|
|
28
|
+
return CGSize(width: self.frame.width, height: 52.0)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
func commonInit() {
|
|
32
|
+
|
|
33
|
+
let cardView = RNViewManager.sharedInstance.viewForModule("hyperSwitch", initialProperties: ["props": ["type": "expressCheckout"]])
|
|
34
|
+
cardView.backgroundColor = UIColor.clear
|
|
35
|
+
addSubview(cardView)
|
|
36
|
+
cardView.translatesAutoresizingMaskIntoConstraints = false
|
|
37
|
+
cardView.centerYAnchor.constraint(equalTo: self.centerYAnchor).isActive = true
|
|
38
|
+
cardView.leadingAnchor.constraint(equalTo: self.leadingAnchor).isActive = true
|
|
39
|
+
cardView.trailingAnchor.constraint(equalTo: self.trailingAnchor).isActive = true
|
|
40
|
+
cardView.heightAnchor.constraint(equalToConstant: 52.0).isActive = true
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
//
|
|
2
|
+
// PaymentCardTextField+SwiftUI.swift
|
|
3
|
+
// Hyperswitch
|
|
4
|
+
//
|
|
5
|
+
// Created by Harshit Srivastava on 10/05/23.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
import Combine
|
|
9
|
+
import SwiftUI
|
|
10
|
+
|
|
11
|
+
extension PaymentCardTextField {
|
|
12
|
+
|
|
13
|
+
@available(iOS 13.0, *)
|
|
14
|
+
public struct Representable: UIViewRepresentable {
|
|
15
|
+
@Binding var paymentMethodParams: PaymentMethodParams?
|
|
16
|
+
|
|
17
|
+
public typealias UIViewType = PaymentCardTextField
|
|
18
|
+
|
|
19
|
+
public init(paymentMethodParams: Binding<PaymentMethodParams?>) {
|
|
20
|
+
_paymentMethodParams = paymentMethodParams
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public func makeUIView(context: Context) -> PaymentCardTextField {
|
|
24
|
+
let cardTextField = PaymentCardTextField()
|
|
25
|
+
cardTextField.setContentHuggingPriority(.defaultHigh, for: .vertical)
|
|
26
|
+
return cardTextField
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
public func updateUIView(_ uiView: PaymentCardTextField, context: Context) {
|
|
30
|
+
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
@available(iOS 13.0, *)
|
|
35
|
+
extension View {
|
|
36
|
+
public func paymentConfirmationSheet(
|
|
37
|
+
isConfirmingPayment: Binding<Bool>,
|
|
38
|
+
paymentIntentParams: PaymentIntentParams,
|
|
39
|
+
onCompletion: @escaping PaymentHandler.PaymentHandlerActionPaymentIntentCompletionBlock
|
|
40
|
+
) -> some View {
|
|
41
|
+
self.modifier(
|
|
42
|
+
PaymentConfirmationModifier(
|
|
43
|
+
isConfirmingPayment: isConfirmingPayment,
|
|
44
|
+
paymentIntentParams: paymentIntentParams,
|
|
45
|
+
onCompletion: onCompletion
|
|
46
|
+
)
|
|
47
|
+
)
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
@available(iOS 13.0, *)
|
|
51
|
+
struct PaymentConfirmationModifier: ViewModifier {
|
|
52
|
+
@Binding var isConfirmingPayment: Bool
|
|
53
|
+
let paymentIntentParams: PaymentIntentParams
|
|
54
|
+
let onCompletion: PaymentHandler.PaymentHandlerActionPaymentIntentCompletionBlock
|
|
55
|
+
|
|
56
|
+
func body(content: Content) -> some View {
|
|
57
|
+
content
|
|
58
|
+
.onReceive(Just(isConfirmingPayment)) { newValue in
|
|
59
|
+
if newValue {
|
|
60
|
+
DispatchQueue.main.async {
|
|
61
|
+
PaymentHandler.sharedHandler.confirmPayment(paymentIntentParams, with: UIViewController(), completion: onCompletion)
|
|
62
|
+
isConfirmingPayment = false
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
//
|
|
2
|
+
// PaymentCardTextField.swift
|
|
3
|
+
// Hyperswitch
|
|
4
|
+
//
|
|
5
|
+
// Created by Harshit Srivastava on 10/05/23.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
import Foundation
|
|
9
|
+
|
|
10
|
+
public class PaymentCardTextField: UIControl {
|
|
11
|
+
|
|
12
|
+
required public init?(
|
|
13
|
+
coder aDecoder: NSCoder
|
|
14
|
+
) {
|
|
15
|
+
super.init(coder: aDecoder)
|
|
16
|
+
commonInit()
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
public override init(
|
|
20
|
+
frame: CGRect
|
|
21
|
+
) {
|
|
22
|
+
super.init(frame: frame)
|
|
23
|
+
self.backgroundColor = .clear
|
|
24
|
+
commonInit()
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
public override var intrinsicContentSize: CGSize {
|
|
28
|
+
return CGSize(width: self.frame.width, height: 52.0)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
@objc public var paymentMethodParams: PaymentMethodParams?
|
|
32
|
+
|
|
33
|
+
func commonInit() {
|
|
34
|
+
|
|
35
|
+
let cardView = RNViewManager.sharedInstance.viewForModule("hyperSwitch", initialProperties: ["props": ["type": "card"]])
|
|
36
|
+
cardView.backgroundColor = UIColor.clear
|
|
37
|
+
addSubview(cardView)
|
|
38
|
+
cardView.translatesAutoresizingMaskIntoConstraints = false
|
|
39
|
+
cardView.centerYAnchor.constraint(equalTo: self.centerYAnchor).isActive = true
|
|
40
|
+
cardView.leadingAnchor.constraint(equalTo: self.leadingAnchor).isActive = true
|
|
41
|
+
cardView.trailingAnchor.constraint(equalTo: self.trailingAnchor).isActive = true
|
|
42
|
+
cardView.heightAnchor.constraint(equalToConstant: 52.0).isActive = true
|
|
43
|
+
}
|
|
44
|
+
}
|