@juspay-tech/react-native-hyperswitch 1.3.4 → 1.3.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.
- package/android/build.gradle +22 -1
- package/android/src/main/assets/hyperswitch.bundle +590 -590
- package/android/src/main/java/com/hyperswitchsdkreactnative/modules/NativeLog.kt +107 -0
- package/android/src/main/java/com/hyperswitchsdkreactnative/modules/ReactNativeHyperswitchModule.kt +318 -117
- package/android/src/main/java/io/hyperswitch/paymentsession/ExitHeadlessCallBackManager.kt +4 -2
- package/android/src/main/java/io/hyperswitch/paymentsession/PaymentSessionHandlerImpl.kt +20 -4
- package/android/src/main/java/io/hyperswitch/paymentsession/PaymentSessionReactLauncher.kt +104 -9
- package/android/src/main/java/io/hyperswitch/paymentsheet/PaymentResult.kt +7 -1
- package/android/src/main/java/io/hyperswitch/react/HyperModule.kt +13 -0
- package/android/src/main/java/io/hyperswitch/view/PaymentWidgetView.kt +27 -4
- package/android/src/rn79/assets/hyperswitch.bundle +590 -590
- package/android/src/rn79/java/io/hyperswitch/react/HyperFragment.kt +20 -0
- package/android/src/rn81/java/io/hyperswitch/react/HyperFragment.kt +20 -0
- package/ios/Modules/ReactNative/NativeHyperswitchModuleImpl.swift +3 -1
- package/ios/hyperswitchSDK/Core/ApplePay/ApplePayHandler.swift +49 -38
- package/ios/hyperswitchSDK/Core/HyperPaymentSheet/PaymentSheetView+UIKit.swift +1 -5
- package/ios/hyperswitchSDK/Core/NativeModule/HyperModuleImpl.swift +49 -34
- package/ios/hyperswitchSDK/Core/NativeModule/RNHeadlessManager.swift +2 -12
- package/ios/hyperswitchSDK/Core/Resources/hyperswitch-rn82plus.bundle +590 -590
- package/ios/hyperswitchSDK/Core/Resources/hyperswitch.bundle +590 -590
- package/ios/hyperswitchSDK/Shared/Environment.swift +49 -3
- package/ios/hyperswitchSDK/Shared/HyperswitchEnvironment.swift +1 -0
- package/ios/hyperswitchSDK/Shared/NativeLogger/LogBuilder.swift +15 -0
- package/ios/hyperswitchSDK/Shared/NativeLogger/LogManager.swift +10 -2
- package/ios/hyperswitchSDK/Shared/NativeLogger/LogPayload.swift +1 -0
- package/ios/hyperswitchSDK/Shared/NativeLogger/NativeLog.swift +101 -0
- package/ios/hyperswitchSDK/Shared/PaymentSession.swift +8 -1
- package/lib/commonjs/index.bundle.js +2 -2
- package/lib/commonjs/index.bundle.js.map +1 -1
- package/lib/module/index.bundle.js +2 -2
- package/lib/module/index.bundle.js.map +1 -1
- package/lib/typescript/src/context/HyperElements.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/native/NativeResponseMapper.d.ts +2 -1
- package/lib/typescript/src/native/NativeResponseMapper.d.ts.map +1 -1
- package/lib/typescript/src/session/SavedPaymentMethods.d.ts.map +1 -1
- package/lib/typescript/src/session/presentPaymentSheet.d.ts +0 -12
- package/lib/typescript/src/session/presentPaymentSheet.d.ts.map +1 -1
- package/lib/typescript/src/views/PaymentElement.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/context/HyperElements.tsx +7 -6
- package/src/index.ts +9 -1
- package/src/native/NativeResponseMapper.ts +20 -4
- package/src/session/SavedPaymentMethods.ts +10 -2
- package/src/session/presentPaymentSheet.ts +7 -1
- package/src/views/PaymentElement.tsx +17 -8
|
@@ -10,15 +10,61 @@ import Foundation
|
|
|
10
10
|
enum SDKEnvironment {
|
|
11
11
|
case PROD, SANDBOX
|
|
12
12
|
|
|
13
|
+
// Bare hosts; the API path is appended separately (mirrors GlobalHooks.res).
|
|
14
|
+
private static let prodHost = "https://live.hyperswitch.io"
|
|
15
|
+
private static let sandboxHost = "https://app.hyperswitch.io"
|
|
16
|
+
private static let integHost = "https://integ.hyperswitch.io"
|
|
17
|
+
private static let backendPath = "/api"
|
|
18
|
+
private static let logsPath = "/api/logs/sdk"
|
|
19
|
+
|
|
13
20
|
static func getEnvironment(_ publishableKey: String) -> SDKEnvironment {
|
|
14
21
|
return publishableKey.contains("_snd_") ? .SANDBOX : .PROD
|
|
15
22
|
}
|
|
16
23
|
|
|
17
24
|
static func baseURL(for publishableKey: String) -> String {
|
|
18
|
-
return
|
|
25
|
+
return host(for: publishableKey) + backendPath
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/// Resolves the logging endpoint with the same precedence as GlobalHooks.res:
|
|
29
|
+
/// 1. `overrideEndpoints.customLoggingEndpoint`, used exactly as given
|
|
30
|
+
/// 2. `commonEndpoint` (a bare host) + `/api/logs/sdk`
|
|
31
|
+
/// 3. the explicit `environment`'s host (PROD, SANDBOX or INTEG) + `/api/logs/sdk`
|
|
32
|
+
/// 4. the host implied by the publishable key + `/api/logs/sdk`
|
|
33
|
+
static func loggingURL(
|
|
34
|
+
for publishableKey: String,
|
|
35
|
+
environment: HyperswitchEnvironment? = nil,
|
|
36
|
+
customEndpoints: CustomEndpointConfiguration? = nil
|
|
37
|
+
) -> String {
|
|
38
|
+
switch customEndpoints {
|
|
39
|
+
case .overrideEndpoints(let config)?:
|
|
40
|
+
if let url = config.customLoggingEndpoint?.trimmingCharacters(in: .whitespaces), !url.isEmpty {
|
|
41
|
+
return url
|
|
42
|
+
}
|
|
43
|
+
case .commonEndpoint(let common)?:
|
|
44
|
+
let host = common.trimmingCharacters(in: .whitespaces)
|
|
45
|
+
if !host.isEmpty {
|
|
46
|
+
return host.trimmingTrailingSlashes() + logsPath
|
|
47
|
+
}
|
|
48
|
+
case nil:
|
|
49
|
+
break
|
|
50
|
+
}
|
|
51
|
+
return host(for: publishableKey, environment: environment) + logsPath
|
|
19
52
|
}
|
|
20
53
|
|
|
21
|
-
static func
|
|
22
|
-
|
|
54
|
+
private static func host(for publishableKey: String, environment: HyperswitchEnvironment? = nil) -> String {
|
|
55
|
+
switch environment {
|
|
56
|
+
case .production?: return prodHost
|
|
57
|
+
case .sandbox?: return sandboxHost
|
|
58
|
+
case .integ?: return integHost
|
|
59
|
+
case nil: return getEnvironment(publishableKey) == .PROD ? prodHost : sandboxHost
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
private extension String {
|
|
65
|
+
func trimmingTrailingSlashes() -> String {
|
|
66
|
+
var result = self
|
|
67
|
+
while result.hasSuffix("/") { result.removeLast() }
|
|
68
|
+
return result
|
|
23
69
|
}
|
|
24
70
|
}
|
|
@@ -78,6 +78,21 @@ internal class LogBuilder {
|
|
|
78
78
|
return self
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
+
func setInternalMetadata(_ internalMetadata: String) -> LogBuilder {
|
|
82
|
+
self.internalMetadata = internalMetadata
|
|
83
|
+
return self
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
func setAppId(_ appId: String?) -> LogBuilder {
|
|
87
|
+
self.appId = appId
|
|
88
|
+
return self
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
func setSource(_ source: String) -> LogBuilder {
|
|
92
|
+
self.source = source
|
|
93
|
+
return self
|
|
94
|
+
}
|
|
95
|
+
|
|
81
96
|
func setSessionId(_ sessionId: String) -> LogBuilder {
|
|
82
97
|
self.sessionId = sessionId
|
|
83
98
|
return self
|
|
@@ -25,10 +25,18 @@ final class LogManager {
|
|
|
25
25
|
return logBatch.compactMap { $0.toJson() }
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
static func initialize(
|
|
28
|
+
static func initialize(
|
|
29
|
+
publishableKey: String,
|
|
30
|
+
environment: HyperswitchEnvironment? = nil,
|
|
31
|
+
customEndpoints: CustomEndpointConfiguration? = nil
|
|
32
|
+
) {
|
|
29
33
|
queue.async {
|
|
30
34
|
self.publishableKey = publishableKey
|
|
31
|
-
self.loggingEndPoint = SDKEnvironment.loggingURL(
|
|
35
|
+
self.loggingEndPoint = SDKEnvironment.loggingURL(
|
|
36
|
+
for: publishableKey,
|
|
37
|
+
environment: environment,
|
|
38
|
+
customEndpoints: customEndpoints
|
|
39
|
+
)
|
|
32
40
|
}
|
|
33
41
|
if !publishableKey.isEmpty {
|
|
34
42
|
sendLogsFromFile()
|
|
@@ -53,6 +53,7 @@ enum EventName: String, Codable {
|
|
|
53
53
|
case hyperOTAInit = "HYPER_OTA_INIT"
|
|
54
54
|
case hyperOTAFinish = "HYPER_OTA_FINISH"
|
|
55
55
|
case hyperOTAEvent = "HYPER_OTA_EVENT"
|
|
56
|
+
case rnSdkLifeCycle = "RN_SDK_LIFE_CYCLE"
|
|
56
57
|
|
|
57
58
|
case authenticationSessionInit = "AUTHENTICATION_SESSION_INIT"
|
|
58
59
|
case authenticationSessionReturned = "AUTHENTICATION_SESSION_RETURNED"
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
//
|
|
2
|
+
// NativeLog.swift
|
|
3
|
+
// hyperswitch
|
|
4
|
+
//
|
|
5
|
+
|
|
6
|
+
import Foundation
|
|
7
|
+
import UIKit
|
|
8
|
+
|
|
9
|
+
/// Native SDK lifecycle logs sent through `LogManager`. Same shape as Android's `NativeLog`:
|
|
10
|
+
/// - event_name RN_SDK_LIFE_CYCLE
|
|
11
|
+
/// - value a stable snake_case event id (filterable, no variable data)
|
|
12
|
+
/// - internal_metadata a JSON object with the event's details, plus `app_state` and `orientation`
|
|
13
|
+
/// - source "native"
|
|
14
|
+
///
|
|
15
|
+
/// Never throws. Builds on the main thread because it reads UIKit state.
|
|
16
|
+
internal enum NativeLog {
|
|
17
|
+
private static let source = "native"
|
|
18
|
+
|
|
19
|
+
/// Payment of the latest session the SDK was asked about; nil until the first one.
|
|
20
|
+
private static var paymentId: String?
|
|
21
|
+
private static let paymentIdLock = NSLock()
|
|
22
|
+
|
|
23
|
+
/// Every later log carries the payment id read from `sdkAuthorization`.
|
|
24
|
+
static func setSdkAuthorization(_ sdkAuthorization: String?) {
|
|
25
|
+
let id = paymentId(from: sdkAuthorization)
|
|
26
|
+
paymentIdLock.lock()
|
|
27
|
+
paymentId = id
|
|
28
|
+
paymentIdLock.unlock()
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
private static func currentPaymentId() -> String {
|
|
32
|
+
paymentIdLock.lock()
|
|
33
|
+
defer { paymentIdLock.unlock() }
|
|
34
|
+
return paymentId ?? ""
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/// Same rule as client-core's Utils.getSdkAuthorizationData: base64 "key=value,..." pairs,
|
|
38
|
+
/// payment_id, else the client_secret part before "_secret_".
|
|
39
|
+
private static func paymentId(from sdkAuthorization: String?) -> String? {
|
|
40
|
+
guard var base64 = sdkAuthorization, !base64.isEmpty else { return nil }
|
|
41
|
+
base64 += String(repeating: "=", count: (4 - base64.count % 4) % 4)
|
|
42
|
+
guard let data = Data(base64Encoded: base64),
|
|
43
|
+
let decoded = String(data: data, encoding: .utf8) else { return nil }
|
|
44
|
+
var fields: [String: String] = [:]
|
|
45
|
+
for pair in decoded.split(separator: ",") {
|
|
46
|
+
guard let i = pair.firstIndex(of: "="), i != pair.startIndex else { continue }
|
|
47
|
+
fields[String(pair[..<i])] = String(pair[pair.index(after: i)...])
|
|
48
|
+
}
|
|
49
|
+
if let id = fields["payment_id"], !id.isEmpty { return id }
|
|
50
|
+
guard let secret = fields["client_secret"] else { return nil }
|
|
51
|
+
let id = secret.components(separatedBy: "_secret_")[0]
|
|
52
|
+
return id.isEmpty ? nil : id
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
static func debug(_ event: String, _ details: [String: Any?] = [:]) { send(.DEBUG, event, details) }
|
|
56
|
+
static func warning(_ event: String, _ details: [String: Any?] = [:]) { send(.WARNING, event, details) }
|
|
57
|
+
static func error(_ event: String, _ details: [String: Any?] = [:]) { send(.ERROR, event, details) }
|
|
58
|
+
|
|
59
|
+
private static func send(_ type: LogType, _ event: String, _ details: [String: Any?]) {
|
|
60
|
+
let build = {
|
|
61
|
+
var metadata: [String: Any] = details.compactMapValues { $0 }
|
|
62
|
+
metadata["app_state"] = appState()
|
|
63
|
+
metadata["orientation"] = orientation()
|
|
64
|
+
let json = (try? JSONSerialization.data(withJSONObject: metadata, options: [.sortedKeys]))
|
|
65
|
+
.flatMap { String(data: $0, encoding: .utf8) } ?? ""
|
|
66
|
+
let log = LogBuilder()
|
|
67
|
+
.setLogType(type.rawValue)
|
|
68
|
+
.setCategory(.API)
|
|
69
|
+
.setEventName(.rnSdkLifeCycle)
|
|
70
|
+
.setValue(event)
|
|
71
|
+
.setPaymentId(currentPaymentId())
|
|
72
|
+
.setInternalMetadata(json)
|
|
73
|
+
.setAppId(Bundle.main.bundleIdentifier)
|
|
74
|
+
.setSource(source)
|
|
75
|
+
.build()
|
|
76
|
+
LogManager.addLog(log)
|
|
77
|
+
}
|
|
78
|
+
if Thread.isMainThread { build() } else { DispatchQueue.main.async(execute: build) }
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
private static func appState() -> String {
|
|
82
|
+
switch UIApplication.shared.applicationState {
|
|
83
|
+
case .active: return "active"
|
|
84
|
+
case .inactive: return "inactive"
|
|
85
|
+
case .background: return "background"
|
|
86
|
+
@unknown default: return "unknown"
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
private static func orientation() -> String {
|
|
91
|
+
let scenes = UIApplication.shared.connectedScenes.compactMap { $0 as? UIWindowScene }
|
|
92
|
+
let scene = scenes.first { $0.activationState == .foregroundActive } ?? scenes.first
|
|
93
|
+
switch scene?.interfaceOrientation {
|
|
94
|
+
case .portrait: return "portrait"
|
|
95
|
+
case .portraitUpsideDown: return "portraitUpsideDown"
|
|
96
|
+
case .landscapeLeft: return "landscapeLeft"
|
|
97
|
+
case .landscapeRight: return "landscapeRight"
|
|
98
|
+
default: return "unknown"
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
@@ -34,11 +34,17 @@ public class PaymentSession {
|
|
|
34
34
|
internal init(paymentSessionConfiguration: PaymentSessionConfiguration, hyperswitchConfiguration: HyperswitchConfiguration? = nil) {
|
|
35
35
|
self.paymentSessionConfiguration = paymentSessionConfiguration
|
|
36
36
|
self.hyperswitchConfiguration = hyperswitchConfiguration
|
|
37
|
+
NativeLog.setSdkAuthorization(paymentSessionConfiguration.sdkAuthorization)
|
|
37
38
|
|
|
38
39
|
if let hyperswitchConfiguration = hyperswitchConfiguration {
|
|
40
|
+
NativeLog.debug("sdk_initialised", ["environment": hyperswitchConfiguration.environment?.rawValue])
|
|
39
41
|
#if canImport(HyperOTA)
|
|
40
42
|
OTAServices.shared.initialize(publishableKey: hyperswitchConfiguration.publishableKey)
|
|
41
|
-
LogManager.initialize(
|
|
43
|
+
LogManager.initialize(
|
|
44
|
+
publishableKey: hyperswitchConfiguration.publishableKey,
|
|
45
|
+
environment: hyperswitchConfiguration.environment,
|
|
46
|
+
customEndpoints: hyperswitchConfiguration.customEndpoints
|
|
47
|
+
)
|
|
42
48
|
#endif
|
|
43
49
|
}
|
|
44
50
|
}
|
|
@@ -71,6 +77,7 @@ public class PaymentSession {
|
|
|
71
77
|
// MARK: workaround
|
|
72
78
|
authorizationProvider { [weak self] sdkAuthorization in
|
|
73
79
|
self?.paymentSessionConfiguration = PaymentSessionConfiguration(sdkAuthorization: sdkAuthorization)
|
|
80
|
+
NativeLog.setSdkAuthorization(sdkAuthorization)
|
|
74
81
|
completion(UpdateIntentResult.success)
|
|
75
82
|
}
|
|
76
83
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react-native"),t=require("react");const n=e.TurboModuleRegistry.get("NativeHyperswitchModule")??e.NativeModules.NativeHyperswitchModule,r=e.TurboModuleRegistry.get("NativeWidgetHelperModule")??e.NativeModules.NativeWidgetHelperModule;function o(e){switch(e){case"succeeded":case"completed":case"requires_capture":case"success":return"completed";case"cancelled":case"canceled":return"canceled";default:return"failed"}}
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react-native"),t=require("react");const n=e.TurboModuleRegistry.get("NativeHyperswitchModule")??e.NativeModules.NativeHyperswitchModule,r=e.TurboModuleRegistry.get("NativeWidgetHelperModule")??e.NativeModules.NativeWidgetHelperModule;function o(e){if("object"==typeof e&&null!==e)return e;try{return JSON.parse(e)}catch{return{status:"failed",message:String(e)}}}function a(...e){for(const t of e)if("string"==typeof t&&""!==t.trim())return t}function i(e){const t=o(e),n=function(e){switch(e){case"succeeded":case"completed":case"requires_capture":case"success":return"completed";case"cancelled":case"canceled":return"canceled";default:return"failed"}}(t.status),r=a(t.message,t.error,t.code);return{status:n,type:a(t.type,t.code,n)??"",message:r??("failed"===n?"The payment failed but no error detail was returned.":"")}}const s=new Map;function l(e,t){s.set(e,t)}function u(e){s.delete(e)}function c(e){const t=[...s.values()].map(t=>new Promise(n=>{r.updateIntentCompleteForWidget(t,e,e=>n(i(e)))}));return Promise.all(t)}let y=!1;function d(e){y=e}let f=!1;function p(e){f=e}let m=0;async function g(e){if(y)return{status:"failed",type:"initialization_in_progress",message:"SDK is reloading. Please wait for initialisation to complete before presenting the payment sheet."};if(f)return{status:"canceled",type:"sheet_already_presented",message:"A payment sheet is already presented."};const t=++m;p(!0);try{return i(await n.presentPaymentSheet({hyperswitchConfig:e.hyperswitchConfig,paymentSessionConfig:e.paymentSessionConfig,configuration:e.configuration}))}finally{t===m&&p(!1)}}function h(e){if(!e)throw new Error("A widgetId is required to confirm a saved payment method");const t=function(e){return s.get(e)}(e);if(void 0===t)throw new Error(`Widget ${e} not found or not mounted`);return t}function b(e){if(null==e||"string"!=typeof e)return e??null;try{return JSON.parse(e)}catch{return null}}function v(e){try{const t=JSON.parse(e);return{...t,billing:b(t.billing)}}catch{return null}}async function S(e,t,r){const a={hyperswitchConfig:e,paymentSessionConfig:t,configuration:{...r,paymentMethodLayout:{savedMethodCustomization:{hiddenPaymentMethods:r?.hiddenPaymentMethods??[]}}}},s=await n.getCustomerSavedPaymentMethods(a),{status:l,code:u,message:c}=o(s);if("failed"===l||"error"===u)throw new Error(c??"Failed to load saved payment methods");return{getCustomerLastUsedPaymentMethodData:async()=>v(await n.getCustomerLastUsedPaymentMethodData()),getCustomerDefaultSavedPaymentMethodData:async()=>v(await n.getCustomerDefaultSavedPaymentMethodData()),getCustomerSavedPaymentMethodData:async()=>v(await n.getCustomerSavedPaymentMethodData()),confirmWithCustomerLastUsedPaymentMethod:async e=>i(await n.confirmWithCustomerLastUsedPaymentMethod(h(e?.id))),confirmWithCustomerDefaultPaymentMethod:async e=>i(await n.confirmWithCustomerDefaultPaymentMethod(h(e?.id)))}}async function w(e,t){const r=await(o=n.getWalletSession({hyperswitchConfig:e,paymentSessionConfig:t}),a="getWalletSession",new Promise((e,t)=>{const n=setTimeout(()=>{t(new Error(`${a} timed out after 15000ms`))},15e3);o.then(t=>{clearTimeout(n),e(t)},e=>{clearTimeout(n),t(e)})}));var o,a;let s,l;try{const e=JSON.parse(r);s=e.status,l=e.message}catch{s=void 0}if("failed"===s)throw new Error(l??"Failed to initialise the wallet session");return{isWalletEligible:e=>n.isWalletEligible(e).catch(()=>!1),isGooglePayEligible:()=>n.isWalletEligible("google_pay").catch(()=>!1),isApplePayEligible:()=>n.isWalletEligible("apple_pay").catch(()=>!1),launchWallet:async e=>i(await n.launchWallet(e)),launchGooglePay:async()=>i(await n.launchWallet("google_pay")),launchApplePay:async()=>i(await n.launchWallet("apple_pay"))}}function P(e){return async function(t){const n=function(e,t,n){const r={...e};return delete r.platformPublishableKey,{hyperswitchConfig:r,paymentSessionConfig:t,configuration:n??{}}}(e.hyperswitchConfig,e.paymentSessionConfig,t);return g(n)}}function E(e){return function(t){return S(e.hyperswitchConfig,e.paymentSessionConfig,t)}}function C(e){return function(){return w(e.hyperswitchConfig,e.paymentSessionConfig)}}async function _(e){let t;try{await function(){const e=[...s.values()].map(e=>new Promise(t=>{r.updateIntentInitForWidget(e,e=>t(i(e)))}));return Promise.all(e)}(),t=await e(),await c(t.sdkAuthorization)}catch{return void await c("")}}function k(e,t){const n={hyperswitchConfig:e,paymentSessionConfig:t};return{presentPaymentSheet:P(n),async confirmPayment(e,t){if("string"==typeof e){return i(await function(e){const t=s.get(e);return void 0===t?Promise.resolve(JSON.stringify({status:"failed",message:`Widget ${e} not found or not mounted`,type:void 0})):new Promise(e=>{r.confirmPayment(t,e)})}(e))}const n=e.current;if(!n)throw new Error("PaymentElement reference is not mounted");return n.confirmPayment(t)},getCustomerSavedPaymentMethods:E(n),getWalletSession:C(n),updateIntent:_}}var R,N={exports:{}},O={};var A,T,x={};
|
|
2
2
|
/**
|
|
3
3
|
* @license React
|
|
4
4
|
* react-jsx-runtime.development.js
|
|
@@ -7,5 +7,5 @@
|
|
|
7
7
|
*
|
|
8
8
|
* This source code is licensed under the MIT license found in the
|
|
9
9
|
* LICENSE file in the root directory of this source tree.
|
|
10
|
-
*/function T(){return N||(N=1,"production"!==process.env.NODE_ENV&&function(){function e(t){if(null==t)return null;if("function"==typeof t)return t.$$typeof===_?null:t.displayName||t.name||null;if("string"==typeof t)return t;switch(t){case d:return"Fragment";case g:return"Profiler";case m:return"StrictMode";case S:return"Suspense";case w:return"SuspenseList";case C:return"Activity"}if("object"==typeof t)switch("number"==typeof t.tag&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),t.$$typeof){case f:return"Portal";case b:return t.displayName||"Context";case h:return(t._context.displayName||"Context")+".Consumer";case v:var n=t.render;return(t=t.displayName)||(t=""!==(t=n.displayName||n.name||"")?"ForwardRef("+t+")":"ForwardRef"),t;case P:return null!==(n=t.displayName||null)?n:e(t.type)||"Memo";case E:n=t._payload,t=t._init;try{return e(t(n))}catch(e){}}return null}function n(e){return""+e}function r(e){try{n(e);var t=!1}catch(e){t=!0}if(t){var r=(t=console).error,o="function"==typeof Symbol&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object";return r.call(t,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",o),n(e)}}function o(t){if(t===d)return"<>";if("object"==typeof t&&null!==t&&t.$$typeof===E)return"<...>";try{var n=e(t);return n?"<"+n+">":"<...>"}catch(e){return"<...>"}}function a(){return Error("react-stack-top-frame")}function i(){var t=e(this.type);return T[t]||(T[t]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),void 0!==(t=this.props.ref)?t:null}function s(t,n,o,a,s,u){var y,f=n.children;if(void 0!==f)if(a)if(N(f)){for(a=0;a<f.length;a++)l(f[a]);Object.freeze&&Object.freeze(f)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else l(f);if(R.call(n,"key")){f=e(t);var d=Object.keys(n).filter(function(e){return"key"!==e});a=0<d.length?"{key: someKey, "+d.join(": ..., ")+": ...}":"{key: someKey}",j[f+a]||(d=0<d.length?"{"+d.join(": ..., ")+": ...}":"{}",console.error('A props object containing a "key" prop is being spread into JSX:\n let props = %s;\n <%s {...props} />\nReact keys must be passed directly to JSX without using spread:\n let props = %s;\n <%s key={someKey} {...props} />',a,f,d,f),j[f+a]=!0)}if(f=null,void 0!==o&&(r(o),f=""+o),function(e){if(R.call(e,"key")){var t=Object.getOwnPropertyDescriptor(e,"key").get;if(t&&t.isReactWarning)return!1}return void 0!==e.key}(n)&&(r(n.key),f=""+n.key),"key"in n)for(var m in o={},n)"key"!==m&&(o[m]=n[m]);else o=n;return f&&function(e,t){function n(){c||(c=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",t))}n.isReactWarning=!0,Object.defineProperty(e,"key",{get:n,configurable:!0})}(o,"function"==typeof t?t.displayName||t.name||"Unknown":t),function(e,t,n,r,o,a){var s=n.ref;return e={$$typeof:p,type:e,key:t,props:n,_owner:r},null!==(void 0!==s?s:null)?Object.defineProperty(e,"ref",{enumerable:!1,get:i}):Object.defineProperty(e,"ref",{enumerable:!1,value:null}),e._store={},Object.defineProperty(e._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(e,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(e,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:o}),Object.defineProperty(e,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:a}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}(t,f,o,null===(y=k.A)?null:y.getOwner(),s,u)}function l(e){u(e)?e._store&&(e._store.validated=1):"object"==typeof e&&null!==e&&e.$$typeof===E&&("fulfilled"===e._payload.status?u(e._payload.value)&&e._payload.value._store&&(e._payload.value._store.validated=1):e._store&&(e._store.validated=1))}function u(e){return"object"==typeof e&&null!==e&&e.$$typeof===p}var c,y=t,p=Symbol.for("react.transitional.element"),f=Symbol.for("react.portal"),d=Symbol.for("react.fragment"),m=Symbol.for("react.strict_mode"),g=Symbol.for("react.profiler"),h=Symbol.for("react.consumer"),b=Symbol.for("react.context"),v=Symbol.for("react.forward_ref"),S=Symbol.for("react.suspense"),w=Symbol.for("react.suspense_list"),P=Symbol.for("react.memo"),E=Symbol.for("react.lazy"),C=Symbol.for("react.activity"),_=Symbol.for("react.client.reference"),k=y.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,R=Object.prototype.hasOwnProperty,N=Array.isArray,O=console.createTask?console.createTask:function(){return null},T={},x=(y={react_stack_bottom_frame:function(e){return e()}}).react_stack_bottom_frame.bind(y,a)(),M=O(o(a)),j={};A.Fragment=d,A.jsx=function(e,t,n){var r=1e4>k.recentlyCreatedOwnerStacks++;return s(e,t,n,!1,r?Error("react-stack-top-frame"):x,r?O(o(e)):M)},A.jsxs=function(e,t,n){var r=1e4>k.recentlyCreatedOwnerStacks++;return s(e,t,n,!0,r?Error("react-stack-top-frame"):x,r?O(o(e)):M)}}()),A}var x=(O||(O=1,"production"===process.env.NODE_ENV?k.exports=function(){if(_)return R;_=1;var e=Symbol.for("react.transitional.element"),t=Symbol.for("react.fragment");function n(t,n,r){var o=null;if(void 0!==r&&(o=""+r),void 0!==n.key&&(o=""+n.key),"key"in n)for(var a in r={},n)"key"!==a&&(r[a]=n[a]);else r=n;return n=r.ref,{$$typeof:e,type:t,key:o,ref:void 0!==n?n:null,props:r}}return R.Fragment=t,R.jsx=n,R.jsxs=n,R}():k.exports=T()),k.exports);const M=t.createContext(void 0);function j(){const e=t.useContext(M);if(void 0===e)throw new Error("useHyperElementsContext must be used inside <HyperElements>");return e}function W(){const e=t.useContext(M);return{walletSession:e?.walletSession??null,isGooglePayEligible:e?.walletEligibility.googlePay??!1,isApplePayEligible:e?.walletEligibility.applePay??!1,loading:e?.walletLoading??!1,load:e?.loadWalletSession??(async()=>null)}}function D(){const e=t.useContext(M);return e?.paymentSession??null}function I(){return j().elements}M.displayName="HyperElementsContext";const H=null!=global.nativeFabricUIManager?require("../codegen/components/PaymentWidgetNativeComponent").default:e.requireNativeComponent("RCTNativePaymentWidget");function L(n,r){const[o,a]=t.useState(void 0);return t.useEffect(()=>{if(void 0!==o)return;let t,i=!0;const s=o=>{if(!i)return;if(null==n.current)return void(o<20&&(t=setTimeout(()=>s(o+1),100)));const l=e.findNodeHandle(n.current)??-1;-1!==l?(r?.(),a(l)):o<20&&(t=setTimeout(()=>s(o+1),100))};return s(0),()=>{i=!1,void 0!==t&&clearTimeout(t)}},[o]),o}const U=t.forwardRef((e,n)=>{const{id:r,options:o,onChange:a,onFocus:i,onBlur:u,onPaymentResult:c,style:y,onReady:p}=e,{paymentSessionConfig:f,hyperswitchConfig:d}=j(),m=t.useRef(null),g=L(m,p),h=void 0!==r&&void 0!==g;t.useEffect(()=>{if(!h)return;const e=r;return s(e,g),()=>l(e)},[h]);const b=t.useMemo(()=>{const e=o,t=e?.paymentMethodLayout;return{...e,paymentMethodLayout:{...t,savedMethodCustomization:{...t?.savedMethodCustomization,cvcIcon:e?.cvcIcon??"shown"}}}},[o]);return x.jsx(H,{ref:m,widgetType:"cvcWidget",sdkAuthorization:f?.sdkAuthorization??"",onPaymentEvent:e=>{if(a?.(e.nativeEvent),"CVC_STATUS"===e.nativeEvent.eventName)try{const t=e.nativeEvent.payload,n="string"==typeof t?JSON.parse(t):t;if(!n)return;const r=n.cvcStatus;if(!r)return;const o=Boolean(r.isCvcFocused),a=Boolean(r.isCvcBlur);o&&i?.(),a&&u?.()}catch{}},onPaymentResult:e=>{var t;c?.((t=e.nativeEvent.result??"",JSON.parse(t)))},options:{hyperswitchConfig:d||void 0,paymentSessionConfig:f||void 0,configuration:b},style:y})}),$=["PAYMENT_METHOD_INFO_CARD","PAYMENT_METHOD_STATUS","FORM_STATUS","PAYMENT_METHOD_INFO_ADDRESS","PAYMENT_METHOD_INFO_BILLING_ADDRESS","CVC_STATUS"];function z(e){return{message:`Unknown event(s) subscribed: [${e.join(", ")}]. Valid events are: ${$.join(", ")}`,invalidEvents:e,validEvents:$}}const B=t.forwardRef((n,o)=>{const{widgetId:i,options:u,onPaymentResult:c,onChange:y,onReady:p,style:f}=n,{paymentSessionConfig:d,hyperswitchConfig:m}=j(),g=t.useRef(null),h=L(g,p);t.useEffect(()=>{if(void 0!==h)return s(i,h),()=>l(i)},[h,i]),t.useEffect(()=>{void 0!==h&&e.UIManager.dispatchViewManagerCommand(h,1,[])},[h]),t.useImperativeHandle(o,()=>({confirmPayment:t=>{if(null==g.current)return Promise.resolve({status:"failed",type:"widget_not_ready",message:"Widget not ready"});const n=e.findNodeHandle(g.current)??-1;return-1===n?Promise.resolve({status:"failed",type:"widget_not_ready",message:"Unable to find native view handle"}):new Promise(e=>{r.confirmPayment(n,t=>{e(a(t))})})}}),[h]);const b=t.useRef(!1);t.useEffect(()=>{if(!u||!y||b.current)return;const e=function(e){return e?e.filter(e=>!$.includes(e)):[]}(u.subscribedEvents);if(e.length>0){b.current=!0;const t=z(e);y({eventName:"UNKNOWN_EVENT_SUBSCRIBED",payload:JSON.stringify({message:t.message,invalidEvents:t.invalidEvents,validEvents:t.validEvents})})}},[u,y]);return x.jsx(H,{ref:g,sdkAuthorization:d?.sdkAuthorization??"",widgetType:"widgetPaymentSheet",onPaymentEvent:e=>{y?.(e.nativeEvent)},onPaymentResult:t=>{c(a("ios"===e.Platform.OS?t.nativeEvent.result??"":t.nativeEvent.payload??""))},options:{hyperswitchConfig:m||void 0,paymentSessionConfig:d||void 0,configuration:u},style:{...f,flex:1}})});function F(){return n.isGooglePaySupported().catch(()=>!1)}function G(){return n.isApplePaySupported().catch(()=>!1)}function K({wallet:e,label:n,session:r,onPaymentResult:o}){const a=D(),{walletSession:i,load:s}=W(),l=t.useRef(!1);return async()=>{const t=r??a;if(!t&&!i){const e=new Error(`${n} was pressed without a payment session. Pass a "session" prop or render it inside <HyperElements>.`);if(!o)throw e;return void o({status:"failed",type:"no_session",message:e.message})}if(l.current){const e=new Error(`${n} is already processing a payment. Ignoring this press.`);if(!o)throw e;return void o({status:"failed",type:"already_in_progress",message:e.message})}l.current=!0;try{const r=i??await s()??await t.getWalletSession();if(!await r.isWalletEligible(e)){const e=new Error(`${n} is not eligible for this payment.`);if(!o)throw e;return void o({status:"failed",type:"not_eligible",message:e.message})}const a=await r.launchWallet(e);o?.(a)}catch(e){const t=e instanceof Error?e.message:String(e);if(!o)throw e;o({status:"failed",type:"launch_failed",message:t})}finally{l.current=!1}}}function J({wallet:e,label:n,session:r,onReady:o,onLoadError:a}){const i=D(),{walletSession:s,load:l}=W(),u=t.useRef(o),c=t.useRef(a),y=t.useRef(s),p=t.useRef(l);t.useEffect(()=>{u.current=o,c.current=a,y.current=s,p.current=l},[o,a,s,l]),t.useEffect(()=>{let t=!1;const o=(e,t)=>{c.current?.({status:"failed",type:e,message:t})};return(async()=>{try{const a=await(async()=>r?r.getWalletSession():y.current?y.current:i?p.current():null)();if(t)return;if(!a)return void o("no_session",`${n} has no payment session. Pass a "session" prop or render it inside <HyperElements>.`);const s=await a.isWalletEligible(e);if(t)return;s?u.current?.():o("not_eligible",`${n} is not eligible for this payment.`)}catch(e){if(t)return;o("launch_failed",e instanceof Error?e.message:String(e))}})(),()=>{t=!0}},[r,i,e,n])}const q={BUY:1,BOOK:6,CHECKOUT:5,DONATE:4,ORDER:11,PAY:1e3,SUBSCRIBE:7,PLAIN:1001},V={light:1,dark:2},Y={plain:0,buy:1,setUp:2,inStore:3,donate:4,checkout:5,book:6,subscribe:7},X={white:0,whiteOutline:1,black:2};function Q(e){return"hidden"===e?.visibility}function Z(e){return e?.appearance?.primaryButton?.shapes?.borderRadius??e?.appearance?.shapes?.borderRadius??4}function ee(e,t){const n=e?.appearance?.theme;return"Dark"===n||"Light"!==n&&"dark"===t}const te=function(){if("android"!==e.Platform.OS)return null;try{return null!=globalThis.nativeFabricUIManager?require("../codegen/components/HyperGooglePayNativeComponent").default:e.requireNativeComponent("HyperGooglePayButton")}catch{return null}}();const ne=function(){if("ios"!==e.Platform.OS)return null;try{return null!=globalThis.nativeFabricUIManager?require("../codegen/components/HyperApplePayNativeComponent").default:e.requireNativeComponent("HyperApplePayButton")}catch{return null}}();function re(e){return y(!0),n.initialise(e.publishableKey,e.platformPublishableKey??"",e.profileId??"",e.environment??"PROD",e.customEndpoints??{}).then(()=>(y(!1),{publishableKey:e.publishableKey,initPaymentSession:async t=>function(e,t){const n={hyperswitchConfig:e,paymentSessionConfig:t};return{presentPaymentSheet:S(n),getCustomerSavedPaymentMethods:w(n),getWalletSession:P(n),updateIntent:E}}(e,t),async elements(t){return{hyperswitchConfig:n=e,...C(n,t)};var n}})).catch(e=>{throw y(!1),console.error("Error initializing Hyperswitch SDK:",e),e})}const oe={init:re};exports.ApplePayButton=function({options:t,session:n,onPaymentResult:r,onReady:o,onLoadError:a,disabled:i=!1,style:s}){const l=e.useColorScheme(),u=K({wallet:"apple_pay",label:"Apple Pay",session:n,onPaymentResult:r});J({wallet:"apple_pay",label:"Apple Pay",session:n,onReady:o,onLoadError:a});const{hidden:c,type:y,buttonStyle:p,borderRadius:f}=function(e,t){const n=e?.walletButtonsConfiguration?.applePay,r=ee(e,t),o=r?n?.buttonStyle?.dark:n?.buttonStyle?.light;return{hidden:Q(n),type:Y[n?.buttonType??"plain"],buttonStyle:X[o??(r?"white":"black")],borderRadius:Z(e)}}(t,"dark"===l?"dark":"light");return c||null==ne?null:x.jsx(e.Pressable,{focusable:!0,accessible:!0,accessibilityRole:"button",accessibilityLabel:"Apple Pay",onPress:u,disabled:i,style:s,children:x.jsx(ne,{type:y,buttonStyle:p,buttonBorderRadius:f,disabled:i,style:e.StyleSheet.absoluteFill})})},exports.CardCVCElement=U,exports.GooglePayButton=function({options:t,session:n,onPaymentResult:r,onReady:o,onLoadError:a,style:i}){const s=e.useColorScheme(),l=K({wallet:"google_pay",label:"Google Pay",session:n,onPaymentResult:r});J({wallet:"google_pay",label:"Google Pay",session:n,onReady:o,onLoadError:a});const{hidden:u,type:c,appearance:y,borderRadius:p}=function(e,t){const n=e?.walletButtonsConfiguration?.googlePay,r=ee(e,t),o=r?n?.buttonStyle?.dark:n?.buttonStyle?.light;return{hidden:Q(n),type:q[n?.buttonType??"PLAIN"],appearance:V[o??(r?"dark":"light")],borderRadius:Z(e)}}(t,"dark"===s?"dark":"light");return u||null==te?null:x.jsx(e.Pressable,{focusable:!0,accessible:!0,accessibilityRole:"button",accessibilityLabel:"Google Pay",onPress:l,style:i,children:x.jsx(te,{type:c,appearance:y,borderRadius:p,style:e.StyleSheet.absoluteFill})})},exports.HyperElements=function({hyper:e,options:n,children:r}){const[o,a]=t.useState(null),[i,s]=t.useState(null),[l,u]=t.useState(null),[c,y]=t.useState(null),[p,f]=t.useState(null),[d,m]=t.useState(null),[g,h]=t.useState(!0),[b,v]=t.useState(null),[S,w]=t.useState(null),[P,E]=t.useState({googlePay:!1,applePay:!1}),[C,_]=t.useState(!1),k=t.useCallback(async()=>{if(!o)return null;_(!0);try{const e=await o.getWalletSession(),[t,n]=await Promise.all([e.isGooglePayEligible(),e.isApplePayEligible()]);return w(e),E({googlePay:t,applePay:n}),e}catch{return w(null),E({googlePay:!1,applePay:!1}),null}finally{_(!1)}},[o]);return t.useEffect(()=>{w(null),E({googlePay:!1,applePay:!1})},[o]),t.useEffect(()=>{if(!e)return;let t=!1;return(async()=>{try{const r=await Promise.resolve(e),o={sdkAuthorization:n.sdkAuthorization},i=await r.elements(o);t||(a({...i}),u(i.hyperswitchConfig),y(o),s(i),f(r.publishableKey??null),m(n.sdkAuthorization??null),h(!1))}catch(e){t||(v(e instanceof Error?e:new Error(String(e))),h(!1))}})(),()=>{t=!0}},[e,n.sdkAuthorization]),x.jsx(M.Provider,{value:{paymentSession:o,walletSession:S,walletEligibility:P,walletLoading:C,loadWalletSession:k,elements:i,publishableKey:p,sdkAuthorization:d,loading:g,error:b,paymentSessionConfig:c,hyperswitchConfig:l},children:r})},exports.Hyperswitch=oe,exports.PaymentElement=B,exports.default=oe,exports.isApplePaySupported=G,exports.isGooglePaySupported=F,exports.isPlatformPaySupported=function(){return"ios"===e.Platform.OS?G():"android"===e.Platform.OS?F():Promise.resolve(!1)},exports.isWalletSupported=function(e){return"google_pay"===e?F():G()},exports.loadHyper=re,exports.useElements=I,exports.usePaymentSession=function(){return j().paymentSession},exports.useWalletSession=function(){const e=j();return{walletSession:e.walletSession,isGooglePayEligible:e.walletEligibility.googlePay,isApplePayEligible:e.walletEligibility.applePay,loading:e.walletLoading,load:e.loadWalletSession}},exports.useWidgets=I;
|
|
10
|
+
*/function M(){return A||(A=1,"production"!==process.env.NODE_ENV&&function(){function e(t){if(null==t)return null;if("function"==typeof t)return t.$$typeof===_?null:t.displayName||t.name||null;if("string"==typeof t)return t;switch(t){case p:return"Fragment";case g:return"Profiler";case m:return"StrictMode";case S:return"Suspense";case w:return"SuspenseList";case C:return"Activity"}if("object"==typeof t)switch("number"==typeof t.tag&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),t.$$typeof){case f:return"Portal";case b:return t.displayName||"Context";case h:return(t._context.displayName||"Context")+".Consumer";case v:var n=t.render;return(t=t.displayName)||(t=""!==(t=n.displayName||n.name||"")?"ForwardRef("+t+")":"ForwardRef"),t;case P:return null!==(n=t.displayName||null)?n:e(t.type)||"Memo";case E:n=t._payload,t=t._init;try{return e(t(n))}catch(e){}}return null}function n(e){return""+e}function r(e){try{n(e);var t=!1}catch(e){t=!0}if(t){var r=(t=console).error,o="function"==typeof Symbol&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object";return r.call(t,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",o),n(e)}}function o(t){if(t===p)return"<>";if("object"==typeof t&&null!==t&&t.$$typeof===E)return"<...>";try{var n=e(t);return n?"<"+n+">":"<...>"}catch(e){return"<...>"}}function a(){return Error("react-stack-top-frame")}function i(){var t=e(this.type);return A[t]||(A[t]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),void 0!==(t=this.props.ref)?t:null}function s(t,n,o,a,s,u){var y,f=n.children;if(void 0!==f)if(a)if(N(f)){for(a=0;a<f.length;a++)l(f[a]);Object.freeze&&Object.freeze(f)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else l(f);if(R.call(n,"key")){f=e(t);var p=Object.keys(n).filter(function(e){return"key"!==e});a=0<p.length?"{key: someKey, "+p.join(": ..., ")+": ...}":"{key: someKey}",j[f+a]||(p=0<p.length?"{"+p.join(": ..., ")+": ...}":"{}",console.error('A props object containing a "key" prop is being spread into JSX:\n let props = %s;\n <%s {...props} />\nReact keys must be passed directly to JSX without using spread:\n let props = %s;\n <%s key={someKey} {...props} />',a,f,p,f),j[f+a]=!0)}if(f=null,void 0!==o&&(r(o),f=""+o),function(e){if(R.call(e,"key")){var t=Object.getOwnPropertyDescriptor(e,"key").get;if(t&&t.isReactWarning)return!1}return void 0!==e.key}(n)&&(r(n.key),f=""+n.key),"key"in n)for(var m in o={},n)"key"!==m&&(o[m]=n[m]);else o=n;return f&&function(e,t){function n(){c||(c=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",t))}n.isReactWarning=!0,Object.defineProperty(e,"key",{get:n,configurable:!0})}(o,"function"==typeof t?t.displayName||t.name||"Unknown":t),function(e,t,n,r,o,a){var s=n.ref;return e={$$typeof:d,type:e,key:t,props:n,_owner:r},null!==(void 0!==s?s:null)?Object.defineProperty(e,"ref",{enumerable:!1,get:i}):Object.defineProperty(e,"ref",{enumerable:!1,value:null}),e._store={},Object.defineProperty(e._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(e,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(e,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:o}),Object.defineProperty(e,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:a}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}(t,f,o,null===(y=k.A)?null:y.getOwner(),s,u)}function l(e){u(e)?e._store&&(e._store.validated=1):"object"==typeof e&&null!==e&&e.$$typeof===E&&("fulfilled"===e._payload.status?u(e._payload.value)&&e._payload.value._store&&(e._payload.value._store.validated=1):e._store&&(e._store.validated=1))}function u(e){return"object"==typeof e&&null!==e&&e.$$typeof===d}var c,y=t,d=Symbol.for("react.transitional.element"),f=Symbol.for("react.portal"),p=Symbol.for("react.fragment"),m=Symbol.for("react.strict_mode"),g=Symbol.for("react.profiler"),h=Symbol.for("react.consumer"),b=Symbol.for("react.context"),v=Symbol.for("react.forward_ref"),S=Symbol.for("react.suspense"),w=Symbol.for("react.suspense_list"),P=Symbol.for("react.memo"),E=Symbol.for("react.lazy"),C=Symbol.for("react.activity"),_=Symbol.for("react.client.reference"),k=y.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,R=Object.prototype.hasOwnProperty,N=Array.isArray,O=console.createTask?console.createTask:function(){return null},A={},T=(y={react_stack_bottom_frame:function(e){return e()}}).react_stack_bottom_frame.bind(y,a)(),M=O(o(a)),j={};x.Fragment=p,x.jsx=function(e,t,n){var r=1e4>k.recentlyCreatedOwnerStacks++;return s(e,t,n,!1,r?Error("react-stack-top-frame"):T,r?O(o(e)):M)},x.jsxs=function(e,t,n){var r=1e4>k.recentlyCreatedOwnerStacks++;return s(e,t,n,!0,r?Error("react-stack-top-frame"):T,r?O(o(e)):M)}}()),x}var j=(T||(T=1,"production"===process.env.NODE_ENV?N.exports=function(){if(R)return O;R=1;var e=Symbol.for("react.transitional.element"),t=Symbol.for("react.fragment");function n(t,n,r){var o=null;if(void 0!==r&&(o=""+r),void 0!==n.key&&(o=""+n.key),"key"in n)for(var a in r={},n)"key"!==a&&(r[a]=n[a]);else r=n;return n=r.ref,{$$typeof:e,type:t,key:o,ref:void 0!==n?n:null,props:r}}return O.Fragment=t,O.jsx=n,O.jsxs=n,O}():N.exports=M()),N.exports);const W=t.createContext(void 0);function D(){const e=t.useContext(W);if(void 0===e)throw new Error("useHyperElementsContext must be used inside <HyperElements>");return e}function I(){const e=t.useContext(W);return{walletSession:e?.walletSession??null,isGooglePayEligible:e?.walletEligibility.googlePay??!1,isApplePayEligible:e?.walletEligibility.applePay??!1,loading:e?.walletLoading??!1,load:e?.loadWalletSession??(async()=>null)}}function H(){const e=t.useContext(W);return e?.paymentSession??null}function L(){return D().elements}W.displayName="HyperElementsContext";const U=null!=global.nativeFabricUIManager?require("../codegen/components/PaymentWidgetNativeComponent").default:e.requireNativeComponent("RCTNativePaymentWidget");function $(n,r){const[o,a]=t.useState(void 0);return t.useEffect(()=>{if(void 0!==o)return;let t,i=!0;const s=o=>{if(!i)return;if(null==n.current)return void(o<20&&(t=setTimeout(()=>s(o+1),100)));const l=e.findNodeHandle(n.current)??-1;-1!==l?(r?.(),a(l)):o<20&&(t=setTimeout(()=>s(o+1),100))};return s(0),()=>{i=!1,void 0!==t&&clearTimeout(t)}},[o]),o}const z=t.forwardRef((e,n)=>{const{id:r,options:o,onChange:a,onFocus:i,onBlur:s,onPaymentResult:c,style:y,onReady:d}=e,{paymentSessionConfig:f,hyperswitchConfig:p}=D(),m=t.useRef(null),g=$(m,d),h=void 0!==r&&void 0!==g;t.useEffect(()=>{if(!h)return;const e=r;return l(e,g),()=>u(e)},[h]);const b=t.useMemo(()=>{const e=o,t=e?.paymentMethodLayout;return{...e,paymentMethodLayout:{...t,savedMethodCustomization:{...t?.savedMethodCustomization,cvcIcon:e?.cvcIcon??"shown"}}}},[o]);return j.jsx(U,{ref:m,widgetType:"cvcWidget",sdkAuthorization:f?.sdkAuthorization??"",onPaymentEvent:e=>{if(a?.(e.nativeEvent),"CVC_STATUS"===e.nativeEvent.eventName)try{const t=e.nativeEvent.payload,n="string"==typeof t?JSON.parse(t):t;if(!n)return;const r=n.cvcStatus;if(!r)return;const o=Boolean(r.isCvcFocused),a=Boolean(r.isCvcBlur);o&&i?.(),a&&s?.()}catch{}},onPaymentResult:e=>{var t;c?.((t=e.nativeEvent.result??"",JSON.parse(t)))},options:{hyperswitchConfig:p||void 0,paymentSessionConfig:f||void 0,configuration:b},style:y})}),F=["PAYMENT_METHOD_INFO_CARD","PAYMENT_METHOD_STATUS","FORM_STATUS","PAYMENT_METHOD_INFO_ADDRESS","PAYMENT_METHOD_INFO_BILLING_ADDRESS","CVC_STATUS"];function B(e){return{message:`Unknown event(s) subscribed: [${e.join(", ")}]. Valid events are: ${F.join(", ")}`,invalidEvents:e,validEvents:F}}const G=t.forwardRef((n,o)=>{const{widgetId:a,options:s,onPaymentResult:c,onChange:y,onReady:d,style:f}=n,{paymentSessionConfig:p,hyperswitchConfig:m}=D(),g=t.useRef(null),h=$(g,d);t.useEffect(()=>{if(void 0!==h)return l(a,h),()=>u(a)},[h,a]),t.useEffect(()=>{void 0!==h&&e.UIManager.dispatchViewManagerCommand(h,1,[])},[h]),t.useImperativeHandle(o,()=>({confirmPayment:t=>{if(null==g.current)return Promise.resolve({status:"failed",type:"widget_not_ready",message:"Widget not ready"});const n=e.findNodeHandle(g.current)??-1;return-1===n?Promise.resolve({status:"failed",type:"widget_not_ready",message:"Unable to find native view handle"}):new Promise(e=>{r.confirmPayment(n,t=>{e(i(t))})})}}),[h]);const b=t.useRef(!1);t.useEffect(()=>{if(!s||!y||b.current)return;const e=function(e){return e?e.filter(e=>!F.includes(e)):[]}(s.subscribedEvents);if(e.length>0){b.current=!0;const t=B(e);y({eventName:"UNKNOWN_EVENT_SUBSCRIBED",payload:JSON.stringify({message:t.message,invalidEvents:t.invalidEvents,validEvents:t.validEvents})})}},[s,y]);return j.jsx(U,{ref:g,sdkAuthorization:p?.sdkAuthorization??"",widgetType:"widgetPaymentSheet",onPaymentEvent:e=>{y?.(e.nativeEvent)},onPaymentResult:t=>{c(i("ios"===e.Platform.OS?t.nativeEvent.result??"":t.nativeEvent.payload??""))},options:{hyperswitchConfig:m||void 0,paymentSessionConfig:p||void 0,configuration:s},style:{...f,flex:1}})});function K(){return n.isGooglePaySupported().catch(()=>!1)}function J(){return n.isApplePaySupported().catch(()=>!1)}function q({wallet:e,label:n,session:r,onPaymentResult:o}){const a=H(),{walletSession:i,load:s}=I(),l=t.useRef(!1);return async()=>{const t=r??a;if(!t&&!i){const e=new Error(`${n} was pressed without a payment session. Pass a "session" prop or render it inside <HyperElements>.`);if(!o)throw e;return void o({status:"failed",type:"no_session",message:e.message})}if(l.current){const e=new Error(`${n} is already processing a payment. Ignoring this press.`);if(!o)throw e;return void o({status:"failed",type:"already_in_progress",message:e.message})}l.current=!0;try{const r=i??await s()??await t.getWalletSession();if(!await r.isWalletEligible(e)){const e=new Error(`${n} is not eligible for this payment.`);if(!o)throw e;return void o({status:"failed",type:"not_eligible",message:e.message})}const a=await r.launchWallet(e);o?.(a)}catch(e){const t=e instanceof Error?e.message:String(e);if(!o)throw e;o({status:"failed",type:"launch_failed",message:t})}finally{l.current=!1}}}function V({wallet:e,label:n,session:r,onReady:o,onLoadError:a}){const i=H(),{walletSession:s,load:l}=I(),u=t.useRef(o),c=t.useRef(a),y=t.useRef(s),d=t.useRef(l);t.useEffect(()=>{u.current=o,c.current=a,y.current=s,d.current=l},[o,a,s,l]),t.useEffect(()=>{let t=!1;const o=(e,t)=>{c.current?.({status:"failed",type:e,message:t})};return(async()=>{try{const a=await(async()=>r?r.getWalletSession():y.current?y.current:i?d.current():null)();if(t)return;if(!a)return void o("no_session",`${n} has no payment session. Pass a "session" prop or render it inside <HyperElements>.`);const s=await a.isWalletEligible(e);if(t)return;s?u.current?.():o("not_eligible",`${n} is not eligible for this payment.`)}catch(e){if(t)return;o("launch_failed",e instanceof Error?e.message:String(e))}})(),()=>{t=!0}},[r,i,e,n])}const Y={BUY:1,BOOK:6,CHECKOUT:5,DONATE:4,ORDER:11,PAY:1e3,SUBSCRIBE:7,PLAIN:1001},X={light:1,dark:2},Q={plain:0,buy:1,setUp:2,inStore:3,donate:4,checkout:5,book:6,subscribe:7},Z={white:0,whiteOutline:1,black:2};function ee(e){return"hidden"===e?.visibility}function te(e){return e?.appearance?.primaryButton?.shapes?.borderRadius??e?.appearance?.shapes?.borderRadius??4}function ne(e,t){const n=e?.appearance?.theme;return"Dark"===n||"Light"!==n&&"dark"===t}const re=function(){if("android"!==e.Platform.OS)return null;try{return null!=globalThis.nativeFabricUIManager?require("../codegen/components/HyperGooglePayNativeComponent").default:e.requireNativeComponent("HyperGooglePayButton")}catch{return null}}();const oe=function(){if("ios"!==e.Platform.OS)return null;try{return null!=globalThis.nativeFabricUIManager?require("../codegen/components/HyperApplePayNativeComponent").default:e.requireNativeComponent("HyperApplePayButton")}catch{return null}}();function ae(e){return d(!0),p(!1),n.initialise(e.publishableKey,e.platformPublishableKey??"",e.profileId??"",e.environment??"PROD",e.customEndpoints??{}).then(()=>(d(!1),{publishableKey:e.publishableKey,initPaymentSession:async t=>function(e,t){const n={hyperswitchConfig:e,paymentSessionConfig:t};return{presentPaymentSheet:P(n),getCustomerSavedPaymentMethods:E(n),getWalletSession:C(n),updateIntent:_}}(e,t),async elements(t){return{hyperswitchConfig:n=e,...k(n,t)};var n}})).catch(e=>{throw d(!1),console.error("Error initializing Hyperswitch SDK:",e),e})}const ie={init:ae};exports.ApplePayButton=function({options:t,session:n,onPaymentResult:r,onReady:o,onLoadError:a,disabled:i=!1,style:s}){const l=e.useColorScheme(),u=q({wallet:"apple_pay",label:"Apple Pay",session:n,onPaymentResult:r});V({wallet:"apple_pay",label:"Apple Pay",session:n,onReady:o,onLoadError:a});const{hidden:c,type:y,buttonStyle:d,borderRadius:f}=function(e,t){const n=e?.walletButtonsConfiguration?.applePay,r=ne(e,t),o=r?n?.buttonStyle?.dark:n?.buttonStyle?.light;return{hidden:ee(n),type:Q[n?.buttonType??"plain"],buttonStyle:Z[o??(r?"white":"black")],borderRadius:te(e)}}(t,"dark"===l?"dark":"light");return c||null==oe?null:j.jsx(e.Pressable,{focusable:!0,accessible:!0,accessibilityRole:"button",accessibilityLabel:"Apple Pay",onPress:u,disabled:i,style:s,children:j.jsx(oe,{type:y,buttonStyle:d,buttonBorderRadius:f,disabled:i,style:e.StyleSheet.absoluteFill})})},exports.CardCVCElement=z,exports.GooglePayButton=function({options:t,session:n,onPaymentResult:r,onReady:o,onLoadError:a,style:i}){const s=e.useColorScheme(),l=q({wallet:"google_pay",label:"Google Pay",session:n,onPaymentResult:r});V({wallet:"google_pay",label:"Google Pay",session:n,onReady:o,onLoadError:a});const{hidden:u,type:c,appearance:y,borderRadius:d}=function(e,t){const n=e?.walletButtonsConfiguration?.googlePay,r=ne(e,t),o=r?n?.buttonStyle?.dark:n?.buttonStyle?.light;return{hidden:ee(n),type:Y[n?.buttonType??"PLAIN"],appearance:X[o??(r?"dark":"light")],borderRadius:te(e)}}(t,"dark"===s?"dark":"light");return u||null==re?null:j.jsx(e.Pressable,{focusable:!0,accessible:!0,accessibilityRole:"button",accessibilityLabel:"Google Pay",onPress:l,style:i,children:j.jsx(re,{type:c,appearance:y,borderRadius:d,style:e.StyleSheet.absoluteFill})})},exports.HyperElements=function({hyper:e,options:n,children:r}){const[o,a]=t.useState(null),[i,s]=t.useState(null),[l,u]=t.useState(null),[c,y]=t.useState(null),[d,f]=t.useState(null),[p,m]=t.useState(null),[g,h]=t.useState(!0),[b,v]=t.useState(null),[S,w]=t.useState(null),[P,E]=t.useState({googlePay:!1,applePay:!1}),[C,_]=t.useState(!1),k=t.useCallback(async()=>{if(!o)return null;_(!0);try{const e=await o.getWalletSession(),[t,n]=await Promise.all([e.isGooglePayEligible(),e.isApplePayEligible()]);return w(e),E({googlePay:t,applePay:n}),e}catch{return w(null),E({googlePay:!1,applePay:!1}),null}finally{_(!1)}},[o]);return t.useEffect(()=>{w(null),E({googlePay:!1,applePay:!1})},[o]),t.useEffect(()=>{if(!e)return;let t=!1;return(async()=>{try{const r=await Promise.resolve(e),o={sdkAuthorization:n.sdkAuthorization},i=await r.elements(o);t||(a({...i}),u(i.hyperswitchConfig),y(o),s(i),f(r.publishableKey??null),m(n.sdkAuthorization??null),h(!1))}catch(e){t||(v(e instanceof Error?e:new Error(String(e))),h(!1))}})(),()=>{t=!0}},[e,n.sdkAuthorization]),j.jsx(W.Provider,{value:{paymentSession:o,walletSession:S,walletEligibility:P,walletLoading:C,loadWalletSession:k,elements:i,publishableKey:d,sdkAuthorization:p,loading:g,error:b,paymentSessionConfig:c,hyperswitchConfig:l},children:r})},exports.Hyperswitch=ie,exports.PaymentElement=G,exports.default=ie,exports.isApplePaySupported=J,exports.isGooglePaySupported=K,exports.isPlatformPaySupported=function(){return"ios"===e.Platform.OS?J():"android"===e.Platform.OS?K():Promise.resolve(!1)},exports.isWalletSupported=function(e){return"google_pay"===e?K():J()},exports.loadHyper=ae,exports.useElements=L,exports.usePaymentSession=function(){return D().paymentSession},exports.useWalletSession=function(){const e=D();return{walletSession:e.walletSession,isGooglePayEligible:e.walletEligibility.googlePay,isApplePayEligible:e.walletEligibility.applePay,loading:e.walletLoading,load:e.loadWalletSession}},exports.useWidgets=L;
|
|
11
11
|
//# sourceMappingURL=index.bundle.js.map
|