update tran pin request

Nabeel-DG-BS
Raja Nabeel 2 years ago
parent 6f95055761
commit d605caaa82

@ -10,4 +10,5 @@ public interface UCOURI {
String GENERATE_TRANSACTIONS_REPORT = "/generateReport";
String CREATE_TRAN_PIN = "/createTransactionPin";
String VERIFY_TRAN_PIN = "/verifyTransactionPin";
String CHANGE_TRAN_PIN = "/changeTransactionPin";
}

@ -128,7 +128,7 @@ public class UserController {
try {
boolean isVerified = transactionPinService.verifyOTPAndSavePin(request);
if (isVerified) {
return ResponseEntity.ok("PIN verified successfully.");
return ResponseEntity.ok("OTP PIN verified and tran pin changed successfully.");
} else {
return ResponseEntity.badRequest().body("PIN verification failed.");
}
@ -136,4 +136,16 @@ public class UserController {
return ResponseEntity.status(500).body("Error during PIN verification: " + e.getMessage());
}
}
@PutMapping(UCOURI.CHANGE_TRAN_PIN)
public ResponseEntity<String> updateTransactionPin(@RequestBody ChangeTransactionPinRequest request) {
try {
transactionPinService.updateTransactionPin(request);
return ResponseEntity.ok("OTP sent");
} catch (IllegalArgumentException e) {
return ResponseEntity.badRequest().body("Error: " + e.getMessage());
} catch (Exception e) {
return ResponseEntity.internalServerError().body("An unexpected error occurred.");
}
}
}

@ -0,0 +1,20 @@
package com.mfsys.uco.dto;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class ChangeTransactionPinRequest {
private String oldTransPincode;
private String newTransPincode;
private String channelCode;
private String pctCstycode;
private String porOrgacode;
private String cmpCustcode;
private boolean isOtpRequired;
}

@ -0,0 +1,13 @@
package com.mfsys.uco.exception;
import com.mfsys.comm.exception.ApplicationException;
import com.mfsys.comm.exception.ERRCode;
import javax.swing.*;
public class OldPinIncorrectException extends ApplicationException {
public OldPinIncorrectException() {
super(null, ERRCode.OLD_PIN_INCORRECT, null);
}
}

@ -53,6 +53,8 @@ public class CustomerProfile {
@Column(name = "CMP_TRAN_PIN", nullable=false, columnDefinition=FieldNameLength.PIN_VALUE)
protected String cmpTranpin;
@Column(name = "CMP_UNVERIFIED_TRAN_PIN", nullable=true, columnDefinition=FieldNameLength.PIN_VALUE)
protected String cmpUnverifiedTranpin;
@Column(name = "CMP_TRAN_PIN_VERIFIED", nullable=false, columnDefinition=FieldNameLength.BOOLEAN_BIT)
protected boolean cmpTranpinVerfied = false;
}

@ -1,19 +1,22 @@
package com.mfsys.uco.service;
import com.mfsys.uco.dto.ChangeTransactionPinRequest;
import com.mfsys.uco.dto.CreateTransactionPinRequest;
import com.mfsys.uco.dto.OTPRequest;
import com.mfsys.uco.dto.VerifyPinRequest;
import com.mfsys.uco.exception.OldPinIncorrectException;
import com.mfsys.uco.model.CustomerProfile;
import com.mfsys.uco.model.CustomerProfileId;
import com.mfsys.uco.repository.CustomerProfileRepository;
import com.mfsys.uco.repository.PinRepository;
import jakarta.transaction.Transactional;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import java.util.Optional;
import java.util.Objects;
@Service
@RequiredArgsConstructor
@Transactional
public class TransactionPinService {
private final CustomerProfileRepository customerProfileRepository;
@ -21,18 +24,8 @@ public class TransactionPinService {
public void createTransactionPin(CreateTransactionPinRequest request) {
CustomerProfile profile = fetchCustomer(request.getPorOrgacode(), request.getCmpCustcode());
OTPRequest otpRequest = OTPRequest.builder()
.porOrgacode(request.getPorOrgacode())
.channelCode(request.getChannelCode())
.pinType("C_PIN")
.email(profile.getCmpEmail())
.phone(profile.getPadAdrsmobphone())
.isOtpRequired(request.isOtpRequired())
.username(profile.getCmpUserName())
.subject("Create Transaction Pin Verification OTP")
.build();
notificationService.sendOtp(otpRequest);
profile.setCmpTranpin(request.getNewTransPincode());
sendOtp(profile, request.getChannelCode(), "C_PIN", "Create Transaction Pin Verification OTP", request.isOtpRequired());
customerProfileRepository.save(profile);
}
@ -40,6 +33,10 @@ public class TransactionPinService {
public boolean verifyOTPAndSavePin(VerifyPinRequest request) {
notificationService.verifyOtp(request.getPorOrgacode(), request.getEmail(), request.getObpPincode());
CustomerProfile profile = fetchCustomer(request.getPorOrgacode(), request.getCmpCustcode());
if(Objects.nonNull(profile.getCmpUnverifiedTranpin())) {
profile.setCmpTranpin(profile.getCmpUnverifiedTranpin());
profile.setCmpUnverifiedTranpin(null);
}
profile.setCmpTranpinVerfied(true);
customerProfileRepository.save(profile);
return true;
@ -50,4 +47,33 @@ public class TransactionPinService {
return customerProfileRepository.findById(profileId)
.orElseThrow(() -> new IllegalArgumentException("Customer profile not found for ID: " + profileId));
}
public void updateTransactionPin(ChangeTransactionPinRequest request) {
CustomerProfile profile = fetchCustomer(request.getPorOrgacode(), request.getCmpCustcode());
validateOldPin(profile, request.getOldTransPincode());
profile.setCmpUnverifiedTranpin(request.getNewTransPincode());
customerProfileRepository.save(profile);
sendOtp(profile, request.getChannelCode(), "U_PIN", "Change Transaction Pin Verification OTP", request.isOtpRequired());
}
private void validateOldPin(CustomerProfile profile, String oldPin) {
if (!profile.getCmpTranpin().equals(oldPin)) {
throw new OldPinIncorrectException();
}
}
private void sendOtp(CustomerProfile profile, String channelCode, String pinType, String subject, boolean isOtpRequired) {
OTPRequest otpRequest = OTPRequest.builder()
.porOrgacode(profile.getPorOrgacode())
.channelCode(channelCode)
.pinType(pinType)
.email(profile.getCmpEmail())
.phone(profile.getPadAdrsmobphone())
.isOtpRequired(isOtpRequired)
.username(profile.getCmpUserName())
.subject(subject)
.build();
notificationService.sendOtp(otpRequest);
}
}

Loading…
Cancel
Save