01-12-25
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
package com.billpaymentservice.bbps.config;
|
||||
|
||||
import java.security.Key;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
import java.util.Base64;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
@@ -67,13 +69,13 @@ public class JwtUtil {
|
||||
|
||||
private String createToken(Map<String, Object> claims, String subject) {
|
||||
return Jwts.builder().setClaims(claims).setSubject(subject).setIssuedAt(new Date(System.currentTimeMillis()))
|
||||
.setExpiration(new Date(System.currentTimeMillis() + BBPSConstant.JWT_EXPIRATION_MS))
|
||||
.setExpiration(new Date(System.currentTimeMillis() + BBPSConstant.JWT_TEMPERARY_EXPIRATION_MS))
|
||||
.signWith(getSigningKey(), SignatureAlgorithm.HS512).compact();
|
||||
}
|
||||
|
||||
private String createToken1(Map<String, Object> claims,String subject) {
|
||||
private String createToken1(Map<String, Object> claims, String subject) {
|
||||
return Jwts.builder().setClaims(claims).setSubject(subject).setIssuedAt(new Date(System.currentTimeMillis()))
|
||||
.setExpiration(new Date(System.currentTimeMillis() + 1000 * 60 * 60 * 10))
|
||||
.setExpiration(new Date(System.currentTimeMillis() + BBPSConstant.JWT_EXPIRATION_MS))
|
||||
.signWith(getSigningKey(), SignatureAlgorithm.HS512).compact();
|
||||
}
|
||||
|
||||
@@ -83,10 +85,10 @@ public class JwtUtil {
|
||||
// }
|
||||
|
||||
public Boolean validateToken(String token, UserDetails userDetails) {
|
||||
final String mobileNo = extractUsername(token);
|
||||
final String mobileNo = extractUsername(token);
|
||||
// System.out.println("Extracted mobileNo from token: " + mobileNo );
|
||||
// System.out.println("Username from UserDetails: " + userDetails.getUsername());
|
||||
return (mobileNo .equals(userDetails.getUsername()) && !isTokenExpired(token));
|
||||
return (mobileNo.equals(userDetails.getUsername()) && !isTokenExpired(token));
|
||||
}
|
||||
|
||||
public void invalidateToken(String token) {
|
||||
@@ -101,7 +103,28 @@ public class JwtUtil {
|
||||
public String generateToken(String mobileNo) {
|
||||
Map<String, Object> claims = new HashMap<>();
|
||||
claims.put("mobileNo", mobileNo);
|
||||
return createToken1(claims,mobileNo);
|
||||
return createToken1(claims, mobileNo);
|
||||
}
|
||||
|
||||
public String generateTemperaryToken(String mobileNo) {
|
||||
Map<String, Object> claims = new HashMap<>();
|
||||
long currentTime = System.currentTimeMillis();
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("hh:mm a dd/MM/yyyy");
|
||||
String formattedDate = sdf.format(new Date(currentTime));
|
||||
claims.put("mobileNo", mobileNo);
|
||||
claims.put("timestamp", formattedDate);
|
||||
return createToken(claims, mobileNo);
|
||||
}
|
||||
|
||||
public Claims parseToken(String token) {
|
||||
byte[] decodedKey = Base64.getDecoder().decode(secret);
|
||||
Key key = Keys.hmacShaKeyFor(decodedKey); // Generate the key
|
||||
|
||||
return Jwts.parserBuilder() // Use parserBuilder() instead of parser() as it's more modern
|
||||
.setSigningKey(key) // Use the Key object
|
||||
.build() // Build the JwtParser
|
||||
.parseClaimsJws(token) // Parse the JWT
|
||||
.getBody(); // Return claims
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.billpaymentservice.bbps.dto.ResponseModel;
|
||||
import com.billpaymentservice.bbps.dto.request.PaymentHistoryByTxnRequest;
|
||||
import com.billpaymentservice.bbps.dto.request.PaymentHistoryRequest;
|
||||
import com.billpaymentservice.bbps.service.TxnHistoryService;
|
||||
|
||||
@@ -32,7 +33,15 @@ public class TxnHistoryController {
|
||||
public ResponseEntity<ResponseModel> getPaymentHistory(
|
||||
@Validated @RequestBody PaymentHistoryRequest paymentHistoryRequest) {
|
||||
|
||||
ResponseModel response = txnHistory.getPaymentHostoryDetails(paymentHistoryRequest);
|
||||
ResponseModel response = txnHistory.getPaymentHistoryDetails(paymentHistoryRequest);
|
||||
return ResponseEntity.ok(response);
|
||||
}
|
||||
|
||||
@PostMapping(value = "/paymentHistoryByTxnId", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
public ResponseEntity<ResponseModel> getPaymentHistoryByTxnId(
|
||||
@Validated @RequestBody PaymentHistoryByTxnRequest request) {
|
||||
|
||||
ResponseModel response = txnHistory.getPaymentHistoryDetailsByTxnId(request);
|
||||
return ResponseEntity.ok(response);
|
||||
}
|
||||
}
|
||||
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
package com.billpaymentservice.bbps.dto;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class TransactionHistoryParticularDetailsDTO {
|
||||
|
||||
private String billerCategory;
|
||||
|
||||
private String billerName;
|
||||
|
||||
private Double totalTxnAmount;
|
||||
|
||||
private String bankTxnId;
|
||||
|
||||
private String txnId;
|
||||
|
||||
private String creationDate;
|
||||
|
||||
private String status;
|
||||
}
|
||||
@@ -18,6 +18,4 @@ public class UserDetailsDTO {
|
||||
private String userMobNo;
|
||||
|
||||
private String userName;
|
||||
|
||||
private String userAge;
|
||||
}
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
package com.billpaymentservice.bbps.dto.auth;
|
||||
|
||||
import com.billpaymentservice.bbps.dto.request.BaseClass;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class RegisterRequest {
|
||||
private String mobile;
|
||||
private String name;
|
||||
private String email;
|
||||
private String age;
|
||||
public class RegisterRequest extends BaseClass {
|
||||
private String mobile;
|
||||
private String name;
|
||||
private String email;
|
||||
private String registrationToken;
|
||||
|
||||
}
|
||||
@@ -10,11 +10,9 @@ import lombok.Setter;
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class UserDto {
|
||||
private Long id;
|
||||
private String mobile;
|
||||
private String name;
|
||||
private String email;
|
||||
private String age;
|
||||
private Long id;
|
||||
private String mobile;
|
||||
private String name;
|
||||
private String email;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.billpaymentservice.bbps.dto.request;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class PaymentHistoryByTxnRequest extends BaseClass {
|
||||
|
||||
@NotBlank(message = "txn Id not be null")
|
||||
private String txnId;
|
||||
}
|
||||
@@ -23,6 +23,8 @@ public class AuthResponses {
|
||||
|
||||
private String anotherData;
|
||||
|
||||
private String registrationToken;
|
||||
|
||||
// Constructor
|
||||
public AuthResponses(String status, String message, int statusCode, String token) {
|
||||
|
||||
@@ -32,12 +34,14 @@ public class AuthResponses {
|
||||
this.token = token;
|
||||
}
|
||||
|
||||
public AuthResponses(String token, String status, String message, int statusCode, Object data) {
|
||||
public AuthResponses(String token, String status, String message, int statusCode, Object data,
|
||||
String registrationToken) {
|
||||
this.token = token;
|
||||
this.status = status;
|
||||
this.message = message;
|
||||
this.statusCode = statusCode;
|
||||
this.data = data;
|
||||
this.registrationToken = registrationToken;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
package com.billpaymentservice.bbps.entites;
|
||||
|
||||
import com.billpaymentservice.bbps.audit.Auditable;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.GenerationType;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.Table;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Entity
|
||||
@Getter
|
||||
@Setter
|
||||
@Table(name = "complaint_responses")
|
||||
public class ComplaintResponseEntity extends Auditable<String> {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
private Long id;
|
||||
|
||||
@Column(name = "ref_id")
|
||||
private String refId;
|
||||
|
||||
@Column(name = "txn_npci_id")
|
||||
private String txnNpciId;
|
||||
|
||||
@Column(name = "ticket_id")
|
||||
private String ticketId;
|
||||
|
||||
@Column(name = "ticket_type")
|
||||
private String ticketType;
|
||||
|
||||
@Column(name = "ticket_npci_id")
|
||||
private String ticketNpciId;
|
||||
|
||||
@Column(name = "ticket_desp")
|
||||
private String ticketDesp;
|
||||
|
||||
@Column(name = "ticket_desr")
|
||||
private String ticketDesr;
|
||||
|
||||
@Column(name = "message")
|
||||
private String message;
|
||||
|
||||
@Column(name = "remarks")
|
||||
private String remarks;
|
||||
|
||||
@Column(name = "status")
|
||||
private String status;
|
||||
|
||||
@Column(name = "status_code")
|
||||
private String statusCode;
|
||||
|
||||
@Column(name = "complaint_ticket_id")
|
||||
private String complaintTicketId;
|
||||
|
||||
@Column(name = "req_id")
|
||||
private String reqId;
|
||||
|
||||
@Column(name = "txn_id")
|
||||
private String txnId;
|
||||
|
||||
}
|
||||
@@ -21,29 +21,20 @@ import lombok.Setter;
|
||||
@NoArgsConstructor
|
||||
public class UserEntity extends Auditable<String> {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@Column(name = "mobile", nullable = false, unique = true, length = 20)
|
||||
private String mobile;
|
||||
@Column(name = "mobile", nullable = false, unique = true, length = 20)
|
||||
private String mobile;
|
||||
|
||||
@Column(name = "name", length = 150)
|
||||
private String name;
|
||||
@Column(name = "name", length = 150)
|
||||
private String name;
|
||||
|
||||
@Column(name = "email", length = 150)
|
||||
private String email;
|
||||
|
||||
@Column(name = "age")
|
||||
private String age;
|
||||
|
||||
public UserEntity(String mobile, String name, String email, String age) {
|
||||
this.mobile = mobile;
|
||||
this.name = name;
|
||||
this.email = email;
|
||||
this.age = age;
|
||||
}
|
||||
@Column(name = "email", length = 150)
|
||||
private String email;
|
||||
|
||||
@Column(name = "mid")
|
||||
private String mid;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.billpaymentservice.bbps.repository;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import com.billpaymentservice.bbps.entites.ComplaintResponseEntity;
|
||||
|
||||
@Repository
|
||||
public interface ComplaintResponseRepository extends JpaRepository<ComplaintResponseEntity, Long> {
|
||||
|
||||
}
|
||||
@@ -14,4 +14,7 @@ public interface TransactionMasterRepository extends JpaRepository<TransactionMa
|
||||
List<TransactionMaster> findByMidOrClientUserId(@Param("mid") String mid,
|
||||
@Param("clientUserId") String clientUserId);
|
||||
|
||||
@Query("SELECT t FROM TransactionMaster t WHERE t.txnId = :txnId")
|
||||
List<TransactionMaster> findByTxnId(@Param("txnId") String txnId);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
package com.billpaymentservice.bbps.service;
|
||||
|
||||
import com.billpaymentservice.bbps.dto.ResponseModel;
|
||||
import com.billpaymentservice.bbps.dto.request.PaymentHistoryByTxnRequest;
|
||||
import com.billpaymentservice.bbps.dto.request.PaymentHistoryRequest;
|
||||
|
||||
public interface TxnHistoryService {
|
||||
|
||||
ResponseModel getPaymentHostoryDetails(PaymentHistoryRequest paymentHistoryRequest);
|
||||
ResponseModel getPaymentHistoryDetails(PaymentHistoryRequest paymentHistoryRequest);
|
||||
|
||||
ResponseModel getPaymentHistoryDetailsByTxnId(PaymentHistoryByTxnRequest request);
|
||||
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,15 +1,19 @@
|
||||
package com.billpaymentservice.bbps.util;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
public class BBPSConstant {
|
||||
|
||||
// Jwt Token Expiration Time
|
||||
public static final long JWT_EXPIRATION_MS = 1000 * 60 * 60 * 24; // 24 hours
|
||||
public static final long JWT_TEMPERARY_EXPIRATION_MS = 1000 * 60 * 5; // 5 minutes
|
||||
public static final long REFRESH_EXPIRATION_MS = 1000L * 60 * 60 * 24 * 7; // 7 days
|
||||
|
||||
public static final Long SENT_TO_PROCESSOR_CODE = 198L;
|
||||
public static final Long SUCCESS_CODE = 200L;
|
||||
public static final Long FAILED_CODE = 99L;
|
||||
public static final int OTP_VERIFIED_USER_NOT_FORUN =601;
|
||||
public static final int OTP_VERIFIED_USER_NOT_FORUN = 601;
|
||||
public static final Long SCHEDULER_CODE = 222L;
|
||||
public static final Long PENDING_CODE = 211L;
|
||||
public static final Long FRAUD_CODE = 1001L;
|
||||
@@ -106,6 +110,7 @@ public class BBPSConstant {
|
||||
public static final String API_FETCH_PLAN_BY_CATEGORIES = "FetchPlanByCategories";
|
||||
public static final String API_GET_TICKET_DISPOSITIONS = "GetTicketDispositionDetails";
|
||||
public static final String GET_PAYMENT_HISTORY = "GET_PAYMENT_HISTORY";
|
||||
public static final String GET_PAYMENT_HISTORY_BY_TXN_ID = "GET_PAYMENT_HISTORY_TXN_ID";
|
||||
|
||||
// Payment related API names
|
||||
public static final String API_INITIATE_PAYMENT = "InitiatePayment";
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package com.billpaymentservice.bbps.util;
|
||||
|
||||
import java.time.OffsetDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
@@ -7,6 +10,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.modelmapper.ModelMapper;
|
||||
@@ -32,6 +36,7 @@ import com.billpaymentservice.bbps.dto.PlanDTO;
|
||||
import com.billpaymentservice.bbps.dto.TicketDetailsDTO;
|
||||
import com.billpaymentservice.bbps.dto.TicketDispositionsDTO;
|
||||
import com.billpaymentservice.bbps.dto.TransactionHistoryMasterDTO;
|
||||
import com.billpaymentservice.bbps.dto.TransactionHistoryParticularDetailsDTO;
|
||||
import com.billpaymentservice.bbps.dto.request.BillFetchByBillIdRequest;
|
||||
import com.billpaymentservice.bbps.dto.request.BillPaymentRequest;
|
||||
import com.billpaymentservice.bbps.dto.request.ComplaintRequestDTO;
|
||||
@@ -42,6 +47,7 @@ import com.billpaymentservice.bbps.dto.response.AmountOptionsResponse;
|
||||
import com.billpaymentservice.bbps.dto.response.BillDataResponse;
|
||||
import com.billpaymentservice.bbps.dto.response.ClientReqIdResponse;
|
||||
import com.billpaymentservice.bbps.dto.response.ComplaintHistoryStatusResponse;
|
||||
import com.billpaymentservice.bbps.dto.response.ComplaintResponse;
|
||||
import com.billpaymentservice.bbps.dto.response.FetchBillValidateResponse;
|
||||
import com.billpaymentservice.bbps.dto.response.PlanResponse;
|
||||
import com.billpaymentservice.bbps.dto.response.TicketCheckStatusResponse;
|
||||
@@ -72,6 +78,7 @@ import com.billpaymentservice.bbps.entites.CheckClientBillerData;
|
||||
import com.billpaymentservice.bbps.entites.CheckClientStatusReqId;
|
||||
import com.billpaymentservice.bbps.entites.ComplainStatus;
|
||||
import com.billpaymentservice.bbps.entites.ComplaintHistory;
|
||||
import com.billpaymentservice.bbps.entites.ComplaintResponseEntity;
|
||||
import com.billpaymentservice.bbps.entites.ComplaintStatusDetails;
|
||||
import com.billpaymentservice.bbps.entites.ContactMasterData;
|
||||
import com.billpaymentservice.bbps.entites.CustomerParamBill;
|
||||
@@ -97,6 +104,7 @@ import com.billpaymentservice.bbps.repository.CheckClientBillerDataRepository;
|
||||
import com.billpaymentservice.bbps.repository.ClientReqIdRepository;
|
||||
import com.billpaymentservice.bbps.repository.ComplainDetailRepository;
|
||||
import com.billpaymentservice.bbps.repository.ComplaintHistoryRepository;
|
||||
import com.billpaymentservice.bbps.repository.ComplaintResponseRepository;
|
||||
import com.billpaymentservice.bbps.repository.ComplaintStatusRepository;
|
||||
import com.billpaymentservice.bbps.repository.ContactMasterDataRepository;
|
||||
import com.billpaymentservice.bbps.repository.CustomerParamGroupByBillerIdRepository;
|
||||
@@ -130,6 +138,7 @@ public class BillerMapperHelper {
|
||||
private final BillerDataRepository billerDataRespository;
|
||||
private final BillMasterRepository billMasterRepository;
|
||||
private final BillValidationRepository billValidationRepository;
|
||||
private final ComplaintResponseRepository complaintResponseRepository;
|
||||
|
||||
public BillerMapperHelper(BillerCategoryWiseRepository billerRepo,
|
||||
CustomerParamGroupByBillerIdRepository customerParamGroupByBillerIdRepo,
|
||||
@@ -145,7 +154,8 @@ public class BillerMapperHelper {
|
||||
ViewAllComplainTicketDetailRepository viewAllComplainTicketDetailRepository,
|
||||
ContactMasterDataRepository contactMasterDataRepository, BBPSMasterDataRepo bbpsMasterDataRepo,
|
||||
BillerDataRepository billerDataRespository, BillMasterRepository billMasterRepository,
|
||||
BillValidationRepository billValidationRepository) {
|
||||
BillValidationRepository billValidationRepository,
|
||||
ComplaintResponseRepository complaintResponseRepository) {
|
||||
this.billerRepo = billerRepo;
|
||||
this.customerParamGroupByBillerIdRepo = customerParamGroupByBillerIdRepo;
|
||||
this.amountOptionByBillerIdRepository = amountOptionByBillerIdRepository;
|
||||
@@ -165,6 +175,7 @@ public class BillerMapperHelper {
|
||||
this.billerDataRespository = billerDataRespository;
|
||||
this.billMasterRepository = billMasterRepository;
|
||||
this.billValidationRepository = billValidationRepository;
|
||||
this.complaintResponseRepository = complaintResponseRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1109,4 +1120,95 @@ public class BillerMapperHelper {
|
||||
|
||||
return dto;
|
||||
}
|
||||
|
||||
public TransactionHistoryParticularDetailsDTO billerRemainingDetails(TransactionMaster transactionMaster) {
|
||||
if (transactionMaster == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Create a new DTO and set the values from the entity
|
||||
TransactionHistoryParticularDetailsDTO dto = new TransactionHistoryParticularDetailsDTO();
|
||||
dto.setBankTxnId(transactionMaster.getBankTxnId());
|
||||
dto.setTxnId(transactionMaster.getTxnId());
|
||||
dto.setCreationDate(transactionMaster.getCreationDate());
|
||||
dto.setBillerCategory(transactionMaster.getBillerCategory());
|
||||
dto.setBillerName(transactionMaster.getBillerName());
|
||||
dto.setStatus(transactionMaster.getStatus());
|
||||
dto.setTotalTxnAmount(transactionMaster.getTotalTxnAmount());
|
||||
|
||||
return dto;
|
||||
}
|
||||
|
||||
public static boolean isComplaintAllowed(String transactionCreatedDateString) {
|
||||
// Define the format of the transaction creation date including the time zone
|
||||
// offset
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssXXX");
|
||||
|
||||
try {
|
||||
// Parse the transaction creation date string to OffsetDateTime (handles time
|
||||
// zone)
|
||||
OffsetDateTime transactionCreatedDate = OffsetDateTime.parse(transactionCreatedDateString, formatter);
|
||||
|
||||
// Get the current time (with offset)
|
||||
OffsetDateTime currentTime = OffsetDateTime.now();
|
||||
|
||||
// Calculate the difference in hours
|
||||
long hoursDifference = ChronoUnit.HOURS.between(transactionCreatedDate, currentTime);
|
||||
|
||||
// Return true if complaint can be raised (i.e., within 24 hours)
|
||||
return hoursDifference >= 24;
|
||||
|
||||
} catch (Exception e) {
|
||||
// Handle invalid date format or other parsing issues
|
||||
System.err.println("Invalid date format: " + e.getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public String saveComplaintResponseEntity(ComplaintResponse responseWrapper, String requestId, String txnId) {
|
||||
|
||||
// 1. Convert ComplaintResponse DTO to ComplaintResponseEntity
|
||||
ComplaintResponseEntity complaintResponseEntity = new ComplaintResponseEntity();
|
||||
|
||||
// Map fields from DTO to entity
|
||||
complaintResponseEntity.setRefId(responseWrapper.getTicketDetails().getRefId()); // For example, generate a
|
||||
// unique ID
|
||||
complaintResponseEntity.setTxnNpciId(responseWrapper.getTicketDetails().getTxnNpciId());
|
||||
complaintResponseEntity.setTicketId(responseWrapper.getTicketDetails().getTicketId());
|
||||
complaintResponseEntity.setTicketType(responseWrapper.getTicketDetails().getTicketType());
|
||||
complaintResponseEntity.setTicketNpciId(responseWrapper.getTicketDetails().getTicketNpciId());
|
||||
complaintResponseEntity.setTicketDesp(responseWrapper.getTicketDetails().getTicketDesp());
|
||||
complaintResponseEntity.setTicketDesr(responseWrapper.getTicketDetails().getTicketDesr());
|
||||
|
||||
// Additional fields from ComplaintResponse DTO
|
||||
complaintResponseEntity.setMessage(responseWrapper.getMessage());
|
||||
complaintResponseEntity.setRemarks(responseWrapper.getRemarks());
|
||||
complaintResponseEntity.setStatus(responseWrapper.getStatus());
|
||||
complaintResponseEntity.setStatusCode(responseWrapper.getStatusCode());
|
||||
|
||||
// Set requestId and txnId from parameters
|
||||
complaintResponseEntity.setReqId(requestId);
|
||||
complaintResponseEntity.setTxnId(txnId);
|
||||
complaintResponseEntity.setCreateDateTime(new Date());
|
||||
// If you need a separate complaintTicketId, you can set it here
|
||||
complaintResponseEntity.setComplaintTicketId(generateComplaintTicketId()); // Generate or set manually
|
||||
|
||||
// Save the entity
|
||||
complaintResponseRepository.save(complaintResponseEntity);
|
||||
ComplaintResponseEntity savedEntity = complaintResponseRepository.save(complaintResponseEntity);
|
||||
|
||||
// Check if the entity is saved successfully and return count (1 for success)
|
||||
if (savedEntity != null) {
|
||||
return "1 record saved with RefId: " + savedEntity.toString();
|
||||
} else {
|
||||
return "Failed to save complaint response.";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Save Complain Response From DB
|
||||
private String generateComplaintTicketId() {
|
||||
// Logic for generating complaint ticket ID
|
||||
return "CMP-" + UUID.randomUUID().toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,9 @@ package com.billpaymentservice.bbps.util;
|
||||
|
||||
import java.security.SecureRandom;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Date;
|
||||
import java.util.Random;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
@@ -10,10 +13,10 @@ import org.springframework.stereotype.Component;
|
||||
|
||||
import com.billpaymentservice.bbps.dto.auth.RegisterRequest;
|
||||
import com.billpaymentservice.bbps.entites.BBPSMastersData;
|
||||
import com.billpaymentservice.bbps.entites.BharatConnectMaster;
|
||||
import com.billpaymentservice.bbps.entites.InboundTraceLog;
|
||||
import com.billpaymentservice.bbps.entites.OutboundTraceLog;
|
||||
import com.billpaymentservice.bbps.entites.UserEntity;
|
||||
import com.billpaymentservice.bbps.entites.BharatConnectMaster;
|
||||
import com.billpaymentservice.bbps.exception.CustomException;
|
||||
import com.billpaymentservice.bbps.repository.BBPSMasterDataRepo;
|
||||
import com.billpaymentservice.bbps.repository.BillMasterRepository;
|
||||
@@ -170,12 +173,15 @@ public class Helper {
|
||||
|
||||
public UserEntity createNewUser(RegisterRequest request) {
|
||||
UserEntity user = new UserEntity();
|
||||
|
||||
user.setMobile(request.getMobile());
|
||||
user.setName(request.getName());
|
||||
user.setEmail(request.getEmail());
|
||||
user.setAge(request.getAge());
|
||||
return user;
|
||||
|
||||
// user.setId(generateUserId());
|
||||
user.setMobile(request.getMobile());
|
||||
user.setName(request.getName());
|
||||
user.setEmail(request.getEmail());
|
||||
user.setMid(request.getMid());
|
||||
user.setCreateDateTime(new Date());
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user