Commit customer onboarding product based account opening

add account
currency commit
Nabeel-DG-BS
Raja Nabeel 2 years ago
parent 8ab351dc51
commit 82a020d409

@ -3,6 +3,7 @@ package com.mfsys.uco;
public interface UCOURI { public interface UCOURI {
String VIEW_BALANCE = "/user/viewBalance"; String VIEW_BALANCE = "/user/viewBalance";
String ONBOARD_CUSTOMER = "/auth/user/authenticate/onboardCutomer"; String ONBOARD_CUSTOMER = "/auth/user/authenticate/onboardCutomer";
String ADD_UCO_CUSTOMER_ACCOUNT = "/createUcoAccount";
String FETCH_DEPOSITACCOUNTS = "/depositAccounts"; String FETCH_DEPOSITACCOUNTS = "/depositAccounts";
String FETCH_ACCOUNT_STATEMENT = "/accountStatement"; String FETCH_ACCOUNT_STATEMENT = "/accountStatement";
String FETCH_ACCOUNT_INQUIRY = "/accountInquiry"; String FETCH_ACCOUNT_INQUIRY = "/accountInquiry";
@ -16,6 +17,7 @@ public interface UCOURI {
String GET_DR_TRANSACTION_PIN = "/sendDrTranOtpAndVerifyTranPin"; String GET_DR_TRANSACTION_PIN = "/sendDrTranOtpAndVerifyTranPin";
String RESEND_GET_DR_TRANSACTION_PIN = "/resendDrTranOtp"; String RESEND_GET_DR_TRANSACTION_PIN = "/resendDrTranOtp";
String SUBMIT_DR_TRANSACTION = "/submitDrTransaction"; String SUBMIT_DR_TRANSACTION = "/submitDrTransaction";
String CURRENCY_EVALUATION = "/getEvaluatedCurrency";
String SUBMIT_CR_TRANSACTION = "/submitCrTransaction"; String SUBMIT_CR_TRANSACTION = "/submitCrTransaction";
String PENDING_CR_TRANSACTION = "/fetchPendingCredittransaction"; String PENDING_CR_TRANSACTION = "/fetchPendingCredittransaction";
String ACCOUNT_STATEMENT = "/fetchDepositAccountStatement"; String ACCOUNT_STATEMENT = "/fetchDepositAccountStatement";

@ -5,5 +5,6 @@ public interface UCOURI {
String CUSTOMER_ONBOARDING = "/crm/onboarding/digital/customer"; String CUSTOMER_ONBOARDING = "/crm/onboarding/digital/customer";
String GET_CMP_UCOACCOUNTS = "/deposit/getUcoAccounts"; String GET_CMP_UCOACCOUNTS = "/deposit/getUcoAccounts";
String FETCH_EXCHANGE_RATE = "/deposit/uco/fetchExchangeRate"; String FETCH_EXCHANGE_RATE = "/deposit/uco/fetchExchangeRate";
String UCO_CUSTOMER_ACCOUNT = "/deposit/onboarding/digital/UcoCustomerAccount";
} }

@ -3,6 +3,7 @@ package com.mfsys.uco.controller;
import com.mfsys.uco.UCOURI; import com.mfsys.uco.UCOURI;
import com.mfsys.uco.dto.CashInTransactionRequest; import com.mfsys.uco.dto.CashInTransactionRequest;
import com.mfsys.uco.dto.CashOutTransactionRequest; import com.mfsys.uco.dto.CashOutTransactionRequest;
import com.mfsys.uco.dto.EvaluatedCurrencyReponse;
import com.mfsys.uco.dto.Transaction.TransactionOtpRequestModel; import com.mfsys.uco.dto.Transaction.TransactionOtpRequestModel;
import com.mfsys.uco.dto.TransactionPinResponseModel; import com.mfsys.uco.dto.TransactionPinResponseModel;
import com.mfsys.uco.model.TransactionTrail; import com.mfsys.uco.model.TransactionTrail;
@ -52,5 +53,15 @@ public class TransactionController {
@RequestParam String mbmBkmsnumber) { @RequestParam String mbmBkmsnumber) {
return transactionService.fetchDepositAccountStatement(porOrgacode, mbmBkmsnumber); return transactionService.fetchDepositAccountStatement(porOrgacode, mbmBkmsnumber);
} }
@GetMapping(UCOURI.CURRENCY_EVALUATION)
public EvaluatedCurrencyReponse getEvaluatedCurrency(
@RequestParam String porOrgacode,
@RequestParam String baseCurrency,
@RequestParam String targetCurrency,
@RequestParam double sgtGntramtfc) {
return transactionService.getEvaluatedCurrency(porOrgacode, baseCurrency,targetCurrency,sgtGntramtfc);
}
} }

@ -56,7 +56,7 @@ public class UserController {
@RequestParam String porOrgacode, @RequestParam String porOrgacode,
@RequestParam String cmpCustcode, @RequestParam String cmpCustcode,
@RequestParam String pctCstycode) { @RequestParam String pctCstycode) {
return List.of(ucoAccountService.fetchdepositAccountFromCiihive(porOrgacode, cmpCustcode)); return ucoAccountService.fetchdepositAccountFromCiihive(porOrgacode, cmpCustcode);
} }
@GetMapping(UCOURI.FETCH_ACCOUNT_STATEMENT) @GetMapping(UCOURI.FETCH_ACCOUNT_STATEMENT)
@ -172,4 +172,10 @@ public class UserController {
notificationService.sendOtp(otpRequest); notificationService.sendOtp(otpRequest);
return ResponseEntity.ok("OTP sent"); return ResponseEntity.ok("OTP sent");
} }
@PostMapping(UCOURI.ADD_UCO_CUSTOMER_ACCOUNT)
public ResponseEntity<HttpStatus> addUcoCustomerAccount(@RequestBody AddAccountRequestModel addAccountRequestModel) {
ucoAccountService.addUcoAccount(addAccountRequestModel);
return ResponseEntity.ok(HttpStatus.OK);
}
} }

@ -0,0 +1,18 @@
package com.mfsys.uco.dto;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class AddAccountRequestModel {
private String porOrgacode;
private String email;
private String title;
private String dmpProdcode;
private String channelCode;
}

@ -0,0 +1,17 @@
package com.mfsys.uco.dto;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.math.BigDecimal;
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class EvaluatedCurrencyReponse {
private String pcrCurrcode;
private double sgtGntramtfc;
}

@ -20,6 +20,7 @@ public class AccountDetail {
protected String dmpProddesc; protected String dmpProddesc;
protected String plcLocadesc; protected String plcLocadesc;
protected String pcrCurrcode; protected String pcrCurrcode;
protected String pcrCurrshort;
protected String pcrCurrdesc; protected String pcrCurrdesc;
protected String cmpCustcode; protected String cmpCustcode;
protected boolean mbmBkmsclosed; protected boolean mbmBkmsclosed;

@ -51,4 +51,7 @@ public class CustomerProfile {
private String cmpName; private String cmpName;
@Column(name = "CMP_USERNAME", nullable = true, columnDefinition = FieldNameLength.CODE_50) @Column(name = "CMP_USERNAME", nullable = true, columnDefinition = FieldNameLength.CODE_50)
private String cmpUserName; private String cmpUserName;
@Column(name = "CMP_ADDRESS", nullable = true, columnDefinition = FieldNameLength.DESCRIPTION_LONG)
private String cmpAddress;
} }

@ -27,6 +27,7 @@ public class TransactionService {
private final NotificationService notificationService; private final NotificationService notificationService;
private final TransactionPinService transactionPinService; private final TransactionPinService transactionPinService;
private final TransactionTrailRepository transactionTrailRepository; private final TransactionTrailRepository transactionTrailRepository;
private final UcoAccountService ucoAccountService;
private final WebClientDepositService webClientDepositService; private final WebClientDepositService webClientDepositService;
public TransactionPinResponseModel sendOtpAndValidateTranPin(TransactionOtpRequestModel transactionOtpRequestModel, boolean isResendOtp) { public TransactionPinResponseModel sendOtpAndValidateTranPin(TransactionOtpRequestModel transactionOtpRequestModel, boolean isResendOtp) {
@ -136,4 +137,38 @@ public class TransactionService {
} }
throw new RuntimeException("may day"); throw new RuntimeException("may day");
} }
public EvaluatedCurrencyReponse getEvaluatedCurrency(String porOrgacode, String baseCurrencyCode, String targetCurrencyCode, double sgtGntramtfc) {
List<Map> exchangeRateList = (List<Map>) ucoAccountService.fetchExchangeRate(porOrgacode);
Map<String, Double> exchangeRates = new HashMap<>();
for (Map rateEntry : exchangeRateList) {
String currencyCode = (String) rateEntry.get("pcrCurrcode");
Double rate = (Double) rateEntry.get("perEratrateact");
exchangeRates.put(currencyCode, rate);
}
double convertedAmount = convertCurrency(baseCurrencyCode, targetCurrencyCode, sgtGntramtfc, exchangeRates);
return EvaluatedCurrencyReponse.builder().pcrCurrcode(targetCurrencyCode).sgtGntramtfc(convertedAmount).build();
}
public double convertCurrency(String baseCurrencyCode, String targetCurrencyCode, double amount, Map<String, Double> exchangeRates) {
if (baseCurrencyCode.equals("default")) {
return exchangeRates.get(targetCurrencyCode) * amount;
} else if (targetCurrencyCode.equals("default")) {
return exchangeRates.get(baseCurrencyCode) * amount;
}
if (baseCurrencyCode.equals(targetCurrencyCode)) {
return amount;
}
if (!exchangeRates.containsKey(baseCurrencyCode) || !exchangeRates.containsKey(targetCurrencyCode)) {
throw new IllegalArgumentException("Unsupported currency code");
}
double amountInPKR = amount * exchangeRates.get(baseCurrencyCode);
double amountInTargetCurrency = amountInPKR / exchangeRates.get(targetCurrencyCode);
return amountInTargetCurrency;
}
} }

@ -1,9 +1,11 @@
package com.mfsys.uco.service; package com.mfsys.uco.service;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.mfsys.uco.constants.UCOConstants; import com.mfsys.uco.constants.UCOConstants;
import com.mfsys.uco.constants.UCOURI; import com.mfsys.uco.constants.UCOURI;
import com.mfsys.uco.dto.AccountInquiryResponse; import com.mfsys.uco.dto.AccountInquiryResponse;
import com.mfsys.uco.dto.AddAccountRequestModel;
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;
@ -16,15 +18,11 @@ import com.mfsys.uco.repository.UCOAccountRepository;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.time.LocalDate; import java.time.LocalDate;
import java.util.List; import java.util.*;
import java.util.Map;
import java.util.Objects;
@Service @Service
public class UcoAccountService { public class UcoAccountService {
ObjectMapper objectMapper;
private final CustomerProfileRepository customerProfileRepository; private final CustomerProfileRepository customerProfileRepository;
private final UCOAccountRepository ucoAccountRepository; private final UCOAccountRepository ucoAccountRepository;
private final CustomerProfileService customerProfileService; private final CustomerProfileService customerProfileService;
@ -32,12 +30,14 @@ public class UcoAccountService {
private final WebClientDepositService webClientDeposit; private final WebClientDepositService webClientDeposit;
private final WebClientCrmService webClientCrmService; private final WebClientCrmService webClientCrmService;
public UcoAccountService(CustomerProfileRepository customerProfileRepository, UCOAccountRepository ucoAccountRepository, CustomerProfileService customerProfileService, WebClientDepositService webClientDeposit, WebClientCrmService webClientCrmService) { public UcoAccountService(CustomerProfileRepository customerProfileRepository, UCOAccountRepository ucoAccountRepository, CustomerProfileService customerProfileService, WebClientDepositService webClientDeposit, WebClientCrmService webClientCrmService
,ObjectMapper objectMapper) {
this.customerProfileRepository = customerProfileRepository; this.customerProfileRepository = customerProfileRepository;
this.ucoAccountRepository = ucoAccountRepository; this.ucoAccountRepository = ucoAccountRepository;
this.customerProfileService = customerProfileService; this.customerProfileService = customerProfileService;
this.webClientDeposit = webClientDeposit; this.webClientDeposit = webClientDeposit;
this.webClientCrmService = webClientCrmService; this.webClientCrmService = webClientCrmService;
this.objectMapper = objectMapper;
} }
public AccountInquiryResponse fetchAccountTitile(String porOrgacode, String acntTypeCode, String acntTypeValue) { public AccountInquiryResponse fetchAccountTitile(String porOrgacode, String acntTypeCode, String acntTypeValue) {
@ -70,7 +70,6 @@ public class UcoAccountService {
if (Objects.nonNull(customerProfileService.fetchCustcodeBasedOnEmail(signupStep3RequestModel.getPorOrgacode(), signupStep3RequestModel.getEmail()))) { if (Objects.nonNull(customerProfileService.fetchCustcodeBasedOnEmail(signupStep3RequestModel.getPorOrgacode(), signupStep3RequestModel.getEmail()))) {
throw new UserAlreadyRegisteredException(null); 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()
@ -80,7 +79,7 @@ public class UcoAccountService {
String cmpCustcode = String.valueOf(cmpCustcodeReturn.get("cmpCustcode")); String cmpCustcode = String.valueOf(cmpCustcodeReturn.get("cmpCustcode"));
System.out.println(cmpCustcode); System.out.println(cmpCustcode);
AccountDetail accountDetail = fetchdepositAccountFromCiihive(porOrgacode, cmpCustcode); AccountDetail accountDetail = fetchdepositAccountFromCiihive(porOrgacode, cmpCustcode).get(0);
CustomerProfile customerProfile = CustomerProfile.builder().cmpCustcode(accountDetail.getCmpCustcode()).cmpEmail(signupStep3RequestModel.getEmail()) CustomerProfile customerProfile = CustomerProfile.builder().cmpCustcode(accountDetail.getCmpCustcode()).cmpEmail(signupStep3RequestModel.getEmail())
.cmpName(signupStep3RequestModel.getName()).cmpIsKycVerified(signupStep3RequestModel.isKycAdded()) .cmpName(signupStep3RequestModel.getName()).cmpIsKycVerified(signupStep3RequestModel.isKycAdded())
.pitIdencode(signupStep3RequestModel.getIdentificationType()).pitIdenvalue(signupStep3RequestModel.getIdentificationNumber()) .pitIdencode(signupStep3RequestModel.getIdentificationType()).pitIdenvalue(signupStep3RequestModel.getIdentificationNumber())
@ -104,12 +103,13 @@ public class UcoAccountService {
} }
public AccountDetail fetchdepositAccountFromCiihive(String porOrgacode, String cmpCustcode) { public List<AccountDetail> fetchdepositAccountFromCiihive(String porOrgacode, String cmpCustcode) {
String url = UCOURI.GET_CMP_UCOACCOUNTS + "?porOrgacode=" + porOrgacode + "&cmpCustcode=" + cmpCustcode; String url = UCOURI.GET_CMP_UCOACCOUNTS + "?porOrgacode=" + porOrgacode + "&cmpCustcode=" + cmpCustcode;
List<Object> map = (List<Object>) webClientDeposit.getCmpUcoAccounts(url, porOrgacode); List<Object> map = (List<Object>) webClientDeposit.getCmpUcoAccounts(url, porOrgacode);
ObjectMapper objectMapper = new ObjectMapper(); ObjectMapper objectMapper = new ObjectMapper();
return objectMapper.convertValue(map.get(0), AccountDetail.class); return objectMapper.convertValue(map, objectMapper.getTypeFactory().constructCollectionType(List.class, AccountDetail.class));
} }
@ -117,5 +117,75 @@ public class UcoAccountService {
String url = UCOURI.FETCH_EXCHANGE_RATE + "?porOrgacode=" + porOrgacode; String url = UCOURI.FETCH_EXCHANGE_RATE + "?porOrgacode=" + porOrgacode;
return webClientDeposit.fetchExchangeRate(url, porOrgacode); return webClientDeposit.fetchExchangeRate(url, porOrgacode);
} }
public void addUcoAccount(AddAccountRequestModel addAccountRequestModel){
String porOrgacode = addAccountRequestModel.getPorOrgacode();
CustomerProfile customerProfile = customerProfileRepository.findCustomerProfileByCmpEmailAndPorOrgacode(porOrgacode,addAccountRequestModel.getEmail());
String accountNumber = webClientDeposit.createUcoAccount(JsonToString(Map.of("payload",preparePayloadForAccount(customerProfile,addAccountRequestModel.getTitle()),
"uniqueConstraints",List.of(List.of(String.valueOf(addAccountRequestModel.getDmpProdcode()))))),UCOURI.UCO_CUSTOMER_ACCOUNT,porOrgacode);
saveCustomerAccountDetails(porOrgacode,customerProfile.getCmpCustcode(),accountNumber);
}
public void saveCustomerAccountDetails(String porOrgacode, String cmpCustcode,String accountNumber){
fetchdepositAccountFromCiihive(porOrgacode, cmpCustcode).stream().forEach(k -> {
if(k.getMbmBkmsnumber().equals(accountNumber)){
UcoAccount ucoAccount = UcoAccount.builder()
.id(new AccountId(k.getPorOrgacode(), k.getMbmBkmsnumber())) // Set the AccountId, assuming a method exists to create or retrieve it
.dmpProdcode(k.getDmpProdcode())
.mbmBkmstitle(k.getMbmBkmstitle())
.pcrCurrdesc(k.getPcrCurrdesc())
.cmpCustcode(k.getCmpCustcode())
.pcrCurrcode(k.getPcrCurrcode())
.mbmBkmsclosed(k.isMbmBkmsclosed())
.mbmBkmsopendate(LocalDate.now())
.sgtLasttrandate(LocalDate.now())
.build();
ucoAccountRepository.save(ucoAccount);
}
});
}
public String preparePayloadForAccount(CustomerProfile customerProfile,String title){
Map<String,Object> jsonMap = new HashMap<>();
jsonMap.put("SUS_USERCODE", "01");
jsonMap.put("CMP_CUSTCODE",customerProfile.getCmpCustcode());
jsonMap.put("CMP_FULLNAME", title);
jsonMap.put("PLC_LOCACODE", "2003");
jsonMap.put("workFlowStage", "BN_WF_CP_AUTHORIZATION");
jsonMap.put("PCT_CSTYCODE", "I");
jsonMap.put("POR_ORGACODE", customerProfile.getPorOrgacode());
List<Map<String, Object>> workFlowLog = new ArrayList<>();
Map<String, Object> logEntry = new HashMap<>();
logEntry.put("susUsercode", "01");
logEntry.put("formId", "BN_WF_CP_AUTHORIZATION");
workFlowLog.add(logEntry);
jsonMap.put("workFlowLog", workFlowLog);
List<Map<String, Object>> bnCsItIdentifier = new ArrayList<>();
Map<String, Object> identifierEntry = new HashMap<>();
identifierEntry.put("CIT_IDENVALUE", customerProfile.getPitIdenvalue());
identifierEntry.put("PIT_PRIMARYIDENCODE", true);
identifierEntry.put("PIT_IDENCODE", customerProfile.getPitIdencode());
bnCsItIdentifier.add(identifierEntry);
jsonMap.put("BN_CS_IT_IDENTIFIER", bnCsItIdentifier);
jsonMap.put("@_CREATEUSER", "01");
List<Map<String, Object>> bnCsAdAddress = new ArrayList<>();
Map<String, Object> addressEntry = new HashMap<>();
addressEntry.put("PAD_ADRSCORRESPONDENCE", true);
addressEntry.put("PAD_ADRSMOBPHONE", customerProfile.getPadAdrsmobphone());
bnCsAdAddress.add(addressEntry);
jsonMap.put("BN_CS_AD_ADDRESS", customerProfile.getCmpAddress());
Map<String, Object> createdDateMap = new HashMap<>();
createdDateMap.put("$date", new Date());
jsonMap.put("@_CREATEDATE", createdDateMap);
return JsonToString(jsonMap);
}
public String JsonToString(Object jsonMap){
try {
return this.objectMapper.writeValueAsString(jsonMap);
} catch (JsonProcessingException var3) {
throw new RuntimeException(var3);
}
}
} }

@ -46,7 +46,13 @@ public class WebClientDepositService {
porOrgaCode); porOrgaCode);
} }
public String createUcoAccount(Object payload, String url, String porOrgaCode) {
return handleResponse(webClientDeposit.post().uri(url).bodyValue(payload).accept(MediaType.APPLICATION_JSON)
.header("SUS_USERCODE", porOrgaCode)
.header("POR_ORGACODE", porOrgaCode).retrieve()
.toEntity(String.class),
porOrgaCode);
}
public Object fetchExchangeRate(String url, String porOrgacode) { public Object fetchExchangeRate(String url, String porOrgacode) {
return handleResponse(webClientDeposit.get().uri(url).accept(MediaType.APPLICATION_JSON) return handleResponse(webClientDeposit.get().uri(url).accept(MediaType.APPLICATION_JSON)
.header("SUS_USERCODE", porOrgacode) .header("SUS_USERCODE", porOrgacode)

Loading…
Cancel
Save