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