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,59 @@
|
|
|
1
|
+
//
|
|
2
|
+
// PaymentHandler.swift
|
|
3
|
+
// Hyperswitch
|
|
4
|
+
//
|
|
5
|
+
// Created by Harshit Srivastava on 10/05/23.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
public class PaymentHandler: NSObject {
|
|
9
|
+
|
|
10
|
+
@objc public static let sharedHandler: PaymentHandler = PaymentHandler()
|
|
11
|
+
@objc var completion: PaymentHandlerActionPaymentIntentCompletionBlock?
|
|
12
|
+
@objc public class func shared() -> PaymentHandler {
|
|
13
|
+
return PaymentHandler.sharedHandler
|
|
14
|
+
}
|
|
15
|
+
internal init(apiClient: APIClient = .shared) {
|
|
16
|
+
self.apiClient = apiClient
|
|
17
|
+
super.init()
|
|
18
|
+
}
|
|
19
|
+
internal var apiClient: APIClient
|
|
20
|
+
|
|
21
|
+
@objc(confirmPayment:withAuthenticationContext:completion:)
|
|
22
|
+
public func confirmPayment(
|
|
23
|
+
_ paymentParams: PaymentIntentParams,
|
|
24
|
+
with authenticationContext: UIViewController,
|
|
25
|
+
completion: @escaping PaymentHandlerActionPaymentIntentCompletionBlock
|
|
26
|
+
) {
|
|
27
|
+
self.completion = completion
|
|
28
|
+
|
|
29
|
+
RNViewManager.sharedInstance.responseHandler = self
|
|
30
|
+
HyperModule.shared?.confirm(data: paymentParams.description())
|
|
31
|
+
}
|
|
32
|
+
public typealias PaymentHandlerActionPaymentIntentCompletionBlock = (
|
|
33
|
+
PaymentHandlerActionStatus, PaymentIntent?, NSError?
|
|
34
|
+
) -> Void
|
|
35
|
+
|
|
36
|
+
@objc public enum PaymentHandlerActionStatus: Int {
|
|
37
|
+
case succeeded
|
|
38
|
+
case canceled
|
|
39
|
+
case failed
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
public class PaymentIntent: NSObject {
|
|
44
|
+
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
extension PaymentHandler: RNResponseHandler {
|
|
48
|
+
func didReceiveResponse(response: String?, error: Error?) {
|
|
49
|
+
if let completion = completion {
|
|
50
|
+
if let error = error {
|
|
51
|
+
completion(.failed, nil, error as NSError)
|
|
52
|
+
} else if response == "cancelled" {
|
|
53
|
+
completion(.canceled, nil, nil)
|
|
54
|
+
} else {
|
|
55
|
+
completion(.succeeded, nil, nil)
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
//
|
|
2
|
+
// PaymentIntentParams.swift
|
|
3
|
+
// Hyperswitch
|
|
4
|
+
//
|
|
5
|
+
// Created by Harshit Srivastava on 10/05/23.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
import Foundation
|
|
9
|
+
import UIKit
|
|
10
|
+
|
|
11
|
+
public class PaymentIntentParams: NSObject {
|
|
12
|
+
|
|
13
|
+
public init(sdkAuthorization: String) {
|
|
14
|
+
self.sdkAuthorization = sdkAuthorization
|
|
15
|
+
super.init()
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
public var sdkAuthorization: String = ""
|
|
19
|
+
@objc public var paymentMethodParams: PaymentMethodParams?
|
|
20
|
+
|
|
21
|
+
public func description() -> [String: Any] {
|
|
22
|
+
let props: [String: Any] = [
|
|
23
|
+
"publishableKey": APIClient.shared.publishableKey ?? "",
|
|
24
|
+
"profileId": APIClient.shared.profileId ?? "",
|
|
25
|
+
"sdkAuthorization": self.sdkAuthorization,
|
|
26
|
+
"paymentMethodType": "Card",
|
|
27
|
+
"paymentMethodData": "",
|
|
28
|
+
]
|
|
29
|
+
return props
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
//
|
|
2
|
+
// PaymentMethodParams.swift
|
|
3
|
+
// Hyperswitch
|
|
4
|
+
//
|
|
5
|
+
// Created by Harshit Srivastava on 10/05/23.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
import Foundation
|
|
9
|
+
import UIKit
|
|
10
|
+
|
|
11
|
+
public class PaymentMethodParams: NSObject {
|
|
12
|
+
|
|
13
|
+
public init(card: String?, billingDetails: String?, metadata: String?) {
|
|
14
|
+
self.card = card
|
|
15
|
+
self.billingDetails = billingDetails
|
|
16
|
+
self.metadata = metadata
|
|
17
|
+
|
|
18
|
+
super.init()
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public var card: String? = ""
|
|
22
|
+
public var billingDetails: String? = ""
|
|
23
|
+
public var metadata: String? = ""
|
|
24
|
+
|
|
25
|
+
}
|
package/ios/hyperswitchSDK/Core/HyperPaymentMethodManagement/PaymentManagementConfiguration.swift
ADDED
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
//
|
|
2
|
+
// PaymentManagementConfiguration.swift
|
|
3
|
+
// hyperswitch
|
|
4
|
+
//
|
|
5
|
+
// Created by Shivam Nan on 30/09/24.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
import Foundation
|
|
9
|
+
import UIKit
|
|
10
|
+
|
|
11
|
+
// MARK: - Payment Methods Management Configuration
|
|
12
|
+
|
|
13
|
+
/// Configuration for Payment Method Management Sheet
|
|
14
|
+
public struct PMMConfiguration: DictionaryConverter {
|
|
15
|
+
/// Describes the appearance of PaymentSheet
|
|
16
|
+
public var appearance = PMMAppearance.default
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/// Describes the appearance of Payment Method Management Sheet
|
|
20
|
+
public struct PMMAppearance: Equatable, DictionaryConverter {
|
|
21
|
+
/// The default appearance for PaymentSheet
|
|
22
|
+
public static let `default` = PMMAppearance()
|
|
23
|
+
|
|
24
|
+
/// Creates a `PaymentSheet.Appearance` with default values
|
|
25
|
+
public init() {}
|
|
26
|
+
|
|
27
|
+
/// Describes the appearance of fonts in PaymentSheet
|
|
28
|
+
public var font: Font = Font()
|
|
29
|
+
|
|
30
|
+
/// Describes the colors in PaymentSheet
|
|
31
|
+
public var colors: Colors = Colors()
|
|
32
|
+
|
|
33
|
+
/// The corner radius used for buttons, inputs, tabs in PaymentSheet
|
|
34
|
+
/// - Note: The behavior of this property is consistent with the behavior of corner radius on `CALayer`
|
|
35
|
+
public var cornerRadius: CGFloat?
|
|
36
|
+
|
|
37
|
+
/// The border used for inputs and tabs in PaymentSheet
|
|
38
|
+
/// - Note: The behavior of this property is consistent with the behavior of border width on `CALayer`
|
|
39
|
+
public var borderWidth: CGFloat?
|
|
40
|
+
|
|
41
|
+
/// The shadow used for inputs and tabs in PaymentSheet
|
|
42
|
+
/// - Note: Set this to `.disabled` to disable shadows
|
|
43
|
+
public var shadow: Shadow?
|
|
44
|
+
|
|
45
|
+
public var theme: Theme?
|
|
46
|
+
|
|
47
|
+
public enum Theme {
|
|
48
|
+
case `default`
|
|
49
|
+
case light
|
|
50
|
+
case dark
|
|
51
|
+
case minimal
|
|
52
|
+
case flatMinimal
|
|
53
|
+
|
|
54
|
+
var themeLabel: String {
|
|
55
|
+
switch self {
|
|
56
|
+
case .`default`:
|
|
57
|
+
return "Default"
|
|
58
|
+
case .light:
|
|
59
|
+
return "Light"
|
|
60
|
+
case .dark:
|
|
61
|
+
return "Dark"
|
|
62
|
+
case .minimal:
|
|
63
|
+
return "Minimal"
|
|
64
|
+
case .flatMinimal:
|
|
65
|
+
return "FlatMinimal"
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// MARK: Fonts
|
|
71
|
+
/// Describes the appearance of fonts in PaymentSheet
|
|
72
|
+
public struct Font: Equatable, DictionaryConverter {
|
|
73
|
+
|
|
74
|
+
/// Creates a `PaymentSheet.Appearance.Font` with default values
|
|
75
|
+
public init() {}
|
|
76
|
+
|
|
77
|
+
/// The scale factor for all font sizes in PaymentSheet.
|
|
78
|
+
/// Font sizes are multiplied by this value before being displayed. For example, setting this to 1.2 increases the size of all text by 20%.
|
|
79
|
+
/// - Note: This value must be greater than 0. The default value is 1.0.
|
|
80
|
+
/// - Note: This is used in conjunction with the Dynamic Type accessibility text size.
|
|
81
|
+
public var sizeScaleFactor: CGFloat?
|
|
82
|
+
|
|
83
|
+
/// The font family of this font is used throughout PaymentSheet. PaymentSheet uses this font at multiple weights (e.g., regular, medium, semibold) if they exist.
|
|
84
|
+
/// - Note: The size and weight of the font is ignored. To adjust font sizes, see `sizeScaleFactor`.
|
|
85
|
+
public var base: UIFont?
|
|
86
|
+
|
|
87
|
+
/// The size adjustment for all heading texts in PaymentSheet
|
|
88
|
+
/// Font sizes of all headings will be increased by this value from their respective default size
|
|
89
|
+
public var headingTextSizeAdjust: CGFloat?
|
|
90
|
+
|
|
91
|
+
/// The size for all sub heading texts in PaymentSheet
|
|
92
|
+
/// Font sizes of all sub headings will be increased by this value from their respective default size
|
|
93
|
+
public var subHeadingTextSizeAdjust: CGFloat?
|
|
94
|
+
|
|
95
|
+
/// The size for all placeholder texts in PaymentSheet
|
|
96
|
+
/// Font sizes of all placeholder texts will be increased by this value from their respective default size
|
|
97
|
+
public var placeholderTextSizeAdjust: CGFloat?
|
|
98
|
+
|
|
99
|
+
/// The size for all button texts in PaymentSheet
|
|
100
|
+
/// Font sizes of all button texts will be increased by this value from their respective default size
|
|
101
|
+
public var buttonTextSizeAdjust: CGFloat?
|
|
102
|
+
|
|
103
|
+
/// The size for all error texts in PaymentSheet
|
|
104
|
+
/// Font sizes of all error texts will be increased by this value from their respective default size
|
|
105
|
+
public var errorTextSizeAdjust: CGFloat?
|
|
106
|
+
|
|
107
|
+
/// The size for all link texts in PaymentSheet
|
|
108
|
+
/// Font sizes of all link texts will be increased by this value from their respective default size
|
|
109
|
+
public var linkTextSizeAdjust: CGFloat?
|
|
110
|
+
|
|
111
|
+
/// The size for all modal texts in PaymentSheet
|
|
112
|
+
/// Font sizes of all modal texts will be increased by this value from their respective default size
|
|
113
|
+
public var modalTextSizeAdjust: CGFloat?
|
|
114
|
+
|
|
115
|
+
/// The size for all card texts in PaymentSheet
|
|
116
|
+
/// Font sizes of all card texts will be increased by this value from their respective default size
|
|
117
|
+
public var cardTextSizeAdjust: CGFloat?
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// MARK: Colors
|
|
121
|
+
/// Describes the colors in PaymentSheet
|
|
122
|
+
public struct Colors: Equatable, DictionaryConverter {
|
|
123
|
+
|
|
124
|
+
/// Creates a `PaymentSheet.Appearance.Colors` with default values
|
|
125
|
+
public init() {}
|
|
126
|
+
|
|
127
|
+
/// The primary color used throughout PaymentSheet
|
|
128
|
+
public var primary: UIColor?
|
|
129
|
+
|
|
130
|
+
/// The color used for the background of PaymentSheet
|
|
131
|
+
public var background: UIColor?
|
|
132
|
+
|
|
133
|
+
/// The color used for the background of inputs, tabs, and other components
|
|
134
|
+
public var componentBackground: UIColor?
|
|
135
|
+
|
|
136
|
+
/// The border color used for inputs, tabs, and other components
|
|
137
|
+
public var componentBorder: UIColor?
|
|
138
|
+
|
|
139
|
+
/// The color of the divider lines used inside inputs, tabs, and other components
|
|
140
|
+
public var componentDivider: UIColor?
|
|
141
|
+
|
|
142
|
+
/// The default text color used in PaymentSheet, appearing over the background color
|
|
143
|
+
public var text: UIColor?
|
|
144
|
+
|
|
145
|
+
/// The color used for text of secondary importance. For example, this color is used for the label above input fields
|
|
146
|
+
public var textSecondary: UIColor?
|
|
147
|
+
|
|
148
|
+
/// The color of text appearing over `componentBackground`
|
|
149
|
+
public var componentText: UIColor?
|
|
150
|
+
|
|
151
|
+
/// The color used for input placeholder text
|
|
152
|
+
public var componentPlaceholderText: UIColor?
|
|
153
|
+
|
|
154
|
+
/// The color used for icons in PaymentSheet, such as the close or back icons
|
|
155
|
+
public var icon: UIColor?
|
|
156
|
+
|
|
157
|
+
/// The color used to indicate errors or destructive actions in PaymentSheet
|
|
158
|
+
public var danger: UIColor?
|
|
159
|
+
|
|
160
|
+
/// The color used to indicate Loader Background Color
|
|
161
|
+
public var loaderBackground: UIColor?
|
|
162
|
+
|
|
163
|
+
/// The color used to indicate Loader Foreground Color
|
|
164
|
+
public var loaderForeground: UIColor?
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// MARK: Shadow
|
|
168
|
+
/// Represents a shadow in PaymentSheet
|
|
169
|
+
public struct Shadow: Equatable, DictionaryConverter {
|
|
170
|
+
|
|
171
|
+
/// A pre-configured `Shadow` in the disabled or off state
|
|
172
|
+
public static var disabled: Shadow?
|
|
173
|
+
|
|
174
|
+
/// Color of the shadow
|
|
175
|
+
/// - Note: The behavior of this property is consistent with `CALayer.shadowColor`
|
|
176
|
+
public var color: UIColor?
|
|
177
|
+
|
|
178
|
+
/// Opacity or alpha of the shadow
|
|
179
|
+
/// - Note: The behavior of this property is consistent with `CALayer.shadowOpacity`
|
|
180
|
+
public var opacity: CGFloat?
|
|
181
|
+
|
|
182
|
+
/// Offset of the shadow
|
|
183
|
+
/// - Note: The behavior of this property is consistent with `CALayer.shadowOffset`
|
|
184
|
+
public var offset: CGSize?
|
|
185
|
+
|
|
186
|
+
/// Radius of the shadow
|
|
187
|
+
/// - Note: The behavior of this property is consistent with `CALayer.shadowRadius`
|
|
188
|
+
public var radius: CGFloat?
|
|
189
|
+
|
|
190
|
+
/// intensity of the shadow
|
|
191
|
+
/// - Note: The behavior of this property is consistent with `CALayer.shadowIntensity`
|
|
192
|
+
public var intensity: CGFloat?
|
|
193
|
+
|
|
194
|
+
/// Creates a `PaymentSheet.Appearance.Shadow` with default values
|
|
195
|
+
public init() {}
|
|
196
|
+
|
|
197
|
+
/// Creates a `Shadow` with the specified parameters
|
|
198
|
+
/// - Parameters:
|
|
199
|
+
/// - color: Color of the shadow
|
|
200
|
+
/// - opacity: Opacity or opacity of the shadow
|
|
201
|
+
/// - offset: Offset of the shadow
|
|
202
|
+
/// - radius: Radius of the shadow
|
|
203
|
+
/// - intensity: Intensity of the shadow
|
|
204
|
+
public init(color: UIColor?, opacity: CGFloat?, offset: CGSize?, radius: CGFloat?, intensity: CGFloat?) {
|
|
205
|
+
self.color = color
|
|
206
|
+
self.opacity = opacity
|
|
207
|
+
self.offset = offset
|
|
208
|
+
self.radius = radius
|
|
209
|
+
self.intensity = intensity
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
}
|
package/ios/hyperswitchSDK/Core/HyperPaymentMethodManagement/PaymentMethodManagementWidget.swift
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
//
|
|
2
|
+
// PaymentMethodManagementWidget.swift
|
|
3
|
+
// hyperswitch
|
|
4
|
+
//
|
|
5
|
+
// Created by Shivam Nan on 18/10/24.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
import Foundation
|
|
9
|
+
import UIKit
|
|
10
|
+
import WebKit
|
|
11
|
+
|
|
12
|
+
/// PaymentResult is an enum that represents the possible outcomes of a payment sheet operation.
|
|
13
|
+
@frozen public enum PaymentMethodManagementResult {
|
|
14
|
+
case closed(data: String)
|
|
15
|
+
case failed(error: Error)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
internal class PaymentMethodManagementWidget: UIControl {
|
|
19
|
+
internal static var onAddPaymentMethod: (() -> Void)?
|
|
20
|
+
private var completion: ((PaymentMethodManagementResult) -> Void)?
|
|
21
|
+
|
|
22
|
+
// Initialize the widget with the ephemeral key and configuration.
|
|
23
|
+
public init(onAddPaymentMethod: (() -> Void)?, completion: @escaping (PaymentMethodManagementResult) -> Void) {
|
|
24
|
+
PaymentMethodManagementWidget.onAddPaymentMethod = onAddPaymentMethod
|
|
25
|
+
self.completion = completion
|
|
26
|
+
super.init(frame: .zero)
|
|
27
|
+
commonInit()
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
required public init?(
|
|
31
|
+
coder: NSCoder
|
|
32
|
+
) {
|
|
33
|
+
super.init(coder: coder)
|
|
34
|
+
commonInit()
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
public override init(
|
|
38
|
+
frame: CGRect
|
|
39
|
+
) {
|
|
40
|
+
super.init(frame: frame)
|
|
41
|
+
commonInit()
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
private func commonInit() {
|
|
45
|
+
let hyperParams = SDKParams.getSDKParams()
|
|
46
|
+
|
|
47
|
+
// Prepare the props to send to the React Native module.
|
|
48
|
+
let props: [String: Any] = [
|
|
49
|
+
"type": "paymentMethodsManagement",
|
|
50
|
+
"hyperParams": hyperParams,
|
|
51
|
+
// "ephemeralKey": PaymentSession.ephemeralKey ?? "", // TODO: use paymentSession.ephemeralKey
|
|
52
|
+
"publishableKey": APIClient.shared.publishableKey as Any,
|
|
53
|
+
"profileId": APIClient.shared.profileId as Any,
|
|
54
|
+
"customBackendUrl": APIClient.shared.customBackendUrl as Any,
|
|
55
|
+
"customLogUrl": APIClient.shared.customLogUrl as Any,
|
|
56
|
+
"customParams": APIClient.shared.customParams as Any,
|
|
57
|
+
]
|
|
58
|
+
|
|
59
|
+
RNViewManager.sharedInstance.responseHandler = self
|
|
60
|
+
|
|
61
|
+
// Get the React Native view from RNViewManager.
|
|
62
|
+
let rootView = RNViewManager.sharedInstance.viewForModule("hyperSwitch", initialProperties: ["props": props])
|
|
63
|
+
|
|
64
|
+
rootView.frame = self.bounds
|
|
65
|
+
|
|
66
|
+
// Add the React Native view to the current view.
|
|
67
|
+
addSubview(rootView)
|
|
68
|
+
|
|
69
|
+
rootView.translatesAutoresizingMaskIntoConstraints = false
|
|
70
|
+
NSLayoutConstraint.activate([
|
|
71
|
+
rootView.topAnchor.constraint(equalTo: self.topAnchor),
|
|
72
|
+
rootView.bottomAnchor.constraint(equalTo: self.bottomAnchor),
|
|
73
|
+
rootView.leadingAnchor.constraint(equalTo: self.leadingAnchor),
|
|
74
|
+
rootView.trailingAnchor.constraint(equalTo: self.trailingAnchor),
|
|
75
|
+
])
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/// An extension that conforms to the RNResponseHandler protocol, which handles the response from the payment sheet operation.
|
|
80
|
+
extension PaymentMethodManagementWidget: RNResponseHandler {
|
|
81
|
+
func didReceiveResponse(response: String?, error: Error?) {
|
|
82
|
+
if let completion = completion {
|
|
83
|
+
if let error = error {
|
|
84
|
+
completion(.failed(error: error))
|
|
85
|
+
} else if response == "cancelled" {
|
|
86
|
+
completion(.closed(data: "cancelled"))
|
|
87
|
+
} else {
|
|
88
|
+
completion(.closed(data: response ?? "failed"))
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
//
|
|
2
|
+
// PaymentSheet+Events.swift
|
|
3
|
+
// hyperswitch
|
|
4
|
+
//
|
|
5
|
+
// Created by Harshit Srivastava on 07/05/26.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
import Foundation
|
|
9
|
+
|
|
10
|
+
extension PaymentSheet {
|
|
11
|
+
internal func dispatchPaymentEvent(type: String, payload: [String: Any]) {
|
|
12
|
+
guard let listener = paymentEventListener else { return }
|
|
13
|
+
let event = PaymentEvent(type: type, payload: payload)
|
|
14
|
+
if Thread.isMainThread {
|
|
15
|
+
listener.onPaymentEvent(event)
|
|
16
|
+
} else {
|
|
17
|
+
DispatchQueue.main.async { listener.onPaymentEvent(event) }
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public func shouldProceedWithPayment(_ callback: @escaping (PaymentRequestData, @escaping (Bool) -> Void) -> Void) {
|
|
22
|
+
self.shouldProceedWithPaymentCallback = callback
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
internal func handleShouldProceedWithPayment(payload: String, callback: @escaping (Bool) -> Void) {
|
|
26
|
+
if self.shouldProceedWithPaymentCallback == nil {
|
|
27
|
+
callback(true)
|
|
28
|
+
} else {
|
|
29
|
+
if let data = payload.data(using: .utf8),
|
|
30
|
+
let paymentRequestData = try? JSONDecoder().decode(PaymentRequestData.self, from: data)
|
|
31
|
+
{
|
|
32
|
+
shouldProceedWithPaymentCallback?(paymentRequestData, callback)
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
//
|
|
2
|
+
// PaymentSheetView+SwiftUI.swift
|
|
3
|
+
// Hyperswitch
|
|
4
|
+
//
|
|
5
|
+
// Created by Balaganesh on 09/12/22.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
import Foundation
|
|
9
|
+
import React
|
|
10
|
+
import SwiftUI
|
|
11
|
+
|
|
12
|
+
/// Extension on the PaymentSheet class to provide a SwiftUI integration for presenting the payment sheet.
|
|
13
|
+
extension PaymentSheet {
|
|
14
|
+
|
|
15
|
+
/// A SwiftUI View struct that represents a button for presenting the payment sheet.
|
|
16
|
+
@available(iOS 13.0, *)
|
|
17
|
+
public struct PaymentButton<Content: View>: View {
|
|
18
|
+
private let paymentSession: PaymentSession
|
|
19
|
+
private let configuration: Configuration
|
|
20
|
+
private let content: Content
|
|
21
|
+
private let completion: (PaymentResult) -> Void
|
|
22
|
+
|
|
23
|
+
@Environment(\.viewController) private var viewControllerHolder: UIViewController?
|
|
24
|
+
|
|
25
|
+
/// Initializer for the PaymentButton.
|
|
26
|
+
public init(
|
|
27
|
+
paymentSession: PaymentSession,
|
|
28
|
+
configuration: Configuration,
|
|
29
|
+
onCompletion: @escaping (PaymentResult) -> Void,
|
|
30
|
+
@ViewBuilder content: () -> Content
|
|
31
|
+
) {
|
|
32
|
+
self.paymentSession = paymentSession
|
|
33
|
+
self.configuration = configuration
|
|
34
|
+
self.completion = onCompletion
|
|
35
|
+
self.content = content()
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/// The body of the PaymentButton view.
|
|
39
|
+
public var body: some View {
|
|
40
|
+
Button(action: {
|
|
41
|
+
if let vc = viewControllerHolder {
|
|
42
|
+
paymentSession.presentPaymentSheet(viewController: vc, configuration: configuration, completion: completion)
|
|
43
|
+
}
|
|
44
|
+
}) {
|
|
45
|
+
content
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
//
|
|
2
|
+
// PaymentSheetView+UIKit.swift
|
|
3
|
+
// Hyperswitch
|
|
4
|
+
//
|
|
5
|
+
// Created by Harshit Srivastava on 15/12/23.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
import Foundation
|
|
9
|
+
import React
|
|
10
|
+
|
|
11
|
+
/// Extension on the PaymentSheet class to handle the presentation of the payment sheet view.
|
|
12
|
+
internal extension PaymentSheet {
|
|
13
|
+
|
|
14
|
+
/// Method to present the payment sheet view with a given root view and completion handler.
|
|
15
|
+
private func presentWithRootView(
|
|
16
|
+
from presentingViewController: UIViewController,
|
|
17
|
+
rootView: RCTRootView,
|
|
18
|
+
completion: @escaping (PaymentResult) -> Void
|
|
19
|
+
) {
|
|
20
|
+
|
|
21
|
+
self.completion = completion
|
|
22
|
+
|
|
23
|
+
let paymentSheetViewController = HyperUIViewController()
|
|
24
|
+
paymentSheetViewController.paymentSheet = self
|
|
25
|
+
paymentSheetViewController.modalPresentationStyle = .overFullScreen
|
|
26
|
+
paymentSheetViewController.view = rootView
|
|
27
|
+
|
|
28
|
+
/// Present the payment sheet view controller modally from the presenting view controller.
|
|
29
|
+
presentingViewController.present(paymentSheetViewController, animated: false)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/// Method to present the payment sheet view with the default configuration.
|
|
33
|
+
func present(from presentingViewController: UIViewController, completion: @escaping (PaymentResult) -> Void) {
|
|
34
|
+
|
|
35
|
+
// Present the payment sheet view with the root view obtained from the getRootView() method.
|
|
36
|
+
self.presentWithRootView(from: presentingViewController, rootView: self.getRootView(), completion: completion)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/// Method to present the payment sheet view with custom parameters.
|
|
40
|
+
func presentWithParams(
|
|
41
|
+
from presentingViewController: UIViewController,
|
|
42
|
+
props: [String: Any],
|
|
43
|
+
completion: @escaping ((PaymentResult) -> Void)
|
|
44
|
+
) {
|
|
45
|
+
|
|
46
|
+
// Present the payment sheet view with the root view obtained from the getRootViewWithParams() method.
|
|
47
|
+
self.presentWithRootView(from: presentingViewController, rootView: self.getRootViewWithParams(props: props), completion: completion)
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
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() -> RCTRootView {
|
|
17
|
+
|
|
18
|
+
let hyperswitchConfiguration = try? hyperswitchConfiguration?.toDictionary()
|
|
19
|
+
let paymentSessionConfiguration = try? paymentSessionConfiguration.toDictionary()
|
|
20
|
+
|
|
21
|
+
/// Get the configuration dictionary from the configuration object.
|
|
22
|
+
var configuration = try? self.configuration?.toDictionary()
|
|
23
|
+
configuration?["subscribedEvents"] = subscribedEvents
|
|
24
|
+
|
|
25
|
+
/// Create a dictionary of hyperParams with app ID, sdkVersion, country, user agent, default view, and launch time.
|
|
26
|
+
let sdkParams = SDKParams.getSDKParams()
|
|
27
|
+
|
|
28
|
+
/// Create a dictionary of props to be sent to React Native with configuration, type, sdkAuthorization, publishable key, hyperParams, custom backend URL, themes, and custom parameters.
|
|
29
|
+
let props: [String: Any] = [
|
|
30
|
+
"type": "payment",
|
|
31
|
+
"hyperswitchConfig": hyperswitchConfiguration as Any,
|
|
32
|
+
"paymentSessionConfig": paymentSessionConfiguration as Any,
|
|
33
|
+
"sdkParams": sdkParams,
|
|
34
|
+
"configuration": configuration as Any,
|
|
35
|
+
]
|
|
36
|
+
/// Get the root view from the RNViewManager with the "hyperSwitch" module and the props dictionary.
|
|
37
|
+
let rootView = RNViewManager.sharedInstance.viewForModule("hyperSwitch", initialProperties: ["props": props])
|
|
38
|
+
|
|
39
|
+
rootView.backgroundColor = UIColor.clear
|
|
40
|
+
return rootView
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/// Method to get the root view for the payment sheet with custom parameters.
|
|
44
|
+
/// - Note: Used by Flutter and React Native Wrappers to send separate props.
|
|
45
|
+
func getRootViewWithParams(props: [String: Any]) -> RCTRootView {
|
|
46
|
+
|
|
47
|
+
let hyperswitchConfiguration = try? hyperswitchConfiguration?.toDictionary()
|
|
48
|
+
let paymentSessionConfiguration = try? paymentSessionConfiguration.toDictionary()
|
|
49
|
+
|
|
50
|
+
let sdkParams = SDKParams.getSDKParams()
|
|
51
|
+
var propsDict = props
|
|
52
|
+
propsDict["subscribedEvents"] = subscribedEvents
|
|
53
|
+
|
|
54
|
+
let props: [String: Any] = [
|
|
55
|
+
"type": "payment",
|
|
56
|
+
"hyperswitchConfig": hyperswitchConfiguration as Any,
|
|
57
|
+
"paymentSessionConfig": paymentSessionConfiguration as Any,
|
|
58
|
+
"sdkParams": sdkParams,
|
|
59
|
+
"configuration": propsDict,
|
|
60
|
+
"from": "rn",
|
|
61
|
+
]
|
|
62
|
+
|
|
63
|
+
let rootView = RNViewManager.sharedInstance.viewForModule("hyperSwitch", initialProperties: ["props": props])
|
|
64
|
+
|
|
65
|
+
rootView.backgroundColor = UIColor.clear
|
|
66
|
+
return rootView
|
|
67
|
+
}
|
|
68
|
+
}
|