Subversion Repositories SmartDukaan

Rev

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

Rev 35458 Rev 35652
Line 1... Line 1...
1
package com.spice.profitmandi.web.controller;
1
package com.spice.profitmandi.web.controller;
2
 
2
 
3
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
3
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
4
import com.spice.profitmandi.common.model.CustomRetailer;
4
import com.spice.profitmandi.common.model.CustomRetailer;
5
import com.spice.profitmandi.common.model.ProfitMandiConstants;
5
import com.spice.profitmandi.common.model.ProfitMandiConstants;
-
 
6
import com.spice.profitmandi.common.model.UserInfo;
6
import com.spice.profitmandi.common.web.util.ResponseSender;
7
import com.spice.profitmandi.common.web.util.ResponseSender;
7
import com.spice.profitmandi.dao.entity.fofo.FofoPayment;
8
import com.spice.profitmandi.dao.entity.fofo.FofoPayment;
-
 
9
import com.spice.profitmandi.dao.entity.fofo.PendingOrder;
8
import com.spice.profitmandi.dao.entity.transaction.AddWalletRequest;
10
import com.spice.profitmandi.dao.entity.transaction.AddWalletRequest;
9
import com.spice.profitmandi.dao.entity.transaction.HdfcPayment;
11
import com.spice.profitmandi.dao.entity.transaction.HdfcPayment;
10
import com.spice.profitmandi.dao.enumuration.fofo.Gateway;
12
import com.spice.profitmandi.dao.enumuration.fofo.Gateway;
11
import com.spice.profitmandi.dao.enumuration.transaction.AddWalletRequestStatus;
13
import com.spice.profitmandi.dao.enumuration.transaction.AddWalletRequestStatus;
-
 
14
import com.spice.profitmandi.dao.model.AddAmountToWalletModel;
12
import com.spice.profitmandi.dao.model.PaymentOptionModel;
15
import com.spice.profitmandi.dao.model.PaymentOptionModel;
13
import com.spice.profitmandi.dao.repository.catalog.AddWalletRequestRepository;
16
import com.spice.profitmandi.dao.repository.catalog.AddWalletRequestRepository;
14
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
17
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
15
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
-
 
16
import com.spice.profitmandi.dao.repository.fofo.FofoPaymentRepository;
18
import com.spice.profitmandi.dao.repository.fofo.FofoPaymentRepository;
-
 
19
import com.spice.profitmandi.dao.repository.fofo.PendingOrderRepository;
17
import com.spice.profitmandi.dao.repository.transaction.HdfcPaymentRepository;
20
import com.spice.profitmandi.dao.repository.transaction.HdfcPaymentRepository;
18
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
-
 
19
import com.spice.profitmandi.service.integrations.CCAvenuePaymentService;
21
import com.spice.profitmandi.service.integrations.CCAvenuePaymentService;
-
 
22
import com.spice.profitmandi.service.integrations.pinelabs.PinelabsOrderService;
20
import com.spice.profitmandi.service.user.RetailerService;
23
import com.spice.profitmandi.service.user.RetailerService;
21
import com.spice.profitmandi.service.wallet.WalletService;
24
import com.spice.profitmandi.service.wallet.WalletService;
22
import com.spice.profitmandi.web.req.CreateAddMoneyRequest;
25
import com.spice.profitmandi.web.req.CreateAddMoneyRequest;
23
import io.swagger.annotations.ApiImplicitParam;
26
import io.swagger.annotations.ApiImplicitParam;
24
import io.swagger.annotations.ApiImplicitParams;
27
import io.swagger.annotations.ApiImplicitParams;
25
import io.swagger.annotations.ApiOperation;
28
import io.swagger.annotations.ApiOperation;
26
import org.apache.logging.log4j.LogManager;
29
import org.apache.logging.log4j.LogManager;
27
import org.apache.logging.log4j.Logger;
30
import org.apache.logging.log4j.Logger;
28
import org.springframework.beans.factory.annotation.Autowired;
31
import org.springframework.beans.factory.annotation.Autowired;
29
import org.springframework.beans.factory.annotation.Qualifier;
-
 
30
import org.springframework.http.MediaType;
32
import org.springframework.http.MediaType;
31
import org.springframework.http.ResponseEntity;
33
import org.springframework.http.ResponseEntity;
32
import org.springframework.mail.javamail.JavaMailSender;
34
import org.springframework.mail.javamail.JavaMailSender;
33
import org.springframework.mail.javamail.MimeMessageHelper;
35
import org.springframework.mail.javamail.MimeMessageHelper;
34
import org.springframework.stereotype.Controller;
36
import org.springframework.stereotype.Controller;
Line 52... Line 54...
52
@Controller
54
@Controller
53
@Transactional(rollbackFor = Throwable.class)
55
@Transactional(rollbackFor = Throwable.class)
54
public class WalletController {
56
public class WalletController {
55
 
57
 
56
	private static final Logger log = LogManager.getLogger(WalletController.class);
58
	private static final Logger log = LogManager.getLogger(WalletController.class);
57
 
-
 
58
	@Autowired
-
 
59
	UserWalletRepository userWalletRepository;
-
 
60
	
59
	
61
	@Autowired
60
	@Autowired
62
	FofoPaymentRepository fofoPaymentRepository;
61
	FofoPaymentRepository fofoPaymentRepository;
63
 
62
 
64
	@Autowired
63
	@Autowired
Line 69... Line 68...
69
 
68
 
70
	@Autowired
69
	@Autowired
71
	JavaMailSender mailSender;
70
	JavaMailSender mailSender;
72
 
71
 
73
	@Autowired
72
	@Autowired
74
	@Qualifier("userRepository")
-
 
75
	private UserRepository userRepository;
-
 
76
	
-
 
77
	@Autowired
-
 
78
	private CCAvenuePaymentService ccAvenuePaymentService;
73
	private CCAvenuePaymentService ccAvenuePaymentService;
79
 
74
 
80
	@Autowired
75
	@Autowired
81
	private UserAccountRepository userAccountRepository;
76
	private UserAccountRepository userAccountRepository;
82
 
77
 
83
	@Autowired
78
	@Autowired
84
	private RetailerService retailerService;
79
	private RetailerService retailerService;
85
 
80
 
86
	@Autowired
81
	@Autowired
-
 
82
	private PinelabsOrderService pinelabsOrderService;
-
 
83
 
-
 
84
	@Autowired
-
 
85
	private PendingOrderRepository pendingOrderRepository;
-
 
86
 
-
 
87
	@Autowired
87
	ResponseSender<?> responseSender;
88
	ResponseSender<?> responseSender;
88
 
89
 
89
	@RequestMapping(value = ProfitMandiConstants.URL_MY_WALLET, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
90
	@RequestMapping(value = ProfitMandiConstants.URL_MY_WALLET, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
90
	@ApiImplicitParams({
91
	@ApiImplicitParams({
91
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
92
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
Line 109... Line 110...
109
	}
110
	}
110
	
111
	
111
	@RequestMapping(value = "/wallet/add-via-loan", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
112
	@RequestMapping(value = "/wallet/add-via-loan", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
112
	@ApiImplicitParams({
113
	@ApiImplicitParams({
113
		@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
114
		@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
114
	public ResponseEntity<?> payViaLoan(HttpServletRequest request, @RequestParam double loanAmount, 
115
	public ResponseEntity<?> payViaLoan(HttpServletRequest request, @RequestParam double loanAmount, @RequestParam double surcharge, @RequestParam String payMethod,  @RequestParam Gateway gateway) throws Exception {
115
			@RequestParam double surcharge,
-
 
116
			@RequestParam String payMethod,  @RequestParam Gateway gateway) throws Exception {
-
 
117
		List<PaymentOptionModel> paymentOptionModels = ccAvenuePaymentService.getPaymentOptionModelMap().get(gateway);
116
		List<PaymentOptionModel> paymentOptionModels = ccAvenuePaymentService.getPaymentOptionModelMap().get(gateway);
118
		Optional<PaymentOptionModel> optPaymentOptionModel = paymentOptionModels.stream().filter(x->x.getPaymentMethod().equals(payMethod)).findFirst();
117
		Optional<PaymentOptionModel> optPaymentOptionModel = paymentOptionModels.stream().filter(x->x.getPaymentMethod().equals(payMethod)).findFirst();
119
		
118
		
120
		if(!optPaymentOptionModel.isPresent()) {
119
		if(!optPaymentOptionModel.isPresent()) {
121
			return responseSender.badRequest(new ProfitMandiBusinessException("", "", "Bad parameters in request"));
120
			return responseSender.badRequest(new ProfitMandiBusinessException("", "", "Bad parameters in request"));
Line 224... Line 223...
224
		int userId = (int) request.getAttribute(ProfitMandiConstants.USER_ID);
223
		int userId = (int) request.getAttribute(ProfitMandiConstants.USER_ID);
225
		int retailerId = userAccountRepository.selectRetailerIdByUserId(userId);
224
		int retailerId = userAccountRepository.selectRetailerIdByUserId(userId);
226
		List<AddWalletRequest> walletRequest = addWalletRequestRepository.selectByRetailerId(offset, limit, retailerId);
225
		List<AddWalletRequest> walletRequest = addWalletRequestRepository.selectByRetailerId(offset, limit, retailerId);
227
		return responseSender.ok(walletRequest);
226
		return responseSender.ok(walletRequest);
228
	}
227
	}
229
	
-
 
230
	
-
 
231
	
228
 
232
	@RequestMapping(value = "/getPaymentOptions", method = RequestMethod.GET)
229
	@RequestMapping(value = "/getPaymentOptions", method = RequestMethod.GET)
233
	public ResponseEntity<?> getPaymentOptions(HttpServletRequest request, Model model) throws Exception {
230
	public ResponseEntity<?> getPaymentOptions(HttpServletRequest request, Model model) throws Exception {
234
		return responseSender.ok(ccAvenuePaymentService.getPaymentOptionModelMap());
231
		return responseSender.ok(ccAvenuePaymentService.getPaymentOptionModelMap());
235
	}
232
	}
236
 
233
 
-
 
234
	@RequestMapping(value = "/pay-by-pinelabs", method = RequestMethod.POST)
-
 
235
	public ResponseEntity<?> payByPineLabs(HttpServletRequest request, @RequestBody AddAmountToWalletModel addAmountToWalletModel) throws Exception {
-
 
236
		UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
-
 
237
		PendingOrder pendingOrder = new PendingOrder();
-
 
238
		pendingOrder.setId(addAmountToWalletModel.getOrderId());
-
 
239
		pendingOrder.setCustomerId(userInfo.getUserId());
-
 
240
		pendingOrder.setTotalAmount(addAmountToWalletModel.getOrderAmount());
-
 
241
		pendingOrder.setCustomerAddressId(addAmountToWalletModel.getCustomerAddressId());
-
 
242
		pendingOrder.setCustomerAddress(addAmountToWalletModel.getCustomerAddress());
-
 
243
		String response = pinelabsOrderService.createOrder(pendingOrder);
-
 
244
		return responseSender.ok(response);
-
 
245
	}
-
 
246
 
-
 
247
	@RequestMapping(value = "/pinelabs/status/{orderId}", method = RequestMethod.GET)
-
 
248
	public ResponseEntity<?> checkPaymentStatus(HttpServletRequest request, @PathVariable int orderId) throws Exception {
-
 
249
		UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
-
 
250
		PendingOrder  pendingOrder = pendingOrderRepository.selectById(orderId);
-
 
251
		boolean response = pinelabsOrderService.validatePayment(pendingOrder, orderId);
-
 
252
		return responseSender.ok(response);
-
 
253
	}
-
 
254
 
237
}
255
}
238
256