@ -5,6 +5,7 @@ package com.gcc.communityHall.paymentService.scheduler;
/ / package com.gcc.communityHall.paymentService.Scheduler ;
import com.fasterxml.jackson.databind.ObjectMapper ;
import com.gcc.communityHall.entity.BookingCalendar ;
import com.gcc.communityHall.entity.BookingDetails ;
import com.gcc.communityHall.entity.Payments ;
import com.gcc.communityHall.entity.RefundTransaction ;
@ -20,6 +21,7 @@ import com.gcc.communityHall.paymentService.repository.TransactionStatusLogRepos
import com.gcc.communityHall.paymentService.service.PaymentGatewayServiceImpl ;
import com.gcc.communityHall.repository.PaymentsRepository ;
import com.gcc.communityHall.service.BookingService ;
import com.gcc.communityHall.service.CalendarService ;
import com.gcc.communityHall.service.TransactionService ;
import com.google.gson.Gson ;
import jakarta.transaction.Transactional ;
@ -31,10 +33,7 @@ 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 ;
import java.util.* ;
@Component
@EnableScheduling
@ -68,11 +67,14 @@ public class PaymentStatusScheduler {
@Autowired
private PaymentGatewayServiceImpl paymentGatewayServiceImpl ;
/ / @Scheduled ( cron = "0 0 0 * * ?" , zone = "Asia/Kolkata" ) / / executed at 12 : 00 AM
/ / @Scheduled ( fixedRate = 900000 )
@Autowired
private CalendarService calendarService ;
/ / @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 12:00 AM IST" ) ;
System . out . println ( "Fetching Payment Status...At 15 min Testing" ) ;
try {
@ -93,21 +95,21 @@ public class PaymentStatusScheduler {
transaction . put ( "token" , "" ) ;
transaction . put ( "reference" , "" ) ;
System . out . println ( "=====================================" + transactionRecord . get ( "txansaction_id" ) ) ;
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 ( ) ) ;
/ / 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 ) ;
System . out . println ( "formattedDate" + formattedDate ) ;
} else {
transaction . put ( "dateTime" , "" ) ;
}
@ -115,7 +117,7 @@ public class PaymentStatusScheduler {
Gson gson = new Gson ( ) ;
String json = gson . toJson ( status ) ;
System . out . println ( "Hello json " + json ) ;
System . out . println ( "Hello json " + json ) ;
String encryptHxRefund = paymentGatewayService . encryptHxRefund ( json ) ;
RestTemplate restTemplate = new RestTemplate ( ) ;
@ -124,12 +126,12 @@ public class PaymentStatusScheduler {
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" ) ;
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 ( "hello " + myObj ) ;
System . out . println ( ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" ) ;
TransactionStatusLog log = new TransactionStatusLog ( ) ;
@ -141,7 +143,7 @@ public class PaymentStatusScheduler {
log . setStatusMessage ( response . get ( "statusMessage" ) . toString ( ) ) ;
log . setStatusCode ( response . get ( "statusCode" ) . toString ( ) ) ;
log . setRefundIdentifier ( response . get ( "refundIdentifier" ) . toString ( ) ) ;
/ / log . setResponse ( response . toString ( ) ) ;
/ / log . setResponse ( response . toString ( ) ) ;
log . setAmount ( response . get ( "amount" ) . toString ( ) ) ;
log . setBalanceAmt ( response . get ( "balanceAmount" ) . toString ( ) ) ;
log . setReceivedDate ( response . get ( "dateTime" ) . toString ( ) ) ;
@ -163,21 +165,21 @@ public class PaymentStatusScheduler {
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" ) ) {
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 . 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 ( ) ) ;
/ / 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 ( ) ) ) ;
intiateRefund ( transRes . getBookingId ( ) , Integer . parseInt ( transRes . getUserId ( ) ) ) ;
} else if ( response . get ( "statusCode" ) . toString ( ) . equals ( "0300" ) ) {
} else if ( response . get ( "statusCode" ) . toString ( ) . equals ( "0300" ) ) {
payments = new Payments ( ) ;
@ -191,13 +193,12 @@ public class PaymentStatusScheduler {
/ / 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 {
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 . setAmountReceived ( Double . parseDouble ( response . get ( "amount" ) ! = null ? response . get ( "amount" ) . toString ( ) : "0" ) ) ;
payments . setPaymentStatus ( "Not Completed" ) ;
payments . setCdate ( new Date ( ) ) ;
paymentsRepository . save ( payments ) ;
@ -205,7 +206,7 @@ public class PaymentStatusScheduler {
}
updateRefundInfo ( response , log ) ;
updateRefundInfo ( response , log ) ;
} catch ( Exception ex ) {
System . err . println ( "Error processing transaction record: " + ex . getMessage ( ) ) ;
@ -221,26 +222,31 @@ public class PaymentStatusScheduler {
}
public void updateRefundInfo ( Map < String , Object > response , TransactionStatusLog log ) {
public void updateRefundInfo ( Map < String , Object > response , TransactionStatusLog log ) {
if ( response . get ( "refundDdetails" ) ! = null ) {
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 ( ) ) {
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 . 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 ) ;
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 ( ) ; } ;
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" ) ) {
if ( mapRef . get ( "STATUS" ) ! = null & & mapRef . get ( "STATUS" ) . toString ( ) . equals ( "INITIATED" ) ) {
refundResponse . setStatusCode ( "0400" ) ;
} else {
} else {
refundResponse . setStatusCode ( "0399" ) ;
}
refundResponse . setResponse ( refundDetails . toString ( ) ) ;
@ -250,7 +256,7 @@ public class PaymentStatusScheduler {
Double amt = Double . parseDouble ( response . get ( "amount" ) . toString ( ) ) ;
Double balAmt = Double . parseDouble ( response . get ( "balanceAmount" ) . toString ( ) ) ;
if ( amt ! = balAmt ) {
if ( amt ! = balAmt ) {
RefundTransaction refundTrans = transactionService . getRefundTrans ( saverRefundResponse . getBookingId ( ) ) ;
if ( refundTrans ! = null ) {
@ -263,31 +269,36 @@ public class PaymentStatusScheduler {
transactionService . saveRefundTransaction ( refundTrans ) ;
} else {
refundTrans = new RefundTransaction ( ) ;
refundTrans . setAmountRefunded ( amt - balAmt ) ;
double refundAmt = amt - balAmt ;
System . out . println ( "refundAmt.." + refundAmt ) ;
refundTrans . setAmountRefunded ( refundAmt ) ;
refundTrans . setRefundStatus ( "0400" ) ;
refundTrans . setRefundIdentifier ( response . get ( "refundIdentifier" ) . toString ( ) ) ;
refundTrans . setCdate ( new Date ( ) ) ;
refundTrans . setTransactionId ( log . getTransactionId ( ) ) ;
BookingDetails bookings = new BookingDetails ( ) ;
BookingDetails bookingsById = bookingService . getBookingsById ( Integer . parseInt ( log . getBookingId ( ) ) ) ;
refundTrans . setBookingDetails ( bookingsById ) ;
transactionService . saveRefundTransaction ( refundTrans ) ;
System . out . println ( "bookingsById" + bookingsById . getBookingId ( ) ) ;
bookings . setBookingId ( bookingsById . getBookingId ( ) ) ;
refundTrans . setBookingDetails ( bookings ) ;
System . out . println ( refundTrans . toString ( ) ) ;
transactionService . saveRefundTransactionDetails ( refundTrans ) ;
}
bookingService . updateRefundStatus ( saverRefundResponse . getBookingId ( ) , BookingDetails . RefundStatus . COMPLETED ) ; }
/ / bookingService . updateRefundStatus ( saverRefundResponse . getBookingId ( ) , BookingDetails . RefundStatus . COMPLETED ) ;
bookingService . updateRefundStatusScheduler ( saverRefundResponse . getBookingId ( ) , BookingDetails . RefundStatus . COMPLETED ) ;
}
saveRefundClientInfo ( refundDetails , log . getUserId ( ) , log . getBookingId ( ) , log . getTransactionId ( ) ) ;
saveRefundClientInfo ( refundDetails , log . getUserId ( ) , log . getBookingId ( ) , log . getTransactionId ( ) ) ;
}
}
}
public String saveRefundClientInfo ( List < Map < String , Object > > refundDetail , String userId , String bookingId , String transactionId ) {
public String saveRefundClientInfo ( List < Map < String , Object > > refundDetail , String userId , String bookingId , String transactionId ) {
if ( refundDetail = = null | | refundDetail . isEmpty ( ) ) {
@ -301,38 +312,39 @@ public class PaymentStatusScheduler {
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 ( ) : "" ) ;
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 {
@Transactional
public void intiateRefund ( int bookingId , int userId ) throws Exception {
List < BookingCalendar > bc = calendarService . getCalendarByBookingId ( bookingId ) ;
if ( bc ! = null & & bc . isEmpty ( ) ) {
String s = paymentGatewayServiceImpl . refundTheAmount ( bookingId , userId ) ;
if ( s . equals ( "Refunded" ) ) {
bookingService . updateRefundStatus ( bookingId , BookingDetails . RefundStatus . COMPLETED ) ;
} else
{
bookingService . updateRefundStatus ( bookingId , BookingDetails . RefundStatus . FAILURE ) ;
if ( s . equals ( "Refunded" ) ) {
bookingService . updateRefundStatus ( bookingId , BookingDetails . RefundStatus . COMPLETED ) ;
}
} else {
bookingService . updateRefundStatus ( bookingId , BookingDetails . RefundStatus . FAILURE ) ;
}
}
}
* /