@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.
Files changed (46) hide show
  1. package/android/build.gradle +22 -1
  2. package/android/src/main/assets/hyperswitch.bundle +590 -590
  3. package/android/src/main/java/com/hyperswitchsdkreactnative/modules/NativeLog.kt +107 -0
  4. package/android/src/main/java/com/hyperswitchsdkreactnative/modules/ReactNativeHyperswitchModule.kt +318 -117
  5. package/android/src/main/java/io/hyperswitch/paymentsession/ExitHeadlessCallBackManager.kt +4 -2
  6. package/android/src/main/java/io/hyperswitch/paymentsession/PaymentSessionHandlerImpl.kt +20 -4
  7. package/android/src/main/java/io/hyperswitch/paymentsession/PaymentSessionReactLauncher.kt +104 -9
  8. package/android/src/main/java/io/hyperswitch/paymentsheet/PaymentResult.kt +7 -1
  9. package/android/src/main/java/io/hyperswitch/react/HyperModule.kt +13 -0
  10. package/android/src/main/java/io/hyperswitch/view/PaymentWidgetView.kt +27 -4
  11. package/android/src/rn79/assets/hyperswitch.bundle +590 -590
  12. package/android/src/rn79/java/io/hyperswitch/react/HyperFragment.kt +20 -0
  13. package/android/src/rn81/java/io/hyperswitch/react/HyperFragment.kt +20 -0
  14. package/ios/Modules/ReactNative/NativeHyperswitchModuleImpl.swift +3 -1
  15. package/ios/hyperswitchSDK/Core/ApplePay/ApplePayHandler.swift +49 -38
  16. package/ios/hyperswitchSDK/Core/HyperPaymentSheet/PaymentSheetView+UIKit.swift +1 -5
  17. package/ios/hyperswitchSDK/Core/NativeModule/HyperModuleImpl.swift +49 -34
  18. package/ios/hyperswitchSDK/Core/NativeModule/RNHeadlessManager.swift +2 -12
  19. package/ios/hyperswitchSDK/Core/Resources/hyperswitch-rn82plus.bundle +590 -590
  20. package/ios/hyperswitchSDK/Core/Resources/hyperswitch.bundle +590 -590
  21. package/ios/hyperswitchSDK/Shared/Environment.swift +49 -3
  22. package/ios/hyperswitchSDK/Shared/HyperswitchEnvironment.swift +1 -0
  23. package/ios/hyperswitchSDK/Shared/NativeLogger/LogBuilder.swift +15 -0
  24. package/ios/hyperswitchSDK/Shared/NativeLogger/LogManager.swift +10 -2
  25. package/ios/hyperswitchSDK/Shared/NativeLogger/LogPayload.swift +1 -0
  26. package/ios/hyperswitchSDK/Shared/NativeLogger/NativeLog.swift +101 -0
  27. package/ios/hyperswitchSDK/Shared/PaymentSession.swift +8 -1
  28. package/lib/commonjs/index.bundle.js +2 -2
  29. package/lib/commonjs/index.bundle.js.map +1 -1
  30. package/lib/module/index.bundle.js +2 -2
  31. package/lib/module/index.bundle.js.map +1 -1
  32. package/lib/typescript/src/context/HyperElements.d.ts.map +1 -1
  33. package/lib/typescript/src/index.d.ts.map +1 -1
  34. package/lib/typescript/src/native/NativeResponseMapper.d.ts +2 -1
  35. package/lib/typescript/src/native/NativeResponseMapper.d.ts.map +1 -1
  36. package/lib/typescript/src/session/SavedPaymentMethods.d.ts.map +1 -1
  37. package/lib/typescript/src/session/presentPaymentSheet.d.ts +0 -12
  38. package/lib/typescript/src/session/presentPaymentSheet.d.ts.map +1 -1
  39. package/lib/typescript/src/views/PaymentElement.d.ts.map +1 -1
  40. package/package.json +1 -1
  41. package/src/context/HyperElements.tsx +7 -6
  42. package/src/index.ts +9 -1
  43. package/src/native/NativeResponseMapper.ts +20 -4
  44. package/src/session/SavedPaymentMethods.ts +10 -2
  45. package/src/session/presentPaymentSheet.ts +7 -1
  46. package/src/views/PaymentElement.tsx +17 -8
@@ -0,0 +1,107 @@
1
+ package com.hyperswitchsdkreactnative.modules
2
+
3
+ import android.content.res.Configuration
4
+ import android.util.Base64
5
+ import com.facebook.react.common.LifecycleState
6
+ import com.facebook.react.bridge.ReactApplicationContext
7
+ import com.facebook.react.bridge.UiThreadUtil
8
+ import io.hyperswitch.logs.EventName
9
+ import io.hyperswitch.logs.HSLog
10
+ import io.hyperswitch.logs.HyperLogManager
11
+ import io.hyperswitch.logs.LogCategory
12
+ import org.json.JSONObject
13
+ import java.lang.ref.WeakReference
14
+
15
+ /**
16
+ * Native SDK lifecycle logs sent through HyperLogManager. Same shape as the iOS `NativeLog`:
17
+ * - event_name RN_SDK_LIFE_CYCLE
18
+ * - value a stable snake_case event id (filterable, no variable data)
19
+ * - internal_metadata a JSON object with the event's details plus app_state and orientation
20
+ * - source "native"
21
+ *
22
+ * [enabled] is set from the module once the logging endpoint is known. Never throws, so logging
23
+ * cannot break a payment flow. addLog runs on the UI thread because the logger keeps an
24
+ * unsynchronised batch that its debouncer reads on the main looper.
25
+ */
26
+ object NativeLog {
27
+ private const val SOURCE = "native"
28
+
29
+ @Volatile
30
+ var enabled = false
31
+
32
+ private var reactContext: WeakReference<ReactApplicationContext>? = null
33
+
34
+ /* Payment of the latest session the SDK was asked about; null until the first one. */
35
+ @Volatile
36
+ private var paymentId: String? = null
37
+
38
+ /** Every later log carries the payment id read from [sdkAuthorization]. */
39
+ fun setSdkAuthorization(sdkAuthorization: String?) {
40
+ paymentId = paymentIdFrom(sdkAuthorization)
41
+ }
42
+
43
+ /**
44
+ * Same rule as client-core's Utils.getSdkAuthorizationData: base64 "key=value,..." pairs,
45
+ * payment_id, else the client_secret part before "_secret_".
46
+ */
47
+ private fun paymentIdFrom(sdkAuthorization: String?): String? {
48
+ if (sdkAuthorization.isNullOrEmpty()) return null
49
+ val decoded = runCatching {
50
+ String(Base64.decode(sdkAuthorization, Base64.DEFAULT), Charsets.UTF_8)
51
+ }.getOrNull() ?: return null
52
+ val fields = decoded.split(",").mapNotNull { pair ->
53
+ val i = pair.indexOf('=')
54
+ if (i > 0) pair.substring(0, i) to pair.substring(i + 1) else null
55
+ }.toMap()
56
+ return fields["payment_id"]?.ifEmpty { null }
57
+ ?: fields["client_secret"]?.substringBefore("_secret_")?.ifEmpty { null }
58
+ }
59
+
60
+ /** Lets every log carry app_state and orientation, as on iOS. */
61
+ fun attach(context: ReactApplicationContext) {
62
+ reactContext = WeakReference(context)
63
+ }
64
+
65
+ private fun context(): Map<String, Any?> {
66
+ val ctx = reactContext?.get()
67
+ val appState = when (ctx?.lifecycleState) {
68
+ LifecycleState.RESUMED -> "active"
69
+ LifecycleState.BEFORE_RESUME -> "inactive"
70
+ LifecycleState.BEFORE_CREATE -> "background"
71
+ null -> "unknown"
72
+ }
73
+ val orientation = when (ctx?.resources?.configuration?.orientation) {
74
+ Configuration.ORIENTATION_PORTRAIT -> "portrait"
75
+ Configuration.ORIENTATION_LANDSCAPE -> "landscape"
76
+ else -> "unknown"
77
+ }
78
+ return mapOf("app_state" to appState, "orientation" to orientation)
79
+ }
80
+
81
+ /** `production` / `sandbox` / `integ`, the same values iOS logs. */
82
+ fun environmentName(name: String?): String? = when (name) {
83
+ null -> null
84
+ "PROD" -> "production"
85
+ else -> name.lowercase()
86
+ }
87
+
88
+ fun debug(event: String, details: Map<String, Any?> = emptyMap()) = send("debug", event, details)
89
+ fun warning(event: String, details: Map<String, Any?> = emptyMap()) = send("warning", event, details)
90
+ fun error(event: String, details: Map<String, Any?> = emptyMap()) = send("error", event, details)
91
+
92
+ fun send(logType: String, event: String, details: Map<String, Any?> = emptyMap()) {
93
+ if (!enabled) return
94
+ val log = runCatching {
95
+ HSLog.LogBuilder()
96
+ .logType(logType)
97
+ .category(LogCategory.API)
98
+ .eventName(EventName.RN_SDK_LIFE_CYCLE)
99
+ .value(event)
100
+ .paymentId(paymentId ?: "")
101
+ .internalMetadata(JSONObject((details + context()).filterValues { it != null }).toString())
102
+ .source(SOURCE)
103
+ .build()
104
+ }.getOrNull() ?: return
105
+ UiThreadUtil.runOnUiThread { runCatching { HyperLogManager.addLog(log) } }
106
+ }
107
+ }