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,81 @@
|
|
|
1
|
+
import { createContext, useContext, useEffect, useState, type ReactNode } from 'react';
|
|
2
|
+
import { PaymentSession } from '../types/definitions';
|
|
3
|
+
import { Elements, HyperswitchSession } from '../types/elements';
|
|
4
|
+
|
|
5
|
+
interface HyperElementsContext {
|
|
6
|
+
paymentSession: PaymentSession | null;
|
|
7
|
+
elements: Elements | null;
|
|
8
|
+
publishableKey: string | null;
|
|
9
|
+
sdkAuthorization: string | null;
|
|
10
|
+
loading: boolean;
|
|
11
|
+
error: Error | null;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const HyperElementsContext = createContext<HyperElementsContext | undefined>(undefined);
|
|
15
|
+
|
|
16
|
+
HyperElementsContext.displayName = 'HyperElementsContext';
|
|
17
|
+
|
|
18
|
+
export interface HyperElementsProps {
|
|
19
|
+
hyper: HyperswitchSession | Promise<HyperswitchSession> | null;
|
|
20
|
+
options: { sdkAuthorization: string };
|
|
21
|
+
children: ReactNode;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function HyperElements({ hyper, options, children }: HyperElementsProps) {
|
|
25
|
+
const [paymentSession, setPaymentSession] = useState<PaymentSession | null>(null);
|
|
26
|
+
const [elements, setElements] = useState<Elements | null>(null);
|
|
27
|
+
const [publishableKey, setPublishableKey] = useState<string | null>(null);
|
|
28
|
+
const [sdkAuthorization, setSdkAuthorization] = useState<string | null>(null);
|
|
29
|
+
const [loading, setLoading] = useState(true);
|
|
30
|
+
const [error, setError] = useState<Error | null>(null);
|
|
31
|
+
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
if (!hyper) return;
|
|
34
|
+
|
|
35
|
+
let cancelled = false;
|
|
36
|
+
|
|
37
|
+
(async () => {
|
|
38
|
+
try {
|
|
39
|
+
const session = await Promise.resolve(hyper);
|
|
40
|
+
const els = await session.elements({
|
|
41
|
+
sdkAuthorization: options.sdkAuthorization,
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
if (!cancelled) {
|
|
45
|
+
setPaymentSession({
|
|
46
|
+
...els,
|
|
47
|
+
} as PaymentSession);
|
|
48
|
+
setElements(els);
|
|
49
|
+
setPublishableKey(session.publishableKey ?? null);
|
|
50
|
+
setSdkAuthorization(options.sdkAuthorization ?? null);
|
|
51
|
+
setLoading(false);
|
|
52
|
+
}
|
|
53
|
+
} catch (err) {
|
|
54
|
+
if (!cancelled) {
|
|
55
|
+
setError(err instanceof Error ? err : new Error(String(err)));
|
|
56
|
+
setLoading(false);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
})();
|
|
60
|
+
|
|
61
|
+
return () => {
|
|
62
|
+
cancelled = true;
|
|
63
|
+
};
|
|
64
|
+
}, [hyper, options.sdkAuthorization]);
|
|
65
|
+
|
|
66
|
+
return (
|
|
67
|
+
<HyperElementsContext.Provider
|
|
68
|
+
value={{ paymentSession, elements, publishableKey, sdkAuthorization, loading, error }}
|
|
69
|
+
>
|
|
70
|
+
{children}
|
|
71
|
+
</HyperElementsContext.Provider>
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function useHyperElementsContext(): HyperElementsContext {
|
|
76
|
+
const ctx = useContext(HyperElementsContext);
|
|
77
|
+
if (ctx === undefined) {
|
|
78
|
+
throw new Error('useHyperElementsContext must be used inside <HyperElements>');
|
|
79
|
+
}
|
|
80
|
+
return ctx;
|
|
81
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import NativeHyperswitchModule from '../specs/NativeHyperswitchModule';
|
|
2
|
+
import type {
|
|
3
|
+
HyperswitchConfiguration,
|
|
4
|
+
NativePaymentSheetPayload,
|
|
5
|
+
PaymentSession,
|
|
6
|
+
PaymentSessionConfiguration,
|
|
7
|
+
} from '../types/definitions';
|
|
8
|
+
import { buildPresentPaymentSheetPayload } from '../utils/LaunchOptions';
|
|
9
|
+
import { getCustomerSavedPaymentMethods } from './SavedPaymentMethods';
|
|
10
|
+
import type { PaymentResult } from '../types/paymentresult';
|
|
11
|
+
import type { CustomerSavedPaymentMethodsSession } from '../types/savedPaymentMethods';
|
|
12
|
+
import { isInitializing, isSheetPresented, setSheetPresented } from '../utils/InitializationState';
|
|
13
|
+
|
|
14
|
+
interface NativeResponse {
|
|
15
|
+
status: string;
|
|
16
|
+
message: string;
|
|
17
|
+
data?: any;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function parseNativeResponse(
|
|
21
|
+
raw: string | NativeResponse
|
|
22
|
+
): NativeResponse {
|
|
23
|
+
if (typeof raw === 'object' && raw !== null) {
|
|
24
|
+
return raw as NativeResponse;
|
|
25
|
+
}
|
|
26
|
+
try {
|
|
27
|
+
return JSON.parse(raw as string) as NativeResponse;
|
|
28
|
+
} catch {
|
|
29
|
+
return { status: 'failed', message: String(raw) };
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function mapStatus(status: string): PaymentResult['type'] {
|
|
34
|
+
switch (status) {
|
|
35
|
+
case 'succeeded':
|
|
36
|
+
case 'completed':
|
|
37
|
+
case 'success':
|
|
38
|
+
return 'completed';
|
|
39
|
+
case 'cancelled':
|
|
40
|
+
case 'canceled':
|
|
41
|
+
return 'canceled';
|
|
42
|
+
case 'failed':
|
|
43
|
+
case 'error':
|
|
44
|
+
default:
|
|
45
|
+
return 'failed';
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function mapNativeResponseToPaymentResult(
|
|
50
|
+
raw: string | NativeResponse
|
|
51
|
+
): PaymentResult {
|
|
52
|
+
const parsed = parseNativeResponse(raw);
|
|
53
|
+
return {
|
|
54
|
+
type: mapStatus(parsed.status),
|
|
55
|
+
message: parsed.message,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export async function presentPaymentSheetWithPayload(
|
|
60
|
+
payload: NativePaymentSheetPayload
|
|
61
|
+
): Promise<PaymentResult> {
|
|
62
|
+
if (isInitializing()) {
|
|
63
|
+
return {
|
|
64
|
+
type: 'failed',
|
|
65
|
+
message: 'SDK is reloading. Please wait for initialisation to complete before presenting the payment sheet.',
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
if (isSheetPresented()) {
|
|
69
|
+
// A sheet is already open (e.g. a hot-reload fired while the sheet was visible).
|
|
70
|
+
// Silently skip so the existing sheet is not covered by a new one.
|
|
71
|
+
return {
|
|
72
|
+
type: 'canceled',
|
|
73
|
+
message: 'A payment sheet is already presented.',
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
setSheetPresented(true);
|
|
77
|
+
try {
|
|
78
|
+
const raw = await NativeHyperswitchModule.presentPaymentSheet({
|
|
79
|
+
hyperswitchConfig: payload.hyperswitchConfig,
|
|
80
|
+
paymentSessionConfig: payload.paymentSessionConfig,
|
|
81
|
+
configuration: payload.configuration,
|
|
82
|
+
});
|
|
83
|
+
return mapNativeResponseToPaymentResult(raw);
|
|
84
|
+
} finally {
|
|
85
|
+
setSheetPresented(false);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export async function updateIntent(
|
|
90
|
+
_intentResolver: () => Promise<PaymentSessionConfiguration>
|
|
91
|
+
): Promise<void> {
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function createPaymentSession(
|
|
95
|
+
hyperswitchConfig: HyperswitchConfiguration,
|
|
96
|
+
paymentSessionConfig: PaymentSessionConfiguration
|
|
97
|
+
): PaymentSession {
|
|
98
|
+
return {
|
|
99
|
+
async presentPaymentSheet(
|
|
100
|
+
configuration?: Record<string, unknown>
|
|
101
|
+
): Promise<PaymentResult> {
|
|
102
|
+
const payload = buildPresentPaymentSheetPayload(
|
|
103
|
+
hyperswitchConfig,
|
|
104
|
+
paymentSessionConfig,
|
|
105
|
+
configuration
|
|
106
|
+
);
|
|
107
|
+
return presentPaymentSheetWithPayload(payload);
|
|
108
|
+
},
|
|
109
|
+
|
|
110
|
+
async getCustomerSavedPaymentMethods(
|
|
111
|
+
configuration?: Record<string, unknown>
|
|
112
|
+
): Promise<CustomerSavedPaymentMethodsSession> {
|
|
113
|
+
return getCustomerSavedPaymentMethods(
|
|
114
|
+
hyperswitchConfig,
|
|
115
|
+
paymentSessionConfig,
|
|
116
|
+
configuration
|
|
117
|
+
);
|
|
118
|
+
},
|
|
119
|
+
updateIntent,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import NativeHyperswitchModule from '../specs/NativeHyperswitchModule';
|
|
2
|
+
import {
|
|
3
|
+
HyperswitchConfiguration,
|
|
4
|
+
PaymentSessionConfiguration,
|
|
5
|
+
} from '../types/definitions';
|
|
6
|
+
import {
|
|
7
|
+
CustomerSavedPaymentMethodsSession,
|
|
8
|
+
CustomerLastUsedPaymentMethod,
|
|
9
|
+
} from '../types/savedPaymentMethods';
|
|
10
|
+
import { buildPresentPaymentSheetPayload } from '../utils/LaunchOptions';
|
|
11
|
+
|
|
12
|
+
function parsePaymentMethod(raw: string): CustomerLastUsedPaymentMethod {
|
|
13
|
+
const parsed = JSON.parse(raw) as CustomerLastUsedPaymentMethod & {
|
|
14
|
+
billing?: string | object | null;
|
|
15
|
+
};
|
|
16
|
+
if (parsed.billing && typeof parsed.billing === 'string') {
|
|
17
|
+
try {
|
|
18
|
+
parsed.billing = JSON.parse(parsed.billing);
|
|
19
|
+
} catch {
|
|
20
|
+
parsed.billing = null;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return parsed as CustomerLastUsedPaymentMethod;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function createCustomerSavedPaymentMethodsSession(): CustomerSavedPaymentMethodsSession {
|
|
27
|
+
return {
|
|
28
|
+
async getCustomerLastUsedPaymentMethodData(): Promise<CustomerLastUsedPaymentMethod | null> {
|
|
29
|
+
const raw =
|
|
30
|
+
await NativeHyperswitchModule.getCustomerLastUsedPaymentMethodData();
|
|
31
|
+
return parsePaymentMethod(raw);
|
|
32
|
+
},
|
|
33
|
+
|
|
34
|
+
async getCustomerDefaultSavedPaymentMethodData(): Promise<CustomerLastUsedPaymentMethod | null> {
|
|
35
|
+
const raw =
|
|
36
|
+
await NativeHyperswitchModule.getCustomerDefaultSavedPaymentMethodData();
|
|
37
|
+
return parsePaymentMethod(raw);
|
|
38
|
+
},
|
|
39
|
+
|
|
40
|
+
async getCustomerSavedPaymentMethodData(): Promise<CustomerLastUsedPaymentMethod | null> {
|
|
41
|
+
const raw =
|
|
42
|
+
await NativeHyperswitchModule.getCustomerSavedPaymentMethodData();
|
|
43
|
+
return parsePaymentMethod(raw);
|
|
44
|
+
},
|
|
45
|
+
|
|
46
|
+
async confirmWithCustomerLastUsedPaymentMethod(args?: {
|
|
47
|
+
id?: string;
|
|
48
|
+
}): Promise<any> {
|
|
49
|
+
const raw = await NativeHyperswitchModule
|
|
50
|
+
.confirmWithCustomerLastUsedPaymentMethod
|
|
51
|
+
// args?.id
|
|
52
|
+
();
|
|
53
|
+
// return mapNativeResponseToPaymentResult(raw);
|
|
54
|
+
},
|
|
55
|
+
|
|
56
|
+
async confirmWithCustomerDefaultPaymentMethod(args?: {
|
|
57
|
+
id?: string;
|
|
58
|
+
}): Promise<any> {
|
|
59
|
+
const raw = await NativeHyperswitchModule
|
|
60
|
+
.confirmWithCustomerDefaultPaymentMethod
|
|
61
|
+
// args?.id
|
|
62
|
+
();
|
|
63
|
+
// return mapNativeResponseToPaymentResult(raw);
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export async function getCustomerSavedPaymentMethods(
|
|
69
|
+
hyperswitchConfig: HyperswitchConfiguration,
|
|
70
|
+
paymentSessionConfig: PaymentSessionConfiguration,
|
|
71
|
+
configuration?: Record<string, unknown>
|
|
72
|
+
): Promise<CustomerSavedPaymentMethodsSession> {
|
|
73
|
+
const payload = buildPresentPaymentSheetPayload(
|
|
74
|
+
hyperswitchConfig,
|
|
75
|
+
paymentSessionConfig,
|
|
76
|
+
configuration
|
|
77
|
+
);
|
|
78
|
+
await NativeHyperswitchModule.getCustomerSavedPaymentMethods(payload);
|
|
79
|
+
return createCustomerSavedPaymentMethodsSession();
|
|
80
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import {
|
|
2
|
+
confirmPayment as nativeConfirmPayment,
|
|
3
|
+
updateIntentInitForWidget,
|
|
4
|
+
updateIntentCompleteForWidget,
|
|
5
|
+
} from '../modules/NativeHyperswitchSdk';
|
|
6
|
+
import type { paymentResult } from '../modules/NativeHyperswitchSdk';
|
|
7
|
+
|
|
8
|
+
const widgetHashMap: Record<string, number | undefined> = {};
|
|
9
|
+
|
|
10
|
+
export function registerWidget(widgetId: string, nativeViewId: number): void {
|
|
11
|
+
widgetHashMap[widgetId] = nativeViewId;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function getWidget(widgetId: string): number | undefined {
|
|
15
|
+
return widgetHashMap[widgetId];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function unregisterWidget(widgetId: string): void {
|
|
19
|
+
delete widgetHashMap[widgetId];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function confirmPayment(widgetId: string): Promise<paymentResult> {
|
|
23
|
+
const nativeId = widgetHashMap[widgetId];
|
|
24
|
+
if (nativeId !== undefined) {
|
|
25
|
+
return new Promise((resolve) => {
|
|
26
|
+
nativeConfirmPayment(nativeId, (result: paymentResult) => {
|
|
27
|
+
resolve({
|
|
28
|
+
status: result.status,
|
|
29
|
+
message: result.message,
|
|
30
|
+
type: result.type,
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
return Promise.resolve({
|
|
36
|
+
status: 'failed',
|
|
37
|
+
message: `Widget ${widgetId} not found or not mounted`,
|
|
38
|
+
type: undefined,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function updateIntentInitForAllWidgets(): Promise<paymentResult[]> {
|
|
43
|
+
const promises = Object.values(widgetHashMap)
|
|
44
|
+
.filter((nativeId): nativeId is number => nativeId !== undefined)
|
|
45
|
+
.map((nativeId) => {
|
|
46
|
+
return new Promise<paymentResult>((resolve) => {
|
|
47
|
+
updateIntentInitForWidget(nativeId, (result: paymentResult) => {
|
|
48
|
+
resolve(result);
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
return Promise.all(promises);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function updateIntentCompleteForAllWidgets(
|
|
57
|
+
sdkAuthorization: string
|
|
58
|
+
): Promise<paymentResult[]> {
|
|
59
|
+
const promises = Object.values(widgetHashMap)
|
|
60
|
+
.filter((nativeId): nativeId is number => nativeId !== undefined)
|
|
61
|
+
.map((nativeId) => {
|
|
62
|
+
return new Promise<paymentResult>((resolve) => {
|
|
63
|
+
updateIntentCompleteForWidget(
|
|
64
|
+
nativeId,
|
|
65
|
+
sdkAuthorization,
|
|
66
|
+
(result: paymentResult) => {
|
|
67
|
+
resolve(result);
|
|
68
|
+
}
|
|
69
|
+
);
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
return Promise.all(promises);
|
|
74
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { useCallback, useMemo } from 'react';
|
|
2
|
+
import { useHyperElementsContext } from './HyperElements';
|
|
3
|
+
import { PaymentSession, PaymentSessionConfiguration, PaymentElementHandle } from '../types/definitions';
|
|
4
|
+
import { ElementsActions } from '../types/elements';
|
|
5
|
+
import { CustomerSavedPaymentMethodsSession } from '../types/savedPaymentMethods';
|
|
6
|
+
|
|
7
|
+
export function usePaymentSession(): PaymentSession | null {
|
|
8
|
+
const { paymentSession } = useHyperElementsContext();
|
|
9
|
+
|
|
10
|
+
const updateIntent = useCallback(
|
|
11
|
+
async (intentResolver: () => Promise<PaymentSessionConfiguration>): Promise<void> => {
|
|
12
|
+
if (!paymentSession) {
|
|
13
|
+
throw new Error('HyperElements is not initialized');
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return paymentSession.updateIntent(intentResolver);
|
|
17
|
+
},
|
|
18
|
+
[paymentSession],
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
return useMemo(
|
|
22
|
+
() => (paymentSession ? { ...paymentSession, updateIntent } : paymentSession),
|
|
23
|
+
[paymentSession, updateIntent],
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function useElements(): ElementsActions {
|
|
28
|
+
const { elements } = useHyperElementsContext();
|
|
29
|
+
|
|
30
|
+
const confirmPayment = useCallback(
|
|
31
|
+
async (
|
|
32
|
+
paymentElement: { current: PaymentElementHandle | null } | string,
|
|
33
|
+
options?: { confirmParams?: Record<string, Object> },
|
|
34
|
+
): Promise<PaymentResult> => {
|
|
35
|
+
if (!elements) {
|
|
36
|
+
throw new Error('HyperElements is not initialized');
|
|
37
|
+
}
|
|
38
|
+
if (elements.confirmPayment) {
|
|
39
|
+
return elements.confirmPayment(paymentElement, options);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (typeof paymentElement === 'string') {
|
|
43
|
+
throw new Error('confirmPayment by widget id is not supported by this Hyper elements handle');
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const ref = paymentElement.current;
|
|
47
|
+
if (!ref) {
|
|
48
|
+
throw new Error('PaymentElement reference is not mounted');
|
|
49
|
+
}
|
|
50
|
+
return ref.confirmPayment(options);
|
|
51
|
+
},
|
|
52
|
+
[elements],
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
const updateIntent = useCallback(
|
|
56
|
+
async (intentResolver: () => Promise<PaymentSessionConfiguration>): Promise<void> => {
|
|
57
|
+
if (!elements) {
|
|
58
|
+
throw new Error('HyperElements is not initialized');
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return elements.updateIntent(intentResolver);
|
|
62
|
+
},
|
|
63
|
+
[elements],
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
const getCustomerSavedPaymentMethods = useCallback(async (): Promise<CustomerSavedPaymentMethodsSession> => {
|
|
67
|
+
if (!elements) {
|
|
68
|
+
throw new Error('HyperElements is not initialized');
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return elements.getCustomerSavedPaymentMethods();
|
|
72
|
+
}, [elements]);
|
|
73
|
+
|
|
74
|
+
return {
|
|
75
|
+
getCustomerSavedPaymentMethods,
|
|
76
|
+
confirmPayment,
|
|
77
|
+
updateIntent,
|
|
78
|
+
};
|
|
79
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
HyperswitchConfiguration,
|
|
3
|
+
PaymentSession,
|
|
4
|
+
PaymentSessionConfiguration,
|
|
5
|
+
HyperswitchSession
|
|
6
|
+
} from './types/definitions';
|
|
7
|
+
|
|
8
|
+
export type * from './types/definitions';
|
|
9
|
+
export type * from './types/elements';
|
|
10
|
+
export type * from './types/NativeModuleTypes';
|
|
11
|
+
export type * from './types/PaymentSheetConfiguration'
|
|
12
|
+
|
|
13
|
+
import NativeHyperswitchModule from './specs/NativeHyperswitchModule';
|
|
14
|
+
import { createPaymentSession } from './context/PaymentSession';
|
|
15
|
+
import { Elements } from './types/elements';
|
|
16
|
+
import { createElements } from './context/Elements';
|
|
17
|
+
import { setInitializing } from './utils/InitializationState';
|
|
18
|
+
|
|
19
|
+
export function loadHyper(
|
|
20
|
+
config: HyperswitchConfiguration
|
|
21
|
+
): Promise<HyperswitchSession> {
|
|
22
|
+
setInitializing(true);
|
|
23
|
+
return NativeHyperswitchModule.initialise(
|
|
24
|
+
config.publishableKey,
|
|
25
|
+
config.platformPublishableKey ?? '',
|
|
26
|
+
config.profileId ?? '',
|
|
27
|
+
config.environment ?? 'PROD',
|
|
28
|
+
config.customEndpoints ?? {}
|
|
29
|
+
).then(() => {
|
|
30
|
+
setInitializing(false);
|
|
31
|
+
return {
|
|
32
|
+
publishableKey: config.publishableKey,
|
|
33
|
+
async initPaymentSession(
|
|
34
|
+
options: PaymentSessionConfiguration
|
|
35
|
+
): Promise<PaymentSession> {
|
|
36
|
+
return createPaymentSession(config, options);
|
|
37
|
+
},
|
|
38
|
+
async elements(options: PaymentSessionConfiguration): Promise<Elements> {
|
|
39
|
+
return createElements(config, options);
|
|
40
|
+
},
|
|
41
|
+
}
|
|
42
|
+
}).catch((error) => {
|
|
43
|
+
setInitializing(false);
|
|
44
|
+
console.error('Error initializing Hyperswitch SDK:', error);
|
|
45
|
+
throw error;
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
export const Hyperswitch = {
|
|
52
|
+
init: loadHyper,
|
|
53
|
+
};
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { NativeModules } from 'react-native';
|
|
2
|
+
import type { options as PaymentSheetConfigurationOptions } from '../types/PaymentSheetConfiguration';
|
|
3
|
+
|
|
4
|
+
export type initPaymentSessionParams = { sdkAuthorization?: string };
|
|
5
|
+
|
|
6
|
+
export type initPaymentSessionResult = { error?: string };
|
|
7
|
+
|
|
8
|
+
export type presentPaymentSheetParams = PaymentSheetConfigurationOptions;
|
|
9
|
+
|
|
10
|
+
export type presentPaymentSheet = (
|
|
11
|
+
params: presentPaymentSheetParams
|
|
12
|
+
) => Promise<string>;
|
|
13
|
+
|
|
14
|
+
export type paymentResult = {
|
|
15
|
+
status: string;
|
|
16
|
+
message: string;
|
|
17
|
+
error?: string;
|
|
18
|
+
type?: string;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export type error = { code?: string; message?: string };
|
|
22
|
+
|
|
23
|
+
export type presentPaymentSheetResult = {
|
|
24
|
+
error?: error;
|
|
25
|
+
paymentResult?: paymentResult;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export type cardDetails = {
|
|
29
|
+
expiry_year: string;
|
|
30
|
+
card_issuer: string;
|
|
31
|
+
expiry_month: string;
|
|
32
|
+
nick_name: string;
|
|
33
|
+
last4_digits: string;
|
|
34
|
+
card_holder_name: string;
|
|
35
|
+
card_network: string;
|
|
36
|
+
card_isin: string;
|
|
37
|
+
scheme: string;
|
|
38
|
+
issuer_country: string;
|
|
39
|
+
card_type: string;
|
|
40
|
+
saved_to_locker: boolean;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export type savedPaymentMethod = {
|
|
44
|
+
card?: cardDetails;
|
|
45
|
+
requires_cvv: boolean;
|
|
46
|
+
payment_method_str: string;
|
|
47
|
+
payment_method_type: string;
|
|
48
|
+
payment_experience: string[];
|
|
49
|
+
default_payment_method_set: boolean;
|
|
50
|
+
recurring_enabled: boolean;
|
|
51
|
+
payment_method_issuer: string;
|
|
52
|
+
last_used_at: string;
|
|
53
|
+
installment_payment_enabled: boolean;
|
|
54
|
+
payment_method_id: string;
|
|
55
|
+
customer_id: string;
|
|
56
|
+
payment_token: string;
|
|
57
|
+
created: string;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
type ConfirmPaymentCallback = (result: paymentResult) => void;
|
|
61
|
+
type ConfirmPaymentCVCCallback = (result: paymentResult) => void;
|
|
62
|
+
|
|
63
|
+
type NativePaymentWidget = {
|
|
64
|
+
confirmPayment: (viewId: number, callback: ConfirmPaymentCallback) => void;
|
|
65
|
+
updateIntentInitForWidget: (
|
|
66
|
+
viewId: number,
|
|
67
|
+
callback: ConfirmPaymentCallback
|
|
68
|
+
) => void;
|
|
69
|
+
updateIntentCompleteForWidget: (
|
|
70
|
+
viewId: number,
|
|
71
|
+
sdkAuthorization: string,
|
|
72
|
+
callback: ConfirmPaymentCallback
|
|
73
|
+
) => void;
|
|
74
|
+
confirmPaymentCVC: (
|
|
75
|
+
viewId: number,
|
|
76
|
+
paymentToken: string,
|
|
77
|
+
paymentMethodId: string,
|
|
78
|
+
callback: ConfirmPaymentCVCCallback
|
|
79
|
+
) => void;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const nativePaymentWidgetDict = NativeModules.NativePaymentWidget ?? {};
|
|
83
|
+
|
|
84
|
+
function getFunctionFromModule<T>(key: string, defaultFn: T): T {
|
|
85
|
+
const fn = (nativePaymentWidgetDict as Record<string, unknown>)[key];
|
|
86
|
+
return typeof fn === 'function' ? (fn as T) : defaultFn;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const nativePaymentWidget: NativePaymentWidget = {
|
|
90
|
+
confirmPayment: getFunctionFromModule(
|
|
91
|
+
'confirmPayment',
|
|
92
|
+
(_viewId: number, _callback: ConfirmPaymentCallback) => {}
|
|
93
|
+
),
|
|
94
|
+
updateIntentInitForWidget: getFunctionFromModule(
|
|
95
|
+
'updateIntentInitForWidget',
|
|
96
|
+
(_viewId: number, _callback: ConfirmPaymentCallback) => {}
|
|
97
|
+
),
|
|
98
|
+
updateIntentCompleteForWidget: getFunctionFromModule(
|
|
99
|
+
'updateIntentCompleteForWidget',
|
|
100
|
+
(
|
|
101
|
+
_viewId: number,
|
|
102
|
+
_sdkAuthorization: string,
|
|
103
|
+
_callback: ConfirmPaymentCallback
|
|
104
|
+
) => {}
|
|
105
|
+
),
|
|
106
|
+
confirmPaymentCVC: getFunctionFromModule(
|
|
107
|
+
'confirmPaymentCVC',
|
|
108
|
+
(
|
|
109
|
+
_viewId: number,
|
|
110
|
+
_paymentToken: string,
|
|
111
|
+
_paymentMethodId: string,
|
|
112
|
+
_callback: ConfirmPaymentCVCCallback
|
|
113
|
+
) => {}
|
|
114
|
+
),
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
export function confirmPayment(
|
|
118
|
+
viewId: number,
|
|
119
|
+
callback: ConfirmPaymentCallback
|
|
120
|
+
): void {
|
|
121
|
+
nativePaymentWidget.confirmPayment(viewId, callback);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export function updateIntentInitForWidget(
|
|
125
|
+
viewId: number,
|
|
126
|
+
callback: ConfirmPaymentCallback
|
|
127
|
+
): void {
|
|
128
|
+
nativePaymentWidget.updateIntentInitForWidget(viewId, callback);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export function updateIntentCompleteForWidget(
|
|
132
|
+
viewId: number,
|
|
133
|
+
sdkAuthorization: string,
|
|
134
|
+
callback: ConfirmPaymentCallback
|
|
135
|
+
): void {
|
|
136
|
+
nativePaymentWidget.updateIntentCompleteForWidget(
|
|
137
|
+
viewId,
|
|
138
|
+
sdkAuthorization,
|
|
139
|
+
callback
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export function confirmPaymentCVC(
|
|
144
|
+
viewId: number,
|
|
145
|
+
paymentToken: string,
|
|
146
|
+
paymentMethodId: string,
|
|
147
|
+
callback: ConfirmPaymentCVCCallback
|
|
148
|
+
): void {
|
|
149
|
+
nativePaymentWidget.confirmPaymentCVC(
|
|
150
|
+
viewId,
|
|
151
|
+
paymentToken,
|
|
152
|
+
paymentMethodId,
|
|
153
|
+
callback
|
|
154
|
+
);
|
|
155
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';
|
|
2
|
+
import type { ViewProps } from 'react-native';
|
|
3
|
+
import type { Double } from 'react-native/Libraries/Types/CodegenTypes';
|
|
4
|
+
|
|
5
|
+
export interface NativeProps extends ViewProps {
|
|
6
|
+
buttonType?: string;
|
|
7
|
+
buttonStyle?: string;
|
|
8
|
+
cornerRadius?: Double;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export default codegenNativeComponent<NativeProps>('ApplePayView');
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type {TurboModule} from 'react-native';
|
|
2
|
+
import {TurboModuleRegistry} from 'react-native';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Codegen spec for the HyperHeadless TurboModule.
|
|
6
|
+
*
|
|
7
|
+
* Naming convention: Native<ModuleName>.ts — required by the RN codegen.
|
|
8
|
+
* number → Double on Android; Object → ReadableMap; Array<Object> → ReadableArray.
|
|
9
|
+
*/
|
|
10
|
+
export interface Spec extends TurboModule {
|
|
11
|
+
getPaymentSession(
|
|
12
|
+
rootTag: number,
|
|
13
|
+
defaultPaymentMethod: Object,
|
|
14
|
+
lastUsedPaymentMethod: Object,
|
|
15
|
+
allPaymentMethods: Array<Object>,
|
|
16
|
+
callback: (result: Object) => void,
|
|
17
|
+
): void;
|
|
18
|
+
|
|
19
|
+
exitHeadless(rootTag: number, status: string): void;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export default TurboModuleRegistry.get<Spec>('HyperHeadless');
|