| Line 9... |
Line 9... |
| 9 |
import com.spice.profitmandi.service.integrations.smartping.SmartPingService;
|
9 |
import com.spice.profitmandi.service.integrations.smartping.SmartPingService;
|
| 10 |
import com.spice.profitmandi.service.integrations.smartping.model.CallDetailModel;
|
10 |
import com.spice.profitmandi.service.integrations.smartping.model.CallDetailModel;
|
| 11 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
11 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
| 12 |
import org.apache.logging.log4j.LogManager;
|
12 |
import org.apache.logging.log4j.LogManager;
|
| 13 |
import org.apache.logging.log4j.Logger;
|
13 |
import org.apache.logging.log4j.Logger;
|
| 14 |
import org.json.JSONObject;
|
- |
|
| 15 |
import org.springframework.beans.factory.annotation.Autowired;
|
14 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 16 |
import org.springframework.beans.factory.annotation.Value;
|
15 |
import org.springframework.beans.factory.annotation.Value;
|
| 17 |
import org.springframework.http.HttpStatus;
|
16 |
import org.springframework.http.HttpStatus;
|
| 18 |
import org.springframework.http.MediaType;
|
17 |
import org.springframework.http.MediaType;
|
| 19 |
import org.springframework.http.ResponseEntity;
|
18 |
import org.springframework.http.ResponseEntity;
|
| Line 77... |
Line 76... |
| 77 |
private UpsellRazorpayPaymentStatusRepository upsellRazorpayPaymentStatusRepository;
|
76 |
private UpsellRazorpayPaymentStatusRepository upsellRazorpayPaymentStatusRepository;
|
| 78 |
|
77 |
|
| 79 |
@RequestMapping(value = "/upsellPayment/callback", method = RequestMethod.GET)
|
78 |
@RequestMapping(value = "/upsellPayment/callback", method = RequestMethod.GET)
|
| 80 |
public ResponseEntity<String> handleCallback(HttpServletRequest request) {
|
79 |
public ResponseEntity<String> handleCallback(HttpServletRequest request) {
|
| 81 |
try {
|
80 |
try {
|
| 82 |
LOGGER.info("webhook called {}", request);
|
81 |
LOGGER.info("Webhook called with query parameters");
|
| 83 |
|
82 |
|
| 84 |
// Verify the callback request
|
- |
|
| 85 |
Map<String, String> headers = getHeadersInfo(request);
|
- |
|
| 86 |
String razorpaySignature = headers.get("x-razorpay-signature");
|
- |
|
| 87 |
|
- |
|
| 88 |
// Retrieve the payload from query parameters
|
83 |
// Retrieve the Razorpay parameters from the query string
|
| 89 |
String paymentId = request.getParameter("razorpay_payment_id");
|
84 |
String paymentId = request.getParameter("razorpay_payment_id");
|
| 90 |
String status = request.getParameter("status");
|
85 |
String razorpaySignature = request.getParameter("razorpay_signature");
|
| 91 |
|
- |
|
| 92 |
// Assuming notes are passed as individual parameters
|
- |
|
| 93 |
String orderId = request.getParameter("orderId");
|
86 |
String orderId = request.getParameter("orderId");
|
| 94 |
String insuranceAmount = request.getParameter("insuranceAmount");
|
87 |
String insuranceAmount = request.getParameter("insuranceAmount");
|
| 95 |
|
88 |
|
| 96 |
// Verify that all necessary parameters are received
|
89 |
// Check for required parameters
|
| 97 |
if (paymentId == null || status == null || orderId == null || insuranceAmount == null) {
|
90 |
if (paymentId == null || razorpaySignature == null || orderId == null || insuranceAmount == null) {
|
| 98 |
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Missing required parameters");
|
91 |
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Missing required parameters");
|
| 99 |
}
|
92 |
}
|
| 100 |
|
93 |
|
| 101 |
// Construct payload for signature verification
|
94 |
// Construct payload for signature verification
|
| 102 |
JSONObject payloadJson = new JSONObject();
|
- |
|
| 103 |
payloadJson.put("razorpay_payment_id", paymentId);
|
- |
|
| 104 |
payloadJson.put("status", status);
|
- |
|
| 105 |
|
- |
|
| 106 |
JSONObject notes = new JSONObject();
|
- |
|
| 107 |
notes.put("orderId", orderId);
|
- |
|
| 108 |
notes.put("insuranceAmount", insuranceAmount);
|
95 |
String payload = "razorpay_payment_id=" + paymentId + "&orderId=" + orderId + "&insuranceAmount=" + insuranceAmount;
|
| 109 |
payloadJson.put("notes", notes);
|
- |
|
| 110 |
|
96 |
|
| 111 |
String payload = payloadJson.toString();
|
97 |
// Verify the signature
|
| 112 |
boolean isSignatureValid = verifySignature(payload, razorpaySignature);
|
98 |
boolean isSignatureValid = verifySignature(payload, razorpaySignature);
|
| 113 |
|
- |
|
| 114 |
if (!isSignatureValid) {
|
99 |
if (!isSignatureValid) {
|
| 115 |
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Invalid signature");
|
100 |
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Invalid signature");
|
| 116 |
}
|
101 |
}
|
| 117 |
|
102 |
|
| 118 |
// Process the payment status
|
- |
|
| 119 |
if ("captured".equals(status)) {
|
- |
|
| 120 |
updatePaymentStatus(paymentId, "captured", orderId, insuranceAmount);
|
103 |
// Handle the payment status (you may need to add more logic depending on the status)
|
| 121 |
return ResponseEntity.ok("Payment successful for ID: " + paymentId);
|
- |
|
| 122 |
} else {
|
- |
|
| 123 |
updatePaymentStatus(paymentId, "failed", orderId, insuranceAmount);
|
104 |
updatePaymentStatus(paymentId, "captured", orderId, insuranceAmount);
|
| - |
|
105 |
|
| 124 |
return ResponseEntity.ok("Payment failed for ID: " + paymentId);
|
106 |
return ResponseEntity.ok("Payment successful for ID: " + paymentId);
|
| 125 |
}
|
107 |
|
| 126 |
} catch (Exception e) {
|
108 |
} catch (Exception e) {
|
| 127 |
e.printStackTrace();
|
109 |
e.printStackTrace();
|
| 128 |
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Error processing callback");
|
110 |
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Error processing callback");
|
| 129 |
}
|
111 |
}
|
| 130 |
}
|
112 |
}
|