Subversion Repositories SmartDukaan

Rev

Rev 36557 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 36557 Rev 37657
Line 16... Line 16...
16
import org.springframework.web.bind.annotation.RequestMapping;
16
import org.springframework.web.bind.annotation.RequestMapping;
17
import org.springframework.web.bind.annotation.RequestMethod;
17
import org.springframework.web.bind.annotation.RequestMethod;
18
 
18
 
19
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
19
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
20
import com.spice.profitmandi.common.model.ProfitMandiConstants;
20
import com.spice.profitmandi.common.model.ProfitMandiConstants;
21
import com.spice.profitmandi.common.services.mandii.AccountStatusResponseOut;
21
import com.spice.profitmandi.common.services.sdcredit.AccountStatusResponseOut;
22
import com.spice.profitmandi.common.services.mandii.EligibilityStatusEnum;
22
import com.spice.profitmandi.common.services.sdcredit.EligibilityStatusEnum;
23
import com.spice.profitmandi.common.services.mandii.MandiiService;
-
 
24
import com.spice.profitmandi.common.web.util.ResponseSender;
23
import com.spice.profitmandi.common.web.util.ResponseSender;
25
import com.spice.profitmandi.dao.entity.dtr.CreditAccount;
24
import com.spice.profitmandi.dao.entity.dtr.CreditAccount;
26
import com.spice.profitmandi.dao.entity.dtr.CreditStatus;
25
import com.spice.profitmandi.dao.entity.dtr.CreditStatus;
27
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
26
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
28
import com.spice.profitmandi.dao.entity.transaction.Loan;
27
import com.spice.profitmandi.dao.entity.transaction.Loan;
Line 64... Line 63...
64
	FofoStoreRepository fofoStoreRepository;
63
	FofoStoreRepository fofoStoreRepository;
65
 
64
 
66
	@Autowired
65
	@Autowired
67
	private UserAccountRepository userAccountRepository;
66
	private UserAccountRepository userAccountRepository;
68
 
67
 
69
	@Autowired
-
 
70
	private MandiiService mandiiService;
-
 
71
 
68
 
72
	@Autowired
69
	@Autowired
73
	ResponseSender<?> responseSender;
70
	ResponseSender<?> responseSender;
74
 
71
 
75
	@Autowired
72
	@Autowired
Line 90... Line 87...
90
	@RequestMapping(value = "payment/gateway/status/{gateway}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
87
	@RequestMapping(value = "payment/gateway/status/{gateway}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
91
	public ResponseEntity<?> getLoanStatus(HttpServletRequest request, @PathVariable Gateway gateway)
88
	public ResponseEntity<?> getLoanStatus(HttpServletRequest request, @PathVariable Gateway gateway)
92
			throws ProfitMandiBusinessException {
89
			throws ProfitMandiBusinessException {
93
		int userId = (int) request.getAttribute(ProfitMandiConstants.USER_ID);
90
		int userId = (int) request.getAttribute(ProfitMandiConstants.USER_ID);
94
		int retailerId = userAccountRepository.selectRetailerIdByUserId(userId);
91
		int retailerId = userAccountRepository.selectRetailerIdByUserId(userId);
95
		FofoStore fs = fofoStoreRepository.selectByRetailerId(retailerId);
-
 
96
		if (gateway != null && gateway.equals(Gateway.MANDII)) {
-
 
97
			try {
-
 
98
 
-
 
99
				AccountStatusResponseOut accountStatusResponseOut = mandiiService.getStatus(fs.getPan());
-
 
100
 
-
 
101
				CreditAccount creditAccount = creditAccountRepository.selectByFofoIdAndGateway(retailerId,
-
 
102
						Gateway.MANDII);
-
 
103
 
-
 
104
				if (creditAccount == null) {
-
 
105
 
-
 
106
					creditAccount = new CreditAccount();
-
 
107
 
-
 
108
					creditAccount.setFofoId(retailerId);
-
 
109
					creditAccount.setGateway(Gateway.MANDII);
-
 
110
 
-
 
111
				}
-
 
112
 
-
 
113
				if (accountStatusResponseOut == null) {
-
 
114
					creditAccount.setCreditStatus(CreditStatus.UNKNOWN);
-
 
115
					creditAccount.setDescription("User company not found");
-
 
116
 
-
 
117
				} else {
-
 
118
					creditAccount.setSanctionedAmount(accountStatusResponseOut.getSanctionLimit().floatValue());
-
 
119
					creditAccount.setInterestRate(accountStatusResponseOut.getRateOfInterest());
-
 
120
					creditAccount.setAvailableAmount(accountStatusResponseOut.getBalanceAmount().floatValue());
-
 
121
					creditAccount.setDescription(accountStatusResponseOut.getCurrentStage().toString());
-
 
122
					if (accountStatusResponseOut.getStatus().equals(EligibilityStatusEnum.SANCTION_AVAILABLE)) {
-
 
123
						creditAccount.setCreditStatus(CreditStatus.SANCTIONED);
-
 
124
					} else if (accountStatusResponseOut.getStatus().equals(EligibilityStatusEnum.IN_ELIGIBLE)) {
-
 
125
						creditAccount.setCreditStatus(CreditStatus.INELIGIBLE);
-
 
126
					} else {
-
 
127
 
-
 
128
						creditAccount.setCreditStatus(CreditStatus.TO_BE_EVALUATED);
-
 
129
					}
-
 
130
				}
-
 
131
 
-
 
132
				creditAccount.setUpdatedOn(LocalDateTime.now());
-
 
133
 
-
 
134
				creditAccountRepository.persist(creditAccount);
-
 
135
				return responseSender.ok(accountStatusResponseOut);
-
 
136
			} catch (Exception e) {
-
 
137
				log.info("Trace {}\n{}", e.getMessage(), e);
-
 
138
				throw new ProfitMandiBusinessException("Loan Provider", gateway, "Can't fetch details for provider");
-
 
139
			}
-
 
140
		} else if (gateway != null && gateway.equals(Gateway.SDDIRECT)) {
92
		if (gateway != null && gateway.equals(Gateway.SDDIRECT)) {
141
			CreditAccount creditAccount = creditAccountRepository.selectByFofoIdAndGateway(retailerId,
93
			CreditAccount creditAccount = creditAccountRepository.selectByFofoIdAndGateway(retailerId,
142
					Gateway.SDDIRECT);
94
					Gateway.SDDIRECT);
143
 
95
 
144
			com.spice.profitmandi.dao.model.CreditSummary creditSummary = sdCreditService.getCreditSummary(retailerId);
96
			com.spice.profitmandi.dao.model.CreditSummary creditSummary = sdCreditService.getCreditSummary(retailerId);
145
 
97