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 java.util.List;
import java.util.Map;
@RestController
@RequiredArgsConstructor
@ -27,15 +28,13 @@ public class TransactionController {
}
@PostMapping(UCOURI.SUBMIT_DR_TRANSACTION)
public ResponseEntity<FunctionReturnDetail<String>> cashInTransaction(@RequestBody CashInTransactionRequest transactionRequest) {
transactionService.cashInTransaction(transactionRequest);
return null;
public Map<String,Object> cashInTransaction(@RequestBody CashInTransactionRequest transactionRequest) {
return transactionService.cashInTransaction(transactionRequest);
}
@PostMapping(UCOURI.SUBMIT_CR_TRANSACTION)
public ResponseEntity<FunctionReturnDetail<String>> cashOutTransaction(@RequestBody CashOutTransactionRequest transactionRequest) {
transactionService.cashOutTransaction(transactionRequest);
return null;
public Map<String,Object> cashOutTransaction(@RequestBody CashOutTransactionRequest transactionRequest) {
return transactionService.cashOutTransaction(transactionRequest);
}
@GetMapping(UCOURI.PENDING_CR_TRANSACTION)

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

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

@ -29,5 +29,6 @@ public class CashInTransactionRequest {
private String transMode;
private double sgtGntramtfc;
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")
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 org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import java.util.List;
@ -10,5 +11,6 @@ import java.util.Optional;
@Repository
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);
}

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

@ -2,9 +2,11 @@ package com.mfsys.uco.service;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.mfsys.uco.constants.UCOURI;
import com.mfsys.uco.dto.AccountInquiryResponse;
import com.mfsys.uco.dto.SignupStep3RequestModel;
import com.mfsys.uco.dto.webclientdto.AccountDetail;
import com.mfsys.uco.exception.AccountDoesntExistsException;
import com.mfsys.uco.exception.UserAlreadyRegisteredException;
import com.mfsys.uco.model.AccountId;
import com.mfsys.uco.model.CustomerProfile;
import com.mfsys.uco.model.UcoAccount;
@ -22,24 +24,27 @@ public class UcoAccountService {
private final CustomerProfileRepository customerProfileRepository;
private final UCOAccountRepository ucoAccountRepository;
private final CustomerProfileService customerProfileService;
private final WebClientDepositService webClientDeposit;
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.ucoAccountRepository = ucoAccountRepository;
this.customerProfileService = customerProfileService;
this.webClientDeposit = webClientDeposit;
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")){
CustomerProfile customerProfile = customerProfileRepository.findProfilesByMobilePhone(porOrgacode,acntTypeValue);
if(Objects.isNull(customerProfile)){
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;
}
@ -55,6 +60,10 @@ public class UcoAccountService {
public void onBoardCustomer(SignupStep3RequestModel signupStep3RequestModel) {
if(Objects.nonNull(customerProfileService.fetchCustcodeBasedOnEmail(signupStep3RequestModel.getPorOrgacode(),signupStep3RequestModel.getEmail()))){
throw new UserAlreadyRegisteredException(null);
}
String porOrgacode = signupStep3RequestModel.getPorOrgacode();
Map cmpCustcodeReturn = (Map) webClientCrmService.onboardCustomer(Map.of("CMP_FULLNAME",signupStep3RequestModel.getName()
,"PIT_IDENCODE",signupStep3RequestModel.getIdentificationType(),"CIT_IDENVALUE",signupStep3RequestModel.getIdentificationNumber()

@ -38,11 +38,11 @@ public class WebClientDepositService {
.header("POR_ORGACODE", porOrgacode).retrieve().toEntity(Object.class),
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)
.header("SUS_USERCODE", porOrgaCode)
.header("POR_ORGACODE", porOrgaCode).retrieve()
.toEntity(FunctionReturnDetail.class),
.toEntity(Object.class),
porOrgaCode);
}

Loading…
Cancel
Save