Subversion Repositories SmartDukaan

Rev

Rev 29577 | Rev 29813 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 29577 Rev 29812
Line 1... Line 1...
1
package com.spice.profitmandi.web.controller;
1
package com.spice.profitmandi.web.controller;
2
 
2
 
-
 
3
import java.time.LocalDateTime;
-
 
4
 
3
import javax.servlet.http.HttpServletRequest;
5
import javax.servlet.http.HttpServletRequest;
4
 
6
 
5
import org.apache.logging.log4j.LogManager;
7
import org.apache.logging.log4j.LogManager;
6
import org.apache.logging.log4j.Logger;
8
import org.apache.logging.log4j.Logger;
7
import org.springframework.beans.factory.annotation.Autowired;
9
import org.springframework.beans.factory.annotation.Autowired;
Line 15... Line 17...
15
import org.springframework.web.bind.annotation.RequestMapping;
17
import org.springframework.web.bind.annotation.RequestMapping;
16
import org.springframework.web.bind.annotation.RequestMethod;
18
import org.springframework.web.bind.annotation.RequestMethod;
17
 
19
 
18
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
20
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
19
import com.spice.profitmandi.common.model.ProfitMandiConstants;
21
import com.spice.profitmandi.common.model.ProfitMandiConstants;
-
 
22
import com.spice.profitmandi.common.services.mandii.AccountStatusResponseOut;
-
 
23
import com.spice.profitmandi.common.services.mandii.EligibilityStatusEnum;
20
import com.spice.profitmandi.common.services.mandii.MandiiService;
24
import com.spice.profitmandi.common.services.mandii.MandiiService;
21
import com.spice.profitmandi.common.web.util.ResponseSender;
25
import com.spice.profitmandi.common.web.util.ResponseSender;
-
 
26
import com.spice.profitmandi.dao.entity.dtr.CreditAccount;
-
 
27
import com.spice.profitmandi.dao.entity.dtr.CreditStatus;
22
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
28
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
23
import com.spice.profitmandi.dao.enumuration.fofo.Gateway;
29
import com.spice.profitmandi.dao.enumuration.fofo.Gateway;
24
import com.spice.profitmandi.dao.repository.catalog.AddWalletRequestRepository;
30
import com.spice.profitmandi.dao.repository.catalog.AddWalletRequestRepository;
-
 
31
import com.spice.profitmandi.dao.repository.dtr.CreditAccountRepository;
25
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
32
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
26
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
33
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
27
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
34
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
28
import com.spice.profitmandi.dao.repository.transaction.PaymentRepository;
35
import com.spice.profitmandi.dao.repository.transaction.PaymentRepository;
29
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
36
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
Line 35... Line 42...
35
 
42
 
36
	private static final Logger log = LogManager.getLogger(GatewayController.class);
43
	private static final Logger log = LogManager.getLogger(GatewayController.class);
37
 
44
 
38
	@Autowired
45
	@Autowired
39
	UserWalletRepository userWalletRepository;
46
	UserWalletRepository userWalletRepository;
40
	
47
 
41
	@Autowired
48
	@Autowired
42
	PaymentRepository paymentRepository;
49
	PaymentRepository paymentRepository;
43
 
50
 
44
	@Autowired
51
	@Autowired
45
	AddWalletRequestRepository addWalletRequestRepository;
52
	AddWalletRequestRepository addWalletRequestRepository;
Line 47... Line 54...
47
	@Autowired
54
	@Autowired
48
	WalletService walletService;
55
	WalletService walletService;
49
 
56
 
50
	@Autowired
57
	@Autowired
51
	FofoStoreRepository fofoStoreRepository;
58
	FofoStoreRepository fofoStoreRepository;
52
	
59
 
53
	@Autowired
60
	@Autowired
54
	JavaMailSender mailSender;
61
	JavaMailSender mailSender;
55
 
62
 
56
	@Autowired
63
	@Autowired
57
	@Qualifier("userRepository")
64
	@Qualifier("userRepository")
Line 64... Line 71...
64
	private MandiiService mandiiService;
71
	private MandiiService mandiiService;
65
 
72
 
66
	@Autowired
73
	@Autowired
67
	ResponseSender<?> responseSender;
74
	ResponseSender<?> responseSender;
68
 
75
 
-
 
76
	@Autowired
-
 
77
	CreditAccountRepository creditAccountRepository;
69
 
78
 
70
	@RequestMapping(value = "payment/gateway/status/{gateway}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
79
	@RequestMapping(value = "payment/gateway/status/{gateway}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
71
	public ResponseEntity<?> getLoanStatus(HttpServletRequest request,
80
	public ResponseEntity<?> getLoanStatus(HttpServletRequest request, @PathVariable Gateway gateway)
72
			@PathVariable Gateway gateway) throws ProfitMandiBusinessException {
81
			throws ProfitMandiBusinessException {
73
		int userId = (int) request.getAttribute(ProfitMandiConstants.USER_ID);
82
		int userId = (int) request.getAttribute(ProfitMandiConstants.USER_ID);
74
		int retailerId = userAccountRepository.selectRetailerIdByUserId(userId);
83
		int retailerId = userAccountRepository.selectRetailerIdByUserId(userId);
75
		FofoStore fs = fofoStoreRepository.selectByRetailerId(retailerId);
84
		FofoStore fs = fofoStoreRepository.selectByRetailerId(retailerId);
76
		if(gateway != null && gateway.equals(Gateway.MANDII)) {
85
		if (gateway != null && gateway.equals(Gateway.MANDII)) {
77
			try {
86
			try {
-
 
87
 
-
 
88
				AccountStatusResponseOut accountStatusResponseOut = mandiiService.getStatus(fs.getPan());
-
 
89
				CreditAccount creditAccount = creditAccountRepository.selectByFofoId(retailerId);
-
 
90
 
-
 
91
				if (creditAccount == null) {
-
 
92
 
-
 
93
					creditAccount = new CreditAccount();
-
 
94
 
-
 
95
					creditAccount.setFofoId(retailerId);
-
 
96
					creditAccount.setGateway(Gateway.MANDII);
-
 
97
 
-
 
98
				}
-
 
99
				creditAccount.setSanctionedAmount(accountStatusResponseOut.getSanctionLimit().floatValue());
-
 
100
				creditAccount.setInterestRate(accountStatusResponseOut.getRateOfInterest());
-
 
101
				creditAccount.setAvailableAmount(accountStatusResponseOut.getBalanceAmount().floatValue());
-
 
102
				creditAccount.setUpdatedOn(LocalDateTime.now());
-
 
103
				creditAccount.setDescription(accountStatusResponseOut.getCurrentStage().toString());
-
 
104
				if (accountStatusResponseOut.getStatus().equals(EligibilityStatusEnum.SANCTION_AVAILABLE)) {
-
 
105
					creditAccount.setCreditStatus(CreditStatus.SANCTIONED);
-
 
106
				} else if (accountStatusResponseOut.getStatus().equals(EligibilityStatusEnum.IN_ELIGIBLE)) {
-
 
107
					creditAccount.setCreditStatus(CreditStatus.INELIGIBLE);
-
 
108
				} else {
-
 
109
 
-
 
110
					creditAccount.setCreditStatus(CreditStatus.TO_BE_EVALUATED);
-
 
111
				}
-
 
112
				creditAccountRepository.persist(creditAccount);
78
				return responseSender.ok(mandiiService.getStatus(fs.getPan()));
113
				return responseSender.ok(accountStatusResponseOut);
79
			} catch (Exception e) {
114
			} catch (Exception e) {
80
				throw new ProfitMandiBusinessException("Loan Provider", gateway, "Cant fetch details for provider");
115
				throw new ProfitMandiBusinessException("Loan Provider", gateway, "Cant fetch details for provider");
81
			}
116
			}
82
		} else {
117
		} else {
83
			throw new ProfitMandiBusinessException("Provider", "Empty", "Provider cant be empty");
118
			throw new ProfitMandiBusinessException("Provider", "Empty", "Provider cant be empty");