01-12-25
This commit is contained in:
@@ -1,14 +1,17 @@
|
||||
package com.billpaymentservice.bbps.serviceImpl;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import com.billpaymentservice.bbps.config.JwtUtil;
|
||||
import com.billpaymentservice.bbps.dto.UserDetailsDTO;
|
||||
import com.billpaymentservice.bbps.dto.ResponseModel;
|
||||
import com.billpaymentservice.bbps.dto.UserDetailsDTO;
|
||||
import com.billpaymentservice.bbps.dto.auth.AuthResponse;
|
||||
import com.billpaymentservice.bbps.dto.auth.LoginRequest;
|
||||
import com.billpaymentservice.bbps.dto.auth.OtpSendResponse;
|
||||
@@ -18,13 +21,17 @@ import com.billpaymentservice.bbps.dto.auth.VerifyOtpRequest;
|
||||
import com.billpaymentservice.bbps.dto.response.AuthResponses;
|
||||
import com.billpaymentservice.bbps.entites.UserEntity;
|
||||
import com.billpaymentservice.bbps.entites.UsersDetails;
|
||||
import com.billpaymentservice.bbps.exception.CustomException;
|
||||
import com.billpaymentservice.bbps.repository.UserRepository;
|
||||
import com.billpaymentservice.bbps.repository.UsersDetailsRepository;
|
||||
import com.billpaymentservice.bbps.service.AuthService;
|
||||
import com.billpaymentservice.bbps.util.BBPSConstant;
|
||||
import com.billpaymentservice.bbps.util.Helper;
|
||||
import com.billpaymentservice.bbps.util.OtpClient;
|
||||
import java.util.Optional;
|
||||
|
||||
import io.jsonwebtoken.Claims;
|
||||
import io.jsonwebtoken.ExpiredJwtException;
|
||||
import io.jsonwebtoken.JwtException;
|
||||
|
||||
@Service
|
||||
public class AuthServiceImpl implements AuthService {
|
||||
@@ -87,18 +94,22 @@ public class AuthServiceImpl implements AuthService {
|
||||
|
||||
if (user != null) {
|
||||
userDetailsDTO = UserDetailsDTO.builder().id(user.getId()).userEmailId(user.getEmail())
|
||||
.userMobNo(user.getMobile()).userName(user.getName()).userAge(user.getAge()).build();
|
||||
.userMobNo(user.getMobile()).userName(user.getName()).build();
|
||||
}
|
||||
|
||||
AuthResponses authResp = new AuthResponses(token, "Success", "Login Success", 200, userDetailsDTO);
|
||||
AuthResponses authResp = new AuthResponses(token, "Success", "Login Success", 200, userDetailsDTO,
|
||||
null);
|
||||
return ResponseModel.builder().message("Login Success").status("Success").statusCode(200).data(authResp)
|
||||
.build();
|
||||
} else {
|
||||
|
||||
LOGGER.warn("OTP verified successfully, but user not found for mobileNo: {}", mobileNo);
|
||||
// AuthResponses authResp = new AuthResponses("", "User Not Found", "Authentication failed", 401, null);
|
||||
AuthResponses authResp = new AuthResponses("", "User Not Found",
|
||||
"OTP verified successfully, but user not found", BBPSConstant.OTP_VERIFIED_USER_NOT_FORUN,
|
||||
null);
|
||||
|
||||
String token = jwtUtil.generateTemperaryToken(mobileNo);
|
||||
|
||||
AuthResponses authResp = new AuthResponses(null, "User Not Found",
|
||||
"OTP verified successfully, but user not found", BBPSConstant.OTP_VERIFIED_USER_NOT_FORUN, null,
|
||||
token);
|
||||
return ResponseModel.builder().message("OTP verified successfully, but user not found")
|
||||
.status("Failure").statusCode(BBPSConstant.OTP_VERIFIED_USER_NOT_FORUN) // Not Found
|
||||
.data(authResp).build();
|
||||
@@ -115,67 +126,85 @@ public class AuthServiceImpl implements AuthService {
|
||||
@Transactional
|
||||
public ResponseModel<?> registerUser(RegisterRequest request) {
|
||||
try {
|
||||
String tokens = request.getRegistrationToken();
|
||||
Claims claims = jwtUtil.parseToken(tokens); // Parse the JWT token
|
||||
String tokenMobileNo = claims.get("mobileNo", String.class); // Extract the mobile number from the token
|
||||
Date tokenExpiryTime = claims.getExpiration(); // Extract the expiration time from the token
|
||||
String timeGenerated = claims.get("timestamp", String.class);
|
||||
LOGGER.info("Token Mobile Number -:" + tokenMobileNo);
|
||||
LOGGER.info("Time Generated Token -: " + timeGenerated);
|
||||
LOGGER.info("Time Expiry Token -: " + tokenExpiryTime);
|
||||
|
||||
if (!tokenMobileNo.equals(request.getMobile())) {
|
||||
AuthResponse ar = new AuthResponse(false, "User mobile number does not match", request.getMobile());
|
||||
return ResponseModel.builder().message(ar.getMessage()).status("Failure").statusCode(400).data(ar)
|
||||
.build();
|
||||
}
|
||||
Optional<UserEntity> existing = userRepository.findByMobile(request.getMobile());
|
||||
if (existing.isPresent()) {
|
||||
UserEntity u = existing.get();
|
||||
UserDto dto = new UserDto(u.getId(), u.getMobile(), u.getName(), u.getEmail(), u.getAge());
|
||||
UserDto dto = new UserDto(u.getId(), u.getMobile(), u.getName(), u.getEmail());
|
||||
AuthResponse ar = new AuthResponse(false, "User already exists", true, dto);
|
||||
return ResponseModel.builder().message(ar.getMessage()).status("Failure").statusCode(409).data(ar)
|
||||
.build();
|
||||
}
|
||||
|
||||
UserEntity newUser = new UserEntity(request.getMobile(), request.getName(), request.getEmail(),
|
||||
request.getAge());
|
||||
userRepository.save(newUser);
|
||||
String token = jwtUtil.generateToken(newUser.getMobile());
|
||||
UserDto dto = new UserDto(newUser.getId(), newUser.getMobile(), newUser.getName(), newUser.getEmail(),
|
||||
newUser.getAge());
|
||||
UserEntity userEntity = helper.createNewUser(request);
|
||||
userRepository.save(userEntity);
|
||||
String token = jwtUtil.generateToken(userEntity.getMobile());
|
||||
UserDto dto = new UserDto(userEntity.getId(), userEntity.getMobile(), userEntity.getName(),
|
||||
userEntity.getEmail());
|
||||
AuthResponse ar = new AuthResponse(true, "user registed sucessfully", token);
|
||||
return ResponseModel.builder().message(ar.getMessage()).status("Success").statusCode(201).data(ar).build();
|
||||
} catch (ExpiredJwtException e) {
|
||||
LOGGER.error("Token has expired: {}", e.getMessage());
|
||||
return ResponseModel.builder().message("Token has expired. Please log in again.").status("Failure")
|
||||
.statusCode(401).data(null).build();
|
||||
} catch (Exception ex) {
|
||||
LOGGER.error("Error in registerUser: {}", ex.getMessage(), ex);
|
||||
return ResponseModel.builder().message("An unexpected error occurred while registering user")
|
||||
.status("Failure").statusCode(500).data(null).build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseModel<?> authenticateUser(LoginRequest loginRequest) {
|
||||
LOGGER.info("Processing login for Request: {}", loginRequest);
|
||||
|
||||
try {
|
||||
String mobileNo = loginRequest.getMobile();
|
||||
|
||||
Optional<UsersDetails> byMobileNo = userRepo.findByUserMobNo(mobileNo);
|
||||
|
||||
if (byMobileNo.isPresent()) {
|
||||
UsersDetails user = (UsersDetails) byMobileNo.get();
|
||||
String token = jwtUtil.generateToken(user.getUserMobNo());
|
||||
|
||||
LOGGER.info("Generated JWT token for mobileNo: " + mobileNo);
|
||||
|
||||
Object userDetailsDTO = null;
|
||||
|
||||
if (user != null) {
|
||||
userDetailsDTO = UserDetailsDTO.builder().id(user.getId()).userEmailId(user.getUserEmailId())
|
||||
.userMobNo(user.getUserMobNo()).userName(user.getUserName()).userAge(user.getUserAge())
|
||||
.build();
|
||||
}
|
||||
AuthResponses authResp = new AuthResponses(token, "Success", "Login Done", 200, userDetailsDTO);
|
||||
return ResponseModel.builder().message("Login Done").status("Success").statusCode(200).data(authResp)
|
||||
.build();
|
||||
} else {
|
||||
AuthResponses authResp = new AuthResponses("", "User Not Found", "Authentication failed", 401, null);
|
||||
return ResponseModel.builder().message("User Not Found").status("Failure").statusCode(401)
|
||||
.data(authResp).build();
|
||||
}
|
||||
|
||||
} catch (Exception ex) {
|
||||
LOGGER.error("Error occurred during login for mobile no: {} Exception: {}", loginRequest.getMobile(),
|
||||
ex.getMessage(), ex);
|
||||
return ResponseModel.builder().message("Authentication failed: " + ex.getMessage()).status("Failure")
|
||||
.statusCode(500).data(null).build();
|
||||
}
|
||||
// LOGGER.info("Processing login for Request: {}", loginRequest);
|
||||
//
|
||||
// try {
|
||||
// String mobileNo = loginRequest.getMobile();
|
||||
//
|
||||
// Optional<UsersDetails> byMobileNo = userRepo.findByUserMobNo(mobileNo);
|
||||
//
|
||||
// if (byMobileNo.isPresent()) {
|
||||
// UsersDetails user = (UsersDetails) byMobileNo.get();
|
||||
// String token = jwtUtil.generateToken(user.getUserMobNo());
|
||||
//
|
||||
// LOGGER.info("Generated JWT token for mobileNo: " + mobileNo);
|
||||
//
|
||||
// Object userDetailsDTO = null;
|
||||
//
|
||||
// if (user != null) {
|
||||
// userDetailsDTO = UserDetailsDTO.builder().id(user.getId()).userEmailId(user.getUserEmailId())
|
||||
// .userMobNo(user.getUserMobNo()).userName(user.getUserName()).build();
|
||||
// }
|
||||
// AuthResponses authResp = new AuthResponses(token, "Success", "Login Done", 200, userDetailsDTO);
|
||||
// return ResponseModel.builder().message("Login Done").status("Success").statusCode(200).data(authResp)
|
||||
// .build();
|
||||
// } else {
|
||||
// AuthResponses authResp = new AuthResponses("", "User Not Found", "Authentication failed", 401, null);
|
||||
// return ResponseModel.builder().message("User Not Found").status("Failure").statusCode(401)
|
||||
// .data(authResp).build();
|
||||
// }
|
||||
//
|
||||
//
|
||||
// } catch (Exception ex) {
|
||||
// LOGGER.error("Error occurred during login for mobile no: {} Exception: {}", loginRequest.getMobile(),
|
||||
// ex.getMessage(), ex);
|
||||
// return ResponseModel.builder().message("Authentication failed: " + ex.getMessage()).status("Failure")
|
||||
// .statusCode(500).data(null).build();
|
||||
// }
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -124,6 +124,22 @@ public class ComplainServiceImpl implements ComplainService {
|
||||
|
||||
TransactionMaster transData = dataById.get();
|
||||
// Inject tenantId + agentId into request JSON
|
||||
String transactionCreatedDateString = transData.getCreationDate();
|
||||
LOGGER.info("Date is coming -:" + transactionCreatedDateString);
|
||||
LOGGER.info("Return Date Time After 24 Hours"
|
||||
+ BillerMapperHelper.isComplaintAllowed(transactionCreatedDateString));
|
||||
if (!BillerMapperHelper.isComplaintAllowed(transactionCreatedDateString)) {
|
||||
|
||||
LOGGER.warn("Complaint cannot be raised after 24 hours for txnId: {}", complainRequestDTO.getTxnId());
|
||||
|
||||
String responseData = "Complaint cannot be raised after 24 hours for txnId: "
|
||||
+ complainRequestDTO.getTxnId();
|
||||
helper.updateOutboundLogResponse(outboundLog, responseData);
|
||||
|
||||
return ResponseModel.builder().message("Complaint cannot be raised after 24 hours of transaction.")
|
||||
.status("Failure").statusCode(400) // Bad request
|
||||
.data(null).build();
|
||||
}
|
||||
ObjectNode root = (ObjectNode) objectMapper.readTree(forwardJson);
|
||||
root.put("tenantId", headersData.getTenantId());
|
||||
root.put("agentId", headersData.getAgentId());
|
||||
@@ -169,6 +185,9 @@ public class ComplainServiceImpl implements ComplainService {
|
||||
// Convert to response wrapper
|
||||
ComplaintResponse responseWrapper = objectMapper.convertValue(dataMap, ComplaintResponse.class);
|
||||
|
||||
String saveComplaintResponseEntity = mapperHelper.saveComplaintResponseEntity(responseWrapper, requestId,
|
||||
txnId);
|
||||
LOGGER.info("Save Complaint Response Count" + saveComplaintResponseEntity);
|
||||
ResponseModel responseModel = new ResponseModel(responseWrapper.getMessage(), responseWrapper.getStatus(),
|
||||
Integer.parseInt(responseWrapper.getStatusCode()), responseWrapper);
|
||||
|
||||
|
||||
@@ -7,6 +7,8 @@ import org.springframework.stereotype.Service;
|
||||
|
||||
import com.billpaymentservice.bbps.dto.ResponseModel;
|
||||
import com.billpaymentservice.bbps.dto.TransactionHistoryMasterDTO;
|
||||
import com.billpaymentservice.bbps.dto.TransactionHistoryParticularDetailsDTO;
|
||||
import com.billpaymentservice.bbps.dto.request.PaymentHistoryByTxnRequest;
|
||||
import com.billpaymentservice.bbps.dto.request.PaymentHistoryRequest;
|
||||
import com.billpaymentservice.bbps.entites.InboundTraceLog;
|
||||
import com.billpaymentservice.bbps.entites.OutboundTraceLog;
|
||||
@@ -36,7 +38,7 @@ public class TxnHistoryServiceImpl implements TxnHistoryService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseModel getPaymentHostoryDetails(PaymentHistoryRequest paymentHistoryRequest) {
|
||||
public ResponseModel getPaymentHistoryDetails(PaymentHistoryRequest paymentHistoryRequest) {
|
||||
|
||||
String apiName = BBPSConstant.GET_PAYMENT_HISTORY;
|
||||
String requestId = paymentHistoryRequest.getReqId();
|
||||
@@ -65,8 +67,8 @@ public class TxnHistoryServiceImpl implements TxnHistoryService {
|
||||
Integer responseData = dataResult.size();
|
||||
log.info("[{}] Response Fetch From DB | reqId={} | data={}", apiName, requestId, responseData);
|
||||
|
||||
List<TransactionHistoryMasterDTO> responseDatas = dataResult.stream().map(mapperHelper::toDTO)
|
||||
.collect(Collectors.toList());
|
||||
List<TransactionHistoryParticularDetailsDTO> responseDatas = dataResult.stream()
|
||||
.map(mapperHelper::billerRemainingDetails).collect(Collectors.toList());
|
||||
|
||||
helper.updateOutboundLogResponse(outboundLog, String.valueOf(responseData));
|
||||
|
||||
@@ -86,4 +88,54 @@ public class TxnHistoryServiceImpl implements TxnHistoryService {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseModel getPaymentHistoryDetailsByTxnId(PaymentHistoryByTxnRequest request) {
|
||||
String apiName = BBPSConstant.GET_PAYMENT_HISTORY_BY_TXN_ID;
|
||||
String requestId = request.getReqId();
|
||||
String mid = request.getMid();
|
||||
String clientUserId = request.getClientUserId();
|
||||
log.info("[{}] START | reqId={} | mid={} | userId={}", apiName, requestId, mid, clientUserId);
|
||||
|
||||
String txnId = helper.generateTxnId(15);
|
||||
String fullUrl = "this api fetch data from DB not BBPS url !";
|
||||
log.info("[{}] Full URL={}", apiName, fullUrl);
|
||||
String requestJson = helper.convertObjectToJson(request);
|
||||
InboundTraceLog inboundLog = helper.createInboundLog(requestId, txnId, apiName, mid, BBPSConstant.HTTP_GET,
|
||||
requestJson);
|
||||
helper.validateMerchant(mid);
|
||||
OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, requestId, apiName, fullUrl,
|
||||
BBPSConstant.HTTP_GET, null);
|
||||
|
||||
try {
|
||||
List<TransactionMaster> dataResult = transactionMasterRepository.findByTxnId(request.getTxnId());
|
||||
|
||||
if (dataResult == null || dataResult.isEmpty()) {
|
||||
log.info("[{}] Response Fetch From DB | reqId={} | data={}", apiName, requestId, dataResult);
|
||||
throw new CustomException("No Transcation Found This Txn", "FAILED", BBPSConstant.BADREQUEST, null);
|
||||
}
|
||||
|
||||
Integer responseData = dataResult.size();
|
||||
log.info("[{}] Response Fetch From DB | reqId={} | data={}", apiName, requestId, responseData);
|
||||
|
||||
TransactionMaster transaction = dataResult.get(0); // Fetch the first transaction if you want one
|
||||
TransactionHistoryMasterDTO transactionDTO = mapperHelper.toDTO(transaction); // Convert to DTO
|
||||
|
||||
helper.updateOutboundLogResponse(outboundLog, String.valueOf(responseData));
|
||||
|
||||
return new ResponseModel(BBPSConstant.ALL_MASTER_FIELDS_FETCH, BBPSConstant.SUCCESS_RESPONSE,
|
||||
BBPSConstant.HTTP_OK_INT, transactionDTO,null,responseData);
|
||||
|
||||
} catch (CustomException e) {
|
||||
// Log and rethrow the custom exception
|
||||
log.error("[{}] CustomException occurred: {}", apiName, e.getMessage(), e);
|
||||
helper.updateInboundLogFailure(inboundLog, e.getMessage(), BBPSConstant.NO_BILL_FOUND);
|
||||
throw e; // Propagate the exact CustomException
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("JSON Parsing Error: {}", e.getMessage());
|
||||
helper.updateInboundLogFailure(inboundLog, e.getMessage(), BBPSConstant.JSON_ERROR);
|
||||
throw new CustomException("Invalid JSON received from API");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user