You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

723 lines
37 KiB

2 years ago
​
​
​
​
2 years ago
​
2 years ago
​
2 years ago
​
​
2 years ago
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
2 years ago
2 years ago
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
2 years ago
​
​
​
​
​
​
2 years ago
​
​
​
​
2 years ago
2 years ago
​
​
2 years ago
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
2 years ago
2 years ago
2 years ago
​
​
2 years ago
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
2 years ago
​
​
​
2 years ago
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
2 years ago
​
​
​
​
2 years ago
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
2 years ago
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. package com.gcc.communityHall.paymentService.controller;
  2. import java.io.BufferedReader;
  3. import java.io.InputStreamReader;
  4. import java.net.HttpURLConnection;
  5. import java.net.URL;
  6. import java.security.NoSuchAlgorithmException;
  7. import java.security.Timestamp;
  8. import java.text.SimpleDateFormat;
  9. import java.time.LocalDate;
  10. import java.time.format.DateTimeFormatter;
  11. import java.util.*;
  12. import com.fasterxml.jackson.databind.JsonNode;
  13. import com.fasterxml.jackson.databind.ObjectMapper;
  14. import com.gcc.communityHall.configuration.EncryptionUtil;
  15. import com.gcc.communityHall.entity.*;
  16. import com.gcc.communityHall.others.AppConfig;
  17. //import com.gcc.communityHall.repository.ErpPostDataRepository;
  18. import com.gcc.communityHall.service.PaymentsService;
  19. import org.apache.tomcat.util.json.JSONParser;
  20. import org.springframework.beans.factory.annotation.Autowired;
  21. import org.springframework.boot.autoconfigure.AutoConfigurationPackage;
  22. import org.springframework.stereotype.Controller;
  23. import org.springframework.ui.Model;
  24. import org.springframework.web.bind.annotation.PostMapping;
  25. import org.springframework.web.bind.annotation.RequestMapping;
  26. import org.springframework.web.bind.annotation.RequestParam;
  27. import com.gcc.communityHall.entity.BookingDetails.BookingStatus;
  28. import com.gcc.communityHall.entity.BookingDetails.RefundStatus;
  29. import com.gcc.communityHall.paymentService.config.PaymentConfig;
  30. import com.gcc.communityHall.paymentService.entity.TransactionResponse;
  31. import com.gcc.communityHall.paymentService.repository.TransactionResponseRepository;
  32. import com.gcc.communityHall.paymentService.service.PaymentGatewayService;
  33. import com.gcc.communityHall.repository.BookingDetailsRepository;
  34. import com.gcc.communityHall.repository.ExtraPaymentsRepository;
  35. import com.gcc.communityHall.repository.PaymentsRepository;
  36. import com.gcc.communityHall.service.Impl.BookingServiceImpl;
  37. import com.gcc.communityHall.service.UserService;
  38. import org.springframework.web.client.RestTemplate;
  39. import org.springframework.web.util.UriComponentsBuilder;
  40. @Controller
  41. @RequestMapping("/communityhall/payment")
  42. public class PaymentController {
  43. // ak
  44. @Autowired
  45. private EncryptionUtil encryptionUtil;
  46. @Autowired
  47. PaymentGatewayService paymentService;
  48. @Autowired
  49. private PaymentConfig paymentConfig;
  50. @Autowired
  51. private BookingServiceImpl bookser;
  52. @Autowired
  53. private TransactionResponseRepository transactionResRepo;
  54. @Autowired
  55. private PaymentsRepository paymentRepo;
  56. @Autowired
  57. private ExtraPaymentsRepository extraPaymentsRepository;
  58. @Autowired
  59. private BookingDetailsRepository bookingDetailsRepository;
  60. @Autowired
  61. private AppConfig appConfig;
  62. // @Autowired
  63. // private ErpPostDataRepository erpPostDataRepository;
  64. @Autowired
  65. private PaymentsService paymentsService;
  66. // ak
  67. @PostMapping(value = "/response")
  68. public String response(Model model, @RequestParam(required = false) String msg) throws NoSuchAlgorithmException {
  69. System.out.println("Payment Response receiving from Payment Gateway...");
  70. String salt = this.paymentConfig.getEncryptionKey();
  71. String confirmToken = "";
  72. String status = this.paymentConfig.getTransactionSuccessCode();
  73. String refId = "";
  74. String[] res = msg.split("\\|");
  75. String c = "";
  76. TransactionResponse response = this.paymentService.getTransactionResponseByTxansactionId(res[3], "temp");
  77. Payments payment = new Payments();
  78. payment.setTransactionId(response.getTxansactionId());
  79. double amount = 0;
  80. // ------------------ PAYMENT STRING PROCESSING ------------------
  81. for (int i = 0; i < res.length; i++) {
  82. if (i == res.length - 1) {
  83. c = c + salt;
  84. confirmToken = res[i];
  85. } else if (res[i].isEmpty()) {
  86. c = c + "|";
  87. } else if (res[i].equals("NA")) {
  88. c = c + "NA|";
  89. } else {
  90. c = c + res[i] + "|";
  91. }
  92. if (i == 5) {
  93. response.setTpslTxnId(res[i]);
  94. response.setAmount(res[6]);
  95. response.setTxansactionId(res[3]);
  96. response.setDate(res[8]);
  97. }
  98. }
  99. int bookingId = response.getBookingId();
  100. try {
  101. amount = Double.parseDouble(response.getAmount());
  102. } catch (Exception e) {
  103. }
  104. payment.setAmountReceived(amount);
  105. payment.setPaymentStatus("Not Completed");
  106. BookingDetails bookingsDetails = bookser.getBookingsById(bookingId); // JPA fetch
  107. payment.setBookingDetails(bookingsDetails);
  108. response.setResponse(msg);
  109. response.setStatusCode(res[0]);
  110. bookingsDetails.setPayments(payment);
  111. payment.setCdate(new Date());
  112. // save transaction response
  113. transactionResRepo.save(response);
  114. // =============================================================
  115. // CASE 1: FAILURE - AMOUNT MISMATCH
  116. // =============================================================
  117. if (bookingsDetails.getAmountReceived() != amount) {
  118. if (paymentService.generateToken(c).equals(confirmToken) && status.equals(res[0])) {
  119. payment.setPaymentStatus("Success");
  120. bookingsDetails.setPayments(payment);
  121. paymentRepo.save(payment);
  122. // booking failure logic
  123. bookser.bookingFailure(bookingsDetails, 1);
  124. }
  125. // Fetch OR Generate booking_ref_id
  126. refId = bookser.getBookingRefIdByBookingId(bookingId);
  127. // encrypt bookingId (coworkspace logic)
  128. String encryptedId = encryptionUtil.encrypt(String.valueOf(bookingId));
  129. model.addAttribute("ref_id", refId);
  130. model.addAttribute("encryptedId", encryptedId);
  131. return "redirect:/communityhall/user/acknowledgement?ref_id=" + refId;
  132. }
  133. // =============================================================
  134. // CASE 2: SUCCESS FLOW
  135. // =============================================================
  136. if (paymentService.generateToken(c).equals(confirmToken) && status.equals(res[0])) {
  137. payment.setPaymentStatus("Success");
  138. bookingsDetails.setPayments(payment);
  139. paymentRepo.save(payment);
  140. // 🔥 Fetch OR Generate booking_ref_id
  141. refId = bookser.getBookingRefIdByBookingId(bookingId);
  142. try {
  143. bookser.confirmBooking(bookingId);
  144. } catch (Exception e) {
  145. e.printStackTrace();
  146. System.out.println("Exception Occured inside /response end point : " + e.getMessage());
  147. // ignore
  148. }
  149. }
  150. // 🔐 Encrypt bookingId
  151. String encryptedId = encryptionUtil.encrypt(String.valueOf(bookingId));
  152. model.addAttribute("ref_id", refId);
  153. model.addAttribute("encryptedId", encryptedId);
  154. return "redirect:/communityhall/user/acknowledgement?ref_id=" + refId;
  155. }
  156. /*
  157. * @PostMapping(value = "/response")
  158. * public String response(Model model, @RequestParam(required = false) String
  159. * msg) throws NoSuchAlgorithmException {
  160. *
  161. * String salt = this.paymentConfig.getEncryptionKey();
  162. *
  163. * String confirmToken = "";
  164. * String status = this.paymentConfig.getTransactionSuccessCode();
  165. * String s = new String(msg);
  166. * String c = new String();
  167. * String res[] = s.split("\\|");
  168. *
  169. * TransactionResponse response =
  170. * this.paymentService.getTransactionResponseByTxansactionId(res[3], "temp");
  171. * Payments payment = new Payments();
  172. * payment.setTransactionId(response.getTxansactionId());
  173. * double amount = 0;
  174. *
  175. *
  176. * for (int i = 0; i < res.length; i++) {
  177. * if (i == res.length - 1) {
  178. * c = c + salt;
  179. * confirmToken = res[i];
  180. * } else if (res[i].isEmpty()) {
  181. * c = c + "|";
  182. * } else if (res[i].equals("NA")) {
  183. * c = c + "NA|";
  184. * } else {
  185. * c = c + res[i] + "|";
  186. * }
  187. *
  188. * if (i == 5) {
  189. * response.setTpslTxnId(res[i]);
  190. * response.setAmount(res[6]);
  191. * response.setTxansactionId(res[3]);
  192. * //String[] tDate = res[8].split(" ");
  193. * response.setDate(res[8]);
  194. * }
  195. * }
  196. * int bookingId = response.getBookingId();
  197. * try {
  198. * amount = Double.parseDouble(response.getAmount());
  199. * } catch (Exception e) {
  200. * // TODO: handle exception
  201. * //System.out.println("payment Controller lineNo-67");
  202. * }
  203. * payment.setAmountReceived(amount);
  204. * payment.setPaymentStatus("Not Completed");
  205. *
  206. * BookingDetails bookingsDetails = bookser.getBookingsById(bookingId);
  207. * payment.setBookingDetails(bookingsDetails);
  208. * response.setResponse(msg);
  209. * response.setStatusCode(res[0]);
  210. * bookingsDetails.setPayments(payment);
  211. * payment.setCdate(new Date());
  212. *
  213. * System.out.println("bookingsDetails.getAmountReceived().." +
  214. * bookingsDetails.getAmountReceived());
  215. * System.out.println("amount: " + amount);
  216. *
  217. * TransactionResponse save = transactionResRepo.save(response);
  218. *
  219. * if (bookingsDetails.getAmountReceived() != amount) { // Reject booking if the
  220. * amount is incorrect
  221. * if(paymentService.generateToken(c).equals(confirmToken) &&
  222. * status.equals(res[0])){
  223. * payment.setPaymentStatus("Success");
  224. * bookingsDetails.setPayments(payment);
  225. * paymentRepo.save(payment);
  226. * bookser.bookingFailure(bookingsDetails, 1);
  227. * }
  228. * //ak
  229. *
  230. *
  231. *
  232. * model.addAttribute("bookingsDetails", bookingsDetails);
  233. * return "redirect:/communityhall/user/acknowledgement?bookingId=" +
  234. * bookingsDetails.getBookingId();
  235. * }
  236. *
  237. *
  238. * if (paymentService.generateToken(c).equals(confirmToken) &&
  239. * status.equals(res[0])) {
  240. * payment.setPaymentStatus("Success");
  241. * bookingsDetails.setPayments(payment);
  242. * try {
  243. * String confirmBooking = bookser.confirmBooking(response.getBookingId());
  244. * }catch (Exception e){
  245. * // return "redirect:/communityhall/user/acknowledgement?bookingId=" +
  246. * bookingsDetails.getBookingId();
  247. *
  248. * }
  249. * // postDataToERP(payment, response); // post payment details to ERP
  250. * //
  251. * System.out.println("\n confirmBooking:- paymentController 111"+confirmBooking
  252. * +"\n");
  253. * // if(confirmBooking.equals("Booking confirmed successfully")) {
  254. * // //bookser.updateBookingStatusById(bookingsDetails.getBookingId(),
  255. * BookingDetails.BookingStatus.APPROVED, "confirm");
  256. * // // String bookingconfimationsms =
  257. * "Your booking with ID "+bookingsDetails.getBookingId()+" on"
  258. * +bookingsDetails.getBookingId()
  259. * +" has been successfully confirmed. Thanks for using GCC Community Hall Booking System."
  260. * ;
  261. * // }else if(confirmBooking.equals("Slot occupied")) {
  262. * //// System.out.println("Slot occupied line 115");
  263. * //// BookingDetails crrSts =
  264. * bookser.updateBookingStatusById(bookingsDetails.getBookingId(),
  265. * BookingDetails.BookingStatus.REFUNDED,
  266. * "slot occupied Refund will happen shortly");
  267. * //// System.out.println("BookingDetails:-"+crrSts.getBookingStatus());
  268. * // }
  269. * // else if(confirmBooking.equals("Error confirming booking")) {
  270. * // bookser.updateBookingStatusById(bookingsDetails.getBookingId(),
  271. * BookingDetails.BookingStatus.PENDING, "Error");
  272. * //
  273. * // }
  274. *
  275. * }
  276. *
  277. * // System.out.println(response.toString());
  278. * model.addAttribute("bookingsDetails", bookingsDetails); // Add single
  279. * BookingDetails object
  280. * //System.out.println(save.toString());
  281. * paymentRepo.save(payment);
  282. * return "redirect:/communityhall/user/acknowledgement?bookingId=" +
  283. * bookingsDetails.getBookingId();
  284. * }
  285. */
  286. /*
  287. * public void postDataToERP(Payments payment, TransactionResponse res) {
  288. * RestTemplate restTemplate = new RestTemplate();
  289. * erpPostData erpData = new erpPostData();
  290. *
  291. * SimpleDateFormat outputFormat = new SimpleDateFormat("dd/MM/yyyy");
  292. * String txDate = outputFormat.format(payment.getCdate());
  293. * String assesNo = LocalDate.now().getYear() + "/COMM/" + res.getBookingId();
  294. *
  295. * Map<String, Object> data = new TreeMap<>();
  296. *//* static mandatory input to be sent *//*
  297. * data.put("serviceId", "getOtherCollection");
  298. * data.put("COLLECTION_TYPE", "Community Hall");
  299. * data.put("TOTALTRANSACTIONCODE", "450310000");
  300. * // /end of static/
  301. * // /unique data to be send/
  302. * data.put("ASSESSMENTNO", assesNo);
  303. * data.put("UNIQUERECEIPTID", res.getBookingId());
  304. * data.put("TRANSACTIONNO", payment.getTransactionId());
  305. * data.put("TRANSACTIONREFNO", res.getTpslTxnId());
  306. * data.put("TRANSACTIONDATE", txDate); //payment date format dd/mm/yyyy
  307. * -> 19/02/2025
  308. * data.put("TOTALTRANSACTIONAMOUNT",
  309. * payment.getBookingDetails().getAmountReceived());
  310. *
  311. * data.put("MSTRCODEONE", "061");
  312. * data.put("SPLITAMOUNTONE",
  313. * payment.getBookingDetails().getHallAmount());
  314. * data.put("MSTRCODETWO", "062");
  315. * data.put("SPLITAMOUNTTWO",
  316. * payment.getBookingDetails().getDepositAmount());
  317. * data.put("MSTRCODETHREE", "063");
  318. * data.put("SPLITAMOUNTTHREE", payment.getBookingDetails().getGst());
  319. * // /Amount Collected from party/
  320. * data.put("PARTYNAME",
  321. * payment.getBookingDetails().getUsers().getName());
  322. * data.put("PARTYADDRESS",
  323. * payment.getBookingDetails().getUsers().getStreet() + "," +
  324. * payment.getBookingDetails().getUsers().getArea() + "," +
  325. * payment.getBookingDetails().getUsers().getLocation() + "," +
  326. * payment.getBookingDetails().getUsers().getPinCode());
  327. * data.put("PARTYMOBILE",
  328. * payment.getBookingDetails().getUsers().getMobileNo());
  329. *//* end *//*
  330. * System.out.println(data);
  331. * System.out.println(appConfig.getCommErpUrl());
  332. * // ResponseEntity<String> stringResponseEntity =
  333. * restTemplate.postForEntity(appConfig.getErpUrl(), data,
  334. * String.class);
  335. * // System.out.println(stringResponseEntity.getBody());
  336. *
  337. * erpData.setTx_id(payment.getTransactionId());
  338. * erpData.setBooking_det_booking_id(res.getBookingId());
  339. * erpData.setStatus(true);
  340. * erpData.setCdate(LocalDate.now());
  341. * erpData.setPay_status(1);
  342. * erpPostDataRepository.save(erpData);
  343. *
  344. * UriComponentsBuilder builder =
  345. * UriComponentsBuilder.fromHttpUrl(appConfig.getCommErpUrl())
  346. * ;
  347. * for (Map.Entry<String, Object> entry : data.entrySet()) {
  348. * builder.queryParam(entry.getKey(), entry.getValue());
  349. * }
  350. *
  351. * String urlMsg = builder.toUriString();
  352. * System.out.println(urlMsg);
  353. *
  354. * try {
  355. * HttpURLConnection connection = null;
  356. *
  357. * URL url = new URL(urlMsg);
  358. * connection = (HttpURLConnection) url.openConnection();
  359. * connection.setRequestMethod("GET");
  360. *
  361. * int responseCode = connection.getResponseCode();
  362. * // response=responseCode+"";
  363. * System.out.println("Response Code: " + responseCode);
  364. *
  365. * if (responseCode == HttpURLConnection.HTTP_OK) { // 200 OK
  366. * BufferedReader in = new BufferedReader(new
  367. * InputStreamReader(connection.getInputStream()));
  368. * String inputLine;
  369. * StringBuilder response = new StringBuilder();
  370. * while ((inputLine = in.readLine()) != null) {
  371. * response.append(inputLine);
  372. * }
  373. * in.close();
  374. * System.out.println("Response: " + response.toString());
  375. *
  376. * ObjectMapper objectMapper = new ObjectMapper();
  377. * JsonNode jsonNode =
  378. * objectMapper.readTree(response.toString());
  379. *
  380. * String resultStatus =
  381. * jsonNode.get("ResultStatus").asText();
  382. *
  383. * if (!resultStatus.isEmpty() &&
  384. * resultStatus.equals("false")) {
  385. * erpData.setStatus(false);
  386. * erpPostDataRepository.save(erpData);
  387. * }
  388. *
  389. * } else {
  390. * System.out.println("GET request failed.");
  391. * }
  392. *
  393. * } catch (Exception e) {
  394. * e.printStackTrace();
  395. * }
  396. * }
  397. */
  398. @PostMapping(value = "/additionaldamage-response")
  399. public String additionaldamagePaymentresponse(Model model, @RequestParam(required = false) String msg)
  400. throws NoSuchAlgorithmException {
  401. String salt = this.paymentConfig.getEncryptionKey();
  402. String confirmToken = "";
  403. String status = this.paymentConfig.getTransactionSuccessCode();
  404. String s = new String(msg);
  405. String c = new String();
  406. String res[] = s.split("\\|");
  407. TransactionResponse response = this.paymentService.getTransactionResponseByTxansactionId(res[3], "temp");
  408. ExtraPayments payment = new ExtraPayments();
  409. payment.setTransactionId(response.getTxansactionId());
  410. double amount = 0;
  411. for (int i = 0; i < res.length; i++) {
  412. if (i == res.length - 1) {
  413. c = c + salt;
  414. confirmToken = res[i];
  415. } else if (res[i].isEmpty()) {
  416. c = c + "|";
  417. } else if (res[i].equals("NA")) {
  418. c = c + "NA|";
  419. } else {
  420. c = c + res[i] + "|";
  421. }
  422. if (i == 5) {
  423. response.setTpslTxnId(res[i]);
  424. response.setAmount(res[6]);
  425. response.setTxansactionId(res[3]);
  426. // String[] tDate = res[8].split(" ");
  427. response.setDate(res[8]);
  428. }
  429. }
  430. int bookingId = response.getBookingId();
  431. try {
  432. amount = Double.parseDouble(response.getAmount());
  433. } catch (Exception e) {
  434. // TODO: handle exception
  435. // System.out.println("payment Controller lineNo-67");
  436. }
  437. payment.setAmountReceived(amount);
  438. payment.setPaymentStatus("Not Completed");
  439. BookingDetails bookingsDetails = bookser.getBookingsById(bookingId);
  440. payment.setBookingDetails(bookingsDetails);
  441. response.setResponse(msg);
  442. response.setStatusCode(res[0]);
  443. bookingsDetails.setExtrapayments(payment);
  444. payment.setCdate(new Date());
  445. TransactionResponse save = transactionResRepo.save(response);
  446. if (paymentService.generateToken(c).equals(confirmToken) && status.equals(res[0])) {
  447. payment.setPaymentStatus("Success");
  448. bookingsDetails.setExtrapayments(payment);
  449. bookingsDetails.getSettlement().setCollectionStatus("Paid");
  450. bookingsDetails.setBookingStatus(BookingStatus.COMPLETED);
  451. bookingsDetails.setRefundStatus(RefundStatus.CLOSED);
  452. bookingsDetails.setComments("Collection Amount Paid Successfully");
  453. bookingDetailsRepository.save(bookingsDetails);
  454. }
  455. model.addAttribute("bookingsDetails", bookingsDetails);
  456. extraPaymentsRepository.save(payment);
  457. // postEPDataToERP(payment, response); //post extra payments details to ERP
  458. // return
  459. // "redirect:/communityhall/user/collectionpendingacknowledgement?bookingId=" +
  460. // bookingsDetails.getBookingId();
  461. return "redirect:/communityhall/user/collectionpendingacknowledgement?bookingId="
  462. + bookingsDetails.getBookingId();
  463. }
  464. /*
  465. * public void postEPDataToERP(ExtraPayments payment, TransactionResponse res) {
  466. * RestTemplate restTemplate = new RestTemplate();
  467. * erpPostData erpData = new erpPostData();
  468. *
  469. * SimpleDateFormat outputFormat = new SimpleDateFormat("dd/MM/yyyy");
  470. * String txDate = outputFormat.format(payment.getCdate());
  471. * String assesNo = LocalDate.now().getYear() + "/COMM/ED/" +
  472. * res.getBookingId();
  473. *
  474. * Map<String, Object> data = new TreeMap<>();
  475. *//* static mandatory input to be sent *//*
  476. * data.put("serviceId", "getOtherCollection");
  477. * data.put("COLLECTION_TYPE", "Community Hall");
  478. * data.put("TOTALTRANSACTIONCODE", "450310000");
  479. * // /end of static/
  480. * // /unique data to be send/
  481. * data.put("ASSESSMENTNO", assesNo);
  482. * data.put("UNIQUERECEIPTID", res.getBookingId());
  483. * data.put("TRANSACTIONNO", payment.getTransactionId());
  484. * data.put("TRANSACTIONREFNO", res.getTpslTxnId());
  485. * data.put("TRANSACTIONDATE", txDate); //payment date format dd/mm/yyyy
  486. * -> 19/02/2025
  487. * data.put("TOTALTRANSACTIONAMOUNT", payment.getAmountReceived());
  488. *
  489. * data.put("MSTRCODEONE", "061");
  490. * data.put("SPLITAMOUNTONE", 0);
  491. * data.put("MSTRCODETWO", "062");
  492. * data.put("SPLITAMOUNTTWO", payment.getAmountReceived());
  493. * data.put("MSTRCODETHREE", "063");
  494. * data.put("SPLITAMOUNTTHREE", 0);
  495. * // /Amount Collected from party/
  496. * data.put("PARTYNAME",
  497. * payment.getBookingDetails().getUsers().getName());
  498. * data.put("PARTYADDRESS",
  499. * payment.getBookingDetails().getUsers().getStreet() + "," +
  500. * payment.getBookingDetails().getUsers().getArea() + "," +
  501. * payment.getBookingDetails().getUsers().getLocation() + "," +
  502. * payment.getBookingDetails().getUsers().getPinCode());
  503. * data.put("PARTYMOBILE",
  504. * payment.getBookingDetails().getUsers().getMobileNo());
  505. *//* end *//*
  506. * System.out.println(data);
  507. * System.out.println(appConfig.getCommErpUrl());
  508. * // ResponseEntity<String> stringResponseEntity =
  509. * restTemplate.postForEntity(appConfig.getErpUrl(), data,
  510. * String.class);
  511. * // System.out.println(stringResponseEntity.getBody());
  512. *
  513. * erpData.setTx_id(payment.getTransactionId());
  514. * erpData.setBooking_det_booking_id(res.getBookingId());
  515. * erpData.setStatus(true);
  516. * erpData.setCdate(LocalDate.now());
  517. * erpData.setPay_status(2);
  518. * erpPostDataRepository.save(erpData);
  519. *
  520. * UriComponentsBuilder builder =
  521. * UriComponentsBuilder.fromHttpUrl(appConfig.getCommErpUrl())
  522. * ;
  523. * for (Map.Entry<String, Object> entry : data.entrySet()) {
  524. * builder.queryParam(entry.getKey(), entry.getValue());
  525. * }
  526. *
  527. * String urlMsg = builder.toUriString();
  528. * System.out.println(urlMsg);
  529. *
  530. * try {
  531. * HttpURLConnection connection = null;
  532. *
  533. * URL url = new URL(urlMsg);
  534. * connection = (HttpURLConnection) url.openConnection();
  535. * connection.setRequestMethod("GET");
  536. *
  537. * int responseCode = connection.getResponseCode();
  538. * // response=responseCode+"";
  539. * System.out.println("Response Code: " + responseCode);
  540. *
  541. * if (responseCode == HttpURLConnection.HTTP_OK) { // 200 OK
  542. * BufferedReader in = new BufferedReader(new
  543. * InputStreamReader(connection.getInputStream()));
  544. * String inputLine;
  545. * StringBuilder response = new StringBuilder();
  546. * while ((inputLine = in.readLine()) != null) {
  547. * response.append(inputLine);
  548. * }
  549. * in.close();
  550. * System.out.println("Response: " + response.toString());
  551. *
  552. * ObjectMapper objectMapper = new ObjectMapper();
  553. * JsonNode jsonNode =
  554. * objectMapper.readTree(response.toString());
  555. *
  556. * String resultStatus =
  557. * jsonNode.get("ResultStatus").asText();
  558. *
  559. * if (!resultStatus.isEmpty() &&
  560. * resultStatus.equals("false")) {
  561. * erpData.setStatus(false);
  562. * erpPostDataRepository.save(erpData);
  563. * }
  564. *
  565. * } else {
  566. * System.out.println("GET request failed.");
  567. * }
  568. *
  569. * } catch (Exception e) {
  570. * e.printStackTrace();
  571. * }
  572. * }
  573. */
  574. @PostMapping(value = "/updatetransaction")
  575. public String updatetransaction(Model model, @RequestParam(required = false) String txansactionId,
  576. @RequestParam(required = false) String msg) throws NoSuchAlgorithmException {
  577. Optional<TransactionResponse> transactionresponse = transactionResRepo.findByTxansactionId(txansactionId);
  578. TransactionResponse transactionres = transactionresponse.get();
  579. if ("temp".equals(transactionres.getStatusCode()) && !"0300".equals(transactionres.getStatusCode())) {
  580. String salt = this.paymentConfig.getEncryptionKey();
  581. String confirmToken = "";
  582. String status = this.paymentConfig.getTransactionSuccessCode();
  583. String s = new String(msg);
  584. String c = new String();
  585. String res[] = s.split("\\|");
  586. TransactionResponse response = this.paymentService.getTransactionResponseByTxansactionId(res[3], "temp");
  587. Payments payment = new Payments();
  588. payment.setTransactionId(response.getTxansactionId());
  589. double amount = 0;
  590. for (int i = 0; i < res.length; i++) {
  591. if (i == res.length - 1) {
  592. c = c + salt;
  593. confirmToken = res[i];
  594. } else if (res[i].isEmpty()) {
  595. c = c + "|";
  596. } else if (res[i].equals("NA")) {
  597. c = c + "NA|";
  598. } else {
  599. c = c + res[i] + "|";
  600. }
  601. if (i == 5) {
  602. response.setTpslTxnId(res[i]);
  603. response.setAmount(res[6]);
  604. response.setTxansactionId(res[3]);
  605. // String[] tDate = res[8].split(" ");
  606. response.setDate(res[8]);
  607. }
  608. }
  609. int bookingId = response.getBookingId();
  610. try {
  611. amount = Double.parseDouble(response.getAmount());
  612. } catch (Exception e) {
  613. // TODO: handle exception
  614. // System.out.println("payment Controller lineNo-67");
  615. }
  616. payment.setAmountReceived(amount);
  617. payment.setPaymentStatus("Not Completed");
  618. BookingDetails bookingsDetails = bookser.getBookingsById(bookingId);
  619. payment.setBookingDetails(bookingsDetails);
  620. response.setResponse(msg);
  621. response.setStatusCode(res[0]);
  622. bookingsDetails.setPayments(payment);
  623. payment.setCdate(new Date());
  624. TransactionResponse save = transactionResRepo.save(response);
  625. if (paymentService.generateToken(c).equals(confirmToken) && status.equals(res[0])) {
  626. payment.setPaymentStatus("Success");
  627. bookingsDetails.setPayments(payment);
  628. String confirmBooking = bookser.confirmBooking(response.getBookingId());
  629. }
  630. // System.out.println(response.toString());
  631. model.addAttribute("bookingsDetails", bookingsDetails); // Add single BookingDetails object
  632. // System.out.println(save.toString());
  633. paymentRepo.save(payment);
  634. return "success";
  635. } else {
  636. return "already exists";
  637. }
  638. }
  639. @PostMapping(value = "/refundcompleted")
  640. public String refundCompleted(Model model, @RequestParam String txansactionId,
  641. @RequestParam(required = false) String msg) throws NoSuchAlgorithmException {
  642. Optional<TransactionResponse> transactionresponse = transactionResRepo.findByTxansactionId(txansactionId);
  643. if (transactionresponse.isPresent()) {
  644. TransactionResponse transactionres = transactionresponse.get();
  645. Optional<BookingDetails> bookings = bookingDetailsRepository.findById(transactionres.getBookingId());
  646. if (bookings.isPresent()) {
  647. BookingDetails bookingDetails = bookings.get();
  648. bookingDetails.setRefundStatus(RefundStatus.CLOSED);
  649. bookingDetailsRepository.save(bookingDetails);
  650. return "success";
  651. } else {
  652. return "failure";
  653. }
  654. } else {
  655. return "failure";
  656. }
  657. }
  658. }