react-native-hyperswitch-dev-sdk 0.4.3 → 0.4.5
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 +4 -0
- package/android/build.gradle +0 -6
- package/android/src/main/java/com/hyperswitchsdkreactnative/modules/ReactNativeHyperswitchModule.kt +1 -5
- package/ios/Modules/ReactNative/HyperModule.h +25 -0
- package/ios/Modules/ReactNative/HyperModule.mm +169 -0
- package/ios/Modules/ReactNative/HyperswitchModule.swift +223 -165
- package/ios/Modules/ReactNative/NativeHyperswitchModule.mm +17 -12
- package/ios/Modules/ReactNative/NativeHyperswitchModuleImpl.swift +18 -7
- package/ios/Modules/ReactNative/NativePaymentElementModule.mm +122 -122
- package/ios/Views/Fabric/NativePaymentElementView.mm +8 -0
- package/ios/Views/Native/NativePaymentWidget.swift +125 -121
- package/ios/hyperswitchSDK/Core/HyperCVCWidget/CVCWidget.swift +9 -7
- package/ios/hyperswitchSDK/Core/HyperPaymentCardTextField/PaymentHandler.swift +1 -1
- package/ios/hyperswitchSDK/Core/HyperPaymentSheet/PaymentSheetView+UIKit.swift +79 -13
- package/ios/hyperswitchSDK/Core/HyperPaymentSheet/PaymentSheetView.swift +2 -2
- package/ios/hyperswitchSDK/Core/HyperPaymentWidget/PaymentWidget.swift +23 -19
- package/ios/hyperswitchSDK/Core/HyperSession/PaymentSession+UIKit.swift +14 -0
- package/ios/hyperswitchSDK/Core/NativeModule/HyperModuleImpl.swift +388 -0
- package/ios/hyperswitchSDK/Core/NativeModule/RNHeadlessManager.swift +58 -22
- package/ios/hyperswitchSDK/Core/NativeModule/RNViewManager.swift +84 -29
- package/ios/hyperswitchSDK/Core/NativeModule/hyper-Bridging-Header.h +2 -0
- package/ios/hyperswitchSDK/Public/RNBridgeFactory.h +28 -0
- package/ios/hyperswitchSDK/Public/RNBridgeFactory.mm +167 -0
- package/ios/hyperswitchSDK/Shared/PaymentSheet.swift +1 -1
- package/lib/commonjs/index.bundle.js +1 -1
- package/lib/commonjs/index.bundle.js.map +1 -1
- package/lib/module/index.bundle.js +1 -1
- package/lib/module/index.bundle.js.map +1 -1
- package/package.json +8 -4
- package/src/context/PaymentSession.ts +2 -0
- package/src/specs/NativeHyperswitchModule.ts +2 -2
- package/ios/Modules/ReactNative/HyperswitchSdkReactNative.h +0 -5
- package/ios/Modules/ReactNative/HyperswitchSdkReactNative.mm +0 -121
- package/ios/hyperswitchSDK/Core/NativeModule/HyperModule.m +0 -31
- package/ios/hyperswitchSDK/Core/NativeModule/HyperModule.swift +0 -343
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.bundle.js","sources":["../../../../src/specs/NativeHyperswitchModule.ts","../../../../src/utils/LaunchOptions.ts","../../../../src/context/SavedPaymentMethods.ts","../../../../src/utils/InitializationState.ts","../../../../src/context/PaymentSession.ts","../../../../src/context/Elements.ts","../../../../src/index.ts"],"sourcesContent":["import type { TurboModule } from 'react-native';\nimport { NativeModules, TurboModuleRegistry } from 'react-native';\n\nexport type CustomEndpoints = Object;\n\nexport interface SessionData {\n hyperswitchConfig: Object;\n paymentSessionConfig: { sdkAuthorization: string };\n configuration: Object;\n}\n\nexport interface SavedPaymentMethodsConfiguration {\n hiddenPaymentMethods?: string[];\n}\n\nexport interface Spec extends TurboModule {\n initialise(\n publishableKey: string,\n platformPublishableKey: string,\n profileId: string,\n environment: string,\n customEndpoints: CustomEndpoints\n ): Promise<string>;\n\n presentPaymentSheet(params: SessionData): Promise<string>;\n\n getCustomerSavedPaymentMethods(params?: SessionData): Promise<string>;\n\n getCustomerLastUsedPaymentMethodData(): Promise<string>;\n\n getCustomerDefaultSavedPaymentMethodData(): Promise<string>;\n\n getCustomerSavedPaymentMethodData(): Promise<string>;\n\n confirmWithCustomerLastUsedPaymentMethod(reactTag: number): Promise<string>;\n\n confirmWithCustomerDefaultPaymentMethod(reactTag: number): Promise<string>;\n\n confirmWithCustomerPaymentToken(reactTag: number, token: string): Promise<string>;\n}\n\n/**\n * Use `TurboModuleRegistry.get` first for new-arch TurboModules, and fall back\n * to `NativeModules` for legacy/old-arch support.\n */\nconst NativeHyperswitchModule =\n TurboModuleRegistry.get<Spec>('NativeHyperswitchModule') ??\n NativeModules.NativeHyperswitchModule;\nconsole.log('NativeHyperswitchModule', NativeHyperswitchModule);\nexport default NativeHyperswitchModule as Spec;\nexport { NativeHyperswitchModule };\n","import type {\n HyperswitchConfiguration,\n NativePaymentSheetPayload,\n} from '../types/definitions';\nimport type { PaymentSessionConfiguration } from '../types/definitions';\nimport { PaymentResult } from '../types/paymentresult';\n\nfunction buildPresentPaymentSheetPayload(\n hyperswitchConfig: HyperswitchConfiguration,\n paymentSessionConfig: PaymentSessionConfiguration,\n configuration: Record<string, unknown> = {},\n): NativePaymentSheetPayload {\n // platformPublishableKey is internal to the RN bridge; it is not part of the\n // merchant-facing hyperswitchConfig payload.\n const { platformPublishableKey: _platformPublishableKey, ...restConfig } =\n hyperswitchConfig;\n\n return {\n hyperswitchConfig: restConfig as Record<string, unknown>,\n paymentSessionConfig: paymentSessionConfig,\n configuration,\n };\n}\n\nfunction mapStatus(status: string): PaymentResult['type'] {\n switch (status) {\n case 'succeeded':\n case 'completed':\n case 'success':\n return 'completed';\n case 'cancelled':\n case 'canceled':\n return 'canceled';\n case 'failed':\n case 'error':\n default:\n return 'failed';\n }\n}\n\nexport { buildPresentPaymentSheetPayload, mapStatus };\n","import NativeHyperswitchModule from '../specs/NativeHyperswitchModule';\nimport {\n HyperswitchConfiguration,\n PaymentSessionConfiguration,\n} from '../types/definitions';\nimport {\n CustomerSavedPaymentMethodsSession,\n CustomerLastUsedPaymentMethod,\n} from '../types/savedPaymentMethods';\nimport { buildPresentPaymentSheetPayload } from '../utils/LaunchOptions';\n\nfunction parsePaymentMethod(raw: string): CustomerLastUsedPaymentMethod {\n const parsed = JSON.parse(raw) as CustomerLastUsedPaymentMethod & {\n billing?: string | object | null;\n };\n if (parsed.billing && typeof parsed.billing === 'string') {\n try {\n parsed.billing = JSON.parse(parsed.billing);\n } catch {\n parsed.billing = null;\n }\n }\n return parsed as CustomerLastUsedPaymentMethod;\n}\n\nexport function createCustomerSavedPaymentMethodsSession(): CustomerSavedPaymentMethodsSession {\n return {\n async getCustomerLastUsedPaymentMethodData(): Promise<CustomerLastUsedPaymentMethod | null> {\n const raw =\n await NativeHyperswitchModule.getCustomerLastUsedPaymentMethodData();\n return parsePaymentMethod(raw);\n },\n\n async getCustomerDefaultSavedPaymentMethodData(): Promise<CustomerLastUsedPaymentMethod | null> {\n const raw =\n await NativeHyperswitchModule.getCustomerDefaultSavedPaymentMethodData();\n return parsePaymentMethod(raw);\n },\n\n async getCustomerSavedPaymentMethodData(): Promise<CustomerLastUsedPaymentMethod | null> {\n const raw =\n await NativeHyperswitchModule.getCustomerSavedPaymentMethodData();\n return parsePaymentMethod(raw);\n },\n\n async confirmWithCustomerLastUsedPaymentMethod(args?: {\n id?: string;\n }): Promise<any> {\n const raw = await NativeHyperswitchModule\n .confirmWithCustomerLastUsedPaymentMethod\n // args?.id\n ();\n // return mapNativeResponseToPaymentResult(raw);\n },\n\n async confirmWithCustomerDefaultPaymentMethod(args?: {\n id?: string;\n }): Promise<any> {\n const raw = await NativeHyperswitchModule\n .confirmWithCustomerDefaultPaymentMethod\n // args?.id\n ();\n // return mapNativeResponseToPaymentResult(raw);\n },\n };\n}\n\nexport async function getCustomerSavedPaymentMethods(\n hyperswitchConfig: HyperswitchConfiguration,\n paymentSessionConfig: PaymentSessionConfiguration,\n configuration?: Record<string, unknown>\n): Promise<CustomerSavedPaymentMethodsSession> {\n const payload = buildPresentPaymentSheetPayload(\n hyperswitchConfig,\n paymentSessionConfig,\n configuration\n );\n await NativeHyperswitchModule.getCustomerSavedPaymentMethods(payload);\n return createCustomerSavedPaymentMethodsSession();\n}\n","/**\n * Tracks whether the Hyperswitch SDK is currently initialising (or re-initialising\n * after a reload). presentPaymentSheet should be blocked while this flag is true\n * so the native SDK is not asked to open a sheet before it is ready.\n *\n * Also tracks whether a payment sheet is currently presented so that a hot-reload\n * (or any other code path) cannot stack a second sheet on top of an open one.\n */\n\nlet _isInitializing = false;\n\nexport function setInitializing(value: boolean): void {\n _isInitializing = value;\n}\n\nexport function isInitializing(): boolean {\n return _isInitializing;\n}\n\nlet _isSheetPresented = false;\n\nexport function setSheetPresented(value: boolean): void {\n _isSheetPresented = value;\n}\n\nexport function isSheetPresented(): boolean {\n return _isSheetPresented;\n}\n","import NativeHyperswitchModule from '../specs/NativeHyperswitchModule';\nimport type {\n HyperswitchConfiguration,\n NativePaymentSheetPayload,\n PaymentSession,\n PaymentSessionConfiguration,\n} from '../types/definitions';\nimport { buildPresentPaymentSheetPayload } from '../utils/LaunchOptions';\nimport { getCustomerSavedPaymentMethods } from './SavedPaymentMethods';\nimport type { PaymentResult } from '../types/paymentresult';\nimport type { CustomerSavedPaymentMethodsSession } from '../types/savedPaymentMethods';\nimport { isInitializing, isSheetPresented, setSheetPresented } from '../utils/InitializationState';\n\ninterface NativeResponse {\n status: string;\n message: string;\n data?: any;\n}\n\nexport function parseNativeResponse(\n raw: string | NativeResponse\n): NativeResponse {\n if (typeof raw === 'object' && raw !== null) {\n return raw as NativeResponse;\n }\n try {\n return JSON.parse(raw as string) as NativeResponse;\n } catch {\n return { status: 'failed', message: String(raw) };\n }\n}\n\nexport function mapStatus(status: string): PaymentResult['type'] {\n switch (status) {\n case 'succeeded':\n case 'completed':\n case 'success':\n return 'completed';\n case 'cancelled':\n case 'canceled':\n return 'canceled';\n case 'failed':\n case 'error':\n default:\n return 'failed';\n }\n}\n\nexport function mapNativeResponseToPaymentResult(\n raw: string | NativeResponse\n): PaymentResult {\n const parsed = parseNativeResponse(raw);\n return {\n type: mapStatus(parsed.status),\n message: parsed.message,\n };\n}\n\nexport async function presentPaymentSheetWithPayload(\n payload: NativePaymentSheetPayload\n): Promise<PaymentResult> {\n if (isInitializing()) {\n return {\n type: 'failed',\n message: 'SDK is reloading. Please wait for initialisation to complete before presenting the payment sheet.',\n };\n }\n if (isSheetPresented()) {\n // A sheet is already open (e.g. a hot-reload fired while the sheet was visible).\n // Silently skip so the existing sheet is not covered by a new one.\n return {\n type: 'canceled',\n message: 'A payment sheet is already presented.',\n };\n }\n setSheetPresented(true);\n try {\n const raw = await NativeHyperswitchModule.presentPaymentSheet({\n hyperswitchConfig: payload.hyperswitchConfig,\n paymentSessionConfig: payload.paymentSessionConfig,\n configuration: payload.configuration,\n });\n return mapNativeResponseToPaymentResult(raw);\n } finally {\n setSheetPresented(false);\n }\n}\n\nexport async function updateIntent(\n _intentResolver: () => Promise<PaymentSessionConfiguration>\n): Promise<void> {\n}\n\nexport function createPaymentSession(\n hyperswitchConfig: HyperswitchConfiguration,\n paymentSessionConfig: PaymentSessionConfiguration\n): PaymentSession {\n return {\n async presentPaymentSheet(\n configuration?: Record<string, unknown>\n ): Promise<PaymentResult> {\n const payload = buildPresentPaymentSheetPayload(\n hyperswitchConfig,\n paymentSessionConfig,\n configuration\n );\n return presentPaymentSheetWithPayload(payload);\n },\n\n async getCustomerSavedPaymentMethods(\n configuration?: Record<string, unknown>\n ): Promise<CustomerSavedPaymentMethodsSession> {\n return getCustomerSavedPaymentMethods(\n hyperswitchConfig,\n paymentSessionConfig,\n configuration\n );\n },\n updateIntent,\n };\n}\n","import type {\n HyperswitchConfiguration,\n PaymentElementHandle,\n PaymentSessionConfiguration,\n} from '../types/definitions';\nimport { buildPresentPaymentSheetPayload } from '../utils/LaunchOptions';\nimport {\n presentPaymentSheetWithPayload,\n updateIntent,\n} from '../context/PaymentSession';\nimport type { PaymentResult } from '../types/paymentresult';\nimport type { CustomerSavedPaymentMethodsSession } from '../types/savedPaymentMethods';\n\nimport { getCustomerSavedPaymentMethods } from './SavedPaymentMethods';\nimport { Elements } from '../types/elements';\n\ntype ElementsNativeActions = Pick<\n Elements,\n | 'confirmPayment'\n | 'presentPaymentSheet'\n | 'getCustomerSavedPaymentMethods'\n | 'updateIntent'\n>;\n\nexport function createElementsNativeActions(\n hyperswitchConfig: HyperswitchConfiguration,\n paymentSessionConfig: PaymentSessionConfiguration\n): ElementsNativeActions {\n return {\n async presentPaymentSheet(\n configuration?: Record<string, unknown>\n ): Promise<PaymentResult> {\n const payload = buildPresentPaymentSheetPayload(\n hyperswitchConfig,\n paymentSessionConfig,\n configuration\n );\n return presentPaymentSheetWithPayload(payload);\n },\n\n async confirmPayment(\n paymentElementRef: { current: PaymentElementHandle | null } | string,\n _confirmOptions?: { confirmParams?: Record<string, any> }\n ): Promise<any> {\n // if (typeof paymentElementRef === 'string') {\n // const result = await widgetConfirm(paymentElementRef);\n // return {\n // type: mapStatus(result.status),\n // message: result.message,\n // };\n // }\n // const ref = paymentElementRef.current;\n // if (!ref) {\n // throw new Error('PaymentElement reference is not mounted');\n // }\n // return ref.confirmPayment(_confirmOptions);\n },\n\n async getCustomerSavedPaymentMethods(\n configuration?: Record<string, unknown>\n ): Promise<CustomerSavedPaymentMethodsSession> {\n return getCustomerSavedPaymentMethods(\n hyperswitchConfig,\n paymentSessionConfig,\n configuration\n );\n },\n\n updateIntent: updateIntent,\n };\n}\n\nexport function createElements(\n hyperswitchConfig: HyperswitchConfiguration,\n paymentSessionConfig: PaymentSessionConfiguration\n): Elements {\n return {\n ...createElementsNativeActions(hyperswitchConfig, paymentSessionConfig),\n };\n}\n","import type {\n HyperswitchConfiguration,\n PaymentSession,\n PaymentSessionConfiguration,\n HyperswitchSession\n} from './types/definitions';\n\nexport type * from './types/definitions';\nexport type * from './types/elements';\nexport type * from './types/NativeModuleTypes';\nexport type * from './types/PaymentSheetConfiguration'\n\nimport NativeHyperswitchModule from './specs/NativeHyperswitchModule';\nimport { createPaymentSession } from './context/PaymentSession';\nimport { Elements } from './types/elements';\nimport { createElements } from './context/Elements';\nimport { setInitializing } from './utils/InitializationState';\n\nexport function loadHyper(\n config: HyperswitchConfiguration\n): Promise<HyperswitchSession> {\n setInitializing(true);\n return NativeHyperswitchModule.initialise(\n config.publishableKey,\n config.platformPublishableKey ?? '',\n config.profileId ?? '',\n config.environment ?? 'PROD',\n config.customEndpoints ?? {}\n ).then(() => {\n setInitializing(false);\n return {\n publishableKey: config.publishableKey,\n async initPaymentSession(\n options: PaymentSessionConfiguration\n ): Promise<PaymentSession> {\n return createPaymentSession(config, options);\n },\n async elements(options: PaymentSessionConfiguration): Promise<Elements> {\n return createElements(config, options);\n },\n }\n }).catch((error) => {\n setInitializing(false);\n console.error('Error initializing Hyperswitch SDK:', error);\n throw error;\n });\n\n}\n\n\nexport const Hyperswitch = {\n init: loadHyper,\n};"],"names":["NativeHyperswitchModule","TurboModuleRegistry","get","NativeModules","buildPresentPaymentSheetPayload","hyperswitchConfig","paymentSessionConfig","configuration","platformPublishableKey","_platformPublishableKey","restConfig","parsePaymentMethod","raw","parsed","JSON","parse","billing","async","getCustomerSavedPaymentMethods","payload","getCustomerLastUsedPaymentMethodData","getCustomerDefaultSavedPaymentMethodData","getCustomerSavedPaymentMethodData","confirmWithCustomerLastUsedPaymentMethod","args","confirmWithCustomerDefaultPaymentMethod","console","log","_isInitializing","setInitializing","value","_isSheetPresented","setSheetPresented","mapStatus","status","mapNativeResponseToPaymentResult","message","String","parseNativeResponse","type","presentPaymentSheetWithPayload","presentPaymentSheet","updateIntent","_intentResolver","createElementsNativeActions","confirmPayment","paymentElementRef","_confirmOptions","loadHyper","config","initialise","publishableKey","profileId","environment","customEndpoints","then","initPaymentSession","options","catch","error","Hyperswitch","init"],"mappings":"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"}
|
|
1
|
+
{"version":3,"file":"index.bundle.js","sources":["../../../../src/specs/NativeHyperswitchModule.ts","../../../../src/utils/LaunchOptions.ts","../../../../src/context/SavedPaymentMethods.ts","../../../../src/utils/InitializationState.ts","../../../../src/context/PaymentSession.ts","../../../../src/context/Elements.ts","../../../../src/index.ts"],"sourcesContent":["import type { TurboModule } from 'react-native';\nimport { NativeModules, TurboModuleRegistry } from 'react-native';\n\nexport type CustomEndpoints = Object;\n\nexport interface SessionData {\n hyperswitchConfig: Object;\n paymentSessionConfig: { sdkAuthorization: string };\n configuration: Object;\n}\n\nexport interface SavedPaymentMethodsConfiguration {\n hiddenPaymentMethods?: string[];\n}\n\nexport interface Spec extends TurboModule {\n initialise(\n publishableKey: string,\n platformPublishableKey: string,\n profileId: string,\n environment: string,\n customEndpoints: CustomEndpoints\n ): Promise<string>;\n\n presentPaymentSheet(params: Object): Promise<string>;\n\n getCustomerSavedPaymentMethods(params?: Object): Promise<string>;\n\n getCustomerLastUsedPaymentMethodData(): Promise<string>;\n\n getCustomerDefaultSavedPaymentMethodData(): Promise<string>;\n\n getCustomerSavedPaymentMethodData(): Promise<string>;\n\n confirmWithCustomerLastUsedPaymentMethod(reactTag: number): Promise<string>;\n\n confirmWithCustomerDefaultPaymentMethod(reactTag: number): Promise<string>;\n\n confirmWithCustomerPaymentToken(reactTag: number, token: string): Promise<string>;\n}\n\n/**\n * Use `TurboModuleRegistry.get` first for new-arch TurboModules, and fall back\n * to `NativeModules` for legacy/old-arch support.\n */\nconst NativeHyperswitchModule =\n TurboModuleRegistry.get<Spec>('NativeHyperswitchModule') ??\n NativeModules.NativeHyperswitchModule;\nconsole.log('NativeHyperswitchModule', NativeHyperswitchModule);\nexport default NativeHyperswitchModule as Spec;\nexport { NativeHyperswitchModule };\n","import type {\n HyperswitchConfiguration,\n NativePaymentSheetPayload,\n} from '../types/definitions';\nimport type { PaymentSessionConfiguration } from '../types/definitions';\nimport { PaymentResult } from '../types/paymentresult';\n\nfunction buildPresentPaymentSheetPayload(\n hyperswitchConfig: HyperswitchConfiguration,\n paymentSessionConfig: PaymentSessionConfiguration,\n configuration: Record<string, unknown> = {},\n): NativePaymentSheetPayload {\n // platformPublishableKey is internal to the RN bridge; it is not part of the\n // merchant-facing hyperswitchConfig payload.\n const { platformPublishableKey: _platformPublishableKey, ...restConfig } =\n hyperswitchConfig;\n\n return {\n hyperswitchConfig: restConfig as Record<string, unknown>,\n paymentSessionConfig: paymentSessionConfig,\n configuration,\n };\n}\n\nfunction mapStatus(status: string): PaymentResult['type'] {\n switch (status) {\n case 'succeeded':\n case 'completed':\n case 'success':\n return 'completed';\n case 'cancelled':\n case 'canceled':\n return 'canceled';\n case 'failed':\n case 'error':\n default:\n return 'failed';\n }\n}\n\nexport { buildPresentPaymentSheetPayload, mapStatus };\n","import NativeHyperswitchModule from '../specs/NativeHyperswitchModule';\nimport {\n HyperswitchConfiguration,\n PaymentSessionConfiguration,\n} from '../types/definitions';\nimport {\n CustomerSavedPaymentMethodsSession,\n CustomerLastUsedPaymentMethod,\n} from '../types/savedPaymentMethods';\nimport { buildPresentPaymentSheetPayload } from '../utils/LaunchOptions';\n\nfunction parsePaymentMethod(raw: string): CustomerLastUsedPaymentMethod {\n const parsed = JSON.parse(raw) as CustomerLastUsedPaymentMethod & {\n billing?: string | object | null;\n };\n if (parsed.billing && typeof parsed.billing === 'string') {\n try {\n parsed.billing = JSON.parse(parsed.billing);\n } catch {\n parsed.billing = null;\n }\n }\n return parsed as CustomerLastUsedPaymentMethod;\n}\n\nexport function createCustomerSavedPaymentMethodsSession(): CustomerSavedPaymentMethodsSession {\n return {\n async getCustomerLastUsedPaymentMethodData(): Promise<CustomerLastUsedPaymentMethod | null> {\n const raw =\n await NativeHyperswitchModule.getCustomerLastUsedPaymentMethodData();\n return parsePaymentMethod(raw);\n },\n\n async getCustomerDefaultSavedPaymentMethodData(): Promise<CustomerLastUsedPaymentMethod | null> {\n const raw =\n await NativeHyperswitchModule.getCustomerDefaultSavedPaymentMethodData();\n return parsePaymentMethod(raw);\n },\n\n async getCustomerSavedPaymentMethodData(): Promise<CustomerLastUsedPaymentMethod | null> {\n const raw =\n await NativeHyperswitchModule.getCustomerSavedPaymentMethodData();\n return parsePaymentMethod(raw);\n },\n\n async confirmWithCustomerLastUsedPaymentMethod(args?: {\n id?: string;\n }): Promise<any> {\n const raw = await NativeHyperswitchModule\n .confirmWithCustomerLastUsedPaymentMethod\n // args?.id\n ();\n // return mapNativeResponseToPaymentResult(raw);\n },\n\n async confirmWithCustomerDefaultPaymentMethod(args?: {\n id?: string;\n }): Promise<any> {\n const raw = await NativeHyperswitchModule\n .confirmWithCustomerDefaultPaymentMethod\n // args?.id\n ();\n // return mapNativeResponseToPaymentResult(raw);\n },\n };\n}\n\nexport async function getCustomerSavedPaymentMethods(\n hyperswitchConfig: HyperswitchConfiguration,\n paymentSessionConfig: PaymentSessionConfiguration,\n configuration?: Record<string, unknown>\n): Promise<CustomerSavedPaymentMethodsSession> {\n const payload = buildPresentPaymentSheetPayload(\n hyperswitchConfig,\n paymentSessionConfig,\n configuration\n );\n await NativeHyperswitchModule.getCustomerSavedPaymentMethods(payload);\n return createCustomerSavedPaymentMethodsSession();\n}\n","/**\n * Tracks whether the Hyperswitch SDK is currently initialising (or re-initialising\n * after a reload). presentPaymentSheet should be blocked while this flag is true\n * so the native SDK is not asked to open a sheet before it is ready.\n *\n * Also tracks whether a payment sheet is currently presented so that a hot-reload\n * (or any other code path) cannot stack a second sheet on top of an open one.\n */\n\nlet _isInitializing = false;\n\nexport function setInitializing(value: boolean): void {\n _isInitializing = value;\n}\n\nexport function isInitializing(): boolean {\n return _isInitializing;\n}\n\nlet _isSheetPresented = false;\n\nexport function setSheetPresented(value: boolean): void {\n _isSheetPresented = value;\n}\n\nexport function isSheetPresented(): boolean {\n return _isSheetPresented;\n}\n","import NativeHyperswitchModule from '../specs/NativeHyperswitchModule';\nimport type {\n HyperswitchConfiguration,\n NativePaymentSheetPayload,\n PaymentSession,\n PaymentSessionConfiguration,\n} from '../types/definitions';\nimport { buildPresentPaymentSheetPayload } from '../utils/LaunchOptions';\nimport { getCustomerSavedPaymentMethods } from './SavedPaymentMethods';\nimport type { PaymentResult } from '../types/paymentresult';\nimport type { CustomerSavedPaymentMethodsSession } from '../types/savedPaymentMethods';\nimport { isInitializing, isSheetPresented, setSheetPresented } from '../utils/InitializationState';\n\ninterface NativeResponse {\n status: string;\n message: string;\n data?: any;\n}\n\nexport function parseNativeResponse(\n raw: string | NativeResponse\n): NativeResponse {\n if (typeof raw === 'object' && raw !== null) {\n return raw as NativeResponse;\n }\n try {\n return JSON.parse(raw as string) as NativeResponse;\n } catch {\n return { status: 'failed', message: String(raw) };\n }\n}\n\nexport function mapStatus(status: string): PaymentResult['type'] {\n switch (status) {\n case 'succeeded':\n case 'completed':\n case 'success':\n return 'completed';\n case 'cancelled':\n case 'canceled':\n return 'canceled';\n case 'failed':\n case 'error':\n default:\n return 'failed';\n }\n}\n\nexport function mapNativeResponseToPaymentResult(\n raw: string | NativeResponse\n): PaymentResult {\n const parsed = parseNativeResponse(raw);\n return {\n type: mapStatus(parsed.status),\n message: parsed.message,\n };\n}\n\nexport async function presentPaymentSheetWithPayload(\n payload: NativePaymentSheetPayload\n): Promise<PaymentResult> {\n if (isInitializing()) {\n return {\n type: 'failed',\n message: 'SDK is reloading. Please wait for initialisation to complete before presenting the payment sheet.',\n };\n }\n if (isSheetPresented()) {\n // A sheet is already open (e.g. a hot-reload fired while the sheet was visible).\n // Silently skip so the existing sheet is not covered by a new one.\n return {\n type: 'canceled',\n message: 'A payment sheet is already presented.',\n };\n }\n setSheetPresented(true);\n try {\n console.log('Presenting payment sheet with payload:', payload);\n const raw = await NativeHyperswitchModule.presentPaymentSheet({\n hyperswitchConfig: payload.hyperswitchConfig,\n paymentSessionConfig: payload.paymentSessionConfig,\n configuration: payload.configuration,\n });\n console.log('Native response from presentPaymentSheet:', raw);\n return mapNativeResponseToPaymentResult(raw);\n } finally {\n setSheetPresented(false);\n }\n}\n\nexport async function updateIntent(\n _intentResolver: () => Promise<PaymentSessionConfiguration>\n): Promise<void> {\n}\n\nexport function createPaymentSession(\n hyperswitchConfig: HyperswitchConfiguration,\n paymentSessionConfig: PaymentSessionConfiguration\n): PaymentSession {\n return {\n async presentPaymentSheet(\n configuration?: Record<string, unknown>\n ): Promise<PaymentResult> {\n const payload = buildPresentPaymentSheetPayload(\n hyperswitchConfig,\n paymentSessionConfig,\n configuration\n );\n return presentPaymentSheetWithPayload(payload);\n },\n\n async getCustomerSavedPaymentMethods(\n configuration?: Record<string, unknown>\n ): Promise<CustomerSavedPaymentMethodsSession> {\n return getCustomerSavedPaymentMethods(\n hyperswitchConfig,\n paymentSessionConfig,\n configuration\n );\n },\n updateIntent,\n };\n}\n","import type {\n HyperswitchConfiguration,\n PaymentElementHandle,\n PaymentSessionConfiguration,\n} from '../types/definitions';\nimport { buildPresentPaymentSheetPayload } from '../utils/LaunchOptions';\nimport {\n presentPaymentSheetWithPayload,\n updateIntent,\n} from '../context/PaymentSession';\nimport type { PaymentResult } from '../types/paymentresult';\nimport type { CustomerSavedPaymentMethodsSession } from '../types/savedPaymentMethods';\n\nimport { getCustomerSavedPaymentMethods } from './SavedPaymentMethods';\nimport { Elements } from '../types/elements';\n\ntype ElementsNativeActions = Pick<\n Elements,\n | 'confirmPayment'\n | 'presentPaymentSheet'\n | 'getCustomerSavedPaymentMethods'\n | 'updateIntent'\n>;\n\nexport function createElementsNativeActions(\n hyperswitchConfig: HyperswitchConfiguration,\n paymentSessionConfig: PaymentSessionConfiguration\n): ElementsNativeActions {\n return {\n async presentPaymentSheet(\n configuration?: Record<string, unknown>\n ): Promise<PaymentResult> {\n const payload = buildPresentPaymentSheetPayload(\n hyperswitchConfig,\n paymentSessionConfig,\n configuration\n );\n return presentPaymentSheetWithPayload(payload);\n },\n\n async confirmPayment(\n paymentElementRef: { current: PaymentElementHandle | null } | string,\n _confirmOptions?: { confirmParams?: Record<string, any> }\n ): Promise<any> {\n // if (typeof paymentElementRef === 'string') {\n // const result = await widgetConfirm(paymentElementRef);\n // return {\n // type: mapStatus(result.status),\n // message: result.message,\n // };\n // }\n // const ref = paymentElementRef.current;\n // if (!ref) {\n // throw new Error('PaymentElement reference is not mounted');\n // }\n // return ref.confirmPayment(_confirmOptions);\n },\n\n async getCustomerSavedPaymentMethods(\n configuration?: Record<string, unknown>\n ): Promise<CustomerSavedPaymentMethodsSession> {\n return getCustomerSavedPaymentMethods(\n hyperswitchConfig,\n paymentSessionConfig,\n configuration\n );\n },\n\n updateIntent: updateIntent,\n };\n}\n\nexport function createElements(\n hyperswitchConfig: HyperswitchConfiguration,\n paymentSessionConfig: PaymentSessionConfiguration\n): Elements {\n return {\n ...createElementsNativeActions(hyperswitchConfig, paymentSessionConfig),\n };\n}\n","import type {\n HyperswitchConfiguration,\n PaymentSession,\n PaymentSessionConfiguration,\n HyperswitchSession\n} from './types/definitions';\n\nexport type * from './types/definitions';\nexport type * from './types/elements';\nexport type * from './types/NativeModuleTypes';\nexport type * from './types/PaymentSheetConfiguration'\n\nimport NativeHyperswitchModule from './specs/NativeHyperswitchModule';\nimport { createPaymentSession } from './context/PaymentSession';\nimport { Elements } from './types/elements';\nimport { createElements } from './context/Elements';\nimport { setInitializing } from './utils/InitializationState';\n\nexport function loadHyper(\n config: HyperswitchConfiguration\n): Promise<HyperswitchSession> {\n setInitializing(true);\n return NativeHyperswitchModule.initialise(\n config.publishableKey,\n config.platformPublishableKey ?? '',\n config.profileId ?? '',\n config.environment ?? 'PROD',\n config.customEndpoints ?? {}\n ).then(() => {\n setInitializing(false);\n return {\n publishableKey: config.publishableKey,\n async initPaymentSession(\n options: PaymentSessionConfiguration\n ): Promise<PaymentSession> {\n return createPaymentSession(config, options);\n },\n async elements(options: PaymentSessionConfiguration): Promise<Elements> {\n return createElements(config, options);\n },\n }\n }).catch((error) => {\n setInitializing(false);\n console.error('Error initializing Hyperswitch SDK:', error);\n throw error;\n });\n\n}\n\n\nexport const Hyperswitch = {\n init: loadHyper,\n};"],"names":["NativeHyperswitchModule","TurboModuleRegistry","get","NativeModules","buildPresentPaymentSheetPayload","hyperswitchConfig","paymentSessionConfig","configuration","platformPublishableKey","_platformPublishableKey","restConfig","parsePaymentMethod","raw","parsed","JSON","parse","billing","async","getCustomerSavedPaymentMethods","payload","getCustomerLastUsedPaymentMethodData","getCustomerDefaultSavedPaymentMethodData","getCustomerSavedPaymentMethodData","confirmWithCustomerLastUsedPaymentMethod","args","confirmWithCustomerDefaultPaymentMethod","console","log","_isInitializing","setInitializing","value","_isSheetPresented","setSheetPresented","mapStatus","status","mapNativeResponseToPaymentResult","message","String","parseNativeResponse","type","presentPaymentSheetWithPayload","presentPaymentSheet","updateIntent","_intentResolver","createElementsNativeActions","confirmPayment","paymentElementRef","_confirmOptions","loadHyper","config","initialise","publishableKey","profileId","environment","customEndpoints","then","initPaymentSession","options","catch","error","Hyperswitch","init"],"mappings":"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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-hyperswitch-dev-sdk",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.5",
|
|
4
4
|
"description": "Hyperswitch SDK for React Native",
|
|
5
5
|
"main": "lib/commonjs/index.bundle.js",
|
|
6
6
|
"module": "lib/module/index.bundle.js",
|
|
@@ -59,13 +59,13 @@
|
|
|
59
59
|
],
|
|
60
60
|
"repository": {
|
|
61
61
|
"type": "git",
|
|
62
|
-
"url": "https://github.com/
|
|
62
|
+
"url": "https://github.com/juspay/react-native-hyperswitch",
|
|
63
63
|
"directory": "packages/react-native-hyperswitch"
|
|
64
64
|
},
|
|
65
65
|
"author": "Hyperswitch",
|
|
66
66
|
"license": "Apache-2.0",
|
|
67
67
|
"bugs": {
|
|
68
|
-
"url": "https://github.com/
|
|
68
|
+
"url": "https://github.com/juspay/react-native-hyperswitch"
|
|
69
69
|
},
|
|
70
70
|
"homepage": "https://hyperswitch.io",
|
|
71
71
|
"publishConfig": {
|
|
@@ -170,8 +170,12 @@
|
|
|
170
170
|
"javaPackageName": "com.hyperswitchsdkreactnative"
|
|
171
171
|
},
|
|
172
172
|
"ios": {
|
|
173
|
+
"modulesProvider": {
|
|
174
|
+
"NativeHyperswitchModule": "NativeHyperswitchModule"
|
|
175
|
+
},
|
|
173
176
|
"componentProvider": {
|
|
174
|
-
"ApplePayView": "ApplePayView"
|
|
177
|
+
"ApplePayView": "ApplePayView",
|
|
178
|
+
"RCTNativePaymentElement": "NativePaymentElementView"
|
|
175
179
|
}
|
|
176
180
|
}
|
|
177
181
|
},
|
|
@@ -75,11 +75,13 @@ export async function presentPaymentSheetWithPayload(
|
|
|
75
75
|
}
|
|
76
76
|
setSheetPresented(true);
|
|
77
77
|
try {
|
|
78
|
+
console.log('Presenting payment sheet with payload:', payload);
|
|
78
79
|
const raw = await NativeHyperswitchModule.presentPaymentSheet({
|
|
79
80
|
hyperswitchConfig: payload.hyperswitchConfig,
|
|
80
81
|
paymentSessionConfig: payload.paymentSessionConfig,
|
|
81
82
|
configuration: payload.configuration,
|
|
82
83
|
});
|
|
84
|
+
console.log('Native response from presentPaymentSheet:', raw);
|
|
83
85
|
return mapNativeResponseToPaymentResult(raw);
|
|
84
86
|
} finally {
|
|
85
87
|
setSheetPresented(false);
|
|
@@ -22,9 +22,9 @@ export interface Spec extends TurboModule {
|
|
|
22
22
|
customEndpoints: CustomEndpoints
|
|
23
23
|
): Promise<string>;
|
|
24
24
|
|
|
25
|
-
presentPaymentSheet(params:
|
|
25
|
+
presentPaymentSheet(params: Object): Promise<string>;
|
|
26
26
|
|
|
27
|
-
getCustomerSavedPaymentMethods(params?:
|
|
27
|
+
getCustomerSavedPaymentMethods(params?: Object): Promise<string>;
|
|
28
28
|
|
|
29
29
|
getCustomerLastUsedPaymentMethodData(): Promise<string>;
|
|
30
30
|
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
#import "HyperswitchSdkReactNative.h"
|
|
2
|
-
#import <React/RCTComponent.h>
|
|
3
|
-
#import <memory>
|
|
4
|
-
#if __has_include("HyperswitchSdkReactNative-Swift.h")
|
|
5
|
-
#import "HyperswitchSdkReactNative-Swift.h"
|
|
6
|
-
#else
|
|
7
|
-
// When using use_frameworks! :linkage => :static in Podfile
|
|
8
|
-
#import <HyperswitchSdkReactNative/HyperswitchSdkReactNative-Swift.h>
|
|
9
|
-
#endif
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
@implementation HyperswitchSdkReactNative
|
|
13
|
-
|
|
14
|
-
@synthesize viewRegistry_DEPRECATED = _viewRegistry_DEPRECATED;
|
|
15
|
-
|
|
16
|
-
RCT_EXPORT_MODULE()
|
|
17
|
-
|
|
18
|
-
RCT_EXPORT_METHOD(initialise:(nonnull NSDictionary *)config
|
|
19
|
-
resolve:(nonnull RCTPromiseResolveBlock)resolve
|
|
20
|
-
reject:(nonnull RCTPromiseRejectBlock)reject) {
|
|
21
|
-
NSString *publishableKey = [config[@"publishableKey"] isKindOfClass:NSString.class] ? config[@"publishableKey"] : nil;
|
|
22
|
-
NSString *profileId = [config[@"profileId"] isKindOfClass:NSString.class] ? config[@"profileId"] : nil;
|
|
23
|
-
NSDictionary *customEndpoints = [config[@"customEndpoints"] isKindOfClass:NSDictionary.class] ? config[@"customEndpoints"] : nil;
|
|
24
|
-
NSDictionary *overrideEndpoints = [customEndpoints[@"overrideEndpoints"] isKindOfClass:NSDictionary.class] ? customEndpoints[@"overrideEndpoints"] : nil;
|
|
25
|
-
NSString *customBackendUrl = [overrideEndpoints[@"customBackendEndpoint"] isKindOfClass:NSString.class] ? overrideEndpoints[@"customBackendEndpoint"] : nil;
|
|
26
|
-
NSString *customLogUrl = [overrideEndpoints[@"customLoggingEndpoint"] isKindOfClass:NSString.class] ? overrideEndpoints[@"customLoggingEndpoint"] : nil;
|
|
27
|
-
|
|
28
|
-
NSMutableDictionary *customParams = [NSMutableDictionary dictionary];
|
|
29
|
-
if (profileId != nil) {
|
|
30
|
-
customParams[@"profileId"] = profileId;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
[[self hyperswitchModule] initialiseWithPublishableKey:publishableKey customBackendUrl:customBackendUrl customLogUrl:customLogUrl customParams:customParams resolve:resolve reject:reject];
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
RCT_EXPORT_METHOD(initPaymentSession:(nonnull NSString *)instanceHandle
|
|
37
|
-
sdkAuthorization:(nonnull NSString *)sdkAuthorization
|
|
38
|
-
resolve:(nonnull RCTPromiseResolveBlock)resolve
|
|
39
|
-
reject:(nonnull RCTPromiseRejectBlock)reject) {
|
|
40
|
-
[[self hyperswitchModule] initPaymentSession:instanceHandle sdkAuthorization:sdkAuthorization resolve:resolve reject:reject];
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
RCT_EXPORT_METHOD(presentPaymentSheet:(nonnull NSDictionary *)configuration
|
|
44
|
-
resolve:(nonnull RCTPromiseResolveBlock)resolve
|
|
45
|
-
reject:(nonnull RCTPromiseRejectBlock)reject)
|
|
46
|
-
{
|
|
47
|
-
[[self hyperswitchModule] presentPaymentSheet:configuration resolve:resolve reject:reject];
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
#pragma mark - Headless Payment Methods
|
|
51
|
-
|
|
52
|
-
RCT_EXPORT_METHOD(getCustomerSavedPaymentMethods:(nullable NSDictionary *)options
|
|
53
|
-
resolve:(RCTPromiseResolveBlock)resolve
|
|
54
|
-
reject:(RCTPromiseRejectBlock)reject)
|
|
55
|
-
{
|
|
56
|
-
[[self hyperswitchModule] getCustomerSavedPaymentMethods:options resolve:resolve reject:reject];
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
RCT_EXPORT_METHOD(getCustomerDefaultSavedPaymentMethodData:(RCTPromiseResolveBlock)resolve
|
|
60
|
-
reject:(RCTPromiseRejectBlock)reject)
|
|
61
|
-
{
|
|
62
|
-
[[self hyperswitchModule] getCustomerDefaultSavedPaymentMethodDataWithResolve:resolve reject:reject];
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
RCT_EXPORT_METHOD(getCustomerLastUsedPaymentMethodData:(RCTPromiseResolveBlock)resolve
|
|
66
|
-
reject:(RCTPromiseRejectBlock)reject)
|
|
67
|
-
{
|
|
68
|
-
[[self hyperswitchModule] getCustomerLastUsedPaymentMethodDataWithResolve:resolve reject:reject];
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
RCT_EXPORT_METHOD(confirmWithCustomerDefaultPaymentMethod:(nullable NSString *)cvcWidgetReactTag
|
|
72
|
-
resolve:(RCTPromiseResolveBlock)resolve
|
|
73
|
-
reject:(RCTPromiseRejectBlock)reject)
|
|
74
|
-
{
|
|
75
|
-
[[self hyperswitchModule] confirmWithCustomerDefaultPaymentMethod:cvcWidgetReactTag resolve:resolve reject:reject];
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
RCT_EXPORT_METHOD(confirmWithCustomerLastUsedPaymentMethod:(nullable NSString *)cvcWidgetReactTag
|
|
79
|
-
resolve:(RCTPromiseResolveBlock)resolve
|
|
80
|
-
reject:(RCTPromiseRejectBlock)reject)
|
|
81
|
-
{
|
|
82
|
-
[[self hyperswitchModule] confirmWithCustomerLastUsedPaymentMethod:cvcWidgetReactTag resolve:resolve reject:reject];
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
RCT_EXPORT_METHOD(confirmWithCustomerPaymentToken:(nonnull NSString *)paymentToken
|
|
86
|
-
resolve:(RCTPromiseResolveBlock)resolve
|
|
87
|
-
reject:(RCTPromiseRejectBlock)reject)
|
|
88
|
-
{
|
|
89
|
-
[[self hyperswitchModule] confirmWithCustomerPaymentToken:paymentToken resolve:resolve reject:reject];
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
RCT_EXPORT_METHOD(updateIntent:(nonnull NSString *)sdkAuthorization
|
|
93
|
-
resolve:(RCTPromiseResolveBlock)resolve
|
|
94
|
-
reject:(RCTPromiseRejectBlock)reject)
|
|
95
|
-
{
|
|
96
|
-
[[self hyperswitchModule] updateIntent:sdkAuthorization resolve:resolve reject:reject];
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
|
|
100
|
-
(const facebook::react::ObjCTurboModule::InitParams &)params
|
|
101
|
-
{
|
|
102
|
-
return std::make_shared<facebook::react::NativeHyperswitchSdkReactNativeSpecJSI>(params);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
+ (BOOL)requiresMainQueueSetup
|
|
106
|
-
{
|
|
107
|
-
return YES;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
- (dispatch_queue_t)methodQueue
|
|
111
|
-
{
|
|
112
|
-
return dispatch_get_main_queue();
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
- (HyperswitchModule *)hyperswitchModule
|
|
116
|
-
{
|
|
117
|
-
HyperswitchModule.shared.viewRegistry_DEPRECATED = self.viewRegistry_DEPRECATED;
|
|
118
|
-
return HyperswitchModule.shared;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
@end
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
#import <React/RCTEventEmitter.h>
|
|
2
|
-
|
|
3
|
-
@interface RCT_EXTERN_MODULE(HyperModule, RCTEventEmitter)
|
|
4
|
-
|
|
5
|
-
RCT_EXTERN_METHOD(sendMessageToNative: (NSString)rnMessage)
|
|
6
|
-
RCT_EXTERN_METHOD(exitPaymentsheet: (nonnull NSNumber *)reactTag :(NSString)rnMessage :(BOOL)reset)
|
|
7
|
-
RCT_EXTERN_METHOD(exitPaymentMethodManagement: (nonnull NSNumber *)reactTag :(NSString)rnMessage :(BOOL)reset)
|
|
8
|
-
RCT_EXTERN_METHOD(exitCardForm: (NSString)rnMessage)
|
|
9
|
-
RCT_EXTERN_METHOD(launchWidgetPaymentSheet: (NSDictionary) rnMessage :(RCTResponseSenderBlock)rnCallback)
|
|
10
|
-
RCT_EXTERN_METHOD(onAddPaymentMethod: (NSString)rnMessage)
|
|
11
|
-
RCT_EXTERN_METHOD(exitWidgetPaymentsheet: (nonnull NSNumber *)reactTag :(NSString)rnMessage :(BOOL)reset)
|
|
12
|
-
RCT_EXTERN_METHOD(launchApplePay: (NSString)rnMessage :(RCTResponseSenderBlock)rnCallback)
|
|
13
|
-
RCT_EXTERN_METHOD(startApplePay: (NSString)rnMessage :(RCTResponseSenderBlock)startCallback)
|
|
14
|
-
RCT_EXTERN_METHOD(presentApplePay: (NSString)rnMessage :(RCTResponseSenderBlock)presentCallback)
|
|
15
|
-
RCT_EXTERN_METHOD(notifyWidgetPaymentResult: (nonnull NSNumber *)rootTag :(NSString)rnMessage)
|
|
16
|
-
RCT_EXTERN_METHOD(emitPaymentEvent: (nonnull NSNumber *)rootTag :(NSString)eventType :(NSDictionary)payload)
|
|
17
|
-
RCT_EXTERN_METHOD(onUpdateIntentEvent: (nonnull NSNumber *)rootTag :(NSString)type :(NSString)result)
|
|
18
|
-
RCT_EXTERN_METHOD(onPaymentConfirmButtonClick: (nonnull NSNumber *)rootTag :(NSString)payload :(RCTResponseSenderBlock)callback)
|
|
19
|
-
RCT_EXTERN_METHOD(openIframeBridge: (NSString)url :(nonnull NSNumber *)timeoutMs :(RCTResponseSenderBlock)callback)
|
|
20
|
-
|
|
21
|
-
+ (BOOL)requiresMainQueueSetup
|
|
22
|
-
{
|
|
23
|
-
return YES;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
- (dispatch_queue_t)methodQueue
|
|
27
|
-
{
|
|
28
|
-
return dispatch_get_main_queue();
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
@end
|
|
@@ -1,343 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// HyperModule.swift
|
|
3
|
-
// Hyperswitch
|
|
4
|
-
//
|
|
5
|
-
// Created by Harshit Srivastava on 07/03/24.
|
|
6
|
-
//
|
|
7
|
-
|
|
8
|
-
import Foundation
|
|
9
|
-
import React
|
|
10
|
-
|
|
11
|
-
@objc(HyperModule)
|
|
12
|
-
internal class HyperModule: RCTEventEmitter {
|
|
13
|
-
|
|
14
|
-
private let applePayPaymentHandler = ApplePayHandler()
|
|
15
|
-
private let expressCheckoutHandler = ExpressCheckoutLauncher()
|
|
16
|
-
private var presentCallback: RCTResponseSenderBlock? = nil
|
|
17
|
-
internal static var shared: HyperModule?
|
|
18
|
-
|
|
19
|
-
override init() {
|
|
20
|
-
super.init()
|
|
21
|
-
HyperModule.shared = self
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
@objc
|
|
25
|
-
internal override static func requiresMainQueueSetup() -> Bool {
|
|
26
|
-
return true
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
@objc
|
|
30
|
-
internal override func supportedEvents() -> [String] {
|
|
31
|
-
return ["confirm", "confirmEC", "triggerWidgetAction", "updateIntentInit", "updateIntentComplete"]
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
@objc
|
|
35
|
-
internal func confirm(data: [String: Any]) {
|
|
36
|
-
self.sendEvent(withName: "confirm", body: data)
|
|
37
|
-
}
|
|
38
|
-
// MARK: WIP
|
|
39
|
-
// @objc func confirmEC(data: [String: Any]) {
|
|
40
|
-
// self.sendEvent(withName: "confirmEC", body: data)
|
|
41
|
-
// }
|
|
42
|
-
|
|
43
|
-
@objc
|
|
44
|
-
private func sendMessageToNative(_ rnMessage: String) {}
|
|
45
|
-
|
|
46
|
-
@objc
|
|
47
|
-
private func launchWidgetPaymentSheet(_ request: NSMutableDictionary, _ callback: @escaping RCTResponseSenderBlock) {
|
|
48
|
-
expressCheckoutHandler.launchPaymentSheet(paymentResult: request, callBack: callback)
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
@objc
|
|
52
|
-
private func onAddPaymentMethod(_ rnMessage: String) {
|
|
53
|
-
PaymentMethodManagementWidget.onAddPaymentMethod?()
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
@objc
|
|
57
|
-
private func launchApplePay(_ rnMessage: String, _ rnCallback: @escaping RCTResponseSenderBlock) {
|
|
58
|
-
applePayPaymentHandler.startPayment(rnMessage: rnMessage, rnCallback: rnCallback, presentCallback: self.presentCallback)
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
@objc
|
|
62
|
-
private func startApplePay(_ rnMessage: String, _ rnCallback: @escaping RCTResponseSenderBlock) {
|
|
63
|
-
rnCallback([])
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
@objc
|
|
67
|
-
private func presentApplePay(_ rnMessage: String, _ rnCallback: @escaping RCTResponseSenderBlock) {
|
|
68
|
-
self.presentCallback = rnCallback
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
@objc
|
|
72
|
-
private func exitPaymentsheet(_ reactTag: NSNumber, _ rnMessage: String, _ reset: Bool) {
|
|
73
|
-
let result = paymentResult(from: rnMessage)
|
|
74
|
-
withPaymentSheet(reactTag) { vc, sheet in
|
|
75
|
-
sheet?.completion?(result)
|
|
76
|
-
vc?.dismiss(animated: false, completion: nil)
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
@objc
|
|
81
|
-
private func exitWidgetPaymentsheet(_ reactTag: NSNumber, _ rnMessage: String, _ reset: Bool) {
|
|
82
|
-
let result = paymentResult(from: rnMessage)
|
|
83
|
-
withWidget(reactTag) { w in
|
|
84
|
-
w.handleConfirmPaymentResponse(result)
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
private func paymentResult(from rnMessage: String) -> PaymentResult {
|
|
89
|
-
guard let data = rnMessage.data(using: .utf8) else {
|
|
90
|
-
return .failed(
|
|
91
|
-
error: NSError(
|
|
92
|
-
domain: "UNKNOWN_ERROR",
|
|
93
|
-
code: 0,
|
|
94
|
-
userInfo: ["message": "An error has occurred."]
|
|
95
|
-
)
|
|
96
|
-
)
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
do {
|
|
100
|
-
guard let jsonDictionary = try JSONSerialization.jsonObject(with: data, options: []) as? [String: String] else {
|
|
101
|
-
return .failed(
|
|
102
|
-
error: NSError(
|
|
103
|
-
domain: "UNKNOWN_ERROR",
|
|
104
|
-
code: 0,
|
|
105
|
-
userInfo: ["message": "An error has occurred."]
|
|
106
|
-
)
|
|
107
|
-
)
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
let status = jsonDictionary["status"]
|
|
111
|
-
|
|
112
|
-
if status == "success" || status == "succeeded" || status == "completed" {
|
|
113
|
-
return .completed(data: status ?? "success")
|
|
114
|
-
} else if status == "cancelled" || status == "canceled" {
|
|
115
|
-
return .canceled(data: status ?? "cancelled")
|
|
116
|
-
} else {
|
|
117
|
-
let error = NSError(
|
|
118
|
-
domain: (jsonDictionary["code"] ?? "") != "" ? jsonDictionary["code"]! : "UNKNOWN_ERROR",
|
|
119
|
-
code: 0,
|
|
120
|
-
userInfo: ["message": jsonDictionary["message"] ?? status ?? "An error has occurred."]
|
|
121
|
-
)
|
|
122
|
-
return .failed(error: error)
|
|
123
|
-
}
|
|
124
|
-
} catch {
|
|
125
|
-
return .failed(
|
|
126
|
-
error: NSError(
|
|
127
|
-
domain: "UNKNOWN_ERROR",
|
|
128
|
-
code: 0,
|
|
129
|
-
userInfo: ["message": "An error has occurred."]
|
|
130
|
-
)
|
|
131
|
-
)
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
@objc
|
|
136
|
-
private func exitPaymentMethodManagement(_ reactTag: NSNumber, _ rnMessage: String, _ reset: Bool) {
|
|
137
|
-
exitSheet(rnMessage)
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
@objc
|
|
141
|
-
private func notifyWidgetPaymentResult(_ rootTag: NSNumber, _ rnMessage: String) {
|
|
142
|
-
let result = paymentResult(from: rnMessage)
|
|
143
|
-
guard case .failed = result else { return }
|
|
144
|
-
withNativePaymentWidgetView(rootTag) { view in
|
|
145
|
-
view.handleConfirmPaymentNotification(result)
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
@objc
|
|
150
|
-
private func onUpdateIntentEvent(_ rootTag: NSNumber, _ type: String, _ result: String) {
|
|
151
|
-
withWidget(rootTag) { widget in
|
|
152
|
-
widget.handleUpdateIntentEvent(type: type, result: result)
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
@objc func emitPaymentEvent(_ rootTag: NSNumber, _ eventType: String, _ payload: NSDictionary) {
|
|
157
|
-
let map = (payload as? [String: Any]) ?? [:]
|
|
158
|
-
resolveSubscribingTarget(rootTag) { target in
|
|
159
|
-
if let widget = target as? PaymentWidget, widget.paymentEventListener != nil {
|
|
160
|
-
widget.dispatchPaymentEvent(type: eventType, payload: map)
|
|
161
|
-
} else if let cvc = target as? CVCWidget, cvc.paymentEventListener != nil {
|
|
162
|
-
cvc.dispatchPaymentEvent(type: eventType, payload: map)
|
|
163
|
-
} else if let sheet = target as? PaymentSheet, sheet.paymentEventListener != nil {
|
|
164
|
-
sheet.dispatchPaymentEvent(type: eventType, payload: map)
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
@objc
|
|
170
|
-
private func exitCardForm(_ rnMessage: String) {
|
|
171
|
-
var response: String?
|
|
172
|
-
var error: NSError?
|
|
173
|
-
|
|
174
|
-
if let data = rnMessage.data(using: .utf8) {
|
|
175
|
-
do {
|
|
176
|
-
if let jsonDictionary = try JSONSerialization.jsonObject(with: data, options: []) as? [String: String] {
|
|
177
|
-
let status = jsonDictionary["status"]
|
|
178
|
-
|
|
179
|
-
if status == "failed" || status == "requires_payment_method" {
|
|
180
|
-
error = NSError(
|
|
181
|
-
domain: (jsonDictionary["code"] ?? "") != "" ? jsonDictionary["code"]! : "UNKNOWN_ERROR",
|
|
182
|
-
code: 0,
|
|
183
|
-
userInfo: ["message": jsonDictionary["message"] ?? "An error has occurred."]
|
|
184
|
-
)
|
|
185
|
-
} else {
|
|
186
|
-
response = status
|
|
187
|
-
}
|
|
188
|
-
RNViewManager.sharedInstance.responseHandler?.didReceiveResponse(response: response, error: error)
|
|
189
|
-
} else {
|
|
190
|
-
RNViewManager.sharedInstance.responseHandler?.didReceiveResponse(
|
|
191
|
-
response: "failed",
|
|
192
|
-
error: NSError(domain: "UNKNOWN_ERROR", code: 0, userInfo: ["message": "An error has occurred."])
|
|
193
|
-
)
|
|
194
|
-
}
|
|
195
|
-
} catch {
|
|
196
|
-
RNViewManager.sharedInstance.responseHandler?.didReceiveResponse(
|
|
197
|
-
response: "failed",
|
|
198
|
-
error: NSError(domain: "UNKNOWN_ERROR", code: 0, userInfo: ["message": "An error has occurred."])
|
|
199
|
-
)
|
|
200
|
-
}
|
|
201
|
-
} else {
|
|
202
|
-
RNViewManager.sharedInstance.responseHandler?.didReceiveResponse(
|
|
203
|
-
response: "failed",
|
|
204
|
-
error: NSError(domain: "UNKNOWN_ERROR", code: 0, userInfo: ["message": "An error has occurred."])
|
|
205
|
-
)
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
@objc
|
|
210
|
-
private func exitSheet(_ rnMessage: String) {
|
|
211
|
-
var response: String?
|
|
212
|
-
var error: NSError?
|
|
213
|
-
|
|
214
|
-
if let data = rnMessage.data(using: .utf8) {
|
|
215
|
-
do {
|
|
216
|
-
if let jsonDictionary = try JSONSerialization.jsonObject(with: data, options: []) as? [String: String] {
|
|
217
|
-
let status = jsonDictionary["status"]
|
|
218
|
-
|
|
219
|
-
if status == "failed" || status == "requires_payment_method" {
|
|
220
|
-
error = NSError(
|
|
221
|
-
domain: (jsonDictionary["code"] ?? "") != "" ? jsonDictionary["code"]! : "UNKNOWN_ERROR",
|
|
222
|
-
code: 0,
|
|
223
|
-
userInfo: ["message": jsonDictionary["message"] ?? "An error has occurred."]
|
|
224
|
-
)
|
|
225
|
-
} else {
|
|
226
|
-
response = status
|
|
227
|
-
}
|
|
228
|
-
RNViewManager.sharedInstance.responseHandler?.didReceiveResponse(response: response, error: error)
|
|
229
|
-
} else {
|
|
230
|
-
RNViewManager.sharedInstance.responseHandler?.didReceiveResponse(
|
|
231
|
-
response: "failed",
|
|
232
|
-
error: NSError(domain: "UNKNOWN_ERROR", code: 0, userInfo: ["message": "An error has occurred."])
|
|
233
|
-
)
|
|
234
|
-
}
|
|
235
|
-
} catch {
|
|
236
|
-
RNViewManager.sharedInstance.responseHandler?.didReceiveResponse(
|
|
237
|
-
response: "failed",
|
|
238
|
-
error: NSError(domain: "UNKNOWN_ERROR", code: 0, userInfo: ["message": "An error has occurred."])
|
|
239
|
-
)
|
|
240
|
-
}
|
|
241
|
-
} else {
|
|
242
|
-
RNViewManager.sharedInstance.responseHandler?.didReceiveResponse(
|
|
243
|
-
response: "failed",
|
|
244
|
-
error: NSError(domain: "UNKNOWN_ERROR", code: 0, userInfo: ["message": "An error has occurred."])
|
|
245
|
-
)
|
|
246
|
-
}
|
|
247
|
-
DispatchQueue.main.async {
|
|
248
|
-
if let view = RNViewManager.sharedInstance.rootView {
|
|
249
|
-
let reactNativeVC: UIViewController? = view.reactViewController()
|
|
250
|
-
reactNativeVC?.dismiss(animated: false, completion: nil)
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
@objc
|
|
256
|
-
private func onPaymentConfirmButtonClick(_ rootTag: NSNumber, _ payload: String, _ callback: @escaping RCTResponseSenderBlock) {
|
|
257
|
-
resolveSubscribingTarget(rootTag) { target in
|
|
258
|
-
if let widget = target as? PaymentWidget {
|
|
259
|
-
widget.handleShouldProceedWithPayment(payload: payload) { shouldProceed in
|
|
260
|
-
callback([shouldProceed])
|
|
261
|
-
}
|
|
262
|
-
} else if let sheet = target as? PaymentSheet {
|
|
263
|
-
sheet.handleShouldProceedWithPayment(payload: payload) { shouldProceed in
|
|
264
|
-
callback([shouldProceed])
|
|
265
|
-
}
|
|
266
|
-
} else {
|
|
267
|
-
callback([true])
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
@objc
|
|
273
|
-
private func openIframeBridge(_ url: String, _ timeoutMs: NSNumber, _ callback: @escaping RCTResponseSenderBlock) {
|
|
274
|
-
DispatchQueue.main.async {
|
|
275
|
-
let headlessWebView = HeadlessWebView(url: url, timeoutMs: timeoutMs, callback: callback)
|
|
276
|
-
headlessWebView.startFlow()
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
private func withWidget(_ rootTag: NSNumber, _ block: @escaping (PaymentWidget) -> Void) {
|
|
281
|
-
RCTGetUIManagerQueue().async {
|
|
282
|
-
self.bridge.uiManager.addUIBlock { _, viewRegistry in
|
|
283
|
-
guard let view = viewRegistry?[rootTag] else { return }
|
|
284
|
-
var current: UIView? = view
|
|
285
|
-
while let v = current {
|
|
286
|
-
if let widget = v as? PaymentWidget {
|
|
287
|
-
block(widget)
|
|
288
|
-
return
|
|
289
|
-
}
|
|
290
|
-
current = v.superview
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
private func withNativePaymentWidgetView(_ rootTag: NSNumber, _ block: @escaping (NativePaymentWidgetView) -> Void) {
|
|
297
|
-
RCTGetUIManagerQueue().async {
|
|
298
|
-
self.bridge.uiManager.addUIBlock { _, viewRegistry in
|
|
299
|
-
guard let view = viewRegistry?[rootTag] else { return }
|
|
300
|
-
var current: UIView? = view
|
|
301
|
-
while let v = current {
|
|
302
|
-
if let nativeWidget = v as? NativePaymentWidgetView {
|
|
303
|
-
block(nativeWidget)
|
|
304
|
-
return
|
|
305
|
-
}
|
|
306
|
-
current = v.superview
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
private func resolveSubscribingTarget(_ rootTag: NSNumber, _ block: @escaping (AnyObject?) -> Void) {
|
|
313
|
-
RCTGetUIManagerQueue().async {
|
|
314
|
-
self.bridge.uiManager.addUIBlock { _, viewRegistry in
|
|
315
|
-
guard let view = viewRegistry?[rootTag] else {
|
|
316
|
-
DispatchQueue.main.async { block(nil) }
|
|
317
|
-
return
|
|
318
|
-
}
|
|
319
|
-
var current: UIView? = view
|
|
320
|
-
while let v = current {
|
|
321
|
-
if v is PaymentWidget || v is CVCWidget {
|
|
322
|
-
DispatchQueue.main.async { block(v) }
|
|
323
|
-
return
|
|
324
|
-
}
|
|
325
|
-
current = v.superview
|
|
326
|
-
}
|
|
327
|
-
let sheet = (view.reactViewController() as? HyperUIViewController)?.paymentSheet
|
|
328
|
-
DispatchQueue.main.async { block(sheet) }
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
private func withPaymentSheet(_ rootTag: NSNumber, _ block: @escaping (UIViewController?, PaymentSheet?) -> Void) {
|
|
334
|
-
RCTGetUIManagerQueue().async {
|
|
335
|
-
self.bridge.uiManager.addUIBlock { _, viewRegistry in
|
|
336
|
-
let view = viewRegistry?[rootTag]
|
|
337
|
-
let vc = view?.reactViewController() as? HyperUIViewController
|
|
338
|
-
let sheet = vc?.paymentSheet
|
|
339
|
-
DispatchQueue.main.async { block(vc, sheet) }
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
}
|