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.
Files changed (35) hide show
  1. package/HyperswitchSdkReactNative.podspec +4 -0
  2. package/android/build.gradle +0 -6
  3. package/android/src/main/java/com/hyperswitchsdkreactnative/modules/ReactNativeHyperswitchModule.kt +1 -5
  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 +125 -121
  12. package/ios/hyperswitchSDK/Core/HyperCVCWidget/CVCWidget.swift +9 -7
  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 +23 -19
  17. package/ios/hyperswitchSDK/Core/HyperSession/PaymentSession+UIKit.swift +14 -0
  18. package/ios/hyperswitchSDK/Core/NativeModule/HyperModuleImpl.swift +388 -0
  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 +8 -4
  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
  35. package/ios/hyperswitchSDK/Core/NativeModule/HyperModule.swift +0 -343
@@ -2,46 +2,82 @@
2
2
  // RNHeadlessManager.swift
3
3
  // Hyperswitch
4
4
  //
5
+ // Hosts the SDK's headless React Native runtime (the "HyperHeadless" module)
6
+ // that drives headless payment sessions without any visible UI.
7
+ //
8
+ // New Architecture note:
9
+ // ----------------------
10
+ // Mirrors RNViewManager: uses the full RCTReactNativeFactory rather than the
11
+ // legacy RCTBridge(delegate:launchOptions:) + RCTRootView(bridge:…) pair.
12
+ // The raw bridge init is incompatible with RCTSetNewArchEnabled(YES) (set
13
+ // globally by the host app's RN runtime), which caused EXC_BAD_ACCESS at
14
+ // offset 0x69f when accessing the bridge's C++ internals via RCTRootView.
15
+ //
16
+ // reinvalidateBridge() is preserved for callers (PaymentSession+UIKit) that
17
+ // need to reset the headless runtime between sessions; it now tears down and
18
+ // lazily recreates the RCTReactNativeFactory instead of the bare bridge.
19
+ //
5
20
  // Created by Shivam Shashank on 09/11/22.
6
21
  //
7
22
 
8
23
  import Foundation
9
24
  import React
25
+ import React_RCTAppDelegate
26
+ import ReactAppDependencyProvider
10
27
 
11
- internal class RNHeadlessManager: NSObject {
28
+ internal class RNHeadlessManager: RCTDefaultReactNativeFactoryDelegate {
12
29
 
13
30
  internal var responseHandler: RNResponseHandler?
14
- internal var rootView: RCTRootView?
31
+ internal var rootView: UIView?
15
32
 
16
- internal lazy var bridgeHeadless: RCTBridge = {
17
- RCTBridge.init(delegate: self, launchOptions: nil)
18
- }()
33
+ private var reactNativeFactory: RCTReactNativeFactory?
19
34
 
20
35
  internal static let sharedInstance = RNHeadlessManager()
21
36
 
22
- internal func viewForModule(_ moduleName: String, initialProperties: [String: Any]?) -> RCTRootView {
23
- let rootView: RCTRootView = RCTRootView(
24
- bridge: self.bridgeHeadless,
25
- moduleName: moduleName,
37
+ // MARK: - Factory lifecycle
38
+
39
+ /// Lazily creates the RCTReactNativeFactory (and its bridge) on first use.
40
+ private func factory() -> RCTReactNativeFactory {
41
+ if let existing = reactNativeFactory {
42
+ return existing
43
+ }
44
+ self.dependencyProvider = RCTAppDependencyProvider()
45
+ let created = RCTReactNativeFactory(delegate: self)
46
+ reactNativeFactory = created
47
+ return created
48
+ }
49
+
50
+ // MARK: - View creation
51
+
52
+ internal func viewForModule(_ moduleName: String, initialProperties: [String: Any]?) -> UIView {
53
+ let view = factory().rootViewFactory.view(
54
+ withModuleName: moduleName,
26
55
  initialProperties: initialProperties
27
56
  )
28
- self.rootView = rootView
29
- return rootView
57
+ self.rootView = view
58
+ return view
30
59
  }
31
60
 
61
+ /// Tear down the current factory (and its bridge) so the next call to
62
+ /// viewForModule starts a fresh JS runtime for the new headless session.
32
63
  internal func reinvalidateBridge() {
33
- self.bridgeHeadless.invalidate()
34
- self.bridgeHeadless = RCTBridge.init(delegate: self, launchOptions: nil)
64
+ reactNativeFactory = nil
65
+ rootView = nil
35
66
  }
36
- }
37
67
 
38
- extension RNHeadlessManager: RCTBridgeDelegate {
39
- func sourceURL(for bridge: RCTBridge) -> URL? {
40
- switch Helper.getInfoPlist("HyperswitchSource") {
41
- case "LocalHosted":
42
- return RCTBundleURLProvider.sharedSettings().jsBundleURL(forBundleRoot: "index")
43
- default:
44
- return Bundle(for: RNHeadlessManager.self).url(forResource: "hyperswitch", withExtension: "bundle")
45
- }
68
+ // MARK: - RCTDefaultReactNativeFactoryDelegate
69
+
70
+ /// Use bridge mode (not bridgeless) so the headless module can use the
71
+ /// legacy RCTBridge event / callback APIs.
72
+ public override func bridgelessEnabled() -> Bool {
73
+ return false
74
+ }
75
+
76
+ override func sourceURL(for bridge: RCTBridge) -> URL? {
77
+ return bundleURL()
78
+ }
79
+
80
+ public override func bundleURL() -> URL? {
81
+ return Bundle(for: RNHeadlessManager.self).url(forResource: "hyperswitch", withExtension: "bundle")
46
82
  }
47
83
  }
@@ -2,54 +2,109 @@
2
2
  // RNViewManager.swift
3
3
  // Hyperswitch
4
4
  //
5
+ // Hosts the SDK's embedded React Native runtime that renders the payment sheet
6
+ // from the packaged `hyperswitch.bundle`.
7
+ //
8
+ // New Architecture note:
9
+ // ----------------------
10
+ // The embedded runtime MUST be created through the full `RCTReactNativeFactory`.
11
+ // That initializer performs the essential RN setup — feature flags,
12
+ // `RCTSetNewArchEnabled`, `RCTEnableTurboModule`, the Fabric component provider —
13
+ // and wires a TurboModule manager that can resolve RN's own CORE modules
14
+ // (`DeviceInfo`, `ExceptionsManager`, `RedBox`, …). Building the low-level
15
+ // `RCTRootViewFactory` directly (as the old `RNBridgeFactory` did) leaves the
16
+ // runtime under-initialised, so `getEnforcing('DeviceInfo')` fails and the bundle
17
+ // can't boot — the sheet renders blank.
18
+ //
19
+ // The bridge is intentionally kept alive (Fabric-on-bridge) for now because the
20
+ // legacy widget code still uses `bridge.enqueueJSCall` / `bridge.uiManager`.
21
+ // For the payment-sheet-only build we do not capture or expose the bridge here.
22
+ //
5
23
  // Created by Shivam Shashank on 09/11/22.
6
24
  //
7
25
 
8
26
  import Foundation
9
27
  import React
28
+ import React_RCTAppDelegate
29
+ import ReactAppDependencyProvider
10
30
 
11
- internal class RNViewManager: NSObject {
31
+ internal class RNViewManager: RCTDefaultReactNativeFactoryDelegate {
12
32
 
13
33
  internal var responseHandler: RNResponseHandler?
14
- internal var rootView: RCTRootView?
34
+ internal var rootView: UIView?
15
35
 
16
- internal lazy var bridge: RCTBridge = {
17
- RCTBridge.init(delegate: self, launchOptions: nil)
18
- }()
36
+ private var reactNativeFactory: RCTReactNativeFactory?
37
+
38
+ // Bridge capture removed for the payment-sheet-only/bridgeless build.
39
+ // private weak var capturedBridge: RCTBridge?
19
40
 
20
41
  internal static let sharedInstance = RNViewManager()
21
42
 
22
- internal func viewForModule(_ moduleName: String, initialProperties: [String: Any]?) -> RCTRootView {
23
- let rootView: RCTRootView = RCTRootView(
24
- bridge: self.bridge,
25
- moduleName: moduleName,
43
+ /// Lazily create the standard RN factory (does the full runtime setup).
44
+ private func factory() -> RCTReactNativeFactory {
45
+ if let existing = reactNativeFactory {
46
+ return existing
47
+ }
48
+ self.dependencyProvider = RCTAppDependencyProvider()
49
+ let created = RCTReactNativeFactory(delegate: self)
50
+ reactNativeFactory = created
51
+ return created
52
+ }
53
+
54
+ /// The bridge backing the embedded runtime. Kept for the SDK's widget commands
55
+ /// (`bridge.enqueueJSCall` / `bridge.uiManager`). Available after the first view
56
+ /// is created.
57
+ // internal var bridge: RCTBridge? {
58
+ // return capturedBridge
59
+ // }
60
+
61
+ internal func viewForModule(_ moduleName: String, initialProperties: [String: Any]?) -> UIView {
62
+ let view = factory().rootViewFactory.view(
63
+ withModuleName: moduleName,
26
64
  initialProperties: initialProperties
27
65
  )
28
- self.rootView = rootView
29
- return rootView
66
+ self.rootView = view
67
+ return view
30
68
  }
31
- internal func widgetViewForModule(_ moduleName: String, initialProperties: [String: Any]?) -> RCTRootView {
32
- return RCTRootView(
33
- bridge: self.bridge,
34
- moduleName: moduleName,
69
+
70
+ internal func widgetViewForModule(_ moduleName: String, initialProperties: [String: Any]?) -> UIView {
71
+ return factory().rootViewFactory.view(
72
+ withModuleName: moduleName,
35
73
  initialProperties: initialProperties
36
74
  )
37
75
  }
38
- }
39
76
 
40
- extension RNViewManager: RCTBridgeDelegate {
41
- func sourceURL(for bridge: RCTBridge) -> URL? {
42
- switch Helper.getInfoPlist("HyperswitchSource") {
43
- case "LocalHosted":
44
- return RCTBundleURLProvider.sharedSettings().jsBundleURL(forBundleRoot: "index")
45
- case "LocalBundle":
46
- return Bundle.main.url(forResource: "hyperswitch", withExtension: "bundle")
47
- default:
48
- #if canImport(HyperOTA)
49
- return OTAServices.shared.getBundleURL()
50
- #else
77
+ // MARK: - Arch configuration
78
+
79
+ /// Keep a bridge-backed Fabric runtime so the bundled payment sheet can boot.
80
+ /// (The bridge itself is not exposed here; only the factory/rootView is used.)
81
+ public override func bridgelessEnabled() -> Bool {
82
+ return false
83
+ }
84
+
85
+ // MARK: - Bundle source
86
+ // Both are required in bridge mode: the default implementations throw.
87
+
88
+ override func sourceURL(for bridge: RCTBridge) -> URL? {
89
+ // Called while the embedded bridge loads its JS — capture it for the SDK's
90
+ // bridge-dependent widget commands.
91
+ // self.capturedBridge = bridge
92
+ return bundleURL()
93
+ }
94
+
95
+ public override func bundleURL() -> URL? {
96
+ // switch Helper.getInfoPlist("HyperswitchSource") {
97
+ // case "LocalHosted":
98
+ // return RCTBundleURLProvider.sharedSettings().jsBundleURL(forBundleRoot: "index")
99
+ // case "LocalBundle":
100
+ // return Bundle.main.url(forResource: "hyperswitch", withExtension: "bundle")
101
+ // default:
102
+ // #if canImport(HyperOTA)
103
+ // return OTAServices.shared.getBundleURL()
104
+ // #else
51
105
  return Bundle(for: RNViewManager.self).url(forResource: "hyperswitch", withExtension: "bundle")
52
- #endif
53
- }
106
+ // #endif
107
+ // }
54
108
  }
55
109
  }
110
+
@@ -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","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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"}
@@ -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