| 29577 |
amit.gupta |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
|
|
3 |
import javax.servlet.http.HttpServletRequest;
|
|
|
4 |
|
|
|
5 |
import org.apache.logging.log4j.LogManager;
|
|
|
6 |
import org.apache.logging.log4j.Logger;
|
|
|
7 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
8 |
import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
9 |
import org.springframework.http.MediaType;
|
|
|
10 |
import org.springframework.http.ResponseEntity;
|
|
|
11 |
import org.springframework.mail.javamail.JavaMailSender;
|
|
|
12 |
import org.springframework.stereotype.Controller;
|
|
|
13 |
import org.springframework.transaction.annotation.Transactional;
|
|
|
14 |
import org.springframework.web.bind.annotation.PathVariable;
|
|
|
15 |
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
16 |
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
17 |
|
|
|
18 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
|
|
19 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
|
|
20 |
import com.spice.profitmandi.common.services.mandii.MandiiService;
|
|
|
21 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
|
|
22 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
|
|
23 |
import com.spice.profitmandi.dao.enumuration.fofo.Gateway;
|
|
|
24 |
import com.spice.profitmandi.dao.repository.catalog.AddWalletRequestRepository;
|
|
|
25 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
|
|
26 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
|
|
27 |
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
|
|
|
28 |
import com.spice.profitmandi.dao.repository.transaction.PaymentRepository;
|
|
|
29 |
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
|
|
|
30 |
import com.spice.profitmandi.service.wallet.WalletService;
|
|
|
31 |
|
|
|
32 |
@Controller
|
|
|
33 |
@Transactional(rollbackFor = Throwable.class)
|
|
|
34 |
public class GatewayController {
|
|
|
35 |
|
|
|
36 |
private static final Logger log = LogManager.getLogger(GatewayController.class);
|
|
|
37 |
|
|
|
38 |
@Autowired
|
|
|
39 |
UserWalletRepository userWalletRepository;
|
|
|
40 |
|
|
|
41 |
@Autowired
|
|
|
42 |
PaymentRepository paymentRepository;
|
|
|
43 |
|
|
|
44 |
@Autowired
|
|
|
45 |
AddWalletRequestRepository addWalletRequestRepository;
|
|
|
46 |
|
|
|
47 |
@Autowired
|
|
|
48 |
WalletService walletService;
|
|
|
49 |
|
|
|
50 |
@Autowired
|
|
|
51 |
FofoStoreRepository fofoStoreRepository;
|
|
|
52 |
|
|
|
53 |
@Autowired
|
|
|
54 |
JavaMailSender mailSender;
|
|
|
55 |
|
|
|
56 |
@Autowired
|
|
|
57 |
@Qualifier("userRepository")
|
|
|
58 |
private UserRepository userRepository;
|
|
|
59 |
|
|
|
60 |
@Autowired
|
|
|
61 |
private UserAccountRepository userAccountRepository;
|
|
|
62 |
|
|
|
63 |
@Autowired
|
|
|
64 |
private MandiiService mandiiService;
|
|
|
65 |
|
|
|
66 |
@Autowired
|
|
|
67 |
ResponseSender<?> responseSender;
|
|
|
68 |
|
|
|
69 |
|
|
|
70 |
@RequestMapping(value = "payment/gateway/status/{gateway}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
71 |
public ResponseEntity<?> getLoanStatus(HttpServletRequest request,
|
|
|
72 |
@PathVariable Gateway gateway) throws ProfitMandiBusinessException {
|
|
|
73 |
int userId = (int) request.getAttribute(ProfitMandiConstants.USER_ID);
|
|
|
74 |
int retailerId = userAccountRepository.selectRetailerIdByUserId(userId);
|
|
|
75 |
FofoStore fs = fofoStoreRepository.selectByRetailerId(retailerId);
|
|
|
76 |
if(gateway != null && gateway.equals(Gateway.MANDII)) {
|
|
|
77 |
try {
|
|
|
78 |
return responseSender.ok(mandiiService.getStatus(fs.getPan()));
|
|
|
79 |
} catch (Exception e) {
|
|
|
80 |
throw new ProfitMandiBusinessException("Loan Provider", gateway, "Cant fetch details for provider");
|
|
|
81 |
}
|
|
|
82 |
} else {
|
|
|
83 |
throw new ProfitMandiBusinessException("Provider", "Empty", "Provider cant be empty");
|
|
|
84 |
}
|
|
|
85 |
}
|
|
|
86 |
}
|