Subversion Repositories SmartDukaan

Rev

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

Rev 29928 Rev 30014
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
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
 
3
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
23
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
4
import com.spice.profitmandi.common.model.ProfitMandiConstants;
24
import com.spice.profitmandi.common.model.ProfitMandiConstants;
5
import com.spice.profitmandi.common.services.mandii.AccountStatusResponseOut;
25
import com.spice.profitmandi.common.services.mandii.AccountStatusResponseOut;
6
import com.spice.profitmandi.common.services.mandii.EligibilityStatusEnum;
26
import com.spice.profitmandi.common.services.mandii.EligibilityStatusEnum;
7
import com.spice.profitmandi.common.services.mandii.MandiiService;
27
import com.spice.profitmandi.common.services.mandii.MandiiService;
-
 
28
import com.spice.profitmandi.common.services.mandii.TransactionSummaryResponseOut;
8
import com.spice.profitmandi.common.web.util.ResponseSender;
29
import com.spice.profitmandi.common.web.util.ResponseSender;
9
import com.spice.profitmandi.dao.entity.dtr.CreditAccount;
30
import com.spice.profitmandi.dao.entity.dtr.CreditAccount;
10
import com.spice.profitmandi.dao.entity.dtr.CreditStatus;
31
import com.spice.profitmandi.dao.entity.dtr.CreditStatus;
-
 
32
import com.spice.profitmandi.dao.entity.dtr.FundFinaPreApproval;
11
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
33
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
12
import com.spice.profitmandi.dao.enumuration.fofo.Gateway;
34
import com.spice.profitmandi.dao.enumuration.fofo.Gateway;
13
import com.spice.profitmandi.dao.repository.catalog.AddWalletRequestRepository;
35
import com.spice.profitmandi.dao.repository.catalog.AddWalletRequestRepository;
14
import com.spice.profitmandi.dao.repository.dtr.CreditAccountRepository;
36
import com.spice.profitmandi.dao.repository.dtr.CreditAccountRepository;
15
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
37
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
-
 
38
import com.spice.profitmandi.dao.repository.dtr.FundFinaPreApprovalRepository;
16
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
39
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
17
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
40
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
18
import com.spice.profitmandi.dao.repository.transaction.PaymentRepository;
41
import com.spice.profitmandi.dao.repository.transaction.PaymentRepository;
19
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
42
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
20
import com.spice.profitmandi.service.wallet.WalletService;
43
import com.spice.profitmandi.service.wallet.WalletService;
21
import org.apache.logging.log4j.LogManager;
-
 
22
import org.apache.logging.log4j.Logger;
-
 
23
import org.springframework.beans.factory.annotation.Autowired;
-
 
24
import org.springframework.beans.factory.annotation.Qualifier;
-
 
25
import org.springframework.http.MediaType;
-
 
26
import org.springframework.http.ResponseEntity;
-
 
27
import org.springframework.mail.javamail.JavaMailSender;
-
 
28
import org.springframework.stereotype.Controller;
-
 
29
import org.springframework.transaction.annotation.Transactional;
-
 
30
import org.springframework.web.bind.annotation.PathVariable;
-
 
31
import org.springframework.web.bind.annotation.RequestMapping;
-
 
32
import org.springframework.web.bind.annotation.RequestMethod;
-
 
33
 
44
 
34
import javax.servlet.http.HttpServletRequest;
45
import io.swagger.annotations.ApiImplicitParam;
35
import java.time.LocalDateTime;
46
import io.swagger.annotations.ApiImplicitParams;
36
 
47
 
37
@Controller
48
@Controller
38
@Transactional(rollbackFor = Throwable.class)
49
@Transactional(rollbackFor = Throwable.class)
39
public class GatewayController {
50
public class GatewayController {
40
 
51
 
Line 72... Line 83...
72
	ResponseSender<?> responseSender;
83
	ResponseSender<?> responseSender;
73
 
84
 
74
	@Autowired
85
	@Autowired
75
	CreditAccountRepository creditAccountRepository;
86
	CreditAccountRepository creditAccountRepository;
76
 
87
 
-
 
88
	@Autowired
-
 
89
	FundFinaPreApprovalRepository fundFinaPreApprovalRepository;
-
 
90
 
77
	@RequestMapping(value = "payment/gateway/status/{gateway}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
91
	@RequestMapping(value = "payment/gateway/status/{gateway}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
78
	public ResponseEntity<?> getLoanStatus(HttpServletRequest request, @PathVariable Gateway gateway)
92
	public ResponseEntity<?> getLoanStatus(HttpServletRequest request, @PathVariable Gateway gateway)
79
			throws ProfitMandiBusinessException {
93
			throws ProfitMandiBusinessException {
80
		int userId = (int) request.getAttribute(ProfitMandiConstants.USER_ID);
94
		int userId = (int) request.getAttribute(ProfitMandiConstants.USER_ID);
81
		int retailerId = userAccountRepository.selectRetailerIdByUserId(userId);
95
		int retailerId = userAccountRepository.selectRetailerIdByUserId(userId);
Line 120... Line 134...
120
 
134
 
121
				creditAccountRepository.persist(creditAccount);
135
				creditAccountRepository.persist(creditAccount);
122
				return responseSender.ok(accountStatusResponseOut);
136
				return responseSender.ok(accountStatusResponseOut);
123
			} catch (Exception e) {
137
			} catch (Exception e) {
124
				log.info("Trace {}\n{}", e.getMessage(), e);
138
				log.info("Trace {}\n{}", e.getMessage(), e);
125
				throw new ProfitMandiBusinessException("Loan Provider", gateway, "Cant fetch details for provider");
139
				throw new ProfitMandiBusinessException("Loan Provider", gateway, "Can't fetch details for provider");
126
			}
140
			}
-
 
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
 
127
		} else {
149
			} else {
-
 
150
				FundFinaPreApproval fpa = fundFinaPreApprovalRepository
-
 
151
						.selectByProductId(creditAccount.getLoanReferenceId());
-
 
152
 
-
 
153
				creditAccount.setExpiredOn(fpa.getExpiryDate());
128
			throw new ProfitMandiBusinessException("Provider", "Empty", "Provider cant be empty");
154
				creditAccount.setProcessingFee(fpa.getProcessingFee());
-
 
155
 
-
 
156
			}
-
 
157
 
-
 
158
			return responseSender.ok(creditAccount);
129
		}
159
		}
-
 
160
 
-
 
161
		else {
-
 
162
			throw new ProfitMandiBusinessException("Provider", "Empty", "Provider can't be empty");
-
 
163
		}
-
 
164
	}
-
 
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()));
130
	}
180
	}
131
}
181
}
132
182