| Line 1... |
Line 1... |
| 1 |
package com.spice.profitmandi.web.controller;
|
1 |
package com.spice.profitmandi.web.controller;
|
| 2 |
|
2 |
|
| 3 |
import java.text.MessageFormat;
|
3 |
import java.text.MessageFormat;
|
| 4 |
import java.time.LocalDateTime;
|
4 |
import java.time.LocalDateTime;
|
| 5 |
import java.util.ArrayList;
|
- |
|
| 6 |
import java.util.HashMap;
|
- |
|
| 7 |
import java.util.List;
|
5 |
import java.util.List;
|
| 8 |
import java.util.Map;
|
6 |
import java.util.Map;
|
| 9 |
import java.util.Optional;
|
7 |
import java.util.Optional;
|
| 10 |
|
8 |
|
| 11 |
import javax.mail.internet.InternetAddress;
|
9 |
import javax.mail.internet.InternetAddress;
|
| Line 31... |
Line 29... |
| 31 |
|
29 |
|
| 32 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
30 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 33 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
31 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
| 34 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
32 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 35 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
33 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
| 36 |
import com.spice.profitmandi.dao.entity.fofo.LoanPaymentRequest;
|
34 |
import com.spice.profitmandi.dao.entity.fofo.FofoPayment;
|
| 37 |
import com.spice.profitmandi.dao.entity.transaction.AddWalletRequest;
|
35 |
import com.spice.profitmandi.dao.entity.transaction.AddWalletRequest;
|
| 38 |
import com.spice.profitmandi.dao.enumuration.fofo.Gateway;
|
36 |
import com.spice.profitmandi.dao.enumuration.fofo.Gateway;
|
| 39 |
import com.spice.profitmandi.dao.enumuration.transaction.AddWalletRequestStatus;
|
37 |
import com.spice.profitmandi.dao.enumuration.transaction.AddWalletRequestStatus;
|
| 40 |
import com.spice.profitmandi.dao.model.PaymentOptionModel;
|
38 |
import com.spice.profitmandi.dao.model.PaymentOptionModel;
|
| 41 |
import com.spice.profitmandi.dao.repository.catalog.AddWalletRequestRepository;
|
39 |
import com.spice.profitmandi.dao.repository.catalog.AddWalletRequestRepository;
|
| 42 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
40 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
| 43 |
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
|
41 |
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
|
| 44 |
import com.spice.profitmandi.dao.repository.fofo.LoanPaymentRequestRepository;
|
42 |
import com.spice.profitmandi.dao.repository.fofo.FofoPaymentRepository;
|
| 45 |
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
|
43 |
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
|
| 46 |
import com.spice.profitmandi.service.integrations.CCAvenuePaymentService;
|
44 |
import com.spice.profitmandi.service.integrations.CCAvenuePaymentService;
|
| 47 |
import com.spice.profitmandi.service.user.RetailerService;
|
45 |
import com.spice.profitmandi.service.user.RetailerService;
|
| 48 |
import com.spice.profitmandi.service.wallet.WalletService;
|
46 |
import com.spice.profitmandi.service.wallet.WalletService;
|
| 49 |
import com.spice.profitmandi.web.req.CreateAddMoneyRequest;
|
47 |
import com.spice.profitmandi.web.req.CreateAddMoneyRequest;
|
| Line 60... |
Line 58... |
| 60 |
|
58 |
|
| 61 |
@Autowired
|
59 |
@Autowired
|
| 62 |
UserWalletRepository userWalletRepository;
|
60 |
UserWalletRepository userWalletRepository;
|
| 63 |
|
61 |
|
| 64 |
@Autowired
|
62 |
@Autowired
|
| 65 |
LoanPaymentRequestRepository loanPaymentRequestRepository;
|
63 |
FofoPaymentRepository fofoPaymentRepository;
|
| 66 |
|
64 |
|
| 67 |
@Autowired
|
65 |
@Autowired
|
| 68 |
AddWalletRequestRepository addWalletRequestRepository;
|
66 |
AddWalletRequestRepository addWalletRequestRepository;
|
| 69 |
|
67 |
|
| 70 |
@Autowired
|
68 |
@Autowired
|
| Line 128... |
Line 126... |
| 128 |
return responseSender.badRequest(new ProfitMandiBusinessException("", "", "Bad parameters in request"));
|
126 |
return responseSender.badRequest(new ProfitMandiBusinessException("", "", "Bad parameters in request"));
|
| 129 |
}
|
127 |
}
|
| 130 |
}
|
128 |
}
|
| 131 |
int userId = (int) request.getAttribute("userId");
|
129 |
int userId = (int) request.getAttribute("userId");
|
| 132 |
int retailerId = userAccountRepository.selectRetailerIdByUserId(userId);
|
130 |
int retailerId = userAccountRepository.selectRetailerIdByUserId(userId);
|
| 133 |
LoanPaymentRequest loanPaymentRequest = new LoanPaymentRequest();
|
131 |
FofoPayment fofoPayment = new FofoPayment();
|
| 134 |
loanPaymentRequest.setCreateTimestamp(LocalDateTime.now());
|
132 |
fofoPayment.setCreateTimestamp(LocalDateTime.now());
|
| 135 |
loanPaymentRequest.setFofoId(retailerId);
|
133 |
fofoPayment.setFofoId(retailerId);
|
| 136 |
loanPaymentRequest.setCreditAmount(loanAmount);
|
134 |
fofoPayment.setAmount(loanAmount);
|
| 137 |
loanPaymentRequest.setGatewayFee(surcharge);
|
135 |
fofoPayment.setGatewayFee(surcharge);
|
| 138 |
loanPaymentRequest.setGateway(gateway);
|
136 |
fofoPayment.setGateway(gateway);
|
| 139 |
loanPaymentRequest.setPaymentMethod(optPaymentOptionModel.get().getPaymentMethodDesctiption());
|
137 |
fofoPayment.setPaymentMethod(optPaymentOptionModel.get().getPaymentMethodDesctiption());
|
| 140 |
loanPaymentRequestRepository.persist(loanPaymentRequest);
|
138 |
fofoPaymentRepository.persist(fofoPayment);
|
| 141 |
Map<String, String> returnMap = ccAvenuePaymentService.getFormParams(loanPaymentRequest, payMethod);
|
139 |
Map<String, String> returnMap = ccAvenuePaymentService.getFormParams(fofoPayment, payMethod);
|
| 142 |
returnMap.put("status", "pending");
|
140 |
returnMap.put("status", "pending");
|
| 143 |
return responseSender.ok(returnMap);
|
141 |
return responseSender.ok(returnMap);
|
| 144 |
|
142 |
|
| 145 |
}
|
143 |
}
|
| 146 |
|
144 |
|
| Line 181... |
Line 179... |
| 181 |
public ResponseEntity<?> addMoneyToWallet(HttpServletRequest request,@PathVariable int loanId) throws Exception {
|
179 |
public ResponseEntity<?> addMoneyToWallet(HttpServletRequest request,@PathVariable int loanId) throws Exception {
|
| 182 |
int userId = (int) request.getAttribute(ProfitMandiConstants.USER_ID);
|
180 |
int userId = (int) request.getAttribute(ProfitMandiConstants.USER_ID);
|
| 183 |
log.info("user_id" + userId);
|
181 |
log.info("user_id" + userId);
|
| 184 |
int retailerId = userAccountRepository.selectRetailerIdByUserId(userId);
|
182 |
int retailerId = userAccountRepository.selectRetailerIdByUserId(userId);
|
| 185 |
|
183 |
|
| 186 |
LoanPaymentRequest loanPaymentRequest = loanPaymentRequestRepository.selectById(loanId);
|
184 |
FofoPayment fofoPayment = fofoPaymentRepository.selectById(loanId);
|
| 187 |
if(loanPaymentRequest.getFofoId()!=retailerId) {
|
185 |
if(fofoPayment.getFofoId()!=retailerId) {
|
| 188 |
return responseSender.badRequest(new ProfitMandiBusinessException("Invalid Add Money Id", "Invalid Add money id", "Invalid Add Money"));
|
186 |
return responseSender.badRequest(new ProfitMandiBusinessException("Invalid Add Money Id", "Invalid Add money id", "Invalid Add Money"));
|
| 189 |
}
|
187 |
}
|
| 190 |
return responseSender.ok(loanPaymentRequest);
|
188 |
return responseSender.ok(fofoPayment);
|
| 191 |
}
|
189 |
}
|
| 192 |
|
190 |
|
| 193 |
private void sendMailWithAttachments(String email, String subject, String messageText) throws Exception {
|
191 |
private void sendMailWithAttachments(String email, String subject, String messageText) throws Exception {
|
| 194 |
log.info("message" + messageText);
|
192 |
log.info("message" + messageText);
|
| 195 |
MimeMessage message = mailSender.createMimeMessage();
|
193 |
MimeMessage message = mailSender.createMimeMessage();
|