react-native-hyperswitch-dev-sdk 0.4.2 → 0.4.4

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.
Files changed (34) hide show
  1. package/HyperswitchSdkReactNative.podspec +4 -0
  2. package/android/build.gradle +0 -6
  3. package/android/hyperswitch_autolinking.gradle +1 -1
  4. package/ios/Modules/ReactNative/HyperModule.h +25 -0
  5. package/ios/Modules/ReactNative/HyperModule.mm +169 -0
  6. package/ios/Modules/ReactNative/HyperswitchModule.swift +223 -165
  7. package/ios/Modules/ReactNative/NativeHyperswitchModule.mm +17 -12
  8. package/ios/Modules/ReactNative/NativeHyperswitchModuleImpl.swift +18 -7
  9. package/ios/Modules/ReactNative/NativePaymentElementModule.mm +122 -122
  10. package/ios/Views/Fabric/NativePaymentElementView.mm +8 -0
  11. package/ios/Views/Native/NativePaymentWidget.swift +26 -22
  12. package/ios/hyperswitchSDK/Core/HyperCVCWidget/CVCWidget.swift +3 -2
  13. package/ios/hyperswitchSDK/Core/HyperPaymentCardTextField/PaymentHandler.swift +1 -1
  14. package/ios/hyperswitchSDK/Core/HyperPaymentSheet/PaymentSheetView+UIKit.swift +79 -13
  15. package/ios/hyperswitchSDK/Core/HyperPaymentSheet/PaymentSheetView.swift +2 -2
  16. package/ios/hyperswitchSDK/Core/HyperPaymentWidget/PaymentWidget.swift +5 -4
  17. package/ios/hyperswitchSDK/Core/HyperSession/PaymentSession+UIKit.swift +14 -0
  18. package/ios/hyperswitchSDK/Core/NativeModule/{HyperModule.swift → HyperModuleImpl.swift} +156 -113
  19. package/ios/hyperswitchSDK/Core/NativeModule/RNHeadlessManager.swift +58 -22
  20. package/ios/hyperswitchSDK/Core/NativeModule/RNViewManager.swift +84 -29
  21. package/ios/hyperswitchSDK/Core/NativeModule/hyper-Bridging-Header.h +2 -0
  22. package/ios/hyperswitchSDK/Public/RNBridgeFactory.h +28 -0
  23. package/ios/hyperswitchSDK/Public/RNBridgeFactory.mm +167 -0
  24. package/ios/hyperswitchSDK/Shared/PaymentSheet.swift +1 -1
  25. package/lib/commonjs/index.bundle.js +1 -1
  26. package/lib/commonjs/index.bundle.js.map +1 -1
  27. package/lib/module/index.bundle.js +1 -1
  28. package/lib/module/index.bundle.js.map +1 -1
  29. package/package.json +6 -2
  30. package/src/context/PaymentSession.ts +2 -0
  31. package/src/specs/NativeHyperswitchModule.ts +2 -2
  32. package/ios/Modules/ReactNative/HyperswitchSdkReactNative.h +0 -5
  33. package/ios/Modules/ReactNative/HyperswitchSdkReactNative.mm +0 -121
  34. package/ios/hyperswitchSDK/Core/NativeModule/HyperModule.m +0 -31
@@ -7,6 +7,8 @@
7
7
  #import <React/RCTBundleURLProvider.h>
8
8
  #import <React/RCTViewManager.h>
9
9
  #import <React/RCTUIManager.h>
10
+ // Factory for the SDK's internal React Native surface, usable from Swift.
11
+ #import "RNBridgeFactory.h"
10
12
  // Shared view registry — exposes NativePaymentWidgetViewRegistry to Swift so that
11
13
  // the old-arch NativePaymentWidget view-manager commands can fall back to Fabric views.
12
14
  #import "NativePaymentWidgetViewRegistry.h"
@@ -0,0 +1,28 @@
1
+ //
2
+ // RNBridgeFactory.h
3
+ // HyperswitchSdkReactNative
4
+ //
5
+ // Factory for the SDK's internal React Native surface. On React Native 0.79+
6
+ // with the New Architecture enabled this uses RCTRootViewFactory so that core
7
+ // TurboModules (DeviceInfo, ExceptionsManager, etc.) and codegen-generated
8
+ // third-party modules are registered in the secondary bridge.
9
+ //
10
+
11
+ #import <UIKit/UIKit.h>
12
+
13
+ @class RCTBridge;
14
+
15
+ NS_ASSUME_NONNULL_BEGIN
16
+
17
+ @interface RNBridgeFactory : NSObject
18
+
19
+ + (instancetype)sharedInstance;
20
+
21
+ - (UIView *)hyperswitchViewForModuleName:(NSString *)moduleName
22
+ initialProperties:(nullable NSDictionary *)initialProperties;
23
+
24
+ @property (nonatomic, readonly, nullable) RCTBridge *bridge;
25
+
26
+ @end
27
+
28
+ NS_ASSUME_NONNULL_END
@@ -0,0 +1,167 @@
1
+ //
2
+ // RNBridgeFactory.mm
3
+ // HyperswitchSdkReactNative
4
+ //
5
+
6
+ #import "RNBridgeFactory.h"
7
+
8
+ #import <React/RCTBridge.h>
9
+ #import <React/RCTBundleURLProvider.h>
10
+ #import <React/RCTLog.h>
11
+ #import <React/RCTRootView.h>
12
+ #import <React-RCTAppDelegate/RCTRootViewFactory.h>
13
+ #import <React/CoreModulesPlugins.h>
14
+
15
+ #if __has_include(<React-RCTAppDelegate/RCTDependencyProvider.h>)
16
+ #import <React-RCTAppDelegate/RCTDependencyProvider.h>
17
+ #endif
18
+
19
+ #if __has_include(<ReactAppDependencyProvider/RCTAppDependencyProvider.h>)
20
+ #import <ReactAppDependencyProvider/RCTAppDependencyProvider.h>
21
+ #endif
22
+
23
+ #if __has_include(<ReactCodegen/RCTModuleProviders.h>)
24
+ #import <ReactCodegen/RCTModuleProviders.h>
25
+ #endif
26
+
27
+ #if __has_include(<react/nativemodule/defaults/DefaultTurboModules.h>)
28
+ #include <react/nativemodule/defaults/DefaultTurboModules.h>
29
+ #endif
30
+
31
+ #if __has_include(<ReactCommon/RCTHost.h>)
32
+ #import <ReactCommon/RCTHost.h>
33
+ #endif
34
+
35
+ @interface RNBridgeFactory () <RCTBridgeDelegate, RCTTurboModuleManagerDelegate, RCTHostDelegate>
36
+
37
+ @property (nonatomic, strong, nullable) RCTRootViewFactory *factory;
38
+ @property (nonatomic, strong, nullable) id<RCTDependencyProvider> dependencyProvider;
39
+
40
+ @end
41
+
42
+ @implementation RNBridgeFactory
43
+
44
+ + (instancetype)sharedInstance {
45
+ static RNBridgeFactory *instance = nil;
46
+ static dispatch_once_t onceToken;
47
+ dispatch_once(&onceToken, ^{
48
+ instance = [[self alloc] init];
49
+ });
50
+ return instance;
51
+ }
52
+
53
+ - (instancetype)init {
54
+ self = [super init];
55
+ if (!self) {
56
+ return nil;
57
+ }
58
+
59
+ if (![self isModernFactoryAvailable]) {
60
+ return self;
61
+ }
62
+
63
+ self.dependencyProvider = [[RCTAppDependencyProvider alloc] init];
64
+
65
+ NSURL *bundleURL = [self sourceURLForBridge:nil];
66
+
67
+ BOOL newArch = RCTIsNewArchEnabled();
68
+ RCTRootViewFactoryConfiguration *configuration =
69
+ [[RCTRootViewFactoryConfiguration alloc] initWithBundleURL:bundleURL
70
+ newArchEnabled:newArch
71
+ turboModuleEnabled:newArch || RCTTurboModuleEnabled()
72
+ bridgelessEnabled:NO];
73
+
74
+ configuration.sourceURLForBridge = ^NSURL *(RCTBridge *bridge) {
75
+ return [RNBridgeFactory.sharedInstance sourceURLForBridge:bridge];
76
+ };
77
+
78
+ self.factory = [[RCTRootViewFactory alloc] initWithTurboModuleDelegate:self
79
+ hostDelegate:self
80
+ configuration:configuration];
81
+ return self;
82
+ }
83
+
84
+ - (BOOL)isModernFactoryAvailable {
85
+ return NSClassFromString(@"RCTRootViewFactory") != nil
86
+ && NSClassFromString(@"RCTAppDependencyProvider") != nil
87
+ && NSClassFromString(@"RCTDependencyProvider") != nil;
88
+ }
89
+
90
+ - (nullable RCTBridge *)bridge {
91
+ return self.factory.bridge;
92
+ }
93
+
94
+ - (UIView *)hyperswitchViewForModuleName:(NSString *)moduleName
95
+ initialProperties:(nullable NSDictionary *)initialProperties {
96
+ if (self.factory) {
97
+ return [self.factory viewWithModuleName:moduleName
98
+ initialProperties:initialProperties
99
+ launchOptions:nil];
100
+ }
101
+
102
+ return [[RCTRootView alloc] initWithBridge:[[RCTBridge alloc] initWithDelegate:self launchOptions:nil]
103
+ moduleName:moduleName
104
+ initialProperties:initialProperties];
105
+ }
106
+
107
+ #pragma mark - RCTBridgeDelegate
108
+
109
+ - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge {
110
+ NSString *source = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"HyperswitchSource"];
111
+
112
+ if ([source isEqualToString:@"LocalHosted"]) {
113
+ return [RCTBundleURLProvider.sharedSettings jsBundleURLForBundleRoot:@"index"];
114
+ }
115
+
116
+ if ([source isEqualToString:@"LocalBundle"]) {
117
+ return [[NSBundle mainBundle] URLForResource:@"hyperswitch" withExtension:@"bundle"];
118
+ }
119
+
120
+ return [[NSBundle bundleForClass:[self class]] URLForResource:@"hyperswitch" withExtension:@"bundle"];
121
+ }
122
+
123
+ #pragma mark - RCTTurboModuleManagerDelegate
124
+
125
+ - (Class)getModuleClassFromName:(const char *)name {
126
+ #if RN_DISABLE_OSS_PLUGIN_HEADER
127
+ Class klass = NSClassFromString(@"RCTTurboModulePluginClassProvider");
128
+ if (klass) {
129
+ return ((Class (*)(const char *))[klass methodForSelector:NSSelectorFromString(@"pluginClassProvider:")])(name);
130
+ }
131
+ return nil;
132
+ #else
133
+ return RCTCoreModulesClassProvider(name);
134
+ #endif
135
+ }
136
+
137
+ - (nullable id<RCTModuleProvider>)getModuleProvider:(const char *)name {
138
+ if (!self.dependencyProvider) {
139
+ return nil;
140
+ }
141
+
142
+ NSDictionary<NSString *, id<RCTModuleProvider>> *providers = [self.dependencyProvider moduleProviders];
143
+ return providers[[NSString stringWithUTF8String:name]];
144
+ }
145
+
146
+ #ifdef __cplusplus
147
+ - (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:(const std::string &)name
148
+ jsInvoker:(std::shared_ptr<facebook::react::CallInvoker>)jsInvoker {
149
+ #if __has_include(<react/nativemodule/defaults/DefaultTurboModules.h>)
150
+ return facebook::react::DefaultTurboModules::getTurboModule(name, jsInvoker);
151
+ #else
152
+ return nullptr;
153
+ #endif
154
+ }
155
+ #endif
156
+
157
+ - (id<RCTTurboModule>)getModuleInstanceFromClass:(Class)moduleClass {
158
+ return [[moduleClass alloc] init];
159
+ }
160
+
161
+ #pragma mark - RCTHostDelegate
162
+
163
+ - (void)hostDidStart:(RCTHost *)host {
164
+ // no-op
165
+ }
166
+
167
+ @end
@@ -26,7 +26,7 @@ public class PaymentSheet {
26
26
 
27
27
  /// The configuration object that holds the settings for the payment sheet.
28
28
  internal let configuration: Configuration?
29
- internal var completion: ((PaymentResult) -> Void)?
29
+ internal var completion: ((String) -> Void)?
30
30
  internal var subscribedEvents: [String]?
31
31
  internal var paymentEventListener: PaymentEventListener?
32
32
  internal var shouldProceedWithPaymentCallback: ((PaymentRequestData, @escaping (Bool) -> Void) -> Void)?
@@ -1,2 +1,2 @@
1
- "use strict";var e=require("react-native");const t=e.TurboModuleRegistry.get("NativeHyperswitchModule")??e.NativeModules.NativeHyperswitchModule;function n(e,t,n={}){const{platformPublishableKey:a,...s}=e;return{hyperswitchConfig:s,paymentSessionConfig:t,configuration:n}}function a(e){const t=JSON.parse(e);if(t.billing&&"string"==typeof t.billing)try{t.billing=JSON.parse(t.billing)}catch{t.billing=null}return t}async function s(e,s,i){const r=n(e,s,i);return await t.getCustomerSavedPaymentMethods(r),{getCustomerLastUsedPaymentMethodData:async()=>a(await t.getCustomerLastUsedPaymentMethodData()),getCustomerDefaultSavedPaymentMethodData:async()=>a(await t.getCustomerDefaultSavedPaymentMethodData()),getCustomerSavedPaymentMethodData:async()=>a(await t.getCustomerSavedPaymentMethodData()),async confirmWithCustomerLastUsedPaymentMethod(e){await t.confirmWithCustomerLastUsedPaymentMethod()},async confirmWithCustomerDefaultPaymentMethod(e){await t.confirmWithCustomerDefaultPaymentMethod()}}}console.log("NativeHyperswitchModule",t);let i=!1;function r(e){i=e}let o=!1;function c(e){o=e}function u(e){switch(e){case"succeeded":case"completed":case"success":return"completed";case"cancelled":case"canceled":return"canceled";default:return"failed"}}function l(e){const t=function(e){if("object"==typeof e&&null!==e)return e;try{return JSON.parse(e)}catch{return{status:"failed",message:String(e)}}}(e);return{type:u(t.status),message:t.message}}async function y(e){if(i)return{type:"failed",message:"SDK is reloading. Please wait for initialisation to complete before presenting the payment sheet."};if(o)return{type:"canceled",message:"A payment sheet is already presented."};c(!0);try{return l(await t.presentPaymentSheet({hyperswitchConfig:e.hyperswitchConfig,paymentSessionConfig:e.paymentSessionConfig,configuration:e.configuration}))}finally{c(!1)}}async function m(e){}function d(e,t){return{presentPaymentSheet:async a=>y(n(e,t,a)),async confirmPayment(e,t){},getCustomerSavedPaymentMethods:async n=>s(e,t,n),updateIntent:m}}function f(e){return r(!0),t.initialise(e.publishableKey,e.platformPublishableKey??"",e.profileId??"",e.environment??"PROD",e.customEndpoints??{}).then(()=>(r(!1),{publishableKey:e.publishableKey,async initPaymentSession(t){return a=e,i=t,{presentPaymentSheet:async e=>y(n(a,i,e)),getCustomerSavedPaymentMethods:async e=>s(a,i,e),updateIntent:m};var a,i},elements:async t=>({...d(e,t)})})).catch(e=>{throw r(!1),console.error("Error initializing Hyperswitch SDK:",e),e})}const h={init:f};exports.Hyperswitch=h,exports.loadHyper=f;
1
+ "use strict";var e=require("react-native");const t=e.TurboModuleRegistry.get("NativeHyperswitchModule")??e.NativeModules.NativeHyperswitchModule;function n(e,t,n={}){const{platformPublishableKey:a,...s}=e;return{hyperswitchConfig:s,paymentSessionConfig:t,configuration:n}}function a(e){const t=JSON.parse(e);if(t.billing&&"string"==typeof t.billing)try{t.billing=JSON.parse(t.billing)}catch{t.billing=null}return t}async function s(e,s,i){const o=n(e,s,i);return await t.getCustomerSavedPaymentMethods(o),{getCustomerLastUsedPaymentMethodData:async()=>a(await t.getCustomerLastUsedPaymentMethodData()),getCustomerDefaultSavedPaymentMethodData:async()=>a(await t.getCustomerDefaultSavedPaymentMethodData()),getCustomerSavedPaymentMethodData:async()=>a(await t.getCustomerSavedPaymentMethodData()),async confirmWithCustomerLastUsedPaymentMethod(e){await t.confirmWithCustomerLastUsedPaymentMethod()},async confirmWithCustomerDefaultPaymentMethod(e){await t.confirmWithCustomerDefaultPaymentMethod()}}}console.log("NativeHyperswitchModule",t);let i=!1;function o(e){i=e}let r=!1;function c(e){r=e}function u(e){switch(e){case"succeeded":case"completed":case"success":return"completed";case"cancelled":case"canceled":return"canceled";default:return"failed"}}function l(e){const t=function(e){if("object"==typeof e&&null!==e)return e;try{return JSON.parse(e)}catch{return{status:"failed",message:String(e)}}}(e);return{type:u(t.status),message:t.message}}async function y(e){if(i)return{type:"failed",message:"SDK is reloading. Please wait for initialisation to complete before presenting the payment sheet."};if(r)return{type:"canceled",message:"A payment sheet is already presented."};c(!0);try{console.log("Presenting payment sheet with payload:",e);const n=await t.presentPaymentSheet({hyperswitchConfig:e.hyperswitchConfig,paymentSessionConfig:e.paymentSessionConfig,configuration:e.configuration});return console.log("Native response from presentPaymentSheet:",n),l(n)}finally{c(!1)}}async function m(e){}function d(e,t){return{presentPaymentSheet:async a=>y(n(e,t,a)),async confirmPayment(e,t){},getCustomerSavedPaymentMethods:async n=>s(e,t,n),updateIntent:m}}function h(e){return o(!0),t.initialise(e.publishableKey,e.platformPublishableKey??"",e.profileId??"",e.environment??"PROD",e.customEndpoints??{}).then(()=>(o(!1),{publishableKey:e.publishableKey,async initPaymentSession(t){return a=e,i=t,{presentPaymentSheet:async e=>y(n(a,i,e)),getCustomerSavedPaymentMethods:async e=>s(a,i,e),updateIntent:m};var a,i},elements:async t=>({...d(e,t)})})).catch(e=>{throw o(!1),console.error("Error initializing Hyperswitch SDK:",e),e})}const f={init:h};exports.Hyperswitch=f,exports.loadHyper=h;
2
2
  //# sourceMappingURL=index.bundle.js.map
@@ -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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A,GAC/CA,GAGV,CAGO,MAAMC,EAAc,CACzBC,KAAMb"}
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":"2CA6CA,MAAMA,EACJC,EAAAA,oBAAoBC,IAAU,4BAC9BC,EAAAA,cAAcH,wBCxChB,SAASI,EACPC,EACAC,EACAC,EAAyC,CAAA,GAIzC,MAAQC,uBAAwBC,KAA4BC,GAC1DL,EAEF,MAAO,CACLA,kBAAmBK,EACnBJ,qBAAsBA,EACtBC,gBAEJ,CCXA,SAASI,EAAmBC,GAC1B,MAAMC,EAASC,KAAKC,MAAMH,GAG1B,GAAIC,EAAOG,SAAqC,iBAAnBH,EAAOG,QAClC,IACEH,EAAOG,QAAUF,KAAKC,MAAMF,EAAOG,QACrC,CAAE,MACAH,EAAOG,QAAU,IACnB,CAEF,OAAOH,CACT,CA4COI,eAAeC,EACpBb,EACAC,EACAC,GAEA,MAAMY,EAAUf,EACdC,EACAC,EACAC,GAGF,aADMP,EAAwBkB,+BAA+BC,GAnDtD,CACLF,qCAA0C,SAGjCN,QADCX,EAAwBoB,wCAIlCH,yCAA8C,SAGrCN,QADCX,EAAwBqB,4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ACdC,EACAC,EACAC,IAKJ,oBAAMsC,CACJC,EACAC,GAcF,EAEA9B,+BAAoC,MAClCV,GAEOW,EACLb,EACAC,EACAC,GAIJmC,aAAcA,EAElB,CCpDM,SAAUM,EACdC,GAGA,OADApB,GAAgB,GACT7B,EAAwBkD,WAC7BD,EAAOE,eACPF,EAAOzC,wBAA0B,GACjCyC,EAAOG,WAAa,GACpBH,EAAOI,aAAe,OACtBJ,EAAOK,iBAAmB,CAAA,GAC1BC,KAAK,KACL1B,GAAgB,GACT,CACLsB,eAAgBF,EAAOE,eACvB,wBAAMK,CACJC,GAEA,OF6DNpD,EE7DkC4C,EF8DlC3C,EE9D0CmD,EFgEnC,CACLxC,oBAAyB,MACvBV,GAOOiC,EALSpC,EACdC,EACAC,EACAC,IAKJU,+BAAoC,MAClCV,GAEOW,EACLb,EACAC,EACAC,GAGJmC,gBAzBE,IACJrC,EACAC,CE7DI,EACAW,SAAc,MAACwC,IDuCZ,IACFb,ECvCuBK,EAAQQ,QAGjCC,MAAOC,IAGR,MAFA9B,GAAgB,GAChBH,QAAQiC,MAAM,sCAAuCA,GAC/CA,GAGV,CAGO,MAAMC,EAAc,CACzBC,KAAMb"}
@@ -1,2 +1,2 @@
1
- import{TurboModuleRegistry as e,NativeModules as t}from"react-native";const n=e.get("NativeHyperswitchModule")??t.NativeHyperswitchModule;function a(e,t,n={}){const{platformPublishableKey:a,...s}=e;return{hyperswitchConfig:s,paymentSessionConfig:t,configuration:n}}function s(e){const t=JSON.parse(e);if(t.billing&&"string"==typeof t.billing)try{t.billing=JSON.parse(t.billing)}catch{t.billing=null}return t}async function i(e,t,i){const o=a(e,t,i);return await n.getCustomerSavedPaymentMethods(o),{getCustomerLastUsedPaymentMethodData:async()=>s(await n.getCustomerLastUsedPaymentMethodData()),getCustomerDefaultSavedPaymentMethodData:async()=>s(await n.getCustomerDefaultSavedPaymentMethodData()),getCustomerSavedPaymentMethodData:async()=>s(await n.getCustomerSavedPaymentMethodData()),async confirmWithCustomerLastUsedPaymentMethod(e){await n.confirmWithCustomerLastUsedPaymentMethod()},async confirmWithCustomerDefaultPaymentMethod(e){await n.confirmWithCustomerDefaultPaymentMethod()}}}console.log("NativeHyperswitchModule",n);let o=!1;function r(e){o=e}let c=!1;function u(e){c=e}function l(e){switch(e){case"succeeded":case"completed":case"success":return"completed";case"cancelled":case"canceled":return"canceled";default:return"failed"}}function y(e){const t=function(e){if("object"==typeof e&&null!==e)return e;try{return JSON.parse(e)}catch{return{status:"failed",message:String(e)}}}(e);return{type:l(t.status),message:t.message}}async function m(e){if(o)return{type:"failed",message:"SDK is reloading. Please wait for initialisation to complete before presenting the payment sheet."};if(c)return{type:"canceled",message:"A payment sheet is already presented."};u(!0);try{return y(await n.presentPaymentSheet({hyperswitchConfig:e.hyperswitchConfig,paymentSessionConfig:e.paymentSessionConfig,configuration:e.configuration}))}finally{u(!1)}}async function f(e){}function d(e,t){return{presentPaymentSheet:async n=>m(a(e,t,n)),async confirmPayment(e,t){},getCustomerSavedPaymentMethods:async n=>i(e,t,n),updateIntent:f}}function h(e){return r(!0),n.initialise(e.publishableKey,e.platformPublishableKey??"",e.profileId??"",e.environment??"PROD",e.customEndpoints??{}).then(()=>(r(!1),{publishableKey:e.publishableKey,async initPaymentSession(t){return n=e,s=t,{presentPaymentSheet:async e=>m(a(n,s,e)),getCustomerSavedPaymentMethods:async e=>i(n,s,e),updateIntent:f};var n,s},elements:async t=>({...d(e,t)})})).catch(e=>{throw r(!1),console.error("Error initializing Hyperswitch SDK:",e),e})}const p={init:h};export{p as Hyperswitch,h as loadHyper};
1
+ import{TurboModuleRegistry as e,NativeModules as t}from"react-native";const n=e.get("NativeHyperswitchModule")??t.NativeHyperswitchModule;function a(e,t,n={}){const{platformPublishableKey:a,...s}=e;return{hyperswitchConfig:s,paymentSessionConfig:t,configuration:n}}function s(e){const t=JSON.parse(e);if(t.billing&&"string"==typeof t.billing)try{t.billing=JSON.parse(t.billing)}catch{t.billing=null}return t}async function i(e,t,i){const o=a(e,t,i);return await n.getCustomerSavedPaymentMethods(o),{getCustomerLastUsedPaymentMethodData:async()=>s(await n.getCustomerLastUsedPaymentMethodData()),getCustomerDefaultSavedPaymentMethodData:async()=>s(await n.getCustomerDefaultSavedPaymentMethodData()),getCustomerSavedPaymentMethodData:async()=>s(await n.getCustomerSavedPaymentMethodData()),async confirmWithCustomerLastUsedPaymentMethod(e){await n.confirmWithCustomerLastUsedPaymentMethod()},async confirmWithCustomerDefaultPaymentMethod(e){await n.confirmWithCustomerDefaultPaymentMethod()}}}console.log("NativeHyperswitchModule",n);let o=!1;function r(e){o=e}let c=!1;function u(e){c=e}function l(e){switch(e){case"succeeded":case"completed":case"success":return"completed";case"cancelled":case"canceled":return"canceled";default:return"failed"}}function y(e){const t=function(e){if("object"==typeof e&&null!==e)return e;try{return JSON.parse(e)}catch{return{status:"failed",message:String(e)}}}(e);return{type:l(t.status),message:t.message}}async function m(e){if(o)return{type:"failed",message:"SDK is reloading. Please wait for initialisation to complete before presenting the payment sheet."};if(c)return{type:"canceled",message:"A payment sheet is already presented."};u(!0);try{console.log("Presenting payment sheet with payload:",e);const t=await n.presentPaymentSheet({hyperswitchConfig:e.hyperswitchConfig,paymentSessionConfig:e.paymentSessionConfig,configuration:e.configuration});return console.log("Native response from presentPaymentSheet:",t),y(t)}finally{u(!1)}}async function f(e){}function d(e,t){return{presentPaymentSheet:async n=>m(a(e,t,n)),async confirmPayment(e,t){},getCustomerSavedPaymentMethods:async n=>i(e,t,n),updateIntent:f}}function h(e){return r(!0),n.initialise(e.publishableKey,e.platformPublishableKey??"",e.profileId??"",e.environment??"PROD",e.customEndpoints??{}).then(()=>(r(!1),{publishableKey:e.publishableKey,async initPaymentSession(t){return n=e,s=t,{presentPaymentSheet:async e=>m(a(n,s,e)),getCustomerSavedPaymentMethods:async e=>i(n,s,e),updateIntent:f};var n,s},elements:async t=>({...d(e,t)})})).catch(e=>{throw r(!1),console.error("Error initializing Hyperswitch SDK:",e),e})}const p={init:h};export{p as Hyperswitch,h as loadHyper};
2
2
  //# sourceMappingURL=index.bundle.js.map
@@ -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":"sEA6CA,MAAMA,EACJC,EAAoBC,IAAU,4BAC9BC,EAAcH,wBCxChB,SAASI,EACPC,EACAC,EACAC,EAAyC,CAAA,GAIzC,MAAQC,uBAAwBC,KAA4BC,GAC1DL,EAEF,MAAO,CACLA,kBAAmBK,EACnBJ,qBAAsBA,EACtBC,gBAEJ,CCXA,SAASI,EAAmBC,GAC1B,MAAMC,EAASC,KAAKC,MAAMH,GAG1B,GAAIC,EAAOG,SAAqC,iBAAnBH,EAAOG,QAClC,IACEH,EAAOG,QAAUF,KAAKC,MAAMF,EAAOG,QACrC,CAAE,MACAH,EAAOG,QAAU,IACnB,CAEF,OAAOH,CACT,CA4COI,eAAeC,EACpBb,EACAC,EACAC,GAEA,MAAMY,EAAUf,EACdC,EACAC,EACAC,GAGF,aADMP,EAAwBkB,+BAA+BC,GAnDtD,CACLF,qCAA0C,SAGjCN,QADCX,EAAwBoB,wCAIlCH,yCAA8C,SAGrCN,QADCX,EAAwBqB,4CAIlCJ,kCAAuC,SAG9BN,QADCX,EAAwBsB,qCAIlC,8CA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,GAGA,OADApB,GAAgB,GACT7B,EAAwBkD,WAC7BD,EAAOE,eACPF,EAAOzC,wBAA0B,GACjCyC,EAAOG,WAAa,GACpBH,EAAOI,aAAe,OACtBJ,EAAOK,iBAAmB,CAAA,GAC1BC,KAAK,KACL1B,GAAgB,GACT,CACLsB,eAAgBF,EAAOE,eACvB,wBAAMK,CACJC,GAEA,OF2DNpD,EE3DkC4C,EF4DlC3C,EE5D0CmD,EF8DnC,CACLxC,oBAAyB,MACvBV,GAOOiC,EALSpC,EACdC,EACAC,EACAC,IAKJU,+BAAoC,MAClCV,GAEOW,EACLb,EACAC,EACAC,GAGJmC,gBAzBE,IACJrC,EACAC,CE3DI,EACAW,SAAc,MAACwC,IDuCZ,IACFb,ECvCuBK,EAAQQ,QAGjCC,MAAOC,IAGR,MAFA9B,GAAgB,GAChBH,QAAQiC,MAAM,sCAAuCA,GAC/CA,GAGV,CAGO,MAAMC,EAAc,CACzBC,KAAMb"}
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":"sEA6CA,MAAMA,EACJC,EAAoBC,IAAU,4BAC9BC,EAAcH,wBCxChB,SAASI,EACPC,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MAAMC,EAAc,CACzBC,KAAMb"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-hyperswitch-dev-sdk",
3
- "version": "0.4.2",
3
+ "version": "0.4.4",
4
4
  "description": "Hyperswitch SDK for React Native",
5
5
  "main": "lib/commonjs/index.bundle.js",
6
6
  "module": "lib/module/index.bundle.js",
@@ -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: SessionData): Promise<string>;
25
+ presentPaymentSheet(params: Object): Promise<string>;
26
26
 
27
- getCustomerSavedPaymentMethods(params?: SessionData): Promise<string>;
27
+ getCustomerSavedPaymentMethods(params?: Object): Promise<string>;
28
28
 
29
29
  getCustomerLastUsedPaymentMethodData(): Promise<string>;
30
30
 
@@ -1,5 +0,0 @@
1
- #import <HyperswitchSdkReactNativeSpec/HyperswitchSdkReactNativeSpec.h>
2
-
3
- @interface HyperswitchSdkReactNative : NSObject <NativeHyperswitchSdkReactNativeSpec>
4
-
5
- @end
@@ -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