| 29577 |
amit.gupta |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
| 30014 |
tejbeer |
3 |
import java.time.LocalDateTime;
|
|
|
4 |
import java.util.Comparator;
|
|
|
5 |
import java.util.List;
|
|
|
6 |
import java.util.stream.Collectors;
|
|
|
7 |
|
|
|
8 |
import javax.servlet.http.HttpServletRequest;
|
|
|
9 |
|
|
|
10 |
import org.apache.logging.log4j.LogManager;
|
|
|
11 |
import org.apache.logging.log4j.Logger;
|
|
|
12 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
13 |
import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
14 |
import org.springframework.http.MediaType;
|
|
|
15 |
import org.springframework.http.ResponseEntity;
|
|
|
16 |
import org.springframework.mail.javamail.JavaMailSender;
|
|
|
17 |
import org.springframework.stereotype.Controller;
|
|
|
18 |
import org.springframework.transaction.annotation.Transactional;
|
|
|
19 |
import org.springframework.web.bind.annotation.PathVariable;
|
|
|
20 |
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
21 |
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
22 |
|
| 29577 |
amit.gupta |
23 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
|
|
24 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 29812 |
tejbeer |
25 |
import com.spice.profitmandi.common.services.mandii.AccountStatusResponseOut;
|
|
|
26 |
import com.spice.profitmandi.common.services.mandii.EligibilityStatusEnum;
|
| 29577 |
amit.gupta |
27 |
import com.spice.profitmandi.common.services.mandii.MandiiService;
|
| 30014 |
tejbeer |
28 |
import com.spice.profitmandi.common.services.mandii.TransactionSummaryResponseOut;
|
| 29577 |
amit.gupta |
29 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
| 29812 |
tejbeer |
30 |
import com.spice.profitmandi.dao.entity.dtr.CreditAccount;
|
|
|
31 |
import com.spice.profitmandi.dao.entity.dtr.CreditStatus;
|
| 30014 |
tejbeer |
32 |
import com.spice.profitmandi.dao.entity.dtr.FundFinaPreApproval;
|
| 29577 |
amit.gupta |
33 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
|
|
34 |
import com.spice.profitmandi.dao.enumuration.fofo.Gateway;
|
|
|
35 |
import com.spice.profitmandi.dao.repository.catalog.AddWalletRequestRepository;
|
| 29812 |
tejbeer |
36 |
import com.spice.profitmandi.dao.repository.dtr.CreditAccountRepository;
|
| 29577 |
amit.gupta |
37 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
| 30014 |
tejbeer |
38 |
import com.spice.profitmandi.dao.repository.dtr.FundFinaPreApprovalRepository;
|
| 29577 |
amit.gupta |
39 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
|
|
40 |
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
|
|
|
41 |
import com.spice.profitmandi.dao.repository.transaction.PaymentRepository;
|
|
|
42 |
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
|
|
|
43 |
import com.spice.profitmandi.service.wallet.WalletService;
|
|
|
44 |
|
| 30014 |
tejbeer |
45 |
import io.swagger.annotations.ApiImplicitParam;
|
|
|
46 |
import io.swagger.annotations.ApiImplicitParams;
|
| 29928 |
amit.gupta |
47 |
|
| 29577 |
amit.gupta |
48 |
@Controller
|
|
|
49 |
@Transactional(rollbackFor = Throwable.class)
|
|
|
50 |
public class GatewayController {
|
|
|
51 |
|
|
|
52 |
private static final Logger log = LogManager.getLogger(GatewayController.class);
|
|
|
53 |
|
|
|
54 |
@Autowired
|
|
|
55 |
UserWalletRepository userWalletRepository;
|
| 29812 |
tejbeer |
56 |
|
| 29577 |
amit.gupta |
57 |
@Autowired
|
|
|
58 |
PaymentRepository paymentRepository;
|
|
|
59 |
|
|
|
60 |
@Autowired
|
|
|
61 |
AddWalletRequestRepository addWalletRequestRepository;
|
|
|
62 |
|
|
|
63 |
@Autowired
|
|
|
64 |
WalletService walletService;
|
|
|
65 |
|
|
|
66 |
@Autowired
|
|
|
67 |
FofoStoreRepository fofoStoreRepository;
|
| 29812 |
tejbeer |
68 |
|
| 29577 |
amit.gupta |
69 |
@Autowired
|
|
|
70 |
JavaMailSender mailSender;
|
|
|
71 |
|
|
|
72 |
@Autowired
|
|
|
73 |
@Qualifier("userRepository")
|
|
|
74 |
private UserRepository userRepository;
|
|
|
75 |
|
|
|
76 |
@Autowired
|
|
|
77 |
private UserAccountRepository userAccountRepository;
|
|
|
78 |
|
|
|
79 |
@Autowired
|
|
|
80 |
private MandiiService mandiiService;
|
|
|
81 |
|
|
|
82 |
@Autowired
|
|
|
83 |
ResponseSender<?> responseSender;
|
|
|
84 |
|
| 29812 |
tejbeer |
85 |
@Autowired
|
|
|
86 |
CreditAccountRepository creditAccountRepository;
|
| 29577 |
amit.gupta |
87 |
|
| 30014 |
tejbeer |
88 |
@Autowired
|
|
|
89 |
FundFinaPreApprovalRepository fundFinaPreApprovalRepository;
|
|
|
90 |
|
| 29577 |
amit.gupta |
91 |
@RequestMapping(value = "payment/gateway/status/{gateway}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 29812 |
tejbeer |
92 |
public ResponseEntity<?> getLoanStatus(HttpServletRequest request, @PathVariable Gateway gateway)
|
|
|
93 |
throws ProfitMandiBusinessException {
|
| 29577 |
amit.gupta |
94 |
int userId = (int) request.getAttribute(ProfitMandiConstants.USER_ID);
|
|
|
95 |
int retailerId = userAccountRepository.selectRetailerIdByUserId(userId);
|
|
|
96 |
FofoStore fs = fofoStoreRepository.selectByRetailerId(retailerId);
|
| 29812 |
tejbeer |
97 |
if (gateway != null && gateway.equals(Gateway.MANDII)) {
|
| 29577 |
amit.gupta |
98 |
try {
|
| 29812 |
tejbeer |
99 |
|
|
|
100 |
AccountStatusResponseOut accountStatusResponseOut = mandiiService.getStatus(fs.getPan());
|
| 29834 |
tejbeer |
101 |
|
| 29813 |
tejbeer |
102 |
CreditAccount creditAccount = creditAccountRepository.selectByFofoIdAndGateway(retailerId,
|
|
|
103 |
Gateway.MANDII);
|
| 29812 |
tejbeer |
104 |
|
|
|
105 |
if (creditAccount == null) {
|
|
|
106 |
|
|
|
107 |
creditAccount = new CreditAccount();
|
|
|
108 |
|
|
|
109 |
creditAccount.setFofoId(retailerId);
|
|
|
110 |
creditAccount.setGateway(Gateway.MANDII);
|
|
|
111 |
|
|
|
112 |
}
|
| 29834 |
tejbeer |
113 |
|
|
|
114 |
if (accountStatusResponseOut == null) {
|
|
|
115 |
creditAccount.setCreditStatus(CreditStatus.UNKNOWN);
|
|
|
116 |
creditAccount.setDescription("User company not found");
|
|
|
117 |
|
| 29812 |
tejbeer |
118 |
} else {
|
| 29834 |
tejbeer |
119 |
creditAccount.setSanctionedAmount(accountStatusResponseOut.getSanctionLimit().floatValue());
|
|
|
120 |
creditAccount.setInterestRate(accountStatusResponseOut.getRateOfInterest());
|
|
|
121 |
creditAccount.setAvailableAmount(accountStatusResponseOut.getBalanceAmount().floatValue());
|
|
|
122 |
creditAccount.setDescription(accountStatusResponseOut.getCurrentStage().toString());
|
|
|
123 |
if (accountStatusResponseOut.getStatus().equals(EligibilityStatusEnum.SANCTION_AVAILABLE)) {
|
|
|
124 |
creditAccount.setCreditStatus(CreditStatus.SANCTIONED);
|
|
|
125 |
} else if (accountStatusResponseOut.getStatus().equals(EligibilityStatusEnum.IN_ELIGIBLE)) {
|
|
|
126 |
creditAccount.setCreditStatus(CreditStatus.INELIGIBLE);
|
|
|
127 |
} else {
|
| 29812 |
tejbeer |
128 |
|
| 29834 |
tejbeer |
129 |
creditAccount.setCreditStatus(CreditStatus.TO_BE_EVALUATED);
|
|
|
130 |
}
|
| 29812 |
tejbeer |
131 |
}
|
| 29834 |
tejbeer |
132 |
|
|
|
133 |
creditAccount.setUpdatedOn(LocalDateTime.now());
|
|
|
134 |
|
| 29812 |
tejbeer |
135 |
creditAccountRepository.persist(creditAccount);
|
|
|
136 |
return responseSender.ok(accountStatusResponseOut);
|
| 29577 |
amit.gupta |
137 |
} catch (Exception e) {
|
| 29928 |
amit.gupta |
138 |
log.info("Trace {}\n{}", e.getMessage(), e);
|
| 30014 |
tejbeer |
139 |
throw new ProfitMandiBusinessException("Loan Provider", gateway, "Can't fetch details for provider");
|
| 29577 |
amit.gupta |
140 |
}
|
| 30014 |
tejbeer |
141 |
} else if (gateway != null && gateway.equals(Gateway.FUNDFINA)) {
|
|
|
142 |
|
|
|
143 |
CreditAccount creditAccount = creditAccountRepository.selectByFofoIdAndGateway(retailerId,
|
|
|
144 |
Gateway.FUNDFINA);
|
|
|
145 |
if (creditAccount == null) {
|
|
|
146 |
creditAccount = new CreditAccount();
|
|
|
147 |
creditAccount.setCreditStatus(CreditStatus.UNKNOWN);
|
|
|
148 |
|
|
|
149 |
} else {
|
|
|
150 |
FundFinaPreApproval fpa = fundFinaPreApprovalRepository
|
|
|
151 |
.selectByProductId(creditAccount.getLoanReferenceId());
|
|
|
152 |
|
|
|
153 |
creditAccount.setExpiredOn(fpa.getExpiryDate());
|
|
|
154 |
creditAccount.setProcessingFee(fpa.getProcessingFee());
|
|
|
155 |
|
|
|
156 |
}
|
|
|
157 |
|
|
|
158 |
return responseSender.ok(creditAccount);
|
| 29577 |
amit.gupta |
159 |
}
|
| 30014 |
tejbeer |
160 |
|
|
|
161 |
else {
|
|
|
162 |
throw new ProfitMandiBusinessException("Provider", "Empty", "Provider can't be empty");
|
|
|
163 |
}
|
| 29577 |
amit.gupta |
164 |
}
|
| 30014 |
tejbeer |
165 |
|
|
|
166 |
@RequestMapping(value = "payment/gateway/transactionSummary", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
167 |
@ApiImplicitParams({
|
|
|
168 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
|
|
169 |
public ResponseEntity<?> getLoanStatus(HttpServletRequest request) throws Exception {
|
|
|
170 |
int userId = (int) request.getAttribute(ProfitMandiConstants.USER_ID);
|
|
|
171 |
int retailerId = userAccountRepository.selectRetailerIdByUserId(userId);
|
|
|
172 |
FofoStore fs = fofoStoreRepository.selectByRetailerId(retailerId);
|
|
|
173 |
List<TransactionSummaryResponseOut> tranactionSummary = mandiiService.getTransactionSummary(fs.getPan());
|
|
|
174 |
tranactionSummary = tranactionSummary.stream()
|
|
|
175 |
.sorted(Comparator.comparingInt(TransactionSummaryResponseOut::getMerchantOrderNumber).reversed())
|
|
|
176 |
.collect(Collectors.toList());
|
|
|
177 |
log.info("tranactionSummary" + tranactionSummary);
|
|
|
178 |
|
|
|
179 |
return responseSender.ok(tranactionSummary.stream().limit(10).collect(Collectors.toList()));
|
|
|
180 |
}
|
| 29577 |
amit.gupta |
181 |
}
|