Subversion Repositories SmartDukaan

Rev

Rev 35458 | Rev 35654 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 35458 Rev 35624
Line 1... Line 1...
1
package com.spice.profitmandi.web.controller;
1
package com.spice.profitmandi.web.controller;
2
 
2
 
-
 
3
import com.fasterxml.jackson.databind.ObjectMapper;
3
import com.razorpay.Utils;
4
import com.razorpay.Utils;
4
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
5
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
5
import com.spice.profitmandi.common.web.util.ResponseSender;
6
import com.spice.profitmandi.common.web.util.ResponseSender;
6
import com.spice.profitmandi.dao.entity.fofo.Customer;
7
import com.spice.profitmandi.dao.entity.fofo.Customer;
7
import com.spice.profitmandi.dao.entity.fofo.FofoOrder;
8
import com.spice.profitmandi.dao.entity.fofo.FofoOrder;
Line 22... Line 23...
22
import org.springframework.beans.factory.annotation.Value;
23
import org.springframework.beans.factory.annotation.Value;
23
import org.springframework.http.HttpStatus;
24
import org.springframework.http.HttpStatus;
24
import org.springframework.http.MediaType;
25
import org.springframework.http.MediaType;
25
import org.springframework.http.ResponseEntity;
26
import org.springframework.http.ResponseEntity;
26
import org.springframework.stereotype.Controller;
27
import org.springframework.stereotype.Controller;
-
 
28
import org.springframework.transaction.annotation.Transactional;
27
import org.springframework.ui.Model;
29
import org.springframework.ui.Model;
28
import org.springframework.web.bind.annotation.ModelAttribute;
30
import org.springframework.web.bind.annotation.ModelAttribute;
29
import org.springframework.web.bind.annotation.RequestBody;
31
import org.springframework.web.bind.annotation.RequestBody;
30
import org.springframework.web.bind.annotation.RequestMapping;
32
import org.springframework.web.bind.annotation.RequestMapping;
31
import org.springframework.web.bind.annotation.RequestMethod;
33
import org.springframework.web.bind.annotation.RequestMethod;
32
 
34
 
33
import javax.servlet.http.HttpServletRequest;
35
import javax.servlet.http.HttpServletRequest;
34
import org.springframework.transaction.annotation.Transactional;
-
 
35
 
36
 
36
@Controller
37
@Controller
37
@Transactional(rollbackFor = Throwable.class)
38
@Transactional(rollbackFor = Throwable.class)
38
public class WebHookController {
39
public class WebHookController {
39
 
40
 
Line 58... Line 59...
58
    RecordingService recordingService;
59
    RecordingService recordingService;
59
 
60
 
60
    @Autowired
61
    @Autowired
61
    AgentRecordingRepository agentRecordingRepository;
62
    AgentRecordingRepository agentRecordingRepository;
62
 
63
 
-
 
64
    /**
-
 
65
     * Knowlarity Click2Call Webhook - First Event (Call Report Handler).
-
 
66
     * <p>
-
 
67
     * This endpoint is called by Knowlarity when a click-to-call event is initiated or completed.
-
 
68
     * Knowlarity sends call detail data as form-urlencoded POST, which is mapped to {@link CallDetailModel}.
-
 
69
     * <p>
-
 
70
     * The incoming third-party data from Knowlarity may not always match our expected model fields.
-
 
71
     * If Knowlarity changes their payload structure or sends unexpected/null values,
-
 
72
     * errors can occur during binding or in {@link RecordingService#updateAgentRecording}.
-
 
73
     * <p>
-
 
74
     * URL: POST /click2call/report-handler
-
 
75
     * Content-Type: application/x-www-form-urlencoded
-
 
76
     * Third-party: Knowlarity
-
 
77
     */
63
    @RequestMapping(value = "/click2call/report-handler", method = RequestMethod.POST, consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
78
    @RequestMapping(value = "/click2call/report-handler", method = RequestMethod.POST, consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
64
    public ResponseEntity<?> click2callReportHandlerPost(HttpServletRequest request, Model model, @ModelAttribute CallDetailModel callDetail) throws Exception {
79
    public ResponseEntity<?> click2callReportHandlerPost(HttpServletRequest request, Model model, @ModelAttribute CallDetailModel callDetail) throws Exception {
-
 
80
        // Log raw parameters from Knowlarity before processing, so we can see exactly what they sent
-
 
81
        LOGGER.info("report-handler raw params from Knowlarity: {}", request.getParameterMap());
-
 
82
        try {
65
        LOGGER.info("first event call detail {}", callDetail);
83
            LOGGER.info("first event call detail (mapped): {}", callDetail);
66
        recordingService.updateAgentRecording(callDetail);
84
            recordingService.updateAgentRecording(callDetail);
-
 
85
        } catch (Exception e) {
-
 
86
            LOGGER.error("Error processing report-handler webhook. Raw params: {}", request.getParameterMap(), e);
67
 
87
        }
68
        return responseSender.ok(true);
88
        return responseSender.ok(true);
69
    }
89
    }
70
 
90
 
71
 
91
 
-
 
92
    /**
-
 
93
     * Knowlarity Click2Call Webhook - Recording URL Update.
-
 
94
     *
-
 
95
     * This endpoint is called by Knowlarity after a call recording is available.
-
 
96
     * Knowlarity sends updated call detail (including the recording URL) as form-urlencoded POST,
-
 
97
     * mapped to {@link CallDetailModel}.
-
 
98
     *
-
 
99
     * The incoming third-party data from Knowlarity may not always match our expected model fields.
-
 
100
     * If Knowlarity changes their payload structure or sends unexpected/null values,
-
 
101
     * errors can occur during binding or in {@link RecordingService#updateAgentRecordingUrl}.
-
 
102
     *
-
 
103
     * URL: POST /click2call/report-handler/recording-url
-
 
104
     * Content-Type: application/x-www-form-urlencoded
-
 
105
     * Third-party: Knowlarity
-
 
106
     */
72
    @RequestMapping(value = "/click2call/report-handler/recording-url", method = RequestMethod.POST, consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
107
    @RequestMapping(value = "/click2call/report-handler/recording-url", method = RequestMethod.POST, consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
73
    public ResponseEntity<?> click2callReportHandlerUpdateRecordingUrlPost(HttpServletRequest request, Model model, @ModelAttribute CallDetailModel callDetail) throws Exception {
108
    public ResponseEntity<?> click2callReportHandlerUpdateRecordingUrlPost(HttpServletRequest request, Model model, @ModelAttribute CallDetailModel callDetail) throws Exception {
-
 
109
        // Log raw parameters from Knowlarity before processing, so we can see exactly what they sent
-
 
110
        LOGGER.info("recording-url raw params from Knowlarity: {}", request.getParameterMap());
-
 
111
        try {
74
        LOGGER.info("update call detail {}", callDetail);
112
            LOGGER.info("update call detail (mapped): {}", callDetail);
75
        recordingService.updateAgentRecordingUrl(callDetail);
113
            recordingService.updateAgentRecordingUrl(callDetail);
-
 
114
        } catch (Exception e) {
-
 
115
            LOGGER.error("Error processing recording-url webhook. Raw params: {}", request.getParameterMap(), e);
-
 
116
        }
76
        return responseSender.ok(true);
117
        return responseSender.ok(true);
77
    }
118
    }
78
 
119
 
-
 
120
    /**
-
 
121
     * Knowlarity Click2Call Webhook - Push Call Log.
-
 
122
     *
-
 
123
     * This endpoint is called by Knowlarity to push call log data in JSON format,
-
 
124
     * mapped to {@link PushCallLogModel}.
-
 
125
     *
-
 
126
     * The incoming third-party data from Knowlarity may not always match our expected model fields.
-
 
127
     * If Knowlarity changes their JSON payload structure or sends unexpected/null values,
-
 
128
     * errors can occur during deserialization or in {@link RecordingService#updateAgentCallLog}.
-
 
129
     *
-
 
130
     * URL: POST /click2call/push-call-log-handler
-
 
131
     * Content-Type: application/json
-
 
132
     * Third-party: Knowlarity
-
 
133
     */
79
    @RequestMapping(value = "/click2call/push-call-log-handler", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
134
    @RequestMapping(value = "/click2call/push-call-log-handler", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
80
    public ResponseEntity<?> click2callPushLogHandler(@RequestBody PushCallLogModel pushCallLogModel) throws Exception {
135
    public ResponseEntity<?> click2callPushLogHandler(HttpServletRequest request, @RequestBody String rawBody) throws Exception {
-
 
136
        // Log raw JSON body from Knowlarity before processing, so we can see exactly what they sent
-
 
137
        LOGGER.info("push-call-log raw JSON from Knowlarity: {}", rawBody);
-
 
138
        try {
-
 
139
            ObjectMapper objectMapper = new ObjectMapper();
-
 
140
            PushCallLogModel pushCallLogModel = objectMapper.readValue(rawBody, PushCallLogModel.class);
81
        LOGGER.info("update call detail - push log {}", pushCallLogModel);
141
            LOGGER.info("update call detail - push log (mapped): {}", pushCallLogModel);
82
        recordingService.updateAgentCallLog(pushCallLogModel);
142
            recordingService.updateAgentCallLog(pushCallLogModel);
-
 
143
        } catch (Exception e) {
-
 
144
            LOGGER.error("Error processing push-call-log webhook. Raw JSON: {}", rawBody, e);
-
 
145
        }
83
        return responseSender.ok("true");
146
        return responseSender.ok("true");
84
    }
147
    }
85
 
148
 
86
 
149
 
87
    @Value("${razorpay.account.keySecret}")
150
    @Value("${razorpay.account.keySecret}")