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,251 @@
|
|
|
1
|
+
//
|
|
2
|
+
// ApplePayHandlerLite.swift
|
|
3
|
+
// Hyperswitch
|
|
4
|
+
//
|
|
5
|
+
// Created by Harshit Srivastava on 30/08/24.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
import Foundation
|
|
9
|
+
import PassKit
|
|
10
|
+
|
|
11
|
+
typealias ApplePayCallback = ([[String: Any]]) -> Void
|
|
12
|
+
|
|
13
|
+
internal class ApplePayHandlerLite: NSObject {
|
|
14
|
+
|
|
15
|
+
var paymentStatus: PKPaymentAuthorizationStatus? = .failure
|
|
16
|
+
var callback: ApplePayCallback?
|
|
17
|
+
|
|
18
|
+
internal func startPayment(rnMessage: String, rnCallback: @escaping ApplePayCallback) {
|
|
19
|
+
|
|
20
|
+
callback = rnCallback
|
|
21
|
+
var requiredBillingContactFields: Set<PKContactField>?
|
|
22
|
+
var requiredShippingContactFields: Set<PKContactField>?
|
|
23
|
+
|
|
24
|
+
guard let dict = rnMessage.toJSON() as? [String: AnyObject] else {
|
|
25
|
+
callback?([["status": "Failed", "message": "ApplePay: missing field payment_request_data"]])
|
|
26
|
+
callback = nil
|
|
27
|
+
return
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
guard let payment_request_data = dict["payment_request_data"] else {
|
|
31
|
+
callback?([["status": "Failed", "message": "ApplePay: missing field payment_request_data"]])
|
|
32
|
+
callback = nil
|
|
33
|
+
return
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
guard let countryCode = payment_request_data["country_code"] as? String else {
|
|
37
|
+
callback?([["status": "Failed", "message": "ApplePay: missing field country_code"]])
|
|
38
|
+
callback = nil
|
|
39
|
+
return
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
guard let currencyCode = payment_request_data["currency_code"] as? String else {
|
|
43
|
+
callback?([["status": "Failed", "message": "ApplePay: missing field currency_code"]])
|
|
44
|
+
callback = nil
|
|
45
|
+
return
|
|
46
|
+
}
|
|
47
|
+
guard let total = payment_request_data["total"] as? [String: AnyObject] else {
|
|
48
|
+
callback?([["status": "Failed", "message": "ApplePay: missing field total"]])
|
|
49
|
+
callback = nil
|
|
50
|
+
return
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
guard let amount = total["amount"] as? String,
|
|
54
|
+
let label = total["label"] as? String,
|
|
55
|
+
let type = total["type"] as? String
|
|
56
|
+
else {
|
|
57
|
+
callback?([["status": "Failed", "message": "ApplePay: missing fields amount, label, type"]])
|
|
58
|
+
callback = nil
|
|
59
|
+
return
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
guard let merchant_capabilities_array = payment_request_data["merchant_capabilities"] as? [String] else {
|
|
63
|
+
callback?([["status": "Failed", "message": "ApplePay: missing field merchant_capabilities"]])
|
|
64
|
+
callback = nil
|
|
65
|
+
return
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
guard let merchantIdentifier = payment_request_data["merchant_identifier"] as? String else {
|
|
69
|
+
callback?([["status": "Failed", "message": "ApplePay: missing field merchant_identifier"]])
|
|
70
|
+
callback = nil
|
|
71
|
+
return
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
guard let supported_networks_array = payment_request_data["supported_networks"] as? [String] else {
|
|
75
|
+
callback?([["status": "Failed", "message": "ApplePay: missing field supported_networks"]])
|
|
76
|
+
callback = nil
|
|
77
|
+
return
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
let supportedNetworks = supported_networks_array.compactMap { (string) -> PKPaymentNetwork? in
|
|
81
|
+
switch string {
|
|
82
|
+
case "visa":
|
|
83
|
+
return .visa
|
|
84
|
+
case "masterCard":
|
|
85
|
+
return .masterCard
|
|
86
|
+
case "amex":
|
|
87
|
+
return .amex
|
|
88
|
+
case "discover":
|
|
89
|
+
return .discover
|
|
90
|
+
case "quicPay":
|
|
91
|
+
return .quicPay
|
|
92
|
+
default:
|
|
93
|
+
return nil
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if let required_billing_contact_fields = payment_request_data["required_billing_contact_fields"] as? [String] {
|
|
98
|
+
requiredBillingContactFields = Set(required_billing_contact_fields.compactMap(mapToPKContactField))
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if let required_shipping_contact_fields = payment_request_data["required_shipping_contact_fields"] as? [String] {
|
|
102
|
+
requiredShippingContactFields = Set(required_shipping_contact_fields.compactMap(mapToPKContactField))
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
let paymentSummaryItems = PKPaymentSummaryItem(
|
|
106
|
+
label: label,
|
|
107
|
+
amount: NSDecimalNumber(string: amount),
|
|
108
|
+
type: (type == "final") ? .final : .pending
|
|
109
|
+
)
|
|
110
|
+
let paymentRequest = PKPaymentRequest()
|
|
111
|
+
paymentRequest.paymentSummaryItems = [paymentSummaryItems]
|
|
112
|
+
paymentRequest.merchantIdentifier = merchantIdentifier
|
|
113
|
+
paymentRequest.countryCode = countryCode
|
|
114
|
+
paymentRequest.currencyCode = currencyCode
|
|
115
|
+
paymentRequest.requiredShippingContactFields = requiredShippingContactFields ?? []
|
|
116
|
+
paymentRequest.requiredBillingContactFields = requiredBillingContactFields ?? []
|
|
117
|
+
paymentRequest.supportedNetworks = supportedNetworks
|
|
118
|
+
for val in merchant_capabilities_array {
|
|
119
|
+
paymentRequest.merchantCapabilities = (val == "supports3DS") ? .threeDSecure : .debit
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/// Create and present the PKPaymentAuthorizationController
|
|
123
|
+
guard
|
|
124
|
+
PKPaymentAuthorizationController.canMakePayments(),
|
|
125
|
+
!paymentRequest.merchantIdentifier.isEmpty,
|
|
126
|
+
PKPaymentAuthorizationViewController(paymentRequest: paymentRequest) != nil
|
|
127
|
+
else {
|
|
128
|
+
callback?([["status": "Failed", "message": "ApplePay: cannot make payments"]])
|
|
129
|
+
callback = nil
|
|
130
|
+
return
|
|
131
|
+
}
|
|
132
|
+
let paymentController = PKPaymentAuthorizationController(paymentRequest: paymentRequest)
|
|
133
|
+
paymentController.delegate = self
|
|
134
|
+
paymentController.present(completion: { presented in
|
|
135
|
+
if presented {
|
|
136
|
+
self.paymentStatus = nil
|
|
137
|
+
} else {
|
|
138
|
+
self.callback?([["status": "Failed", "message": "ApplePay: unable to present"]])
|
|
139
|
+
self.callback = nil
|
|
140
|
+
}
|
|
141
|
+
})
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/// Extension to conform to PKPaymentAuthorizationControllerDelegate
|
|
146
|
+
extension ApplePayHandlerLite: PKPaymentAuthorizationControllerDelegate {
|
|
147
|
+
|
|
148
|
+
/// Handle successful payment authorization
|
|
149
|
+
internal func paymentAuthorizationController(
|
|
150
|
+
_ controller: PKPaymentAuthorizationController,
|
|
151
|
+
didAuthorizePayment payment: PKPayment,
|
|
152
|
+
handler completion: @escaping (PKPaymentAuthorizationResult) -> Void
|
|
153
|
+
) {
|
|
154
|
+
|
|
155
|
+
let errors = [Error]()
|
|
156
|
+
let status = PKPaymentAuthorizationStatus.success
|
|
157
|
+
self.paymentStatus = status
|
|
158
|
+
|
|
159
|
+
let dataString = payment.token.paymentData.base64EncodedString()
|
|
160
|
+
|
|
161
|
+
var paymentType = "debit"
|
|
162
|
+
switch payment.token.paymentMethod.type {
|
|
163
|
+
case .debit: paymentType = "debit"
|
|
164
|
+
case .credit: paymentType = "credit"
|
|
165
|
+
case .store: paymentType = "store"
|
|
166
|
+
case .prepaid: paymentType = "prepaid"
|
|
167
|
+
case .eMoney: paymentType = "eMoney"
|
|
168
|
+
default: paymentType = "unknown"
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
self.callback?(
|
|
172
|
+
[
|
|
173
|
+
[
|
|
174
|
+
"status": "Success",
|
|
175
|
+
"payment_data": dataString,
|
|
176
|
+
"payment_method": [
|
|
177
|
+
"type": paymentType,
|
|
178
|
+
"network": payment.token.paymentMethod.network ?? "",
|
|
179
|
+
"display_name": payment.token.paymentMethod.displayName ?? "",
|
|
180
|
+
],
|
|
181
|
+
"transaction_identifier": payment.token.transactionIdentifier,
|
|
182
|
+
"billing_contact": convertPKContactToDictionary(payment.billingContact),
|
|
183
|
+
"shipping_contact": convertPKContactToDictionary(payment.shippingContact),
|
|
184
|
+
]
|
|
185
|
+
]
|
|
186
|
+
)
|
|
187
|
+
completion(PKPaymentAuthorizationResult(status: paymentStatus ?? .failure, errors: errors))
|
|
188
|
+
}
|
|
189
|
+
/// Handle completion of the payment authorization flow
|
|
190
|
+
internal func paymentAuthorizationControllerDidFinish(_ controller: PKPaymentAuthorizationController) {
|
|
191
|
+
controller.dismiss {
|
|
192
|
+
DispatchQueue.main.async {
|
|
193
|
+
if self.paymentStatus == .failure {
|
|
194
|
+
self.callback?([["status": "Failed", "message": "ApplePay: payment failed"]])
|
|
195
|
+
} else if self.paymentStatus == nil {
|
|
196
|
+
self.callback?([["status": "Cancelled"]])
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
private func mapToPKContactField(_ string: String) -> PKContactField? {
|
|
203
|
+
switch string {
|
|
204
|
+
case "postalAddress": return .postalAddress
|
|
205
|
+
case "email": return .emailAddress
|
|
206
|
+
case "phone": return .phoneNumber
|
|
207
|
+
case "name": return .name
|
|
208
|
+
case "phoneticName": return .phoneticName
|
|
209
|
+
default: return nil
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
private func convertPKContactToDictionary(_ contact: PKContact?) -> [String: Any] {
|
|
214
|
+
var contactDict = [String: Any]()
|
|
215
|
+
|
|
216
|
+
if let name = contact?.name {
|
|
217
|
+
var nameDict = [String: Any]()
|
|
218
|
+
nameDict["givenName"] = name.givenName
|
|
219
|
+
nameDict["familyName"] = name.familyName
|
|
220
|
+
nameDict["namePrefix"] = name.namePrefix
|
|
221
|
+
nameDict["nameSuffix"] = name.nameSuffix
|
|
222
|
+
nameDict["nickname"] = name.nickname
|
|
223
|
+
nameDict["middleName"] = name.middleName
|
|
224
|
+
// nameDict["phoneticRepresentation"] = name.phoneticRepresentation
|
|
225
|
+
contactDict["name"] = nameDict
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
if let postalAddress = contact?.postalAddress {
|
|
229
|
+
var addressDict = [String: Any]()
|
|
230
|
+
addressDict["street"] = postalAddress.street
|
|
231
|
+
addressDict["city"] = postalAddress.city
|
|
232
|
+
addressDict["state"] = postalAddress.state
|
|
233
|
+
addressDict["postalCode"] = postalAddress.postalCode
|
|
234
|
+
addressDict["country"] = postalAddress.country
|
|
235
|
+
addressDict["subLocality"] = postalAddress.subLocality
|
|
236
|
+
addressDict["subAdministrativeArea"] = postalAddress.subAdministrativeArea
|
|
237
|
+
addressDict["isoCountryCode"] = postalAddress.isoCountryCode
|
|
238
|
+
contactDict["postalAddress"] = addressDict
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
if let phoneNumber = contact?.phoneNumber {
|
|
242
|
+
contactDict["phoneNumber"] = phoneNumber.stringValue
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
if let emailAddress = contact?.emailAddress {
|
|
246
|
+
contactDict["emailAddress"] = emailAddress
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
return contactDict
|
|
250
|
+
}
|
|
251
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
//
|
|
2
|
+
// PaymentSession+Lite.swift
|
|
3
|
+
// hyperswitch
|
|
4
|
+
//
|
|
5
|
+
// Created by Harshit Srivastava on 30/08/24.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
import Foundation
|
|
9
|
+
import UIKit
|
|
10
|
+
|
|
11
|
+
extension PaymentSession {
|
|
12
|
+
|
|
13
|
+
public func presentPaymentSheetLite(
|
|
14
|
+
viewController: UIViewController,
|
|
15
|
+
configuration: PaymentSheet.Configuration,
|
|
16
|
+
completion: @escaping (PaymentResult) -> Void
|
|
17
|
+
) {
|
|
18
|
+
let paymentSheet = PaymentSheet(
|
|
19
|
+
paymentSessionConfiguration: paymentSessionConfiguration,
|
|
20
|
+
hyperswitchConfiguration: hyperswitchConfiguration,
|
|
21
|
+
configuration: configuration
|
|
22
|
+
)
|
|
23
|
+
paymentSheet.presentLite(from: viewController, completion: completion)
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
//
|
|
2
|
+
// PaymentSheetView+Lite.swift
|
|
3
|
+
// hyperswitch
|
|
4
|
+
//
|
|
5
|
+
// Created by Harshit Srivastava on 30/08/24.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
import UIKit
|
|
9
|
+
import WebKit
|
|
10
|
+
|
|
11
|
+
extension PaymentSheet {
|
|
12
|
+
|
|
13
|
+
func presentLite(from presentingViewController: UIViewController, completion: @escaping (PaymentResult) -> Void) {
|
|
14
|
+
|
|
15
|
+
let hyperswitchConfiguration = try? hyperswitchConfiguration?.toDictionary()
|
|
16
|
+
let paymentSessionConfiguration = try? paymentSessionConfiguration.toDictionary()
|
|
17
|
+
|
|
18
|
+
let configuration = try? self.configuration?.toDictionary()
|
|
19
|
+
|
|
20
|
+
let sdkParams = SDKParams.getSDKParams()
|
|
21
|
+
|
|
22
|
+
/// 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
|
|
23
|
+
let props: [String: Any] = [
|
|
24
|
+
"type": "payment",
|
|
25
|
+
"hyperswitchConfig": hyperswitchConfiguration as Any,
|
|
26
|
+
"paymentSessionConfig": paymentSessionConfiguration as Any,
|
|
27
|
+
"sdkParams": sdkParams,
|
|
28
|
+
"configuration": configuration as Any,
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
let initialProps: [String: Any] = [
|
|
32
|
+
"initialProps": [
|
|
33
|
+
"props": props
|
|
34
|
+
]
|
|
35
|
+
]
|
|
36
|
+
|
|
37
|
+
let paymentSheetViewController = WebViewController(props: initialProps, completion: completion)
|
|
38
|
+
|
|
39
|
+
paymentSheetViewController.view.backgroundColor = UIColor.clear
|
|
40
|
+
/// Set the modal presentation style to cover the entire screen.
|
|
41
|
+
paymentSheetViewController.modalPresentationStyle = .overFullScreen
|
|
42
|
+
/// Present the payment sheet view controller modally from the presenting view controller.
|
|
43
|
+
presentingViewController.present(paymentSheetViewController, animated: false)
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
//
|
|
2
|
+
// SwiftUI+Lite.swift
|
|
3
|
+
// hyperswitch
|
|
4
|
+
//
|
|
5
|
+
// Created by Harshit Srivastava on 25/10/24.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
import Foundation
|
|
9
|
+
import SwiftUI
|
|
10
|
+
|
|
11
|
+
/// Extension on the PaymentSheet class to provide a SwiftUI integration for presenting the payment sheet.
|
|
12
|
+
extension PaymentSheet {
|
|
13
|
+
|
|
14
|
+
/// A SwiftUI View struct that represents a button for presenting the payment sheet.
|
|
15
|
+
@available(iOS 13.0, *)
|
|
16
|
+
public struct PaymentButtonLite<Content: View>: View {
|
|
17
|
+
private let paymentSession: PaymentSession
|
|
18
|
+
private let configuration: Configuration
|
|
19
|
+
private let content: Content
|
|
20
|
+
private let completion: (PaymentResult) -> Void
|
|
21
|
+
|
|
22
|
+
@Environment(\.viewController) private var viewControllerHolder: UIViewController?
|
|
23
|
+
|
|
24
|
+
/// Initializer for the PaymentButton.
|
|
25
|
+
public init(
|
|
26
|
+
paymentSession: PaymentSession,
|
|
27
|
+
configuration: Configuration,
|
|
28
|
+
onCompletion: @escaping (PaymentResult) -> Void,
|
|
29
|
+
@ViewBuilder content: () -> Content
|
|
30
|
+
) {
|
|
31
|
+
self.paymentSession = paymentSession
|
|
32
|
+
self.configuration = configuration
|
|
33
|
+
self.completion = onCompletion
|
|
34
|
+
self.content = content()
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/// The body of the PaymentButton view.
|
|
38
|
+
public var body: some View {
|
|
39
|
+
Button(action: {
|
|
40
|
+
if let vc = viewControllerHolder {
|
|
41
|
+
paymentSession.presentPaymentSheetLite(viewController: vc, configuration: configuration, completion: completion)
|
|
42
|
+
}
|
|
43
|
+
}) {
|
|
44
|
+
content
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
//
|
|
2
|
+
// WebViewController.swift
|
|
3
|
+
// hyperswitch
|
|
4
|
+
//
|
|
5
|
+
// Created by Harshit Srivastava on 30/08/24.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
import UIKit
|
|
9
|
+
@preconcurrency import WebKit
|
|
10
|
+
|
|
11
|
+
#if canImport(HyperswitchScanCard)
|
|
12
|
+
import HyperswitchScanCard
|
|
13
|
+
#endif
|
|
14
|
+
|
|
15
|
+
internal class WebViewController: HyperUIViewController {
|
|
16
|
+
|
|
17
|
+
private let applePayPaymentHandler = ApplePayHandlerLite()
|
|
18
|
+
|
|
19
|
+
private let baseUrl = URL(string: "https://beta.hyperswitch.io/mobile/1.7.4/index.html")
|
|
20
|
+
private var webView: WKWebView = WKWebView()
|
|
21
|
+
private var popupWebView: WKWebView?
|
|
22
|
+
private var props: [String: Any]?
|
|
23
|
+
private var completion: ((PaymentResult) -> Void)?
|
|
24
|
+
|
|
25
|
+
typealias scanCallback = ([[String: Any]]) -> Void
|
|
26
|
+
|
|
27
|
+
override func viewDidLoad() {
|
|
28
|
+
super.viewDidLoad()
|
|
29
|
+
configureWebView()
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
init(props: [String: Any], completion: ((PaymentResult) -> Void)?) {
|
|
33
|
+
self.props = props
|
|
34
|
+
self.completion = completion
|
|
35
|
+
super.init(nibName: nil, bundle: nil)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
required init?(coder: NSCoder) {
|
|
39
|
+
super.init(coder: coder)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
private func configureWebView() {
|
|
43
|
+
|
|
44
|
+
let contentController = WKUserContentController()
|
|
45
|
+
contentController.add(self, name: "sdkInitialised")
|
|
46
|
+
contentController.add(self, name: "exitPaymentSheet")
|
|
47
|
+
contentController.add(self, name: "launchScanCard")
|
|
48
|
+
contentController.add(self, name: "launchApplePay")
|
|
49
|
+
|
|
50
|
+
let configuration = WKWebViewConfiguration()
|
|
51
|
+
configuration.userContentController = contentController
|
|
52
|
+
if #available(iOS 14.0, *) {
|
|
53
|
+
configuration.defaultWebpagePreferences.allowsContentJavaScript = true
|
|
54
|
+
} else {
|
|
55
|
+
configuration.preferences.javaScriptEnabled = true
|
|
56
|
+
}
|
|
57
|
+
configuration.preferences.javaScriptCanOpenWindowsAutomatically = true
|
|
58
|
+
|
|
59
|
+
webView = WKWebView(frame: self.view.bounds, configuration: configuration)
|
|
60
|
+
|
|
61
|
+
webView.uiDelegate = self
|
|
62
|
+
webView.navigationDelegate = self
|
|
63
|
+
|
|
64
|
+
webView.translatesAutoresizingMaskIntoConstraints = false
|
|
65
|
+
webView.backgroundColor = .clear
|
|
66
|
+
webView.isOpaque = false
|
|
67
|
+
webView.scrollView.isScrollEnabled = false
|
|
68
|
+
webView.scrollView.bounces = false
|
|
69
|
+
webView.scrollView.contentInsetAdjustmentBehavior = .never
|
|
70
|
+
|
|
71
|
+
view.addSubview(webView)
|
|
72
|
+
|
|
73
|
+
guard let baseUrl = baseUrl else {
|
|
74
|
+
return
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
let request = URLRequest(url: baseUrl)
|
|
78
|
+
webView.load(request)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
private func sendPropsToJS(props: [String: Any]?) {
|
|
82
|
+
do {
|
|
83
|
+
let jsonData = try JSONSerialization.data(withJSONObject: props as Any)
|
|
84
|
+
if let jsonString = String(data: jsonData, encoding: .utf8) {
|
|
85
|
+
let escapedJsonString = jsonString.replacingOccurrences(of: "\\", with: "\\\\")
|
|
86
|
+
.replacingOccurrences(of: "\"", with: "\\\"")
|
|
87
|
+
.replacingOccurrences(of: "\n", with: "\\n")
|
|
88
|
+
|
|
89
|
+
let jsCode = "window.postMessage(\"\(escapedJsonString)\", '*');"
|
|
90
|
+
webView.evaluateJavaScript(jsCode) { (result, error) in
|
|
91
|
+
if let error = error {
|
|
92
|
+
print("Error sending message: \(error)")
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
} catch {
|
|
97
|
+
print("Error creating JSON: \(error)")
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
private func callback(_ result: PaymentResult) {
|
|
102
|
+
DispatchQueue.main.async { [weak self] in
|
|
103
|
+
self?.completion?(result)
|
|
104
|
+
self?.webView.stopLoading()
|
|
105
|
+
self?.dismiss(animated: false)
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
extension WebViewController: WKUIDelegate {
|
|
110
|
+
internal func webView(
|
|
111
|
+
_ webView: WKWebView,
|
|
112
|
+
runJavaScriptAlertPanelWithMessage message: String,
|
|
113
|
+
initiatedByFrame frame: WKFrameInfo,
|
|
114
|
+
completionHandler: @escaping () -> Void
|
|
115
|
+
) {
|
|
116
|
+
DispatchQueue.main.async {
|
|
117
|
+
let alert = UIAlertController(title: nil, message: message, preferredStyle: .alert)
|
|
118
|
+
let title = NSLocalizedString("OK", comment: "OK Button")
|
|
119
|
+
let ok = UIAlertAction(title: title, style: .default) { (action: UIAlertAction) -> Void in
|
|
120
|
+
alert.dismiss(animated: true, completion: nil)
|
|
121
|
+
completionHandler()
|
|
122
|
+
}
|
|
123
|
+
alert.addAction(ok)
|
|
124
|
+
self.present(alert, animated: true)
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
extension WebViewController: WKScriptMessageHandler {
|
|
130
|
+
internal func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
|
|
131
|
+
if message.name == "sdkInitialised" {
|
|
132
|
+
self.sendPropsToJS(props: self.props)
|
|
133
|
+
}
|
|
134
|
+
if message.name == "launchApplePay" {
|
|
135
|
+
guard let body = message.body as? String else {
|
|
136
|
+
return
|
|
137
|
+
}
|
|
138
|
+
applePayPaymentHandler.startPayment(
|
|
139
|
+
rnMessage: body,
|
|
140
|
+
rnCallback: { props in
|
|
141
|
+
let applePayProps = [
|
|
142
|
+
"applePayData": props[0]
|
|
143
|
+
]
|
|
144
|
+
self.sendPropsToJS(props: applePayProps)
|
|
145
|
+
}
|
|
146
|
+
)
|
|
147
|
+
}
|
|
148
|
+
if message.name == "launchScanCard" {
|
|
149
|
+
#if canImport(HyperswitchScanCard)
|
|
150
|
+
DispatchQueue.main.async {
|
|
151
|
+
var message: [String: Any] = [:]
|
|
152
|
+
var callback: [String: Any] = [:]
|
|
153
|
+
let cardScanSheet = CardScanSheet()
|
|
154
|
+
cardScanSheet.present(from: self) { result in
|
|
155
|
+
switch result {
|
|
156
|
+
case .completed(let card as ScannedCard?):
|
|
157
|
+
message["pan"] = card?.pan
|
|
158
|
+
message["expiryMonth"] = card?.expiryMonth
|
|
159
|
+
message["expiryYear"] = card?.expiryYear
|
|
160
|
+
callback["status"] = "Succeeded"
|
|
161
|
+
callback["data"] = message
|
|
162
|
+
case .canceled:
|
|
163
|
+
callback["status"] = "Cancelled"
|
|
164
|
+
case .failed(_):
|
|
165
|
+
callback["status"] = "Failed"
|
|
166
|
+
}
|
|
167
|
+
self.sendPropsToJS(props: ["scanCardData": callback])
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
#endif
|
|
171
|
+
}
|
|
172
|
+
if message.name == "exitPaymentSheet" {
|
|
173
|
+
do {
|
|
174
|
+
guard let body = message.body as? String,
|
|
175
|
+
let data = body.data(using: .utf8),
|
|
176
|
+
let jsonDictionary = try JSONSerialization.jsonObject(with: data) as? [String: String]
|
|
177
|
+
else {
|
|
178
|
+
throw NSError(domain: "UNKNOWN_ERROR", code: 0, userInfo: ["message": "An error has occurred."])
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
let result: PaymentResult
|
|
182
|
+
|
|
183
|
+
if let status = jsonDictionary["status"] {
|
|
184
|
+
switch status {
|
|
185
|
+
case "failed", "requires_payment_method":
|
|
186
|
+
let errorDomain = jsonDictionary["code"] ?? "UNKNOWN_ERROR"
|
|
187
|
+
let errorMessage = jsonDictionary["message"] ?? "An error has occurred."
|
|
188
|
+
let error = NSError(domain: errorDomain, code: 0, userInfo: ["message": errorMessage])
|
|
189
|
+
result = .failed(error: error)
|
|
190
|
+
case "cancelled":
|
|
191
|
+
result = .canceled(data: jsonDictionary["message"] ?? "Payment was canceled")
|
|
192
|
+
default:
|
|
193
|
+
result = .completed(data: status)
|
|
194
|
+
}
|
|
195
|
+
} else {
|
|
196
|
+
throw NSError(domain: "UNKNOWN_ERROR", code: 0, userInfo: ["message": "An error has occurred."])
|
|
197
|
+
}
|
|
198
|
+
callback(result)
|
|
199
|
+
} catch {
|
|
200
|
+
callback(.failed(error: NSError(domain: "UNKNOWN_ERROR", code: 0, userInfo: ["message": "An error has occurred."])))
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
if message.name == "closePopupWebView" {
|
|
205
|
+
popupWebView?.removeFromSuperview()
|
|
206
|
+
self.popupWebView = nil
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
extension WebViewController: WKNavigationDelegate {
|
|
212
|
+
func webView(
|
|
213
|
+
_ webView: WKWebView,
|
|
214
|
+
createWebViewWith configuration: WKWebViewConfiguration,
|
|
215
|
+
for navigationAction: WKNavigationAction,
|
|
216
|
+
windowFeatures: WKWindowFeatures
|
|
217
|
+
) -> WKWebView? {
|
|
218
|
+
if navigationAction.targetFrame == nil {
|
|
219
|
+
|
|
220
|
+
configuration.userContentController.removeScriptMessageHandler(forName: "closePopupWebView")
|
|
221
|
+
configuration.userContentController.add(self, name: "closePopupWebView")
|
|
222
|
+
|
|
223
|
+
let webView = WKWebView(frame: self.view.bounds, configuration: configuration)
|
|
224
|
+
webView.uiDelegate = self
|
|
225
|
+
webView.navigationDelegate = self
|
|
226
|
+
|
|
227
|
+
webView.translatesAutoresizingMaskIntoConstraints = false
|
|
228
|
+
webView.backgroundColor = .clear
|
|
229
|
+
webView.isOpaque = true
|
|
230
|
+
webView.scrollView.isScrollEnabled = false
|
|
231
|
+
webView.scrollView.bounces = false
|
|
232
|
+
webView.scrollView.contentInsetAdjustmentBehavior = .never
|
|
233
|
+
|
|
234
|
+
webView.translatesAutoresizingMaskIntoConstraints = false
|
|
235
|
+
self.view.addSubview(webView)
|
|
236
|
+
|
|
237
|
+
NSLayoutConstraint.activate([
|
|
238
|
+
webView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor),
|
|
239
|
+
webView.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor),
|
|
240
|
+
webView.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor),
|
|
241
|
+
webView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor),
|
|
242
|
+
])
|
|
243
|
+
|
|
244
|
+
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
|
|
245
|
+
let js = """
|
|
246
|
+
var closeButtonContainer = document.createElement('div');
|
|
247
|
+
closeButtonContainer.style.position = 'fixed';
|
|
248
|
+
closeButtonContainer.style.top = '16px';
|
|
249
|
+
closeButtonContainer.style.right = '20px';
|
|
250
|
+
closeButtonContainer.style.zIndex = '1000';
|
|
251
|
+
closeButtonContainer.style.cursor = 'pointer';
|
|
252
|
+
|
|
253
|
+
closeButtonContainer.innerHTML = `
|
|
254
|
+
<svg height="24" width="24" fill="rgba(53, 64, 82, 0.25)" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16">
|
|
255
|
+
<path d="M13.7429 2.27713C13.3877 1.92197 12.8117 1.92197 12.4618 2.27713L8.01009 6.71659L3.55299 2.26637C3.19771 1.91121 2.62173 1.91121 2.27184 2.26637C1.91656 2.62152 1.91656 3.19731 2.27184 3.54709L6.72356 7.99731L2.26646 12.4529C1.91118 12.8081 1.91118 13.3839 2.26646 13.7336C2.62173 14.0888 3.19771 14.0888 3.5476 13.7336L7.99932 9.28341L12.451 13.7336C12.8063 14.0888 13.3823 14.0888 13.7322 13.7336C14.0875 13.3785 14.0875 12.8027 13.7322 12.4529L9.28047 8.00269L13.7322 3.55247C14.0875 3.20807 14.0875 2.62152 13.7429 2.27713Z" fill="#8D8D8D"></path>
|
|
256
|
+
</svg>
|
|
257
|
+
`;
|
|
258
|
+
|
|
259
|
+
closeButtonContainer.onclick = function() {
|
|
260
|
+
window.webkit.messageHandlers.closePopupWebView.postMessage(`{\"type\":\"\",\"code\":\"\",\"message\":\"\",\"status\":\"cancelled\"}`);
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
document.body.appendChild(closeButtonContainer);
|
|
264
|
+
"""
|
|
265
|
+
|
|
266
|
+
webView.evaluateJavaScript(js, completionHandler: nil)
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
popupWebView = webView
|
|
270
|
+
return webView
|
|
271
|
+
}
|
|
272
|
+
return nil
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
func webViewDidClose(_ webView: WKWebView) {
|
|
276
|
+
webView.removeFromSuperview()
|
|
277
|
+
}
|
|
278
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
//
|
|
2
|
+
// APIClient.swift
|
|
3
|
+
// Hyperswitch
|
|
4
|
+
//
|
|
5
|
+
// Created by Harshit Srivastava on 10/05/23.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
import Foundation
|
|
9
|
+
|
|
10
|
+
@objc internal class APIClient: NSObject {
|
|
11
|
+
|
|
12
|
+
@objc(sharedClient) public static let shared: APIClient = {
|
|
13
|
+
let client = APIClient()
|
|
14
|
+
return client
|
|
15
|
+
}()
|
|
16
|
+
|
|
17
|
+
@objc public var publishableKey: String?
|
|
18
|
+
@objc public var profileId: String?
|
|
19
|
+
@objc public var customBackendUrl: String?
|
|
20
|
+
@objc public var customParams: [String: Any]?
|
|
21
|
+
@objc public var customLogUrl: String?
|
|
22
|
+
}
|