| 21532 |
kshitij.so |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
|
|
3 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 23942 |
tejbeer |
4 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
| 21532 |
kshitij.so |
5 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 22609 |
ashik.ali |
6 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
| 29503 |
amit.gupta |
7 |
import com.spice.profitmandi.dao.entity.fofo.FofoPayment;
|
| 23936 |
tejbeer |
8 |
import com.spice.profitmandi.dao.entity.transaction.AddWalletRequest;
|
| 28257 |
amit.gupta |
9 |
import com.spice.profitmandi.dao.enumuration.fofo.Gateway;
|
| 23936 |
tejbeer |
10 |
import com.spice.profitmandi.dao.enumuration.transaction.AddWalletRequestStatus;
|
| 28257 |
amit.gupta |
11 |
import com.spice.profitmandi.dao.model.PaymentOptionModel;
|
| 23936 |
tejbeer |
12 |
import com.spice.profitmandi.dao.repository.catalog.AddWalletRequestRepository;
|
|
|
13 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
|
|
14 |
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
|
| 29503 |
amit.gupta |
15 |
import com.spice.profitmandi.dao.repository.fofo.FofoPaymentRepository;
|
| 22555 |
amit.gupta |
16 |
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
|
| 28257 |
amit.gupta |
17 |
import com.spice.profitmandi.service.integrations.CCAvenuePaymentService;
|
| 23942 |
tejbeer |
18 |
import com.spice.profitmandi.service.user.RetailerService;
|
| 22605 |
ashik.ali |
19 |
import com.spice.profitmandi.service.wallet.WalletService;
|
| 23936 |
tejbeer |
20 |
import com.spice.profitmandi.web.req.CreateAddMoneyRequest;
|
| 21532 |
kshitij.so |
21 |
import io.swagger.annotations.ApiImplicitParam;
|
|
|
22 |
import io.swagger.annotations.ApiImplicitParams;
|
|
|
23 |
import io.swagger.annotations.ApiOperation;
|
| 30700 |
amit.gupta |
24 |
import org.apache.logging.log4j.LogManager;
|
|
|
25 |
import org.apache.logging.log4j.Logger;
|
|
|
26 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
27 |
import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
28 |
import org.springframework.http.MediaType;
|
|
|
29 |
import org.springframework.http.ResponseEntity;
|
|
|
30 |
import org.springframework.mail.javamail.JavaMailSender;
|
|
|
31 |
import org.springframework.mail.javamail.MimeMessageHelper;
|
|
|
32 |
import org.springframework.stereotype.Controller;
|
|
|
33 |
import org.springframework.transaction.annotation.Transactional;
|
|
|
34 |
import org.springframework.ui.Model;
|
|
|
35 |
import org.springframework.web.bind.annotation.*;
|
| 21532 |
kshitij.so |
36 |
|
| 30700 |
amit.gupta |
37 |
import javax.mail.internet.InternetAddress;
|
|
|
38 |
import javax.mail.internet.MimeMessage;
|
|
|
39 |
import javax.servlet.http.HttpServletRequest;
|
|
|
40 |
import java.text.MessageFormat;
|
|
|
41 |
import java.time.LocalDateTime;
|
|
|
42 |
import java.util.List;
|
|
|
43 |
import java.util.Map;
|
|
|
44 |
import java.util.Optional;
|
|
|
45 |
|
| 21532 |
kshitij.so |
46 |
@Controller
|
| 23936 |
tejbeer |
47 |
@Transactional(rollbackFor = Throwable.class)
|
| 21532 |
kshitij.so |
48 |
public class WalletController {
|
|
|
49 |
|
| 23936 |
tejbeer |
50 |
private static final Logger log = LogManager.getLogger(WalletController.class);
|
| 21532 |
kshitij.so |
51 |
|
|
|
52 |
@Autowired
|
| 23037 |
ashik.ali |
53 |
UserWalletRepository userWalletRepository;
|
| 28257 |
amit.gupta |
54 |
|
|
|
55 |
@Autowired
|
| 29503 |
amit.gupta |
56 |
FofoPaymentRepository fofoPaymentRepository;
|
| 23936 |
tejbeer |
57 |
|
| 21532 |
kshitij.so |
58 |
@Autowired
|
| 23936 |
tejbeer |
59 |
AddWalletRequestRepository addWalletRequestRepository;
|
|
|
60 |
|
|
|
61 |
@Autowired
|
| 23037 |
ashik.ali |
62 |
WalletService walletService;
|
| 23936 |
tejbeer |
63 |
|
| 23037 |
ashik.ali |
64 |
@Autowired
|
| 31644 |
tejbeer |
65 |
@Qualifier(value = "googleMailSender")
|
| 23936 |
tejbeer |
66 |
JavaMailSender mailSender;
|
|
|
67 |
|
|
|
68 |
@Autowired
|
|
|
69 |
@Qualifier("userRepository")
|
|
|
70 |
private UserRepository userRepository;
|
| 28257 |
amit.gupta |
71 |
|
|
|
72 |
@Autowired
|
|
|
73 |
private CCAvenuePaymentService ccAvenuePaymentService;
|
| 23936 |
tejbeer |
74 |
|
|
|
75 |
@Autowired
|
|
|
76 |
private UserAccountRepository userAccountRepository;
|
| 25249 |
amit.gupta |
77 |
|
| 23942 |
tejbeer |
78 |
@Autowired
|
|
|
79 |
private RetailerService retailerService;
|
| 23936 |
tejbeer |
80 |
|
|
|
81 |
@Autowired
|
| 23037 |
ashik.ali |
82 |
ResponseSender<?> responseSender;
|
|
|
83 |
|
| 23936 |
tejbeer |
84 |
@RequestMapping(value = ProfitMandiConstants.URL_MY_WALLET, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 21532 |
kshitij.so |
85 |
@ApiImplicitParams({
|
| 23936 |
tejbeer |
86 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
| 21532 |
kshitij.so |
87 |
@ApiOperation(value = "")
|
| 23936 |
tejbeer |
88 |
public ResponseEntity<?> getMyWallet(HttpServletRequest request) throws ProfitMandiBusinessException {
|
|
|
89 |
int userId = (int) request.getAttribute("userId");
|
| 25249 |
amit.gupta |
90 |
return responseSender.ok(walletService.getUserWalletByUserId(userId));
|
| 21532 |
kshitij.so |
91 |
}
|
|
|
92 |
|
| 23936 |
tejbeer |
93 |
@RequestMapping(value = ProfitMandiConstants.URL_MY_WALLET_HISTORY, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 21532 |
kshitij.so |
94 |
@ApiImplicitParams({
|
| 23936 |
tejbeer |
95 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
|
|
96 |
public ResponseEntity<?> getMyWalletHistory(HttpServletRequest request) throws ProfitMandiBusinessException {
|
|
|
97 |
int userId = (int) request.getAttribute("userId");
|
| 28257 |
amit.gupta |
98 |
int retailerId = userAccountRepository.selectRetailerIdByUserId(userId);
|
| 23936 |
tejbeer |
99 |
try {
|
| 28257 |
amit.gupta |
100 |
return responseSender.ok(walletService.getPaginatedUserWalletHistoryByRetailerId(retailerId, null, null, 0, 150));
|
| 23936 |
tejbeer |
101 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
| 23037 |
ashik.ali |
102 |
return responseSender.badRequest(profitMandiBusinessException);
|
|
|
103 |
}
|
| 21532 |
kshitij.so |
104 |
}
|
| 28257 |
amit.gupta |
105 |
|
|
|
106 |
@RequestMapping(value = "/wallet/add-via-loan", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
107 |
@ApiImplicitParams({
|
|
|
108 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
|
|
109 |
public ResponseEntity<?> payViaLoan(HttpServletRequest request, @RequestParam double loanAmount,
|
|
|
110 |
@RequestParam double surcharge,
|
|
|
111 |
@RequestParam String payMethod, @RequestParam Gateway gateway) throws Exception {
|
|
|
112 |
List<PaymentOptionModel> paymentOptionModels = ccAvenuePaymentService.getPaymentOptionModelMap().get(gateway);
|
|
|
113 |
Optional<PaymentOptionModel> optPaymentOptionModel = paymentOptionModels.stream().filter(x->x.getPaymentMethod().equals(payMethod)).findFirst();
|
|
|
114 |
|
|
|
115 |
if(!optPaymentOptionModel.isPresent()) {
|
|
|
116 |
return responseSender.badRequest(new ProfitMandiBusinessException("", "", "Bad parameters in request"));
|
|
|
117 |
} else {
|
| 30700 |
amit.gupta |
118 |
double interimValue = optPaymentOptionModel.get().getSurcharge() * 1.18 / 100;
|
|
|
119 |
double calculatedSurcharge = Math.round(loanAmount * interimValue / (1 - interimValue));
|
|
|
120 |
if (Math.abs(calculatedSurcharge - surcharge) >= 1) {
|
| 28257 |
amit.gupta |
121 |
return responseSender.badRequest(new ProfitMandiBusinessException("", "", "Bad parameters in request"));
|
|
|
122 |
}
|
|
|
123 |
}
|
|
|
124 |
int userId = (int) request.getAttribute("userId");
|
|
|
125 |
int retailerId = userAccountRepository.selectRetailerIdByUserId(userId);
|
| 29503 |
amit.gupta |
126 |
FofoPayment fofoPayment = new FofoPayment();
|
|
|
127 |
fofoPayment.setCreateTimestamp(LocalDateTime.now());
|
|
|
128 |
fofoPayment.setFofoId(retailerId);
|
|
|
129 |
fofoPayment.setAmount(loanAmount);
|
|
|
130 |
fofoPayment.setGatewayFee(surcharge);
|
|
|
131 |
fofoPayment.setGateway(gateway);
|
|
|
132 |
fofoPayment.setPaymentMethod(optPaymentOptionModel.get().getPaymentMethodDesctiption());
|
|
|
133 |
fofoPaymentRepository.persist(fofoPayment);
|
|
|
134 |
Map<String, String> returnMap = ccAvenuePaymentService.getFormParams(fofoPayment, payMethod);
|
| 28257 |
amit.gupta |
135 |
returnMap.put("status", "pending");
|
|
|
136 |
return responseSender.ok(returnMap);
|
|
|
137 |
|
|
|
138 |
}
|
| 21532 |
kshitij.so |
139 |
|
| 23936 |
tejbeer |
140 |
@RequestMapping(value = ProfitMandiConstants.URL_ADD_MONEY_TO_WALLET, method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
141 |
@ApiImplicitParams({
|
|
|
142 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
| 28257 |
amit.gupta |
143 |
public ResponseEntity<?> addMoneyToWallet(HttpServletRequest request,
|
| 23936 |
tejbeer |
144 |
@RequestBody CreateAddMoneyRequest createAddMoneyRequest) throws Exception {
|
|
|
145 |
int userId = (int) request.getAttribute(ProfitMandiConstants.USER_ID);
|
| 25249 |
amit.gupta |
146 |
log.info("user_id" + userId);
|
| 23936 |
tejbeer |
147 |
int retailerId = userAccountRepository.selectRetailerIdByUserId(userId);
|
| 25249 |
amit.gupta |
148 |
CustomRetailer customRetailer = retailerService.getFofoRetailer(retailerId);
|
| 23936 |
tejbeer |
149 |
AddWalletRequest addWalletrequest = new AddWalletRequest();
|
|
|
150 |
addWalletrequest.setRetailerId(retailerId);
|
|
|
151 |
addWalletrequest.setAmount(createAddMoneyRequest.getAmount());
|
|
|
152 |
addWalletrequest.setTransaction_reference(createAddMoneyRequest.getTransaction_reference());
|
| 24089 |
tejbeer |
153 |
addWalletrequest.setReference_date(createAddMoneyRequest.getReference_date());
|
| 24749 |
tejbeer |
154 |
addWalletrequest.setBank_name(createAddMoneyRequest.getBank_name());
|
| 23936 |
tejbeer |
155 |
addWalletrequest.setStatus(AddWalletRequestStatus.pending);
|
| 25249 |
amit.gupta |
156 |
log.info("info" + addWalletrequest);
|
| 23936 |
tejbeer |
157 |
addWalletRequestRepository.persist(addWalletrequest);
|
| 23942 |
tejbeer |
158 |
log.info("fofoinfo" + customRetailer);
|
| 23936 |
tejbeer |
159 |
String subject = "Add money to wallet request";
|
| 25249 |
amit.gupta |
160 |
String messageText = MessageFormat.format(
|
|
|
161 |
"User Id - {0}\n Name -{1}\n Email -{2}\n Reference - {3}\n Amount - Rs.{4} \n link - {5}",
|
|
|
162 |
new Integer(addWalletrequest.getRetailerId()), customRetailer.getBusinessName(),
|
|
|
163 |
customRetailer.getEmail(), addWalletrequest.getTransaction_reference(),
|
|
|
164 |
new Float(addWalletrequest.getAmount()), "http://partners.smartdukaan.com/dashboard");
|
| 23943 |
tejbeer |
165 |
String email = "neeraj.gupta@smartdukaan.com";
|
| 23936 |
tejbeer |
166 |
this.sendMailWithAttachments(email, subject, messageText);
|
|
|
167 |
|
|
|
168 |
return responseSender.ok(true);
|
|
|
169 |
}
|
| 28257 |
amit.gupta |
170 |
|
|
|
171 |
@RequestMapping(value = "/wallet/add-money/{loanId}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
172 |
@ApiImplicitParams({
|
|
|
173 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
|
|
174 |
public ResponseEntity<?> addMoneyToWallet(HttpServletRequest request,@PathVariable int loanId) throws Exception {
|
|
|
175 |
int userId = (int) request.getAttribute(ProfitMandiConstants.USER_ID);
|
|
|
176 |
log.info("user_id" + userId);
|
|
|
177 |
int retailerId = userAccountRepository.selectRetailerIdByUserId(userId);
|
|
|
178 |
|
| 29503 |
amit.gupta |
179 |
FofoPayment fofoPayment = fofoPaymentRepository.selectById(loanId);
|
|
|
180 |
if(fofoPayment.getFofoId()!=retailerId) {
|
| 28257 |
amit.gupta |
181 |
return responseSender.badRequest(new ProfitMandiBusinessException("Invalid Add Money Id", "Invalid Add money id", "Invalid Add Money"));
|
|
|
182 |
}
|
| 29503 |
amit.gupta |
183 |
return responseSender.ok(fofoPayment);
|
| 28257 |
amit.gupta |
184 |
}
|
| 23936 |
tejbeer |
185 |
|
|
|
186 |
private void sendMailWithAttachments(String email, String subject, String messageText) throws Exception {
|
|
|
187 |
log.info("message" + messageText);
|
|
|
188 |
MimeMessage message = mailSender.createMimeMessage();
|
|
|
189 |
MimeMessageHelper helper = new MimeMessageHelper(message, true);
|
|
|
190 |
helper.setSubject(subject);
|
|
|
191 |
helper.setText(messageText);
|
|
|
192 |
helper.setTo(email);
|
| 25249 |
amit.gupta |
193 |
// helper.setCc("neerajgupta2021@gmail.com");
|
| 23936 |
tejbeer |
194 |
InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "ProfitMandi Admin");
|
|
|
195 |
helper.setFrom(senderAddress);
|
|
|
196 |
mailSender.send(message);
|
|
|
197 |
|
|
|
198 |
}
|
| 25249 |
amit.gupta |
199 |
|
| 23942 |
tejbeer |
200 |
@RequestMapping(value = ProfitMandiConstants.URL_ADD_MONEY_TO_WALLET_HISTORY, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
201 |
@ApiImplicitParams({
|
|
|
202 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
| 25249 |
amit.gupta |
203 |
public ResponseEntity<?> getAddMoneyToWalletHistory(HttpServletRequest request,
|
|
|
204 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
| 23942 |
tejbeer |
205 |
@RequestParam(name = "limit", defaultValue = "10") int limit) throws ProfitMandiBusinessException {
|
|
|
206 |
int userId = (int) request.getAttribute(ProfitMandiConstants.USER_ID);
|
|
|
207 |
int retailerId = userAccountRepository.selectRetailerIdByUserId(userId);
|
| 25249 |
amit.gupta |
208 |
List<AddWalletRequest> walletRequest = addWalletRequestRepository.selectByRetailerId(offset, limit, retailerId);
|
|
|
209 |
return responseSender.ok(walletRequest);
|
| 23942 |
tejbeer |
210 |
}
|
| 28257 |
amit.gupta |
211 |
|
|
|
212 |
|
|
|
213 |
|
|
|
214 |
@RequestMapping(value = "/getPaymentOptions", method = RequestMethod.GET)
|
|
|
215 |
public ResponseEntity<?> getPaymentOptions(HttpServletRequest request, Model model) throws Exception {
|
|
|
216 |
return responseSender.ok(ccAvenuePaymentService.getPaymentOptionModelMap());
|
|
|
217 |
}
|
| 25249 |
amit.gupta |
218 |
|
| 21532 |
kshitij.so |
219 |
}
|