@@ -43,21 +43,26 @@ class Logger private constructor() {
4343 initBasePayload()
4444 }
4545
46+ private fun resetBasePayload (isInit : Boolean = false) {
47+ LogCat .debug(TAG , if (isInit) " initBasePayload" else " resetBasePayload" )
48+ this .payload = TrackingPayload (
49+ clientId = clientId,
50+ merchantId = null ,
51+ partnerAttributionId = null ,
52+ // merchantProfileHash will be later defined by pulling from LocalStorage
53+ merchantProfileHash = null ,
54+ deviceId = Settings .Secure .ANDROID_ID ,
55+ // TODO Determine SessionId for Logger
56+ sessionId = " random for now, TBD at later point to what this is specifically" ,
57+ integrationName = integrationName,
58+ integrationVersion = integrationVersion,
59+ components = mutableListOf (),
60+ )
61+ }
62+
4663 private fun initBasePayload () {
4764 if (clientId != = " " ) {
48- this .payload = TrackingPayload (
49- clientId = clientId,
50- merchantId = null ,
51- partnerAttributionId = null ,
52- // merchantProfileHash can be later defined after a message request by pulling from paypalmessagelocalstorage
53- merchantProfileHash = null ,
54- deviceId = Settings .Secure .ANDROID_ID ,
55- // TODO Determine SessionId for Logger
56- sessionId = " random for now, TBD at later point to what this is specifically" ,
57- integrationName = integrationName,
58- integrationVersion = integrationVersion,
59- components = mutableListOf (),
60- )
65+ resetBasePayload(true )
6166 }
6267 else {
6368 val exception = InvalidCheckoutConfigException ()
@@ -113,18 +118,16 @@ class Logger private constructor() {
113118 delay(5000 ) // Wait 5 seconds before sending our payload
114119
115120 val localStorage = LocalStorage (context)
116- LogCat .debug(TAG , localStorage.merchantHash.toString())
117- finalPayload.components.forEach { component ->
118- component.instanceId?.let { LogCat .debug(TAG , it) }
119- component.events.forEach { event ->
120- LogCat .debug(TAG , event.eventType.toString())
121- }
121+ val hash = localStorage.merchantHash
122+ val payloadSummary = finalPayload.components.joinToString(" \n " ) {
123+ val eventsString = it.events.joinToString { event -> event.eventType.toString() }
124+ " type: ${it.type} \n instanceId: ${it.instanceId} \n events: $eventsString \n "
122125 }
126+ LogCat .debug(TAG , " merchantHash: ${hash} \n payloadSummary:\n $payloadSummary " )
123127
128+ finalPayload.merchantProfileHash = hash
124129 Api .callLoggerEndpoint(finalPayload)
125-
126- // After our response has completed, we can reset our base payload.
127- initBasePayload()
130+ resetBasePayload()
128131 }
129132 }
130133}
0 commit comments