1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160package io.hyperswitch.logs
import org.json.JSONException
import org.json.JSONObject
enum class LogType {
DEBUG, INFO, ERROR, WARNING
}
enum class LogCategory {
API, USER_ERROR, USER_EVENT, MERCHANT_EVENT, OTA_LIFE_CYCLE
}
enum class EventName {
HYPER_OTA_INIT, HYPER_OTA_FINISH , HYPER_OTA_EVENT, CRASH_EVENT, CLICK_TO_PAY_FLOW
}
data class HSLog(
val timestamp: String,
val logType: LogType,
val component: String = "MOBILE",
val category: LogCategory,
val version: String,
var codePushVersion: String,
var clientCoreVersion: String,
val value: String,
val internalMetadata: String,
val sessionId: String,
var merchantId: String,
val paymentId: String,
val appId: String? = null,
val platform: String = "ANDROID",
val userAgent: String,
val eventName: EventName,
val latency: String? = null,
val firstEvent: Boolean = false,
val paymentMethod: String? = null,
val paymentExperience: String? = null,
val source: String
) {
fun toJson(): String {
try {
val logData = JSONObject().apply {
put("timestamp", timestamp)
put("log_type", logType.name)
put("component", component)
put("category", category.toString())
put("version", version)
put("code_push_version", codePushVersion)
put("client_core_version", clientCoreVersion)
put("value", value)
put("internal_metadata", internalMetadata)
put("session_id", sessionId)
put("merchant_id", merchantId)
put("payment_id", paymentId)
put("app_id", appId ?: "")
put("platform", platform)
put("user_agent", userAgent)
put("event_name", eventName.name)
put("first_event", firstEvent.toString())
put("payment_method", paymentMethod ?: "")
put("payment_experience", paymentExperience ?: "")
put("latency", latency ?: "")
put("source", source)
}
val jsonString = logData.toString()
return jsonString
} catch (e: JSONException) {
return ""
}
}
class LogBuilder {
private var timestamp: String = System.currentTimeMillis().toString()
private var logType: LogType = LogType.INFO
private var component: String = "MOBILE"
private lateinit var category: LogCategory
private var version: String = ""
private var codePushVersion: String = ""
private var clientCoreVersion: String = ""
private var value: String = ""
private var internalMetadata: String = ""
private var sessionId: String = ""
private var merchantId: String = ""
private var paymentId: String = ""
private var appId: String? = null
private var platform: String = "ANDROID"
private var userAgent: String = ""
private lateinit var eventName: EventName
private var latency: String? = null
private var firstEvent: Boolean = false
private var paymentMethod: String? = null
private var paymentExperience: String? = null
private var source: String = ""
fun timestamp(timestamp: String) = apply { this.timestamp = timestamp }
fun logType(logType: String) = apply {
this.logType =
LogType.entries.find { it.name == logType.uppercase() } ?: LogType.INFO
}
fun component(component: String) = apply { this.component = component }
fun category(category: LogCategory) = apply { this.category = category }
fun version(version: String) = apply { this.version = version }
fun codePushVersion(codePushVersion: String) =
apply { this.codePushVersion = codePushVersion }
fun clientCoreVersion(clientCoreVersion: String) =
apply { this.clientCoreVersion = clientCoreVersion }
fun value(value: String) = apply { this.value = value }
fun internalMetadata(internalMetadata: String) =
apply { this.internalMetadata = internalMetadata }
fun sessionId(sessionId: String) = apply { this.sessionId = sessionId }
fun merchantId(merchantId: String) = apply { this.merchantId = merchantId }
fun paymentId(paymentId: String) = apply { this.paymentId = paymentId }
fun appId(appId: String?) = apply { this.appId = appId }
fun platform(platform: String) = apply { this.platform = platform }
fun userAgent(userAgent: String) = apply { this.userAgent = userAgent }
fun eventName(eventName: EventName) = apply { this.eventName = eventName }
fun latency(latency: String?) = apply { this.latency = latency }
fun firstEvent(firstEvent: Boolean) = apply { this.firstEvent = firstEvent }
fun paymentMethod(paymentMethod: String?) = apply { this.paymentMethod = paymentMethod }
fun paymentExperience(paymentExperience: String?) =
apply { this.paymentExperience = paymentExperience }
fun source(source: String) = apply { this.source = source }
fun build(): HSLog {
return HSLog(
timestamp,
logType,
component,
category,
version,
codePushVersion,
clientCoreVersion,
value,
internalMetadata,
sessionId,
merchantId,
paymentId,
appId,
platform,
userAgent,
eventName,
latency,
firstEvent,
paymentMethod,
paymentExperience,
source
)
}
}
}