23 changed files with 2557 additions and 694 deletions
-
82src/main/java/com/gcc/communityHall/entity/erpPostData.java
-
9src/main/java/com/gcc/communityHall/others/AppConfig.java
-
588src/main/java/com/gcc/communityHall/paymentService/controller/PaymentController.java
-
326src/main/java/com/gcc/communityHall/paymentService/controller/RefundController.java
-
140src/main/java/com/gcc/communityHall/paymentService/entity/RefundClientInfo.java
-
23src/main/java/com/gcc/communityHall/paymentService/entity/TransactionResponse.java
-
160src/main/java/com/gcc/communityHall/paymentService/entity/TransactionStatusLog.java
-
8src/main/java/com/gcc/communityHall/paymentService/repository/RefundClientInfoRepository.java
-
15src/main/java/com/gcc/communityHall/paymentService/repository/TransactionResponseRepository.java
-
7src/main/java/com/gcc/communityHall/paymentService/repository/TransactionStatusLogRepository.java
-
291src/main/java/com/gcc/communityHall/paymentService/scheduler/ERPScheduler.java
-
335src/main/java/com/gcc/communityHall/paymentService/scheduler/PaymentStatusScheduler.java
-
25src/main/java/com/gcc/communityHall/repository/ErpPostDataRepository.java
-
7src/main/java/com/gcc/communityHall/repository/ExtraPaymentsRepository.java
-
10src/main/java/com/gcc/communityHall/repository/PaymentsRepository.java
-
8src/main/java/com/gcc/communityHall/repository/RefundTransactionRepository.java
-
1src/main/java/com/gcc/communityHall/service/Impl/PaymentsServiceImpl.java
-
22src/main/java/com/gcc/communityHall/service/Impl/TransactionServiceImpl.java
-
1src/main/java/com/gcc/communityHall/service/PaymentsService.java
-
6src/main/java/com/gcc/communityHall/service/TransactionService.java
-
1src/main/resources/application-dev.properties
-
22src/main/resources/paymentConfig.properties
-
1138src/main/resources/templates/officiallogin.html
@ -0,0 +1,82 @@ |
|||
package com.gcc.communityHall.entity; |
|||
|
|||
import jakarta.persistence.Entity; |
|||
import jakarta.persistence.GeneratedValue; |
|||
import jakarta.persistence.GenerationType; |
|||
import jakarta.persistence.Id; |
|||
import org.springframework.context.annotation.EnableAspectJAutoProxy; |
|||
|
|||
import java.time.LocalDate; |
|||
import java.util.Date; |
|||
|
|||
@Entity |
|||
public class erpPostData { |
|||
@Id |
|||
@GeneratedValue(strategy = GenerationType.IDENTITY) |
|||
private Long id; |
|||
private String tx_id; |
|||
private int booking_det_booking_id; |
|||
private boolean status; |
|||
private LocalDate cdate; |
|||
private int pay_status; |
|||
|
|||
public void setId(Long id) { |
|||
this.id = id; |
|||
} |
|||
|
|||
public Long getId() { |
|||
return id; |
|||
} |
|||
|
|||
public String getTx_id() { |
|||
return tx_id; |
|||
} |
|||
|
|||
public void setTx_id(String tx_id) { |
|||
this.tx_id = tx_id; |
|||
} |
|||
|
|||
public int getBooking_det_booking_id() { |
|||
return booking_det_booking_id; |
|||
} |
|||
|
|||
public void setBooking_det_booking_id(int booking_det_booking_id) { |
|||
this.booking_det_booking_id = booking_det_booking_id; |
|||
} |
|||
|
|||
public boolean isStatus() { |
|||
return status; |
|||
} |
|||
|
|||
public void setStatus(boolean status) { |
|||
this.status = status; |
|||
} |
|||
|
|||
public LocalDate getCdate() { |
|||
return cdate; |
|||
} |
|||
|
|||
public void setCdate(LocalDate cdate) { |
|||
this.cdate = cdate; |
|||
} |
|||
|
|||
public int getPay_status() { |
|||
return pay_status; |
|||
} |
|||
|
|||
public void setPay_status(int pay_status) { |
|||
this.pay_status = pay_status; |
|||
} |
|||
|
|||
@Override |
|||
public String toString() { |
|||
return "erpPostData{" + |
|||
"id=" + id + |
|||
", tx_id='" + tx_id + '\'' + |
|||
", booking_det_booking_id=" + booking_det_booking_id + |
|||
", status=" + status + |
|||
", cdate=" + cdate + |
|||
", pay_status=" + pay_status + |
|||
'}'; |
|||
} |
|||
} |
|||
@ -0,0 +1,326 @@ |
|||
package com.gcc.communityHall.paymentService.controller; |
|||
|
|||
import com.fasterxml.jackson.databind.ObjectMapper; |
|||
import com.gcc.communityHall.entity.BookingDetails; |
|||
import com.gcc.communityHall.entity.Payments; |
|||
import com.gcc.communityHall.entity.RefundTransaction; |
|||
import com.gcc.communityHall.paymentService.config.PaymentConfig; |
|||
import com.gcc.communityHall.paymentService.entity.RefundClientInfo; |
|||
import com.gcc.communityHall.paymentService.entity.RefundResponse; |
|||
import com.gcc.communityHall.paymentService.entity.TransactionResponse; |
|||
import com.gcc.communityHall.paymentService.entity.TransactionStatusLog; |
|||
import com.gcc.communityHall.paymentService.repository.RefundClientInfoRepository; |
|||
import com.gcc.communityHall.paymentService.repository.TransRefundResRepository; |
|||
import com.gcc.communityHall.paymentService.repository.TransactionResponseRepository; |
|||
import com.gcc.communityHall.paymentService.repository.TransactionStatusLogRepository; |
|||
import com.gcc.communityHall.paymentService.service.PaymentGatewayServiceImpl; |
|||
import com.gcc.communityHall.repository.PaymentsRepository; |
|||
import com.gcc.communityHall.service.BookingService; |
|||
import com.gcc.communityHall.service.TransactionService; |
|||
import com.google.gson.Gson; |
|||
import jakarta.transaction.Transactional; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.http.ResponseEntity; |
|||
import org.springframework.web.bind.annotation.GetMapping; |
|||
import org.springframework.web.bind.annotation.RestController; |
|||
import org.springframework.web.client.RestTemplate; |
|||
|
|||
import java.time.LocalDate; |
|||
import java.util.Date; |
|||
import java.util.HashMap; |
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
@RestController |
|||
public class RefundController { |
|||
|
|||
@Autowired |
|||
public RefundClientInfoRepository refundClientInfoRepository; |
|||
|
|||
@Autowired |
|||
public TransactionResponseRepository transactionResponseRepository; |
|||
|
|||
@Autowired |
|||
private TransactionStatusLogRepository transactionStatusLogRepository; |
|||
|
|||
@Autowired |
|||
private PaymentConfig paymentConfig; |
|||
|
|||
@Autowired |
|||
private PaymentsRepository paymentsRepository; |
|||
|
|||
@Autowired |
|||
private BookingService bookingService; |
|||
|
|||
@Autowired |
|||
private PaymentGatewayServiceImpl paymentGatewayService; |
|||
@Autowired |
|||
private TransRefundResRepository transRefundResRepository; |
|||
|
|||
@Autowired |
|||
private TransactionService transactionService; |
|||
@Autowired |
|||
private PaymentGatewayServiceImpl paymentGatewayServiceImpl; |
|||
|
|||
|
|||
@GetMapping(value = "/refundProcess") |
|||
public ResponseEntity refundProcess() { |
|||
try { |
|||
List<Map<String, Object>> pendingTransactions = transactionResponseRepository.getTransactionResponseByStatus("temp"); |
|||
|
|||
for (Map<String, Object> transactionRecord : pendingTransactions) { |
|||
try { |
|||
Map<String, Object> status = new HashMap<>(); |
|||
Map<String, Object> merchant = new HashMap<>(); |
|||
Map<String, Object> transaction = new HashMap<>(); |
|||
|
|||
status.put("merchant", merchant); |
|||
status.put("transaction", transaction); |
|||
|
|||
merchant.put("identifier", paymentConfig.getMerchantId()); |
|||
transaction.put("identifier", transactionRecord.get("txansaction_id")); |
|||
transaction.put("requestType", "O"); |
|||
transaction.put("token", ""); |
|||
transaction.put("reference", ""); |
|||
|
|||
System.out.println("=====================================" + transactionRecord.get("txansaction_id")); |
|||
System.out.println(merchant); |
|||
System.out.println(transaction); |
|||
System.out.println(status); |
|||
System.out.println("======================================"); |
|||
String bookingDate = transactionRecord.get("booking_date").toString(); |
|||
if (bookingDate != null && !bookingDate.isEmpty()) { |
|||
String[] dateParts = bookingDate.split("-"); |
|||
String formattedDate = dateParts[2] + "-" + dateParts[1] + "-" + dateParts[0]; |
|||
transaction.put("dateTime", formattedDate); |
|||
} else { |
|||
transaction.put("dateTime", ""); |
|||
} |
|||
|
|||
|
|||
Gson gson = new Gson(); |
|||
String json = gson.toJson(status); |
|||
System.out.println("Hello json " + json); |
|||
String encryptHxRefund = paymentGatewayService.encryptHxRefund(json); |
|||
|
|||
RestTemplate restTemplate = new RestTemplate(); |
|||
String url = "https://www.tpsl-india.in/PaymentGateway/merchant2.pg/" + paymentConfig.getMerchantId(); |
|||
ResponseEntity<String> postForEntity = restTemplate.postForEntity(url, encryptHxRefund, String.class); |
|||
|
|||
String decryptHxTRefund = paymentGatewayService.decryptHxTRefund(postForEntity.getBody()); |
|||
Map<String, Object> myObj = new ObjectMapper().readValue(decryptHxTRefund, Map.class); |
|||
Map<String, Object> paymentMethod = (Map<String, Object>) myObj.get("paymentMethod"); |
|||
Map<String, Object> response = (Map<String, Object>) paymentMethod.get("paymentTransaction"); |
|||
|
|||
System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"); |
|||
System.out.println("hello2" + response); |
|||
System.out.println("hello " + myObj); |
|||
System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"); |
|||
|
|||
TransactionStatusLog log = new TransactionStatusLog(); |
|||
log.setBookingId(transactionRecord.get("booking_id").toString()); |
|||
log.setUserId(transactionRecord.get("user_id").toString()); |
|||
log.setTransactionId(transactionRecord.get("txansaction_id").toString()); |
|||
// log.setStatus(response.get("status").toString()); |
|||
log.setErrorMessage(response.get("errorMessage").toString()); |
|||
log.setStatusMessage(response.get("statusMessage").toString()); |
|||
log.setStatusCode(response.get("statusCode").toString()); |
|||
log.setRefundIdentifier(response.get("refundIdentifier").toString()); |
|||
// log.setResponse(response.toString()); |
|||
log.setAmount(response.get("amount").toString()); |
|||
log.setBalanceAmt(response.get("balanceAmount").toString()); |
|||
log.setReceivedDate(response.get("dateTime").toString()); |
|||
|
|||
TransactionStatusLog saveLog = transactionStatusLogRepository.save(log); |
|||
|
|||
|
|||
TransactionResponse transRes = transactionResponseRepository.findById(Integer.parseInt(transactionRecord.get("id").toString()) |
|||
).orElseThrow(() -> new Exception("TransactionResponse not found")); |
|||
|
|||
transRes.setStatusCode(log.getStatusCode()); |
|||
transRes.setAmount(log.getAmount()); |
|||
transRes.setTpslTxnId(response.get("identifier").toString()); |
|||
transRes.setResponse(response.toString()); |
|||
transRes.setDate(log.getReceivedDate()); |
|||
|
|||
transactionResponseRepository.save(transRes); |
|||
|
|||
|
|||
Payments payments = paymentsRepository.findByBookingId(Integer.valueOf(String.valueOf(transRes.getBookingId()))); |
|||
|
|||
System.out.println("payments hello" + payments); |
|||
if (payments != null && response.get("statusCode").toString().equals("0300")) { |
|||
|
|||
// payments.setBookingDetails(payments.getBookingDetails()); |
|||
payments.setTransactionId(transRes.getTxansactionId()); |
|||
payments.setAmountReceived(Double.parseDouble(response.get("amount").toString())); |
|||
payments.setPaymentStatus("Success"); |
|||
payments.setCdate(new Date()); |
|||
|
|||
paymentsRepository.save(payments); |
|||
|
|||
bookingService.updateBookingStatus(transRes.getBookingId(), BookingDetails.BookingStatus.REFUNDED, "Booking Not Confirmed. Amount will be refunded shortly."); |
|||
intiateRefund(transRes.getBookingId(), Integer.parseInt(transRes.getUserId())); |
|||
|
|||
} else if (response.get("statusCode").toString().equals("0300")) { |
|||
payments = new Payments(); |
|||
BookingDetails bookingsById = bookingService.getBookingsById(transRes.getBookingId()); |
|||
payments.setBookingDetails(bookingsById); |
|||
payments.setTransactionId(transRes.getTxansactionId()); |
|||
payments.setAmountReceived(Double.parseDouble(response.get("amount").toString())); |
|||
payments.setPaymentStatus("Success"); |
|||
payments.setCdate(new Date()); |
|||
|
|||
paymentsRepository.save(payments); |
|||
|
|||
bookingService.updateBookingStatus(transRes.getBookingId(), BookingDetails.BookingStatus.REFUNDED, "Booking Not Confirmed. Amount will be refunded shortly."); |
|||
intiateRefund(transRes.getBookingId(), Integer.parseInt(transRes.getUserId())); |
|||
} else { |
|||
payments = new Payments(); |
|||
payments.setBookingDetails(payments.getBookingDetails()); |
|||
payments.setTransactionId(transRes.getTxansactionId()); |
|||
try { |
|||
payments.setAmountReceived(Double.parseDouble(response.get("amount") != null ? response.get("amount").toString() : "0"));//error here |
|||
}catch (Exception e ){ |
|||
payments.setAmountReceived(0); |
|||
} |
|||
payments.setPaymentStatus("Not Completed"); |
|||
payments.setCdate(new Date()); |
|||
|
|||
paymentsRepository.save(payments); |
|||
System.out.println("bookingId "+transRes.getBookingId()); |
|||
bookingService.updateBookingStatus(transRes.getBookingId(), BookingDetails.BookingStatus.PAYMENT_FAILURE, "Booking Not Confirmed. Amount Not Received."); |
|||
|
|||
|
|||
} |
|||
updateRefundInfo(response, log); |
|||
|
|||
} catch (Exception ex) { |
|||
System.err.println("Error processing transaction record: " + ex.getMessage()); |
|||
ex.printStackTrace(); |
|||
} |
|||
} |
|||
} catch (Exception e) { |
|||
System.err.println("Error fetching or saving payment status: " + e.getMessage()); |
|||
e.printStackTrace(); |
|||
} |
|||
return ResponseEntity.ok("refundProcess"); |
|||
|
|||
} |
|||
|
|||
|
|||
public void updateRefundInfo(Map<String, Object> response, TransactionStatusLog log) { |
|||
|
|||
if (response.get("refundDdetails") != null) { |
|||
|
|||
Map<String, Object> refundInfo = (Map<String, Object>) response.get("refundDdetails"); |
|||
List<Map<String, Object>> refundDetails = (List<Map<String, Object>>) refundInfo.get("RefundDetails"); |
|||
System.out.println("inifcon :" + refundDetails); |
|||
if (refundDetails != null && !refundDetails.isEmpty()) { |
|||
RefundResponse refundResponse = new RefundResponse(); |
|||
refundResponse.setAmount(response.get("amount") != null ? response.get("amount").toString() : ""); |
|||
refundResponse.setBalaceAmount(response.get("balanceAmount") != null ? response.get("balanceAmount").toString() : ""); |
|||
refundResponse.setTxansactionId(log.getTransactionId()); |
|||
|
|||
Map<String, Object> mapRef = refundDetails.get(refundDetails.size() - 1); |
|||
LocalDate df = LocalDate.now(); |
|||
try { |
|||
df = LocalDate.parse(mapRef.get("REF_TXN_DATE").toString()); |
|||
} catch (Exception e) { |
|||
df = LocalDate.now(); |
|||
} |
|||
; |
|||
refundResponse.setDate(df); |
|||
if (mapRef.get("STATUS") != null && mapRef.get("STATUS").toString().equals("INITIATED")) { |
|||
refundResponse.setStatusCode("0400"); |
|||
} else { |
|||
refundResponse.setStatusCode("0399"); |
|||
} |
|||
refundResponse.setResponse(refundDetails.toString()); |
|||
refundResponse.setBookingId(Integer.parseInt(log.getBookingId())); |
|||
refundResponse.setUserId(log.getUserId()); |
|||
RefundResponse saverRefundResponse = transRefundResRepository.save(refundResponse); |
|||
|
|||
Double amt = Double.parseDouble(response.get("amount").toString()); |
|||
Double balAmt = Double.parseDouble(response.get("balanceAmount").toString()); |
|||
if (amt != balAmt) { |
|||
RefundTransaction refundTrans = transactionService.getRefundTrans(saverRefundResponse.getBookingId()); |
|||
if (refundTrans != null) { |
|||
|
|||
refundTrans.setAmountRefunded(amt - balAmt); |
|||
refundTrans.setRefundStatus("0400"); |
|||
refundTrans.setRefundIdentifier(response.get("refundIdentifier").toString()); |
|||
refundTrans.setCdate(new Date()); |
|||
|
|||
|
|||
transactionService.saveRefundTransaction(refundTrans); |
|||
} else { |
|||
refundTrans = new RefundTransaction(); |
|||
refundTrans.setAmountRefunded(amt - balAmt); |
|||
refundTrans.setRefundStatus("0400"); |
|||
refundTrans.setRefundIdentifier(response.get("refundIdentifier").toString()); |
|||
refundTrans.setCdate(new Date()); |
|||
refundTrans.setTransactionId(log.getTransactionId()); |
|||
BookingDetails bookingsById = bookingService.getBookingsById(Integer.parseInt(log.getBookingId())); |
|||
|
|||
refundTrans.setBookingDetails(bookingsById); |
|||
transactionService.saveRefundTransaction(refundTrans); |
|||
|
|||
|
|||
} |
|||
bookingService.updateRefundStatus(saverRefundResponse.getBookingId(), BookingDetails.RefundStatus.COMPLETED); |
|||
} |
|||
|
|||
saveRefundClientInfo(refundDetails, log.getUserId(), log.getBookingId(), log.getTransactionId()); |
|||
} |
|||
|
|||
|
|||
} |
|||
|
|||
|
|||
} |
|||
|
|||
public String saveRefundClientInfo(List<Map<String, Object>> refundDetail, String userId, String bookingId, String transactionId) { |
|||
|
|||
|
|||
if (refundDetail == null || refundDetail.isEmpty()) { |
|||
return "error"; |
|||
} |
|||
|
|||
|
|||
for (Map<String, Object> refund : refundDetail) { |
|||
|
|||
RefundClientInfo refundClientInfo = new RefundClientInfo(); |
|||
refundClientInfo.setUserId(Integer.parseInt(userId)); |
|||
refundClientInfo.setBookingId(Integer.parseInt(bookingId)); |
|||
refundClientInfo.setTransactionId(transactionId); |
|||
refundClientInfo.setClntRfndId(refund.get("clnt_rfnd_id") != null ? refund.get("clnt_rfnd_id").toString() : ""); |
|||
refundClientInfo.setArnNo(refund.get("ARN_Number") != null ? refund.get("ARN_Number").toString() : ""); |
|||
refundClientInfo.setGetRefTxnDate(refund.get("REF_TXN_DATE") != null ? refund.get("REF_TXN_DATE").toString() : ""); |
|||
refundClientInfo.setRefTxnAmt(refund.get("REF_TXN_AMT") != null ? refund.get("REF_TXN_AMT").toString() : ""); |
|||
refundClientInfo.setRefTxnId(refund.get("REF_TXN_ID") != null ? refund.get("REF_TXN_ID").toString() : ""); |
|||
refundClientInfo.setStatus(refund.get("STATUS") != null ? refund.get("STATUS").toString() : ""); |
|||
refundClientInfo.setSrno(refund.get("SR_NO") != null ? refund.get("SR_NO").toString() : ""); |
|||
|
|||
refundClientInfoRepository.save(refundClientInfo); |
|||
|
|||
} |
|||
return "success"; |
|||
|
|||
} |
|||
|
|||
@Transactional |
|||
public void intiateRefund(int bookingId, int userId) throws Exception { |
|||
String s = paymentGatewayServiceImpl.refundTheAmount(bookingId, userId); |
|||
if (s.equals("Refunded")) { |
|||
bookingService.updateRefundStatus(bookingId, BookingDetails.RefundStatus.COMPLETED); |
|||
|
|||
} else { |
|||
bookingService.updateRefundStatus(bookingId, BookingDetails.RefundStatus.FAILURE); |
|||
} |
|||
|
|||
|
|||
} |
|||
} |
|||
|
|||
|
|||
@ -0,0 +1,140 @@ |
|||
package com.gcc.communityHall.paymentService.entity; |
|||
|
|||
import jakarta.persistence.*; |
|||
|
|||
import java.util.Date; |
|||
|
|||
@Entity |
|||
public class RefundClientInfo { |
|||
|
|||
@Id |
|||
@GeneratedValue(strategy = GenerationType.IDENTITY) |
|||
private int id; |
|||
private String srno; |
|||
private String refTxnId; |
|||
private String refTxnAmt; |
|||
private String getRefTxnDate; |
|||
private String Status; |
|||
private String clntRfndId; |
|||
private String transactionId; |
|||
private String arnNo; |
|||
private int bookingId; |
|||
private int userId; |
|||
@Column(name = "cdate",nullable = false, columnDefinition = "DATETIME DEFAULT CURRENT_TIMESTAMP") |
|||
private Date cdate = new Date(); |
|||
|
|||
public String getClntRfndId() { |
|||
return clntRfndId; |
|||
} |
|||
|
|||
public void setClntRfndId(String clntRfndId) { |
|||
this.clntRfndId = clntRfndId; |
|||
} |
|||
|
|||
public String getTransactionId() { |
|||
return transactionId; |
|||
} |
|||
|
|||
public void setTransactionId(String transactionId) { |
|||
this.transactionId = transactionId; |
|||
} |
|||
|
|||
public int getId() { |
|||
return id; |
|||
} |
|||
|
|||
public void setId(int id) { |
|||
this.id = id; |
|||
} |
|||
|
|||
public String getSrno() { |
|||
return srno; |
|||
} |
|||
|
|||
public void setSrno(String srno) { |
|||
this.srno = srno; |
|||
} |
|||
|
|||
public String getRefTxnId() { |
|||
return refTxnId; |
|||
} |
|||
|
|||
public void setRefTxnId(String refTxnId) { |
|||
this.refTxnId = refTxnId; |
|||
} |
|||
|
|||
public String getRefTxnAmt() { |
|||
return refTxnAmt; |
|||
} |
|||
|
|||
public void setRefTxnAmt(String refTxnAmt) { |
|||
this.refTxnAmt = refTxnAmt; |
|||
} |
|||
|
|||
public String getGetRefTxnDate() { |
|||
return getRefTxnDate; |
|||
} |
|||
|
|||
public void setGetRefTxnDate(String getRefTxnDate) { |
|||
this.getRefTxnDate = getRefTxnDate; |
|||
} |
|||
|
|||
public String getStatus() { |
|||
return Status; |
|||
} |
|||
|
|||
public void setStatus(String status) { |
|||
Status = status; |
|||
} |
|||
|
|||
|
|||
|
|||
public String getArnNo() { |
|||
return arnNo; |
|||
} |
|||
|
|||
public void setArnNo(String arnNo) { |
|||
this.arnNo = arnNo; |
|||
} |
|||
|
|||
public int getBookingId() { |
|||
return bookingId; |
|||
} |
|||
|
|||
public void setBookingId(int bookingId) { |
|||
this.bookingId = bookingId; |
|||
} |
|||
|
|||
public int getUserId() { |
|||
return userId; |
|||
} |
|||
|
|||
public void setUserId(int userId) { |
|||
this.userId = userId; |
|||
} |
|||
|
|||
public Date getCdate() { |
|||
return cdate; |
|||
} |
|||
|
|||
public void setCdate(Date cdate) { |
|||
this.cdate = cdate; |
|||
} |
|||
|
|||
@Override |
|||
public String toString() { |
|||
return "RefundClientInfo{" + |
|||
"id=" + id + |
|||
", srno='" + srno + '\'' + |
|||
", refTxnId='" + refTxnId + '\'' + |
|||
", refTxnAmt='" + refTxnAmt + '\'' + |
|||
", getRefTxnDate='" + getRefTxnDate + '\'' + |
|||
", Status='" + Status + '\'' + |
|||
", clntRfndId='" + clntRfndId + '\'' + |
|||
", arnNo='" + arnNo + '\'' + |
|||
", bookingId=" + bookingId + |
|||
", userId=" + userId + |
|||
", cdate=" + cdate + |
|||
'}'; |
|||
} |
|||
} |
|||
@ -0,0 +1,160 @@ |
|||
package com.gcc.communityHall.paymentService.entity; |
|||
|
|||
import jakarta.persistence.*; |
|||
|
|||
import java.time.LocalDateTime; |
|||
|
|||
@Entity |
|||
|
|||
public class TransactionStatusLog { |
|||
|
|||
@Id |
|||
@GeneratedValue(strategy = GenerationType.IDENTITY) |
|||
private Integer id; |
|||
|
|||
private String transactionId; |
|||
private String bookingId; |
|||
private String userId; |
|||
private String status; |
|||
private String errorMessage; |
|||
private String statusMessage; |
|||
private String statusCode; |
|||
private String refundIdentifier; |
|||
@Column(columnDefinition = "TEXT") |
|||
private String response; |
|||
private String amount; |
|||
private String balanceAmt; |
|||
private String receivedDate; |
|||
|
|||
@Column(name = "cdate",nullable = false, columnDefinition = "DATETIME DEFAULT CURRENT_TIMESTAMP") |
|||
private LocalDateTime cdate = LocalDateTime.now(); |
|||
|
|||
public String getStatusCode() { |
|||
return statusCode; |
|||
} |
|||
|
|||
public void setStatusCode(String statusCode) { |
|||
this.statusCode = statusCode; |
|||
} |
|||
|
|||
public Integer getId() { |
|||
return id; |
|||
} |
|||
|
|||
public String getTransactionId() { |
|||
return transactionId; |
|||
} |
|||
|
|||
public String getBookingId() { |
|||
return bookingId; |
|||
} |
|||
|
|||
public String getUserId() { |
|||
return userId; |
|||
} |
|||
|
|||
public String getStatus() { |
|||
return status; |
|||
} |
|||
|
|||
public String getErrorMessage() { |
|||
return errorMessage; |
|||
} |
|||
|
|||
public String getStatusMessage() { |
|||
return statusMessage; |
|||
} |
|||
|
|||
public void setId(Integer id) { |
|||
this.id = id; |
|||
} |
|||
|
|||
public void setTransactionId(String transactionId) { |
|||
this.transactionId = transactionId; |
|||
} |
|||
|
|||
public void setBookingId(String bookingId) { |
|||
this.bookingId = bookingId; |
|||
} |
|||
|
|||
public void setUserId(String userId) { |
|||
this.userId = userId; |
|||
} |
|||
|
|||
public void setStatus(String status) { |
|||
this.status = status; |
|||
|
|||
} |
|||
|
|||
public void setErrorMessage(String errorMessage) { |
|||
this.errorMessage = errorMessage; |
|||
} |
|||
|
|||
public void setStatusMessage(String statusMessage) { |
|||
this.statusMessage = statusMessage; |
|||
} |
|||
|
|||
public String getRefundIdentifier() { |
|||
return refundIdentifier; |
|||
} |
|||
|
|||
public void setRefundIdentifier(String refundIdentifier) { |
|||
this.refundIdentifier = refundIdentifier; |
|||
} |
|||
|
|||
public String getResponse() { |
|||
return response; |
|||
} |
|||
|
|||
public void setResponse(String response) { |
|||
this.response = response; |
|||
} |
|||
|
|||
public LocalDateTime getCdate() { |
|||
return cdate; |
|||
} |
|||
|
|||
public void setCdate(LocalDateTime cdate) { |
|||
this.cdate = cdate; |
|||
} |
|||
|
|||
public String getAmount() { |
|||
return amount; |
|||
} |
|||
|
|||
public void setAmount(String amount) { |
|||
this.amount = amount; |
|||
} |
|||
|
|||
public String getBalanceAmt() { |
|||
return balanceAmt; |
|||
} |
|||
|
|||
public void setBalanceAmt(String balanceAmt) { |
|||
this.balanceAmt = balanceAmt; |
|||
} |
|||
|
|||
public String getReceivedDate() { |
|||
return receivedDate; |
|||
} |
|||
|
|||
public void setReceivedDate(String receivedDate) { |
|||
this.receivedDate = receivedDate; |
|||
} |
|||
|
|||
@Override |
|||
public String toString() { |
|||
return "TransactionStatusLog{" + |
|||
"id=" + id + |
|||
", transactionId='" + transactionId + '\'' + |
|||
", bookingId='" + bookingId + '\'' + |
|||
", userId='" + userId + '\'' + |
|||
", status='" + status + '\'' + |
|||
", errorMessage='" + errorMessage + '\'' + |
|||
", statusMessage='" + statusMessage + '\'' + |
|||
", statusCode='" + statusCode + '\'' + |
|||
", refundIdentifier='" + refundIdentifier + '\'' + |
|||
", cdate='" + cdate + '\'' + |
|||
'}'; |
|||
} |
|||
} |
|||
@ -0,0 +1,8 @@ |
|||
package com.gcc.communityHall.paymentService.repository; |
|||
|
|||
|
|||
import com.gcc.communityHall.paymentService.entity.RefundClientInfo; |
|||
import org.springframework.data.jpa.repository.JpaRepository; |
|||
|
|||
public interface RefundClientInfoRepository extends JpaRepository<RefundClientInfo, Integer> { |
|||
} |
|||
@ -0,0 +1,7 @@ |
|||
package com.gcc.communityHall.paymentService.repository; |
|||
|
|||
import com.gcc.communityHall.paymentService.entity.TransactionStatusLog; |
|||
import org.springframework.data.jpa.repository.JpaRepository; |
|||
|
|||
public interface TransactionStatusLogRepository extends JpaRepository<TransactionStatusLog, Integer> { |
|||
} |
|||
@ -0,0 +1,291 @@ |
|||
package com.gcc.communityHall.paymentService.scheduler; |
|||
|
|||
import com.fasterxml.jackson.databind.JsonNode; |
|||
import com.fasterxml.jackson.databind.ObjectMapper; |
|||
import com.gcc.communityHall.entity.BookingDetails; |
|||
import com.gcc.communityHall.entity.ExtraPayments; |
|||
import com.gcc.communityHall.entity.Payments; |
|||
import com.gcc.communityHall.entity.erpPostData; |
|||
import com.gcc.communityHall.others.AppConfig; |
|||
import com.gcc.communityHall.paymentService.entity.TransactionResponse; |
|||
import com.gcc.communityHall.paymentService.repository.TransactionResponseRepository; |
|||
import com.gcc.communityHall.repository.ErpPostDataRepository; |
|||
import com.gcc.communityHall.repository.ExtraPaymentsRepository; |
|||
import com.gcc.communityHall.repository.PaymentsRepository; |
|||
import com.gcc.communityHall.service.BookingService; |
|||
import com.gcc.communityHall.service.PaymentsService; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.scheduling.annotation.EnableScheduling; |
|||
import org.springframework.scheduling.annotation.Scheduled; |
|||
import org.springframework.stereotype.Component; |
|||
import org.springframework.stereotype.Service; |
|||
import org.springframework.web.bind.annotation.GetMapping; |
|||
import org.springframework.web.bind.annotation.RequestMapping; |
|||
import org.springframework.web.bind.annotation.RestController; |
|||
import org.springframework.web.client.RestTemplate; |
|||
import org.springframework.web.util.UriComponentsBuilder; |
|||
|
|||
import javax.swing.text.html.Option; |
|||
import java.io.BufferedReader; |
|||
import java.io.InputStreamReader; |
|||
import java.net.HttpURLConnection; |
|||
import java.net.URL; |
|||
import java.text.SimpleDateFormat; |
|||
import java.time.LocalDate; |
|||
import java.util.*; |
|||
|
|||
@Component |
|||
//@EnableScheduling |
|||
public class ERPScheduler { |
|||
|
|||
@Autowired |
|||
private ErpPostDataRepository erpPostDataRepository; |
|||
|
|||
@Autowired |
|||
private AppConfig appConfig; |
|||
|
|||
@Autowired |
|||
private PaymentsRepository paymentsRepository; |
|||
|
|||
@Autowired |
|||
private TransactionResponseRepository transactionResponseRepository; |
|||
|
|||
@Autowired |
|||
private ExtraPaymentsRepository extraPaymentsRepository; |
|||
|
|||
|
|||
@Scheduled(fixedRate = 30000) |
|||
public void checkERPPostData() { |
|||
|
|||
Payments payment = new Payments(); |
|||
ExtraPayments expayment = new ExtraPayments(); |
|||
|
|||
List<erpPostData> notpostedlist = erpPostDataRepository.getNotPostedDetails(); |
|||
|
|||
System.out.println("notpostedlist....." + notpostedlist); |
|||
|
|||
if (!notpostedlist.isEmpty()) { |
|||
for (erpPostData data : notpostedlist) { |
|||
|
|||
Long bookingId = (long) data.getBooking_det_booking_id(); |
|||
String txId = data.getTx_id(); |
|||
int status = data.getPay_status(); |
|||
|
|||
if (bookingId == null) { |
|||
System.out.println("Invalid Booking ID: " + bookingId); |
|||
} else { |
|||
System.out.println("Processing Booking ID: " + bookingId); |
|||
} |
|||
if (status == 1) { |
|||
payment = paymentsRepository.findByBookingId(Math.toIntExact(bookingId)); |
|||
} else if (status == 2) { |
|||
expayment = extraPaymentsRepository.getExtraPaymentsByBookingId(Math.toIntExact(bookingId)).orElse(null); |
|||
} |
|||
// TransactionResponse txRes = transactionResponseRepository.findById(Integer.valueOf(txId)).orElse(null); |
|||
|
|||
TransactionResponse txRes = transactionResponseRepository.findByTxansactionId(txId).orElse(null); |
|||
|
|||
if (payment == null) { |
|||
System.out.println("No Payment found for Booking ID: " + bookingId); |
|||
} |
|||
if (txRes == null) { |
|||
System.out.println("No Transaction Response found for TX ID: " + txId); |
|||
} |
|||
if (expayment == null) { |
|||
System.out.println("No Extra Payment found for Booking ID: " + bookingId); |
|||
} |
|||
|
|||
|
|||
if (status == 1) { |
|||
if (payment != null && txRes != null) { |
|||
postDataToERP(payment, txRes); |
|||
} |
|||
} else if (status == 2) { |
|||
if (expayment != null && txRes != null) { |
|||
postEDDataToERP(expayment, txRes); |
|||
} |
|||
} |
|||
} |
|||
} else { |
|||
System.out.println("No records found to process."); |
|||
} |
|||
} |
|||
|
|||
public void postDataToERP(Payments payment, TransactionResponse res) { |
|||
System.out.println("postDataToERP..."); |
|||
|
|||
erpPostData erpData = new erpPostData(); |
|||
|
|||
SimpleDateFormat outputFormat = new SimpleDateFormat("dd/MM/yyyy"); |
|||
String txDate = outputFormat.format(payment.getCdate()); |
|||
String assesNo = LocalDate.now().getYear() + "/COMM/" + res.getBookingId(); |
|||
|
|||
Map<String, Object> data = new TreeMap<>(); |
|||
/*static mandatory input to be sent */ |
|||
data.put("serviceId", "getOtherCollection"); |
|||
data.put("COLLECTION_TYPE", "Community Hall"); |
|||
data.put("TOTALTRANSACTIONCODE", "450310000"); |
|||
// /end of static/ |
|||
// /unique data to be send/ |
|||
data.put("ASSESSMENTNO", assesNo); |
|||
data.put("UNIQUERECEIPTID", res.getBookingId()); |
|||
data.put("TRANSACTIONNO", payment.getTransactionId()); |
|||
data.put("TRANSACTIONREFNO", res.getTpslTxnId()); |
|||
data.put("TRANSACTIONDATE", txDate); //payment date format dd/mm/yyyy -> 19/02/2025 |
|||
data.put("TOTALTRANSACTIONAMOUNT", payment.getBookingDetails().getAmountReceived()); |
|||
|
|||
data.put("MSTRCODEONE", "061"); |
|||
data.put("SPLITAMOUNTONE", payment.getBookingDetails().getHallAmount()); |
|||
data.put("MSTRCODETWO", "062"); |
|||
data.put("SPLITAMOUNTTWO", payment.getBookingDetails().getDepositAmount()); |
|||
data.put("MSTRCODETHREE", "063"); |
|||
data.put("SPLITAMOUNTTHREE", payment.getBookingDetails().getGst()); |
|||
// /Amount Collected from party/ |
|||
data.put("PARTYNAME", payment.getBookingDetails().getUsers().getName()); |
|||
data.put("PARTYADDRESS", payment.getBookingDetails().getUsers().getStreet() + "," + payment.getBookingDetails().getUsers().getArea() + "," + payment.getBookingDetails().getUsers().getLocation() + "," + payment.getBookingDetails().getUsers().getPinCode()); |
|||
data.put("PARTYMOBILE", payment.getBookingDetails().getUsers().getMobileNo()); |
|||
/* end */ |
|||
System.out.println(data); |
|||
System.out.println(appConfig.getCommErpUrl()); |
|||
// ResponseEntity<String> stringResponseEntity = restTemplate.postForEntity(appConfig.getErpUrl(), data, String.class); |
|||
// System.out.println(stringResponseEntity.getBody()); |
|||
|
|||
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(appConfig.getCommErpUrl()); |
|||
for (Map.Entry<String, Object> entry : data.entrySet()) { |
|||
builder.queryParam(entry.getKey(), entry.getValue()); |
|||
} |
|||
|
|||
String urlMsg = builder.toUriString(); |
|||
System.out.println(urlMsg); |
|||
|
|||
try { |
|||
HttpURLConnection connection = null; |
|||
|
|||
URL url = new URL(urlMsg); |
|||
connection = (HttpURLConnection) url.openConnection(); |
|||
connection.setRequestMethod("GET"); |
|||
|
|||
int responseCode = connection.getResponseCode(); |
|||
// response=responseCode+""; |
|||
System.out.println("Response Code: " + responseCode); |
|||
|
|||
if (responseCode == HttpURLConnection.HTTP_OK) { // 200 OK |
|||
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream())); |
|||
String inputLine; |
|||
StringBuilder response = new StringBuilder(); |
|||
while ((inputLine = in.readLine()) != null) { |
|||
response.append(inputLine); |
|||
} |
|||
in.close(); |
|||
System.out.println("Response: " + response.toString()); |
|||
|
|||
ObjectMapper objectMapper = new ObjectMapper(); |
|||
JsonNode jsonNode = objectMapper.readTree(response.toString()); |
|||
|
|||
String resultStatus = jsonNode.get("ResultStatus").asText(); |
|||
|
|||
if (!resultStatus.isEmpty() && resultStatus.equals("false")) { |
|||
erpPostDataRepository.updateERPStatus(false, erpData.getId()); |
|||
} else{ |
|||
erpPostDataRepository.updateERPStatus(true,erpData.getId()); |
|||
} |
|||
|
|||
} else { |
|||
System.out.println("GET request failed."); |
|||
} |
|||
|
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
} |
|||
} |
|||
|
|||
public void postEDDataToERP(ExtraPayments payment, TransactionResponse res) { |
|||
System.out.println("Post ED Data to ERP...."); |
|||
RestTemplate restTemplate = new RestTemplate(); |
|||
erpPostData erpData = new erpPostData(); |
|||
|
|||
SimpleDateFormat outputFormat = new SimpleDateFormat("dd/MM/yyyy"); |
|||
String txDate = outputFormat.format(payment.getCdate()); |
|||
String assesNo = LocalDate.now().getYear() + "/COMM/ED/" + res.getBookingId(); |
|||
|
|||
Map<String, Object> data = new TreeMap<>(); |
|||
/*static mandatory input to be sent */ |
|||
data.put("serviceId", "getOtherCollection"); |
|||
data.put("COLLECTION_TYPE", "Community Hall"); |
|||
data.put("TOTALTRANSACTIONCODE", "450310000"); |
|||
// /end of static/ |
|||
// /unique data to be send/ |
|||
data.put("ASSESSMENTNO", assesNo); |
|||
data.put("UNIQUERECEIPTID", res.getBookingId()); |
|||
data.put("TRANSACTIONNO", payment.getTransactionId()); |
|||
data.put("TRANSACTIONREFNO", res.getTpslTxnId()); |
|||
data.put("TRANSACTIONDATE", txDate); //payment date format dd/mm/yyyy -> 19/02/2025 |
|||
data.put("TOTALTRANSACTIONAMOUNT", payment.getAmountReceived()); |
|||
|
|||
data.put("MSTRCODEONE", "061"); |
|||
data.put("SPLITAMOUNTONE", 0); |
|||
data.put("MSTRCODETWO", "062"); |
|||
data.put("SPLITAMOUNTTWO", payment.getAmountReceived()); |
|||
data.put("MSTRCODETHREE", "063"); |
|||
data.put("SPLITAMOUNTTHREE", 0); |
|||
// /Amount Collected from party/ |
|||
data.put("PARTYNAME", payment.getBookingDetails().getUsers().getName()); |
|||
data.put("PARTYADDRESS", payment.getBookingDetails().getUsers().getStreet() + "," + |
|||
payment.getBookingDetails().getUsers().getArea() + "," + payment.getBookingDetails().getUsers().getLocation() + "," + |
|||
payment.getBookingDetails().getUsers().getPinCode()); |
|||
data.put("PARTYMOBILE", payment.getBookingDetails().getUsers().getMobileNo()); |
|||
/* end */ |
|||
System.out.println(data); |
|||
System.out.println(appConfig.getCommErpUrl()); |
|||
// ResponseEntity<String> stringResponseEntity = restTemplate.postForEntity(appConfig.getErpUrl(), data, String.class); |
|||
// System.out.println(stringResponseEntity.getBody()); |
|||
|
|||
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(appConfig.getCommErpUrl()); |
|||
for (Map.Entry<String, Object> entry : data.entrySet()) { |
|||
builder.queryParam(entry.getKey(), entry.getValue()); |
|||
} |
|||
|
|||
String urlMsg = builder.toUriString(); |
|||
System.out.println(urlMsg); |
|||
|
|||
try { |
|||
HttpURLConnection connection = null; |
|||
|
|||
URL url = new URL(urlMsg); |
|||
connection = (HttpURLConnection) url.openConnection(); |
|||
connection.setRequestMethod("GET"); |
|||
|
|||
int responseCode = connection.getResponseCode(); |
|||
// response=responseCode+""; |
|||
System.out.println("Response Code: " + responseCode); |
|||
|
|||
if (responseCode == HttpURLConnection.HTTP_OK) { // 200 OK |
|||
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream())); |
|||
String inputLine; |
|||
StringBuilder response = new StringBuilder(); |
|||
while ((inputLine = in.readLine()) != null) { |
|||
response.append(inputLine); |
|||
} |
|||
in.close(); |
|||
System.out.println("Response: " + response.toString()); |
|||
|
|||
ObjectMapper objectMapper = new ObjectMapper(); |
|||
JsonNode jsonNode = objectMapper.readTree(response.toString()); |
|||
|
|||
String resultStatus = jsonNode.get("ResultStatus").asText(); |
|||
|
|||
if (!resultStatus.isEmpty() && resultStatus.equals("false")) { |
|||
erpPostDataRepository.updateERPStatus(false,erpData.getId()); |
|||
} else{ |
|||
erpPostDataRepository.updateERPStatus(true,erpData.getId()); |
|||
} |
|||
|
|||
} else { |
|||
System.out.println("GET request failed."); |
|||
} |
|||
|
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,335 @@ |
|||
package com.gcc.communityHall.paymentService.scheduler;/* |
|||
// Import necessary packages |
|||
package com.gcc.communityHall.paymentService.Scheduler; |
|||
|
|||
import com.fasterxml.jackson.databind.ObjectMapper; |
|||
import com.gcc.communityHall.entity.BookingDetails; |
|||
import com.gcc.communityHall.entity.Payments; |
|||
import com.gcc.communityHall.entity.RefundTransaction; |
|||
import com.gcc.communityHall.paymentService.config.PaymentConfig; |
|||
import com.gcc.communityHall.paymentService.entity.RefundClientInfo; |
|||
import com.gcc.communityHall.paymentService.entity.RefundResponse; |
|||
import com.gcc.communityHall.paymentService.entity.TransactionResponse; |
|||
import com.gcc.communityHall.paymentService.entity.TransactionStatusLog; |
|||
import com.gcc.communityHall.paymentService.repository.RefundClientInfoRepository; |
|||
import com.gcc.communityHall.paymentService.repository.TransRefundResRepository; |
|||
import com.gcc.communityHall.paymentService.repository.TransactionResponseRepository; |
|||
import com.gcc.communityHall.paymentService.repository.TransactionStatusLogRepository; |
|||
import com.gcc.communityHall.paymentService.service.PaymentGatewayServiceImpl; |
|||
import com.gcc.communityHall.repository.PaymentsRepository; |
|||
import com.gcc.communityHall.service.BookingService; |
|||
import com.gcc.communityHall.service.TransactionService; |
|||
import com.google.gson.Gson; |
|||
import jakarta.transaction.Transactional; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.http.ResponseEntity; |
|||
import org.springframework.scheduling.annotation.EnableScheduling; |
|||
import org.springframework.scheduling.annotation.Scheduled; |
|||
import org.springframework.stereotype.Component; |
|||
import org.springframework.web.client.RestTemplate; |
|||
|
|||
import java.time.LocalDate; |
|||
import java.util.Date; |
|||
import java.util.HashMap; |
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
@Component |
|||
@EnableScheduling |
|||
public class PaymentStatusScheduler { |
|||
|
|||
@Autowired |
|||
public RefundClientInfoRepository refundClientInfoRepository; |
|||
|
|||
@Autowired |
|||
public TransactionResponseRepository transactionResponseRepository; |
|||
|
|||
@Autowired |
|||
private TransactionStatusLogRepository transactionStatusLogRepository; |
|||
|
|||
@Autowired |
|||
private PaymentConfig paymentConfig; |
|||
|
|||
@Autowired |
|||
private PaymentsRepository paymentsRepository; |
|||
|
|||
@Autowired |
|||
private BookingService bookingService; |
|||
|
|||
@Autowired |
|||
private PaymentGatewayServiceImpl paymentGatewayService; |
|||
@Autowired |
|||
private TransRefundResRepository transRefundResRepository; |
|||
|
|||
@Autowired |
|||
private TransactionService transactionService; |
|||
@Autowired |
|||
private PaymentGatewayServiceImpl paymentGatewayServiceImpl; |
|||
|
|||
// @Scheduled(cron = "0 0 0 * * ?", zone = "Asia/Kolkata") //executed at 12:00 AM |
|||
// @Scheduled(fixedRate = 900000) |
|||
@Scheduled(fixedRate = 30000) |
|||
public void fetchAndSavePaymentStatus() { |
|||
// System.out.println("Fetching Payment Status...At 12:00 AM IST"); |
|||
System.out.println("Fetching Payment Status...At 15 min Testing"); |
|||
|
|||
try { |
|||
List<Map<String, Object>> pendingTransactions = transactionResponseRepository.getTransResBycdateandStatus("temp"); |
|||
|
|||
for (Map<String, Object> transactionRecord : pendingTransactions) { |
|||
try { |
|||
Map<String, Object> status = new HashMap<>(); |
|||
Map<String, Object> merchant = new HashMap<>(); |
|||
Map<String, Object> transaction = new HashMap<>(); |
|||
|
|||
status.put("merchant", merchant); |
|||
status.put("transaction", transaction); |
|||
|
|||
merchant.put("identifier", paymentConfig.getMerchantId()); |
|||
transaction.put("identifier", transactionRecord.get("txansaction_id")); |
|||
transaction.put("requestType", "O"); |
|||
transaction.put("token", ""); |
|||
transaction.put("reference", ""); |
|||
|
|||
System.out.println("====================================="+ transactionRecord.get("txansaction_id")); |
|||
System.out.println(merchant); |
|||
System.out.println(transaction); |
|||
System.out.println(status); |
|||
System.out.println(transactionRecord.toString()); |
|||
System.out.println("======================================"); |
|||
String bookingDate = transactionRecord.get("booking_date").toString(); |
|||
// System.out.println("cdate check"+transactionRecord.get("cdate").toString()); |
|||
String cdate = transactionRecord.get("cdate").toString(); |
|||
if (cdate != null && !cdate.isEmpty()) { |
|||
String[] dateParts1 = cdate.split(" "); |
|||
String[] dateParts = dateParts1[0].split("-"); |
|||
String formattedDate = dateParts[2] + "-" + dateParts[1] + "-" + dateParts[0]; |
|||
transaction.put("dateTime", formattedDate); |
|||
System.out.println("formattedDate"+formattedDate); |
|||
} else { |
|||
transaction.put("dateTime", ""); |
|||
} |
|||
|
|||
|
|||
Gson gson = new Gson(); |
|||
String json = gson.toJson(status); |
|||
System.out.println("Hello json "+json); |
|||
String encryptHxRefund = paymentGatewayService.encryptHxRefund(json); |
|||
|
|||
RestTemplate restTemplate = new RestTemplate(); |
|||
String url = "https://www.tpsl-india.in/PaymentGateway/merchant2.pg/" + paymentConfig.getMerchantId(); |
|||
ResponseEntity<String> postForEntity = restTemplate.postForEntity(url, encryptHxRefund, String.class); |
|||
|
|||
String decryptHxTRefund = paymentGatewayService.decryptHxTRefund(postForEntity.getBody()); |
|||
Map<String, Object> myObj = new ObjectMapper().readValue(decryptHxTRefund, Map.class); |
|||
Map<String, Object> paymentMethod = (Map<String, Object>)myObj.get("paymentMethod"); |
|||
Map<String, Object> response = (Map<String, Object>)paymentMethod.get("paymentTransaction"); |
|||
|
|||
System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"); |
|||
System.out.println("hello2" + response); |
|||
System.out.println("hello "+myObj); |
|||
System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"); |
|||
|
|||
TransactionStatusLog log = new TransactionStatusLog(); |
|||
log.setBookingId(transactionRecord.get("booking_id").toString()); |
|||
log.setUserId(transactionRecord.get("user_id").toString()); |
|||
log.setTransactionId(transactionRecord.get("txansaction_id").toString()); |
|||
// log.setStatus(response.get("status").toString()); |
|||
log.setErrorMessage(response.get("errorMessage").toString()); |
|||
log.setStatusMessage(response.get("statusMessage").toString()); |
|||
log.setStatusCode(response.get("statusCode").toString()); |
|||
log.setRefundIdentifier(response.get("refundIdentifier").toString()); |
|||
// log.setResponse(response.toString()); |
|||
log.setAmount(response.get("amount").toString()); |
|||
log.setBalanceAmt(response.get("balanceAmount").toString()); |
|||
log.setReceivedDate(response.get("dateTime").toString()); |
|||
|
|||
TransactionStatusLog saveLog = transactionStatusLogRepository.save(log); |
|||
|
|||
|
|||
TransactionResponse transRes = transactionResponseRepository.findById(Integer.parseInt(transactionRecord.get("id").toString()) |
|||
).orElseThrow(() -> new Exception("TransactionResponse not found")); |
|||
|
|||
transRes.setStatusCode(log.getStatusCode()); |
|||
transRes.setAmount(log.getAmount()); |
|||
transRes.setTpslTxnId(response.get("identifier").toString()); |
|||
transRes.setResponse(response.toString()); |
|||
transRes.setDate(log.getReceivedDate()); |
|||
|
|||
transactionResponseRepository.save(transRes); |
|||
|
|||
|
|||
Payments payments = paymentsRepository.findByBookingId(Integer.valueOf(String.valueOf(transRes.getBookingId()))); |
|||
|
|||
System.out.println("payments hello"+payments); |
|||
if(payments!=null && response.get("statusCode").toString().equals("0300")) { |
|||
|
|||
// payments.setBookingDetails(payments.getBookingDetails()); |
|||
payments.setTransactionId(transRes.getTxansactionId()); |
|||
payments.setAmountReceived(Double.parseDouble(response.get("amount").toString())); |
|||
payments.setPaymentStatus("Success"); |
|||
Date date = new Date(payments.getCdate().getTime()); |
|||
|
|||
//paymentsRepository.updatePaymentInfo(payments.getPaymentId(),payments.getTransactionId(),payments.getAmountReceived(),payments.getPaymentStatus(),transRes.getBookingId()); |
|||
|
|||
bookingService.updateBookingStatus(transRes.getBookingId(), BookingDetails.BookingStatus.REFUNDED, "Booking Not Confirmed. Amount will be refunded shortly."); |
|||
intiateRefund(transRes.getBookingId(),Integer.parseInt(transRes.getUserId())); |
|||
|
|||
}else if(response.get("statusCode").toString().equals("0300")){ |
|||
payments = new Payments(); |
|||
|
|||
|
|||
BookingDetails bookingsById = bookingService.getBookingsById(transRes.getBookingId()); |
|||
payments.setBookingDetails(bookingsById); |
|||
payments.setTransactionId(transRes.getTxansactionId()); |
|||
payments.setAmountReceived(Double.parseDouble(response.get("amount").toString())); |
|||
payments.setPaymentStatus("Success"); |
|||
payments.setCdate(new Date()); |
|||
|
|||
//paymentsRepository.insertPaymentinfo(payments.getPaymentId(),payments.getTransactionId(),payments.getAmountReceived(),payments.getPaymentStatus(),transRes.getBookingId(),payments.getCdate() ); |
|||
|
|||
bookingService.updateBookingStatus(transRes.getBookingId(), BookingDetails.BookingStatus.REFUNDED, "Booking Not Confirmed. Amount will be refunded shortly."); |
|||
intiateRefund(transRes.getBookingId(),Integer.parseInt(transRes.getUserId())); |
|||
} |
|||
|
|||
else{ |
|||
payments.setBookingDetails(payments.getBookingDetails()); |
|||
payments.setTransactionId(transRes.getTxansactionId()); |
|||
payments.setAmountReceived(Double.parseDouble(response.get("amount")!=null?response.get("amount").toString():"0")); payments.setPaymentStatus("Not Completed"); |
|||
payments.setCdate(new Date()); |
|||
|
|||
paymentsRepository.save(payments); |
|||
bookingService.updateBookingStatus(transRes.getBookingId(), BookingDetails.BookingStatus.PAYMENT_FAILURE, "Booking Not Confirmed. Amount Not Received."); |
|||
|
|||
|
|||
} |
|||
updateRefundInfo(response,log); |
|||
|
|||
} catch (Exception ex) { |
|||
System.err.println("Error processing transaction record: " + ex.getMessage()); |
|||
ex.printStackTrace(); |
|||
} |
|||
} |
|||
} catch (Exception e) { |
|||
System.err.println("Error fetching or saving payment status: " + e.getMessage()); |
|||
e.printStackTrace(); |
|||
} |
|||
|
|||
|
|||
} |
|||
|
|||
|
|||
public void updateRefundInfo(Map<String,Object> response,TransactionStatusLog log){ |
|||
|
|||
if(response.get("refundDdetails") != null ){ |
|||
|
|||
Map<String,Object> refundInfo= (Map<String, Object>) response.get("refundDdetails"); |
|||
List<Map<String ,Object>> refundDetails = (List<Map<String, Object>>) refundInfo.get("RefundDetails"); |
|||
System.out.println("inifcon :"+ refundDetails); |
|||
if(refundDetails != null && !refundDetails.isEmpty()){ |
|||
RefundResponse refundResponse = new RefundResponse(); |
|||
refundResponse.setAmount(response.get("amount")!=null?response.get("amount").toString():""); |
|||
refundResponse.setBalaceAmount(response.get("balanceAmount")!=null?response.get("balanceAmount").toString():""); |
|||
refundResponse.setTxansactionId(log.getTransactionId()); |
|||
|
|||
Map<String ,Object> mapRef = refundDetails.get(refundDetails.size()-1); |
|||
LocalDate df = LocalDate.now(); |
|||
try{df =LocalDate.parse(mapRef.get("REF_TXN_DATE").toString());}catch (Exception e){df = LocalDate.now();}; |
|||
refundResponse.setDate(df); |
|||
if(mapRef.get("STATUS")!=null && mapRef.get("STATUS").toString().equals("INITIATED")){ |
|||
refundResponse.setStatusCode("0400"); |
|||
}else{ |
|||
refundResponse.setStatusCode("0399"); |
|||
} |
|||
refundResponse.setResponse(refundDetails.toString()); |
|||
refundResponse.setBookingId(Integer.parseInt(log.getBookingId())); |
|||
refundResponse.setUserId(log.getUserId()); |
|||
RefundResponse saverRefundResponse = transRefundResRepository.save(refundResponse); |
|||
|
|||
Double amt = Double.parseDouble(response.get("amount").toString()); |
|||
Double balAmt = Double.parseDouble(response.get("balanceAmount").toString()); |
|||
if(amt != balAmt ) { |
|||
RefundTransaction refundTrans = transactionService.getRefundTrans(saverRefundResponse.getBookingId()); |
|||
if (refundTrans != null) { |
|||
|
|||
refundTrans.setAmountRefunded(amt - balAmt); |
|||
refundTrans.setRefundStatus("0400"); |
|||
refundTrans.setRefundIdentifier(response.get("refundIdentifier").toString()); |
|||
refundTrans.setCdate(new Date()); |
|||
|
|||
|
|||
transactionService.saveRefundTransaction(refundTrans); |
|||
} else { |
|||
refundTrans = new RefundTransaction(); |
|||
refundTrans.setAmountRefunded(amt - balAmt); |
|||
refundTrans.setRefundStatus("0400"); |
|||
refundTrans.setRefundIdentifier(response.get("refundIdentifier").toString()); |
|||
refundTrans.setCdate(new Date()); |
|||
refundTrans.setTransactionId(log.getTransactionId()); |
|||
BookingDetails bookingsById = bookingService.getBookingsById(Integer.parseInt(log.getBookingId())); |
|||
|
|||
refundTrans.setBookingDetails(bookingsById); |
|||
transactionService.saveRefundTransaction(refundTrans); |
|||
|
|||
|
|||
} |
|||
bookingService.updateRefundStatus(saverRefundResponse.getBookingId(),BookingDetails.RefundStatus.COMPLETED); } |
|||
|
|||
saveRefundClientInfo(refundDetails,log.getUserId() ,log.getBookingId(), log.getTransactionId()); |
|||
} |
|||
|
|||
|
|||
|
|||
} |
|||
|
|||
|
|||
} |
|||
public String saveRefundClientInfo(List<Map<String, Object>> refundDetail,String userId,String bookingId,String transactionId) { |
|||
|
|||
|
|||
|
|||
if (refundDetail == null || refundDetail.isEmpty()) { |
|||
return "error"; |
|||
} |
|||
|
|||
|
|||
for (Map<String, Object> refund : refundDetail) { |
|||
|
|||
RefundClientInfo refundClientInfo = new RefundClientInfo(); |
|||
refundClientInfo.setUserId(Integer.parseInt(userId)); |
|||
refundClientInfo.setBookingId(Integer.parseInt(bookingId)); |
|||
refundClientInfo.setTransactionId(transactionId); |
|||
refundClientInfo.setClntRfndId(refund.get("clnt_rfnd_id")!=null?refund.get("clnt_rfnd_id").toString():""); |
|||
refundClientInfo.setArnNo(refund.get("ARN_Number")!=null?refund.get("ARN_Number").toString():""); |
|||
refundClientInfo.setGetRefTxnDate(refund.get("REF_TXN_DATE")!=null?refund.get("REF_TXN_DATE").toString():""); |
|||
refundClientInfo.setRefTxnAmt(refund.get("REF_TXN_AMT")!=null?refund.get("REF_TXN_AMT").toString():""); |
|||
refundClientInfo.setRefTxnId(refund.get("REF_TXN_ID")!=null?refund.get("REF_TXN_ID").toString():""); |
|||
refundClientInfo.setStatus(refund.get("STATUS")!=null?refund.get("STATUS").toString():""); |
|||
refundClientInfo.setSrno(refund.get("SR_NO")!=null?refund.get("SR_NO").toString():""); |
|||
|
|||
refundClientInfoRepository.save(refundClientInfo); |
|||
|
|||
} |
|||
return "success"; |
|||
|
|||
} |
|||
|
|||
@Transactional |
|||
public void intiateRefund(int bookingId,int userId) throws Exception { |
|||
String s = paymentGatewayServiceImpl.refundTheAmount(bookingId, userId); |
|||
if(s.equals("Refunded")){ |
|||
bookingService.updateRefundStatus(bookingId,BookingDetails.RefundStatus.COMPLETED); |
|||
|
|||
}else |
|||
|
|||
{ |
|||
bookingService.updateRefundStatus(bookingId,BookingDetails.RefundStatus.FAILURE); |
|||
} |
|||
|
|||
|
|||
} |
|||
|
|||
} |
|||
|
|||
|
|||
*/ |
|||
@ -0,0 +1,25 @@ |
|||
package com.gcc.communityHall.repository; |
|||
|
|||
import com.gcc.communityHall.entity.erpPostData; |
|||
import jakarta.transaction.Transactional; |
|||
import org.springframework.data.jpa.repository.JpaRepository; |
|||
import org.springframework.data.jpa.repository.Modifying; |
|||
import org.springframework.data.jpa.repository.Query; |
|||
import org.springframework.stereotype.Repository; |
|||
|
|||
import javax.swing.text.html.Option; |
|||
import java.util.List; |
|||
import java.util.Map; |
|||
import java.util.Optional; |
|||
|
|||
@Repository |
|||
public interface ErpPostDataRepository extends JpaRepository<erpPostData, Long> { |
|||
|
|||
@Query(value = "SELECT * FROM erp_post_data WHERE status = false", nativeQuery = true) |
|||
List<erpPostData> getNotPostedDetails(); |
|||
|
|||
@Modifying |
|||
@Transactional |
|||
@Query(value = "update erp_post_data set status = ? where id =?", nativeQuery = true) |
|||
void updateERPStatus(boolean status, Long id); |
|||
} |
|||
@ -1,12 +1,19 @@ |
|||
package com.gcc.communityHall.repository; |
|||
|
|||
import com.gcc.communityHall.entity.Payments; |
|||
import org.springframework.data.jpa.repository.JpaRepository; |
|||
import org.springframework.data.jpa.repository.Query; |
|||
import org.springframework.stereotype.Repository; |
|||
|
|||
import com.gcc.communityHall.entity.EbDetails; |
|||
import com.gcc.communityHall.entity.ExtraPayments; |
|||
|
|||
import java.util.Optional; |
|||
|
|||
@Repository |
|||
public interface ExtraPaymentsRepository extends JpaRepository<ExtraPayments,Integer> { |
|||
|
|||
@Query(value = "SELECT * FROM extra_payments WHERE booking_details_booking_id = ? ",nativeQuery = true) |
|||
Optional<ExtraPayments> getExtraPaymentsByBookingId(int id); |
|||
|
|||
} |
|||
@ -1,16 +1,16 @@ |
|||
package com.gcc.communityHall.repository; |
|||
|
|||
|
|||
import java.util.List; |
|||
|
|||
import com.gcc.communityHall.entity.RefundTransaction; |
|||
import org.springframework.data.jpa.repository.JpaRepository; |
|||
import org.springframework.data.jpa.repository.Query; |
|||
import org.springframework.stereotype.Repository; |
|||
|
|||
import com.gcc.communityHall.entity.RefundTransaction; |
|||
|
|||
@Repository |
|||
public interface RefundTransactionRepository extends JpaRepository<RefundTransaction,Integer> { |
|||
|
|||
|
|||
@Query(value = "select * from refund_transaction where booking_details_booking_id = ?",nativeQuery = true) |
|||
RefundTransaction findByBookingId(int bookingId); |
|||
|
|||
} |
|||
@ -1,4 +1,24 @@ |
|||
package com.gcc.communityHall.service.Impl; |
|||
|
|||
public class TransactionServiceImpl { |
|||
import com.gcc.communityHall.entity.RefundTransaction; |
|||
import com.gcc.communityHall.repository.RefundTransactionRepository; |
|||
import com.gcc.communityHall.service.TransactionService; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Service; |
|||
|
|||
@Service |
|||
public class TransactionServiceImpl implements TransactionService { |
|||
|
|||
@Autowired |
|||
private RefundTransactionRepository refundTransactionRepository; |
|||
|
|||
@Override |
|||
public RefundTransaction getRefundTrans(int bookingId) { |
|||
return refundTransactionRepository.findByBookingId(bookingId); |
|||
} |
|||
|
|||
@Override |
|||
public RefundTransaction saveRefundTransaction(RefundTransaction refundTransaction) { |
|||
return refundTransactionRepository.save(refundTransaction); |
|||
} |
|||
} |
|||
@ -1,4 +1,10 @@ |
|||
package com.gcc.communityHall.service; |
|||
|
|||
import com.gcc.communityHall.entity.RefundTransaction; |
|||
|
|||
public interface TransactionService { |
|||
|
|||
RefundTransaction getRefundTrans(int bookingId); |
|||
|
|||
RefundTransaction saveRefundTransaction(RefundTransaction refundTransaction); |
|||
} |
|||
@ -1,15 +1,15 @@ |
|||
payment.worldline.merchantId=T955031 |
|||
payment.worldline.encryptionKey=1025180466GPADTD |
|||
payment.worldline.encryptionIV=3232693456UWOWHC |
|||
payment.worldline.schemeCode=FIRST |
|||
payment.worldline.merchantName=Greater Chennai Corporation |
|||
payment.worldline.transactionSuccessCode=0300 |
|||
payment.worldline.refundSuccessCode=0400 |
|||
|
|||
#payment.worldline.merchantId=L1037717 |
|||
#payment.worldline.encryptionKey=6207149300MFLGNY |
|||
#payment.worldline.encryptionIV=3422107798TKQCNG |
|||
#payment.worldline.merchantId=T955031 |
|||
#payment.worldline.encryptionKey=1025180466GPADTD |
|||
#payment.worldline.encryptionIV=3232693456UWOWHC |
|||
#payment.worldline.schemeCode=FIRST |
|||
#payment.worldline.merchantName=Greater Chennai Corporation |
|||
#payment.worldline.transactionSuccessCode=0300 |
|||
#payment.worldline.refundSuccessCode=0400 |
|||
|
|||
payment.worldline.merchantId=T1037717 |
|||
payment.worldline.encryptionKey=6207149300MFLGNY |
|||
payment.worldline.encryptionIV=3422107798TKQCNG |
|||
payment.worldline.schemeCode=FIRST |
|||
payment.worldline.merchantName=Greater Chennai Corporation |
|||
payment.worldline.transactionSuccessCode=0300 |
|||
payment.worldline.refundSuccessCode=0400 |
|||
1138
src/main/resources/templates/officiallogin.html
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
Write
Preview
Loading…
Cancel
Save
Reference in new issue