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