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