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

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.
@@ -100,27 +100,14 @@ class ReactNativeHyperswitchModule(reactContext: ReactApplicationContext) :
100
100
  promise: Promise?
101
101
  ) {
102
102
  try {
103
- // val map = mutableMapOf<String, Any>().apply {
104
- // put("code", "failed")
105
- // put("message", "opened alreday")
106
- // }
107
- // promise?.resolve(map)
108
- // return
109
- // }
110
103
  val props = mutableMapOf<String, Any?>().apply {
111
104
  putAll(params?.toHashMap().orEmpty())
112
105
  put("type", "payment")
113
106
  }
114
-
115
- val map: Map<String, Any?> = mapOf(
116
- "props" to props
117
- )
118
- val bundle = launchOptions?.toBundle(map)
107
+ val bundle = launchOptions?.getBundleWithHyperParams(props)
119
108
  bundle?.let {
120
109
  val isFragment = paymentSessionReactLauncher?.presentSheet(bundle)
121
- // isPresented.set(true)
122
110
  val resultCallback: (String) -> Unit = { it ->
123
- // isPresented.set(false)
124
111
  promise?.resolve(it)
125
112
  }
126
113
  PaymentSheetCallbackManager.setCallback(resultCallback, isFragment == true)
@@ -1,6 +1,5 @@
1
1
  package io.hyperswitch.paymentsession
2
2
 
3
- import org.json.JSONObject
4
3
  import java.util.concurrent.atomic.AtomicReference
5
4
 
6
5
  typealias Callback = (String) -> Unit
@@ -36,7 +36,7 @@ RCT_EXPORT_MODULE(HyperModule)
36
36
 
37
37
  - (NSArray<NSString *> *)supportedEvents
38
38
  {
39
- return @[ @"confirm", @"confirmEC", @"triggerWidgetAction", @"updateIntentInit", @"updateIntentComplete" ];
39
+ return @[ @"confirm" ];
40
40
  }
41
41
 
42
42
  + (BOOL)requiresMainQueueSetup
@@ -97,7 +97,7 @@ RCT_EXPORT_MODULE(HyperModule)
97
97
 
98
98
  - (void)exitWidgetPaymentsheet:(double)rootTag result:(NSString *)result reset:(BOOL)reset
99
99
  {
100
- [HyperModuleImpl.shared exitWidgetPaymentsheet:@(rootTag) result:result reset:reset];
100
+ // [HyperModuleImpl.shared exitWidgetPaymentsheet:@(rootTag) result:result reset:reset];
101
101
  }
102
102
 
103
103
  // MARK: - Widget
@@ -114,7 +114,7 @@ RCT_EXPORT_MODULE(HyperModule)
114
114
 
115
115
  - (void)launchWidgetPaymentSheet:(NSString *)requestObj callback:(RCTResponseSenderBlock)callback
116
116
  {
117
- [HyperModuleImpl.shared launchWidgetPaymentSheet:requestObj callback:callback];
117
+ // [HyperModuleImpl.shared launchWidgetPaymentSheet:requestObj callback:callback];
118
118
  }
119
119
 
120
120
  - (void)updateWidgetHeight:(double)height
@@ -124,31 +124,31 @@ RCT_EXPORT_MODULE(HyperModule)
124
124
 
125
125
  - (void)notifyWidgetPaymentResult:(double)rootTag result:(NSString *)result
126
126
  {
127
- [HyperModuleImpl.shared notifyWidgetPaymentResult:@(rootTag) result:result];
127
+ // [HyperModuleImpl.shared notifyWidgetPaymentResult:@(rootTag) result:result];
128
128
  }
129
129
 
130
130
  // MARK: - Payment method management
131
131
 
132
132
  - (void)onAddPaymentMethod:(NSString *)data
133
133
  {
134
- [HyperModuleImpl.shared onAddPaymentMethod:data];
134
+ // [HyperModuleImpl.shared onAddPaymentMethod:data];
135
135
  }
136
136
 
137
137
  // MARK: - Payment events
138
138
 
139
139
  - (void)emitPaymentEvent:(double)rootTag eventType:(NSString *)eventType payload:(NSDictionary *)payload
140
140
  {
141
- [HyperModuleImpl.shared emitPaymentEvent:@(rootTag) eventType:eventType payload:payload];
141
+ // [HyperModuleImpl.shared emitPaymentEvent:@(rootTag) eventType:eventType payload:payload];
142
142
  }
143
143
 
144
144
  - (void)onUpdateIntentEvent:(double)rootTag type:(NSString *)type result:(NSString *)result
145
145
  {
146
- [HyperModuleImpl.shared onUpdateIntentEvent:@(rootTag) type:type result:result];
146
+ // [HyperModuleImpl.shared onUpdateIntentEvent:@(rootTag) type:type result:result];
147
147
  }
148
148
 
149
149
  - (void)onPaymentConfirmButtonClick:(double)rootTag payload:(NSString *)payload callback:(RCTResponseSenderBlock)callback
150
150
  {
151
- [HyperModuleImpl.shared onPaymentConfirmButtonClick:@(rootTag) payload:payload callback:callback];
151
+ // [HyperModuleImpl.shared onPaymentConfirmButtonClick:@(rootTag) payload:payload callback:callback];
152
152
  }
153
153
 
154
154
  // MARK: - 3DS / DDC iframe bridge
@@ -34,34 +34,34 @@ internal class NativePaymentWidget: RCTViewManager {
34
34
  }
35
35
 
36
36
  @objc func confirmPayment(_ reactTag: NSNumber, _ rnCallback: @escaping RCTResponseSenderBlock) {
37
- bridge.uiManager.addUIBlock { _, viewRegistry in
38
- // Old-arch path: the view is NativePaymentWidgetView directly.
39
- if let view = viewRegistry?[reactTag] as? NativePaymentWidgetView {
40
- view.confirmPayment(rnCallback)
41
- return
42
- }
43
- // New-arch (Fabric) path: the Fabric NativePaymentElementView registered
44
- // the inner NativePaymentWidgetView in the shared registry by the same tag.
45
- // if let view = NativePaymentWidgetViewRegistry.shared().view(forTag: reactTag) as? NativePaymentWidgetView {
46
- // view.confirmPayment(rnCallback)
47
- // return
48
- // }
49
- rnCallback([["status": "failed", "message": "Widget view not found for tag \(reactTag)"]])
50
- }
37
+ // bridge.uiManager.addUIBlock { _, viewRegistry in
38
+ // // Old-arch path: the view is NativePaymentWidgetView directly.
39
+ // if let view = viewRegistry?[reactTag] as? NativePaymentWidgetView {
40
+ // view.confirmPayment(rnCallback)
41
+ // return
42
+ // }
43
+ // // New-arch (Fabric) path: the Fabric NativePaymentElementView registered
44
+ // // the inner NativePaymentWidgetView in the shared registry by the same tag.
45
+ // // if let view = NativePaymentWidgetViewRegistry.shared().view(forTag: reactTag) as? NativePaymentWidgetView {
46
+ // // view.confirmPayment(rnCallback)
47
+ // // return
48
+ // // }
49
+ // rnCallback([["status": "failed", "message": "Widget view not found for tag \(reactTag)"]])
50
+ // }
51
51
  }
52
52
 
53
53
  @objc func updateIntentInitForWidget(_ rootTag: NSNumber, _ rnCallback: @escaping RCTResponseSenderBlock) {
54
- bridge.uiManager.addUIBlock { _, viewRegistry in
55
- if let view = viewRegistry?[rootTag] as? NativePaymentWidgetView {
56
- view.updateIntentInit(rnCallback)
57
- return
58
- }
59
- // if let view = NativePaymentWidgetViewRegistry.shared().view(forTag: rootTag) as? NativePaymentWidgetView {
60
- // view.updateIntentInit(rnCallback)
61
- // return
62
- // }
63
- rnCallback([["status": "failed", "message": "Widget view not found for tag \(rootTag)"]])
64
- }
54
+ // bridge.uiManager.addUIBlock { _, viewRegistry in
55
+ // if let view = viewRegistry?[rootTag] as? NativePaymentWidgetView {
56
+ // view.updateIntentInit(rnCallback)
57
+ // return
58
+ // }
59
+ // // if let view = NativePaymentWidgetViewRegistry.shared().view(forTag: rootTag) as? NativePaymentWidgetView {
60
+ // // view.updateIntentInit(rnCallback)
61
+ // // return
62
+ // // }
63
+ // rnCallback([["status": "failed", "message": "Widget view not found for tag \(rootTag)"]])
64
+ // }
65
65
  }
66
66
 
67
67
  @objc func updateIntentCompleteForWidget(
@@ -69,17 +69,17 @@ internal class NativePaymentWidget: RCTViewManager {
69
69
  _ sdkAuthorization: String,
70
70
  _ rnCallback: @escaping RCTResponseSenderBlock
71
71
  ) {
72
- bridge.uiManager.addUIBlock { _, viewRegistry in
73
- if let view = viewRegistry?[rootTag] as? NativePaymentWidgetView {
74
- view.updateIntentComplete(sdkAuthorization: sdkAuthorization, resolve: rnCallback)
75
- return
76
- }
77
- // if let view = NativePaymentWidgetViewRegistry.shared().view(forTag: rootTag) as? NativePaymentWidgetView {
78
- // view.updateIntentComplete(sdkAuthorization: sdkAuthorization, resolve: rnCallback)
79
- // return
80
- // }
81
- rnCallback([["status": "failed", "message": "Widget view not found for tag \(rootTag)"]])
82
- }
72
+ // bridge.uiManager.addUIBlock { _, viewRegistry in
73
+ // if let view = viewRegistry?[rootTag] as? NativePaymentWidgetView {
74
+ // view.updateIntentComplete(sdkAuthorization: sdkAuthorization, resolve: rnCallback)
75
+ // return
76
+ // }
77
+ // // if let view = NativePaymentWidgetViewRegistry.shared().view(forTag: rootTag) as? NativePaymentWidgetView {
78
+ // // view.updateIntentComplete(sdkAuthorization: sdkAuthorization, resolve: rnCallback)
79
+ // // return
80
+ // // }
81
+ // rnCallback([["status": "failed", "message": "Widget view not found for tag \(rootTag)"]])
82
+ // }
83
83
  }
84
84
 
85
85
  @objc func confirmPaymentCVC(
@@ -88,17 +88,17 @@ internal class NativePaymentWidget: RCTViewManager {
88
88
  _ paymentMethodId: String,
89
89
  _ rnCallback: @escaping RCTResponseSenderBlock
90
90
  ) {
91
- bridge.uiManager.addUIBlock { _, viewRegistry in
92
- if let view = viewRegistry?[reactTag] as? NativePaymentWidgetView {
93
- view.confirmCVCPayment(paymentToken: paymentToken, paymentMethodId: paymentMethodId, resolve: rnCallback)
94
- return
95
- }
96
- // if let view = NativePaymentWidgetViewRegistry.shared().view(forTag: reactTag) as? NativePaymentWidgetView {
97
- // view.confirmCVCPayment(paymentToken: paymentToken, paymentMethodId: paymentMethodId, resolve: rnCallback)
98
- // return
99
- // }
100
- rnCallback([["status": "failed", "message": "Widget view not found for tag \(reactTag)"]])
101
- }
91
+ // bridge.uiManager.addUIBlock { _, viewRegistry in
92
+ // if let view = viewRegistry?[reactTag] as? NativePaymentWidgetView {
93
+ // view.confirmCVCPayment(paymentToken: paymentToken, paymentMethodId: paymentMethodId, resolve: rnCallback)
94
+ // return
95
+ // }
96
+ // // if let view = NativePaymentWidgetViewRegistry.shared().view(forTag: reactTag) as? NativePaymentWidgetView {
97
+ // // view.confirmCVCPayment(paymentToken: paymentToken, paymentMethodId: paymentMethodId, resolve: rnCallback)
98
+ // // return
99
+ // // }
100
+ // rnCallback([["status": "failed", "message": "Widget view not found for tag \(reactTag)"]])
101
+ // }
102
102
  }
103
103
  }
104
104
 
@@ -343,66 +343,66 @@ public class NativePaymentWidgetView: UIView {
343
343
 
344
344
  @objc public func confirmPayment(_ rnCallback: @escaping RCTResponseSenderBlock) {
345
345
  // avoiding duplicate confirm calls (confirmPayment triggered multiple times from RN layer)
346
- if self.responseSenderCallback != nil {
347
- let response = ["status": "failed", "error": "invalid call"]
348
- rnCallback([response])
349
- return
350
- }
351
-
352
- self.responseSenderCallback = rnCallback
353
- guard let paymentWidget = paymentWidget else {
354
- self.responseSenderCallback = nil
355
- rnCallback([[
356
- "status": "failed",
357
- "code": "WIDGET_NOT_READY",
358
- "message": "Widget not ready",
359
- ]])
360
- return
361
- }
362
- paymentWidget.confirm()
346
+ // if self.responseSenderCallback != nil {
347
+ // let response = ["status": "failed", "error": "invalid call"]
348
+ // rnCallback([response])
349
+ // return
350
+ // }
351
+
352
+ // self.responseSenderCallback = rnCallback
353
+ // guard let paymentWidget = paymentWidget else {
354
+ // self.responseSenderCallback = nil
355
+ // rnCallback([[
356
+ // "status": "failed",
357
+ // "code": "WIDGET_NOT_READY",
358
+ // "message": "Widget not ready",
359
+ // ]])
360
+ // return
361
+ // }
362
+ // paymentWidget.confirm()
363
363
  }
364
364
 
365
365
  @objc public func updateIntentInit(_ resolve: @escaping RCTResponseSenderBlock) {
366
- guard let tag = rctRootTag else {
367
- resolve([["status": "failed", "message": "Widget root tag not found"]])
368
- return
369
- }
366
+ // guard let tag = rctRootTag else {
367
+ // resolve([["status": "failed", "message": "Widget root tag not found"]])
368
+ // return
369
+ // }
370
370
 
371
- WidgetResponseRegistry.shared.register(rootTag: tag, action: .updateIntentInit) { [weak self] response, _ in
372
- guard let self = self else { return }
373
- resolve([self.callbackPayload(response["data"])])
374
- }
371
+ // WidgetResponseRegistry.shared.register(rootTag: tag, action: .updateIntentInit) { [weak self] response, _ in
372
+ // guard let self = self else { return }
373
+ // resolve([self.callbackPayload(response["data"])])
374
+ // }
375
375
 
376
- let eventData: [String: Any] = ["rootTag": tag]
377
- RNViewManager.sharedInstance.bridge?.enqueueJSCall(
378
- "RCTDeviceEventEmitter",
379
- method: "emit",
380
- args: ["updateIntentInit", eventData],
381
- completion: nil
382
- )
376
+ // let eventData: [String: Any] = ["rootTag": tag]
377
+ // RNViewManager.sharedInstance.bridge?.enqueueJSCall(
378
+ // "RCTDeviceEventEmitter",
379
+ // method: "emit",
380
+ // args: ["updateIntentInit", eventData],
381
+ // completion: nil
382
+ // )
383
383
  }
384
384
 
385
385
  @objc public func updateIntentComplete(sdkAuthorization: String, resolve: @escaping RCTResponseSenderBlock) {
386
- guard let tag = rctRootTag else {
387
- resolve([["status": "failed", "message": "Widget root tag not found"]])
388
- return
389
- }
390
-
391
- WidgetResponseRegistry.shared.register(rootTag: tag, action: .updateIntentComplete) { [weak self] response, _ in
392
- guard let self = self else { return }
393
- resolve([self.callbackPayload(response["data"])])
394
- }
395
-
396
- let eventData: [String: Any] = [
397
- "rootTag": tag,
398
- "sdkAuthorization": sdkAuthorization,
399
- ]
400
- RNViewManager.sharedInstance.bridge?.enqueueJSCall(
401
- "RCTDeviceEventEmitter",
402
- method: "emit",
403
- args: ["updateIntentComplete", eventData],
404
- completion: nil
405
- )
386
+ // guard let tag = rctRootTag else {
387
+ // resolve([["status": "failed", "message": "Widget root tag not found"]])
388
+ // return
389
+ // }
390
+
391
+ // WidgetResponseRegistry.shared.register(rootTag: tag, action: .updateIntentComplete) { [weak self] response, _ in
392
+ // guard let self = self else { return }
393
+ // resolve([self.callbackPayload(response["data"])])
394
+ // }
395
+
396
+ // let eventData: [String: Any] = [
397
+ // "rootTag": tag,
398
+ // "sdkAuthorization": sdkAuthorization,
399
+ // ]
400
+ // RNViewManager.sharedInstance.bridge?.enqueueJSCall(
401
+ // "RCTDeviceEventEmitter",
402
+ // method: "emit",
403
+ // args: ["updateIntentComplete", eventData],
404
+ // completion: nil
405
+ // )
406
406
  }
407
407
 
408
408
  internal func confirmCVCPayment(paymentToken: String, paymentMethodId: String, resolve: @escaping RCTResponseSenderBlock) {
@@ -112,12 +112,13 @@ public class CVCWidget: UIControl {
112
112
  "paymentToken": paymentToken,
113
113
  "paymentMethodId": paymentMethodId as Any,
114
114
  ]
115
- RNViewManager.sharedInstance.bridge?.enqueueJSCall(
116
- "RCTDeviceEventEmitter",
117
- method: "emit",
118
- args: ["triggerWidgetAction", payload],
119
- completion: nil
120
- )
115
+ // Bridge-based widget emit removed for payment-sheet-only build.
116
+ // RNViewManager.sharedInstance.bridge?.enqueueJSCall(
117
+ // "RCTDeviceEventEmitter",
118
+ // method: "emit",
119
+ // args: ["triggerWidgetAction", payload],
120
+ // completion: nil
121
+ // )
121
122
  }
122
123
 
123
124
  internal func dispatchPaymentEvent(type: String, payload: [String: Any]) {
@@ -124,12 +124,13 @@ public class PaymentWidget: UIControl {
124
124
  .sink { [weak self] in
125
125
  guard let self = self else { return }
126
126
  let payload: [String: Any] = ["rootTag": self.widgetReactTag ?? -1]
127
- RNViewManager.sharedInstance.bridge?.enqueueJSCall(
128
- "RCTDeviceEventEmitter",
129
- method: "emit",
130
- args: ["updateIntentInit", payload],
131
- completion: nil
132
- )
127
+ // Bridge-based widget emit removed for payment-sheet-only build.
128
+ // RNViewManager.sharedInstance.bridge?.enqueueJSCall(
129
+ // "RCTDeviceEventEmitter",
130
+ // method: "emit",
131
+ // args: ["updateIntentInit", payload],
132
+ // completion: nil
133
+ // )
133
134
  }
134
135
  .store(in: &cancellables)
135
136
 
@@ -141,12 +142,13 @@ public class PaymentWidget: UIControl {
141
142
  "rootTag": self.widgetReactTag ?? -1,
142
143
  "sdkAuthorization": sdkAuthorization,
143
144
  ]
144
- RNViewManager.sharedInstance.bridge?.enqueueJSCall(
145
- "RCTDeviceEventEmitter",
146
- method: "emit",
147
- args: ["updateIntentComplete", payload],
148
- completion: nil
149
- )
145
+ // Bridge-based widget emit removed for payment-sheet-only build.
146
+ // RNViewManager.sharedInstance.bridge?.enqueueJSCall(
147
+ // "RCTDeviceEventEmitter",
148
+ // method: "emit",
149
+ // args: ["updateIntentComplete", payload],
150
+ // completion: nil
151
+ // )
150
152
  }
151
153
  .store(in: &cancellables)
152
154
  }
@@ -156,12 +158,13 @@ public class PaymentWidget: UIControl {
156
158
  "rootTag": self.widgetReactTag ?? -1,
157
159
  "actionType": "CONFIRM_PAYMENT_ACTION",
158
160
  ]
159
- RNViewManager.sharedInstance.bridge?.enqueueJSCall(
160
- "RCTDeviceEventEmitter",
161
- method: "emit",
162
- args: ["triggerWidgetAction", payload],
163
- completion: nil
164
- )
161
+ // Bridge-based widget emit removed for payment-sheet-only build.
162
+ // RNViewManager.sharedInstance.bridge?.enqueueJSCall(
163
+ // "RCTDeviceEventEmitter",
164
+ // method: "emit",
165
+ // args: ["triggerWidgetAction", payload],
166
+ // completion: nil
167
+ // )
165
168
  }
166
169
 
167
170
  internal func setPaymentEventListener(_ listener: PaymentEventListener?) {
@@ -38,8 +38,8 @@ public class HyperModuleImpl: NSObject {
38
38
  activePaymentSheetVC = vc
39
39
  }
40
40
 
41
- /// The bridge backing the RN-registered emitter (embedded runtime is bridge-based).
42
- private var bridge: RCTBridge? { eventEmitter?.bridge }
41
+ // Bridge-backed widget helpers removed for the new-arch/bridgeless build.
42
+ // private var bridge: RCTBridge? { eventEmitter?.bridge }
43
43
 
44
44
  // MARK: - Events
45
45
 
@@ -69,16 +69,16 @@ public class HyperModuleImpl: NSObject {
69
69
  self.presentCallback = callback
70
70
  }
71
71
 
72
- // MARK: - Widget
72
+ // MARK: - Widget (commented out — relies on RCTBridge/uiManager)
73
73
 
74
- @objc public func launchWidgetPaymentSheet(_ requestObj: String, callback: @escaping RCTResponseSenderBlock) {
75
- let request = HyperModuleImpl.jsonObject(from: requestObj)
76
- expressCheckoutHandler.launchPaymentSheet(paymentResult: request, callBack: callback)
77
- }
78
-
79
- @objc public func onAddPaymentMethod(_ rnMessage: String) {
80
- PaymentMethodManagementWidget.onAddPaymentMethod?()
81
- }
74
+ @objc public func launchWidgetPaymentSheet(_ requestObj: String, callback: @escaping RCTResponseSenderBlock) {
75
+ // let request = HyperModuleImpl.jsonObject(from: requestObj)
76
+ // expressCheckoutHandler.launchPaymentSheet(paymentResult: request, callBack: callback)
77
+ }
78
+ //
79
+ @objc public func onAddPaymentMethod(_ rnMessage: String) {
80
+ // PaymentMethodManagementWidget.onAddPaymentMethod?()
81
+ }
82
82
 
83
83
  // MARK: - Payment sheet exits
84
84
 
@@ -101,12 +101,12 @@ public class HyperModuleImpl: NSObject {
101
101
  }
102
102
  }
103
103
 
104
- @objc public func exitWidgetPaymentsheet(_ reactTag: NSNumber, result rnMessage: String, reset: Bool) {
105
- let result = paymentResult(from: rnMessage)
106
- withWidget(reactTag) { w in
107
- w.handleConfirmPaymentResponse(result)
108
- }
109
- }
104
+ @objc public func exitWidgetPaymentsheet(_ reactTag: NSNumber, result rnMessage: String, reset: Bool) {
105
+ // let result = paymentResult(from: rnMessage)
106
+ // withWidget(reactTag) { w in
107
+ // w.handleConfirmPaymentResponse(result)
108
+ // }
109
+ }
110
110
 
111
111
  @objc public func exitPaymentMethodManagement(_ reactTag: NSNumber, result rnMessage: String, reset: Bool) {
112
112
  exitSheet(rnMessage)
@@ -116,49 +116,49 @@ public class HyperModuleImpl: NSObject {
116
116
  exitCardFormInternal(rnMessage)
117
117
  }
118
118
 
119
- // MARK: - Payment result / events
119
+ // MARK: - Payment result / events (commented out — rely on RCTBridge/uiManager)
120
120
 
121
- @objc public func notifyWidgetPaymentResult(_ rootTag: NSNumber, result rnMessage: String) {
122
- let result = paymentResult(from: rnMessage)
123
- guard case .failed = result else { return }
124
- withNativePaymentWidgetView(rootTag) { view in
125
- view.handleConfirmPaymentResponse(result)
126
- }
127
- }
121
+ @objc public func notifyWidgetPaymentResult(_ rootTag: NSNumber, result rnMessage: String) {
122
+ // let result = paymentResult(from: rnMessage)
123
+ // guard case .failed = result else { return }
124
+ // withNativePaymentWidgetView(rootTag) { view in
125
+ // view.handleConfirmPaymentResponse(result)
126
+ // }
127
+ }
128
128
 
129
- @objc public func onUpdateIntentEvent(_ rootTag: NSNumber, type: String, result: String) {
130
- withWidget(rootTag) { widget in
131
- widget.handleUpdateIntentEvent(type: type, result: result)
132
- }
133
- }
129
+ @objc public func onUpdateIntentEvent(_ rootTag: NSNumber, type: String, result: String) {
130
+ // withWidget(rootTag) { widget in
131
+ // widget.handleUpdateIntentEvent(type: type, result: result)
132
+ // }
133
+ }
134
134
 
135
135
  @objc public func emitPaymentEvent(_ rootTag: NSNumber, eventType: String, payload: NSDictionary) {
136
- let map = (payload as? [String: Any]) ?? [:]
137
- resolveSubscribingTarget(rootTag) { target in
138
- if let widget = target as? PaymentWidget, widget.paymentEventListener != nil {
139
- widget.dispatchPaymentEvent(type: eventType, payload: map)
140
- } else if let cvc = target as? CVCWidget, cvc.paymentEventListener != nil {
141
- cvc.dispatchPaymentEvent(type: eventType, payload: map)
142
- } else if let sheet = target as? PaymentSheet, sheet.paymentEventListener != nil {
143
- sheet.dispatchPaymentEvent(type: eventType, payload: map)
144
- }
145
- }
136
+ // let map = (payload as? [String: Any]) ?? [:]
137
+ // resolveSubscribingTarget(rootTag) { target in
138
+ // if let widget = target as? PaymentWidget, widget.paymentEventListener != nil {
139
+ // widget.dispatchPaymentEvent(type: eventType, payload: map)
140
+ // } else if let cvc = target as? CVCWidget, cvc.paymentEventListener != nil {
141
+ // cvc.dispatchPaymentEvent(type: eventType, payload: map)
142
+ // } else if let sheet = target as? PaymentSheet, sheet.paymentEventListener != nil {
143
+ // sheet.dispatchPaymentEvent(type: eventType, payload: map)
144
+ // }
145
+ // }
146
146
  }
147
147
 
148
148
  @objc public func onPaymentConfirmButtonClick(_ rootTag: NSNumber, payload: String, callback: @escaping RCTResponseSenderBlock) {
149
- resolveSubscribingTarget(rootTag) { target in
150
- if let widget = target as? PaymentWidget {
151
- widget.handleShouldProceedWithPayment(payload: payload) { shouldProceed in
152
- callback([shouldProceed])
153
- }
154
- } else if let sheet = target as? PaymentSheet {
155
- sheet.handleShouldProceedWithPayment(payload: payload) { shouldProceed in
156
- callback([shouldProceed])
157
- }
158
- } else {
159
- callback([true])
160
- }
161
- }
149
+ // resolveSubscribingTarget(rootTag) { target in
150
+ // if let widget = target as? PaymentWidget {
151
+ // widget.handleShouldProceedWithPayment(payload: payload) { shouldProceed in
152
+ // callback([shouldProceed])
153
+ // }
154
+ // } else if let sheet = target as? PaymentSheet {
155
+ // sheet.handleShouldProceedWithPayment(payload: payload) { shouldProceed in
156
+ // callback([shouldProceed])
157
+ // }
158
+ // } else {
159
+ // callback([true])
160
+ // }
161
+ // }
162
162
  }
163
163
 
164
164
  // MARK: - 3DS / DDC iframe bridge
@@ -313,74 +313,76 @@ public class HyperModuleImpl: NSObject {
313
313
  }
314
314
  }
315
315
 
316
- private func withWidget(_ rootTag: NSNumber, _ block: @escaping (PaymentWidget) -> Void) {
317
- guard let bridge = self.bridge else { return }
318
- RCTGetUIManagerQueue().async {
319
- bridge.uiManager.addUIBlock { _, viewRegistry in
320
- guard let view = viewRegistry?[rootTag] else { return }
321
- var current: UIView? = view
322
- while let v = current {
323
- if let widget = v as? PaymentWidget {
324
- block(widget)
325
- return
326
- }
327
- current = v.superview
328
- }
329
- }
330
- }
331
- }
332
-
333
- private func withNativePaymentWidgetView(_ rootTag: NSNumber, _ block: @escaping (PaymentWidget) -> Void) {
334
- guard let bridge = self.bridge else { return }
335
- RCTGetUIManagerQueue().async {
336
- bridge.uiManager.addUIBlock { _, viewRegistry in
337
- guard let view = viewRegistry?[rootTag] else { return }
338
- var current: UIView? = view
339
- while let v = current {
340
- if let nativeWidget = v as? PaymentWidget {
341
- block(nativeWidget)
342
- return
343
- }
344
- current = v.superview
345
- }
346
- }
347
- }
348
- }
349
-
350
- private func resolveSubscribingTarget(_ rootTag: NSNumber, _ block: @escaping (AnyObject?) -> Void) {
351
- guard let bridge = self.bridge else {
352
- DispatchQueue.main.async { block(nil) }
353
- return
354
- }
355
- RCTGetUIManagerQueue().async {
356
- bridge.uiManager.addUIBlock { _, viewRegistry in
357
- guard let view = viewRegistry?[rootTag] else {
358
- DispatchQueue.main.async { block(nil) }
359
- return
360
- }
361
- var current: UIView? = view
362
- while let v = current {
363
- if v is PaymentWidget || v is CVCWidget {
364
- DispatchQueue.main.async { block(v) }
365
- return
366
- }
367
- current = v.superview
368
- }
369
- let sheet = (view.reactViewController() as? HyperUIViewController)?.paymentSheet
370
- DispatchQueue.main.async { block(sheet) }
371
- }
372
- }
373
- }
374
-
375
- private func withPaymentSheet(_ rootTag: NSNumber, _ block: @escaping (UIViewController?, PaymentSheet?) -> Void) {
376
- guard let bridge = self.bridge else { return }
377
- RCTGetUIManagerQueue().async {
378
- bridge.uiManager.addUIBlock { _, viewRegistry in
379
- let view = viewRegistry?[rootTag]
380
- let vc = view?.reactViewController() as? HyperUIViewController
381
- let sheet = vc?.paymentSheet
382
- DispatchQueue.main.async { block(vc, sheet) }
383
- }
384
- }
385
- }
316
+ // MARK: - Bridge-backed view lookup helpers (commented out for new-arch/bridgeless build)
317
+
318
+ // private func withWidget(_ rootTag: NSNumber, _ block: @escaping (PaymentWidget) -> Void) {
319
+ // guard let bridge = self.bridge else { return }
320
+ // RCTGetUIManagerQueue().async {
321
+ // bridge.uiManager.addUIBlock { _, viewRegistry in
322
+ // guard let view = viewRegistry?[rootTag] else { return }
323
+ // var current: UIView? = view
324
+ // while let v = current {
325
+ // if let widget = v as? PaymentWidget {
326
+ // block(widget)
327
+ // return
328
+ // }
329
+ // current = v.superview
330
+ // }
331
+ // }
332
+ // }
333
+ // }
334
+ //
335
+ // private func withNativePaymentWidgetView(_ rootTag: NSNumber, _ block: @escaping (PaymentWidget) -> Void) {
336
+ // guard let bridge = self.bridge else { return }
337
+ // RCTGetUIManagerQueue().async {
338
+ // bridge.uiManager.addUIBlock { _, viewRegistry in
339
+ // guard let view = viewRegistry?[rootTag] else { return }
340
+ // var current: UIView? = view
341
+ // while let v = current {
342
+ // if let nativeWidget = v as? PaymentWidget {
343
+ // block(nativeWidget)
344
+ // return
345
+ // }
346
+ // current = v.superview
347
+ // }
348
+ // }
349
+ // }
350
+ // }
351
+ //
352
+ // private func resolveSubscribingTarget(_ rootTag: NSNumber, _ block: @escaping (AnyObject?) -> Void) {
353
+ // guard let bridge = self.bridge else {
354
+ // DispatchQueue.main.async { block(nil) }
355
+ // return
356
+ // }
357
+ // RCTGetUIManagerQueue().async {
358
+ // bridge.uiManager.addUIBlock { _, viewRegistry in
359
+ // guard let view = viewRegistry?[rootTag] else {
360
+ // DispatchQueue.main.async { block(nil) }
361
+ // return
362
+ // }
363
+ // var current: UIView? = view
364
+ // while let v = current {
365
+ // if v is PaymentWidget || v is CVCWidget {
366
+ // DispatchQueue.main.async { block(v) }
367
+ // return
368
+ // }
369
+ // current = v.superview
370
+ // }
371
+ // let sheet = (view.reactViewController() as? HyperUIViewController)?.paymentSheet
372
+ // DispatchQueue.main.async { block(sheet) }
373
+ // }
374
+ // }
375
+ // }
376
+ //
377
+ // private func withPaymentSheet(_ rootTag: NSNumber, _ block: @escaping (UIViewController?, PaymentSheet?) -> Void) {
378
+ // guard let bridge = self.bridge else { return }
379
+ // RCTGetUIManagerQueue().async {
380
+ // bridge.uiManager.addUIBlock { _, viewRegistry in
381
+ // let view = viewRegistry?[rootTag]
382
+ // let vc = view?.reactViewController() as? HyperUIViewController
383
+ // let sheet = vc?.paymentSheet
384
+ // DispatchQueue.main.async { block(vc, sheet) }
385
+ // }
386
+ // }
387
+ // }
386
388
  }
@@ -16,8 +16,9 @@
16
16
  // runtime under-initialised, so `getEnforcing('DeviceInfo')` fails and the bundle
17
17
  // can't boot — the sheet renders blank.
18
18
  //
19
- // We keep the *bridge* alive by overriding `bridgelessEnabled` false, because
20
- // the SDK's widget commands still use `bridge.enqueueJSCall` / `bridge.uiManager`.
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.
21
22
  //
22
23
  // Created by Shivam Shashank on 09/11/22.
23
24
  //
@@ -34,9 +35,8 @@ internal class RNViewManager: RCTDefaultReactNativeFactoryDelegate {
34
35
 
35
36
  private var reactNativeFactory: RCTReactNativeFactory?
36
37
 
37
- /// Captured when the embedded bridge loads its JS source (see `sourceURL(for:)`).
38
- /// The host app is bridgeless, so this embedded bridge is the SDK's only bridge.
39
- private weak var capturedBridge: RCTBridge?
38
+ // Bridge capture removed for the payment-sheet-only/bridgeless build.
39
+ // private weak var capturedBridge: RCTBridge?
40
40
 
41
41
  internal static let sharedInstance = RNViewManager()
42
42
 
@@ -54,9 +54,9 @@ internal class RNViewManager: RCTDefaultReactNativeFactoryDelegate {
54
54
  /// The bridge backing the embedded runtime. Kept for the SDK's widget commands
55
55
  /// (`bridge.enqueueJSCall` / `bridge.uiManager`). Available after the first view
56
56
  /// is created.
57
- internal var bridge: RCTBridge? {
58
- return capturedBridge
59
- }
57
+ // internal var bridge: RCTBridge? {
58
+ // return capturedBridge
59
+ // }
60
60
 
61
61
  internal func viewForModule(_ moduleName: String, initialProperties: [String: Any]?) -> UIView {
62
62
  let view = factory().rootViewFactory.view(
@@ -76,8 +76,8 @@ internal class RNViewManager: RCTDefaultReactNativeFactoryDelegate {
76
76
 
77
77
  // MARK: - Arch configuration
78
78
 
79
- /// Keep the legacy bridge alive (Fabric-on-bridge) so the SDK's
80
- /// `bridge.enqueueJSCall` / `bridge.uiManager` widget commands keep working.
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
81
  public override func bridgelessEnabled() -> Bool {
82
82
  return false
83
83
  }
@@ -88,7 +88,7 @@ internal class RNViewManager: RCTDefaultReactNativeFactoryDelegate {
88
88
  override func sourceURL(for bridge: RCTBridge) -> URL? {
89
89
  // Called while the embedded bridge loads its JS — capture it for the SDK's
90
90
  // bridge-dependent widget commands.
91
- self.capturedBridge = bridge
91
+ // self.capturedBridge = bridge
92
92
  return bundleURL()
93
93
  }
94
94
 
@@ -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 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;
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{status:u(t.status),type:t.type??t.status??t.code??"",message:t.message??t.status??t.code??""}}async function y(e){if(i)return{status:"failed",type:"initialization_in_progress",message:"SDK is reloading. Please wait for initialisation to complete before presenting the payment sheet."};if(o)return{status:"canceled",type:"sheet_already_presented",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;
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: 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
+ {"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 code?: string;\n type?: 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['status'] {\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 status: mapStatus(parsed.status),\n type: parsed.type ?? parsed.status ?? parsed.code ?? \"\",\n message: parsed.message ?? parsed.status ?? parsed.code ?? \"\",\n };\n}\n\nexport async function presentPaymentSheetWithPayload(\n payload: NativePaymentSheetPayload\n): Promise<PaymentResult> {\n if (isInitializing()) {\n return {\n status: 'failed',\n type: 'initialization_in_progress',\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 status: 'canceled',\n type: 'sheet_already_presented',\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","code","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{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};
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{status:l(t.status),type:t.type??t.status??t.code??"",message:t.message??t.status??t.code??""}}async function m(e){if(o)return{status:"failed",type:"initialization_in_progress",message:"SDK is reloading. Please wait for initialisation to complete before presenting the payment sheet."};if(c)return{status:"canceled",type:"sheet_already_presented",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 d(e){}function f(e,t){return{presentPaymentSheet:async n=>m(a(e,t,n)),async confirmPayment(e,t){},getCustomerSavedPaymentMethods:async n=>i(e,t,n),updateIntent:d}}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:d};var n,s},elements:async t=>({...f(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: 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
+ {"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 code?: string;\n type?: 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['status'] {\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 status: mapStatus(parsed.status),\n type: parsed.type ?? parsed.status ?? parsed.code ?? \"\",\n message: parsed.message ?? parsed.status ?? parsed.code ?? \"\",\n };\n}\n\nexport async function presentPaymentSheetWithPayload(\n payload: NativePaymentSheetPayload\n): Promise<PaymentResult> {\n if (isInitializing()) {\n return {\n status: 'failed',\n type: 'initialization_in_progress',\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 status: 'canceled',\n type: 'sheet_already_presented',\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","code","presentPaymentSheetWithPayload","presentPaymentSheet","updateIntent","_intentResolver","createElementsNativeActions","confirmPayment","paymentElementRef","_confirmOptions","loadHyper","config","initialise","publishableKey","profileId","environment","customEndpoints","then","initPaymentSession","options","catch","error","Hyperswitch","init"],"mappings":"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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-hyperswitch-dev-sdk",
3
- "version": "0.4.4",
3
+ "version": "0.4.6",
4
4
  "description": "Hyperswitch SDK for React Native",
5
5
  "main": "lib/commonjs/index.bundle.js",
6
6
  "module": "lib/module/index.bundle.js",
@@ -59,13 +59,13 @@
59
59
  ],
60
60
  "repository": {
61
61
  "type": "git",
62
- "url": "https://github.com/manideepk90/react-native-hyperswitch-sdk",
62
+ "url": "https://github.com/juspay/react-native-hyperswitch",
63
63
  "directory": "packages/react-native-hyperswitch"
64
64
  },
65
65
  "author": "Hyperswitch",
66
66
  "license": "Apache-2.0",
67
67
  "bugs": {
68
- "url": "https://github.com/manideepk90/react-native-hyperswitch-sdk"
68
+ "url": "https://github.com/juspay/react-native-hyperswitch/issues"
69
69
  },
70
70
  "homepage": "https://hyperswitch.io",
71
71
  "publishConfig": {
@@ -14,6 +14,8 @@ import { isInitializing, isSheetPresented, setSheetPresented } from '../utils/In
14
14
  interface NativeResponse {
15
15
  status: string;
16
16
  message: string;
17
+ code?: string;
18
+ type?: string;
17
19
  data?: any;
18
20
  }
19
21
 
@@ -30,7 +32,7 @@ export function parseNativeResponse(
30
32
  }
31
33
  }
32
34
 
33
- export function mapStatus(status: string): PaymentResult['type'] {
35
+ export function mapStatus(status: string): PaymentResult['status'] {
34
36
  switch (status) {
35
37
  case 'succeeded':
36
38
  case 'completed':
@@ -51,8 +53,9 @@ export function mapNativeResponseToPaymentResult(
51
53
  ): PaymentResult {
52
54
  const parsed = parseNativeResponse(raw);
53
55
  return {
54
- type: mapStatus(parsed.status),
55
- message: parsed.message,
56
+ status: mapStatus(parsed.status),
57
+ type: parsed.type ?? parsed.status ?? parsed.code ?? "",
58
+ message: parsed.message ?? parsed.status ?? parsed.code ?? "",
56
59
  };
57
60
  }
58
61
 
@@ -61,7 +64,8 @@ export async function presentPaymentSheetWithPayload(
61
64
  ): Promise<PaymentResult> {
62
65
  if (isInitializing()) {
63
66
  return {
64
- type: 'failed',
67
+ status: 'failed',
68
+ type: 'initialization_in_progress',
65
69
  message: 'SDK is reloading. Please wait for initialisation to complete before presenting the payment sheet.',
66
70
  };
67
71
  }
@@ -69,19 +73,18 @@ export async function presentPaymentSheetWithPayload(
69
73
  // A sheet is already open (e.g. a hot-reload fired while the sheet was visible).
70
74
  // Silently skip so the existing sheet is not covered by a new one.
71
75
  return {
72
- type: 'canceled',
76
+ status: 'canceled',
77
+ type: 'sheet_already_presented',
73
78
  message: 'A payment sheet is already presented.',
74
79
  };
75
80
  }
76
81
  setSheetPresented(true);
77
82
  try {
78
- console.log('Presenting payment sheet with payload:', payload);
79
83
  const raw = await NativeHyperswitchModule.presentPaymentSheet({
80
84
  hyperswitchConfig: payload.hyperswitchConfig,
81
85
  paymentSessionConfig: payload.paymentSessionConfig,
82
86
  configuration: payload.configuration,
83
87
  });
84
- console.log('Native response from presentPaymentSheet:', raw);
85
88
  return mapNativeResponseToPaymentResult(raw);
86
89
  } finally {
87
90
  setSheetPresented(false);
@@ -1,4 +1,5 @@
1
1
  export interface PaymentResult {
2
- type: 'completed' | 'canceled' | 'failed';
2
+ status: 'completed' | 'canceled' | 'failed';
3
+ type?: string;
3
4
  message?: string;
4
5
  }