usend ureceive commit

Nabeel-DG-BS
Raja Nabeel 2 years ago
parent 19ee585df7
commit 246703f61d

@ -14,6 +14,7 @@ import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.List; import java.util.List;
import java.util.Map;
@RestController @RestController
@RequiredArgsConstructor @RequiredArgsConstructor
@ -27,15 +28,13 @@ public class TransactionController {
} }
@PostMapping(UCOURI.SUBMIT_DR_TRANSACTION) @PostMapping(UCOURI.SUBMIT_DR_TRANSACTION)
public ResponseEntity<FunctionReturnDetail<String>> cashInTransaction(@RequestBody CashInTransactionRequest transactionRequest) { public Map<String,Object> cashInTransaction(@RequestBody CashInTransactionRequest transactionRequest) {
transactionService.cashInTransaction(transactionRequest); return transactionService.cashInTransaction(transactionRequest);
return null;
} }
@PostMapping(UCOURI.SUBMIT_CR_TRANSACTION) @PostMapping(UCOURI.SUBMIT_CR_TRANSACTION)
public ResponseEntity<FunctionReturnDetail<String>> cashOutTransaction(@RequestBody CashOutTransactionRequest transactionRequest) { public Map<String,Object> cashOutTransaction(@RequestBody CashOutTransactionRequest transactionRequest) {
transactionService.cashOutTransaction(transactionRequest); return transactionService.cashOutTransaction(transactionRequest);
return null;
} }
@GetMapping(UCOURI.PENDING_CR_TRANSACTION) @GetMapping(UCOURI.PENDING_CR_TRANSACTION)

@ -91,7 +91,7 @@ public class UserController {
@RequestParam String acntTypeValue, @RequestParam String acntTypeValue,
@RequestParam String porOrgacode, @RequestParam String porOrgacode,
@RequestParam String channelCode) { @RequestParam String channelCode) {
return new AccountInquiryResponse(ucoAccountService.fetchAccountTitile(porOrgacode,acntTypeCode,acntTypeValue)); return ucoAccountService.fetchAccountTitile(porOrgacode,acntTypeCode,acntTypeValue);
} }
// mine // mine

@ -11,4 +11,5 @@ import lombok.NoArgsConstructor;
@NoArgsConstructor @NoArgsConstructor
public class AccountInquiryResponse { public class AccountInquiryResponse {
private String mbmBkmstitle; private String mbmBkmstitle;
private String mbmBkmsnumber;
} }

@ -29,5 +29,6 @@ public class CashInTransactionRequest {
private String transMode; private String transMode;
private double sgtGntramtfc; private double sgtGntramtfc;
private String otdTrancomment; private String otdTrancomment;
private boolean isOtpRequired; private String obpPincode ;
private String pinType ;
} }

@ -0,0 +1,11 @@
package com.mfsys.uco.exception;
import com.mfsys.comm.exception.ApplicationException;
import com.mfsys.comm.exception.ERRCode;
public class SameCrDrAccountExistsException extends ApplicationException {
public SameCrDrAccountExistsException() {
super(null, ERRCode.CR_DR_SAME_ACCOUNT, null);
}
}

@ -0,0 +1,11 @@
package com.mfsys.uco.exception;
import com.mfsys.comm.exception.ApplicationException;
import com.mfsys.comm.exception.ERRCode;
public class UserAlreadyRegisteredException extends ApplicationException {
public UserAlreadyRegisteredException(String porOrgacode, Object... arguments) {
super(porOrgacode, ERRCode.USER_ALREADY_REGISTERED, arguments);
}
}

@ -12,4 +12,7 @@ public interface PinRepository extends JpaRepository<Pin, Long> {
@Query("SELECT p FROM DG_PN_PIN p WHERE p.userName = :username AND p.pinstatus = 'Unverified' AND p.pinExpirydate > CURRENT_TIMESTAMP AND p.pintype=:pinType ORDER BY p.pinserial DESC LIMIT 1") @Query("SELECT p FROM DG_PN_PIN p WHERE p.userName = :username AND p.pinstatus = 'Unverified' AND p.pinExpirydate > CURRENT_TIMESTAMP AND p.pintype=:pinType ORDER BY p.pinserial DESC LIMIT 1")
Optional<Pin> findLatestActiveOtpByUserName(String username,String pinType); Optional<Pin> findLatestActiveOtpByUserName(String username,String pinType);
@Query("SELECT p FROM DG_PN_PIN p WHERE p.pinserial = :id And p.pincode =:obpPincode AND p.pinstatus = 'Unverified' AND p.pinExpirydate > CURRENT_TIMESTAMP AND p.pintype=:pinType ORDER BY p.pinserial DESC LIMIT 1")
Optional<Pin> findsss(String id,String pinType,String obpPincode);
} }

@ -2,6 +2,7 @@ package com.mfsys.uco.repository;
import com.mfsys.uco.model.TransactionTrail; import com.mfsys.uco.model.TransactionTrail;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.util.List; import java.util.List;
@ -10,5 +11,6 @@ import java.util.Optional;
@Repository @Repository
public interface TransactionTrailRepository extends JpaRepository<TransactionTrail,Integer> { public interface TransactionTrailRepository extends JpaRepository<TransactionTrail,Integer> {
@Query("SELECT t FROM BN_MS_UA_UCOACCOUNTTRAIL t WHERE t.porOrgacode =:porOrgacode and t.crMbmBkmsnumber = :crMbmBkmsnumber and t.batAcnttranReceived = false")
Optional<List<TransactionTrail>> findByPorOrgacodeAndCrMbmBkmsnumberAndBatAcnttranReceivedFalse(String porOrgacode, String crMbmBkmsnumber); Optional<List<TransactionTrail>> findByPorOrgacodeAndCrMbmBkmsnumberAndBatAcnttranReceivedFalse(String porOrgacode, String crMbmBkmsnumber);
} }

@ -59,4 +59,10 @@ public class NotificationService {
} }
throw new InvalidOTPException(porOrgacode); throw new InvalidOTPException(porOrgacode);
} }
public void verifyOtpViaOtpId(String id, String pinType,String obpPincode){
Pin pin = pinRepository.findsss(id,pinType,obpPincode)
.orElseThrow(() -> new IllegalArgumentException("Notification not found for ID: " + id));
pin.setPinstatus("VERIFIED");
pinRepository.save(pin);
}
} }

@ -4,7 +4,9 @@ import com.mfsys.comm.util.FunctionReturnDetail;
import com.mfsys.uco.UCOURI; import com.mfsys.uco.UCOURI;
import com.mfsys.uco.dto.*; import com.mfsys.uco.dto.*;
import com.mfsys.uco.dto.Transaction.TransactionOtpRequestModel; import com.mfsys.uco.dto.Transaction.TransactionOtpRequestModel;
import com.mfsys.uco.exception.SameCrDrAccountExistsException;
import com.mfsys.uco.model.CustomerProfile; import com.mfsys.uco.model.CustomerProfile;
import com.mfsys.uco.model.CustomerProfileId;
import com.mfsys.uco.model.TransactionTrail; import com.mfsys.uco.model.TransactionTrail;
import com.mfsys.uco.repository.CustomerProfileRepository; import com.mfsys.uco.repository.CustomerProfileRepository;
import com.mfsys.uco.repository.TransactionTrailRepository; import com.mfsys.uco.repository.TransactionTrailRepository;
@ -14,9 +16,7 @@ import org.springframework.stereotype.Service;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.time.LocalDate; import java.time.LocalDate;
import java.util.Collections; import java.util.*;
import java.util.List;
import java.util.Optional;
@Service @Service
@Data @Data
@ -36,7 +36,8 @@ public class TransactionService {
transactionOtpRequestModel.getPinType(), "Transaction Verification OTP", transactionOtpRequestModel.isOtpRequired())).build(); transactionOtpRequestModel.getPinType(), "Transaction Verification OTP", transactionOtpRequestModel.isOtpRequired())).build();
} }
public FunctionReturnDetail<String> cashInTransaction(CashInTransactionRequest transactionRequest) { public Map<String,Object> cashInTransaction(CashInTransactionRequest transactionRequest) {
validation(transactionRequest);
TransactionTrail transactionTrail = TransactionTrail.builder() TransactionTrail transactionTrail = TransactionTrail.builder()
.porOrgacode(transactionRequest.getPorOrgacode()) .porOrgacode(transactionRequest.getPorOrgacode())
.drMbmBkmsnumber(transactionRequest.getDrMbmBkmsnumber()) .drMbmBkmsnumber(transactionRequest.getDrMbmBkmsnumber())
@ -65,36 +66,52 @@ public class TransactionService {
.otdTrancomment(transactionRequest.getOtdTrancomment()) .otdTrancomment(transactionRequest.getOtdTrancomment())
.porOrgacode(transactionRequest.getPorOrgacode()) .porOrgacode(transactionRequest.getPorOrgacode())
.build(); .build();
FunctionReturnDetail<String> response = (FunctionReturnDetail<String>) webClientDepositService.postTransaction(coreCashInTransaction, UCOURI.BANKING_CASH_IN,transactionRequest.getPorOrgacode()); Map<String,Object> response = (Map<String,Object>)webClientDepositService.postTransaction(coreCashInTransaction, UCOURI.BANKING_CASH_IN,transactionRequest.getPorOrgacode());
transactionTrail.setSgtSentGntrnumber(extractTranNumber(response)); if(response.containsKey("mbmBkmsBalance")){
Map<String,Object> transactionId = (Map<String,Object>) response.get("FuncReturnDetail");
transactionTrail.setSgtSentGntrnumber(extractTranNumber(List.of(transactionId.get("arguments"))));
transactionTrail.setBatAcnttranSend(true); transactionTrail.setBatAcnttranSend(true);
transactionTrailRepository.save(transactionTrail); transactionTrailRepository.save(transactionTrail);
return response; return response;
} }
return response;
}
private void validation(CashInTransactionRequest transactionRequest) {
if(transactionRequest.getCrMbmBkmsnumber().equals(transactionRequest.getDrMbmBkmsnumber())){
throw new SameCrDrAccountExistsException();
}
notificationService.verifyOtpViaOtpId(transactionRequest.getNotificationId(),transactionRequest.getPinType(),transactionRequest.getObpPincode());
}
public List<TransactionTrail> fetchPendingCrTransactions(String porOrgacode, String mbmBkmsnumber) { public List<TransactionTrail> fetchPendingCrTransactions(String porOrgacode, String mbmBkmsnumber) {
Optional<List<TransactionTrail>> optionalTransactions = transactionTrailRepository.findByPorOrgacodeAndCrMbmBkmsnumberAndBatAcnttranReceivedFalse(porOrgacode, mbmBkmsnumber); Optional<List<TransactionTrail>> optionalTransactions = transactionTrailRepository.findByPorOrgacodeAndCrMbmBkmsnumberAndBatAcnttranReceivedFalse(porOrgacode, mbmBkmsnumber);
return optionalTransactions.orElseGet(Collections::emptyList); return optionalTransactions.orElseGet(Collections::emptyList);
} }
public void cashOutTransaction(CashOutTransactionRequest cashOutTransactionRequest) { public Map<String,Object> cashOutTransaction(CashOutTransactionRequest cashOutTransactionRequest) {
verifyOldPinAndGetCmpProfile(cashOutTransactionRequest.getPorOrgacode(), verifyOldPinAndGetCmpProfile(cashOutTransactionRequest.getPorOrgacode(),
cashOutTransactionRequest.getCmpTranpin(),cashOutTransactionRequest.getCmpCustcode()); cashOutTransactionRequest.getCmpTranpin(),cashOutTransactionRequest.getCmpCustcode());
Map<String,Object> response = new HashMap<>();
Optional<TransactionTrail> transactionTrail = transactionTrailRepository.findById(Math.toIntExact(cashOutTransactionRequest.getId())); Optional<TransactionTrail> transactionTrail = transactionTrailRepository.findById(Math.toIntExact(cashOutTransactionRequest.getId()));
transactionTrail.ifPresent(tran -> { if(transactionTrail.isPresent()) {
CoreCashOutTransaction cashOutTransaction = CoreCashOutTransaction.builder() CoreCashOutTransaction cashOutTransaction = CoreCashOutTransaction.builder()
.crPcrCurrcode("123") .crPcrCurrcode("123")
.crMbmBkmsnumber(tran.getCrMbmBkmsnumber()) .crMbmBkmsnumber(transactionTrail.get().getCrMbmBkmsnumber())
.porOrgacode(cashOutTransactionRequest.getPorOrgacode()) .porOrgacode(cashOutTransactionRequest.getPorOrgacode())
.otdTrancomment(cashOutTransactionRequest.getId()+"_Received") .otdTrancomment(cashOutTransactionRequest.getId() + "_Received")
.sgtGntramtfc(tran.getSgtGntramt()) .sgtGntramtfc(transactionTrail.get().getSgtGntramt())
.build(); .build();
FunctionReturnDetail<String> response = webClientDepositService.postTransaction(cashOutTransaction,UCOURI.BANKING_CASH_OUT,tran.getPorOrgacode()); response = (Map<String,Object>) webClientDepositService.postTransaction(cashOutTransaction, UCOURI.BANKING_CASH_OUT, transactionTrail.get().getPorOrgacode());
tran.setSgtReceiveGntrnumber(extractTranNumber(response)); if(response.containsKey("mbmBkmsBalance")) {
tran.setBatAcnttranReceived(true); Map<String,Object> transactionId = (Map<String,Object>) response.get("FuncReturnDetail");
transactionTrailRepository.save(tran); transactionTrail.get().setSgtReceiveGntrnumber(extractTranNumber(List.of(transactionId.get("arguments"))));
}); transactionTrail.get().setBatAcnttranReceived(true);
transactionTrailRepository.save(transactionTrail.get());
}
}
return response;
} }
private CustomerProfile verifyOldPinAndGetCmpProfile(String porOrgacode, String transPincode,String cmpCustcode) { private CustomerProfile verifyOldPinAndGetCmpProfile(String porOrgacode, String transPincode,String cmpCustcode) {
@ -104,10 +121,15 @@ public class TransactionService {
return customerProfile; return customerProfile;
} }
private String extractTranNumber(FunctionReturnDetail<String> response){ private CustomerProfile fetchCustomerBasedOnCmpCustcode(String porOrgacode, String cmpCustcode) {
Object[] args = response.getArguments(); return customerProfileRepository.findById(new CustomerProfileId(porOrgacode, cmpCustcode))
if (args != null && args.length > 0 && args[0] instanceof String) { .orElseThrow(() -> new IllegalArgumentException("Customer profile not found for ID: " + cmpCustcode));
return (String) args[0];
}
private String extractTranNumber( List<Object> args ){
if (args != null && args.size() > 0) {
return String.valueOf(args.get(0)).replace("[", "").replace("]", "");
} }
throw new RuntimeException("may day"); throw new RuntimeException("may day");
} }

@ -2,9 +2,11 @@ package com.mfsys.uco.service;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.mfsys.uco.constants.UCOURI; import com.mfsys.uco.constants.UCOURI;
import com.mfsys.uco.dto.AccountInquiryResponse;
import com.mfsys.uco.dto.SignupStep3RequestModel; import com.mfsys.uco.dto.SignupStep3RequestModel;
import com.mfsys.uco.dto.webclientdto.AccountDetail; import com.mfsys.uco.dto.webclientdto.AccountDetail;
import com.mfsys.uco.exception.AccountDoesntExistsException; import com.mfsys.uco.exception.AccountDoesntExistsException;
import com.mfsys.uco.exception.UserAlreadyRegisteredException;
import com.mfsys.uco.model.AccountId; import com.mfsys.uco.model.AccountId;
import com.mfsys.uco.model.CustomerProfile; import com.mfsys.uco.model.CustomerProfile;
import com.mfsys.uco.model.UcoAccount; import com.mfsys.uco.model.UcoAccount;
@ -22,24 +24,27 @@ public class UcoAccountService {
private final CustomerProfileRepository customerProfileRepository; private final CustomerProfileRepository customerProfileRepository;
private final UCOAccountRepository ucoAccountRepository; private final UCOAccountRepository ucoAccountRepository;
private final CustomerProfileService customerProfileService;
private final WebClientDepositService webClientDeposit; private final WebClientDepositService webClientDeposit;
private final WebClientCrmService webClientCrmService; private final WebClientCrmService webClientCrmService;
public UcoAccountService(CustomerProfileRepository customerProfileRepository, UCOAccountRepository ucoAccountRepository, WebClientDepositService webClientDeposit, WebClientCrmService webClientCrmService) { public UcoAccountService(CustomerProfileRepository customerProfileRepository, UCOAccountRepository ucoAccountRepository, CustomerProfileService customerProfileService, WebClientDepositService webClientDeposit, WebClientCrmService webClientCrmService) {
this.customerProfileRepository = customerProfileRepository; this.customerProfileRepository = customerProfileRepository;
this.ucoAccountRepository = ucoAccountRepository; this.ucoAccountRepository = ucoAccountRepository;
this.customerProfileService = customerProfileService;
this.webClientDeposit = webClientDeposit; this.webClientDeposit = webClientDeposit;
this.webClientCrmService = webClientCrmService; this.webClientCrmService = webClientCrmService;
} }
public String fetchAccountTitile(String porOrgacode, String acntTypeCode, String acntTypeValue){ public AccountInquiryResponse fetchAccountTitile(String porOrgacode, String acntTypeCode, String acntTypeValue){
if(acntTypeCode.equals("01")){ if(acntTypeCode.equals("01")){
CustomerProfile customerProfile = customerProfileRepository.findProfilesByMobilePhone(porOrgacode,acntTypeValue); CustomerProfile customerProfile = customerProfileRepository.findProfilesByMobilePhone(porOrgacode,acntTypeValue);
if(Objects.isNull(customerProfile)){ if(Objects.isNull(customerProfile)){
throw new AccountDoesntExistsException(); throw new AccountDoesntExistsException();
} }
return ucoAccountRepository.findUcoAccountByCmpCustcode(porOrgacode,customerProfile.getCmpCustcode()).getMbmBkmstitle(); UcoAccount ucoAccount = ucoAccountRepository.findUcoAccountByCmpCustcode(porOrgacode,customerProfile.getCmpCustcode());
return AccountInquiryResponse.builder().mbmBkmsnumber(ucoAccount.getId().getMbmBkmsnumber()).mbmBkmstitle(ucoAccount.getMbmBkmstitle()).build();
} }
return null; return null;
} }
@ -55,6 +60,10 @@ public class UcoAccountService {
public void onBoardCustomer(SignupStep3RequestModel signupStep3RequestModel) { public void onBoardCustomer(SignupStep3RequestModel signupStep3RequestModel) {
if(Objects.nonNull(customerProfileService.fetchCustcodeBasedOnEmail(signupStep3RequestModel.getPorOrgacode(),signupStep3RequestModel.getEmail()))){
throw new UserAlreadyRegisteredException(null);
}
String porOrgacode = signupStep3RequestModel.getPorOrgacode(); String porOrgacode = signupStep3RequestModel.getPorOrgacode();
Map cmpCustcodeReturn = (Map) webClientCrmService.onboardCustomer(Map.of("CMP_FULLNAME",signupStep3RequestModel.getName() Map cmpCustcodeReturn = (Map) webClientCrmService.onboardCustomer(Map.of("CMP_FULLNAME",signupStep3RequestModel.getName()
,"PIT_IDENCODE",signupStep3RequestModel.getIdentificationType(),"CIT_IDENVALUE",signupStep3RequestModel.getIdentificationNumber() ,"PIT_IDENCODE",signupStep3RequestModel.getIdentificationType(),"CIT_IDENVALUE",signupStep3RequestModel.getIdentificationNumber()

@ -38,11 +38,11 @@ public class WebClientDepositService {
.header("POR_ORGACODE", porOrgacode).retrieve().toEntity(Object.class), .header("POR_ORGACODE", porOrgacode).retrieve().toEntity(Object.class),
null); null);
} }
public FunctionReturnDetail postTransaction(Object tranData, String url, String porOrgaCode) { public Object postTransaction(Object tranData, String url, String porOrgaCode) {
return handleResponse(webClientDeposit.post().uri(url).bodyValue(tranData).accept(MediaType.APPLICATION_JSON) return handleResponse(webClientDeposit.post().uri(url).bodyValue(tranData).accept(MediaType.APPLICATION_JSON)
.header("SUS_USERCODE", porOrgaCode) .header("SUS_USERCODE", porOrgaCode)
.header("POR_ORGACODE", porOrgaCode).retrieve() .header("POR_ORGACODE", porOrgaCode).retrieve()
.toEntity(FunctionReturnDetail.class), .toEntity(Object.class),
porOrgaCode); porOrgaCode);
} }

Loading…
Cancel
Save