| Line 1... |
Line 1... |
| 1 |
package com.spice.profitmandi.web.controller;
|
1 |
package com.spice.profitmandi.web.controller;
|
| 2 |
|
2 |
|
| 3 |
import java.math.BigDecimal;
|
3 |
import java.math.BigDecimal;
|
| 4 |
import java.time.LocalDateTime;
|
4 |
import java.time.LocalDateTime;
|
| 5 |
import java.util.Arrays;
|
5 |
import java.util.Arrays;
|
| 6 |
import java.util.Comparator;
|
- |
|
| 7 |
import java.util.List;
|
6 |
import java.util.List;
|
| 8 |
import java.util.stream.Collectors;
|
- |
|
| 9 |
|
7 |
|
| 10 |
import javax.servlet.http.HttpServletRequest;
|
8 |
import javax.servlet.http.HttpServletRequest;
|
| 11 |
|
9 |
|
| 12 |
import org.apache.logging.log4j.LogManager;
|
10 |
import org.apache.logging.log4j.LogManager;
|
| 13 |
import org.apache.logging.log4j.Logger;
|
11 |
import org.apache.logging.log4j.Logger;
|
| 14 |
import org.springframework.beans.factory.annotation.Autowired;
|
12 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 15 |
import org.springframework.beans.factory.annotation.Qualifier;
|
- |
|
| 16 |
import org.springframework.http.MediaType;
|
13 |
import org.springframework.http.MediaType;
|
| 17 |
import org.springframework.http.ResponseEntity;
|
14 |
import org.springframework.http.ResponseEntity;
|
| 18 |
import org.springframework.mail.javamail.JavaMailSender;
|
- |
|
| 19 |
import org.springframework.stereotype.Controller;
|
15 |
import org.springframework.stereotype.Controller;
|
| 20 |
import org.springframework.transaction.annotation.Transactional;
|
16 |
import org.springframework.transaction.annotation.Transactional;
|
| 21 |
import org.springframework.web.bind.annotation.PathVariable;
|
17 |
import org.springframework.web.bind.annotation.PathVariable;
|
| 22 |
import org.springframework.web.bind.annotation.RequestMapping;
|
18 |
import org.springframework.web.bind.annotation.RequestMapping;
|
| 23 |
import org.springframework.web.bind.annotation.RequestMethod;
|
19 |
import org.springframework.web.bind.annotation.RequestMethod;
|
| Line 25... |
Line 21... |
| 25 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
21 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 26 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
22 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 27 |
import com.spice.profitmandi.common.services.mandii.AccountStatusResponseOut;
|
23 |
import com.spice.profitmandi.common.services.mandii.AccountStatusResponseOut;
|
| 28 |
import com.spice.profitmandi.common.services.mandii.EligibilityStatusEnum;
|
24 |
import com.spice.profitmandi.common.services.mandii.EligibilityStatusEnum;
|
| 29 |
import com.spice.profitmandi.common.services.mandii.MandiiService;
|
25 |
import com.spice.profitmandi.common.services.mandii.MandiiService;
|
| 30 |
import com.spice.profitmandi.common.services.mandii.RepaymentDetails;
|
- |
|
| 31 |
import com.spice.profitmandi.common.services.mandii.TransactionSummaryResponseOut;
|
- |
|
| 32 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
26 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
| 33 |
import com.spice.profitmandi.dao.entity.dtr.CreditAccount;
|
27 |
import com.spice.profitmandi.dao.entity.dtr.CreditAccount;
|
| 34 |
import com.spice.profitmandi.dao.entity.dtr.CreditStatus;
|
28 |
import com.spice.profitmandi.dao.entity.dtr.CreditStatus;
|
| 35 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
29 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
| 36 |
import com.spice.profitmandi.dao.entity.transaction.Loan;
|
30 |
import com.spice.profitmandi.dao.entity.transaction.Loan;
|
| 37 |
import com.spice.profitmandi.dao.entity.transaction.LoanStatement;
|
- |
|
| 38 |
import com.spice.profitmandi.dao.entity.transaction.SDCreditRequirement;
|
31 |
import com.spice.profitmandi.dao.entity.transaction.SDCreditRequirement;
|
| 39 |
import com.spice.profitmandi.dao.enumuration.fofo.Gateway;
|
32 |
import com.spice.profitmandi.dao.enumuration.fofo.Gateway;
|
| 40 |
import com.spice.profitmandi.dao.model.SDCreditResponseOut;
|
33 |
import com.spice.profitmandi.dao.model.SDCreditResponseOut;
|
| 41 |
import com.spice.profitmandi.dao.repository.catalog.AddWalletRequestRepository;
|
34 |
import com.spice.profitmandi.dao.repository.catalog.AddWalletRequestRepository;
|
| 42 |
import com.spice.profitmandi.dao.repository.dtr.CreditAccountRepository;
|
35 |
import com.spice.profitmandi.dao.repository.dtr.CreditAccountRepository;
|
| 43 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
36 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
| 44 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
37 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
| 45 |
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
|
- |
|
| 46 |
import com.spice.profitmandi.dao.repository.transaction.LoanRepository;
|
38 |
import com.spice.profitmandi.dao.repository.transaction.LoanRepository;
|
| 47 |
import com.spice.profitmandi.dao.repository.transaction.LoanStatementRepository;
|
39 |
import com.spice.profitmandi.dao.repository.transaction.LoanStatementRepository;
|
| 48 |
import com.spice.profitmandi.dao.repository.transaction.PaymentRepository;
|
40 |
import com.spice.profitmandi.dao.repository.transaction.PaymentRepository;
|
| 49 |
import com.spice.profitmandi.dao.repository.transaction.SDCreditRequirementRepository;
|
41 |
import com.spice.profitmandi.dao.repository.transaction.SDCreditRequirementRepository;
|
| 50 |
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
|
42 |
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
|
| 51 |
import com.spice.profitmandi.service.transaction.SDCreditService;
|
43 |
import com.spice.profitmandi.service.transaction.SDCreditService;
|
| 52 |
import com.spice.profitmandi.service.wallet.WalletService;
|
44 |
import com.spice.profitmandi.service.wallet.WalletService;
|
| 53 |
|
45 |
|
| 54 |
import io.swagger.annotations.ApiImplicitParam;
|
- |
|
| 55 |
import io.swagger.annotations.ApiImplicitParams;
|
- |
|
| 56 |
|
- |
|
| 57 |
@Controller
|
46 |
@Controller
|
| 58 |
@Transactional(rollbackFor = Throwable.class)
|
47 |
@Transactional(rollbackFor = Throwable.class)
|
| 59 |
public class GatewayController {
|
48 |
public class GatewayController {
|
| 60 |
|
49 |
|
| 61 |
private static final Logger log = LogManager.getLogger(GatewayController.class);
|
50 |
private static final Logger log = LogManager.getLogger(GatewayController.class);
|
| Line 74... |
Line 63... |
| 74 |
|
63 |
|
| 75 |
@Autowired
|
64 |
@Autowired
|
| 76 |
FofoStoreRepository fofoStoreRepository;
|
65 |
FofoStoreRepository fofoStoreRepository;
|
| 77 |
|
66 |
|
| 78 |
@Autowired
|
67 |
@Autowired
|
| 79 |
JavaMailSender mailSender;
|
- |
|
| 80 |
|
- |
|
| 81 |
@Autowired
|
- |
|
| 82 |
@Qualifier("userRepository")
|
- |
|
| 83 |
private UserRepository userRepository;
|
- |
|
| 84 |
|
- |
|
| 85 |
@Autowired
|
- |
|
| 86 |
private UserAccountRepository userAccountRepository;
|
68 |
private UserAccountRepository userAccountRepository;
|
| 87 |
|
69 |
|
| 88 |
@Autowired
|
70 |
@Autowired
|
| 89 |
private MandiiService mandiiService;
|
71 |
private MandiiService mandiiService;
|
| 90 |
|
72 |
|
| Line 198... |
Line 180... |
| 198 |
else {
|
180 |
else {
|
| 199 |
throw new ProfitMandiBusinessException("Provider", "Empty", "Provider can't be empty");
|
181 |
throw new ProfitMandiBusinessException("Provider", "Empty", "Provider can't be empty");
|
| 200 |
}
|
182 |
}
|
| 201 |
}
|
183 |
}
|
| 202 |
|
184 |
|
| 203 |
@RequestMapping(value = "payment/gateway/transactionSummary", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
- |
|
| 204 |
@ApiImplicitParams({
|
- |
|
| 205 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
- |
|
| 206 |
public ResponseEntity<?> getLoanStatus(HttpServletRequest request) throws Exception {
|
- |
|
| 207 |
int userId = (int) request.getAttribute(ProfitMandiConstants.USER_ID);
|
- |
|
| 208 |
int retailerId = userAccountRepository.selectRetailerIdByUserId(userId);
|
- |
|
| 209 |
FofoStore fs = fofoStoreRepository.selectByRetailerId(retailerId);
|
- |
|
| 210 |
List<TransactionSummaryResponseOut> tranactionSummary = mandiiService.getTransactionSummary(fs.getPan());
|
- |
|
| 211 |
tranactionSummary = tranactionSummary.stream()
|
- |
|
| 212 |
.sorted(Comparator.comparingInt(TransactionSummaryResponseOut::getMerchantOrderNumber).reversed())
|
- |
|
| 213 |
.collect(Collectors.toList());
|
- |
|
| 214 |
log.info("tranactionSummary" + tranactionSummary);
|
- |
|
| 215 |
|
- |
|
| 216 |
return responseSender.ok(tranactionSummary.stream().limit(10).collect(Collectors.toList()));
|
- |
|
| 217 |
}
|
- |
|
| 218 |
|
- |
|
| 219 |
@RequestMapping(value = "payment/gateway/sddirect/summary", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
185 |
@RequestMapping(value = "payment/gateway/sddirect/summary", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 220 |
public ResponseEntity<?> getSdDirectLoan(HttpServletRequest request) throws ProfitMandiBusinessException {
|
186 |
public ResponseEntity<?> getSdDirectLoan(HttpServletRequest request) throws ProfitMandiBusinessException {
|
| 221 |
int userId = (int) request.getAttribute(ProfitMandiConstants.USER_ID);
|
187 |
int userId = (int) request.getAttribute(ProfitMandiConstants.USER_ID);
|
| 222 |
int retailerId = userAccountRepository.selectRetailerIdByUserId(userId);
|
188 |
int retailerId = userAccountRepository.selectRetailerIdByUserId(userId);
|
| 223 |
SDCreditResponseOut sdCreditResponseOut = sdCreditService.sdDirectService(retailerId);
|
189 |
SDCreditResponseOut sdCreditResponseOut = sdCreditService.sdDirectService(retailerId);
|
| 224 |
return responseSender.ok(sdCreditResponseOut);
|
190 |
return responseSender.ok(sdCreditResponseOut);
|
| 225 |
}
|
191 |
}
|
| - |
|
192 |
@RequestMapping(value = "payment/gateway/sddirect/settle-loan/{loanId}", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
|
| - |
|
193 |
public ResponseEntity<?> settleLoan(HttpServletRequest request, @PathVariable int loanId) throws ProfitMandiBusinessException {
|
| - |
|
194 |
int userId = (int) request.getAttribute(ProfitMandiConstants.USER_ID);
|
| - |
|
195 |
int retailerId = userAccountRepository.selectRetailerIdByUserId(userId);
|
| - |
|
196 |
Loan loan = loanRepository.selectByLoanId(loanId);
|
| - |
|
197 |
if(loan.getFofoId()!=retailerId) {
|
| - |
|
198 |
throw new ProfitMandiBusinessException("Unauthorised", "Unauthorised", "Unauthorised");
|
| - |
|
199 |
}
|
| - |
|
200 |
sdCreditService.settleLoan(loan);
|
| - |
|
201 |
return responseSender.ok(walletService.getWalletAmount(retailerId));
|
| - |
|
202 |
}
|
| 226 |
|
203 |
|
| 227 |
}
|
204 |
}
|
| 228 |
|
205 |
|